예제 #1
0
        public override void Run(object o, EventArgs e)
        {
            ProgressDialog pdialog = new ProgressDialog(Catalog.GetString ("Developing photos"),
                                                        ProgressDialog.CancelButtonType.Cancel,
                                                        App.Instance.Organizer.SelectedPhotos ().Length,
                                                        App.Instance.Organizer.Window);
            Log.Information ("Executing DevelopInUFRaw extension in batch mode");

            foreach (Photo p in App.Instance.Organizer.SelectedPhotos ()) {
                bool cancelled = pdialog.Update(String.Format(Catalog.GetString ("Developing {0}"), p.Name));
                if (cancelled) {
                    break;
                }

                DevelopPhoto (p);
            }
            pdialog.Destroy();
        }
        void zip()
        {
            System.Uri dest = new System.Uri (uri_chooser.Uri);
            Crc32 crc = new Crc32 ();
            string filedest = dest.LocalPath + "/" + filename.Text;
            Log.DebugFormat ("Creating zip file {0}", filedest);
            ZipOutputStream s = new ZipOutputStream (File.Create(filedest));
            if (scale_check.Active)
                Log.DebugFormat ("Scaling to {0}", scale_size.ValueAsInt);

            ProgressDialog progress_dialog = new ProgressDialog (Catalog.GetString ("Exporting files"),
                                  ProgressDialog.CancelButtonType.Stop,
                                  photos.Length, zipdiag);

            //Pack up
            for (int i = 0; i < photos.Length; i ++) {
                if (progress_dialog.Update (String.Format (Catalog.GetString ("Preparing photo \"{0}\""), photos[i].Name))) {
                    progress_dialog.Destroy ();
                    return;
                }
                string f = null;
                // FIXME: embed in a try/catch
                if (scale_check.Active) {
                    FilterSet filters = new FilterSet ();
                    filters.Add (new JpegFilter ());
                    filters.Add (new ResizeFilter ((uint) scale_size.ValueAsInt));
                    FilterRequest freq = new FilterRequest (photos [i].DefaultVersion.Uri);
                    filters.Convert (freq);
                    f = freq.Current.LocalPath;
                } else {
                    f = photos [i].DefaultVersion.Uri.LocalPath;
                }
                FileStream fs = File.OpenRead (f);

                byte [] buffer = new byte [fs.Length];
                fs.Read (buffer, 0, buffer.Length);
                ZipEntry entry = new ZipEntry (System.IO.Path.GetFileName (photos [i].DefaultVersion.Uri.LocalPath));

                entry.DateTime = DateTime.Now;

                entry.Size = fs.Length;
                fs.Close ();

                crc.Reset ();
                crc.Update (buffer);

                entry.Crc = crc.Value;

                s.PutNextEntry (entry);

                s.Write (buffer, 0, buffer.Length);
            }
            s.Finish ();
            s.Close ();
            if (progress_dialog != null)
                progress_dialog.Destroy ();
        }
