[gnome-software/wip/mak/limba: 1/2] Add basic support for Limba



commit 72951c55e9ea818ffda0f78ebc6c831cdace9fa6
Author: Matthias Klumpp <matthias tenstral net>
Date:   Mon Jun 1 17:07:17 2015 +0200

    Add basic support for Limba
    
    Add a simple GS plugin to integrate Limba with GNOME-Software.
    Limba is a 3rd-party software installation solution, allowing upstream
    software developers ship software directly to their users.
    You can find more information about Limba at
    http://lwn.net/Articles/639072/ and https://github.com/ximion/limba
    
    This patch adds very basic support for installing / removing Limba
    applications in GNOME-Software.

 configure.ac                  |    9 ++
 src/plugins/Makefile.am       |   12 ++
 src/plugins/gs-plugin-limba.c |  227 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 248 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index acc11e7..5d04b9a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -114,6 +114,15 @@ AS_IF([test "x$have_firmware" = "xyes"], [
 
 AM_CONDITIONAL(HAVE_FIRMWARE, test x$have_firmware = xyes)
 
+# Limba
+AC_ARG_ENABLE(limba, AS_HELP_STRING([--enable-limba],[enable Limba support]),
+              enable_limba=$enableval,enable_limba=yes)
+if test x$enable_limba = xyes; then
+  PKG_CHECK_MODULES(LIMBA, limba >= 0.4.2)
+  AC_DEFINE(HAVE_LIMBA, 1, [Build Limba support])
+fi
+AM_CONDITIONAL(HAVE_LIMBA, test x$enable_limba = xyes)
+
 # 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=8
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index f01bd5c..3c187f5 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -10,6 +10,7 @@ AM_CPPFLAGS =                                         \
        $(SOUP_CFLAGS)                                  \
        $(SQLITE_CFLAGS)                                \
        $(FWUPD_CFLAGS)                                 \
+       $(LIMBA_CFLAGS)                                 \
        -DBINDIR=\"$(bindir)\"                          \
        -DDATADIR=\"$(datadir)\"                        \
        -DGS_MODULESETDIR=\"$(datadir)/gnome-software/modulesets.d\" \
@@ -48,6 +49,10 @@ if HAVE_FIRMWARE
 plugin_LTLIBRARIES += libgs_plugin_fwupd.la
 endif
 
+if HAVE_LIMBA
+plugin_LTLIBRARIES += libgs_plugin_limba.la
+endif
+
 libgs_plugin_dummy_la_SOURCES = gs-plugin-dummy.c
 libgs_plugin_dummy_la_LIBADD = $(GS_PLUGIN_LIBS)
 libgs_plugin_dummy_la_LDFLAGS = -module -avoid-version
@@ -84,6 +89,13 @@ 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)
 
+if HAVE_LIMBA
+libgs_plugin_limba_la_SOURCES = gs-plugin-limba.c
+libgs_plugin_limba_la_LIBADD = $(GS_PLUGIN_LIBS) $(LIMBA_LIBS)
+libgs_plugin_limba_la_LDFLAGS = -module -avoid-version
+libgs_plugin_limba_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+endif
+
 libgs_plugin_moduleset_la_SOURCES =                    \
        gs-moduleset.c                                  \
        gs-moduleset.h                                  \
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
new file mode 100644
index 0000000..86cad7f
--- /dev/null
+++ b/src/plugins/gs-plugin-limba.c
@@ -0,0 +1,227 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2015 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2015 Matthias Klumpp <matthias tenstral net>
+ *
+ * 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 <limba.h>
+#include <appstream-glib.h>
+#include "gs-cleanup.h"
+#include <gs-plugin.h>
+
+struct GsPluginPrivate {
+       LiManager       *mgr;
+};
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+       return "limba";
+}
+
+/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+       /* create private area */
+       plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+       plugin->priv->mgr = li_manager_new ();
+}
+
+/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+       g_object_unref (plugin->priv->mgr);
+}
+
+/**
+ * gs_plugin_refine_app:
+ */
+static gboolean
+gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
+{
+       AsBundle *bundle;
+       LiPkgInfo *pki;
+       GError *local_error = NULL;
+
+       bundle = gs_app_get_bundle (app);
+
+       /* check if we should process this application */
+       if (bundle == NULL)
+               return TRUE;
+       if (as_bundle_get_kind (bundle) != AS_BUNDLE_KIND_LIMBA)
+               return TRUE;
+
+       pki = li_manager_get_software_by_pkid (plugin->priv->mgr,
+                                                                       as_bundle_get_id (bundle),
+                                                                       &local_error);
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               return FALSE;
+       }
+
+       /* we will handle installations and removals of this application */
+       gs_app_set_management_plugin (app, "Limba");
+
+       if (pki == NULL)
+               return TRUE;
+
+       if (li_pkg_info_has_flag (pki, LI_PACKAGE_FLAG_INSTALLED))
+               gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+       else
+               gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
+
+       gs_app_set_version (app, li_pkg_info_get_version (pki));
+
+       return TRUE;
+}
+
+/**
+ * gs_plugin_refine:
+ */
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+                 GList **list,
+                 GsPluginRefineFlags flags,
+                 GCancellable *cancellable,
+                 GError **error)
+{
+       gboolean ret;
+       GList *l;
+       GsApp *app;
+
+       gs_profile_start (plugin->profile, "limba::refine");
+       for (l = *list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+
+               if (gs_app_get_bundle (app) == NULL)
+                       continue;
+
+               ret = gs_plugin_refine_app (plugin, app, error);
+               if (!ret)
+                       goto out;
+       }
+
+       /* sucess */
+       ret = TRUE;
+out:
+       gs_profile_stop (plugin->profile, "limba::refine");
+       return ret;
+}
+
+/**
+ * gs_plugin_app_remove:
+ */
+gboolean
+gs_plugin_app_remove (GsPlugin *plugin,
+                     GsApp *app,
+                     GCancellable *cancellable,
+                     GError **error)
+{
+       LiManager *mgr;
+       AsBundle *bundle;
+       gboolean ret = FALSE;
+       GError *local_error = NULL;
+
+       bundle = gs_app_get_bundle (app);
+
+       /* check if we can remove this application */
+       if (bundle == NULL)
+               return FALSE;
+       if (as_bundle_get_kind (bundle) != AS_BUNDLE_KIND_LIMBA)
+               return FALSE;
+
+       mgr = li_manager_new ();
+
+       gs_app_set_state (app, AS_APP_STATE_REMOVING);
+       li_manager_remove_software (mgr,
+                                                               as_bundle_get_id (bundle),
+                                                               &local_error);
+       if (local_error != NULL) {
+               gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+               g_propagate_error (error, local_error);
+               goto out;
+       }
+
+       ret = TRUE;
+       gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
+
+out:
+       g_object_unref (mgr);
+       return ret;
+}
+
+/**
+ * gs_plugin_app_install:
+ */
+gboolean
+gs_plugin_app_install (GsPlugin *plugin,
+                      GsApp *app,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       LiInstaller *inst = NULL;
+       AsBundle *bundle;
+       gboolean ret = FALSE;
+       GError *local_error = NULL;
+
+       bundle = gs_app_get_bundle (app);
+
+       /* check if we can install this application */
+       if (bundle == NULL)
+               return FALSE;
+       if (as_bundle_get_kind (bundle) != AS_BUNDLE_KIND_LIMBA)
+               return FALSE;
+
+       /* create new installer and select remote package */
+       inst = li_installer_new ();
+       li_installer_open_remote (inst,
+                                                         as_bundle_get_id (bundle),
+                                                         &local_error);
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               goto out;
+       }
+
+       /* install software */
+       gs_app_set_state (app, AS_APP_STATE_INSTALLING);
+       li_installer_install (inst, &local_error);
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
+               goto out;
+       }
+
+       ret = TRUE;
+       gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+
+out:
+       g_object_unref (inst);
+       return ret;
+}


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