Example #1
0
        //FIXME move all this in a standalone class
        void HandleSlideshow(string tagname)
        {
            Tag tag;

            FSpot.Widgets.SlideShow slideshow = null;

            if (!String.IsNullOrEmpty(tagname))
            {
                tag = Database.Tags.GetTagByName(tagname);
            }
            else
            {
                tag = Database.Tags.GetTagById(Preferences.Get <int> (Preferences.SCREENSAVER_TAG));
            }

            IPhoto[] photos;
            if (tag != null)
            {
                photos = Database.Photos.Query(new Tag[] { tag });
            }
            else if (Preferences.Get <int> (Preferences.SCREENSAVER_TAG) == 0)
            {
                photos = Database.Photos.Query(new Tag [] {});
            }
            else
            {
                photos = new IPhoto [0];
            }

            // Minimum delay 1 second; default is 4s
            var delay = Math.Max(1.0, Preferences.Get <double> (Preferences.SCREENSAVER_DELAY));

            var window = new XScreenSaverSlide();

            window.ModifyFg(Gtk.StateType.Normal, new Gdk.Color(127, 127, 127));
            window.ModifyBg(Gtk.StateType.Normal, new Gdk.Color(0, 0, 0));

            if (photos.Length > 0)
            {
                Array.Sort(photos, new IPhotoComparer.RandomSort());
                slideshow = new FSpot.Widgets.SlideShow(new BrowsablePointer(new PhotoList(photos), 0), (uint)(delay * 1000), true);
                window.Add(slideshow);
            }
            else
            {
                Gtk.HBox outer = new Gtk.HBox();
                Gtk.HBox hbox  = new Gtk.HBox();
                Gtk.VBox vbox  = new Gtk.VBox();

                outer.PackStart(new Gtk.Label(String.Empty));
                outer.PackStart(vbox, false, false, 0);
                vbox.PackStart(new Gtk.Label(String.Empty));
                vbox.PackStart(hbox, false, false, 0);
                hbox.PackStart(new Gtk.Image(Gtk.Stock.DialogWarning, Gtk.IconSize.Dialog),
                               false, false, 0);
                outer.PackStart(new Gtk.Label(String.Empty));

                string msg;
                string long_msg;

                if (tag != null)
                {
                    msg      = String.Format(Catalog.GetString("No photos matching {0} found"), tag.Name);
                    long_msg = String.Format(Catalog.GetString("The tag \"{0}\" is not applied to any photos. Try adding\n" +
                                                               "the tag to some photos or selecting a different tag in the\n" +
                                                               "F-Spot preference dialog."), tag.Name);
                }
                else
                {
                    msg      = Catalog.GetString("Search returned no results");
                    long_msg = Catalog.GetString("The tag F-Spot is looking for does not exist. Try\n" +
                                                 "selecting a different tag in the F-Spot preference\n" +
                                                 "dialog.");
                }

                Gtk.Label label = new Gtk.Label(msg);
                hbox.PackStart(label, false, false, 0);

                Gtk.Label long_label = new Gtk.Label(long_msg);
                long_label.Markup = String.Format("<small>{0}</small>", long_msg);

                vbox.PackStart(long_label, false, false, 0);
                vbox.PackStart(new Gtk.Label(String.Empty));

                window.Add(outer);
                label.ModifyFg(Gtk.StateType.Normal, new Gdk.Color(127, 127, 127));
                label.ModifyBg(Gtk.StateType.Normal, new Gdk.Color(0, 0, 0));
                long_label.ModifyFg(Gtk.StateType.Normal, new Gdk.Color(127, 127, 127));
                long_label.ModifyBg(Gtk.StateType.Normal, new Gdk.Color(0, 0, 0));
            }
            window.ShowAll();

            Register(window);
            GLib.Idle.Add(delegate {
                if (slideshow != null)
                {
                    slideshow.Start();
                }
                return(false);
            });
        }
