private void HandleApply(object sender, EventArgs args)
        {
            BrowsablePointer item   = view.Item;
            EditTarget       target = new EditTarget(item);

            try {
                using (ImageFile img = ImageFile.Create(item.Current.DefaultVersionUri)) {
                    Cairo.Format format = view.CompletePixbuf().HasAlpha ? Cairo.Format.Argb32 : Cairo.Format.Rgb24;

                    MemorySurface dest = new MemorySurface(format,
                                                           info.Bounds.Width,
                                                           info.Bounds.Height);

                    Context ctx = new Context(dest);
                    effect.OnExpose(ctx, info.Bounds);
                    ((IDisposable)ctx).Dispose();

                    string tmp = ImageFile.TempPath(item.Current.DefaultVersionUri.LocalPath);
                    using (Gdk.Pixbuf output = Widgets.CairoUtils.CreatePixbuf(dest)) {
                        using (System.IO.Stream stream = System.IO.File.OpenWrite(tmp)) {
                            img.Save(output, stream);
                        }
                    }

                    dest.Destroy();

                    // FIXME Not this again. I need to imlplement a real version of the transfer
                    // function that shows progress in the main window and allows for all the
                    // goodies we'll need.
                    Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok;
                    result = Gnome.Vfs.Xfer.XferUri(new Gnome.Vfs.Uri(UriList.PathToFileUri(tmp).ToString()),
                                                    new Gnome.Vfs.Uri(target.Uri.ToString()),
                                                    Gnome.Vfs.XferOptions.Default,
                                                    Gnome.Vfs.XferErrorMode.Abort,
                                                    Gnome.Vfs.XferOverwriteMode.Replace,
                                                    delegate {
                        System.Console.Write(".");
                        return(1);
                    });

                    target.Commit();
                }
            } catch (System.Exception e) {
                System.Console.WriteLine(e);
                target.Delete();
                Dialog d = new EditExceptionDialog((Gtk.Window)view.Toplevel, e, view.Item.Current);
                d.Show();
                d.Run();
                d.Destroy();
            }
            Destroy();
        }
		protected override void OnActivated ()
		{
			try {
				RotateOperation op = new RotateOperation (item.Current, direction);
				
				while (op.Step ());
				
				item.Collection.MarkChanged (item.Index, FullInvalidate.Instance);
			} catch (Exception e) {
				Dialog d = new EditExceptionDialog (null, e, item.Current);
				d.Show ();
				d.Run ();
				d.Destroy ();
			}
			   
		}
	public void HandleOpenWith (object sender, Gnome.Vfs.MimeApplication mime_application)
	{
		Photo[] selected = SelectedPhotos ();

		if (selected == null || selected.Length < 1)
			return;

		string header = Catalog.GetPluralString ("Create New Version?", "Create New Versions?", selected.Length); 
		string msg = String.Format (Catalog.GetPluralString (
				"Before launching {1}, should F-Spot create a new version of the selected photo to preserve the original?",
				"Before launching {1}, should F-Spot create new versions of the selected photos to preserve the originals?", selected.Length),
				selected.Length, mime_application.Name);

		// FIXME add cancel button? add help button?
		HigMessageDialog hmd = new HigMessageDialog(GetToplevel (sender), DialogFlags.DestroyWithParent, 
							    MessageType.Question, Gtk.ButtonsType.None,
							    header, msg);

		hmd.AddButton (Gtk.Stock.No, Gtk.ResponseType.No, false);
		//hmd.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, false);
		hmd.AddButton (Gtk.Stock.Yes, Gtk.ResponseType.Yes, true);

		Gtk.ResponseType response = Gtk.ResponseType.Cancel;

		try {
			response = (Gtk.ResponseType) hmd.Run();
		} finally {
			hmd.Destroy ();
		}

		if (response == Gtk.ResponseType.Cancel)
			return;

		bool create_new_versions = (response == Gtk.ResponseType.Yes);

		ArrayList errors = new ArrayList ();
		GLib.List uri_list = new GLib.List (typeof (string));
		foreach (Photo photo in selected) {
			try {
				if (create_new_versions) {
					uint version = photo.CreateNamedVersion (mime_application.Name, photo.DefaultVersionId, true);
					photo.DefaultVersionId = version;
				}
			} catch (Exception e) {
				errors.Add (new EditException (photo, e));
			}

			uri_list.Append (photo.DefaultVersionUri.ToString ());
		}

		// FIXME need to clean up the error dialog here.
		if (errors.Count > 0) {
			Dialog md = new EditExceptionDialog (GetToplevel (sender), errors.ToArray (typeof (EditException)) as EditException []);
			md.Run ();
			md.Destroy ();
		}

		if (create_new_versions)
			db.Photos.Commit (selected);

		mime_application.Launch (uri_list);
	}
