Esempio n. 1
0
        public static void LaunchDefaultForUriAsync(string uri, GLib.AppLaunchContext launch_context, GLib.Cancellable cancellable, GLib.AsyncReadyCallback cb)
        {
            IntPtr native_uri = GLib.Marshaller.StringToPtrGStrdup(uri);

            GLibSharp.AsyncReadyCallbackWrapper cb_wrapper = new GLibSharp.AsyncReadyCallbackWrapper(cb);
            cb_wrapper.PersistUntilCalled();
            g_app_info_launch_default_for_uri_async(native_uri, launch_context == null ? IntPtr.Zero : launch_context.Handle, cancellable == null ? IntPtr.Zero : cancellable.Handle, cb_wrapper.NativeDelegate, IntPtr.Zero);
            GLib.Marshaller.Free(native_uri);
        }
Esempio n. 2
0
        public bool LaunchUris(GLib.List uris, GLib.AppLaunchContext launch_context)
        {
            IntPtr error   = IntPtr.Zero;
            bool   raw_ret = g_app_info_launch_uris(Handle, uris == null ? IntPtr.Zero : uris.Handle, launch_context == null ? IntPtr.Zero : launch_context.Handle, out error);
            bool   ret     = raw_ret;

            if (error != IntPtr.Zero)
            {
                throw new GLib.GException(error);
            }
            return(ret);
        }
Esempio n. 3
0
        public static bool LaunchDefaultForUri(string uri, GLib.AppLaunchContext launch_context)
        {
            IntPtr native_uri = GLib.Marshaller.StringToPtrGStrdup(uri);
            IntPtr error      = IntPtr.Zero;
            bool   raw_ret    = g_app_info_launch_default_for_uri(native_uri, launch_context == null ? IntPtr.Zero : launch_context.Handle, out error);
            bool   ret        = raw_ret;

            GLib.Marshaller.Free(native_uri);
            if (error != IntPtr.Zero)
            {
                throw new GLib.GException(error);
            }
            return(ret);
        }
Esempio n. 4
0
        protected virtual void OnRowActivated(object o, Gtk.RowActivatedArgs args)
        {
            Debug.WriteLine(5, "Row activated");

            Gtk.TreeIter iter;
            BibtexRecord record;

            if (!Model.GetIter(out iter, args.Path))
            {
                Debug.WriteLine(5, "Failed to open record because of GetIter faliure");
                return;
            }
            record = (BibtexRecord)Model.GetValue(iter, 0);
            string uriString = record.GetURI();

            if (string.IsNullOrEmpty(uriString))
            {
                Debug.WriteLine(5, "Selected record does not have a URI field");
                return;
            }

            var uri  = new Uri(uriString);
            var list = new GLib.List(typeof(String));

            list.Append(uriString);

            if (System.IO.File.Exists(uri.LocalPath))
            {
                bool   uncertain;
                string result;
                byte   data;
                ulong  data_size;

                data_size = 0;

                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {
                    // TODO: Does this work under linux?
                    System.Diagnostics.Process.Start(@uri.ToString());
                }
                else
                {
                    result = GLib.ContentType.Guess(uri.ToString(), out data, data_size, out uncertain);

                    if (result != null & result != "" & !uncertain)
                    {
                        GLib.IAppInfo app;

                        app = GLib.AppInfoAdapter.GetDefaultForType(result, true);

                        if (app != null)
                        {
                            GLib.AppLaunchContext appContext;

                            appContext = new GLib.AppLaunchContext();
                            app.LaunchUris(list, appContext);
                            return;
                        }
                    }
                }
            }
            else
            {
                var md = new Gtk.MessageDialog((Gtk.Window)Toplevel, Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Error, Gtk.ButtonsType.Close, "Error loading associated file:\n" + uri.LocalPath);
                md.Run();
                md.Destroy();

                Debug.WriteLine(0, "Error loading associated file:\n{0}", uri.LocalPath);
            }
        }