diff options
author | Richard Hughes <richard@hughsie.com> | 2015-06-16 15:56:48 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2015-06-16 15:57:15 +0100 |
commit | 5f58ca667a9de9a99aa206217d9cdb9bc031c0de (patch) | |
tree | a0cc14c15f92c60ac8ac879052c8b43765279cb5 | |
parent | 9a800edc216cb171db5cd2099044dce62fa815eb (diff) | |
download | appstream-glib-5f58ca667a9de9a99aa206217d9cdb9bc031c0de.tar.gz |
Add a flag to use non-optimal data sources when building metadata
This could be, for example, using the desktop GenericName in the place of
Comment or <summary> for a one line summary.
-rw-r--r-- | client/as-builder.c | 4 | ||||
-rw-r--r-- | libappstream-builder/asb-context.h | 2 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-desktop.c | 11 | ||||
-rw-r--r-- | libappstream-glib/as-app-desktop.c | 49 | ||||
-rw-r--r-- | libappstream-glib/as-app.h | 2 |
5 files changed, 63 insertions, 5 deletions
diff --git a/client/as-builder.c b/client/as-builder.c index 96372f3..685e9ec 100644 --- a/client/as-builder.c +++ b/client/as-builder.c @@ -309,6 +309,10 @@ main (int argc, char **argv) flags |= ASB_CONTEXT_FLAG_IGNORE_SETTINGS; continue; } + if (g_strcmp0 (veto_ignore[i], "use-fallbacks") == 0) { + flags |= ASB_CONTEXT_FLAG_USE_FALLBACKS; + continue; + } g_warning ("Unknown flag name: %s, " "expected 'missing-info' or 'missing-parents'", veto_ignore[i]); diff --git a/libappstream-builder/asb-context.h b/libappstream-builder/asb-context.h index 29a75e1..0c801d2 100644 --- a/libappstream-builder/asb-context.h +++ b/libappstream-builder/asb-context.h @@ -73,6 +73,7 @@ struct _AsbContextClass * @ASB_CONTEXT_FLAG_IGNORE_OBSOLETE_DEPS: Include apps that use obsolete toolkits * @ASB_CONTEXT_FLAG_IGNORE_LEGACY_ICONS: Include apps that use legacy icon formats * @ASB_CONTEXT_FLAG_IGNORE_SETTINGS: Include apps that are marked as settings + * @ASB_CONTEXT_FLAG_USE_FALLBACKS: Fall back to suboptimal data where required * * The flags to use when processing the context. **/ @@ -90,6 +91,7 @@ typedef enum { ASB_CONTEXT_FLAG_IGNORE_OBSOLETE_DEPS = 1 << 8, /* Since: 0.4.1 */ ASB_CONTEXT_FLAG_IGNORE_LEGACY_ICONS = 1 << 9, /* Since: 0.4.1 */ ASB_CONTEXT_FLAG_IGNORE_SETTINGS = 1 << 10, /* Since: 0.4.1 */ + ASB_CONTEXT_FLAG_USE_FALLBACKS = 1 << 11, /* Since: 0.4.1 */ /*< private >*/ ASB_CONTEXT_FLAG_LAST, } AsbContextFlags; diff --git a/libappstream-builder/plugins/asb-plugin-desktop.c b/libappstream-builder/plugins/asb-plugin-desktop.c index 22ecd42..16d294c 100644 --- a/libappstream-builder/plugins/asb-plugin-desktop.c +++ b/libappstream-builder/plugins/asb-plugin-desktop.c @@ -312,22 +312,23 @@ asb_plugin_process_filename (AsbPlugin *plugin, GError **error) { AsIcon *icon; + AsAppParseFlags parse_flags = AS_APP_PARSE_FLAG_USE_HEURISTICS; gboolean ret; _cleanup_free_ gchar *app_id = NULL; _cleanup_free_ gchar *full_filename = NULL; _cleanup_object_unref_ AsbApp *app = NULL; _cleanup_object_unref_ GdkPixbuf *pixbuf = NULL; + /* use GenericName fallback */ + if (asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_USE_FALLBACKS)) + parse_flags |= AS_APP_PARSE_FLAG_USE_FALLBACKS; + /* create app */ app_id = g_path_get_basename (filename); app = asb_app_new (pkg, app_id); asb_app_set_hidpi_enabled (app, asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_HIDPI_ICONS)); full_filename = g_build_filename (tmpdir, filename, NULL); - ret = as_app_parse_file (AS_APP (app), - full_filename, - AS_APP_PARSE_FLAG_USE_HEURISTICS, - error); - if (!ret) + if (!as_app_parse_file (AS_APP (app), full_filename, parse_flags, error)) return FALSE; /* NoDisplay apps are never included */ diff --git a/libappstream-glib/as-app-desktop.c b/libappstream-glib/as-app-desktop.c index a122867..f2b3690 100644 --- a/libappstream-glib/as-app-desktop.c +++ b/libappstream-glib/as-app-desktop.c @@ -320,6 +320,43 @@ as_app_parse_file_key (AsApp *app, } /** + * as_app_parse_file_key_fallback_comment: + **/ +static gboolean +as_app_parse_file_key_fallback_comment (AsApp *app, + GKeyFile *kf, + const gchar *key, + GError **error) +{ + _cleanup_free_ gchar *locale = NULL; + _cleanup_free_ gchar *tmp = NULL; + + /* GenericName */ + if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME) == 0 || + g_strcmp0 (key, "_GenericName") == 0) { + tmp = g_key_file_get_string (kf, + G_KEY_FILE_DESKTOP_GROUP, + key, + NULL); + if (tmp != NULL && tmp[0] != '\0') + as_app_set_comment (app, "C", tmp, -1); + + /* GenericName[] */ + } else if (g_str_has_prefix (key, G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME)) { + locale = as_app_desktop_key_get_locale (key); + tmp = g_key_file_get_locale_string (kf, + G_KEY_FILE_DESKTOP_GROUP, + G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME, + locale, + NULL); + if (tmp != NULL && tmp[0] != '\0') + as_app_set_comment (app, locale, tmp, -1); + } + + return TRUE; +} + +/** * as_app_parse_desktop_file: **/ gboolean @@ -377,6 +414,18 @@ as_app_parse_desktop_file (AsApp *app, } } + /* perform any fallbacks */ + if ((flags & AS_APP_PARSE_FLAG_USE_FALLBACKS) > 0 && + as_app_get_comment_size (app) == 0) { + for (i = 0; keys[i] != NULL; i++) { + if (!as_app_parse_file_key_fallback_comment (app, + kf, + keys[i], + error)) + return FALSE; + } + } + /* all applications require icons */ if (as_app_get_icons(app)->len == 0) as_app_add_veto (app, "%s has no icon", app_id); diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h index d3cd076..467be27 100644 --- a/libappstream-glib/as-app.h +++ b/libappstream-glib/as-app.h @@ -74,6 +74,7 @@ struct _AsAppClass * @AS_APP_PARSE_FLAG_CONVERT_TRANSLATABLE: Allow translatable flags like <_p> * @AS_APP_PARSE_FLAG_APPEND_DATA: Append new data rather than replacing * @AS_APP_PARSE_FLAG_ALLOW_VETO: Do not return errors for vetoed apps + * @AS_APP_PARSE_FLAG_USE_FALLBACKS: Fall back to suboptimal data where required * * The flags to use when parsing resources. **/ @@ -84,6 +85,7 @@ typedef enum { AS_APP_PARSE_FLAG_CONVERT_TRANSLATABLE = 4, /* Since: 0.1.6 */ AS_APP_PARSE_FLAG_APPEND_DATA = 8, /* Since: 0.1.8 */ AS_APP_PARSE_FLAG_ALLOW_VETO = 16, /* Since: 0.2.5 */ + AS_APP_PARSE_FLAG_USE_FALLBACKS = 32, /* Since: 0.4.1 */ /*< private >*/ AS_APP_PARSE_FLAG_LAST, } AsAppParseFlags; |