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



commit 6accf4426f23a9ae14a7969fb99401eb9137e4dd
Author: Richard Hughes <richard hughsie com>
Date:   Thu Feb 25 18:18:52 2016 +0000

    f

 src/plugins/gs-plugin-shell-extensions.c |  271 ++++++++++++++++++++++--------
 1 files changed, 200 insertions(+), 71 deletions(-)
---
diff --git a/src/plugins/gs-plugin-shell-extensions.c b/src/plugins/gs-plugin-shell-extensions.c
index 62dcc43..e4aa4dc 100644
--- a/src/plugins/gs-plugin-shell-extensions.c
+++ b/src/plugins/gs-plugin-shell-extensions.c
@@ -32,42 +32,15 @@
 
 // See https://git.gnome.org/browse/extensions-web/tree/sweettooth/extensions/views.py for src
 
-#if 0
-{
-  "numpages": 1,
-  "total": 1,
-  "extensions": [
-    {
-      "shell_version_map": {
-        "3.18": {
-          "pk": 5353,
-          "version": 23
-        },
-        "3.4.0": {
-          "pk": 2119,
-          "version": 9
-        },
-        "3.20": {
-          "pk": 2999,
-          "version": 110
-        },
-        "3.3.4": {
-          "pk": 848,
-          "version": 6
-        }
-      },
-      "description": "Now updated for shell 3.18\nissue:\nsudo apt-get install gir1.2-gconf\nor similar 
prior to installing",
-      "creator": "jablona123",
-      "name": "Gmail Notify",
-      "link": "\/extension\/154\/gmail-notify\/",
-      "pk": 154,
-      "creator_url": "\/accounts\/profile\/jablona123",
-      "icon": "\/static\/extension-data\/icons\/icon_154_1.png",
-      "uuid": "gmail_notify jablona123 pl"
-    }
-  ]
-}
-#endif
+/*
+ * Things we want from the API:
+ * 
+ *  - License (SPDX?)
+ *  - Screenshots
+ *  - Size on disk/download
+ *  - Review data for each extension?
+ *  - A local icon for a shell extension
+ */
 
 #ifndef JsonParser_autoptr
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(JsonParser, g_object_unref)
@@ -108,6 +81,149 @@ gs_plugin_destroy (GsPlugin *plugin)
 }
 
 /**
+ * _as_markup_import:
+ */
+static gchar *
+_as_markup_import (const gchar *text)
+{
+       GString *str;
+       guint i;
+       g_auto(GStrv) lines = NULL;
+
+       /* just assume paragraphs */
+       str = g_string_new ("<p>");
+       lines = g_strsplit (text, "\n", -1);
+       for (i = 0; lines[i] != NULL; i++) {
+               g_autofree gchar *markup = NULL;
+               if (lines[i][0] == '\0') {
+                       if (g_str_has_suffix (str->str, " "))
+                               g_string_truncate (str, str->len - 1);
+                       g_string_append (str, "</p><p>");
+                       continue;
+               }
+               markup = g_markup_escape_text (lines[i], -1);
+               g_string_append (str, markup);
+               g_string_append (str, " ");
+       }
+       if (g_str_has_suffix (str->str, " "))
+               g_string_truncate (str, str->len - 1);
+       g_string_append (str, "</p>");
+       return g_string_free (str, FALSE);
+}
+
+/**
+ * gs_plugin_shell_extensions_id_from_uuid:
+ */
+static gchar *
+gs_plugin_shell_extensions_id_from_uuid (const gchar *uuid)
+{
+       g_autofree gchar *id = g_strdup (uuid);
+       g_strdelimit (id, "@./", '_');
+       return g_strdup_printf ("gnome-shell-%s.ext", id);
+}
+
+/**
+ * gs_plugin_shell_extensions_add_app:
+ */
+static GsApp *
+gs_plugin_shell_extensions_add_app (const gchar *uuid,
+                                   GVariantIter *iter,
+                                   GError **error)
+{
+       gchar *str;
+       GVariant *val;
+       g_autofree gchar *id = NULL;
+       g_autofree gchar *id_prefix = 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_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 *tmp2 = NULL;
+                       tmp = _as_markup_import (g_variant_get_string (val, NULL));
+                       tmp2 = as_markup_convert_simple (tmp, error);
+                       if (tmp2 == NULL)
+                               return NULL;
+                       gs_app_set_description (app, GS_APP_QUALITY_NORMAL, tmp2);
+                       continue;
+               }
+               if (g_strcmp0 (str, "name") == 0) {
+                       gs_app_set_name (app, GS_APP_QUALITY_NORMAL,
+                                        g_variant_get_string (val, NULL));
+                       continue;
+               }
+               if (g_strcmp0 (str, "url") == 0) {
+                       gs_app_set_url (app, AS_URL_KIND_HOMEPAGE,
+                                       g_variant_get_string (val, NULL));
+                       continue;
+               }
+               if (g_strcmp0 (str, "type") == 0) {
+                       guint val_int = g_variant_get_double (val);
+                       /* FIXME: what does that mean */
+                       switch (val_int) {
+                       case 1:
+                               gs_app_set_kind (app, GS_APP_KIND_NORMAL); //FIXME
+                               break;
+                       case 2:
+                               gs_app_set_kind (app, GS_APP_KIND_NORMAL); //FIXME
+                               break;
+                       default:
+                               g_warning ("%s unknown type %i", uuid, val_int);
+                               break;
+                       }
+                       continue;
+               }
+               if (g_strcmp0 (str, "state") == 0) {
+                       guint val_int = g_variant_get_double (val);
+                       switch (val_int) {
+                       case 1:
+                               gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+                               break;
+                       case 6:
+                               gs_app_set_state (app, AS_APP_STATE_INSTALLED); //FIXME: disabled??
+                               break;
+                       default:
+                               g_error ("%s unknown state %i", uuid, val_int);
+                               break;
+                       }
+                       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);
+                       }
+                       continue;
+               }
+               if (g_strcmp0 (str, "hasPrefs") == 0) {
+                       if (g_variant_get_boolean (val))
+                               gs_app_set_metadata (app, "ShellExtensions::has-prefs", "");
+                       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);
+                       continue;
+               }
+       }
+       return g_steal_pointer (&app);
+}
+
+/**
  * gs_plugin_setup:
  */
 static gboolean