예제 #3
0
        void create_mosaics()
        {
            //Prepare the query
            Db db = App.Instance.Database;
            FSpot.PhotoQuery mini_query = new FSpot.PhotoQuery (db.Photos);
            Photo [] photos;

            if (tags_radio.Active) {
                //Build tag array
                List<Tag> taglist = new List<Tag> ();
                foreach (string tag_name in miniatures_tags.GetTypedTagNames ()) {
                    Tag t = db.Tags.GetTagByName (tag_name);
                    if (t != null)
                        taglist.Add(t);
                }
                mini_query.Terms = FSpot.OrTerm.FromTags (taglist.ToArray ());
                photos = mini_query.Photos;
            } else {
                photos = App.Instance.Organizer.Query.Photos;
            }

            if (photos.Length == 0) {
                //There is no photo for the selected tags! :(
                InfoDialog (Catalog.GetString ("No photos for the selection"),
                        Catalog.GetString ("The tags selected provided no pictures. Please select different tags"),
                        Gtk.MessageType.Error);
                return;
            }

            //Create minis
            ProgressDialog progress_dialog = null;
            progress_dialog = new ProgressDialog (Catalog.GetString ("Creating miniatures"),
                                  ProgressDialog.CancelButtonType.Stop,
                                  photos.Length, metapixel_dialog);

            minidir_tmp = System.IO.Path.GetTempFileName ();
            System.IO.File.Delete (minidir_tmp);
            System.IO.Directory.CreateDirectory (minidir_tmp);
            minidir_tmp += "/";

            //Call MetaPixel to create the minis
            foreach (Photo p in photos) {
                if (progress_dialog.Update (String.Format (Catalog.GetString ("Preparing photo \"{0}\""), p.Name))) {
                    progress_dialog.Destroy ();
                    DeleteTmp ();
                    return;
                }
                //FIXME should switch to retry/skip
                if (!GLib.FileFactory.NewForUri (p.DefaultVersion.Uri).Exists) {
                    Log.WarningFormat (String.Format ("Couldn't access photo {0} while creating miniatures", p.DefaultVersion.Uri.LocalPath));
                    continue;
                }
                //FIXME Check if the picture's format is supproted (jpg, gif)

                FilterSet filters = new FilterSet ();
                filters.Add (new JpegFilter ());
                FilterRequest freq = new FilterRequest (p.DefaultVersion.Uri);
                filters.Convert (freq);

                //We use photo id for minis, instead of photo names, to avoid duplicates
                string minifile = minidir_tmp + p.Id.ToString() + System.IO.Path.GetExtension (p.DefaultVersion.Uri.ToString ());
                string prepare_command = String.Format ("--prepare -w {0} -h {1} {2} {3} {4}tables.mxt",
                                    icon_x_size.Text, //Minis width
                                    icon_y_size.Text, //Minis height
                                    GLib.Shell.Quote (freq.Current.LocalPath), //Source image
                                    GLib.Shell.Quote (minifile),  //Dest image
                                    minidir_tmp);  //Table file
                Log.Debug ("Executing: metapixel " + prepare_command);

                System.Diagnostics.Process mp_prep = System.Diagnostics.Process.Start ("metapixel", prepare_command);
                mp_prep.WaitForExit ();
                if (!System.IO.File.Exists (minifile)) {
                    Log.DebugFormat ("No mini? No party! {0}", minifile);
                    continue;
                }

            } //Finished preparing!
            if (progress_dialog != null)
                progress_dialog.Destroy ();

            progress_dialog = null;
            progress_dialog = new ProgressDialog (Catalog.GetString ("Creating photomosaics"),
                                  ProgressDialog.CancelButtonType.Stop,
                                  App.Instance.Organizer.SelectedPhotos ().Length, metapixel_dialog);

            //Now create the mosaics!
            uint error_count = 0;
            foreach (Photo p in App.Instance.Organizer.SelectedPhotos ()) {
                if (progress_dialog.Update (String.Format (Catalog.GetString ("Processing \"{0}\""), p.Name))) {
                    progress_dialog.Destroy ();
                    DeleteTmp ();
                    return;
                }
                //FIXME should switch to retry/skip
                if (!GLib.FileFactory.NewForUri (p.DefaultVersion.Uri).Exists) {
                    Log.WarningFormat (String.Format ("Couldn't access photo {0} while creating mosaics", p.DefaultVersion.Uri.LocalPath));
                    error_count ++;
                    continue;
                }

                //FIXME Check if the picture's format is supproted (jpg, gif)

                FilterSet filters = new FilterSet ();
                filters.Add (new JpegFilter ());
                FilterRequest freq = new FilterRequest (p.DefaultVersion.Uri);
                filters.Convert (freq);

                string name = GetVersionName (p);
                System.Uri mosaic = GetUriForVersionName (p, name);

                string mosaic_command = String.Format ("--metapixel -l {0} {1} {2}",
                                    minidir_tmp,
                                    GLib.Shell.Quote (freq.Current.LocalPath),
                                    GLib.Shell.Quote (mosaic.LocalPath));
                Log.Debug ("Executing: metapixel " + mosaic_command);
                System.Diagnostics.Process mp_exe = System.Diagnostics.Process.Start ("metapixel", mosaic_command);
                mp_exe.WaitForExit ();
                if (!GLib.FileFactory.NewForUri (mosaic).Exists) {
                    Log.Warning ("Error in processing image " + p.Name);
                    error_count ++;
                    continue;
                }

                p.DefaultVersionId = p.AddVersion (mosaic, name, true);
                p.Changes.DataChanged = true;
                Core.Database.Photos.Commit (p);

            } //Finished creating mosaics
            if (progress_dialog != null)
                progress_dialog.Destroy ();

            string final_message = "Your mosaics have been generated as new versions of the pictures you selected";
            if (error_count > 0)
                final_message += String.Format (".\n{0} images out of {1} had errors",
                            error_count, App.Instance.Organizer.SelectedPhotos ().Length);
            InfoDialog (Catalog.GetString ("PhotoMosaics generated!"),
                    Catalog.GetString (final_message),
                    (error_count == 0 ? Gtk.MessageType.Info : Gtk.MessageType.Warning));
            DeleteTmp ();
        }
		private void GetPreviews ()
		{
			lock (camera) {
				ProgressDialog pdialog = new ProgressDialog (Catalog.GetString ("Downloading Previews"), 
									     ProgressDialog.CancelButtonType.Cancel, 
									     camera.FileList.Count, 
									     this.Dialog);
				
				int index = 0;
				bool load_thumb = true;
				System.Collections.ArrayList sfiles = camera.FileList;
				sfiles.Sort ();
				foreach (GPhotoCameraFile file in sfiles) {
					string msg = String.Format (Catalog.GetString ("Downloading Preview of {0}"), 
								    file.FileName);
					
					
					
					if (load_thumb && pdialog.Update (msg)) {
						load_thumb = false;
						pdialog.Hide ();
					}
					
					Pixbuf scale = null;
					if (load_thumb) {
						Pixbuf thumbscale = camera.GetPreviewPixbuf (file);
						if (thumbscale != null) {
							scale = PixbufUtils.ScaleToMaxSize (thumbscale, 64,64);
							thumbscale.Dispose ();
						}
					}
					
					preview_list_store.AppendValues (file.Directory, file.FileName, scale, index);
					index++;
				}
				
				file_tree.Selection.SelectAll ();
				pdialog.Destroy ();
			}
		}
