[gnome-software] Convert a few GsApp metadata items into properties and clarify the differences



commit 5617178cd6f3e9797c668824d01bfed0f9492ad0
Author: Richard Hughes <richard hughsie com>
Date:   Mon Sep 9 19:08:25 2013 +0100

    Convert a few GsApp metadata items into properties and clarify the differences

 src/gs-app-widget.c                       |   11 ++-
 src/gs-app.c                              |  100 +++++++++++++++++++++++++++++
 src/gs-app.h                              |    9 +++
 src/gs-plugin-loader.c                    |    8 ++-
 src/gs-self-test.c                        |    2 +-
 src/gs-shell-updates.c                    |   10 ++--
 src/plugins/README.md                     |    7 +-
 src/plugins/gs-plugin-appstream.c         |    6 +-
 src/plugins/gs-plugin-desktopdb.c         |    2 +-
 src/plugins/gs-plugin-packagekit-refine.c |    6 +-
 src/plugins/gs-plugin-packagekit.c        |   13 ++--
 11 files changed, 145 insertions(+), 29 deletions(-)
---
diff --git a/src/gs-app-widget.c b/src/gs-app-widget.c
index 7e2f4b1..ca85134 100644
--- a/src/gs-app-widget.c
+++ b/src/gs-app-widget.c
@@ -68,7 +68,7 @@ gs_app_widget_refresh (GsAppWidget *app_widget)
 
        /* get the main body text */
        if (gs_app_get_state (priv->app) == GS_APP_STATE_UPDATABLE)
-               tmp = gs_app_get_metadata_item (priv->app, "update-details");
+               tmp = gs_app_get_update_details (priv->app);
        if (tmp == NULL)
                tmp = gs_app_get_description (priv->app);
        if (tmp == NULL)
@@ -85,8 +85,13 @@ gs_app_widget_refresh (GsAppWidget *app_widget)
 
        gtk_label_set_label (GTK_LABEL (priv->name_label),
                              gs_app_get_name (priv->app));
-       gtk_label_set_label (GTK_LABEL (priv->version_label),
-                            gs_app_get_version (priv->app));
+       if (gs_app_get_state (priv->app) == GS_APP_STATE_UPDATABLE) {
+               gtk_label_set_label (GTK_LABEL (priv->version_label),
+                                    gs_app_get_update_version (priv->app));
+       } else {
+               gtk_label_set_label (GTK_LABEL (priv->version_label),
+                                    gs_app_get_version (priv->app));
+       }
        if (gs_app_get_pixbuf (priv->app))
                gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image),
                                           gs_app_get_pixbuf (priv->app));
diff --git a/src/gs-app.c b/src/gs-app.c
index 477b36c..7978aa3 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -33,11 +33,14 @@ struct GsAppPrivate
 {
        gchar                   *id;
        gchar                   *name;
+       gchar                   *source;
        gchar                   *version;
        gchar                   *summary;
        gchar                   *description;
        gchar                   *screenshot;
         gchar                  *url;
+        gchar                  *update_version;
+        gchar                  *update_details;
        gint                     rating;
        GsAppKind                kind;
        GsAppState               state;
@@ -255,6 +258,8 @@ gs_app_get_name (GsApp *app)
 
 /**
  * gs_app_set_name:
+ * @app:       A #GsApp instance
+ * @name:      The short localized name, e.g. "Calculator"
  */
 void
 gs_app_set_name (GsApp *app, const gchar *name)
@@ -265,6 +270,33 @@ gs_app_set_name (GsApp *app, const gchar *name)
 }
 
 /**
+ * gs_app_get_source:
+ */
+const gchar *
+gs_app_get_source (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       return app->priv->source;
+}
+
+/**
+ * gs_app_set_source:
+ * @app:       A #GsApp instance
+ * @source:    The non-localized short name, e.g. "gnome-calculator"
+ *
+ * This name is used for the update page if the application is collected into
+ * the 'OS Updates' group. It is typically the package name, although this
+ * should not be relied upon.
+ */
+void
+gs_app_set_source (GsApp *app, const gchar *source)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       g_free (app->priv->source);
+       app->priv->source = g_strdup (source);
+}
+
+/**
  * gs_app_get_pixbuf:
  */
 GdkPixbuf *
