[gnome-software/wip/mak/limba] Experimental untested Limba support



commit 7f9b41fb57da2e805c247aed98d756014f0fd127
Author: Matthias Klumpp <matthias tenstral net>
Date:   Fri Mar 20 16:34:52 2015 +0100

    Experimental untested Limba support
    
    This is just to play around with Limba and GS.
    Several important things are missing.

 configure.ac                  |    1 +
 src/plugins/Makefile.am       |    7 +
 src/plugins/gs-plugin-limba.c |  310 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 318 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 285de82..e8d7cce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -66,6 +66,7 @@ PKG_CHECK_MODULES(SQLITE, sqlite3)
 PKG_CHECK_MODULES(SOUP, libsoup-2.4)
 PKG_CHECK_MODULES(GSETTINGS_DESKTOP_SCHEMAS, gsettings-desktop-schemas >= 3.11.5)
 PKG_CHECK_MODULES(GNOME_DESKTOP, gnome-desktop-3.0)
+PKG_CHECK_MODULES(LIMBA, limba >= 0.4.0)
 AC_PATH_PROG(APPSTREAM_UTIL, [appstream-util], [unfound])
 AC_ARG_ENABLE(man,
               [AS_HELP_STRING([--enable-man],
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index de60263..15c88b5 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -9,6 +9,7 @@ AM_CPPFLAGS =                                           \
        $(PACKAGEKIT_CFLAGS)                            \
        $(SOUP_CFLAGS)                                  \
        $(SQLITE_CFLAGS)                                \
+       $(LIMBA_CFLAGS)                         \
        -DBINDIR=\"$(bindir)\"                          \
        -DDATADIR=\"$(datadir)\"                        \
        -DGS_MODULESETDIR=\"$(datadir)/gnome-software/modulesets.d\" \
@@ -29,6 +30,7 @@ plugin_LTLIBRARIES =                                  \
        libgs_plugin_appstream.la                       \
        libgs_plugin_hardcoded-featured.la              \
        libgs_plugin_hardcoded-categories.la            \
+       libgs_plugin_limba.la                           \
        libgs_plugin_moduleset.la                       \
        libgs_plugin_menu-spec-categories.la            \
        libgs_plugin_menu-spec-refine.la                \
@@ -80,6 +82,11 @@ 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_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)
+
 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..e42b71a
--- /dev/null
+++ b/src/plugins/gs-plugin-limba.c
@@ -0,0 +1,310 @@
+/* -*- 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 "gs-cleanup.h"
+#include <gs-plugin.h>
+
+struct GsPluginPrivate {
+       guint                    dummy;
+};
+
+/**
+ * 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->dummy = 999;
+}
+
+/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+       plugin->priv->dummy = 0;
+}
+
+/**
+ * gs_plugin_add_search:
+ */
+gboolean
+gs_plugin_add_search (GsPlugin *plugin,
+                     gchar **values,
+                     GList **list,
+                     GCancellable *cancellable,
+                     GError **error)
+{
+       return TRUE;
+}
+
+/**
+ * gs_plugin_add_installed:
+ */
+gboolean
+gs_plugin_add_installed (GsPlugin *plugin,
+                        GList **list,
+                        GCancellable *cancellable,
+                        GError **error)
+{
+       _cleanup_object_unref_ LiManager *mgr = NULL;
+       _cleanup_list_free_ GList *sw = NULL;
+       GList *l;
+       GError *local_error = NULL;
+
+       mgr = li_manager_new ();
+
+       sw = li_manager_get_software_list (mgr, &local_error);
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               return FALSE;
+       }
+
+       for (l = sw; l != NULL; l = l->next) {
+               _cleanup_object_unref_ GsApp *app = NULL;
+               LiPkgInfo *pki = LI_PKG_INFO (l->data);
+
+               /* FIXME: We want the AppStream id here, not the package-id! */
+               app = gs_app_new (li_pkg_info_get_id (pki));
+
+               gs_app_set_management_plugin (app, "Limba");
+               gs_app_set_name (app, GS_APP_QUALITY_NORMAL, li_pkg_info_get_appname (pki));
+
+               gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "Blurb. GS should parse the AppStream file 
limba placed in /var.");
+               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_kind (app, GS_APP_KIND_NORMAL);
+               gs_app_set_id_kind (app, AS_ID_KIND_DESKTOP);
+               //FIXME need to refine using AppData
+               gs_app_set_pixbuf (app, gdk_pixbuf_new_from_file 
("/usr/share/icons/hicolor/48x48/apps/meld.png", NULL));
+               gs_plugin_add_app (list, app);
+       }
+
+       return TRUE;
+}
+
+/**
+ * gs_plugin_add_sources:
+ */
+gboolean
+gs_plugin_add_sources (GsPlugin *plugin,
+                      GList **list,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       /* FIXME: Limba has no public API for that yet - needs to be added. */
+
+       return TRUE;
+}
+
+/**
+ * gs_plugin_add_updates:
+ */
+gboolean
+gs_plugin_add_updates (GsPlugin *plugin,
+                      GList **list,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+
+       _cleanup_object_unref_ LiManager *mgr = NULL;
+       _cleanup_list_free_ GList *updates = NULL;
+       GList *l;
+       GError *local_error = NULL;
+
+       mgr = li_manager_new ();
+
+       updates = li_manager_get_update_list (mgr, &local_error);
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               return FALSE;
+       }
+
+       for (l = updates; l != NULL; l = l->next) {
+               LiPkgInfo *old_p;
+               _cleanup_object_unref_ GsApp *app = NULL;
+               LiUpdateItem *uitem = LI_UPDATE_ITEM (l->data);
+
+               old_p = li_update_item_get_installed_pkg (uitem);
+               //new_p = li_update_item_get_available_pkg (uitem);
+
+               /* FIXME: We actually want the AppStream ID of the Limba bundle here.
+                * We can fetch that from the AS data (get_cpt_data()) */
+               app = gs_app_new (li_pkg_info_get_name (old_p));
+               gs_app_set_management_plugin (app, "Limba");
+               gs_app_set_state (app, AS_APP_STATE_UPDATABLE);
+               gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
+               gs_plugin_add_app (list, app);
+               gs_app_set_name (app,
+                                GS_APP_QUALITY_LOWEST,
+                                li_pkg_info_get_name (old_p));
+               gs_app_set_summary (app,
+                                   GS_APP_QUALITY_LOWEST,
+                                   li_pkg_info_get_name (old_p));
+               gs_plugin_add_app (list, app);
+       }
+
+       return TRUE;
+}
+
+/**
+ * gs_plugin_refine_item:
+ */
+static gboolean
+gs_plugin_refine_item (GsPlugin *plugin, GsApp *app, GError **error)
+{
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), "Limba") != 0)
+               return TRUE;
+
+       // TODO
+
+       return TRUE;
+}
+
+/**
+ * gs_plugin_refine:
+ */
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+                 GList **list,
+                 GsPluginRefineFlags flags,
+                 GCancellable *cancellable,
+                 GError **error)
+{
+       GList *l;
+       GsApp *app;
+
+       for (l = *list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               if (!gs_plugin_refine_item (plugin, app, error))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+#if 0
+/**
+ * gs_plugin_launch:
+ */
+gboolean
+gs_plugin_launch (GsPlugin *plugin,
+                 GsApp *app,
+                 GCancellable *cancellable,
+                 GError **error)
+{
+       /* FIXME: We need the application bundle name and the executable path here. Identify that via the
+        * software's .desktop file? */
+       const gchar *argv[] = { "runapp", gs_app_get_id (app), NULL };
+       _cleanup_strv_free_ gchar **results = NULL;
+
+       /* run tool sync */
+       ret = g_spawn_sync (NULL, (gchar **) argv, (gchar **) NULL,
+                                       G_SPAWN_SEARCH_PATH | G_SPAWN_CLOEXEC_PIPES,
+                                       NULL, NULL,
+                                       NULL, NULL,
+                                       NULL, error);
+       return TRUE;
+}
+#endif
+
+/**
+ * gs_plugin_app_remove:
+ */
+gboolean
+gs_plugin_app_remove (GsPlugin *plugin,
+                     GsApp *app,
+                     GCancellable *cancellable,
+                     GError **error)
+{
+       LiManager *mgr;
+       gboolean ret = FALSE;
+       GError *local_error = NULL;
+
+       mgr = li_manager_new ();
+
+       li_manager_remove_software (mgr,
+                                                               gs_app_get_id (app),
+                                                               &local_error);
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               goto out;
+       }
+
+       ret = TRUE;
+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;
+       gboolean ret = FALSE;
+       GError *local_error = NULL;
+
+       /* create new installer and select remote package */
+       inst = li_installer_new ();
+       li_installer_open_remote (inst,
+                                                         gs_app_get_id (app),
+                                                         &local_error);
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               goto out;
+       }
+
+       /* install software */
+       li_installer_install (inst, &local_error);
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               goto out;
+       }
+
+       ret = TRUE;
+out:
+       g_object_unref (inst);
+       return ret;
+}


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