[gnome-software] Use the full ID when creating GsApp objects to prevent name clashes



commit 1b3a7555f4d1543df10bdc1d22ff841f9ca4884c
Author: Richard Hughes <richard hughsie com>
Date:   Sun Oct 27 20:47:49 2013 +0000

    Use the full ID when creating GsApp objects to prevent name clashes

 data/featured.ini.in                       |    8 +-
 src/gs-app.c                               |   25 ++++
 src/gs-app.h                               |    1 +
 src/gs-plugin-loader.c                     |    2 +-
 src/plugins/appstream-app.c                |    6 -
 src/plugins/gs-plugin-datadir-apps.c       |   23 ++--
 src/plugins/gs-plugin-desktopdb.c          |    6 +-
 src/plugins/gs-plugin-epiphany.c           |    9 +--
 src/plugins/gs-plugin-hardcoded-popular.c  |  188 ++++++++++++++--------------
 src/plugins/gs-plugin-packagekit-history.c |    4 +-
 10 files changed, 142 insertions(+), 130 deletions(-)
---
diff --git a/data/featured.ini.in b/data/featured.ini.in
index dd72945..88248f9 100644
--- a/data/featured.ini.in
+++ b/data/featured.ini.in
@@ -1,19 +1,19 @@
-[darktable]
+[darktable.desktop]
 background=url('@prefix@/share/gnome-software/featured-darktable.png') left 20% / 50% auto no-repeat, 
