[gnome-software/wip/attente/dpkg: 2/2] Create GsApp using dpkg-deb info



commit 8adb82bbad575bf6d95d03fcc90d984ca8f2f8ea
Author: William Hua <william hua canonical com>
Date:   Thu Mar 3 11:02:30 2016 -0500

    Create GsApp using dpkg-deb info

 src/plugins/gs-plugin-ubuntu-reviews.c |   58 ++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index c6cfbfd..089f4c9 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -21,6 +21,7 @@
 
 #include <config.h>
 
+#include <stdlib.h>
 #include <string.h>
 #include <math.h>
 #include <libsoup/soup.h>
@@ -1230,3 +1231,60 @@ gs_plugin_review_remove (GsPlugin *plugin,
 
        return remove_review (plugin, review_id, error);
 }
+
+gboolean
+gs_plugin_filename_to_app (GsPlugin      *plugin,
+                          GList        **list,
+                          const gchar   *filename,
+                          GCancellable  *cancellable,
+                          GError       **error)
+{
+       GsApp *app;
+       gchar *argv[5] = { NULL };
+       g_autofree gchar *argv0 = NULL;
+       g_autofree gchar *argv1 = NULL;
+       g_autofree gchar *argv2 = NULL;
+       g_autofree gchar *argv3 = NULL;
+       g_autofree gchar *output = NULL;
+       g_autofree gchar *description = NULL;
+       gchar **tokens = NULL;
+
+       argv[0] = argv0 = g_strdup ("dpkg-deb");
+       argv[1] = argv1 = g_strdup ("--showformat=${Package}\\n"
+                                   "${Version}\\n"
+                                   "${Installed-Size}\\n"
+                                   "${Homepage}\\n"
+                                   "${Description}");
+       argv[2] = argv2 = g_strdup ("-W");
+       argv[3] = argv3 = g_strdup (filename);
+
+       if (!g_spawn_sync (NULL,
+                          argv,
+                          NULL,
+                          G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
+                          NULL,
+                          NULL,
+                          &output,
+                          NULL,
+                          NULL,
+                          NULL))
+               return FALSE;
+
+       tokens = g_strsplit (output, "\n", 0);
+       description = g_strjoinv (NULL, tokens + 5);
+
+       app = gs_app_new (tokens[0]);
+
+       gs_app_set_name (app, GS_APP_QUALITY_HIGHEST, tokens[0]);
+       gs_app_set_version (app, tokens[1]);
+       gs_app_set_size (app, 1024 * atoi (tokens[2]));
+       gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, tokens[3]);
+       gs_app_set_summary (app, GS_APP_QUALITY_HIGHEST, tokens[4]);
+       gs_app_set_description (app, GS_APP_QUALITY_HIGHEST, description + 1);
+
+       gs_plugin_add_app (list, app);
+
+       g_strfreev (tokens);
+
+       return TRUE;
+}


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