Commit cb100d10 authored by Robert Ancell's avatar Robert Ancell

[snap-store] Replace XDG categories with Snap sections

Note this removes the featured categories from the home page. This can
be added back by making new snap "games-featured" sections.
parent 17aa97ca
Pipeline #37522 passed with stage
in 9 minutes and 19 seconds
......@@ -19,3 +19,4 @@ option('snap', type : 'boolean', value : false, description : 'enable Snap suppo
option('external_appstream', type : 'boolean', value : false, description : 'enable external AppStream support')
option('valgrind', type : 'boolean', value : true, description : 'enable Valgrind debugging integration')
option('gtk_doc', type : 'boolean', value : true, description : 'enable API reference')
option('desktop_categories', type : 'boolean', value : true, description : 'enable desktop categories support')
......@@ -95,21 +95,23 @@ shared_module(
dependencies : plugin_libs
)
shared_module(
'gs_plugin_desktop-categories',
sources : [
'gs-plugin-desktop-categories.c',
'gs-desktop-common.c',
],
include_directories : [
include_directories('../..'),
include_directories('../../lib'),
],
install : true,
install_dir: plugin_dir,
c_args : cargs,
dependencies : plugin_libs
)
if get_option('desktop_categories')
shared_module(
'gs_plugin_desktop-categories',
sources : [
'gs-plugin-desktop-categories.c',
'gs-desktop-common.c',
],
include_directories : [
include_directories('../..'),
include_directories('../../lib'),
],
install : true,
install_dir: plugin_dir,
c_args : cargs,
dependencies : plugin_libs
)
endif
shared_module(
'gs_plugin_desktop-menu-path',
......
......@@ -112,6 +112,99 @@ gs_plugin_initialize (GsPlugin *plugin)
gs_plugin_set_appstream_id (plugin, "org.gnome.Software.Plugin.Snap");
}
gboolean
gs_plugin_add_categories (GsPlugin *plugin,
GPtrArray *list,
GCancellable *cancellable,
GError **error)
{
g_autoptr(SnapdClient) client = NULL;
g_auto(GStrv) sections = NULL;
guint i;
client = get_client (plugin, error);
if (client == NULL)
return FALSE;
sections = snapd_client_get_sections_sync (client, cancellable, error);
if (sections == NULL)
return FALSE;
for (i = 0; sections[i] != NULL; i++) {
const gchar *section = sections[i];
const gchar *name, *icon = NULL, *color = NULL;
GdkRGBA key_color;
GsCategory *category;
g_autoptr(GsCategory) sub = NULL;
// skip the featured section - that is used for editors picks
if (g_strcmp0 (section, "featured") == 0)
continue;
// hard-coded metadata for each section
category = gs_category_new (section);
if (g_strcmp0 (section, "games") == 0) {
name = gettext ("Games");
icon = "applications-games-symbolic";
color = "#c4a000";
} else if (g_strcmp0 (section, "finance") == 0) {
name = gettext ("Finance");
icon = "accessories-calculator-symbolic"; // FIXME: Need a better coin / note / currency symbol icon
color = "#4e9a06";
} else if (g_strcmp0 (section, "developers") == 0) {
name = gettext ("Developers");
icon = "applications-engineering-symbolic";
color = "#d3d7c7";
} else if (g_strcmp0 (section, "social-networking") == 0) {
name = gettext ("Social Networking");
icon = "user-available-symbolic";
color = "#729fcf";
} else if (g_strcmp0 (section, "video") == 0) {
name = gettext ("Video");
icon = "folder-videos-symbolic";
color = "#215d9c";
} else if (g_strcmp0 (section, "music") == 0) {
name = gettext ("Music");
icon = "folder-music-symbolic";
color = "#215d9c";
} else if (g_strcmp0 (section, "productivity") == 0) {
name = gettext ("Productivity");
icon = "text-editor-symbolic";
color = "#cc0000";
} else if (g_strcmp0 (section, "utilities") == 0) {
name = gettext ("Utilities");
icon = "applications-utilities-symbolic";
color = "#d3d7c7";
} else if (g_strcmp0 (section, "graphics") == 0) {
name = gettext ("Graphics");
icon = "applications-graphics-symbolic";
color = "#75507b";
} else if (g_strcmp0 (section, "server") == 0) {
name = gettext ("Server");
icon = "network-server-symbolic";
color = "#d3d7c7";
} else
name = section;
gs_category_set_name (category, name);
if (icon != NULL)
gs_category_set_icon (category, icon);
gs_category_set_score (category, -i);
if (color != NULL && gdk_rgba_parse (&key_color, color))
gs_category_add_key_color (category, &key_color);
g_ptr_array_add (list, category);
sub = gs_category_new ("all");
gs_category_set_name (sub, gettext ("All"));
gs_category_add_child (category, sub);
// we don't know how many snaps are in this category but we need to tell g-s
// there's at least one so it tries to load them
gs_category_increment_size (category);
}
return TRUE;
}
void
gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
{
......@@ -542,50 +635,25 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
GsCategory *c;
g_autoptr(GString) id = NULL;
const gchar *sections = NULL;
id = g_string_new ("");
for (c = category; c != NULL; c = gs_category_get_parent (c)) {
if (c != category)
g_string_prepend (id, "/");
g_string_prepend (id, gs_category_get_id (c));
}
g_autoptr(GPtrArray) snaps = NULL;
const gchar *id;
guint i;
if (strcmp (id->str, "games/featured") == 0)
sections = "games";
else if (strcmp (id->str, "audio-video/featured") == 0)
sections = "music;video";
else if (strcmp (id->str, "graphics/featured") == 0)
sections = "graphics";
else if (strcmp (id->str, "communication/featured") == 0)
sections = "social-networking";
else if (strcmp (id->str, "productivity/featured") == 0)
sections = "productivity;finance";
else if (strcmp (id->str, "developer-tools/featured") == 0)
sections = "developers";
else if (strcmp (id->str, "utilities/featured") == 0)
sections = "utilities";
if (sections != NULL) {
g_auto(GStrv) tokens = NULL;
int i;
tokens = g_strsplit (sections, ";", -1);
for (i = 0; tokens[i] != NULL; i++) {
g_autoptr(GPtrArray) snaps = NULL;
guint j;
// we only populate the "all" subcategory
if (gs_category_get_parent (category) == NULL)
return TRUE;
if (g_strcmp0 (gs_category_get_id (category), "all") != 0)
return TRUE;
id = gs_category_get_id (gs_category_get_parent (category));
snaps = find_snaps (plugin, SNAPD_FIND_FLAGS_SCOPE_WIDE, tokens[i], NULL, cancellable, error);
if (snaps == NULL)
return FALSE;
for (j = 0; j < snaps->len; j++) {
g_autoptr(GsApp) app = snap_to_app (plugin, g_ptr_array_index (snaps, j));
gs_app_list_add (list, app);
}
}
snaps = find_snaps (plugin, SNAPD_FIND_FLAGS_SCOPE_WIDE, id, NULL, cancellable, error);
if (snaps == NULL)
return FALSE;
for (i = 0; i < snaps->len; i++) {
g_autoptr(GsApp) app = snap_to_app (plugin, g_ptr_array_index (snaps, i));
gs_app_list_add (list, app);
}
return TRUE;
}
......
......@@ -116,6 +116,7 @@ parts:
- -Dtests=false
- -Dgtk_doc=false
- -Dvalgrind=false
- -Ddesktop_categories=false
organize:
snap/snap-store/current/usr: usr
build-packages:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment