[gnome-software/wip/kalev/x-scheme-handler/appstream: 2/2] Support opening appstream URLs



commit 492bfecdb1a19a9c3b78017cf482202a002f93a4
Author: Kalev Lember <klember redhat com>
Date:   Fri Oct 23 18:25:48 2015 +0200

    Support opening appstream URLs
    
    Add support for appstream URLs so that web pages could link to their
    favourite apps with e.g. <a href="appstream:0ad.desktop">Install 0ad</a>

 src/gs-application.c              |   34 ++++++++++++++++++++++++++++++++++
 src/org.gnome.Software.desktop.in |    3 ++-
 2 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index f07f32d..d7c2059 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -29,6 +29,7 @@
 #include <gtk/gtk.h>
 #include <gio/gio.h>
 #include <gio/gdesktopappinfo.h>
+#include <libsoup/soup.h>
 #include <packagekit-glib2/packagekit.h>
 
 #ifdef GDK_WINDOWING_X11
@@ -690,12 +691,44 @@ gs_application_handle_local_options (GApplication *app, GVariantDict *options)
 }
 
 static void
+gs_application_open (GApplication  *application,
+                     GFile        **files,
+                     gint           n_files,
+                     const gchar   *hint)
+{
+       GsApplication *app = GS_APPLICATION (application);
+       gint i;
+
+       for (i = 0; i < n_files; i++) {
+               g_autofree gchar *str = g_file_get_uri (files[i]);
+               g_autoptr(SoupURI) uri = NULL;
+
+               uri = soup_uri_new (str);
+               if (uri == NULL)
+                       continue;
+
+               if (g_strcmp0 (soup_uri_get_scheme (uri), "appstream") == 0) {
+                       const gchar *path = soup_uri_get_path (uri);
+
+                       /* trim any leading slashes */
+                       while (*path == '/')
+                               path++;
+
+                       g_action_group_activate_action (G_ACTION_GROUP (app),
+                                                       "details",
+                                                       g_variant_new ("(ss)", path, ""));
+               }
+       }
+}
+
+static void
 gs_application_class_init (GsApplicationClass *class)
 {
        G_OBJECT_CLASS (class)->dispose = gs_application_dispose;
        G_APPLICATION_CLASS (class)->startup = gs_application_startup;
        G_APPLICATION_CLASS (class)->activate = gs_application_activate;
        G_APPLICATION_CLASS (class)->handle_local_options = gs_application_handle_local_options;
+       G_APPLICATION_CLASS (class)->open = gs_application_open;
        G_APPLICATION_CLASS (class)->dbus_register = gs_application_dbus_register;
        G_APPLICATION_CLASS (class)->dbus_unregister = gs_application_dbus_unregister;
 }
@@ -706,6 +739,7 @@ gs_application_new (void)
        g_set_prgname("org.gnome.Software");
        return g_object_new (GS_APPLICATION_TYPE,
                             "application-id", "org.gnome.Software",
+                            "flags", G_APPLICATION_HANDLES_OPEN,
                             "inactivity-timeout", 12000,
                             NULL);
 }
diff --git a/src/org.gnome.Software.desktop.in b/src/org.gnome.Software.desktop.in
index 849a14c..f416fbb 100644
--- a/src/org.gnome.Software.desktop.in
+++ b/src/org.gnome.Software.desktop.in
@@ -2,12 +2,13 @@
 _Name=Software
 _Comment=Add, remove or update software on this computer
 Icon=gnome-software
-Exec=gnome-software
+Exec=gnome-software %U
 Terminal=false
 Type=Application
 Categories=GNOME;GTK;System;PackageManager;
 _Keywords=Updates;Upgrade;Sources;Repositories;Preferences;Install;Uninstall;Program;Software;App;Store;
 StartupNotify=true
+MimeType=x-scheme-handler/appstream;
 X-GNOME-Bugzilla-Bugzilla=GNOME
 X-GNOME-Bugzilla-Product=gnome-software
 X-GNOME-Bugzilla-Component=gnome-software


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]