示例#4
0
文件: MainWindow.cs 项目: mono/f-spot
		public void HandleOpenWith (object sender, ApplicationActivatedEventArgs e)
		{
			GLib.AppInfo application = e.AppInfo;
			Photo[] selected = SelectedPhotos ();

			if (selected == null || selected.Length < 1)
				return;

			string header = Catalog.GetPluralString ("Create New Version?", "Create New Versions?", selected.Length);
			string msg = String.Format (Catalog.GetPluralString (
				             "Before launching {1}, should F-Spot create a new version of the selected photo to preserve the original?",
				             "Before launching {1}, should F-Spot create new versions of the selected photos to preserve the originals?", selected.Length),
				             selected.Length, application.Name);

			// FIXME add cancel button? add help button?
			HigMessageDialog hmd = new HigMessageDialog (GetToplevel (sender), DialogFlags.DestroyWithParent,
				                       MessageType.Question, Gtk.ButtonsType.None,
				                       header, msg);

			hmd.AddButton (Gtk.Stock.No, Gtk.ResponseType.No, false);
			//hmd.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, false);
			hmd.AddButton (Gtk.Stock.Yes, Gtk.ResponseType.Yes, true);

			bool support_xcf = false;
			;
			if (application.Id == "gimp.desktop")
				foreach (PixbufFormat format in Gdk.Pixbuf.Formats.Where(format => format.Name == "xcf"))
					support_xcf = true;

			//This allows creating a version with a .xcf extension.
			//There's no need to convert the file to xcf file format, gimp will take care of this
			if (support_xcf) {
				CheckButton cb = new CheckButton (Catalog.GetString ("XCF version"));
				cb.Active = Preferences.Get<bool> (Preferences.EDIT_CREATE_XCF_VERSION);
				hmd.VBox.Add (cb);
				cb.Toggled += (s, ea) => Preferences.Set (Preferences.EDIT_CREATE_XCF_VERSION, (s as CheckButton).Active);
				cb.Show ();
			}

			Gtk.ResponseType response = Gtk.ResponseType.Cancel;

			try {
				response = (Gtk.ResponseType)hmd.Run ();
			} finally {
				hmd.Destroy ();
			}

			bool create_xcf = false;
			if (support_xcf)
				create_xcf = Preferences.Get<bool> (Preferences.EDIT_CREATE_XCF_VERSION);

			Log.DebugFormat ("XCF ? {0}", create_xcf);

			if (response == Gtk.ResponseType.Cancel)
				return;

			bool create_new_versions = (response == Gtk.ResponseType.Yes);

			List<EditException> errors = new List<EditException> ();
			GLib.List uri_list = new GLib.List (typeof(string));
			foreach (Photo photo in selected) {
				try {
					if (create_new_versions) {
						uint version = photo.CreateNamedVersion (application.Name, create_xcf ? ".xcf" : null, photo.DefaultVersionId, true);
						photo.DefaultVersionId = version;
					}
				} catch (Exception ex) {
					errors.Add (new EditException (photo, ex));
				}

				uri_list.Append (photo.DefaultVersion.Uri.ToString ());
			}

			// FIXME need to clean up the error dialog here.
			if (errors.Count > 0) {
				Dialog md = new EditExceptionDialog (GetToplevel (sender), errors.ToArray ());
				md.Run ();
				md.Destroy ();
			}

			if (create_new_versions)
				Database.Photos.Commit (selected);

			try {
				application.LaunchUris (uri_list, null);
			} catch (Exception) {
				Log.ErrorFormat ("Failed to lauch {0}", application.Name);
			}
		}
		private void HandleApply (object sender, EventArgs args)
		{
			BrowsablePointer item = view.Item;
			EditTarget target = new EditTarget (item);
			try { 
				using (ImageFile img = ImageFile.Create (item.Current.DefaultVersionUri)) {

					Cairo.Format format = view.CompletePixbuf ().HasAlpha ? Cairo.Format.Argb32 : Cairo.Format.Rgb24;

					MemorySurface dest = new MemorySurface (format,
										info.Bounds.Width,
										info.Bounds.Height);

					Context ctx = new Context (dest);
					effect.OnExpose (ctx, info.Bounds);
					((IDisposable)ctx).Dispose ();

					string tmp = ImageFile.TempPath (item.Current.DefaultVersionUri.LocalPath);
					using (Gdk.Pixbuf output = Widgets.CairoUtils.CreatePixbuf (dest)) {
						using (System.IO.Stream stream = System.IO.File.OpenWrite (tmp)) {
							img.Save (output, stream);
						
						}
					}

					dest.Destroy ();

					// FIXME Not this again. I need to imlplement a real version of the transfer
					// function that shows progress in the main window and allows for all the
					// goodies we'll need.
					Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok;
					result = Gnome.Vfs.Xfer.XferUri (new Gnome.Vfs.Uri (UriList.PathToFileUri (tmp).ToString ()),
									 new Gnome.Vfs.Uri (target.Uri.ToString ()),
									 Gnome.Vfs.XferOptions.Default,
									 Gnome.Vfs.XferErrorMode.Abort, 
									 Gnome.Vfs.XferOverwriteMode.Replace, 
									 delegate {
										 System.Console.Write (".");
										 return 1;
									 });

					target.Commit ();
				}
			} catch (System.Exception e) {
				System.Console.WriteLine (e);
				target.Delete ();
				Dialog d = new EditExceptionDialog ((Gtk.Window) view.Toplevel, e, view.Item.Current);
				d.Show ();
				d.Run ();
				d.Destroy ();
			}
			Destroy ();
		}