Example #1
0
		protected void OpenFromMime (Hit hit)
		{
			string command = null;
			string uri = null, path = null;

			string mimetype = hit.MimeType;

			// FIXME: This is evil.  Nautilus should be handling
			// inode/directory, not just x-directory/normal
			if (mimetype == "inode/directory")
				mimetype = "x-directory/normal";

			// FIXME: I'm not sure that opening the parent
			// URI (if present) is the right thing to do in
			// all cases, but it does work for all our
			// current cases.
			if (hit.ParentUri != null)
				uri = hit.EscapedParentUri;
			else
				uri = hit.EscapedUri;

#if ENABLE_DESKTOP_LAUNCH
			RunDefaultHandler ("desktop-launch", uri);
#elif ENABLE_XDG_OPEN
			RunDefaultHandler ("xdg-open", uri);
#else
			MimeApplication app;
			app = Mime.GetDefaultApplication (mimetype);
			if (app == null) {
				Console.WriteLine ("Can't open MimeType '{0}'", mimetype);
				return;
			}
			
			bool expect_uris = app.SupportsUris ();
			path = hit.Path;

			GLib.List list = new GLib.List ((IntPtr) 0);
			list.Append (expect_uris ? uri : path);

			Gnome.Vfs.Result result = app.Launch (list);
			if (result != Gnome.Vfs.Result.Ok)
				Console.WriteLine ("Error in opening {0}: {1}", uri, result);
#endif
		}