[gnome-software] GsApp: menu_path is an array of strings, no longer a single string



commit ca8d9910ec3fe7e9032eec2c2be71f997ab9c59f
Author: Rafal Luzynski <digitalfreak lingonborough com>
Date:   Tue Sep 1 02:19:06 2015 +0200

    GsApp: menu_path is an array of strings, no longer a single string
    
    This change allows for more precise control of whether the menu path
    elements are displayed as separated with a right-pointing-arrow
    or a left-pointing-arrow depending on the LTR or RTL text direction
    required by the GUI.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754210
    
    Signed-off-by: Richard Hughes <richard hughsie com>

 src/gs-app.c                             |   30 ++++++++++++++++++++++--------
 src/gs-app.h                             |    4 ++--
 src/gs-shell-details.c                   |   12 +++++++++---
 src/plugins/gs-plugin-menu-spec-refine.c |   16 +++++++---------
 4 files changed, 40 insertions(+), 22 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index a988ea1..ed93649 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -74,7 +74,7 @@ struct _GsApp
        GPtrArray               *keywords;
        GHashTable              *urls;
        gchar                   *licence;
-       gchar                   *menu_path;
+       gchar                   **menu_path;
        gchar                   *origin;
        gchar                   *update_version;
        gchar                   *update_version_ui;
@@ -274,8 +274,12 @@ gs_app_to_string (GsApp *app)
                g_string_append_printf (str, "\tlicence:\t%s\n", app->licence);
        if (app->summary_missing != NULL)
                g_string_append_printf (str, "\tsummary-missing:\t%s\n", app->summary_missing);
-       if (app->menu_path != NULL && app->menu_path[0] != '\0')
-               g_string_append_printf (str, "\tmenu-path:\t%s\n", app->menu_path);
+       if (app->menu_path != NULL &&
+           app->menu_path[0] != NULL &&
+           app->menu_path[0][0] != '\0') {
+               g_autofree gchar *path = g_strjoinv (" → ", app->menu_path);
+               g_string_append_printf (str, "\tmenu-path:\t%s\n", path);
+       }
        if (app->origin != NULL && app->origin[0] != '\0')
                g_string_append_printf (str, "\torigin:\t%s\n", app->origin);
        if (app->rating != -1)
@@ -1358,8 +1362,14 @@ gs_app_set_summary_missing (GsApp *app, const gchar *summary_missing)
 
 /**
  * gs_app_get_menu_path:
+ *
+ * Returns the menu path which is an array of path elements.
+ * The resulting array is an internal structure and must not be
+ * modified or freed.
+ *
+ * Returns: a %NULL-terminated array of strings.
  */
