예제 #1
0
        public SendEmail(IBrowsableCollection selection) : base("mail_dialog")
        {
            this.selection = selection;

            // Set default values in dialog. Fetch from Preferences.
            switch ((int)Preferences.Get(Preferences.EXPORT_EMAIL_SIZE))
            {
            case 0:  original_size.Active = true; break;

            case 1:  tiny_size.Active = true; break;

            case 2:  small_size.Active = true; break;

            case 3:  medium_size.Active = true; break;

            case 4:  large_size.Active = true; break;

            case 5:  x_large_size.Active = true; break;

            default: break;
            }
            rotate_check.Active    = (bool)Preferences.Get(Preferences.EXPORT_EMAIL_ROTATE);
            rotate_check.Sensitive = original_size.Active;

            tray_scrolled.Add(new TrayView(selection));

            Dialog.Modal = false;

            string path;

            System.IO.FileInfo file_info;

            // Calculate total original filesize
            foreach (Photo photo in selection.Items)
            {
                if (photo != null)
                {
                    path = photo.GetVersionPath(photo.DefaultVersionId);
                    if (System.IO.File.Exists(path))
                    {
                        file_info        = new System.IO.FileInfo(path);
                        Orig_Photo_Size += file_info.Length;
                    }     // if file exists
                }         // if photo != null
            }             // foreach

            for (int k = 0; k < avg_scale_ref.Length; k++)
            {
                avg_scale[k] = avg_scale_ref[k];
            }


            // Calculate approximate size shrinking, use first photo, and shrink to medium size as base.
            Photo scalephoto = selection.Items [0] as Photo;

            if (scalephoto != null)
            {
                // Get first photos file size
                file_info = new System.IO.FileInfo(scalephoto.GetVersionPath(scalephoto.DefaultVersionId));
                long orig_size = file_info.Length;

                // Get filesize of first photo after resizing it to medium size
                path      = PixbufUtils.Resize(scalephoto.GetVersionPath(scalephoto.DefaultVersionId), sizes[3], true);
                file_info = new System.IO.FileInfo(path);
                long new_size = file_info.Length;

                // Delete the just created temporary resized photo
                System.IO.File.Delete(path);

                if (orig_size > 0)
                {
                    // Get the factor (scale) between original and resized medium size.
                    scale_percentage = 1 - ((float)(orig_size - new_size) / orig_size);

                    // What is the relation between the estimated medium scale factor, and reality?
                    double scale_scale = scale_percentage / avg_scale_ref[3];

                    //System.Console.WriteLine ("scale_percentage {0}, ref {1}, relative {2}",
                    //	scale_percentage, avg_scale_ref[3], scale_scale  );

                    // Re-Calculate the proper relation per size
                    for (int k = 0; k < avg_scale_ref.Length; k++)
                    {
                        avg_scale[k] = avg_scale_ref[k] * scale_scale;
                        //	System.Console.WriteLine ("avg_scale[{0}]={1} (was {2})",
                        //		k, avg_scale[k], avg_scale_ref[k]  );
                    }
                }
            }

            NumberOfPictures.Text  = selection.Count.ToString();
            TotalOriginalSize.Text = SizeUtil.ToHumanReadable(Orig_Photo_Size);

            UpdateEstimatedSize();

            Dialog.ShowAll();

            //LoadHistory ();

            Dialog.Response += HandleResponse;
        }
예제 #2
0
        public Point WindowCoordsToImage(Point win)
        {
            if (Pixbuf == null)
            {
                return(Point.Zero);
            }

            int x_offset = scaled_width < Allocation.Width ? (int)(Allocation.Width - scaled_width) / 2 : -XOffset;
            int y_offset = scaled_height < Allocation.Height ? (int)(Allocation.Height - scaled_height) / 2 : -YOffset;

            win.X = Clamp(win.X - x_offset, 0, (int)scaled_width - 1);
            win.Y = Clamp(win.Y - y_offset, 0, (int)scaled_height - 1);

            win = PixbufUtils.TransformOrientation((int)scaled_width, (int)scaled_height, win, PixbufUtils.ReverseTransformation(pixbuf_orientation));

            return(new Point((int)Math.Floor(win.X * (double)(((int)PixbufOrientation <= 4 ? Pixbuf.Width : Pixbuf.Height) - 1) / (double)(scaled_width - 1) + .5),
                             (int)Math.Floor(win.Y * (double)(((int)PixbufOrientation <= 4 ? Pixbuf.Height : Pixbuf.Width) - 1) / (double)(scaled_height - 1) + .5)));
        }
