[gnome-software] trivial: Factor out some common code



commit 6244213682258151560e9bccebfa214203b5d420
Author: Richard Hughes <richard hughsie com>
Date:   Tue Aug 30 16:58:15 2016 +0100

    trivial: Factor out some common code

 src/gs-common.c         |   23 +++++++++++++++++++++++
 src/gs-common.h         |    2 ++
 src/gs-shell-overview.c |   16 ++--------------
 src/gs-sources-dialog.c |   19 ++++---------------
 4 files changed, 31 insertions(+), 29 deletions(-)
---
diff --git a/src/gs-common.c b/src/gs-common.c
index cd41c86..0db7ce8 100644
--- a/src/gs-common.c
+++ b/src/gs-common.c
@@ -918,4 +918,27 @@ gs_utils_get_error_value (const GError *error)
        return (const gchar *) str + 1;
 }
 
+/**
+ * gs_utils_build_unique_id_kind:
+ * @kind: A #AsAppKind
+ * @id: An application ID
+ *
+ * Converts the ID valid into a wildcard unique ID of a specific kind.
+ * If @id is already a unique ID, then it is returned unchanged.
+ *
+ * Returns: (transfer full): a unique ID, or %NULL
+ */
+gchar *
+gs_utils_build_unique_id_kind (AsAppKind kind, const gchar *id)
+{
+       if (as_utils_unique_id_valid (id))
+               return g_strdup (id);
+       return as_utils_unique_id_build (AS_APP_SCOPE_UNKNOWN,
+                                        AS_BUNDLE_KIND_UNKNOWN,
+                                        NULL,
+                                        kind,
+                                        id,
+                                        NULL);
+}
+
 /* vim: set noexpandtab: */
diff --git a/src/gs-common.h b/src/gs-common.h
index af2cc04..e7b4507 100644
--- a/src/gs-common.h
+++ b/src/gs-common.h
@@ -66,6 +66,8 @@ void           gs_utils_show_error_dialog     (GtkWindow      *parent,
                                                 const gchar    *title,
                                                 const gchar    *msg,
                                                 const gchar    *details);
+gchar          *gs_utils_build_unique_id_kind  (AsAppKind       kind,
+                                                const gchar    *id);
 GtkWidget      *gs_search_button_new           (GtkSearchBar   *search_bar);
 
 G_END_DECLS
diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c
index 42b2f58..1d64135 100644
--- a/src/gs-shell-overview.c
+++ b/src/gs-shell-overview.c
@@ -607,19 +607,6 @@ gs_shell_overview_categories_expander_cb (GtkButton *button, GsShellOverview *se
        gtk_revealer_set_reveal_child (GTK_REVEALER (priv->categories_more), TRUE);
 }
 
-static gchar *
-gs_utils_build_source_unique_id (const gchar *id)
-{
-       if (as_utils_unique_id_valid (id))
-               return g_strdup (id);
-       return as_utils_unique_id_build (AS_APP_SCOPE_UNKNOWN,
-                                        AS_BUNDLE_KIND_UNKNOWN,
-                                        NULL,
-                                        AS_APP_KIND_SOURCE,
-                                        id,
-                                        NULL);
-}
-
 static void
 g_shell_overview_get_sources_cb (GsPluginLoader *plugin_loader,
                                 GAsyncResult *res,
@@ -651,7 +638,8 @@ g_shell_overview_get_sources_cb (GsPluginLoader *plugin_loader,
                g_autofree gchar *unique_id = NULL;
 
                /* match the ID from GSettings to an actual GsApp */
-               unique_id = gs_utils_build_source_unique_id (nonfree_ids[i]);
+               unique_id = gs_utils_build_unique_id_kind (AS_APP_KIND_SOURCE,
+                                                          nonfree_ids[i]);
                app = gs_app_list_lookup (list, unique_id);
                if (app == NULL) {
                        g_warning ("no source for %s", unique_id);
diff --git a/src/gs-sources-dialog.c b/src/gs-sources-dialog.c
index 7538ff3..f6887c1 100644
--- a/src/gs-sources-dialog.c
+++ b/src/gs-sources-dialog.c
@@ -163,19 +163,6 @@ add_source (GtkListBox *listbox, GsApp *app)
        gtk_widget_show (row);
 }
 
-static gchar *
-gs_utils_build_source_unique_id (const gchar *id)
-{
-       if (as_utils_unique_id_valid (id))
-               return g_strdup (id);
-       return as_utils_unique_id_build (AS_APP_SCOPE_UNKNOWN,
-                                        AS_BUNDLE_KIND_UNKNOWN,
-                                        NULL,
-                                        AS_APP_KIND_SOURCE,
-                                        id,
-                                        NULL);
-}
-
 static void
 source_modified_cb (GObject *source,
                    GAsyncResult *res,
@@ -202,7 +189,8 @@ gs_sources_dialog_rescan_proprietary_sources (GsSourcesDialog *dialog)
        for (i = 0; nonfree_ids[i] != NULL; i++) {
                GsApp *app;
                g_autofree gchar *unique_id = NULL;
-               unique_id = gs_utils_build_source_unique_id (nonfree_ids[i]);
+               unique_id = gs_utils_build_unique_id_kind (AS_APP_KIND_SOURCE,
+                                                          nonfree_ids[i]);
                app = gs_app_list_lookup (dialog->source_list, unique_id);
                if (app == NULL) {
                        g_warning ("no source for %s", unique_id);
@@ -294,7 +282,8 @@ gs_sources_dialog_refresh_proprietary_apps (GsSourcesDialog *dialog)
        for (i = 0; nonfree_ids[i] != NULL; i++) {
                GsApp *app;
                g_autofree gchar *unique_id = NULL;
-               unique_id = gs_utils_build_source_unique_id (nonfree_ids[i]);
+               unique_id = gs_utils_build_unique_id_kind (AS_APP_KIND_SOURCE,
+                                                          nonfree_ids[i]);
                app = gs_app_list_lookup (dialog->source_list, unique_id);
                if (app == NULL) {
                        g_warning ("no source for %s", unique_id);


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