[gnome-software] Use libappstream-glib to load AppData and desktop locations



commit 8688a58136ecdb6fe5337433bcda5f9f9ba5cc8b
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jun 26 12:13:30 2014 +0100

    Use libappstream-glib to load AppData and desktop locations

 configure.ac                                   |    4 +-
 contrib/gnome-software.spec.in                 |    2 +-
 src/plugins/Makefile.am                        |   25 --
 src/plugins/README.md                          |   50 +----
 src/plugins/gs-plugin-appdata.c                |  243 -----------------
 src/plugins/gs-plugin-appstream.c              |   67 +++++-
 src/plugins/gs-plugin-datadir-apps.c           |  329 ------------------------
 src/plugins/gs-plugin-datadir-filename-local.c |   76 ------
 src/plugins/gs-plugin-datadir-filename.c       |  163 ------------
 9 files changed, 70 insertions(+), 889 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a09eb5f..4778551 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,7 +61,7 @@ dnl - Check library dependencies
 dnl ---------------------------------------------------------------------------
 PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 3.13.1 gio-unix-2.0)
 PKG_CHECK_MODULES(PACKAGEKIT, packagekit-glib2 >= 0.8.12)
-PKG_CHECK_MODULES(APPSTREAM, appstream-glib >= 0.1.8)
+PKG_CHECK_MODULES(APPSTREAM, appstream-glib >= 0.2.2)
 PKG_CHECK_MODULES(SQLITE, sqlite3)
 PKG_CHECK_MODULES(SOUP, libsoup-2.4)
 PKG_CHECK_MODULES(GSETTINGS_DESKTOP_SCHEMAS, gsettings-desktop-schemas >= 3.11.5)
@@ -89,7 +89,7 @@ AM_CONDITIONAL(ENABLE_DOGTAIL, test "$enable_dogtail" != no)
 
 # this refers to the gnome-software plugin API version
 # this is not in any way related to a package or soname version
-GS_PLUGIN_API_VERSION=3
+GS_PLUGIN_API_VERSION=4
 AC_SUBST(GS_PLUGIN_API_VERSION)
 AC_DEFINE_UNQUOTED([GS_PLUGIN_API_VERSION], "$GS_PLUGIN_API_VERSION", [the plugin API version])
 
diff --git a/contrib/gnome-software.spec.in b/contrib/gnome-software.spec.in
index f8ce7e7..0983b9e 100644
--- a/contrib/gnome-software.spec.in
+++ b/contrib/gnome-software.spec.in
@@ -32,7 +32,7 @@ BuildRequires: gsettings-desktop-schemas-devel
 BuildRequires: libappstream-glib-devel
 
 # this is not a library version
-%define gs_plugin_version               3
+%define gs_plugin_version               4
 
 %description
 gnome-software is an application that makes it easy to add, remove
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 737cc60..3174cef 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -26,11 +26,7 @@ noinst_LTLIBRARIES =                                 \
 
 plugindir = $(libdir)/gs-plugins-${GS_PLUGIN_API_VERSION}
 plugin_LTLIBRARIES =                                   \
-       libgs_plugin_appdata.la                         \
        libgs_plugin_appstream.la                       \
-       libgs_plugin_datadir_apps.la                    \
-       libgs_plugin_datadir_filename.la                \
-       libgs_plugin_datadir_filename_local.la          \
        libgs_plugin_desktopdb.la                       \
        libgs_plugin_hardcoded-featured.la              \
        libgs_plugin_hardcoded-categories.la            \
@@ -81,12 +77,6 @@ libgs_plugin_appstream_la_LIBADD = $(GS_PLUGIN_LIBS) $(APPSTREAM_LIBS)
 libgs_plugin_appstream_la_LDFLAGS = -module -avoid-version
 libgs_plugin_appstream_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
 
-libgs_plugin_appdata_la_SOURCES =                      \
-       gs-plugin-appdata.c
-libgs_plugin_appdata_la_LIBADD = $(GS_PLUGIN_LIBS) $(APPSTREAM_LIBS)
-libgs_plugin_appdata_la_LDFLAGS = -module -avoid-version
-libgs_plugin_appdata_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
-
 libgs_plugin_moduleset_la_SOURCES =                    \
        gs-moduleset.c                                  \
        gs-moduleset.h                                  \