예제 #5
0
파일: SendEmail.cs 프로젝트: GNOME/f-spot
		private void HandleResponse (object sender, Gtk.ResponseArgs args)
		{
			int size = 0;
			bool UserCancelled = false;

			// Lets remove the mail "create mail" dialog
			Destroy();

			if (args.ResponseId != Gtk.ResponseType.Ok) {
				return;
			}
			ProgressDialog progress_dialog = null;

			progress_dialog = new ProgressDialog (Catalog.GetString ("Preparing email"),
												ProgressDialog.CancelButtonType.Stop,
												selection.Count,
												parent_window);

			size = GetScaleSize(); // Which size should we scale to. 0 --> Original

			// evaluate mailto command and define attachment args for cli
			System.Text.StringBuilder attach_arg = new System.Text.StringBuilder ();
			switch (Preferences.Get<string> (Preferences.GNOME_MAILTO_COMMAND)) {
			case "thunderbird %s":
			case "mozilla-thunderbird %s":
			case "seamonkey -mail -compose %s":
			case "icedove %s":
				attach_arg.Append(",");
				break;
			case "kmail %s":
				attach_arg.Append(" --attach ");
				break;
			default://evolution falls into default, since it supports mailto uri correctly
				attach_arg.Append("&attach=");
				break;
			}

			// Create a tmp directory.
			tmp_mail_dir = System.IO.Path.GetTempFileName ();	// Create a tmp file
			System.IO.File.Delete (tmp_mail_dir);			// Delete above tmp file
			System.IO.Directory.CreateDirectory (tmp_mail_dir);	// Create a directory with above tmp name

			System.Text.StringBuilder mail_attach = new System.Text.StringBuilder ();

			FilterSet filters = new FilterSet ();

			if (size != 0)
				filters.Add (new ResizeFilter ((uint) size));
			filters.Add (new UniqueNameFilter (new SafeUri (tmp_mail_dir)));


			for (int i = 0; i < selection.Count; i++) {
				var photo = selection [i];
				if ( (photo != null) && (!UserCancelled) ) {

					if (progress_dialog != null)
						UserCancelled = progress_dialog.Update (String.Format
							(Catalog.GetString ("Exporting picture \"{0}\""), photo.Name));

					if (UserCancelled)
						break;

					try {
						// Prepare a tmp_mail file name
						FilterRequest request = new FilterRequest (photo.DefaultVersion.Uri);

						filters.Convert (request);
						request.Preserve(request.Current);

						mail_attach.Append(((i == 0 && attach_arg.ToString () == ",") ? "" : attach_arg.ToString()) + request.Current.ToString ());
					} catch (Exception e) {
						Hyena.Log.ErrorFormat ("Error preparing {0}: {1}", selection[i].Name, e.Message);
						HigMessageDialog md = new HigMessageDialog (parent_window,
											    DialogFlags.DestroyWithParent,
											    MessageType.Error,
											    ButtonsType.Close,
											    Catalog.GetString("Error processing image"),
											    String.Format(Catalog.GetString("An error occured while processing \"{0}\": {1}"), selection[i].Name, e.Message));
						md.Run();
						md.Destroy();
						UserCancelled = true;
					}
				}
			} // foreach

			if (progress_dialog != null)
				progress_dialog.Destroy (); // No need to keep this window

		    if (UserCancelled)
                return;

		    // Send the mail :)
		    string mail_subject = Catalog.GetString("My Photos");
		    switch (Preferences.Get<string> (Preferences.GNOME_MAILTO_COMMAND)) {
		            // openSuSE
		        case "thunderbird %s":
		            System.Diagnostics.Process.Start("thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
		            break;
		        case "icedove %s":
		            System.Diagnostics.Process.Start("icedove", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
		            break;
		        case "mozilla-thunderbird %s":
		            System.Diagnostics.Process.Start("mozilla-thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
		            break;
		        case "seamonkey -mail -compose %s":
		            System.Diagnostics.Process.Start("seamonkey", " -mail -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
		            break;
		        case "kmail %s":
		            System.Diagnostics.Process.Start("kmail", "  --composer --subject \"" + mail_subject + "\"" + mail_attach);
		            break;
		        case "evolution %s": //evo doesn't urldecode the subject
		            GtkBeans.Global.ShowUri (Screen, "mailto:?subject=" + mail_subject + mail_attach);
		            break;
		        default:
		            GtkBeans.Global.ShowUri (Screen, "mailto:?subject=" + System.Web.HttpUtility.UrlEncode(mail_subject) + mail_attach);
		            break;
		    }
		}
예제 #6
0
        void CreatePhotoWall()
        {
            dir_tmp = System.IO.Path.GetTempFileName ();
            System.IO.File.Delete (dir_tmp);
            System.IO.Directory.CreateDirectory (dir_tmp);
            dir_tmp += "/";

            //Prepare the pictures
            ProgressDialog progress_dialog = null;
            progress_dialog = new ProgressDialog (Catalog.GetString ("Preparing selected pictures"),
                                  ProgressDialog.CancelButtonType.Stop,
                                  App.Instance.Organizer.SelectedPhotos ().Length, picturetile_dialog);

            FilterSet filters = new FilterSet ();
            filters.Add (new JpegFilter ());
            uint counter = 0;
            List<Tag> all_tags = new List<Tag> ();
            foreach (Photo p in App.Instance.Organizer.SelectedPhotos ()) {
                if (progress_dialog.Update (String.Format (Catalog.GetString ("Processing \"{0}\""), p.Name))) {
                    progress_dialog.Destroy ();
                    DeleteTmp ();
                    return;
                }

                //Store photo tags, to attach them later on import
                foreach (Tag tag in p.Tags) {
                    if (! all_tags.Contains (tag))
                        all_tags.Add (tag);
                }

                //FIXME should switch to retry/skip
                if (!GLib.FileFactory.NewForUri (p.DefaultVersion.Uri).Exists) {
                    Log.WarningFormat ("Couldn't access photo {0} while creating mosaics", p.DefaultVersion.Uri.LocalPath);
                    continue;
                }

                using (FilterRequest freq = new FilterRequest (p.DefaultVersion.Uri)) {
                    filters.Convert (freq);
                    File.Copy (freq.Current.LocalPath, String.Format ("{0}{1}.jpg", dir_tmp, counter ++));
                }
            }
            if (progress_dialog != null)
                progress_dialog.Destroy ();

            photo_tags = all_tags.ToArray ();

            string uniform = "";
            if (uniform_images.Active)
                uniform = "--uniform";
            string output_format = "jpeg";
            if (tiff_radio.Active)
                output_format = "tiff";
            string scale = String.Format (CultureInfo.InvariantCulture, "{0,4}", (double) image_scale.Value / (double) 100);

            destfile_tmp = String.Format ("{0}.{1}", System.IO.Path.GetTempFileName (), output_format);

            //Execute picturetile
            string picturetile_command = String.Format ("--size {0}x{1} " +
                                    "--directory {2} " +
                                    "--scale {3} " +
                                    "--margin {4} " +
                                    "--border {5} " +
                                    "--background {6} " +
                                    "--pages {7} " +
                                    "{8} " +
                                    "{9}",
                                x_max_size.Text,
                                y_max_size.Text,
                                dir_tmp,
                                scale,
                                space_between_images.Text,
                                outside_border.Text,
                                colors [background_color.Active],
                                pages.Text,
                                uniform,
                                destfile_tmp);
            Log.Debug ("Executing: picturetile.pl " + picturetile_command);
            System.Diagnostics.Process pt_exe = System.Diagnostics.Process.Start ("picturetile.pl", picturetile_command);
            pt_exe.WaitForExit ();

            // Handle multiple files generation (pages).
            // If the user wants 2 pages (images), and the output filename is out.jpg, picturetile will create
            // /tmp/out1.jpg and /tmp/out2.jpg.
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo (System.IO.Path.GetDirectoryName (destfile_tmp));
            string filemask = System.IO.Path.GetFileNameWithoutExtension (destfile_tmp) + "*" + System.IO.Path.GetExtension (destfile_tmp);
            FileInfo [] fi = di.GetFiles (filemask);

            // Move generated files to f-spot photodir
            string [] photo_import_list = new string [fi.Length];
            counter = 0;
            foreach (FileInfo f in fi) {
                string orig = System.IO.Path.Combine (f.DirectoryName, f.Name);
                photo_import_list [counter ++] = MoveFile (orig);
            }

            //Add the pic(s) to F-Spot!
            Db db = App.Instance.Database;
            ImportCommand command = new ImportCommand (null);
            if (command.ImportFromPaths (db.Photos, photo_import_list, photo_tags) > 0) {
                InfoDialog (Catalog.GetString ("PhotoWall generated!"),
                        Catalog.GetString ("Your photo wall have been generated and imported in F-Spot. Select the last roll to see it"),
                        Gtk.MessageType.Info);
            } else {
                InfoDialog (Catalog.GetString ("Error importing photowall"),
                        Catalog.GetString ("An error occurred while importing the newly generated photowall to F-Spot"),
                        Gtk.MessageType.Error);
            }
            DeleteTmp ();
        }