[gnome-software/wip/hughsie/shell-extensions] f



commit 6cbf58694edfe7e853a36a92edb54928097d2b8d
Author: Richard Hughes <richard hughsie com>
Date:   Thu Feb 25 20:35:10 2016 +0000

    f

 src/gs-app.c                             |    7 +++
 src/gs-app.h                             |    1 +
 src/plugins/gs-plugin-shell-extensions.c |   75 ++++++++++++++++++++++-------
 3 files changed, 65 insertions(+), 18 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 99cd994..881f518 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -154,6 +154,8 @@ gs_app_kind_to_string (GsAppKind kind)
                return "distro-upgrade";
        if (kind == GS_APP_KIND_FIRMWARE_UPDATE)
                return "firmware-update";
+       if (kind == GS_APP_KIND_SHELL_EXTENSION)
+               return "shell-extension";
        return NULL;
 }
 
@@ -627,6 +629,11 @@ gs_app_set_kind (GsApp *app, GsAppKind kind)
                    kind == GS_APP_KIND_UNKNOWN)
                        state_change_ok = TRUE;
                break;
+       case GS_APP_KIND_SHELL_EXTENSION:
+               /* extensions can only be promoted to core */
+               if (kind == GS_APP_KIND_CORE)
+                       state_change_ok = TRUE;
+               break;
        case GS_APP_KIND_SYSTEM:
        case GS_APP_KIND_OS_UPDATE:
        case GS_APP_KIND_CORE:
diff --git a/src/gs-app.h b/src/gs-app.h
index 97d9c9f..b8ebf26 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -50,6 +50,7 @@ typedef enum {
        GS_APP_KIND_CORE,               /* pkg  [ install:0 remove:0 update:1 ] */
        GS_APP_KIND_DISTRO_UPGRADE,     /* meta [ install:0 remove:0 update:1 ] */
        GS_APP_KIND_FIRMWARE_UPDATE,    /* app  [ install:0 remove:0 update:1 ] */
+       GS_APP_KIND_SHELL_EXTENSION,    /* app  [ install:1 remove:1 update:1 ] */
        GS_APP_KIND_LAST
 } GsAppKind;
 