Example #2
0
        void LoadPreference(string key)
        {
            switch (key)
            {
            case Preferences.VIEWER_MAXIMIZED:
                if (Preferences.Get <bool> (key))
                {
                    Window.Maximize();
                }
                else
                {
                    Window.Unmaximize();
                }
                break;

            case Preferences.VIEWER_WIDTH:
            case Preferences.VIEWER_HEIGHT:
                int width, height;
                width  = Preferences.Get <int> (Preferences.VIEWER_WIDTH);
                height = Preferences.Get <int> (Preferences.VIEWER_HEIGHT);

                if (width == 0 || height == 0)
                {
                    break;
                }

                Window.SetDefaultSize(width, height);

                Window.ReshowWithInitialSize();
                break;

            case Preferences.VIEWER_SHOW_TOOLBAR:
                if (toolbar_item.Active != Preferences.Get <bool> (key))
                {
                    toolbar_item.Active = Preferences.Get <bool> (key);
                }

                toolbar_hbox.Visible = Preferences.Get <bool> (key);
                break;

            case Preferences.VIEWER_INTERPOLATION:
                if (Preferences.Get <bool> (key))
                {
                    image_view.Interpolation = Gdk.InterpType.Bilinear;
                }
                else
                {
                    image_view.Interpolation = Gdk.InterpType.Nearest;
                }
                break;

            case Preferences.VIEWER_SHOW_FILENAMES:
                if (filenames_item.Active != Preferences.Get <bool> (key))
                {
                    filenames_item.Active = Preferences.Get <bool> (key);
                }
                break;

            case Preferences.VIEWER_TRANSPARENCY:
                if (Preferences.Get <string> (key) == "CHECK_PATTERN")
                {
                    image_view.CheckPattern = CheckPattern.Dark;
                }
                else if (Preferences.Get <string> (key) == "COLOR")
                {
                    image_view.CheckPattern = new CheckPattern(Preferences.Get <string> (Preferences.VIEWER_TRANS_COLOR));
                }
                else                 // NONE
                {
                    image_view.CheckPattern = new CheckPattern(image_view.Style.BaseColors [(int)Gtk.StateType.Normal]);
                }
                break;

            case Preferences.VIEWER_TRANS_COLOR:
                if (Preferences.Get <string> (Preferences.VIEWER_TRANSPARENCY) == "COLOR")
                {
                    image_view.CheckPattern = new CheckPattern(Preferences.Get <string> (key));
                }
                break;
            }
        }
        public void ProcessImage(int image_num, Filters.FilterSet filter_set)
        {
            IBrowsableItem photo      = collection [image_num];
            string         photo_path = photo.DefaultVersionUri.LocalPath;
            string         path;
            ScaleRequest   req;

            req = requests [0];

            MakeDir(SubdirPath(req.Name));
            path = SubdirPath(req.Name, ImageName(image_num));

            using (Filters.FilterRequest request = new Filters.FilterRequest(photo.DefaultVersionUri)) {
                filter_set.Convert(request);
                if (request.Current.LocalPath == path)
                {
                    request.Preserve(request.Current);
                }
                else
                {
                    File.Copy(request.Current.LocalPath, path, true);
                }

                if (photo != null && photo is Photo && Core.Database != null)
                {
                    Core.Database.Exports.Create((photo as Photo).Id, (photo as Photo).DefaultVersionId,
                                                 ExportStore.FolderExportType,
                                                 // FIXME this is wrong, the final path is the one
                                                 // after the Xfer.
                                                 UriList.PathToFileUriEscaped(path).ToString());
                }

                using (Exif.ExifData data = new Exif.ExifData(photo_path)) {
                    for (int i = 1; i < requests.Length; i++)
                    {
                        req = requests [i];
                        if (scale && req.AvoidScale(size))
                        {
                            continue;
                        }

                        Filters.FilterSet req_set = new Filters.FilterSet();
                        req_set.Add(new Filters.ResizeFilter((uint)Math.Max(req.Width, req.Height)));
                        if ((bool)Preferences.Get(Preferences.EXPORT_FOLDER_SHARPEN))
                        {
                            if (req.Name == "lq")
                            {
                                req_set.Add(new Filters.SharpFilter(0.1, 2, 4));
                            }
                            if (req.Name == "thumbs")
                            {
                                req_set.Add(new Filters.SharpFilter(0.1, 2, 5));
                            }
                        }
                        using (Filters.FilterRequest tmp_req = new Filters.FilterRequest(photo.DefaultVersionUri)) {
                            req_set.Convert(tmp_req);
                            MakeDir(SubdirPath(req.Name));
                            path = SubdirPath(req.Name, ImageName(image_num));
                            System.IO.File.Copy(tmp_req.Current.LocalPath, path, true);
                        }
                    }
                }
            }
        }
        public void Run(IBrowsableCollection selection)
        {
            /*
             * Gnome.Vfs.ModuleCallbackFullAuthentication auth = new Gnome.Vfs.ModuleCallbackFullAuthentication ();
             * auth.Callback += new Gnome.Vfs.ModuleCallbackHandler (HandleAuth);
             * auth.SetDefault ();
             * auth.Push ();
             *
             * Gnome.Vfs.ModuleCallbackAuthentication mauth = new Gnome.Vfs.ModuleCallbackAuthentication ();
             * mauth.Callback += new Gnome.Vfs.ModuleCallbackHandler (HandleAuth);
             * mauth.SetDefault ();
             * mauth.Push ();
             *
             * Gnome.Vfs.ModuleCallbackSaveAuthentication sauth = new Gnome.Vfs.ModuleCallbackSaveAuthentication ();
             * sauth.Callback += new Gnome.Vfs.ModuleCallbackHandler (HandleAuth);
             * sauth.SetDefault ();
             * sauth.Push ();
             *
             * Gnome.Vfs.ModuleCallbackStatusMessage msg = new Gnome.Vfs.ModuleCallbackStatusMessage ();
             * msg.Callback += new Gnome.Vfs.ModuleCallbackHandler (HandleMsg);
             * msg.SetDefault ();
             * msg.Push ();
             */
            this.selection = selection;

            IconView view = (IconView) new IconView(selection);

            view.DisplayDates = false;
            view.DisplayTags  = false;

            Dialog.Modal        = false;
            Dialog.TransientFor = null;

            thumb_scrolledwindow.Add(view);
            HandleSizeActive(null, null);
            name_entry.Text = gallery_name;

            string uri_path = System.IO.Path.Combine(FSpot.Global.HomeDirectory, "Desktop");

            if (!System.IO.Directory.Exists(uri_path))
            {
                uri_path = FSpot.Global.HomeDirectory;
            }

            uri_chooser = new Gtk.FileChooserButton(Catalog.GetString("Select Export Folder"),
                                                    Gtk.FileChooserAction.SelectFolder);

            uri_chooser.LocalOnly = false;

            if (Preferences.Get(Preferences.EXPORT_FOLDER_URI) != null && Preferences.Get(Preferences.EXPORT_FOLDER_URI) as string != String.Empty)
            {
                uri_chooser.SetUri(Preferences.Get(Preferences.EXPORT_FOLDER_URI) as string);
            }
            else
            {
                uri_chooser.SetFilename(uri_path);
            }

            chooser_hbox.PackStart(uri_chooser);

            Dialog.ShowAll();

            //LoadHistory ();
            Dialog.Response += HandleResponse;

            LoadPreference(Preferences.EXPORT_FOLDER_SCALE);
            LoadPreference(Preferences.EXPORT_FOLDER_SIZE);
            LoadPreference(Preferences.EXPORT_FOLDER_OPEN);
            LoadPreference(Preferences.EXPORT_FOLDER_ROTATE);
            LoadPreference(Preferences.EXPORT_FOLDER_METHOD);
        }
        public void Upload()
        {
            // FIXME use mkstemp

            Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok;

            try {
                Dialog.Hide();

                Gnome.Vfs.Uri source = new Gnome.Vfs.Uri(Path.Combine(gallery_path, gallery_name));
                Gnome.Vfs.Uri target = dest.Clone();
                target = target.AppendFileName(source.ExtractShortName());

                if (dest.IsLocal)
                {
                    gallery_path = Gnome.Vfs.Uri.GetLocalPathFromUri(dest.ToString());
                }

                progress_dialog.Message  = Catalog.GetString("Building Gallery");
                progress_dialog.Fraction = 0.0;

                FolderGallery gallery;
                if (static_radio.Active)
                {
                    gallery = new HtmlGallery(selection, gallery_path, gallery_name);
                }
                else if (original_radio.Active)
                {
                    gallery = new OriginalGallery(selection, gallery_path, gallery_name);
                }
                else
                {
                    gallery = new FolderGallery(selection, gallery_path, gallery_name);
                }

                if (scale)
                {
                    System.Console.WriteLine("setting scale to {0}", size);
                    gallery.SetScale(size);
                }
                else
                {
                    System.Console.WriteLine("Exporting full size image");
                }

                if (rotate)
                {
                    System.Console.WriteLine("Exporting rotated image");
                    gallery.SetRotate();
                }

                gallery.Description = description;

                gallery.GenerateLayout();
                Filters.FilterSet filter_set = new Filters.FilterSet();
                if (scale)
                {
                    filter_set.Add(new Filters.ResizeFilter((uint)size));
                }
                else if (rotate)
                {
                    filter_set.Add(new Filters.OrientationFilter());
                }
                filter_set.Add(new Filters.ChmodFilter());
                filter_set.Add(new Filters.UniqueNameFilter(gallery_path));

                for (int photo_index = 0; photo_index < selection.Count; photo_index++)
                {
                    try {
                        progress_dialog.Message  = System.String.Format(Catalog.GetString("Uploading picture \"{0}\""), selection[photo_index].Name);
                        progress_dialog.Fraction = photo_index / (double)selection.Count;
                        gallery.ProcessImage(photo_index, filter_set);
                        progress_dialog.ProgressText = System.String.Format(Catalog.GetString("{0} of {1}"), photo_index, selection.Count);
                    }
                    catch (Exception e) {
                        progress_dialog.Message = String.Format(Catalog.GetString("Error uploading picture \"{0}\" to Gallery:{2}{1}"),
                                                                selection[photo_index].Name, e.Message, Environment.NewLine);
                        progress_dialog.ProgressText = Catalog.GetString("Error");

                        if (progress_dialog.PerformRetrySkip())
                        {
                            photo_index--;
                        }
                    }
                }

                //create the zip tarballs for original
                if (gallery is OriginalGallery && (bool)Preferences.Get(Preferences.EXPORT_FOLDER_INCLUDE_TARBALLS))
                {
                    (gallery as OriginalGallery).CreateZip();
                }

                // we've created the structure, now if the destination was local we are done
                // otherwise we xfer
                if (!dest.IsLocal)
                {
                    Console.WriteLine(target);
                    System.Console.WriteLine("Xfering {0} to {1}", source.ToString(), target.ToString());
                    result = Gnome.Vfs.Xfer.XferUri(source, target,
                                                    Gnome.Vfs.XferOptions.Default,
                                                    Gnome.Vfs.XferErrorMode.Abort,
                                                    Gnome.Vfs.XferOverwriteMode.Replace,
                                                    Progress);
                }

                if (result == Gnome.Vfs.Result.Ok)
                {
                    progress_dialog.Message      = Catalog.GetString("Done Sending Photos");
                    progress_dialog.Fraction     = 1.0;
                    progress_dialog.ProgressText = Catalog.GetString("Transfer Complete");
                    progress_dialog.ButtonLabel  = Gtk.Stock.Ok;
                }
                else
                {
                    progress_dialog.ProgressText = result.ToString();
                    progress_dialog.Message      = Catalog.GetString("Error While Transferring");
                }

                if (open)
                {
                    GnomeUtil.UrlShow(null, target.ToString());
                }

                // Save these settings for next time
                Preferences.Set(Preferences.EXPORT_FOLDER_SCALE, scale);
                Preferences.Set(Preferences.EXPORT_FOLDER_SIZE, size);
                Preferences.Set(Preferences.EXPORT_FOLDER_OPEN, open);
                Preferences.Set(Preferences.EXPORT_FOLDER_ROTATE, rotate);
                Preferences.Set(Preferences.EXPORT_FOLDER_METHOD, static_radio.Active ? "static" : original_radio.Active ? "original" : "folder");
                Preferences.Set(Preferences.EXPORT_FOLDER_URI, uri_chooser.Uri);
            } catch (System.Exception e) {
                // Console.WriteLine (e);
                progress_dialog.Message      = e.ToString();
                progress_dialog.ProgressText = Catalog.GetString("Error Transferring");
            } finally {
                // if the destination isn't local then we want to remove the temp directory we
                // created.
                if (!dest.IsLocal)
                {
                    System.IO.Directory.Delete(gallery_path, true);
                }

                Gtk.Application.Invoke(delegate { Dialog.Destroy(); });
            }
        }
