[gnome-software] Add a plugin that allows us to show applications installed locally



commit e62a17beb3da9a4db90c606b40454b62c6add20d
Author: Richard Hughes <richard hughsie com>
Date:   Mon Sep 2 11:30:19 2013 +0100

    Add a plugin that allows us to show applications installed locally
    
    This fixes applications installed with jhbuild.

 src/gs-application.c                           |    1 +
 src/plugins/Makefile.am                        |    6 ++
 src/plugins/README.md                          |   12 ++++-
 src/plugins/gs-plugin-datadir-filename-local.c |   75 ++++++++++++++++++++++++
 src/plugins/gs-plugin-packagekit.c             |    2 +
 5 files changed, 95 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 962ce37..0f94683 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -163,6 +163,7 @@ gs_application_startup (GApplication *application)
         gs_plugin_loader_set_enabled (app->plugin_loader, "desktopdb", TRUE);
         gs_plugin_loader_set_enabled (app->plugin_loader, "datadir-apps", TRUE);
         gs_plugin_loader_set_enabled (app->plugin_loader, "datadir-filename", TRUE);
+        gs_plugin_loader_set_enabled (app->plugin_loader, "datadir-filename-local", TRUE);
 
         /* show the priority of each plugin */
         gs_plugin_loader_dump_state (app->plugin_loader);
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 348d081..27fb549 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -29,6 +29,7 @@ plugin_LTLIBRARIES =                                  \
        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_dummy.la                           \
        libgs_plugin_hardcoded-descriptions.la          \
@@ -117,4 +118,9 @@ 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) $(WARNINGFLAGS_C)
 
+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) $(WARNINGFLAGS_C)
+
 -include $(top_srcdir)/git.mk
diff --git a/src/plugins/README.md b/src/plugins/README.md
index ddcc1c8..7d834ce 100644
--- a/src/plugins/README.md
+++ b/src/plugins/README.md
@@ -108,7 +108,7 @@ Overview:    | <p>
 Methods:     | Search, AddUpdates, AddInstalled, AppInstall, AppRemove, AppUpdate
 Requires:    | `{package-id}`
 Refines:     | `nothing`
-Refines:     | `{package-id}`, `{package-name}`, `{package-summary}`, `{update-name}`, `{update-details}`
+Refines:     | `{package-id}`, `{package-name}`, `{package-summary}`, `{update-name}`, `{update-details}`, 
`{install-kind}`
 
 ### packagekit-refine ###
 Uses the system PackageKit instance to return convert filenames to package-ids.
@@ -157,3 +157,13 @@ 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]`, `{install-kind}`
diff --git a/src/plugins/gs-plugin-datadir-filename-local.c b/src/plugins/gs-plugin-datadir-filename-local.c
new file mode 100644
index 0000000..0110a4d
--- /dev/null
+++ b/src/plugins/gs-plugin-datadir-filename-local.c
@@ -0,0 +1,75 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <gs-plugin.h>
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+       return "datadir-filename-local";
+}
+
+/**
+ * gs_plugin_get_priority:
+ */
+gdouble
+gs_plugin_get_priority (GsPlugin *plugin)
+{
+       return 1.2f;
+}
+
+/**
+ * gs_plugin_refine:
+ */
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+                 GList *list,
+                 GCancellable *cancellable,
+                 GError **error)
+{
+       const gchar *tmp;
+       GList *l;
+       GsApp *app;
+
+       for (l = list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               if (gs_app_get_state (app) != GS_APP_STATE_UNKNOWN)
+                       continue;
+               tmp = gs_app_get_metadata_item (app, "datadir-desktop-filename");
+               if (tmp == NULL)
+                       continue;
+               if (!g_str_has_prefix (tmp, "/usr")) {
+                       /* FIXME: If the user tries to remove this, we don't
+                        * have a way of removing jhbuilt packages other than
+                        * from deleting the .desktop file */
+                       g_debug ("Desktop file not in /usr, assuming installed");
+                       gs_app_set_state (app, GS_APP_STATE_INSTALLED);
+                       gs_app_set_kind (app, GS_APP_KIND_NORMAL);
+                       gs_app_set_metadata (app, "install-kind", "local");
+               }
+       }
+       return TRUE;
+}
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index 8baf2af..f3e65ab 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -171,6 +171,7 @@ gs_plugin_packagekit_add_installed_results (GsPlugin *plugin,
                gs_app_set_metadata (app,
                                     "package-summary",
                                     pk_package_get_summary (package));
+               gs_app_set_metadata (app, "install-kind", "package");
                gs_app_set_version (app, pk_package_get_version (package));
                switch (pk_package_get_info (package)) {
                case PK_INFO_ENUM_INSTALLED:
@@ -342,6 +343,7 @@ gs_plugin_packagekit_add_updates_results (GsPlugin *plugin,
                gs_app_set_metadata (app, "package-name", split[PK_PACKAGE_ID_NAME]);
                gs_app_set_metadata (app, "update-name", split[PK_PACKAGE_ID_NAME]);
                gs_app_set_metadata (app, "update-details", update_text);
+               gs_app_set_metadata (app, "install-kind", "package");
                gs_app_set_name (app, split[PK_PACKAGE_ID_NAME]);
                gs_app_set_version (app, split[PK_PACKAGE_ID_VERSION]);
                gs_app_set_state (app, GS_APP_STATE_UPDATABLE);


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