[gnome-software/wip/hughsie/flatpak-profile] trivial: Ensure flatpak apps have the same quirks applied as system apps



commit 9c59adc26d925a75c5ff326f44f768ac0e2820e3
Author: Richard Hughes <richard hughsie com>
Date:   Wed Nov 2 09:45:20 2016 +0000

    trivial: Ensure flatpak apps have the same quirks applied as system apps

 src/plugins/gs-appstream.c        |   42 ++++++++++++++++++++++++
 src/plugins/gs-appstream.h        |    2 +
 src/plugins/gs-flatpak.c          |    9 +++++
 src/plugins/gs-plugin-appstream.c |   65 ++++++++----------------------------
 4 files changed, 68 insertions(+), 50 deletions(-)
---
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 952c7ee..08abd8b 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -1048,3 +1048,45 @@ gs_appstream_add_featured (GsPlugin *plugin,
        }
        return TRUE;
 }
+
+void
+gs_appstream_add_extra_info (GsPlugin *plugin, AsApp *app)
+{
+       const gchar *tmp;
+
+       /* add more search terms */
+       switch (as_app_get_kind (app)) {
+       case AS_APP_KIND_WEB_APP:
+       case AS_APP_KIND_INPUT_METHOD:
+               tmp = as_app_kind_to_string (as_app_get_kind (app));
+               g_debug ("adding keyword '%s' to %s",
+                        tmp, as_app_get_unique_id (app));
+               as_app_add_keyword (app, NULL, tmp);
+               break;
+       default:
+               break;
+       }
+
+       /* fix up these */
+       if (as_app_get_kind (app) == AS_APP_KIND_LOCALIZATION &&
+           g_str_has_prefix (as_app_get_id (app),
+                             "org.fedoraproject.LangPack-")) {
+               g_autoptr(AsIcon) icon = NULL;
+
+               /* add icon */
+               icon = as_icon_new ();
+               as_icon_set_kind (icon, AS_ICON_KIND_STOCK);
+               as_icon_set_name (icon, "accessories-dictionary-symbolic");
+               as_app_add_icon (app, icon);
+
+               /* add categories */
+               as_app_add_category (app, "Addons");
+               as_app_add_category (app, "Localization");
+       }
+
+       /* fix up drivers with our nonstandard groups */
+       if (as_app_get_kind (app) == AS_APP_KIND_DRIVER) {
+               as_app_add_category (app, "Addons");
+               as_app_add_category (app, "Drivers");
+       }
+}
diff --git a/src/plugins/gs-appstream.h b/src/plugins/gs-appstream.h
index 4c137ca..6e7af5b 100644
--- a/src/plugins/gs-appstream.h
+++ b/src/plugins/gs-appstream.h
@@ -65,6 +65,8 @@ gboolean       gs_appstream_add_featured              (GsPlugin       *plugin,
                                                         GError         **error);
 void            gs_appstream_ensure_app_token_cache    (GsPlugin       *plugin,
                                                         AsStore        *store);
+void            gs_appstream_add_extra_info            (GsPlugin       *plugin,
+                                                        AsApp          *app);
 
 G_END_DECLS
 
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 28b1de7..1be564b 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -2684,6 +2684,12 @@ gs_flatpak_add_featured (GsFlatpak *self,
 }
 
 static void
+gs_flatpak_store_app_added_cb (AsStore *store, AsApp *app, GsFlatpak *self)
+{
+       gs_appstream_add_extra_info (self->plugin, app);
+}
+
+static void
 gs_flatpak_store_app_removed_cb (AsStore *store, AsApp *app, GsFlatpak *self)
 {
        g_debug ("AppStream app was removed, doing delete from global cache");
@@ -2717,6 +2723,9 @@ gs_flatpak_init (GsFlatpak *self)
        self->broken_remotes = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                      g_free, NULL);
        self->store = as_store_new ();
+       g_signal_connect (self->store, "app-added",
+                         G_CALLBACK (gs_flatpak_store_app_added_cb),
+                         self);
        g_signal_connect (self->store, "app-removed",
                          G_CALLBACK (gs_flatpak_store_app_removed_cb),
                          self);
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 13057b6..b55a7a7 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -133,6 +133,14 @@ gs_plugin_appstream_store_changed_cb (AsStore *store, GsPlugin *plugin)
 }
 
 static void