@@ -368,6 +400,11 @@ out:
 
 /**
  * gs_app_set_version:
+ * @app:       A #GsApp instance
+ * @version:   The version, e.g. "2:1.2.3.fc19"
+ *
+ * This saves the version after stripping out any non-friendly parts, such as
+ * distro tags, git revisions and that kind of thing.
  */
 void
 gs_app_set_version (GsApp *app, const gchar *version)
@@ -389,6 +426,8 @@ gs_app_get_summary (GsApp *app)
 
 /**
  * gs_app_set_summary:
+ * @app:       A #GsApp instance
+ * @summary:   The medium length localized name, e.g. "A graphical calculator for GNOME"
  */
 void
 gs_app_set_summary (GsApp *app, const gchar *summary)
@@ -398,6 +437,9 @@ gs_app_set_summary (GsApp *app, const gchar *summary)
        app->priv->summary = g_strdup (summary);
 }
 
+/**
+ * gs_app_get_description:
+ */
 const gchar *
 gs_app_get_description (GsApp *app)
 {
@@ -405,6 +447,11 @@ gs_app_get_description (GsApp *app)
        return app->priv->description;
 }
 
+/**
+ * gs_app_set_description:
+ * @app:       A #GsApp instance
+ * @summary:   The multiline localized description, e.g. "GNOME Calculator is a graphical calculator for 
GNOME....."
+ */
 void
 gs_app_set_description (GsApp *app, const gchar *description)
 {
@@ -413,6 +460,9 @@ gs_app_set_description (GsApp *app, const gchar *description)
        app->priv->description = g_strdup (description);
 }
 
+/**
+ * gs_app_get_url:
+ */
 const gchar *
 gs_app_get_url (GsApp *app)
 {
@@ -420,6 +470,11 @@ gs_app_get_url (GsApp *app)
        return app->priv->url;
 }
 
+/**
+ * gs_app_set_url:
+ * @app:       A #GsApp instance
+ * @summary:   The home page URL, e.g. "http://www.foo.com/gcalctool/";
+ */
 void
 gs_app_set_url (GsApp *app, const gchar *url)
 {
@@ -450,6 +505,48 @@ gs_app_set_screenshot (GsApp *app, const gchar *screenshot)
 }
 
 /**
+ * gs_app_get_update_version:
+ */
+const gchar *
+gs_app_get_update_version (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       return app->priv->update_version;
+}
+
+/**
+ * gs_app_set_update_version:
+ */
+void
+gs_app_set_update_version (GsApp *app, const gchar *update_version)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       g_free (app->priv->update_version);
+       app->priv->update_version = gs_app_get_pretty_version (update_version);
+}
+
+/**
+ * gs_app_get_update_details:
+ */
+const gchar *
+gs_app_get_update_details (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       return app->priv->update_details;
+}
+
+/**
+ * gs_app_set_update_version:
+ */
+void
+gs_app_set_update_details (GsApp *app, const gchar *update_details)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       g_free (app->priv->update_details);
+       app->priv->update_details = g_strdup (update_details);
+}
+
+/**
  * gs_app_get_rating:
  */
 gint
@@ -757,10 +854,13 @@ gs_app_finalize (GObject *object)
 
        g_free (priv->id);
        g_free (priv->name);
+       g_free (priv->source);
        g_free (priv->version);
        g_free (priv->summary);
        g_free (priv->description);
        g_free (priv->screenshot);
+       g_free (priv->update_version);
+       g_free (priv->update_details);
        g_hash_table_unref (priv->metadata);
        g_ptr_array_unref (priv->related);
        if (priv->pixbuf != NULL)