예제 #3
0
        void PaintRectangle(Rectangle area, InterpType interpolation)
        {
            int x_offset = scaled_width < Allocation.Width ? (int)(Allocation.Width - scaled_width) / 2 : -XOffset;
            int y_offset = scaled_height < Allocation.Height ? (int)(Allocation.Height - scaled_height) / 2 : -YOffset;

            //Draw background
            if (y_offset > 0)                   //Top
            {
                PaintBackground(new Rectangle(0, 0, Allocation.Width, y_offset), area);
            }
            if (x_offset > 0)                   //Left
            {
                PaintBackground(new Rectangle(0, y_offset, x_offset, (int)scaled_height), area);
            }
            if (x_offset >= 0)                  //Right
            {
                PaintBackground(new Rectangle(x_offset + (int)scaled_width, y_offset, Allocation.Width - x_offset - (int)scaled_width, (int)scaled_height), area);
            }
            if (y_offset >= 0)                  //Bottom
            {
                PaintBackground(new Rectangle(0, y_offset + (int)scaled_height, Allocation.Width, Allocation.Height - y_offset - (int)scaled_height), area);
            }

            if (Pixbuf == null)
            {
                return;
            }

            area.Intersect(new Rectangle(x_offset, y_offset, (int)scaled_width, (int)scaled_height));

            if (area.Width <= 0 || area.Height <= 0)
            {
                return;
            }

            //Short circuit for 1:1 zoom
            if (zoom == 1.0 &&
                !Pixbuf.HasAlpha &&
                Pixbuf.BitsPerSample == 8 &&
                pixbuf_orientation == ImageOrientation.TopLeft)
            {
                GdkWindow.DrawPixbuf(Style.BlackGC,
                                     Pixbuf,
                                     area.X - x_offset, area.Y - y_offset,
                                     area.X, area.Y,
                                     area.Width, area.Height,
                                     RgbDither.Max,
                                     area.X - x_offset, area.Y - y_offset);
                return;
            }

            Rectangle pixbuf_area = PixbufUtils.TransformOrientation((int)scaled_width,
                                                                     (int)scaled_height,
                                                                     new Rectangle((area.X - x_offset),
                                                                                   (area.Y - y_offset),
                                                                                   area.Width,
                                                                                   area.Height),
                                                                     PixbufUtils.ReverseTransformation(pixbuf_orientation));

            using (Pixbuf temp_pixbuf = new Pixbuf(Colorspace.Rgb, false, 8, pixbuf_area.Width, pixbuf_area.Height)) {
                if (Pixbuf.HasAlpha)
                {
                    temp_pixbuf.Fill(0x00000000);
                }

                Pixbuf.CompositeColor(temp_pixbuf,
                                      0, 0,
                                      pixbuf_area.Width, pixbuf_area.Height,
                                      -pixbuf_area.X, -pixbuf_area.Y,
                                      zoom, zoom,
                                      zoom == 1.0 ? InterpType.Nearest : interpolation, 255,
                                      pixbuf_area.X, pixbuf_area.Y,
                                      CheckPattern.CheckSize, CheckPattern.Color1, CheckPattern.Color2);


                ApplyColorTransform(temp_pixbuf);

                using (var dest_pixbuf = PixbufUtils.TransformOrientation(temp_pixbuf, pixbuf_orientation)) {
                    GdkWindow.DrawPixbuf(Style.BlackGC,
                                         dest_pixbuf,
                                         0, 0,
                                         area.X, area.Y,
                                         area.Width, area.Height,
                                         RgbDither.Max,
                                         area.X - x_offset, area.Y - y_offset);
                }
            }
        }
        public bool Convert(FilterRequest req)
        {
            string source = req.Current.LocalPath;

            System.Uri dest_uri = req.TempUri(System.IO.Path.GetExtension(source));
            string     dest     = dest_uri.LocalPath;

            using (ImageFile img = ImageFile.Create(source)) {
                bool changed = false;

                if (img.Orientation != PixbufOrientation.TopLeft && img is JpegFile)
                {
                    JpegFile jimg = img as JpegFile;

                    if (img.Orientation == PixbufOrientation.RightTop)
                    {
                        JpegUtils.Transform(source,
                                            dest,
                                            JpegUtils.TransformType.Rotate90);
                        changed = true;
                    }
                    else if (img.Orientation == PixbufOrientation.LeftBottom)
                    {
                        JpegUtils.Transform(source,
                                            dest,
                                            JpegUtils.TransformType.Rotate270);
                        changed = true;
                    }
                    else if (img.Orientation == PixbufOrientation.BottomRight)
                    {
                        JpegUtils.Transform(source,
                                            dest,
                                            JpegUtils.TransformType.Rotate180);
                        changed = true;
                    }

                    int width, height;

                    jimg = ImageFile.Create(dest) as JpegFile;

                    PixbufUtils.GetSize(dest, out width, out height);

                    jimg.SetOrientation(PixbufOrientation.TopLeft);
                    jimg.SetDimensions(width, height);

                    Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(dest, 160, 120, true);
                    jimg.SetThumbnail(pixbuf);
                    pixbuf.Dispose();

                    jimg.SaveMetaData(dest);
                    jimg.Dispose();
                }

                if (changed)
                {
                    req.Current = dest_uri;
                }

                return(changed);
            }
        }