+gs_plugin_appstream_store_app_added_cb (AsStore *store,
+                                       AsApp *app,
+                                       GsPlugin *plugin)
+{
+       gs_appstream_add_extra_info (plugin, app);
+}
+
+static void
 gs_plugin_appstream_store_app_removed_cb (AsStore *store,
                                          AsApp *app,
                                          GsPlugin *plugin)
@@ -146,6 +154,12 @@ gs_plugin_initialize (GsPlugin *plugin)
 {
        GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
        priv->store = as_store_new ();
+       g_signal_connect (priv->store, "app-added",
+                         G_CALLBACK (gs_plugin_appstream_store_app_added_cb),
+                         plugin);
+       g_signal_connect (priv->store, "app-removed",
+                         G_CALLBACK (gs_plugin_appstream_store_app_removed_cb),
+                         plugin);
        as_store_set_add_flags (priv->store,
                                AS_STORE_ADD_FLAG_USE_UNIQUE_ID |
                                AS_STORE_ADD_FLAG_USE_MERGE_HEURISTIC);
@@ -219,7 +233,6 @@ gboolean
 gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
-       AsApp *app;
        GPtrArray *items;
        gboolean ret;
        const gchar *tmp;
@@ -275,9 +288,6 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
        g_signal_connect (priv->store, "changed",
                          G_CALLBACK (gs_plugin_appstream_store_changed_cb),
                          plugin);
-       g_signal_connect (priv->store, "app-removed",
-                         G_CALLBACK (gs_plugin_appstream_store_app_removed_cb),
-                         plugin);
 
        /* ensure the token cache */
        gs_appstream_ensure_app_token_cache (plugin, priv->store);
@@ -285,7 +295,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
        /* add search terms for apps not in the main source */
        origins = gs_plugin_appstream_get_origins_hash (items);
        for (i = 0; i < items->len; i++) {
-               app = g_ptr_array_index (items, i);
+               AsApp *app = g_ptr_array_index (items, i);
                tmp = as_app_get_origin (app);
                if (tmp == NULL || tmp[0] == '\0')
                        continue;
@@ -297,51 +307,6 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
                }
        }
 
-       /* add more search terms */
-       for (i = 0; i < items->len; i++) {
-               app = g_ptr_array_index (items, i);
-               switch (as_app_get_kind (app)) {
-               case AS_APP_KIND_WEB_APP:
-               case AS_APP_KIND_INPUT_METHOD:
-                       tmp = as_app_kind_to_string (as_app_get_kind (app));
-                       g_debug ("adding keyword '%s' to %s",
-                                tmp, as_app_get_unique_id (app));
-                       as_app_add_keyword (app, NULL, tmp);
-                       break;
-               default:
-                       break;
-               }
-       }
-
-       /* fix up these */
-       for (i = 0; i < items->len; i++) {
-               app = g_ptr_array_index (items, i);
-               if (as_app_get_kind (app) == AS_APP_KIND_LOCALIZATION &&
-                   g_str_has_prefix (as_app_get_id (app),
-                                     "org.fedoraproject.LangPack-")) {
-                       g_autoptr(AsIcon) icon = NULL;
-
-                       /* add icon */
-                       icon = as_icon_new ();
-                       as_icon_set_kind (icon, AS_ICON_KIND_STOCK);
-                       as_icon_set_name (icon, "accessories-dictionary-symbolic");
-                       as_app_add_icon (app, icon);
-
-                       /* add categories */
-                       as_app_add_category (app, "Addons");
-                       as_app_add_category (app, "Localization");
-               }
-       }
-
-       /* fix up drivers with our nonstandard groups */
-       for (i = 0; i < items->len; i++) {
-               app = g_ptr_array_index (items, i);
-               if (as_app_get_kind (app) == AS_APP_KIND_DRIVER) {
-                       as_app_add_category (app, "Addons");
-                       as_app_add_category (app, "Drivers");
-               }
-       }
-
        /* rely on the store keeping itself updated */
        return TRUE;
 }


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