diff --git a/src/gs-app.h b/src/gs-app.h
index 1b76cd7..c4a9aeb 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -93,6 +93,9 @@ void           gs_app_set_state               (GsApp          *app,
 const gchar    *gs_app_get_name                (GsApp          *app);
 void            gs_app_set_name                (GsApp          *app,
                                                 const gchar    *name);
+const gchar    *gs_app_get_source              (GsApp          *app);
+void            gs_app_set_source              (GsApp          *app,
+                                                const gchar    *source);
 const gchar    *gs_app_get_version             (GsApp          *app);
 void            gs_app_set_version             (GsApp          *app,
                                                 const gchar    *version);
@@ -108,6 +111,12 @@ void                gs_app_set_url                 (GsApp          *app,
 const gchar    *gs_app_get_screenshot          (GsApp          *app);
 void            gs_app_set_screenshot          (GsApp          *app,
                                                 const gchar    *screenshot);
+const gchar    *gs_app_get_update_version      (GsApp          *app);
+void            gs_app_set_update_version      (GsApp          *app,
+                                                const gchar    *update_version);
+const gchar    *gs_app_get_update_details      (GsApp          *app);
+void            gs_app_set_update_details      (GsApp          *app,
+                                                const gchar    *update_details);
 GdkPixbuf      *gs_app_get_pixbuf              (GsApp          *app);
 void            gs_app_set_pixbuf              (GsApp          *app,
                                                 GdkPixbuf      *pixbuf);
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index e936383..63b487f 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -302,7 +302,12 @@ gs_plugin_loader_app_is_valid (GsApp *app)
                return FALSE;
        }
 
-       /* don't show apps that do not have a name */
+       /* don't show apps that do not have the required details */
+       if (gs_app_get_source (app) == NULL) {
+               g_debug ("app invalid as no source %s",
+                        gs_plugin_loader_get_app_str (app));
+               return FALSE;
+       }
        if (gs_app_get_name (app) == NULL) {
                g_debug ("app invalid as no name %s",
                         gs_plugin_loader_get_app_str (app));
@@ -450,6 +455,7 @@ cd_plugin_loader_get_updates_thread_cb (GSimpleAsyncResult *res,
                app = gs_app_new ("os-update");
                gs_app_set_kind (app, GS_APP_KIND_OS_UPDATE);
                gs_app_set_state (app, GS_APP_STATE_UPDATABLE);
+               gs_app_set_source (app, "os-update");
                gs_app_set_name (app, _("OS Updates"));
                gs_app_set_summary (app, _("Includes performance, stability and security improvements for all 
users."));
                gs_app_set_description (app, _("Includes performance, stability and security improvements for 
all users."));
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 4d5b9cd..20d84e3 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -279,7 +279,7 @@ gs_plugin_loader_empty_func (void)
                                                g_print ("Cat: %s\tSubCat: %s\tPkgName: %s\tAppId: %s\n",
                                                         gs_category_get_id (category),
                                                         gs_category_get_id (sub),
-                                                        gs_app_get_metadata_item (GS_APP (g->data), 
"package-name"),
+                                                        gs_app_get_source (GS_APP (g->data)),
                                                         gs_app_get_id (GS_APP (g->data)));
                                        }
                                }
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 4bca8a1..2ada3bb 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -194,8 +194,8 @@ gs_shell_updates_set_updates_description_ui (GsShellUpdates *shell_updates, GsAp
                gtk_window_set_title (GTK_WINDOW (widget), gs_app_get_name (app));
        } else {
                tmp = g_strdup_printf ("%s %s",
-                                      gs_app_get_metadata_item (app, "package-name"),
-                                      gs_app_get_version (app));
+                                      gs_app_get_source (app),
+                                      gs_app_get_update_version (app));
                gtk_window_set_title (GTK_WINDOW (widget), tmp);
                g_free (tmp);
        }
@@ -208,7 +208,7 @@ gs_shell_updates_set_updates_description_ui (GsShellUpdates *shell_updates, GsAp
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "scrolledwindow_update"));
        gtk_widget_set_visible (widget, kind == GS_APP_KIND_OS_UPDATE);
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "label_update_details"));
-       gtk_label_set_label (GTK_LABEL (widget), gs_app_get_metadata_item (app, "update-details"));
+       gtk_label_set_label (GTK_LABEL (widget), gs_app_get_update_details (app));
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "image_update_icon"));
        gtk_image_set_from_pixbuf (GTK_IMAGE (widget), gs_app_get_pixbuf (app));
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "label_update_name"));
@@ -266,7 +266,7 @@ show_update_details (GsApp *app, GsShellUpdates *shell_updates)
                        app_related = g_ptr_array_index (related, i);
                         row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
                         g_object_set_data_full (G_OBJECT (row), "app", g_object_ref (app_related), 
g_object_unref);
-                        label = gtk_label_new (gs_app_get_metadata_item (app_related, "package-name"));
+                        label = gtk_label_new (gs_app_get_source (app_related));
                         g_object_set (label,
                                       "margin-left", 20,
                                       "margin-right", 20,
@@ -277,7 +277,7 @@ show_update_details (GsApp *app, GsShellUpdates *shell_updates)
                         gtk_widget_set_halign (label, GTK_ALIGN_START);
                         gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
                         gtk_box_pack_start (GTK_BOX (row), label, TRUE, TRUE, 0);
-                        label = gtk_label_new (gs_app_get_version (app_related));
+                        label = gtk_label_new (gs_app_get_update_version (app_related));
                         g_object_set (label,
                                       "margin-left", 20,
                                       "margin-right", 20,
diff --git a/src/plugins/README.md b/src/plugins/README.md
index 7d834ce..a3ac272 100644
--- a/src/plugins/README.md
+++ b/src/plugins/README.md
@@ -107,8 +107,7 @@ Overview:    | <p>
 -------------|---
 Methods:     | Search, AddUpdates, AddInstalled, AppInstall, AppRemove, AppUpdate
 Requires:    | `{package-id}`
-Refines:     | `nothing`
-Refines:     | `{package-id}`, `{package-name}`, `{package-summary}`, `{update-name}`, `{update-details}`, 
`{install-kind}`
+Refines:     | `{package-id}`, `[source]`, `{package-summary}`, `[update-details]`, `{install-kind}`
 
 ### packagekit-refine ###
 Uses the system PackageKit instance to return convert filenames to package-ids.
@@ -126,7 +125,7 @@ Overview:    | <p>
 -------------|---
 Methods:     | `nothing`
 Requires:    | `nothing`
-Refines:     | `{package-name}->{datadir-desktop-filename}`
+Refines:     | `[source]->{datadir-desktop-filename}`
 
 ### appstream ###
 Uses offline AppStream data to refine package results.
@@ -135,7 +134,7 @@ Overview:    | <p>
 -------------|---
 Methods:     | `AddCategoryApps`
 Requires:    | `nothing`
-Refines:     | `{package-name}->[name,summary,pixbuf,id,kind]`
+Refines:     | `[source]->[name,summary,pixbuf,id,kind]`
 
 ### datadir-apps ###
 Uses the files in /usr/share/applications to provide icons and, translations for
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index f17528b..78d7d6b 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -271,8 +271,8 @@ gs_plugin_refine_item (GsPlugin *plugin,
        }
 
        /* set package name */
-       if (appstream_app_get_pkgname (item) != NULL && gs_app_get_metadata_item (app, "package-name") == 
NULL)
-               gs_app_set_metadata (app, "package-name", appstream_app_get_pkgname (item));
+       if (appstream_app_get_pkgname (item) != NULL && gs_app_get_source (app) == NULL)
+               gs_app_set_source (app, appstream_app_get_pkgname (item));
 out:
        g_free (icon_path);
        if (pixbuf != NULL)
@@ -323,7 +323,7 @@ gs_plugin_refine_from_pkgname (GsPlugin *plugin,
        AppstreamApp *item;
 
        /* find anything that matches the ID */
-       pkgname = gs_app_get_metadata_item (app, "package-name");
+       pkgname = gs_app_get_source (app);
        if (pkgname == NULL)
                goto out;
        item = appstream_cache_get_item_by_pkgname (plugin->priv->cache, pkgname);
diff --git a/src/plugins/gs-plugin-desktopdb.c b/src/plugins/gs-plugin-desktopdb.c
index bc02bc2..237cf57 100644
--- a/src/plugins/gs-plugin-desktopdb.c
+++ b/src/plugins/gs-plugin-desktopdb.c
@@ -176,7 +176,7 @@ gs_plugin_refine (GsPlugin *plugin,
                app = GS_APP (l->data);
                if (gs_app_get_metadata_item (app, "datadir-desktop-filename") != NULL)
                        continue;
-               pkgname = gs_app_get_metadata_item (app, "package-name");
+               pkgname = gs_app_get_source (app);
                if (pkgname == NULL)
                        continue;
                gs_plugin_desktopdb_set_metadata (plugin, app, pkgname);
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index f315688..70dd807 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -151,7 +151,7 @@ gs_plugin_packagekit_refine_packages (GsPlugin *plugin,
        package_ids = g_new0 (const gchar *, size + 1);
        for (l = list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
-               pkgname = gs_app_get_metadata_item (app, "package-name");
+               pkgname = gs_app_get_source (app);
                package_ids[i++] = pkgname;
        }
 
@@ -184,7 +184,7 @@ gs_plugin_packagekit_refine_packages (GsPlugin *plugin,
        packages = pk_results_get_package_array (results);
        for (l = list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
-               pkgname = gs_app_get_metadata_item (app, "package-name");
+               pkgname = gs_app_get_source (app);
 
                /* find any packages that match the package name */
                cnt = 0;
@@ -303,7 +303,7 @@ gs_plugin_refine (GsPlugin *plugin,
                app = GS_APP (l->data);
                if (gs_app_get_metadata_item (app, "package-id") != NULL)
                        continue;
-               tmp = gs_app_get_metadata_item (app, "package-name");
+               tmp = gs_app_get_source (app);
                if (tmp != NULL)
                        resolve_all = g_list_prepend (resolve_all, app);
        }
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index e5bde99..44f4924 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -166,11 +166,9 @@ gs_plugin_packagekit_add_installed_results (GsPlugin *plugin,
                                     "package-id",
                                     pk_package_get_id (package));
                gs_app_set_metadata (app,
-                                    "package-name",
-                                    pk_package_get_name (package));
-               gs_app_set_metadata (app,
                                     "package-summary",
                                     pk_package_get_summary (package));
+               gs_app_set_source (app, pk_package_get_name (package));
                gs_app_set_metadata (app, "install-kind", "package");
                gs_app_set_version (app, pk_package_get_version (package));
                switch (pk_package_get_info (package)) {
@@ -341,12 +339,11 @@ gs_plugin_packagekit_add_updates_results (GsPlugin *plugin,
                              NULL);
                split = pk_package_id_split (package_id);
                app = gs_app_new (NULL);
-               gs_app_set_metadata (app, "package-id", package_id);
-               gs_app_set_metadata (app, "package-name", split[PK_PACKAGE_ID_NAME]);
-               gs_app_set_metadata (app, "update-name", split[PK_PACKAGE_ID_NAME]);
-               gs_app_set_metadata (app, "update-details", update_text);
+               gs_app_set_source (app, split[PK_PACKAGE_ID_NAME]);
+               gs_app_set_update_details (app, update_text);
+               gs_app_set_update_version (app, split[PK_PACKAGE_ID_VERSION]);
+               gs_app_set_metadata (app, "update-package-id", package_id);
                gs_app_set_metadata (app, "install-kind", "package");
-               gs_app_set_version (app, split[PK_PACKAGE_ID_VERSION]);
                gs_app_set_state (app, GS_APP_STATE_UPDATABLE);
                gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
                gs_plugin_add_app (list, app);


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