-const gchar *
+gchar **
 gs_app_get_menu_path (GsApp *app)
 {
        g_return_val_if_fail (GS_IS_APP (app), NULL);
@@ -1368,13 +1378,17 @@ gs_app_get_menu_path (GsApp *app)
 
 /**
  * gs_app_set_menu_path:
+ * @menu_path: a %NULL-terminated array of strings
+ *
+ * Sets the new menu path. The menu path is an array of path elements.
+ * This function creates a deep copy of the path.
  */
 void
-gs_app_set_menu_path (GsApp *app, const gchar *menu_path)
+gs_app_set_menu_path (GsApp *app, gchar **menu_path)
 {
        g_return_if_fail (GS_IS_APP (app));
-       g_free (app->menu_path);
-       app->menu_path = g_strdup (menu_path);
+       g_strfreev (app->menu_path);
+       app->menu_path = g_strdupv (menu_path);
 }
 
 /**
@@ -2180,7 +2194,7 @@ gs_app_finalize (GObject *object)
        g_free (app->name);
        g_hash_table_unref (app->urls);
        g_free (app->licence);
-       g_free (app->menu_path);
+       g_strfreev (app->menu_path);
        g_free (app->origin);
        g_ptr_array_unref (app->sources);
        g_ptr_array_unref (app->source_ids);
diff --git a/src/gs-app.h b/src/gs-app.h
index 82d40d3..af985bc 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -158,9 +158,9 @@ void                 gs_app_set_url                 (GsApp          *app,
 const gchar    *gs_app_get_licence             (GsApp          *app);
 void            gs_app_set_licence             (GsApp          *app,
                                                 const gchar    *licence);
-const gchar    *gs_app_get_menu_path           (GsApp          *app);
+gchar          **gs_app_get_menu_path          (GsApp          *app);
 void            gs_app_set_menu_path           (GsApp          *app,
-                                                const gchar    *menu_path);
+                                                gchar          **menu_path);
 const gchar    *gs_app_get_origin              (GsApp          *app);
 void            gs_app_set_origin              (GsApp          *app,
                                                 const gchar    *origin);
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 193b65d..d55da51 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -525,6 +525,7 @@ gs_shell_details_refresh_all (GsShellDetails *self)
        GList *addons;
        GtkWidget *widget;
        const gchar *tmp;
+       gchar **menu_path;
        guint64 updated;
        g_autoptr(GError) error = NULL;
 
@@ -640,13 +641,18 @@ gs_shell_details_refresh_all (GsShellDetails *self)
        }
 
        /* set the category */
-       tmp = gs_app_get_menu_path (self->app);
-       if (tmp == NULL || tmp[0] == '\0') {
+       menu_path = gs_app_get_menu_path (self->app);
+       if (menu_path == NULL || menu_path[0] == NULL || menu_path[0][0] == '\0') {
                /* TRANSLATORS: this is the application isn't in any
                 * defined menu category */
                gtk_label_set_label (GTK_LABEL (self->label_details_category_value), C_("menu category", 
"None"));
        } else {
-               gtk_label_set_label (GTK_LABEL (self->label_details_category_value), tmp);
+               g_autofree gchar *path;
+               if (gtk_widget_get_direction (self->label_details_category_value) == GTK_TEXT_DIR_RTL)
+                       path = g_strjoinv (" ← ", menu_path);
+               else
+                       path = g_strjoinv (" → ", menu_path);
+               gtk_label_set_label (GTK_LABEL (self->label_details_category_value), path);
        }
 
        /* set the origin */
diff --git a/src/plugins/gs-plugin-menu-spec-refine.c b/src/plugins/gs-plugin-menu-spec-refine.c
index a83e0c7..8335c57 100644
--- a/src/plugins/gs-plugin-menu-spec-refine.c
+++ b/src/plugins/gs-plugin-menu-spec-refine.c
@@ -57,6 +57,7 @@ gs_plugin_refine_app_category (GsPlugin *plugin,
                               GsApp *app,
                               const MenuSpecData *cat)
 {
+       const gchar *menu_path[] = { NULL, NULL, NULL };
        const MenuSpecData *msdata;
        gboolean ret = FALSE;
        gchar *tmp;
@@ -72,20 +73,16 @@ gs_plugin_refine_app_category (GsPlugin *plugin,
                        continue;
                ret = gs_app_has_category (app, tmp + 2);
                if (ret) {
-                       g_autofree gchar *str = NULL;
                        g_autofree gchar *msgctxt = NULL;
                        msgctxt = g_strdup_printf ("Menu subcategory of %s", cat->text);
-                       str = g_strdup_printf ("%s → %s",
-                                              gettext (cat->text),
-                                              g_dpgettext2 (GETTEXT_PACKAGE, msgctxt, msdata[i].text));
-                       gs_app_set_menu_path (app, str);
+                       menu_path[1] = g_dpgettext2 (GETTEXT_PACKAGE, msgctxt, msdata[i].text);
                        break;
                }
        }
 
-       /* if we've failed to find a matching sub-level category, just show the top-level */
-       if (!ret)
-               gs_app_set_menu_path (app, gettext (cat->text));
+       /* the top-level category always exists */
+       menu_path[0] = gettext (cat->text);
+       gs_app_set_menu_path (app, (gchar **) menu_path);
 }
 
 /**
@@ -127,6 +124,7 @@ gs_plugin_refine (GsPlugin *plugin,
 {
        GList *l;
        GsApp *app;
+       const gchar *EMPTY[] = { "", NULL };
 
        /* nothing to do here */
        if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH) == 0)
@@ -137,7 +135,7 @@ gs_plugin_refine (GsPlugin *plugin,
                if (gs_app_get_menu_path (app) == NULL) {
                        if (!gs_plugin_refine_app (plugin, app)) {
                                /* don't keep searching for this */
-                               gs_app_set_menu_path (app, "");
+                               gs_app_set_menu_path (app, (gchar **) EMPTY);
                        }
                }
        }


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