예제 #5
0
        public void Save()
        {
            if (!Changed)
            {
                this.Dialog.Destroy();
                return;
            }

            if (!view.Item.IsValid)
            {
                return;
            }

            Console.WriteLine("Saving....");

            Photo photo = (Photo)view.Item.Current;

            try {
                bool create_version = photo.DefaultVersionId == Photo.OriginalVersionId;

                Gdk.Pixbuf orig  = view.CompletePixbuf();
                Gdk.Pixbuf final = new Gdk.Pixbuf(Gdk.Colorspace.Rgb,
                                                  false, 8,
                                                  orig.Width,
                                                  orig.Height);

                Cms.Profile abs = AdjustmentProfile();

                // FIXME this shouldn't use the screen as the destination profile.
                Cms.Profile destination = Cms.Profile.GetScreenProfile(view.Screen);
                if (destination == null)
                {
                    destination = Cms.Profile.CreateStandardRgb();
                }

                Cms.Profile [] list      = new Cms.Profile [] { image_profile, abs, destination };
                Cms.Transform  transform = new Cms.Transform(list,
                                                             PixbufUtils.PixbufCmsFormat(orig),
                                                             PixbufUtils.PixbufCmsFormat(final),
                                                             Cms.Intent.Perceptual, 0x0000);

                PixbufUtils.ColorAdjust(orig,
                                        final,
                                        transform);

                photo.SaveVersion(final, create_version);
                ((PhotoQuery)view.Query).Commit(view.Item.Index);
                final.Dispose();
            } catch (System.Exception e) {
                string msg  = Catalog.GetString("Error saving adjusted photo");
                string desc = String.Format(Catalog.GetString("Received exception \"{0}\". Unable to save photo {1}"),
                                            e.Message, photo.Name);

                HigMessageDialog md = new HigMessageDialog((Gtk.Window)Dialog.Toplevel,
                                                           DialogFlags.DestroyWithParent,
                                                           Gtk.MessageType.Error, ButtonsType.Ok,
                                                           msg,
                                                           desc);
                md.Run();
                md.Destroy();
            }

            this.Dialog.Sensitive = false;
            this.Dialog.Destroy();
        }