Example #6
0
        static int Main(string [] args)
        {
            args = FixArgs(args);

            ApplicationContext.ApplicationName = "F-Spot";
            ApplicationContext.TrySetProcessName(Defines.PACKAGE);

            Paths.ApplicationName = "f-spot";
            ThreadAssist.InitializeMainThread();
            ThreadAssist.ProxyToMainHandler = RunIdle;

            // Options and Option parsing
            bool shutdown  = false;
            bool view      = false;
            bool slideshow = false;
            bool import    = false;

            GLib.GType.Init();
            Catalog.Init("f-spot", Defines.LOCALE_DIR);

            Global.PhotoUri = new SafeUri(Preferences.Get <string> (Preferences.STORAGE_PATH));

            ApplicationContext.CommandLine = new CommandLineParser(args, 0);

            if (ApplicationContext.CommandLine.ContainsStart("help"))
            {
                ShowHelp();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("version"))
            {
                ShowVersion();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("versions"))
            {
                ShowAssemblyVersions();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("shutdown"))
            {
                Log.Information("Shutting down existing F-Spot server...");
                shutdown = true;
            }

            if (ApplicationContext.CommandLine.Contains("slideshow"))
            {
                Log.Information("Running F-Spot in slideshow mode.");
                slideshow = true;
            }

            if (ApplicationContext.CommandLine.Contains("basedir"))
            {
                string dir = ApplicationContext.CommandLine ["basedir"];

                if (!string.IsNullOrEmpty(dir))
                {
                    Global.BaseDirectory = dir;
                    Log.InformationFormat("BaseDirectory is now {0}", dir);
                }
                else
                {
                    Log.Error("f-spot: -basedir option takes one argument");
                    return(1);
                }
            }

            if (ApplicationContext.CommandLine.Contains("photodir"))
            {
                string dir = ApplicationContext.CommandLine ["photodir"];

                if (!string.IsNullOrEmpty(dir))
                {
                    Global.PhotoUri = new SafeUri(dir);
                    Log.InformationFormat("PhotoDirectory is now {0}", dir);
                }
                else
                {
                    Log.Error("f-spot: -photodir option takes one argument");
                    return(1);
                }
            }

            if (ApplicationContext.CommandLine.Contains("import"))
            {
                import = true;
            }

            if (ApplicationContext.CommandLine.Contains("view"))
            {
                view = true;
            }

            if (ApplicationContext.CommandLine.Contains("debug"))
            {
                Log.Debugging = true;
                // Debug GdkPixbuf critical warnings
                var logFunc = new GLib.LogFunc(GLib.Log.PrintTraceLogFunction);
                GLib.Log.SetLogHandler("GdkPixbuf", GLib.LogLevelFlags.Critical, logFunc);

                // Debug Gtk critical warnings
                GLib.Log.SetLogHandler("Gtk", GLib.LogLevelFlags.Critical, logFunc);

                // Debug GLib critical warnings
                GLib.Log.SetLogHandler("GLib", GLib.LogLevelFlags.Critical, logFunc);

                //Debug GLib-GObject critical warnings
                GLib.Log.SetLogHandler("GLib-GObject", GLib.LogLevelFlags.Critical, logFunc);

                GLib.Log.SetLogHandler("GLib-GIO", GLib.LogLevelFlags.Critical, logFunc);
            }

            // Validate command line options
            if ((import && (view || shutdown || slideshow)) ||
                (view && (shutdown || slideshow)) ||
                (shutdown && slideshow))
            {
                Log.Error("Can't mix -import, -view, -shutdown or -slideshow");
                return(1);
            }

            InitializeAddins();

            // Gtk initialization
            Gtk.Application.Init(Defines.PACKAGE, ref args);
            // Maybe we'll add this at a future date
            //Xwt.Application.InitializeAsGuest (Xwt.ToolkitType.Gtk);

            // init web proxy globally
            Platform.WebProxy.Init();

            if (File.Exists(Preferences.Get <string> (Preferences.GTK_RC)))
            {
                if (File.Exists(Path.Combine(Global.BaseDirectory, "gtkrc")))
                {
                    Gtk.Rc.AddDefaultFile(Path.Combine(Global.BaseDirectory, "gtkrc"));
                }

                Global.DefaultRcFiles = Gtk.Rc.DefaultFiles;
                Gtk.Rc.AddDefaultFile(Preferences.Get <string> (Preferences.GTK_RC));
                Gtk.Rc.ReparseAllForSettings(Gtk.Settings.Default, true);
            }

            try {
                Gtk.Window.DefaultIconList = new Gdk.Pixbuf [] {
                    GtkUtil.TryLoadIcon(Global.IconTheme, "f-spot", 16, 0),
                    GtkUtil.TryLoadIcon(Global.IconTheme, "f-spot", 22, 0),
                    GtkUtil.TryLoadIcon(Global.IconTheme, "f-spot", 32, 0),
                    GtkUtil.TryLoadIcon(Global.IconTheme, "f-spot", 48, 0)
                };
            } catch (Exception ex) {
                Log.Exception("Loading default f-spot icons", ex);
            }

            GLib.ExceptionManager.UnhandledException += exceptionArgs =>
            {
                Console.WriteLine("Unhandeled exception handler:");
                var exception = exceptionArgs.ExceptionObject as Exception;
                if (exception != null)
                {
                    Console.WriteLine("Message: " + exception.Message);
                    Console.WriteLine("Stack trace: " + exception.StackTrace);
                }
                else
                {
                    Console.WriteLine("Unknown exception type: " + exceptionArgs.ExceptionObject.GetType().ToString());
                }
            };

            CleanRoomStartup.Startup(Startup);

            // Running threads are preventing the application from quitting
            // we force it for now until this is fixed
            Environment.Exit(0);
            return(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);
            }
        }
