public static string RandomNoteColor() { GLib.List colors = new GLib.List(typeof(string)); colors.Append("#f4ff51"); colors.Append("#88dcd5"); colors.Append("#b3f75f"); colors.Append("#f75f77"); colors.Append("#dc5ff7"); Random random = new Random(); return((string)colors[random.Next(colors.Count)]); }
void LaunchWithFiles(GLib.File app, IEnumerable <GLib.File> files) { AppInfo appinfo = null; if (app != null) { appinfo = GLib.DesktopAppInfo.NewFromFilename(app.Path); } else { if (!files.Any()) { return; } // if we weren't given an app info, query the file for the default handler try { appinfo = files.First().QueryDefaultHandler(null); } catch { // file probably doesnt exist return; } } try { GLib.List launchList; if (!files.Any()) { appinfo.Launch(null, null); // check if the app supports files or Uris } else if (appinfo.SupportsFiles) { launchList = new GLib.List(new GLib.File[] {}, typeof(GLib.File), true, false); foreach (GLib.File f in files) { launchList.Append(f); } appinfo.Launch(launchList, null); launchList.Dispose(); } else if (appinfo.SupportsUris) { launchList = new GLib.List(new string[] {}, typeof(string), true, true); foreach (GLib.File f in files) { // try to use GLib.File.Uri first, if that throws an exception, // catch and use P/Invoke to libdocky. If that's still null, warn & skip the file. try { launchList.Append(f.Uri.ToString()); } catch (UriFormatException) { string uri = f.StringUri(); if (string.IsNullOrEmpty(uri)) { Log <SystemService> .Warn("Failed to retrieve URI for {0}. It will be skipped.", f.Path); continue; } launchList.Append(uri); } } appinfo.LaunchUris(launchList, null); launchList.Dispose(); } else { Log <SystemService> .Error("Error opening files. The application doesn't support files/URIs or wasn't found."); } } catch (GException e) { Log.Notify(string.Format("Error running: {0}", appinfo.Name), Gtk.Stock.DialogWarning, e.Message); Log <SystemService> .Error(e.Message); Log <SystemService> .Info(e.StackTrace); } (appinfo as IDisposable).Dispose(); }
void LaunchWithFiles (GLib.File app, IEnumerable<GLib.File> files) { AppInfo appinfo = null; if (app != null) { appinfo = GLib.DesktopAppInfo.NewFromFilename (app.Path); } else { if (!files.Any ()) return; // if we weren't given an app info, query the file for the default handler try { appinfo = files.First ().QueryDefaultHandler (null); } catch { // file probably doesnt exist return; } } try { GLib.List launchList; if (!files.Any ()) { appinfo.Launch (null, null); // check if the app supports files or Uris } else if (appinfo.SupportsFiles) { launchList = new GLib.List (new GLib.File[] {}, typeof (GLib.File), true, false); foreach (GLib.File f in files) launchList.Append (f); appinfo.Launch (launchList, null); launchList.Dispose (); } else if (appinfo.SupportsUris) { launchList = new GLib.List (new string[] {}, typeof (string), true, true); foreach (GLib.File f in files) { // try to use GLib.File.Uri first, if that throws an exception, // catch and use P/Invoke to libdocky. If that's still null, warn & skip the file. try { launchList.Append (f.Uri.ToString ()); } catch (UriFormatException) { string uri = f.StringUri (); if (string.IsNullOrEmpty (uri)) { Log<SystemService>.Warn ("Failed to retrieve URI for {0}. It will be skipped.", f.Path); continue; } launchList.Append (uri); } } appinfo.LaunchUris (launchList, null); launchList.Dispose (); } else { Log<SystemService>.Error ("Error opening files. The application doesn't support files/URIs or wasn't found."); } } catch (GException e) { Log.Notify (string.Format ("Error running: {0}", appinfo.Name), Gtk.Stock.DialogWarning, e.Message); Log<SystemService>.Error (e.Message); Log<SystemService>.Info (e.StackTrace); } (appinfo as IDisposable).Dispose (); }
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); }
protected void CreateNewVersion() { try { System.Uri original_uri = GetUriForVersionFileName(this.currentphoto, this.currentphoto.DefaultVersion.Uri.LocalPath); System.Uri new_uri = GetUriForVersionFileName(this.currentphoto, new_filename); Console.WriteLine("ok pressed: old: " + this.currentphoto.DefaultVersion.Uri.LocalPath + "; " + original_uri.ToString() + " new: " + new_filename + "; " + new_uri.ToString() + "to open with: "); // check if new version exist and remove foreach (uint id in currentphoto.VersionIds) { if (currentphoto.GetVersion(id).Name == new_version_entry.Text) { this.currentphoto.DeleteVersion(id); } } GLib.File destination = GLib.FileFactory.NewForUri(new_uri); if (destination.Exists) { throw new Exception(String.Format("An object at this uri {0} already exists", new_uri)); } //FIXME. or better, fix the copy api ! GLib.File source = GLib.FileFactory.NewForUri(original_uri); source.Copy(destination, GLib.FileCopyFlags.None, null, null); this.currentphoto.DefaultVersionId = this.currentphoto.AddVersion(new SafeUri(new_uri).GetBaseUri(), new SafeUri(new_uri).GetFilename(), new_version_entry.Text, true); App.Instance.Database.Photos.Commit(this.currentphoto); this.currentphoto.Changes.DataChanged = true;; // run new version with selected application Gtk.TreeIter iter; if (owcb.GetActiveIter(out iter)) { Console.WriteLine((string)owcb.Model.GetValue(iter, 0)); Console.WriteLine((string)owcb.Model.GetValue(iter, 1)); Console.WriteLine((string[])owcb.Model.GetValue(iter, 2)); Console.WriteLine("Getting applications again"); ArrayList union = new ArrayList(); //string[] weekDays = new string[] { "image/jpeg", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; foreach (string mime_type in (string [])owcb.Model.GetValue(iter, 2)) { //foreach (string mime_type in (string []) weekDays) { if (mime_type == null) { continue; } MimeApplication [] apps = Gnome.Vfs.Mime.GetAllApplications(mime_type); foreach (MimeApplication app in apps) { if (!union.Contains(app)) { union.Add(app); } } } foreach (MimeApplication app in union) { if (app.BinaryName.ToString() == (string)owcb.Model.GetValue(iter, 1)) { Console.WriteLine("Winner is " + (string)owcb.Model.GetValue(iter, 1)); // is there a better way to get a GLib.List??? GLib.List uri_list = new GLib.List(typeof(string)); uri_list.Append(new_uri.ToString()); app.Launch(uri_list); } } } } finally { Gtk.Application.Invoke(delegate { dialog.Destroy(); }); } }
protected void CreateNewVersion() { try { System.Uri original_uri = GetUriForVersionFileName (this.currentphoto, this.currentphoto.DefaultVersion.Uri.LocalPath); System.Uri new_uri = GetUriForVersionFileName (this.currentphoto, new_filename); Console.WriteLine ("ok pressed: old: " + this.currentphoto.DefaultVersion.Uri.LocalPath + "; " + original_uri.ToString() + " new: " + new_filename + "; " + new_uri.ToString() + "to open with: " ); // check if new version exist and remove foreach (uint id in currentphoto.VersionIds) { if ( currentphoto.GetVersion (id).Name == new_version_entry.Text ) { this.currentphoto.DeleteVersion ( id ); } } GLib.File destination = GLib.FileFactory.NewForUri (new_uri); if (destination.Exists) throw new Exception (String.Format ("An object at this uri {0} already exists", new_uri)); //FIXME. or better, fix the copy api ! GLib.File source = GLib.FileFactory.NewForUri (original_uri); source.Copy (destination, GLib.FileCopyFlags.None, null, null); this.currentphoto.DefaultVersionId = this.currentphoto.AddVersion (new SafeUri (new_uri).GetBaseUri (),new SafeUri (new_uri).GetFilename (), new_version_entry.Text, true); App.Instance.Database.Photos.Commit (this.currentphoto); this.currentphoto.Changes.DataChanged = true;; // run new version with selected application Gtk.TreeIter iter; if (owcb.GetActiveIter (out iter)){ Console.WriteLine ((string) owcb.Model.GetValue (iter, 0)); Console.WriteLine ((string) owcb.Model.GetValue (iter, 1)); Console.WriteLine ((string[]) owcb.Model.GetValue (iter, 2)); Console.WriteLine ("Getting applications again"); ArrayList union = new ArrayList(); //string[] weekDays = new string[] { "image/jpeg", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; foreach (string mime_type in (string []) owcb.Model.GetValue (iter, 2)) { //foreach (string mime_type in (string []) weekDays) { if (mime_type == null) continue; MimeApplication [] apps = Gnome.Vfs.Mime.GetAllApplications (mime_type); foreach (MimeApplication app in apps) { if (! union.Contains (app)) union.Add (app); } } foreach (MimeApplication app in union) { if (app.BinaryName.ToString() == (string) owcb.Model.GetValue (iter, 1)){ Console.WriteLine ("Winner is "+ (string) owcb.Model.GetValue (iter, 1)); // is there a better way to get a GLib.List??? GLib.List uri_list = new GLib.List (typeof (string)); uri_list.Append(new_uri.ToString()); app.Launch (uri_list); } } } } finally { Gtk.Application.Invoke (delegate { dialog.Destroy(); }); } }
public static string RandomNoteColor() { GLib.List colors = new GLib.List (typeof (string)); colors.Append("#f4ff51"); colors.Append("#88dcd5"); colors.Append("#b3f75f"); colors.Append("#f75f77"); colors.Append("#dc5ff7"); Random random = new Random(); return (string) colors[random.Next(colors.Count)]; }