summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-01-22 14:56:24 +0000
committerRichard Hughes <richard@hughsie.com>2016-01-22 15:03:05 +0000
commit3952f7101803a81a3c2559fcba9bde08271a8054 (patch)
tree51132cd8aeb8af272f04af7787ed3b3ed741b2ef
parentd1909988e2dcbc5d096298fd5413e1f35a47bdfb (diff)
downloadappstream-glib-3952f7101803a81a3c2559fcba9bde08271a8054.tar.gz
Use the project_group heuristics when parsing AppData files
-rw-r--r--libappstream-builder/plugins/asb-plugin-hardcoded.c58
-rw-r--r--libappstream-glib/as-app.c52
2 files changed, 52 insertions, 58 deletions
diff --git a/libappstream-builder/plugins/asb-plugin-hardcoded.c b/libappstream-builder/plugins/asb-plugin-hardcoded.c
index 28098d7..a0fd56d 100644
--- a/libappstream-builder/plugins/asb-plugin-hardcoded.c
+++ b/libappstream-builder/plugins/asb-plugin-hardcoded.c
@@ -23,10 +23,6 @@
#include <asb-plugin.h>
-struct AsbPluginPrivate {
- GPtrArray *project_groups;
-};
-
/**
* asb_plugin_get_name:
*/
@@ -47,47 +43,6 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs)
}
/**
- * asb_plugin_initialize:
- */
-void
-asb_plugin_initialize (AsbPlugin *plugin)
-{
- plugin->priv = ASB_PLUGIN_GET_PRIVATE (AsbPluginPrivate);
- plugin->priv->project_groups = asb_glob_value_array_new ();
-
- /* this is a heuristic */
- g_ptr_array_add (plugin->priv->project_groups,
- asb_glob_value_new ("http*://*.gnome.org*", "GNOME"));
- g_ptr_array_add (plugin->priv->project_groups,
- asb_glob_value_new ("http://gnome-*.sourceforge.net/", "GNOME"));
- g_ptr_array_add (plugin->priv->project_groups,
- asb_glob_value_new ("http*://*.kde.org*", "KDE"));
- g_ptr_array_add (plugin->priv->project_groups,
- asb_glob_value_new ("http://*kde-apps.org/*", "KDE"));
- g_ptr_array_add (plugin->priv->project_groups,
- asb_glob_value_new ("http://*xfce.org*", "XFCE"));
- g_ptr_array_add (plugin->priv->project_groups,
- asb_glob_value_new ("http://lxde.org*", "LXDE"));
- g_ptr_array_add (plugin->priv->project_groups,
- asb_glob_value_new ("http://pcmanfm.sourceforge.net/*", "LXDE"));
- g_ptr_array_add (plugin->priv->project_groups,
- asb_glob_value_new ("http://lxde.sourceforge.net/*", "LXDE"));
- g_ptr_array_add (plugin->priv->project_groups,
- asb_glob_value_new ("http://*mate-desktop.org*", "MATE"));
- g_ptr_array_add (plugin->priv->project_groups,
- asb_glob_value_new ("http://*enlightenment.org*", "Enlightenment"));
-}
-
-/**
- * asb_plugin_destroy:
- */
-void
-asb_plugin_destroy (AsbPlugin *plugin)
-{
- g_ptr_array_unref (plugin->priv->project_groups);
-}
-
-/**
* asb_plugin_process_app:
*/
gboolean
@@ -111,19 +66,6 @@ asb_plugin_process_app (AsbPlugin *plugin,
as_app_get_id (AS_APP (app)));
}
- /* use the URL to guess the project group */
- tmp = asb_package_get_url (pkg);
- if (as_app_get_project_group (AS_APP (app)) == NULL && tmp != NULL) {
- tmp = asb_glob_value_search (plugin->priv->project_groups, tmp);
- if (tmp != NULL)
- as_app_set_project_group (AS_APP (app), tmp);
- }
-
- /* use summary to guess the project group */
- tmp = as_app_get_comment (AS_APP (app), NULL);
- if (tmp != NULL && g_strstr_len (tmp, -1, "for KDE") != NULL)
- as_app_set_project_group (AS_APP (app), "KDE");
-
/* look for any installed docs */
filelist = asb_package_get_filelist (pkg);
for (i = 0; filelist[i] != NULL; i++) {
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 5d5b549..b77a6f2 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -35,6 +35,7 @@
#include "config.h"
#include <string.h>
+#include <fnmatch.h>
#include "as-app-private.h"
#include "as-bundle-private.h"
@@ -4210,6 +4211,50 @@ as_app_parse_appdata_unintltoolize_cb (GNode *node, gpointer data)
}
/**
+ * as_app_parse_appdata_guess_project_group:
+ **/
+static void
+as_app_parse_appdata_guess_project_group (AsApp *app)
+{
+ const gchar *tmp;
+ guint i;
+ struct {
+ const gchar *project_group;
+ const gchar *url_glob;
+ } table[] = {
+ { "Enlightenment", "http://*enlightenment.org*" },
+ { "GNOME", "http*://*.gnome.org*" },
+ { "GNOME", "http://gnome-*.sourceforge.net/" },
+ { "KDE", "http://*kde-apps.org/*" },
+ { "KDE", "http*://*.kde.org*" },
+ { "LXDE", "http://lxde.org*" },
+ { "LXDE", "http://lxde.sourceforge.net/*" },
+ { "LXDE", "http://pcmanfm.sourceforge.net/*" },
+ { "MATE", "http://*mate-desktop.org*" },
+ { "XFCE", "http://*xfce.org*" },
+ { NULL, NULL }
+ };
+
+ /* match a URL glob and set the project group */
+ tmp = as_app_get_url_item (app, AS_URL_KIND_HOMEPAGE);
+ if (tmp == NULL)
+ return;
+ for (i = 0; table[i].project_group != NULL; i++) {
+ if (fnmatch (table[i].url_glob, tmp, 0) == 0) {
+ as_app_set_project_group (app, table[i].project_group);
+ return;
+ }
+ }
+
+ /* use summary to guess the project group */
+ tmp = as_app_get_comment (AS_APP (app), NULL);
+ if (tmp != NULL && g_strstr_len (tmp, -1, "for KDE") != NULL) {
+ as_app_set_project_group (AS_APP (app), "KDE");
+ return;
+ }
+}
+
+/**
* as_app_parse_appdata_file:
**/
static gboolean
@@ -4305,6 +4350,13 @@ as_app_parse_appdata_file (AsApp *app,
as_node_context_set_source_kind (ctx, AS_APP_SOURCE_KIND_APPDATA);
if (!as_app_node_parse_full (app, node, flags, ctx, error))
return FALSE;
+
+ /* use heuristics */
+ if (flags & AS_APP_PARSE_FLAG_USE_HEURISTICS) {
+ if (as_app_get_project_group (app) == NULL)
+ as_app_parse_appdata_guess_project_group (app);
+ }
+
return TRUE;
}