@@ -186,21 +176,6 @@ libgs_plugin_desktopdb_la_LIBADD = $(GS_PLUGIN_LIBS) $(PACKAGEKIT_LIBS)
 libgs_plugin_desktopdb_la_LDFLAGS = -module -avoid-version
 libgs_plugin_desktopdb_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
 
-libgs_plugin_datadir_apps_la_SOURCES = gs-plugin-datadir-apps.c
-libgs_plugin_datadir_apps_la_LIBADD = $(GS_PLUGIN_LIBS) $(GTK_LIBS)
-libgs_plugin_datadir_apps_la_LDFLAGS = -module -avoid-version
-libgs_plugin_datadir_apps_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
-
-libgs_plugin_datadir_filename_la_SOURCES = gs-plugin-datadir-filename.c
-libgs_plugin_datadir_filename_la_LIBADD = $(GS_PLUGIN_LIBS) $(GTK_LIBS)
-libgs_plugin_datadir_filename_la_LDFLAGS = -module -avoid-version
-libgs_plugin_datadir_filename_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
-
-libgs_plugin_datadir_filename_local_la_SOURCES = gs-plugin-datadir-filename-local.c
-libgs_plugin_datadir_filename_local_la_LIBADD = $(GS_PLUGIN_LIBS) $(GTK_LIBS)
-libgs_plugin_datadir_filename_local_la_LDFLAGS = -module -avoid-version
-libgs_plugin_datadir_filename_local_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
-
 check_PROGRAMS =                                       \
        gs-self-test
 
diff --git a/src/plugins/README.md b/src/plugins/README.md
index 07cb292..43f7a30 100644
--- a/src/plugins/README.md
+++ b/src/plugins/README.md
@@ -5,24 +5,7 @@ requests and to service user actions like installing, removing and updating.
 Plugins are disabled by default, and need to be enabled manually before they
 are used.
 This allows different distributions to pick and choose how the application
-installer gathers data just by setting a single GSettings key. For instance:
-
->  SuSE has AppStream data and also uses
-> PackageKit. The default on SuSE would
-> be  to enable the `appstream` and
-> `packagekit` plugins and leave the
-> rest disabled.
-
->  Fedora doesn't have AppStream data,
-> so it has to make do with other local
-> data.  On Fedora we would enable the
-> `datadir-apps`, `desktop-db` and all
-> the  `hardcoded` plugins to get some
-> sensible results. For Fedora, it
-> probably also  makes sense to write a
-> plugin that interfaces with FAS or
-> fedora-tagger to get  the extra
-> metadata for uninstalled applications.
+installer gathers data just by setting a single GSettings key.
 
 Plugins also have a priority system where the largest number gets run first.
 That means if one plugin requires some property or metadata set by another
@@ -135,34 +118,3 @@ Overview:    | <p>
 Methods:     | `AddCategoryApps`
 Requires:    | `nothing`
 Refines:     | `[source]->[name,summary,pixbuf,id,kind]`
-
-### datadir-apps ###
-Uses the files in /usr/share/applications to provide icons and, translations for
-installed applications.
-
-Overview:    | <p>
--------------|---
-Methods:     | `nothing`
-Requires:    | `nothing`
-Refines:     | `{DataDir::desktop-filename}->[name]`, `{DataDir::desktop-filename}->[summary]`, 
`{DataDir::desktop-filename}->[pixbuf]`, `{DataDir::desktop-filename}->[id]`, 
`{DataDir::desktop-filename}->[kind]`
-
-### datadir-filename ###
-Uses the existance of a files in /usr/share/applications, named $id.desktop to
-set the correct desktop filename., This is useful if we just have a bare `[id]`
-from something like, AddPopular and want to get the details using 'datadir-apps'
-
-Overview:    | <p>
--------------|---
-Methods:     | `nothing`
-Requires:    | `nothing`
-Refines:     | `[id]->{DataDir::desktop-filename}`
-
-### datadir-filename-local ###
-Sets any applications not installed with datadir or /usr as installed as these
-might have been installed manually or using jhbuild.
-
-Overview:    | <p>
--------------|---
-Methods:     | `nothing`
-Requires:    | `nothing`
-Refines:     | `{DataDir::desktop-filename}->[state]`, `[management-plugin]`
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 2919fed..53827a5 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -101,7 +101,7 @@ const gchar **
 gs_plugin_get_deps (GsPlugin *plugin)
 {
        static const gchar *deps[] = {
-               "datadir-apps",         /* set the state using the installed file */
+               "hardcoded-categories", /* need category list */
                NULL };
        return deps;
 }
