[gnome-software/wip/mak/limba: 65/65] limba: Adjust plugin to use the new bundle property
- From: Matthias Klumpp <mak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/mak/limba: 65/65] limba: Adjust plugin to use the new bundle property
- Date: Wed, 24 Jun 2015 12:47:56 +0000 (UTC)
commit b938fb2461fbf094d03678f2c809e22db5569f74
Author: Matthias Klumpp <matthias tenstral net>
Date: Tue Jun 2 20:23:07 2015 +0200
limba: Adjust plugin to use the new bundle property
src/plugins/gs-plugin-limba.c | 273 ++++++++++++++++++++---------------------
1 files changed, 135 insertions(+), 138 deletions(-)
---
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
index e42b71a..baf9a54 100644
--- a/src/plugins/gs-plugin-limba.c
+++ b/src/plugins/gs-plugin-limba.c
@@ -23,11 +23,12 @@
#include <config.h>
#include <limba.h>
+#include <appstream-glib.h>
#include "gs-cleanup.h"
#include <gs-plugin.h>
struct GsPluginPrivate {
- guint dummy;
+ LiManager *mgr;
};
/**
@@ -47,7 +48,7 @@ gs_plugin_initialize (GsPlugin *plugin)
{
/* create private area */
plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
- plugin->priv->dummy = 999;
+ plugin->priv->mgr = li_manager_new ();
}
/**
@@ -56,7 +57,7 @@ gs_plugin_initialize (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- plugin->priv->dummy = 0;
+ g_object_unref (plugin->priv->mgr);
}
/**
@@ -73,127 +74,46 @@ gs_plugin_add_search (GsPlugin *plugin,
}
/**
- * gs_plugin_add_installed:
+ * gs_plugin_refine_app:
*/
-gboolean
-gs_plugin_add_installed (GsPlugin *plugin,
- GList **list,
- GCancellable *cancellable,
- GError **error)
+static gboolean
+gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
{
- _cleanup_object_unref_ LiManager *mgr = NULL;
- _cleanup_list_free_ GList *sw = NULL;
- GList *l;
+ AsBundle *bundle;
+ LiPkgInfo *pki;
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)
-{
+ bundle = gs_app_get_bundle (app);
- _cleanup_object_unref_ LiManager *mgr = NULL;
- _cleanup_list_free_ GList *updates = NULL;
- GList *l;
- GError *local_error = NULL;
-
- mgr = li_manager_new ();
+ /* check if we should process this application */
+ if (bundle == NULL)
+ return TRUE;
+ if (as_bundle_get_kind (bundle) != AS_BUNDLE_KIND_LIMBA)
+ return TRUE;
- updates = li_manager_get_update_list (mgr, &local_error);
+ 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;
}
- 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);
+ /* we will handle installations and removals of this application */
+ gs_app_set_management_plugin (app, "Limba");
- /* 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);
- }
+ if (pki == NULL)
+ return TRUE;
- 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_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;
+ gs_app_set_version (app, li_pkg_info_get_version (pki));
- // TODO
+ /* FIXME: Simply have it use the Limba-provided icons */
+ gs_app_set_pixbuf (app, gdk_pixbuf_new_from_file ("/usr/share/icons/hicolor/48x48/apps/meld.png",
NULL));
return TRUE;
}
@@ -208,41 +128,28 @@ gs_plugin_refine (GsPlugin *plugin,
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_plugin_refine_item (plugin, app, error))
- return FALSE;
+
+ if (gs_app_get_bundle (app) == NULL)
+ continue;
+
+ ret = gs_plugin_refine_app (plugin, app, error);
+ if (!ret)
+ goto out;
}
- 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;
+ /* sucess */
+ ret = TRUE;
+out:
+ gs_profile_stop (plugin->profile, "limba::refine");
+ return ret;
}
-#endif
/**
* gs_plugin_app_remove:
@@ -254,20 +161,33 @@ gs_plugin_app_remove (GsPlugin *plugin,
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,
- gs_app_get_id (app),
+ 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;
@@ -283,13 +203,22 @@ gs_plugin_app_install (GsPlugin *plugin,
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,
- gs_app_get_id (app),
+ as_bundle_get_id (bundle),
&local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
@@ -297,14 +226,82 @@ gs_plugin_app_install (GsPlugin *plugin,
}
/* 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;
}
+
+/**
+ * gs_plugin_add_sources:
+ */
+gboolean
+gs_plugin_add_sources (GsPlugin *plugin,
+ GList **list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* TODO: Limba does not expose "simple" API for this - add this feature later. */
+
+ 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;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]