linear-gradient(to bottom, #393d39, #5a5e58)
 stroke=#1f2122
 text=#ffffff
 
-[gimp]
+[gimp.desktop]
 background=url('@prefix@/share/gnome-software/featured-gimp.png') left 50% / 50% auto no-repeat, 
linear-gradient(to bottom, #8ac674, #cbddc3)
 stroke=#2a6c10
 text=#000000
 
-[mypaint]
+[mypaint.desktop]
 background=url('@prefix@/share/gnome-software/featured-mypaint.png') left 67% / 50% auto no-repeat, 
linear-gradient(to bottom, #8fa5d9, #d8e0ef)
 stroke=#4c52aa
 text=#362d89
 
-[org.gnome.Weather.Application]
+[org.gnome.Weather.Application.desktop]
 background=url('@prefix@/share/gnome-software/featured-weather.png') left 80% / 50% auto no-repeat, 
url('@prefix@/share/gnome-software/featured-weather-bg.png'), linear-gradient(to bottom, #25486d, #6693ce)
 stroke=#d8e0ef
 text=#ffffff
diff --git a/src/gs-app.c b/src/gs-app.c
index cfdfcf0..9644997 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -56,6 +56,7 @@ static void   gs_app_finalize (GObject        *object);
 struct GsAppPrivate
 {
        gchar                   *id;
+       gchar                   *id_full;
        gchar                   *name;
        gchar                   *icon;
        GPtrArray               *sources;
@@ -295,14 +296,37 @@ gs_app_get_id (GsApp *app)
 }
 
 /**
+ * gs_app_get_id_full:
+ **/
+const gchar *
+gs_app_get_id_full (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       return app->priv->id_full;
+}
+
+/**
  * gs_app_set_id:
  */
 void
 gs_app_set_id (GsApp *app, const gchar *id)
 {
+       gchar *tmp;
+
        g_return_if_fail (GS_IS_APP (app));
+
+       /* save this unmolested */
+       g_free (app->priv->id_full);
+       app->priv->id_full = g_strdup (id);
+
+       /* save the short form by default */
        g_free (app->priv->id);
        app->priv->id = g_strdup (id);
+       if (app->priv->id != NULL) {
+               tmp = g_strrstr (app->priv->id, ".");
+               if (tmp != NULL)
+                       *tmp = '\0';
+       }
 }
 
 /**
@@ -1547,6 +1571,7 @@ gs_app_finalize (GObject *object)
        GsAppPrivate *priv = app->priv;
 
        g_free (priv->id);
+       g_free (priv->id_full);
        g_free (priv->name);
        g_hash_table_unref (priv->urls);
        g_free (priv->icon);
diff --git a/src/gs-app.h b/src/gs-app.h
index f6d029c..819c104 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -105,6 +105,7 @@ const gchar *gs_app_id_kind_to_string       (GsAppIdKind     id_kind);
 const gchar    *gs_app_state_to_string         (GsAppState      state);
 
 const gchar    *gs_app_get_id                  (GsApp          *app);
+const gchar    *gs_app_get_id_full             (GsApp          *app);
 void            gs_app_set_id                  (GsApp          *app,
                                                 const gchar    *id);
 GsAppKind       gs_app_get_kind                (GsApp          *app);
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index c7e00c1..5dbfc49 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -708,7 +708,7 @@ gs_plugin_loader_add_os_update_item (GList *list)
                goto out;
 
        /* create new meta object */
-       app_os = gs_app_new ("os-update");
+       app_os = gs_app_new ("os-update.virtual");
        gs_app_set_kind (app_os, GS_APP_KIND_OS_UPDATE);
        gs_app_set_state (app_os, GS_APP_STATE_UPDATABLE);
        /* TRANSLATORS: this is a group of updates that are not packages and
diff --git a/src/plugins/appstream-app.c b/src/plugins/appstream-app.c
index d6f6c96..52595db 100644
--- a/src/plugins/appstream-app.c
+++ b/src/plugins/appstream-app.c
@@ -291,13 +291,7 @@ appstream_app_set_id (AppstreamApp *app,
                      const gchar *id,
                      gsize length)
 {
-       gchar *tmp;
        app->id = g_strndup (id, length);
-
-       /* trim the extension as we only use the short form here */
-       tmp = g_strrstr (app->id, ".");
-       if (tmp != NULL)
-               *tmp = '\0';
 }
 
 /**
diff --git a/src/plugins/gs-plugin-datadir-apps.c b/src/plugins/gs-plugin-datadir-apps.c
index 323e32f..7464d05 100644
--- a/src/plugins/gs-plugin-datadir-apps.c
+++ b/src/plugins/gs-plugin-datadir-apps.c
@@ -135,10 +135,11 @@ gs_plugin_datadir_apps_extract_desktop_data (GsPlugin *plugin,
                                             const gchar *desktop_file,
                                             GError **error)
 {
-       const gchar *basename_tmp = NULL;
+       const gchar *app_id_full_noprefix;
        const gchar *icon_tmp = NULL;
        gboolean ret = TRUE;
-       gchar *basename = NULL;
+       gchar *app_id_full = NULL;
+       gchar *app_id = NULL;
        gchar *comment = NULL;
        gchar *name = NULL;
        gchar *pkgname = NULL;
@@ -168,13 +169,14 @@ gs_plugin_datadir_apps_extract_desktop_data (GsPlugin *plugin,
                goto out;
 
        /* set new id */
-       basename = g_path_get_basename (desktop_file);
-       dot = strrchr (basename, '.');
+       app_id_full = g_path_get_basename (desktop_file);
+       app_id_full_noprefix = app_id_full;
+       if (g_str_has_prefix (app_id_full_noprefix, "fedora-"))
+               app_id_full_noprefix += 7;
+       app_id = g_strdup (app_id_full_noprefix);
+       dot = strrchr (app_id, '.');
        if (dot)
                *dot = '\0';
-       basename_tmp = basename;
-       if (g_str_has_prefix (basename_tmp, "fedora-"))
-               basename_tmp += 7;
 
        /* get desktop name */
        name = g_key_file_get_locale_string (key_file,
@@ -203,7 +205,7 @@ gs_plugin_datadir_apps_extract_desktop_data (GsPlugin *plugin,
                goto out;
 
        /* do we have an icon in the cache? */
-       icon_tmp = g_hash_table_lookup (plugin->icon_cache, basename_tmp);
+       icon_tmp = g_hash_table_lookup (plugin->icon_cache, app_id);
        if (icon_tmp != NULL) {
                pixbuf = gdk_pixbuf_new_from_file (icon_tmp, NULL);
        } else {
@@ -214,7 +216,7 @@ gs_plugin_datadir_apps_extract_desktop_data (GsPlugin *plugin,
 
        /* create a new cache entry */
        cache_item = g_slice_new0 (GsPluginDataDirAppsCacheItem);
-       cache_item->id = g_strdup (basename_tmp);
+       cache_item->id = g_strdup (app_id_full_noprefix);
        cache_item->name = g_strdup (name);
        cache_item->summary = g_strdup (comment);
        cache_item->icon_name = g_strdup (icon);
@@ -240,7 +242,8 @@ out:
                g_key_file_unref (key_file);
        if (pixbuf != NULL)
                g_object_unref (pixbuf);
-       g_free (basename);
+       g_free (app_id);
+       g_free (app_id_full);
        g_free (pkgname);
        g_free (icon);
        g_free (name);
diff --git a/src/plugins/gs-plugin-desktopdb.c b/src/plugins/gs-plugin-desktopdb.c
index 4f8c589..2cbcbbf 100644
--- a/src/plugins/gs-plugin-desktopdb.c
+++ b/src/plugins/gs-plugin-desktopdb.c
@@ -89,7 +89,7 @@ gs_plugin_desktopdb_set_metadata (GsPlugin *plugin,
                                  const gchar *pkg_name)
 {
        gchar *desktop_file;
-       gchar *id = NULL, *dot;
+       gchar *id = NULL;
        GError *error = NULL;
        GPtrArray *files = NULL;
 
@@ -130,10 +130,6 @@ gs_plugin_desktopdb_set_metadata (GsPlugin *plugin,
        /* also set the ID if it's missing */
        if (gs_app_get_id (app) == NULL) {
                id = g_path_get_basename (desktop_file);
-               dot = strrchr (id, '.');
-               if (dot)
-                       *dot = '\0';
-
                gs_app_set_id (app, id);
        }
 
diff --git a/src/plugins/gs-plugin-epiphany.c b/src/plugins/gs-plugin-epiphany.c
index e7f27e7..d69a6db 100644
--- a/src/plugins/gs-plugin-epiphany.c
+++ b/src/plugins/gs-plugin-epiphany.c
@@ -93,12 +93,10 @@ gs_plugin_add_installed_file (GsPlugin *plugin,
        GKeyFile *kf;
        gboolean no_display;
        gboolean ret;
-       gchar *app_id = NULL;
        gchar *comment = NULL;
        gchar *icon = NULL;
        gchar *name = NULL;
        gchar *path;
-       gchar *tmp;
 
        /* load keyfile */
        path = g_build_filename (g_get_user_data_dir (),
@@ -150,11 +148,7 @@ gs_plugin_add_installed_file (GsPlugin *plugin,
        }
 
        /* create application */
-       app_id = g_strdup (filename);
-       tmp = g_strrstr (app_id, ".");
-       if (tmp != NULL)
-               *tmp = '\0';
-       *app = gs_app_new (app_id);
+       *app = gs_app_new (filename);
        gs_app_set_name (*app, name);
        gs_app_set_summary (*app, comment);
        /* TRANSLATORS: this is the licence of the web-app */
@@ -170,7 +164,6 @@ gs_plugin_add_installed_file (GsPlugin *plugin,
                goto out;
 out:
        g_key_file_free (kf);
-       g_free (app_id);
        g_free (path);
        g_free (icon);
        g_free (name);
diff --git a/src/plugins/gs-plugin-hardcoded-popular.c b/src/plugins/gs-plugin-hardcoded-popular.c
index 1a79c17..6d3577e 100644
--- a/src/plugins/gs-plugin-hardcoded-popular.c
+++ b/src/plugins/gs-plugin-hardcoded-popular.c
@@ -56,24 +56,24 @@ gs_plugin_add_popular (GsPlugin *plugin,
 {
        GsApp *app;
        const gchar *apps[] = {
-               "transmission-gtk",
-               "inkscape",
-               "scribus",
-               "simple-scan",
-               "tomboy",
-               "gtg",
-               "stellarium",
-               "gnome-maps",
-               "calibre",
-               "hotot-gtk",
-               "musique",
-               "sol", /* aisleriot */
-               "shutter",
-               "gnucash",
-               "iagno",
-               "mozilla-thunderbird",
-               "geary",
-               "pdfshuffler"
+               "transmission-gtk.desktop",
+               "inkscape.desktop",
+               "scribus.desktop",
+               "simple-scan.desktop",
+               "tomboy.desktop",
+               "gtg.desktop",
+               "stellarium.desktop",
+               "gnome-maps.desktop",
+               "calibre.desktop",
+               "hotot-gtk.desktop",
+               "musique.desktop",
+               "sol.desktop", /* aisleriot */
+               "shutter.desktop",
+               "gnucash.desktop",
+               "iagno.desktop",
+               "mozilla-thunderbird.desktop",
+               "geary.desktop",
+               "pdfshuffler.desktop"
        };
        gint primes[] = {
                 2,  3,  5,  7, 11, 13, 17, 19, 23, 29,
@@ -123,82 +123,82 @@ typedef struct {
 } Featured;
 
 static Featured featured[] = {
-       { "Audio", "audacity" },
-       { "Audio", "ardour2" },
-       { "Audio", "gnome-banshee" },
-       { "Audio", "rosegarden" },
-       { "Audio", "sound-juicer" },
-       { "Audio", "rhythmbox" },
-       { "Audio", "brasero" },
-       { "Game", "doom" }, // id ?
-       { "Game", "openarena" },
-       { "Game", "xonotic" },
-       { "Game", "tremulous" },
-       { "Game", "btanks" },
-       { "Game", "frozen-bubble" },
-       { "Game", "quadrapassel" },
-       { "Game", "sol" },
-       { "Game", "neverball" },
-       { "Game", "gnomine" },
-       { "Game", "wesnoth" },
-       { "Game", "supertuxkart" }, // id ?
-       { "Game", "redeclipse" },
-       { "Office", "evolution" },
-       { "Office", "geary" },
-       { "Office", "gnucash" },
-       { "Office", "abiword" },
-       { "Office", "libreoffice-calc" },
-       { "Office", "libreoffice-writer" },
-       { "Office", "libreoffice-impress" },
-       { "Office", "gnumeric" },
-       { "Office", "gramps" },
-       { "Office", "lyx" },
-       { "System", "gparted" },
-       { "System", "gnome-boxes" },
-       { "System", "virt-manager" },
-       { "System", "gnome-disks" },
-       { "Development", "glade" },
-       { "Development", "anjuta" },
-       { "Development", "d-feet" },
-       { "Development", "eclipse" },
-       { "Development", "gitg" },
-       { "Development", "monodevelop" },
-       { "Development", "gedit" },
-       { "Development", "devhelp" },
-       { "Graphics", "gimp" },
-       { "Graphics", "mypaint" },
-       { "Graphics", "blender" },
-       { "Graphics", "darktable" },
-       { "Graphics", "inkscape" },
-       { "Graphics", "libreoffice-draw" },
-       { "Graphics", "shotwell" },
-       { "Graphics", "scribus" },
-       { "Graphics", "simple-scan" },
-       { "Graphics", "gnome-font-viewer" },
-       { "Science", "stellarium" },
-       { "Science", "octave" },
-       { "Science", "saoimage" },
-       { "Utility", "gnome-documents" },
-       { "Utility", "bijiben" },
-       { "Utility", "gnome-photos" },
-       { "Utility", "workrave" },
-       { "Utility", "gnome-clocks" },
-       { "Education", "celestia" },
-       { "Network", "geary" },
-       { "Network", "mozilla-thunderbird" },
-       { "Network", "firefox" },
-       { "Network", "transmission-gtk" },
-       { "Network", "xchat" },
-       { "Network", "polari" }, // id ?
-       { "Network", "vinagre" },
-       { "Network", "epiphany" },
-       { "Network", "pidgin" },
-       { "Network", "chromium" }, // id ?
-       { "Video", "pitivi" },
-       { "Video", "vlc" }, // id ?
-       { "Video", "totem" },
-       { "Video", "openshot" }, // ?
-       { "Video", "cheese" },
+       { "Audio", "audacity.desktop" },
+       { "Audio", "ardour2.desktop" },
+       { "Audio", "gnome-banshee.desktop" },
+       { "Audio", "rosegarden.desktop" },
+       { "Audio", "sound-juicer.desktop" },
+       { "Audio", "rhythmbox.desktop" },
+       { "Audio", "brasero.desktop" },
+       { "Game", "doom.desktop" }, // id ?
+       { "Game", "openarena.desktop" },
+       { "Game", "xonotic.desktop" },
+       { "Game", "tremulous.desktop" },
+       { "Game", "btanks.desktop" },
+       { "Game", "frozen-bubble.desktop" },
+       { "Game", "quadrapassel.desktop" },
+       { "Game", "sol.desktop" },
+       { "Game", "neverball.desktop" },
+       { "Game", "gnomine.desktop" },
+       { "Game", "wesnoth.desktop" },
+       { "Game", "supertuxkart.desktop" }, // id ?
+       { "Game", "redeclipse.desktop" },
+       { "Office", "evolution.desktop" },
+       { "Office", "geary.desktop" },
+       { "Office", "gnucash.desktop" },
+       { "Office", "abiword.desktop" },
+       { "Office", "libreoffice-calc.desktop" },
+       { "Office", "libreoffice-writer.desktop" },
+       { "Office", "libreoffice-impress.desktop" },
+       { "Office", "gnumeric.desktop" },
+       { "Office", "gramps.desktop" },
+       { "Office", "lyx.desktop" },
+       { "System", "gparted.desktop" },
+       { "System", "gnome-boxes.desktop" },
+       { "System", "virt-manager.desktop" },
+       { "System", "gnome-disks.desktop" },
+       { "Development", "glade.desktop" },
+       { "Development", "anjuta.desktop" },
+       { "Development", "d-feet.desktop" },
+       { "Development", "eclipse.desktop" },
+       { "Development", "gitg.desktop" },
+       { "Development", "monodevelop.desktop" },
+       { "Development", "gedit.desktop" },
+       { "Development", "devhelp.desktop" },
+       { "Graphics", "gimp.desktop" },
+       { "Graphics", "mypaint.desktop" },
+       { "Graphics", "blender.desktop" },
+       { "Graphics", "darktable.desktop" },
+       { "Graphics", "inkscape.desktop" },
+       { "Graphics", "libreoffice-draw.desktop" },
+       { "Graphics", "shotwell.desktop" },
+       { "Graphics", "scribus.desktop" },
+       { "Graphics", "simple-scan.desktop" },
+       { "Graphics", "gnome-font-viewer.desktop" },
+       { "Science", "stellarium.desktop" },
+       { "Science", "octave.desktop" },
+       { "Science", "saoimage.desktop" },
+       { "Utility", "gnome-documents.desktop" },
+       { "Utility", "bijiben.desktop" },
+       { "Utility", "gnome-photos.desktop" },
+       { "Utility", "workrave.desktop" },
+       { "Utility", "gnome-clocks.desktop" },
+       { "Education", "celestia.desktop" },
+       { "Network", "geary.desktop" },
+       { "Network", "mozilla-thunderbird.desktop" },
+       { "Network", "firefox.desktop" },
+       { "Network", "transmission-gtk.desktop" },
+       { "Network", "xchat.desktop" },
+       { "Network", "polari.desktop" }, // id ?
+       { "Network", "vinagre.desktop" },
+       { "Network", "epiphany.desktop" },
+       { "Network", "pidgin.desktop" },
+       { "Network", "chromium.desktop" }, // id ?
+       { "Video", "pitivi.desktop" },
+       { "Video", "vlc.desktop" }, // id ?
+       { "Video", "totem.desktop" },
+       { "Video", "openshot.desktop" }, // ?
+       { "Video", "cheese.desktop" },
 };
 
 gboolean
diff --git a/src/plugins/gs-plugin-packagekit-history.c b/src/plugins/gs-plugin-packagekit-history.c
index bcf9132..7c5092d 100644
--- a/src/plugins/gs-plugin-packagekit-history.c
+++ b/src/plugins/gs-plugin-packagekit-history.c
@@ -83,7 +83,7 @@ gs_plugin_packagekit_refine_add_history (GsApp *app, GVariant *dict)
        PkInfoEnum info_enum;
 
        /* create new history item with same ID as parent */
-       history = gs_app_new (gs_app_get_id (app));
+       history = gs_app_new (gs_app_get_id_full (app));
        gs_app_set_kind (history, GS_APP_KIND_PACKAGE);
        gs_app_set_name (history, gs_app_get_name (app));
 
@@ -234,7 +234,7 @@ gs_plugin_packagekit_refine (GsPlugin *plugin,
                        /* make up a fake entry as we know this package was at
                         * least installed at some point in time */
                        if (gs_app_get_state (app) == GS_APP_STATE_INSTALLED) {
-                               app_dummy = gs_app_new (gs_app_get_id (app));
+                               app_dummy = gs_app_new (gs_app_get_id_full (app));
                                gs_app_set_install_date (app_dummy, GS_APP_INSTALL_DATE_UNKNOWN);
                                gs_app_set_kind (app_dummy, GS_APP_KIND_PACKAGE);
                                gs_app_set_state (app_dummy, GS_APP_STATE_INSTALLED);


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