@@ -139,6 +139,8 @@ gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
        ret = as_store_load (plugin->priv->store,
                             AS_STORE_LOAD_FLAG_APP_INFO_SYSTEM |
                             AS_STORE_LOAD_FLAG_APP_INFO_USER |
+                            AS_STORE_LOAD_FLAG_APPDATA |
+                            AS_STORE_LOAD_FLAG_DESKTOP |
                             AS_STORE_LOAD_FLAG_APP_INSTALL,
                             cancellable,
                             error);
@@ -271,6 +273,7 @@ gs_plugin_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
                }
                break;
        default:
+               g_warning ("icon kind unknown for %s", as_app_get_id_full (item));
                break;
        }
 out:
@@ -455,6 +458,27 @@ gs_plugin_refine_item (GsPlugin *plugin,
                }
        }
 
+       /* is installed already */
+       if (gs_app_get_state (app) == GS_APP_STATE_UNKNOWN) {
+               switch (as_app_get_source_kind (item)) {
+               case AS_APP_SOURCE_KIND_APPDATA:
+               case AS_APP_SOURCE_KIND_DESKTOP:
+                       gs_app_set_kind (app, GS_APP_KIND_NORMAL);
+               case AS_APP_SOURCE_KIND_METAINFO:
+                       gs_app_set_state (app, GS_APP_STATE_INSTALLED);
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       /* give the desktopdb plugin a fighting chance */
+       if (as_app_get_source_file (item) != NULL &&
+           gs_app_get_metadata_item (app, "DataDir::desktop-filename") == NULL) {
+               gs_app_set_metadata (app, "DataDir::desktop-filename",
+                                    as_app_get_source_file (item));
+       }
+
        /* set id */
        if (as_app_get_id (item) != NULL && gs_app_get_id (app) == NULL)
                gs_app_set_id (app, as_app_get_id (item));
@@ -824,6 +848,47 @@ out:
 }
 
 /**
+ * gs_plugin_add_installed:
+ */
+gboolean
+gs_plugin_add_installed (GsPlugin *plugin,
+                        GList **list,
+                        GCancellable *cancellable,
+                        GError **error)
+{
+       AsApp *item;
+       gboolean ret = TRUE;
+       GPtrArray *array;
+       GsApp *app;
+       guint i;
+
+       /* load XML files */
+       if (g_once_init_enter (&plugin->priv->done_init)) {
+               ret = gs_plugin_startup (plugin, cancellable, error);
+               g_once_init_leave (&plugin->priv->done_init, TRUE);
+               if (!ret)
+                       goto out;
+       }
+
+       /* search categories for the search term */
+       gs_profile_start (plugin->profile, "appstream::add_installed");
+       array = as_store_get_apps (plugin->priv->store);
+       for (i = 0; i < array->len; i++) {
+               item = g_ptr_array_index (array, i);
+               if (as_app_get_source_kind (item) == AS_APP_SOURCE_KIND_APPDATA) {
+                       app = gs_app_new (as_app_get_id_full (item));
+                       ret = gs_plugin_refine_item (plugin, app, item, error);
+                       if (!ret)
+                               goto out;
+                       gs_plugin_add_app (list, app);
+               }
+       }
+       gs_profile_stop (plugin->profile, "appstream::add_installed");
+out:
+       return ret;
+}
+
+/**
  * gs_plugin_add_categories:
  */
 gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]