@@ -135,6 +251,49 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 }
 
 /**
+ * gs_plugin_add_installed:
+ */
+gboolean
+gs_plugin_add_installed (GsPlugin *plugin,
+                        GList **list,
+                        GCancellable *cancellable,
+                        GError **error)
+{
+       GVariantIter *ext_iter;
+       gchar *ext_uuid;
+       g_autoptr(GVariantIter) iter = NULL;
+       g_autoptr(GVariant) retval = NULL;
+
+       /* connect to gnome-shell */
+       if (!gs_plugin_setup (plugin, cancellable, error))
+               return FALSE;
+
+       /* installed */
+       retval = g_dbus_proxy_call_sync (plugin->priv->proxy,
+                                        "ListExtensions",
+                                        NULL,
+                                        G_DBUS_CALL_FLAGS_NONE,
+                                        -1,
+                                        cancellable,
+                                        error);
+       if (retval == NULL)
+               return FALSE;
+
+       /* parse each installed extension */
+       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;
+               app = gs_plugin_shell_extensions_add_app (ext_uuid,
+                                                         ext_iter,
+                                                         error);
+               if (app == NULL)
+                       return FALSE;
+               gs_plugin_add_app (list, app);
+       }
+       return TRUE;
+}
+
+/**
  * gs_plugin_refine:
  */
 static gboolean
@@ -221,37 +380,6 @@ gs_plugin_shell_extensions_parse_version (GsPlugin *plugin,
 }
 
 /**
- * _as_markup_import:
- */
-static gchar *
-_as_markup_import (const gchar *text)
-{
-       GString *str;
-       guint i;
-       g_auto(GStrv) lines = NULL;
-
-       /* just assume paragraphs */
-       str = g_string_new ("<p>");
-       lines = g_strsplit (text, "\n", -1);
-       for (i = 0; lines[i] != NULL; i++) {
-               g_autofree gchar *markup = NULL;
-               if (lines[i][0] == '\0') {
-                       if (g_str_has_suffix (str->str, " "))
-                               g_string_truncate (str, str->len - 1);
-                       g_string_append (str, "</p><p>");
-                       continue;
-               }
-               markup = g_markup_escape_text (lines[i], -1);
-               g_string_append (str, markup);
-               g_string_append (str, " ");
-       }
-       if (g_str_has_suffix (str->str, " "))
-               g_string_truncate (str, str->len - 1);
-       g_string_append (str, "</p>");
-       return g_string_free (str, FALSE);
-}
-
-/**
  * gs_plugin_shell_extensions_parse_app:
  */
 static AsApp *
@@ -263,14 +391,11 @@ gs_plugin_shell_extensions_parse_app (GsPlugin *plugin,
        JsonObject *json_ver_map;
        const gchar *tmp;
        guint64 pk;
-       g_autofree gchar *id = NULL;
 
        app = as_app_new ();
 
        /* not sure what this is for :/ */
        pk = json_object_get_int_member (json_app, "pk");
-       id = g_strdup_printf ("org.gnome.extensions-%" G_GINT64_FORMAT ".ext", pk);
-       as_app_set_id (app, id);
 
        tmp = json_object_get_string_member (json_app, "description");
        if (tmp != NULL) {
@@ -282,8 +407,12 @@ gs_plugin_shell_extensions_parse_app (GsPlugin *plugin,
        if (tmp != NULL)
                as_app_set_name (app, NULL, tmp);
        tmp = json_object_get_string_member (json_app, "uuid");
-       if (tmp != NULL)
+       if (tmp != NULL) {
+               g_autofree gchar *id = NULL;
+               id = gs_plugin_shell_extensions_id_from_uuid (tmp);
+               as_app_set_id (app, id);
                as_app_add_metadata (app, "ShellExtensions::uuid", tmp);
+       }
        tmp = json_object_get_string_member (json_app, "link");
        if (tmp != NULL) {
                g_autofree gchar *uri = NULL;


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