Example #8
0
        protected override void OnDrawPage(Gtk.PrintContext context, int page_nr)
        {
            base.OnDrawPage(context, page_nr);
            Context cr = context.CairoContext;

            int ppx, ppy;

            switch (photos_per_page)
            {
            default:
            case 1: ppx = ppy = 1; break;

            case 2: ppx = 1; ppy = 2; break;

            case 4: ppx = ppy = 2; break;

            case 9: ppx = ppy = 3; break;

            case 12: ppx = 3; ppy = 4; break;

            case 20: ppx = 4; ppy = 5; break;

            case 30: ppx = 5; ppy = 6; break;
            }

            //FIXME: if paper is landscape, swap ppx with ppy

            double w = context.Width / ppx;
            double h = context.Height / ppy;

            // compute picture size
            double mx = (w / 25.4) * context.DpiX, my = (h / 25.4) * context.DpiY;

            for (int x = 0; x <= ppx; x++)
            {
                for (int y = 0; y <= ppy; y++)
                {
                    int p_index = repeat ? page_nr : page_nr * photos_per_page + y * ppx + x;
                    if (crop_marks)
                    {
                        DrawCropMarks(cr, x * w, y * h, w * .1);
                    }
                    if (x == ppx || y == ppy || p_index >= selected_photos.Length)
                    {
                        continue;
                    }
                    using (var img = App.Instance.Container.Resolve <IImageFileFactory> ().Create(selected_photos [p_index].DefaultVersion.Uri)) {
                        Gdk.Pixbuf pixbuf;
                        try {
                            pixbuf = img.Load((int)mx, (int)my);
                            if (pixbuf == null)
                            {
                                Log.Error("Not enough memory for printing " + selected_photos [p_index].DefaultVersion.Uri);
                                continue;
                            }
                            Cms.Profile printer_profile;
                            if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_OUTPUT_PROFILE), out printer_profile))
                            {
                                ColorManagement.ApplyProfile(pixbuf, img.GetProfile(), printer_profile);
                            }
                        } catch (Exception e) {
                            Log.Exception("Unable to load image " + selected_photos [p_index].DefaultVersion.Uri + "\n", e);
                            // If the image is not found load error pixbuf
                            pixbuf = new Gdk.Pixbuf(PixbufUtils.ErrorPixbuf, 0, 0,
                                                    PixbufUtils.ErrorPixbuf.Width,
                                                    PixbufUtils.ErrorPixbuf.Height);
                        }

                        bool rotated = false;
                        if (Math.Sign((double)pixbuf.Width / pixbuf.Height - 1.0) != Math.Sign(w / h - 1.0))
                        {
                            Gdk.Pixbuf d_pixbuf = pixbuf.RotateSimple(Gdk.PixbufRotation.Counterclockwise);
                            pixbuf.Dispose();
                            pixbuf  = d_pixbuf;
                            rotated = true;
                        }

                        DrawImage(cr, pixbuf, x * w, y * h, w, h);

                        string tag_string = "";
                        foreach (Tag t in selected_photos[p_index].Tags)
                        {
                            tag_string = string.Concat(tag_string, t.Name);
                        }

                        // FIXME: Convert this to StringBuilder?
                        var label = string.Format(print_label_format,
                                                  comment,
                                                  selected_photos [p_index].Name,
                                                  selected_photos [p_index].Time.ToLocalTime().ToShortDateString(),
                                                  selected_photos [p_index].Time.ToLocalTime().ToShortTimeString(),
                                                  tag_string,
                                                  selected_photos [p_index].Description);

                        DrawComment(context, (x + 1) * w, (rotated ? y : y + 1) * h, (rotated ? w : h) * .025, label, rotated);

                        pixbuf.Dispose();
                    }
                }
            }
        }
