summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-01-31 19:55:13 +0000
committerRichard Hughes <richard@hughsie.com>2016-01-31 20:31:14 +0000
commitbfc6783eccc7e4d67d43011fdfaf88cf5972bc83 (patch)
treecc8cb773f7eb70818dec8d47643612d9bdfe35a7
parentd85558dbf74025bddfae6a369d77bc95654e1d91 (diff)
downloadappstream-glib-bfc6783eccc7e4d67d43011fdfaf88cf5972bc83.tar.gz
Move the kudo and provides autodetection to libappstream-glib
-rw-r--r--client/as-compose.c22
-rw-r--r--libappstream-builder/asb-self-test.c4
-rw-r--r--libappstream-builder/plugins/Makefile.am6
-rw-r--r--libappstream-builder/plugins/asb-plugin-dbus.c128
-rw-r--r--libappstream-builder/plugins/asb-plugin-hardcoded.c34
-rw-r--r--libappstream-glib/as-app-builder.c173
-rw-r--r--libappstream-glib/as-app-builder.h8
7 files changed, 222 insertions, 153 deletions
diff --git a/client/as-compose.c b/client/as-compose.c
index 2ad4357..5a5e4a1 100644
--- a/client/as-compose.c
+++ b/client/as-compose.c
@@ -425,6 +425,28 @@ main (int argc, char **argv)
return EXIT_FAILURE;
}
+ /* auto-add kudos */
+ if (!as_app_builder_search_kudos (app_appdata,
+ prefix,
+ AS_APP_BUILDER_FLAG_NONE,
+ &error)) {
+ /* TRANSLATORS: we could not auto-add the kudo */
+ g_print ("%s: %s\n", _("Error parsing kudos"),
+ error->message);
+ return EXIT_FAILURE;
+ }
+
+ /* auto-add provides */
+ if (!as_app_builder_search_provides (app_appdata,
+ prefix,
+ AS_APP_BUILDER_FLAG_NONE,
+ &error)) {
+ /* TRANSLATORS: we could not auto-add the provides */
+ g_print ("%s: %s\n", _("Error parsing provides"),
+ error->message);
+ return EXIT_FAILURE;
+ }
+
as_store_add_app (store, app_appdata);
app_desktop = load_desktop (prefix,
diff --git a/libappstream-builder/asb-self-test.c b/libappstream-builder/asb-self-test.c
index 779c915..8e32d73 100644
--- a/libappstream-builder/asb-self-test.c
+++ b/libappstream-builder/asb-self-test.c
@@ -488,6 +488,7 @@ asb_test_context_test_func (AsbTestContextMode mode)
"<summary>Addons for extra functionality</summary>\n"
"<kudos>\n"
"<kudo>ModernToolkit</kudo>\n"
+ "<kudo>SearchProvider</kudo>\n"
"</kudos>\n"
"<project_license>GPL-2.0+</project_license>\n"
"<url type=\"homepage\">http://people.freedesktop.org/</url>\n"
@@ -495,6 +496,9 @@ asb_test_context_test_func (AsbTestContextMode mode)
"<releases>\n"
"<release version=\"1\" timestamp=\"1407844800\"/>\n"
"</releases>\n"
+ "<provides>\n"
+ "<dbus type=\"session\">org.freedesktop.AppStream</dbus>\n"
+ "</provides>\n"
"<languages>\n"
"<lang percentage=\"100\">en_GB</lang>\n"
"<lang percentage=\"33\">ru</lang>\n"
diff --git a/libappstream-builder/plugins/Makefile.am b/libappstream-builder/plugins/Makefile.am
index 3709321..b933ed2 100644
--- a/libappstream-builder/plugins/Makefile.am
+++ b/libappstream-builder/plugins/Makefile.am
@@ -16,7 +16,6 @@ plugindir = $(libdir)/asb-plugins-$(AS_PLUGIN_VERSION)
plugin_LTLIBRARIES = \
libasb_plugin_absorb.la \
libasb_plugin_appdata.la \
- libasb_plugin_dbus.la \
libasb_plugin_desktop.la \
libasb_plugin_gettext.la \
libasb_plugin_hardcoded.la
@@ -26,11 +25,6 @@ plugin_LTLIBRARIES += \
libasb_plugin_font.la
endif
-libasb_plugin_dbus_la_SOURCES = asb-plugin-dbus.c
-libasb_plugin_dbus_la_LIBADD = $(GLIB_LIBS)
-libasb_plugin_dbus_la_LDFLAGS = -module -avoid-version
-libasb_plugin_dbus_la_CFLAGS = $(GLIB_CFLAGS) $(WARNINGFLAGS_C)
-
libasb_plugin_absorb_la_SOURCES = asb-plugin-absorb.c
libasb_plugin_absorb_la_LIBADD = $(GLIB_LIBS)
libasb_plugin_absorb_la_LDFLAGS = -module -avoid-version
diff --git a/libappstream-builder/plugins/asb-plugin-dbus.c b/libappstream-builder/plugins/asb-plugin-dbus.c
deleted file mode 100644
index c0a861f..0000000
--- a/libappstream-builder/plugins/asb-plugin-dbus.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
- *
- * Licensed under the GNU Lesser General Public License Version 2.1
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <config.h>
-#include <fnmatch.h>
-
-#include <asb-plugin.h>
-
-/**
- * asb_plugin_get_name:
- */
-const gchar *
-asb_plugin_get_name (void)
-{
- return "dbus";
-}
-
-/**
- * asb_plugin_add_globs:
- */
-void
-asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs)
-{
- asb_plugin_add_glob (globs, "/usr/share/dbus-1/system-services/*.service");
- asb_plugin_add_glob (globs, "/usr/share/dbus-1/services/*.service");
-}
-
-/**
- * _asb_plugin_check_filename_system:
- */
-static gboolean
-_asb_plugin_check_filename_system (const gchar *filename)
-{
- if (asb_plugin_match_glob ("/usr/share/dbus-1/system-services/*.service", filename))
- return TRUE;
- return FALSE;
-}
-
-/**
- * _asb_plugin_check_filename_session:
- */
-static gboolean
-_asb_plugin_check_filename_session (const gchar *filename)
-{
- if (asb_plugin_match_glob ("/usr/share/dbus-1/services/*.service", filename))
- return TRUE;
- return FALSE;
-}
-
-/**
- * asb_plugin_process_dbus:
- */
-static gboolean
-asb_plugin_process_dbus (AsbApp *app,
- const gchar *tmpdir,
- const gchar *filename,
- gboolean is_system,
- GError **error)
-{
- g_autofree gchar *filename_full = NULL;
- g_autofree gchar *name = NULL;
- g_autoptr(GKeyFile) kf = NULL;
- g_autoptr(AsProvide) provide = NULL;
-
- /* load file */
- filename_full = g_build_filename (tmpdir, filename, NULL);
- kf = g_key_file_new ();
- if (!g_key_file_load_from_file (kf, filename_full, G_KEY_FILE_NONE, error))
- return FALSE;
- name = g_key_file_get_string (kf, "D-BUS Service", "Name", error);
- if (name == NULL)
- return FALSE;
-
- /* add provide */
- provide = as_provide_new ();
- as_provide_set_kind (provide, is_system ? AS_PROVIDE_KIND_DBUS_SYSTEM :
- AS_PROVIDE_KIND_DBUS_SESSION);
- as_provide_set_value (provide, name);
- as_app_add_provide (AS_APP (app), provide);
- return TRUE;
-}
-
-/**
- * asb_plugin_process_app:
- */
-gboolean
-asb_plugin_process_app (AsbPlugin *plugin,
- AsbPackage *pkg,
- AsbApp *app,
- const gchar *tmpdir,
- GError **error)
-{
- gchar **filelist;
- guint i;
-
- /* look for any GIR files */
- filelist = asb_package_get_filelist (pkg);
- for (i = 0; filelist[i] != NULL; i++) {
- if (_asb_plugin_check_filename_system (filelist[i])) {
- if (!asb_plugin_process_dbus (app, tmpdir, filelist[i],
- TRUE, error))
- return FALSE;
- } else if (_asb_plugin_check_filename_session (filelist[i])) {
- if (!asb_plugin_process_dbus (app, tmpdir, filelist[i],
- FALSE, error))
- return FALSE;
- }
- }
- return TRUE;
-}
diff --git a/libappstream-builder/plugins/asb-plugin-hardcoded.c b/libappstream-builder/plugins/asb-plugin-hardcoded.c
index f15e15c..25334f1 100644
--- a/libappstream-builder/plugins/asb-plugin-hardcoded.c
+++ b/libappstream-builder/plugins/asb-plugin-hardcoded.c
@@ -40,6 +40,8 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs)
{
asb_plugin_add_glob (globs, "/usr/share/help/*");
asb_plugin_add_glob (globs, "/usr/share/gnome-shell/search-providers/*");
+ asb_plugin_add_glob (globs, "/usr/share/dbus-1/system-services/*.service");
+ asb_plugin_add_glob (globs, "/usr/share/dbus-1/services/*.service");
}
/**
@@ -56,6 +58,7 @@ asb_plugin_process_app (AsbPlugin *plugin,
GPtrArray *deps;
gchar **filelist;
guint i;
+ g_autofree gchar *prefix = NULL;
/* look for any installed docs */
filelist = asb_package_get_filelist (pkg);
@@ -71,19 +74,18 @@ asb_plugin_process_app (AsbPlugin *plugin,
}
}
- /* look for a shell search provider */
- for (i = 0; filelist[i] != NULL; i++) {
- if (asb_plugin_match_glob ("/usr/share/gnome-shell/search-providers/*",
- filelist[i])) {
- asb_package_log (pkg,
- ASB_PACKAGE_LOG_LEVEL_DEBUG,
- "Auto-adding kudo SearchProvider for %s",
- as_app_get_id (AS_APP (app)));
- as_app_add_kudo_kind (AS_APP (app),
- AS_KUDO_KIND_SEARCH_PROVIDER);
- break;
- }
- }
+ /* look for kudos and provides */
+ prefix = g_build_filename (tmpdir, "usr", NULL);
+ if (!as_app_builder_search_kudos (AS_APP (app),
+ prefix,
+ AS_APP_BUILDER_FLAG_USE_FALLBACKS,
+ error))
+ return FALSE;
+ if (!as_app_builder_search_provides (AS_APP (app),
+ prefix,
+ AS_APP_BUILDER_FLAG_USE_FALLBACKS,
+ error))
+ return FALSE;
/* look for a high contrast icon */
for (i = 0; filelist[i] != NULL; i++) {
@@ -93,12 +95,6 @@ asb_plugin_process_app (AsbPlugin *plugin,
AS_KUDO_KIND_HIGH_CONTRAST);
break;
}
- if (asb_plugin_match_glob ("/usr/share/icons/hicolor/symbolic/apps/*.svg",
- filelist[i])) {
- as_app_add_kudo_kind (AS_APP (app),
- AS_KUDO_KIND_HIGH_CONTRAST);
- break;
- }
}
/* look for a modern toolkit */
diff --git a/libappstream-glib/as-app-builder.c b/libappstream-glib/as-app-builder.c
index 799e862..12d8b0e 100644
--- a/libappstream-glib/as-app-builder.c
+++ b/libappstream-glib/as-app-builder.c
@@ -516,3 +516,176 @@ as_app_builder_search_translations (AsApp *app,
}
return TRUE;
}
+
+/**
+ * as_app_builder_search_path:
+ **/
+static gboolean
+as_app_builder_search_path (AsApp *app,
+ const gchar *prefix,
+ const gchar *path,
+ AsAppBuilderFlags flags)
+{
+ const gchar *tmp;
+ g_autofree gchar *fn_prefix = NULL;
+ g_autoptr(GDir) dir = NULL;
+
+ /* find dir */
+ fn_prefix = g_build_filename (prefix, path, NULL);
+ if (!g_file_test (fn_prefix, G_FILE_TEST_IS_DIR))
+ return FALSE;
+ dir = g_dir_open (fn_prefix, 0, NULL);
+ if (dir == NULL)
+ return FALSE;
+
+ /* find any file with the app-id prefix */
+ while ((tmp = g_dir_read_name (dir)) != NULL) {
+ if (g_str_has_prefix (tmp, as_app_get_id (app)))
+ return TRUE;
+ }
+
+ /* just anything */
+ if (flags & AS_APP_BUILDER_FLAG_USE_FALLBACKS)
+ return TRUE;
+
+ return FALSE;
+}
+
+/**
+ * as_app_builder_search_kudos:
+ * @app: an #AsApp
+ * @prefix: a prefix to search, e.g. "/usr"
+ * @flags: #AsAppBuilderFlags, e.g. %AS_APP_BUILDER_FLAG_USE_FALLBACKS
+ * @cancellable: a #GCancellable or %NULL
+ * @error: a #GError or %NULL
+ *
+ * Searches a prefix for auto-detected kudos.
+ *
+ * Returns: %TRUE for success
+ *
+ * Since: 0.5.8
+ **/
+gboolean
+as_app_builder_search_kudos (AsApp *app,
+ const gchar *prefix,
+ AsAppBuilderFlags flags,
+ GError **error)
+{
+ /* gnome-shell search provider */
+ if (!as_app_has_kudo_kind (app, AS_KUDO_KIND_SEARCH_PROVIDER) &&
+ as_app_builder_search_path (app, prefix,
+ "share/gnome-shell/search-providers",
+ flags)) {
+ g_debug ("auto-adding SearchProvider kudo");
+ as_app_add_kudo_kind (AS_APP (app), AS_KUDO_KIND_SEARCH_PROVIDER);
+ }
+
+ /* hicolor icon */
+ if (!as_app_has_kudo_kind (app, AS_KUDO_KIND_HIGH_CONTRAST) &&
+ as_app_builder_search_path (app, prefix,
+ "share/icons/hicolor/symbolic/apps",
+ flags)) {
+ g_debug ("auto-adding HighContrast kudo");
+ as_app_add_kudo_kind (AS_APP (app), AS_KUDO_KIND_HIGH_CONTRAST);
+ }
+ return TRUE;
+}
+
+/**
+ * as_app_builder_search_dbus_file:
+ **/
+static gboolean
+as_app_builder_search_dbus_file (AsApp *app,
+ const gchar *filename,
+ AsProvideKind provide_kind,
+ GError **error)
+{
+ g_autofree gchar *name = NULL;
+ g_autoptr(AsProvide) provide = NULL;
+ g_autoptr(GKeyFile) kf = NULL;
+
+ /* load file */
+ kf = g_key_file_new ();
+ if (!g_key_file_load_from_file (kf, filename, G_KEY_FILE_NONE, error))
+ return FALSE;
+ name = g_key_file_get_string (kf, "D-BUS Service", "Name", error);
+ if (name == NULL)
+ return FALSE;
+
+ /* add provide */
+ provide = as_provide_new ();
+ as_provide_set_kind (provide, provide_kind);
+ as_provide_set_value (provide, name);
+ as_app_add_provide (AS_APP (app), provide);
+ return TRUE;
+}
+
+/**
+ * as_app_builder_search_dbus:
+ **/
+static gboolean
+as_app_builder_search_dbus (AsApp *app,
+ const gchar *prefix,
+ const gchar *path,
+ AsProvideKind provide_kind,
+ AsAppBuilderFlags flags,
+ GError **error)
+{
+ const gchar *tmp;
+ g_autofree gchar *fn_prefix = NULL;
+ g_autoptr(GDir) dir = NULL;
+
+ /* find dir */
+ fn_prefix = g_build_filename (prefix, path, NULL);
+ if (!g_file_test (fn_prefix, G_FILE_TEST_IS_DIR))
+ return TRUE;
+ dir = g_dir_open (fn_prefix, 0, error);
+ if (dir == NULL)
+ return FALSE;
+
+ /* find any file with the app-id prefix */
+ while ((tmp = g_dir_read_name (dir)) != NULL) {
+ g_autofree gchar *fn = NULL;
+ if ((flags & AS_APP_BUILDER_FLAG_USE_FALLBACKS) == 0) {
+ if (!g_str_has_prefix (tmp, as_app_get_id (app)))
+ continue;
+ }
+ fn = g_build_filename (fn_prefix, tmp, NULL);
+ if (!as_app_builder_search_dbus_file (app, fn, provide_kind, error))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
+ * as_app_builder_search_provides:
+ * @app: an #AsApp
+ * @prefix: a prefix to search, e.g. "/usr"
+ * @flags: #AsAppBuilderFlags, e.g. %AS_APP_BUILDER_FLAG_USE_FALLBACKS
+ * @cancellable: a #GCancellable or %NULL
+ * @error: a #GError or %NULL
+ *
+ * Searches a prefix for auto-detected provides.
+ *
+ * Returns: %TRUE for success
+ *
+ * Since: 0.5.8
+ **/
+gboolean
+as_app_builder_search_provides (AsApp *app,
+ const gchar *prefix,
+ AsAppBuilderFlags flags,
+ GError **error)
+{
+ if (!as_app_builder_search_dbus (app, prefix,
+ "share/dbus-1/system-services",
+ AS_PROVIDE_KIND_DBUS_SYSTEM,
+ flags, error))
+ return FALSE;
+ if (!as_app_builder_search_dbus (app, prefix,
+ "share/dbus-1/services",
+ AS_PROVIDE_KIND_DBUS_SESSION,
+ flags, error))
+ return FALSE;
+ return TRUE;
+}
diff --git a/libappstream-glib/as-app-builder.h b/libappstream-glib/as-app-builder.h
index 9d0166f..dba3fe4 100644
--- a/libappstream-glib/as-app-builder.h
+++ b/libappstream-glib/as-app-builder.h
@@ -53,6 +53,14 @@ gboolean as_app_builder_search_translations (AsApp *app,
AsAppBuilderFlags flags,
GCancellable *cancellable,
GError **error);
+gboolean as_app_builder_search_kudos (AsApp *app,
+ const gchar *prefix,
+ AsAppBuilderFlags flags,
+ GError **error);
+gboolean as_app_builder_search_provides (AsApp *app,
+ const gchar *prefix,
+ AsAppBuilderFlags flags,
+ GError **error);
G_END_DECLS