예제 #6
0
        protected virtual Pixbuf GetPixbuf(int i, bool highlighted)
        {
            Pixbuf  current = null;
            SafeUri uri     = (selection.Collection [i]).DefaultVersion.Uri;

            try {
                var pixbuf = thumb_cache.Get(uri);
                if (pixbuf != null)
                {
                    current = pixbuf.ShallowCopy();
                }
            } catch (IndexOutOfRangeException) {
                current = null;
            }

            if (current == null)
            {
                var pixbuf = XdgThumbnailSpec.LoadThumbnail(uri, ThumbnailSize.Large, null);
                if (pixbuf == null)
                {
                    ThumbnailLoader.Default.Request(uri, ThumbnailSize.Large, 0);
                    current = FSpot.Core.Global.IconTheme.LoadIcon("gtk-missing-image", ThumbSize, (Gtk.IconLookupFlags) 0);
                }
                else
                {
                    if (SquaredThumbs)
                    {
                        current = PixbufUtils.IconFromPixbuf(pixbuf, ThumbSize);
                    }
                    else
                    {
                        current = pixbuf.ScaleSimple(ThumbSize, ThumbSize, InterpType.Nearest);
                    }
                    pixbuf.Dispose();
                    thumb_cache.Add(uri, current);
                }
            }

            //FIXME: we might end up leaking a pixbuf here
            Cms.Profile screen_profile;
            if (FSpot.ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
            {
                Pixbuf t = current.Copy();
                current = t;
                FSpot.ColorManagement.ApplyProfile(current, screen_profile);
            }

            // Add a four pixel white border around the thumbnail
            using (Pixbuf whiteBorder = new Pixbuf(Gdk.Colorspace.Rgb, true, 8, current.Width, current.Height)) {
                whiteBorder.Fill(0);
                current.CopyArea(1, 1, current.Width - 8, current.Height - 8, whiteBorder, 4, 4);
                current = whiteBorder;
            }

            if (!highlighted)
            {
                return(current);
            }

            Pixbuf highlight = new Pixbuf(Gdk.Colorspace.Rgb, true, 8, current.Width, current.Height);

            highlight.Fill(ColorToInt(Style.Light(StateType.Selected)));

            // Add a two pixel highlight around the thumbnail
            current.CopyArea(2, 2, current.Width - 4, current.Height - 4, highlight, 2, 2);

            return(highlight);
        }
예제 #7
0
        // FIXME this design sucks, I'm just doing it this way while
        // I redesign the editing system.
        private void ProcessImage(bool redeye)
        {
            int x, y, width, height;

            if (!photo_view.GetSelection(out x, out y, out width, out height))
            {
                string msg  = Catalog.GetString("No selection available");
                string desc = Catalog.GetString("This tool requires an active selection. Please select a region of the photo and try the operation again");

                HigMessageDialog md = new HigMessageDialog((Gtk.Window) this.Toplevel, DialogFlags.DestroyWithParent,
                                                           Gtk.MessageType.Error, ButtonsType.Ok,
                                                           msg,
                                                           desc);

                md.Run();
                md.Destroy();
                return;
            }

            Photo photo = (Photo)Item.Current;

            try {
                Pixbuf original_pixbuf = photo_view.CompletePixbuf();
                if (original_pixbuf == null)
                {
                    return;
                }

                Pixbuf edited;
                if (redeye)
                {
                    Gdk.Rectangle area = new Gdk.Rectangle(x, y, width, height);
                    edited = PixbufUtils.RemoveRedeye(original_pixbuf,
                                                      area,
                                                      (int)Preferences.Get(Preferences.EDIT_REDEYE_THRESHOLD));
                }
                else             // Crop (I told you it was ugly)
                {
                    edited = new Pixbuf(original_pixbuf.Colorspace,
                                        original_pixbuf.HasAlpha, original_pixbuf.BitsPerSample,
                                        width, height);

                    original_pixbuf.CopyArea(x, y, width, height, edited, 0, 0);
                }

                bool create_version = photo.DefaultVersionId == Photo.OriginalVersionId;
                photo.SaveVersion(edited, create_version);
                ((PhotoQuery)query).Commit(Item.Index);

                // FIXME the fact that the selection doesn't go away is a bug in ImageView, it should
                // be fixed there.
                photo_view.Pixbuf = edited;
                original_pixbuf.Dispose();
                photo_view.UnsetSelection();

                photo_view.Fit = true;

                if (PhotoChanged != null)
                {
                    PhotoChanged(this);
                }
            } catch (System.Exception e) {
                ShowError(e, photo);
            }
        }
예제 #8
0
        // FIXME Cache the GCs?
        protected virtual void DrawPhoto(int cell_num, Rectangle cell_area, Rectangle expose_area, bool selected, bool focussed)
        {
            if (!cell_area.Intersect(expose_area, out expose_area))
            {
                return;
            }

            IPhoto photo = Collection [cell_num];

            FSpot.PixbufCache.CacheEntry entry = Cache.Lookup(photo.DefaultVersion.Uri);
            if (entry == null)
            {
                Cache.Request(photo.DefaultVersion.Uri, cell_num, ThumbnailWidth, ThumbnailHeight);
            }
            else
            {
                entry.Data = cell_num;
            }

            StateType cell_state = selected ? (HasFocus ? StateType.Selected : StateType.Active) : State;

            if (cell_state != State)
            {
                Style.PaintBox(Style, BinWindow, cell_state,
                               ShadowType.Out, expose_area, this, "IconView",
                               cell_area.X, cell_area.Y,
                               cell_area.Width - 1, cell_area.Height - 1);
            }

            Gdk.Rectangle focus = Gdk.Rectangle.Inflate(cell_area, -3, -3);

            if (HasFocus && focussed)
            {
                Style.PaintFocus(Style, BinWindow,
                                 cell_state, expose_area,
                                 this, null,
                                 focus.X, focus.Y,
                                 focus.Width, focus.Height);
            }

            Gdk.Rectangle region       = Gdk.Rectangle.Zero;
            Gdk.Rectangle image_bounds = Gdk.Rectangle.Inflate(cell_area, -CELL_BORDER_WIDTH, -CELL_BORDER_WIDTH);
            int           expansion    = ThrobExpansion(cell_num, selected);

            Gdk.Pixbuf thumbnail = null;
            if (entry != null)
            {
                thumbnail = entry.ShallowCopyPixbuf();
            }

            Gdk.Rectangle draw = Gdk.Rectangle.Zero;
            if (Gdk.Rectangle.Inflate(image_bounds, expansion + 1, expansion + 1).Intersect(expose_area, out image_bounds) && thumbnail != null)
            {
                PixbufUtils.Fit(thumbnail, ThumbnailWidth, ThumbnailHeight,
                                true, out region.Width, out region.Height);

                region.X = (int)(cell_area.X + (cell_area.Width - region.Width) / 2);
                region.Y = (int)cell_area.Y + ThumbnailHeight - region.Height + CELL_BORDER_WIDTH;

                if (Math.Abs(region.Width - thumbnail.Width) > 1 &&
                    Math.Abs(region.Height - thumbnail.Height) > 1)
                {
                    Cache.Reload(entry, cell_num, thumbnail.Width, thumbnail.Height);
                }

                region = Gdk.Rectangle.Inflate(region, expansion, expansion);
                Pixbuf temp_thumbnail;
                region.Width  = System.Math.Max(1, region.Width);
                region.Height = System.Math.Max(1, region.Height);

                if (Math.Abs(region.Width - thumbnail.Width) > 1 &&
                    Math.Abs(region.Height - thumbnail.Height) > 1)
                {
                    if (region.Width < thumbnail.Width && region.Height < thumbnail.Height)
                    {
                        /*
                         * temp_thumbnail = PixbufUtils.ScaleDown (thumbnail,
                         *      region.Width, region.Height);
                         */
                        temp_thumbnail = thumbnail.ScaleSimple(region.Width, region.Height,
                                                               InterpType.Bilinear);


                        lock (entry) {
                            if (entry.Reload && expansion == 0 && !entry.IsDisposed)
                            {
                                entry.SetPixbufExtended(temp_thumbnail.ShallowCopy(), false);
                                entry.Reload = true;
                            }
                        }
                    }
                    else
                    {
                        temp_thumbnail = thumbnail.ScaleSimple(region.Width, region.Height,
                                                               InterpType.Bilinear);
                    }
                }
                else
                {
                    temp_thumbnail = thumbnail;
                }

                // FIXME There seems to be a rounding issue between the
                // scaled thumbnail sizes, we avoid this for now by using
                // the actual thumnail sizes here.
                region.Width  = temp_thumbnail.Width;
                region.Height = temp_thumbnail.Height;

                draw = Gdk.Rectangle.Inflate(region, 1, 1);

                if (!temp_thumbnail.HasAlpha)
                {
                    Style.PaintShadow(Style, BinWindow, cell_state,
                                      ShadowType.Out, expose_area, this,
                                      "IconView",
                                      draw.X, draw.Y,
                                      draw.Width, draw.Height);
                }

                if (region.Intersect(expose_area, out draw))
                {
                    Cms.Profile screen_profile;
                    if (FSpot.ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
                    {
                        Pixbuf t = temp_thumbnail.Copy();
                        temp_thumbnail.Dispose();
                        temp_thumbnail = t;
                        FSpot.ColorManagement.ApplyProfile(temp_thumbnail, screen_profile);
                    }
                    temp_thumbnail.RenderToDrawable(BinWindow, Style.WhiteGC,
                                                    draw.X - region.X,
                                                    draw.Y - region.Y,
                                                    draw.X, draw.Y,
                                                    draw.Width, draw.Height,
                                                    RgbDither.None,
                                                    draw.X, draw.Y);
                }

                if (temp_thumbnail != thumbnail)
                {
                    temp_thumbnail.Dispose();
                }
            }

            if (thumbnail != null)
            {
                thumbnail.Dispose();
            }

            // Render Decorations
            if (DisplayRatings && region.X == draw.X && region.X != 0)
            {
                rating_renderer.Render(BinWindow, this, region, expose_area, cell_state, photo);
            }

            // Render Captions
            Rectangle caption_area = Rectangle.Zero;

            caption_area.Y     = cell_area.Y + CELL_BORDER_WIDTH + ThumbnailHeight + CAPTION_PADDING;
            caption_area.X     = cell_area.X + CELL_BORDER_WIDTH;
            caption_area.Width = cell_area.Width - 2 * CELL_BORDER_WIDTH;

            if (DisplayDates)
            {
                caption_area.Height = date_renderer.GetHeight(this, ThumbnailWidth);
                date_renderer.Render(BinWindow, this, caption_area, expose_area, cell_state, photo);

                caption_area.Y += caption_area.Height;
            }

            if (DisplayFilenames)
            {
                caption_area.Height = filename_renderer.GetHeight(this, ThumbnailWidth);
                filename_renderer.Render(BinWindow, this, caption_area, expose_area, cell_state, photo);

                caption_area.Y += caption_area.Height;
            }

            if (DisplayTags)
            {
                caption_area.Height = tag_renderer.GetHeight(this, ThumbnailWidth);
                tag_renderer.Render(BinWindow, this, caption_area, expose_area, cell_state, photo);

                caption_area.Y += caption_area.Height;
            }
        }
예제 #9
0
 void HandleEditableTagSelected(Tag tag)
 {
     options.EditableTag   = tag;
     tag_edit_button.Label = tag.Name;
     tag_edit_button.Image = tag.Icon != null ? new Gtk.Image(PixbufUtils.ScaleDown(tag.Icon, 16, 16)) : null;
 }
예제 #10
0
        public void Load(Uri uri)
        {
            this.uri = uri;

            delay.Stop();

            if (!done_reading)
            {
                Close();
            }

            done_reading  = false;
            area_prepared = false;
            damage        = Gdk.Rectangle.Zero;

            using (ImageFile img = ImageFile.Create(uri)) {
                orientation = Accelerometer.GetViewOrientation(img.Orientation);

                try {
                    PixbufOrientation thumb_orientation = Accelerometer.GetViewOrientation(PixbufOrientation.TopLeft);
                    thumb = new Gdk.Pixbuf(ThumbnailGenerator.ThumbnailPath(uri));
                    thumb = PixbufUtils.TransformOrientation(thumb, thumb_orientation);
                } catch (System.Exception e) {
                    //FSpot.ThumbnailGenerator.Default.Request (uri.ToString (), 0, 256, 256);
                    if (!(e is GLib.GException))
                    {
                        System.Console.WriteLine(e.ToString());
                    }
                }

                System.IO.Stream nstream = img.PixbufStream();
                if (nstream == null)
                {
                    FileLoad(img);
                    return;
                }
                else
                {
                    stream = new StreamWrapper(nstream);
                }

                loader = new Gdk.PixbufLoader();
                loader.AreaPrepared += ap;
                loader.AreaUpdated  += au;
                loader.Closed       += ev;

                if (AreaPrepared != null && thumb != null)
                {
                    pixbuf = thumb;
                    AreaPrepared(this, new AreaPreparedArgs(true));
                }

                ThumbnailGenerator.Default.PushBlock();
                //AsyncIORead (null);
                if (nstream is IOChannel)
                {
                    ((IOChannel)nstream).DataReady += IOChannelRead;
                }
                else
                {
                    delay.Start();
                }
            }
        }
예제 #11
0
        public static void Main(string [] args)
        {
            bool    empty   = false;
            Program program = null;
            ICore   control = null;

            SetProcessName(Defines.PACKAGE);

            try {
                FSpotOptions options = new FSpotOptions();
                options.ProcessArgs(args);

                if (!options.Validate())
                {
                    options.DoHelp();
                    return;
                }

                if (options.basedir != null)
                {
                    FSpot.Global.BaseDirectory = options.basedir;
                    System.Console.WriteLine("BaseDirectory is now {0}", FSpot.Global.BaseDirectory);
                }

                if (options.photodir != null)
                {
                    FSpot.Global.PhotoDirectory = System.IO.Path.GetFullPath(options.photodir);
                    System.Console.WriteLine("PhotoDirectory is now {0}", FSpot.Global.PhotoDirectory);
                }

                if (options.slideshow)
                {
                    Catalog.Init("f-spot", Defines.LOCALE_DIR);

                    program = new Program(Defines.PACKAGE,
                                          Defines.VERSION,
                                          Modules.UI, args);
                    Core core = new Core();
                    core.ShowSlides(null);
                    program.Run();
                    System.Console.WriteLine("done");
                    return;
                }

                try {
                    NDesk.DBus.BusG.Init();
                } catch (Exception e) {
                    throw new ApplicationException("F-Spot cannot find the Dbus session bus.  Make sure dbus is configured properly or start a new session for f-spot using \"dbus-launch f-spot\"", e);
                }

                /*
                 * FIXME we need to inialize gobject before making the dbus calls, we'll go
                 * ahead and do it like this for now.
                 */
                program = new Program(Defines.PACKAGE,
                                      Defines.VERSION,
                                      Modules.UI, args);

                Console.WriteLine("Initializing Mono.Addins");
                Mono.Addins.AddinManager.Initialize(FSpot.Global.BaseDirectory);
                Mono.Addins.AddinManager.Registry.Update(null);

                bool create = true;
                while (control == null)
                {
                    try {
                        control = Core.FindInstance();
                        System.Console.WriteLine("Found active FSpot server: {0}", control);
                        program = null;
                    } catch (System.Exception) {
                        if (!options.shutdown)
                        {
                            System.Console.WriteLine("Starting new FSpot server");
                        }
                    }

                    Core core = null;
                    try {
                        if (control == null && create)
                        {
                            create = false;
                            Gnome.Vfs.Vfs.Initialize();
                            StockIcons.Initialize();

                            Catalog.Init("f-spot", Defines.LOCALE_DIR);
                            Gtk.Window.DefaultIconList = new Gdk.Pixbuf [] { PixbufUtils.LoadFromAssembly("f-spot-16.png"),
                                                                             PixbufUtils.LoadFromAssembly("f-spot-22.png"),
                                                                             PixbufUtils.LoadFromAssembly("f-spot-32.png"),
                                                                             PixbufUtils.LoadFromAssembly("f-spot-48.png") };
                            core = new Core(options.view);
                            core.RegisterServer();

                            // FIXME: Error checking is non-existant here...

                            empty   = options.view || Core.Database.Empty;
                            control = core;
                        }
                    } catch (System.Exception e) {
                        System.Console.WriteLine("XXXXX{1}{0}{1}XXXXX", e, Environment.NewLine);
                        control = null;

                        if (core != null)
                        {
                            core.UnregisterServer();
                        }
                    }
                    if (control == null)
                    {
                        System.Console.WriteLine("Can't get a connection to the dbus. Trying again...");
                    }
                }


                UriList list = new UriList();

                if (options.shutdown)
                {
                    try {
                        control.Shutdown();
                    } catch (System.Exception) {
                        // trap errors
                    }
                    System.Environment.Exit(0);
                }

                if (options.import != null)
                {
                    control.Import(options.import);
                }

                if (options.view)
                {
                    foreach (string s in options.Uris)
                    {
                        list.AddUnknown(s);
                    }
                    if (list.Count > 0)
                    {
                        control.View(list.ToString());
                    }
                }

                if (empty && options.import == null && !options.view)
                {
                    control.Import(null);
                }

                if (options.import != null || !options.view)
                {
                    control.Organize();
                    Gdk.Global.NotifyStartupComplete();
                }

                if (program != null)
                {
                    program.Run();
                }

                System.Console.WriteLine("exiting");
            } catch (System.Exception e) {
                Console.Error.WriteLine(e);
                Gtk.Application.Init();
                ExceptionDialog dlg = new ExceptionDialog(e);
                dlg.Run();
                dlg.Destroy();
                System.Environment.Exit(1);
            }
        }
        private void Render()
        {
            double page_width, page_height;

            print_job.GetPageSize(out page_width, out page_height);
            Gnome.PrintContext ctx = print_job.Context;

            ArrayList exceptions = new ArrayList();

            foreach (Photo photo in photos)
            {
                Gdk.Pixbuf image = null;
                try {
                    image = FSpot.PhotoLoader.Load(photo);

                    if (image == null)
                    {
                        throw new System.Exception("Error loading picture");
                    }
                } catch (Exception e) {
                    exceptions.Add(e);
                    continue;
                }

                Gdk.Pixbuf flat = PixbufUtils.Flatten(image);
                if (flat != null)
                {
                    image.Dispose();
                    image = flat;
                }

                Gnome.Print.Beginpage(ctx, "F-Spot" + photo.DefaultVersionUri.ToString());

                bool   rotate = false;
                double width  = page_width;
                double height = page_height;
                if (image.Width > image.Height)
                {
                    rotate = true;
                    width  = page_height;
                    height = page_width;
                }

                double scale = System.Math.Min(width / image.Width,
                                               height / image.Height);

                Gnome.Print.Gsave(ctx);

                if (rotate)
                {
                    Gnome.Print.Rotate(ctx, 90);
                    Gnome.Print.Translate(ctx, 0, -page_width);
                }

                Gnome.Print.Translate(ctx,
                                      (width - image.Width * scale) / 2.0,
                                      (height - image.Height * scale) / 2.0);

                Gnome.Print.Scale(ctx, image.Width * scale, image.Height * scale);
                Gnome.Print.Pixbuf(ctx, image);
                Gnome.Print.Grestore(ctx);

                Gnome.Print.Showpage(ctx);
                image.Dispose();
            }

            print_job.Close();

            if (exceptions.Count != 0)
            {
                //FIXME string freeze the message here is not
                //really appropriate to the problem.
                Dialog md = new EditExceptionDialog(print_dialog,
                                                    (Exception [])exceptions.ToArray(typeof(Exception)));
                md.Run();
                md.Destroy();
            }
        }