Example #9
0
        public PhotoView(IBrowsableCollection query)
        {
            Query = query;

            commit_delay = new DelayedOperation(1000, new GLib.IdleHandler(CommitPendingChanges));
            Destroyed   += HandleDestroy;

            Name = "ImageContainer";
            Box vbox = new VBox(false, 6);

            Add(vbox);

            background = new EventBox();
            Frame frame = new Frame();

            background.Add(frame);

            frame.ShadowType = ShadowType.In;
            vbox.PackStart(background, true, true, 0);

            inner_vbox = new VBox(false, 2);
            inner_hbox = new HBox(false, 2);

            frame.Add(inner_hbox);

            BrowsablePointer bp = new BrowsablePointer(query, -1);

            View = new PhotoImageView(bp);

            filmstrip             = new Filmstrip(bp);
            filmstrip.ThumbOffset = 1;
            filmstrip.Spacing     = 4;
            filmstrip.ThumbSize   = 75;
            PlaceFilmstrip((Orientation)Preferences.Get <int> (Preferences.FILMSTRIP_ORIENTATION), true);

            View.PhotoChanged += HandlePhotoChanged;

            photo_view_scrolled = new ScrolledWindow(null, null);

            photo_view_scrolled.SetPolicy(PolicyType.Automatic, PolicyType.Automatic);
            photo_view_scrolled.ShadowType = ShadowType.None;
            photo_view_scrolled.Add(View);
            photo_view_scrolled.Child.ButtonPressEvent += HandleButtonPressEvent;
            View.AddEvents((int)EventMask.KeyPressMask);
            inner_vbox.PackStart(photo_view_scrolled, true, true, 0);
            inner_hbox.PackStart(inner_vbox, true, true, 0);

            HBox lower_hbox = new HBox(false, 2);

            //inner_hbox.BorderWidth = 6;

            tag_view = new TagView();
            lower_hbox.PackStart(tag_view, false, true, 0);

            Label comment = new Label(Catalog.GetString("Description:"));

            lower_hbox.PackStart(comment, false, false, 0);
            description_entry = new Entry();
            lower_hbox.PackStart(description_entry, true, true, 0);
            description_entry.Changed += HandleDescriptionChanged;

            rating = new RatingEntry {
                HasFrame             = false,
                AlwaysShowEmptyStars = true
            };
            lower_hbox.PackStart(rating, false, false, 0);
            rating.Changed += HandleRatingChanged;

            SetColors();

            inner_vbox.PackStart(lower_hbox, false, true, 0);

            vbox.ShowAll();

            Realized += (o, e) => SetColors();
            Preferences.SettingChanged += OnPreferencesChanged;
        }