diff --git a/src/plugins/gs-plugin-shell-extensions.c b/src/plugins/gs-plugin-shell-extensions.c
index e4aa4dc..58d3fed 100644
--- a/src/plugins/gs-plugin-shell-extensions.c
+++ b/src/plugins/gs-plugin-shell-extensions.c
@@ -130,22 +130,27 @@ gs_plugin_shell_extensions_add_app (const gchar *uuid,
                                    GVariantIter *iter,
                                    GError **error)
 {
+       const gchar *tmp;
        gchar *str;
        GVariant *val;
        g_autofree gchar *id = NULL;
        g_autofree gchar *id_prefix = NULL;
+       g_autoptr(AsIcon) ic = NULL;
        g_autoptr(GsApp) app = NULL;
 
        id = gs_plugin_shell_extensions_id_from_uuid (uuid);
        id_prefix = g_strdup_printf ("user:%s", id);
        app = gs_app_new (id_prefix);
+       gs_app_set_management_plugin (app, "ShellExtensions");
+       gs_app_set_metadata (app, "ShellExtensions::uuid", uuid);
+       gs_app_set_id_kind (app, AS_ID_KIND_DESKTOP);
        gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "GNOME Shell Extension");
        while (g_variant_iter_loop (iter, "{sv}", &str, &val)) {
                if (g_strcmp0 (str, "description") == 0) {
-                       g_autofree gchar *tmp = NULL;
+                       g_autofree gchar *tmp1 = NULL;
                        g_autofree gchar *tmp2 = NULL;
-                       tmp = _as_markup_import (g_variant_get_string (val, NULL));
-                       tmp2 = as_markup_convert_simple (tmp, error);
+                       tmp1 = _as_markup_import (g_variant_get_string (val, NULL));
+                       tmp2 = as_markup_convert_simple (tmp1, error);
                        if (tmp2 == NULL)
                                return NULL;
                        gs_app_set_description (app, GS_APP_QUALITY_NORMAL, tmp2);
@@ -166,10 +171,10 @@ gs_plugin_shell_extensions_add_app (const gchar *uuid,
                        /* FIXME: what does that mean */
                        switch (val_int) {
                        case 1:
-                               gs_app_set_kind (app, GS_APP_KIND_NORMAL); //FIXME
+                               gs_app_set_kind (app, GS_APP_KIND_SHELL_EXTENSION);
                                break;
                        case 2:
-                               gs_app_set_kind (app, GS_APP_KIND_NORMAL); //FIXME
+                               gs_app_set_kind (app, GS_APP_KIND_SHELL_EXTENSION); //FIXME?
                                break;
                        default:
                                g_warning ("%s unknown type %i", uuid, val_int);
@@ -193,7 +198,6 @@ gs_plugin_shell_extensions_add_app (const gchar *uuid,
                        continue;
                }
                if (g_strcmp0 (str, "error") == 0) {
-                       const gchar *tmp;
                        tmp = g_variant_get_string (val, NULL);
                        if (tmp != NULL && tmp[0] != '\0') {
                                g_error ("error: %s", tmp);
@@ -206,20 +210,28 @@ gs_plugin_shell_extensions_add_app (const gchar *uuid,
                        continue;
                }
                if (g_strcmp0 (str, "extension-id") == 0) {
-                       const gchar *tmp;
                        tmp = g_variant_get_string (val, NULL);
                        gs_app_set_metadata (app, "ShellExtensions::extension-id", tmp);
                        continue;
                }
                if (g_strcmp0 (str, "path") == 0) {
-                       g_autoptr(AsIcon) ic = NULL;
-                       ic = as_icon_new ();
-                       as_icon_set_kind (ic, AS_ICON_KIND_STOCK);
-                       as_icon_set_name (ic, "application-x-addon");
-                       gs_app_set_icon (app, ic);
+                       tmp = g_variant_get_string (val, NULL);
+                       gs_app_set_metadata (app, "ShellExtensions::path", tmp);
                        continue;
                }
        }
+
+       /* installed using a package? */
+       tmp = gs_app_get_metadata_item (app, "ShellExtensions::path");
+//     if (tmp != NULL && g_str_has_prefix (tmp, "/usr"))
+//             gs_app_set_kind (app, GS_APP_KIND_CORE);
+
+       /* this should get replaced by the one found in AppStream */
+       ic = as_icon_new ();
+       as_icon_set_kind (ic, AS_ICON_KIND_STOCK);
+       as_icon_set_name (ic, "application-x-addon");
+       gs_app_set_icon (app, ic);
+
        return g_steal_pointer (&app);
 }
 
@@ -283,11 +295,22 @@ gs_plugin_add_installed (GsPlugin *plugin,
        g_variant_get (retval, "(a{sa{sv}})", &iter);
        while (g_variant_iter_loop (iter, "{sa{sv}}", &ext_uuid, &ext_iter)) {
                g_autoptr(GsApp) app = NULL;
+
+               /* parse the data into an GsApp */
                app = gs_plugin_shell_extensions_add_app (ext_uuid,
                                                          ext_iter,
                                                          error);
                if (app == NULL)
                        return FALSE;
+
+               /* we can't remove core shell extensions so just hide them */
+               if (gs_app_get_kind (app) == GS_APP_KIND_CORE) {
+                       g_debug ("ignoring core shell extension %s",
+                                gs_app_get_id (app));
+//                     continue;
+               }
+
+               /* add to results */
                gs_plugin_add_app (list, app);
        }
        return TRUE;
@@ -696,6 +719,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
                      GError **error)
 {
        const gchar *uuid;
+       gboolean ret;
        g_autoptr(GVariant) retval = NULL;
 
        /* only process this app if was created by this plugin */
@@ -718,9 +742,16 @@ gs_plugin_app_remove (GsPlugin *plugin,
        if (retval == NULL)
                return FALSE;
 
-       /* not sure why this would fail */
-       if (!g_variant_get_boolean (retval))
-               g_error ("failed, no message?");
+       /* not sure why this would fail -- perhaps installed in /usr? */
+       g_variant_get (retval, "(b)", &ret);
+       if (!ret) {
+               g_set_error (error,
+                            GS_PLUGIN_ERROR,
+                            GS_PLUGIN_ERROR_FAILED,
+                            "failed to uninstall %s",
+                            gs_app_get_id (app));
+               return FALSE;
+       }
 
        return TRUE;
 }
@@ -735,6 +766,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                       GError **error)
 {
        const gchar *uuid;
+       const gchar *retstr;
        g_autoptr(GVariant) retval = NULL;
 
        /* only process this app if was created by this plugin */
@@ -757,8 +789,8 @@ gs_plugin_app_install (GsPlugin *plugin,
                                         error);
        if (retval == NULL)
                return FALSE;
-       g_warning ("%s", g_variant_get_type_string (retval));
-       g_debug ("shell returned: %s", g_variant_get_string (retval, NULL));
+       g_variant_get (retval, "(&s)", &retstr);
+       g_debug ("shell returned: %s", retstr);
        return TRUE;
 }
 
@@ -784,6 +816,14 @@ gs_plugin_launch (GsPlugin *plugin,
 
        /* install */
        uuid = gs_app_get_metadata_item (app, "ShellExtensions::uuid");
+       if (uuid == NULL) {
+               g_set_error (error,
+                            GS_PLUGIN_ERROR,
+                            GS_PLUGIN_ERROR_FAILED,
+                            "no uuid set for %s",
+                            gs_app_get_id (app));
+               return FALSE;
+       }
        retval = g_dbus_proxy_call_sync (plugin->priv->proxy,
                                         "LaunchExtensionPrefs",
                                         g_variant_new ("(s)", uuid),
@@ -793,6 +833,5 @@ gs_plugin_launch (GsPlugin *plugin,
                                         error);
        if (retval == NULL)
                return FALSE;
-       g_debug ("shell returned: %s", g_variant_get_string (retval, NULL));
        return TRUE;
 }


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