[gnome-software] Split up the desktop categories plugin once again
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Split up the desktop categories plugin once again
- Date: Thu, 2 Jun 2016 14:43:58 +0000 (UTC)
commit 6aa125ea9e4858f6d6b4796309b3aab471ebe4c4
Author: Richard Hughes <richard hughsie com>
Date: Thu Jun 2 15:29:59 2016 +0100
Split up the desktop categories plugin once again
Small detail: the refine has to be run after appstream, and add_categories()
has to be run before... Which explains why we had a common file all this time.
po/POTFILES.in | 2 +-
src/gs-self-test.c | 5 +-
src/plugins/Makefile.am | 22 ++-
...-hardcoded-categories.c => gs-desktop-common.c} | 191 ++------------------
src/plugins/gs-desktop-common.h | 48 +++++
src/plugins/gs-plugin-desktop-categories.c | 125 +++++++++++++
src/plugins/gs-plugin-desktop-menu-path.c | 100 ++++++++++
7 files changed, 311 insertions(+), 182 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 003ed67..c1800b6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -59,4 +59,4 @@ src/org.gnome.Software.desktop.in
[type: gettext/glade]src/gs-popular-tile.ui
src/gs-shell-loading.c
[type: gettext/glade]src/gs-shell-loading.ui
-src/plugins/gs-plugin-hardcoded-categories.c
+src/plugins/gs-desktop-common.c
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index f981ddf..d9c5520 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -478,7 +478,7 @@ gs_plugin_loader_installed_func (GsPluginLoader *plugin_loader)
g_assert (!gs_app_has_category (app, "ImageProcessing"));
g_assert (gs_app_get_menu_path (app) != NULL);
menu_path = g_strjoinv ("->", gs_app_get_menu_path (app));
- g_assert_cmpstr (menu_path, ==, "Audio & Video->Players");
+ g_assert_cmpstr (menu_path, ==, "Audio & Video->Music Players");
/* check addon */
addons = gs_app_get_addons (app);
@@ -862,8 +862,9 @@ main (int argc, char **argv)
"flatpak-user",
"fwupd",
"hardcoded-blacklist",
+ "desktop-categories",
+ "desktop-menu-path",
"icons",
- "menu-spec-refine",
"key-colors",
"provenance",
"provenance-license",
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 813a071..2c025ad 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -30,10 +30,11 @@ plugindir = $(libdir)/gs-plugins-${GS_PLUGIN_API_VERSION}
plugin_LTLIBRARIES = \
libgs_plugin_appstream.la \
libgs_plugin_key-colors.la \
+ libgs_plugin_desktop-categories.la \
+ libgs_plugin_desktop-menu-path.la \
libgs_plugin_dummy.la \
libgs_plugin_dpkg.la \
libgs_plugin_hardcoded-blacklist.la \
- libgs_plugin_hardcoded-categories.la \
libgs_plugin_hardcoded-popular.la \
libgs_plugin_hardcoded-featured.la \
libgs_plugin_fedora-distro-upgrades.la \
@@ -209,10 +210,21 @@ libgs_plugin_steam_la_LDFLAGS = -module -avoid-version
libgs_plugin_steam_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
endif
-libgs_plugin_hardcoded_categories_la_SOURCES = gs-plugin-hardcoded-categories.c
-libgs_plugin_hardcoded_categories_la_LIBADD = $(GS_PLUGIN_LIBS)
-libgs_plugin_hardcoded_categories_la_LDFLAGS = -module -avoid-version
-libgs_plugin_hardcoded_categories_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+libgs_plugin_desktop_categories_la_SOURCES = \
+ gs-plugin-desktop-categories.c \
+ gs-desktop-common.c \
+ gs-desktop-common.h
+libgs_plugin_desktop_categories_la_LIBADD = $(GS_PLUGIN_LIBS)
+libgs_plugin_desktop_categories_la_LDFLAGS = -module -avoid-version
+libgs_plugin_desktop_categories_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+
+libgs_plugin_desktop_menu_path_la_SOURCES = \
+ gs-plugin-desktop-menu-path.c \
+ gs-desktop-common.c \
+ gs-desktop-common.h
+libgs_plugin_desktop_menu_path_la_LIBADD = $(GS_PLUGIN_LIBS)
+libgs_plugin_desktop_menu_path_la_LDFLAGS = -module -avoid-version
+libgs_plugin_desktop_menu_path_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
libgs_plugin_hardcoded_blacklist_la_SOURCES = gs-plugin-hardcoded-blacklist.c
libgs_plugin_hardcoded_blacklist_la_LIBADD = $(GS_PLUGIN_LIBS)
diff --git a/src/plugins/gs-plugin-hardcoded-categories.c b/src/plugins/gs-desktop-common.c
similarity index 64%
rename from src/plugins/gs-plugin-hardcoded-categories.c
rename to src/plugins/gs-desktop-common.c
index 401114e..bb1a900 100644
--- a/src/plugins/gs-plugin-hardcoded-categories.c
+++ b/src/plugins/gs-desktop-common.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2011-2016 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2015-2016 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -19,45 +19,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <config.h>
+#include "config.h"
-#include <gnome-software.h>
#include <glib/gi18n.h>
-/*
- * SECTION:
- * Adds categories from a hardcoded list based on the the desktop menu
- * specification.
- */
-
-void
-gs_plugin_initialize (GsPlugin *plugin)
-{
- /* need categories */
- gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "appstream");
-
- /* the old name for these plugins */
- gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "menu-spec-categories");
- gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "menu-spec-refine");
-}
-
-typedef struct {
- const gchar *id;
- const gchar *name;
- const gchar *fdo_cats[16];
-} GsCategoryMap;
-
-typedef struct {
- const gchar *id;
- GsCategoryMap *mapping;
- const gchar *name;
- const gchar *icon;
- const gchar *key_colors;
- gboolean important;
-} GsCategoryData;
+#include "gs-desktop-common.h"
/* AudioVideo */
-static const GsCategoryMap map_audiovisual[] = {
+static const GsDesktopMap map_audiovisual[] = {
{ "all", NC_("Menu of AudioVideo", "All"),
{ "AudioVideo",
NULL } },
@@ -78,7 +47,7 @@ static const GsCategoryMap map_audiovisual[] = {
};
/* Development */
-static const GsCategoryMap map_developertools[] = {
+static const GsDesktopMap map_developertools[] = {
{ "all", NC_("Menu of Development", "All"),
{ "Development",
NULL } },
@@ -96,7 +65,7 @@ static const GsCategoryMap map_developertools[] = {
};
/* Education */
-static const GsCategoryMap map_education[] = {
+static const GsDesktopMap map_education[] = {
{ "all", NC_("Menu of Education", "All"),
{ "Education",
NULL } },
@@ -121,7 +90,7 @@ static const GsCategoryMap map_education[] = {
};
/* Games */
-static const GsCategoryMap map_games[] = {
+static const GsDesktopMap map_games[] = {
{ "all", NC_("Menu of Games", "All"),
{ "Game",
NULL } },
@@ -169,7 +138,7 @@ static const GsCategoryMap map_games[] = {
};
/* Graphics */
-static const GsCategoryMap map_graphics[] = {
+static const GsDesktopMap map_graphics[] = {
{ "all", NC_("Menu of Graphics", "All"),
{ "Graphics",
NULL } },
@@ -195,7 +164,7 @@ static const GsCategoryMap map_graphics[] = {
};
/* Office */
-static const GsCategoryMap map_productivity[] = {
+static const GsDesktopMap map_productivity[] = {
{ "all", NC_("Menu of Office", "All"),
{ "Office",
NULL } },
@@ -221,7 +190,7 @@ static const GsCategoryMap map_productivity[] = {
};
/* Addons */
-static const GsCategoryMap map_addons[] = {
+static const GsDesktopMap map_addons[] = {
{ "fonts", NC_("Menu of Addons", "Fonts"),
{ "Addons::Fonts",
NULL} },
@@ -244,7 +213,7 @@ static const GsCategoryMap map_addons[] = {
};
/* Science */
-static const GsCategoryMap map_science[] = {
+static const GsDesktopMap map_science[] = {
{ "all", NC_("Menu of Science", "All"),
{ "Science",
NULL } },
@@ -272,7 +241,7 @@ static const GsCategoryMap map_science[] = {
};
/* Communication */
-static const GsCategoryMap map_communication[] = {
+static const GsDesktopMap map_communication[] = {
{ "all", NC_("Menu of Communication", "All"),
{ "Network",
NULL } },
@@ -297,7 +266,7 @@ static const GsCategoryMap map_communication[] = {
};
/* Utility */
-static const GsCategoryMap map_utilities[] = {
+static const GsDesktopMap map_utilities[] = {
{ "all", NC_("Menu of Utility", "All"),
{ "Utility",
NULL } },
@@ -311,7 +280,7 @@ static const GsCategoryMap map_utilities[] = {
};
/* main categories */
-static const GsCategoryData msdata[] = {
+static const GsDesktopData msdata[] = {
/* TRANSLATORS: this is the menu spec main category for Audio & Video */
{ "audio-video", map_audiovisual, N_("Audio & Video"),
"folder-music-symbolic", "#215d9c", TRUE },
@@ -345,134 +314,8 @@ static const GsCategoryData msdata[] = {
{ NULL }
};
-gboolean
-gs_plugin_add_categories (GsPlugin *plugin,
- GPtrArray *list,
- GCancellable *cancellable,
- GError **error)
-{
- gchar msgctxt[100];
- guint i, j, k;
-
- for (i = 0; msdata[i].id != NULL; i++) {
- GdkRGBA key_color;
- GsCategory *category;
-
- /* add parent category */
- category = gs_category_new (msdata[i].id);
- gs_category_set_icon (category, msdata[i].icon);
- gs_category_set_name (category, gettext (msdata[i].name));
- gs_category_set_important (category, msdata[i].important);
- if (gdk_rgba_parse (&key_color, msdata[i].key_colors))
- gs_category_add_key_color (category, &key_color);
- g_ptr_array_add (list, category);
- g_snprintf (msgctxt, sizeof(msgctxt),
- "Menu subcategory of %s", msdata[i].name);
-
- /* add subcategories */
- for (j = 0; msdata[i].mapping[j].id != NULL; j++) {
- const GsCategoryMap *map = &msdata[i].mapping[j];
- g_autoptr(GsCategory) sub = gs_category_new (map->id);
- for (k = 0; map->fdo_cats[k] != NULL; k++)
- gs_category_add_desktop_group (sub, map->fdo_cats[k]);
- gs_category_set_name (sub, g_dpgettext2 (GETTEXT_PACKAGE,
- msgctxt,
- map->name));
- gs_category_add_child (category, sub);
- }
- }
- return TRUE;
-}
-
-/* most of this time this won't be required, unless the user creates a
- * GsCategory manually and uses it to get results, for instance in the
- * overview page or `gnome-software-cmd get-category-apps games/featured` */
-gboolean
-gs_plugin_add_category_apps (GsPlugin *plugin,
- GsCategory *category,
- GsAppList *list,
- GCancellable *cancellable,
- GError **error)
+const GsDesktopData *
+gs_desktop_get_data (void)
{
- GPtrArray *desktop_groups;
- GsCategory *parent;
- guint i, j, k;
-
- /* already set */
- desktop_groups = gs_category_get_desktop_groups (category);
- if (desktop_groups->len > 0)
- return TRUE;
-
- /* not valid */
- parent = gs_category_get_parent (category);
- if (parent == NULL)
- return TRUE;
-
- /* find desktop_groups for a parent::child category */
- for (i = 0; msdata[i].id != NULL; i++) {
- if (g_strcmp0 (gs_category_get_id (parent), msdata[i].id) != 0)
- continue;
- for (j = 0; msdata[i].mapping[j].id != NULL; j++) {
- const GsCategoryMap *map = &msdata[i].mapping[j];
- if (g_strcmp0 (gs_category_get_id (category), map->id) != 0)
- continue;
- for (k = 0; map->fdo_cats[k] != NULL; k++)
- gs_category_add_desktop_group (category, map->fdo_cats[k]);
- }
- }
- return TRUE;
-}
-
-static gboolean
-_gs_app_has_desktop_group (GsApp *app, const gchar *desktop_group)
-{
- guint i;
- g_auto(GStrv) split = g_strsplit (desktop_group, "::", -1);
- for (i = 0; split[i] != NULL; i++) {
- if (!gs_app_has_category (app, split[i]))
- return FALSE;
- }
- return TRUE;
-}
-
-/* adds the menu-path for applications */
-gboolean
-gs_plugin_refine_app (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- gboolean found = FALSE;
- guint i, j, k;
- const gchar *strv[] = { "", NULL, NULL };
-
- /* nothing to do here */
- if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH) == 0)
- return TRUE;
- if (gs_app_get_menu_path (app) != NULL)
- return TRUE;
-
- /* find a top level category the app has */
- for (i = 0; !found && msdata[i].id != NULL; i++) {
- GsCategoryData *data = &msdata[i];
- for (j = 0; !found && data->mapping[j].id != NULL; j++) {
- GsCategoryMap *map = &data->mapping[j];
- if (g_strcmp0 (map->id, "featured") == 0)
- continue;
- for (k = 0; !found && map->fdo_cats[k] != NULL; k++) {
- const gchar *tmp = msdata[i].mapping[j].fdo_cats[k];
- if (_gs_app_has_desktop_group (app, tmp)) {
- strv[0] = msdata[i].name;
- strv[1] = msdata[i].mapping[j].name;
- found = TRUE;
- break;
- }
- }
- }
- }
-
- /* always set something to avoid keep searching for this */
- gs_app_set_menu_path (app, (gchar **) strv);
- return TRUE;
+ return msdata;
}
diff --git a/src/plugins/gs-desktop-common.h b/src/plugins/gs-desktop-common.h
new file mode 100644
index 0000000..40fd254
--- /dev/null
+++ b/src/plugins/gs-desktop-common.h
@@ -0,0 +1,48 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011-2016 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __GS_DESKTOP_GROUP_H
+#define __GS_DESKTOP_GROUP_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct {
+ const gchar *id;
+ const gchar *name;
+ const gchar *fdo_cats[16];
+} GsDesktopMap;
+
+typedef struct {
+ const gchar *id;
+ GsDesktopMap *mapping;
+ const gchar *name;
+ const gchar *icon;
+ const gchar *key_colors;
+ gboolean important;
+} GsDesktopData;
+
+const GsDesktopData *gs_desktop_get_data (void);
+
+G_END_DECLS
+
+#endif /* __GS_DESKTOP_GROUP_H */
diff --git a/src/plugins/gs-plugin-desktop-categories.c b/src/plugins/gs-plugin-desktop-categories.c
new file mode 100644
index 0000000..5a2d9f9
--- /dev/null
+++ b/src/plugins/gs-plugin-desktop-categories.c
@@ -0,0 +1,125 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011-2016 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <gnome-software.h>
+#include <glib/gi18n.h>
+
+#include "gs-desktop-common.h"
+
+/*
+ * SECTION:
+ * Adds categories from a hardcoded list based on the the desktop menu
+ * specification.
+ */
+
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+ /* need categories */
+ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "appstream");
+
+ /* the old name for this plugin */
+ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "menu-spec-categories");
+}
+
+gboolean
+gs_plugin_add_categories (GsPlugin *plugin,
+ GPtrArray *list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const GsDesktopData *msdata;
+ gchar msgctxt[100];
+ guint i, j, k;
+
+ msdata = gs_desktop_get_data ();
+ for (i = 0; msdata[i].id != NULL; i++) {
+ GdkRGBA key_color;
+ GsCategory *category;
+
+ /* add parent category */
+ category = gs_category_new (msdata[i].id);
+ gs_category_set_icon (category, msdata[i].icon);
+ gs_category_set_name (category, gettext (msdata[i].name));
+ gs_category_set_important (category, msdata[i].important);
+ if (gdk_rgba_parse (&key_color, msdata[i].key_colors))
+ gs_category_add_key_color (category, &key_color);
+ g_ptr_array_add (list, category);
+ g_snprintf (msgctxt, sizeof(msgctxt),
+ "Menu subcategory of %s", msdata[i].name);
+
+ /* add subcategories */
+ for (j = 0; msdata[i].mapping[j].id != NULL; j++) {
+ const GsDesktopMap *map = &msdata[i].mapping[j];
+ g_autoptr(GsCategory) sub = gs_category_new (map->id);
+ for (k = 0; map->fdo_cats[k] != NULL; k++)
+ gs_category_add_desktop_group (sub, map->fdo_cats[k]);
+ gs_category_set_name (sub, g_dpgettext2 (GETTEXT_PACKAGE,
+ msgctxt,
+ map->name));
+ gs_category_add_child (category, sub);
+ }
+ }
+ return TRUE;
+}
+
+/* most of this time this won't be required, unless the user creates a
+ * GsCategory manually and uses it to get results, for instance in the
+ * overview page or `gnome-software-cmd get-category-apps games/featured` */
+gboolean
+gs_plugin_add_category_apps (GsPlugin *plugin,
+ GsCategory *category,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GPtrArray *desktop_groups;
+ GsCategory *parent;
+ const GsDesktopData *msdata;
+ guint i, j, k;
+
+ /* already set */
+ desktop_groups = gs_category_get_desktop_groups (category);
+ if (desktop_groups->len > 0)
+ return TRUE;
+
+ /* not valid */
+ parent = gs_category_get_parent (category);
+ if (parent == NULL)
+ return TRUE;
+
+ /* find desktop_groups for a parent::child category */
+ msdata = gs_desktop_get_data ();
+ for (i = 0; msdata[i].id != NULL; i++) {
+ if (g_strcmp0 (gs_category_get_id (parent), msdata[i].id) != 0)
+ continue;
+ for (j = 0; msdata[i].mapping[j].id != NULL; j++) {
+ const GsDesktopMap *map = &msdata[i].mapping[j];
+ if (g_strcmp0 (gs_category_get_id (category), map->id) != 0)
+ continue;
+ for (k = 0; map->fdo_cats[k] != NULL; k++)
+ gs_category_add_desktop_group (category, map->fdo_cats[k]);
+ }
+ }
+ return TRUE;
+}
diff --git a/src/plugins/gs-plugin-desktop-menu-path.c b/src/plugins/gs-plugin-desktop-menu-path.c
new file mode 100644
index 0000000..4bb059a
--- /dev/null
+++ b/src/plugins/gs-plugin-desktop-menu-path.c
@@ -0,0 +1,100 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011-2016 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <gnome-software.h>
+
+#include "gs-desktop-common.h"
+
+/*
+ * SECTION:
+ * Adds categories from a hardcoded list based on the the desktop menu
+ * specification.
+ */
+
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+ /* need categories */
+ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
+
+ /* the old name for this plugin */
+ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "menu-spec-refine");
+}
+
+static gboolean
+_gs_app_has_desktop_group (GsApp *app, const gchar *desktop_group)
+{
+ guint i;
+ g_auto(GStrv) split = g_strsplit (desktop_group, "::", -1);
+ for (i = 0; split[i] != NULL; i++) {
+ if (!gs_app_has_category (app, split[i]))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/* adds the menu-path for applications */
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const gchar *strv[] = { "", NULL, NULL };
+ const GsDesktopData *msdata;
+ gboolean found = FALSE;
+ guint i, j, k;
+
+ /* nothing to do here */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH) == 0)
+ return TRUE;
+ if (gs_app_get_menu_path (app) != NULL)
+ return TRUE;
+
+ /* find a top level category the app has */
+ msdata = gs_desktop_get_data ();
+ for (i = 0; !found && msdata[i].id != NULL; i++) {
+ GsDesktopData *data = &msdata[i];
+ for (j = 0; !found && data->mapping[j].id != NULL; j++) {
+ GsDesktopMap *map = &data->mapping[j];
+ if (g_strcmp0 (map->id, "all") == 0)
+ continue;
+ if (g_strcmp0 (map->id, "featured") == 0)
+ continue;
+ for (k = 0; !found && map->fdo_cats[k] != NULL; k++) {
+ const gchar *tmp = msdata[i].mapping[j].fdo_cats[k];
+ if (_gs_app_has_desktop_group (app, tmp)) {
+ strv[0] = msdata[i].name;
+ strv[1] = msdata[i].mapping[j].name;
+ found = TRUE;
+ break;
+ }
+ }
+ }
+ }
+
+ /* always set something to avoid keep searching for this */
+ gs_app_set_menu_path (app, (gchar **) strv);
+ return TRUE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]