[gnome-software] Add support for epiphany web applications



commit 82a76fc7cf5082ae11681d179b10bdd484129da8
Author: Richard Hughes <richard hughsie com>
Date:   Thu Oct 17 20:23:19 2013 +0100

    Add support for epiphany web applications

 po/POTFILES.in                            |    1 +
 src/gs-app.c                              |    2 +
 src/gs-app.h                              |    1 +
 src/gs-shell-details.c                    |   12 +-
 src/plugins/Makefile.am                   |    6 +
 src/plugins/appstream-app.h               |    1 +
 src/plugins/appstream-cache.c             |    2 +
 src/plugins/gs-plugin-epiphany.c          |  614 +++++++++++++++++++++++++++++
 src/plugins/gs-plugin-packagekit-refine.c |    2 +
 9 files changed, 639 insertions(+), 2 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1d13b71..04da3f9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -21,6 +21,7 @@ src/gs-shell-updates.c
 [type: gettext/glade]src/gs-star-widget.ui
 src/gs-utils.c
 src/plugins/gs-plugin-appstream.c
+src/plugins/gs-plugin-epiphany.c
 src/plugins/gs-plugin-hardcoded-popular.c
 src/plugins/gs-plugin-packagekit.c
 src/plugins/gs-plugin-packagekit-refine.c
diff --git a/src/gs-app.c b/src/gs-app.c
index 1bd5006..8ce35c4 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -183,6 +183,8 @@ gs_app_id_kind_to_string (GsAppIdKind id_kind)
                return "font";
        if (id_kind == GS_APP_ID_KIND_CODEC)
                return "codec";
+       if (id_kind == GS_APP_ID_KIND_WEBAPP)
+               return "webapp";
        return NULL;
 }
 
diff --git a/src/gs-app.h b/src/gs-app.h
index 2480ad7..f59db77 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -83,6 +83,7 @@ typedef enum {
        GS_APP_ID_KIND_INPUT_METHOD,
        GS_APP_ID_KIND_FONT,
        GS_APP_ID_KIND_CODEC,
+       GS_APP_ID_KIND_WEBAPP,
        GS_APP_ID_KIND_LAST
 } GsAppIdKind;
 
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index e856c9b..00dbf0c 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -498,9 +498,17 @@ gs_shell_details_refresh_all (GsShellDetails *shell_details)
                                   gs_app_get_rating (priv->app));
 
        /* make history button insensitive if there is none */
-       history = gs_app_get_history (priv->app);
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_history"));
-       gtk_widget_set_sensitive (widget, history->len > 0);
+       switch (gs_app_get_id_kind (priv->app)) {
+       case GS_APP_ID_KIND_WEBAPP:
+               gtk_widget_set_visible (widget, FALSE);
+               break;
+       default:
+               history = gs_app_get_history (priv->app);
+               gtk_widget_set_sensitive (widget, history->len > 0);
+               gtk_widget_set_visible (widget, TRUE);
+               break;
+       }
 }
 
 /**
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 5c6aecc..89c2d29 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -37,6 +37,7 @@ plugin_LTLIBRARIES =                                  \
        libgs_plugin_menu-spec-refine.la                \
        libgs_plugin_local-ratings.la                   \
        libgs_plugin_fedora_tagger.la                   \
+       libgs_plugin_epiphany.la                        \
        libgs_plugin_systemd-updates.la                 \
        libgs_plugin_packagekit-refine.la               \
        libgs_plugin_packagekit-updates.la              \
@@ -54,6 +55,11 @@ libgs_plugin_fedora_tagger_la_LIBADD = $(GS_PLUGIN_LIBS) $(SOUP_LIBS) $(SQLITE_L
 libgs_plugin_fedora_tagger_la_LDFLAGS = -module -avoid-version
 libgs_plugin_fedora_tagger_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
 
+libgs_plugin_epiphany_la_SOURCES = gs-plugin-epiphany.c
+libgs_plugin_epiphany_la_LIBADD = $(GS_PLUGIN_LIBS) $(SOUP_LIBS)
+libgs_plugin_epiphany_la_LDFLAGS = -module -avoid-version
+libgs_plugin_epiphany_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
+
 libgs_plugin_self_test_la_SOURCES = gs-plugin-self-test.c
 libgs_plugin_self_test_la_LIBADD = $(GS_PLUGIN_LIBS)
 libgs_plugin_self_test_la_LDFLAGS = -module -avoid-version
diff --git a/src/plugins/appstream-app.h b/src/plugins/appstream-app.h
index ecd0da1..ac2329e 100644
--- a/src/plugins/appstream-app.h
+++ b/src/plugins/appstream-app.h
@@ -42,6 +42,7 @@ typedef enum {
        APPSTREAM_APP_ID_KIND_INPUT_METHOD,
        APPSTREAM_APP_ID_KIND_FONT,
        APPSTREAM_APP_ID_KIND_CODEC,
+       APPSTREAM_APP_ID_KIND_WEBAPP,
        APPSTREAM_APP_ID_KIND_LAST
 } AppstreamAppIdKind;
 
diff --git a/src/plugins/appstream-cache.c b/src/plugins/appstream-cache.c
index fd7ba6d..2a95a68 100644
--- a/src/plugins/appstream-cache.c
+++ b/src/plugins/appstream-cache.c
@@ -136,6 +136,8 @@ appstream_cache_app_id_kind_from_string (const gchar *id_kind)
                return APPSTREAM_APP_ID_KIND_FONT;
        if (g_strcmp0 (id_kind, "codec") == 0)
                return APPSTREAM_APP_ID_KIND_CODEC;
+       if (g_strcmp0 (id_kind, "webapp") == 0)
+               return APPSTREAM_APP_ID_KIND_WEBAPP;
        return APPSTREAM_APP_ID_KIND_UNKNOWN;
 }
 
diff --git a/src/plugins/gs-plugin-epiphany.c b/src/plugins/gs-plugin-epiphany.c
new file mode 100644
index 0000000..3e8e6e1
--- /dev/null
+++ b/src/plugins/gs-plugin-epiphany.c
@@ -0,0 +1,614 @@
+/* -*- 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>
+
+#define _GNU_SOURCE
+#include <string.h>
+
+#include <glib/gi18n.h>
+#include <libsoup/soup.h>
+
+#include <gs-plugin.h>
+#include <gs-utils.h>
+
+struct GsPluginPrivate {
+       GList                   *list;
+       SoupSession             *session;
+       gsize                    loaded;
+};
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+       return "epiphany";
+}
+
+/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+       plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+
+       /* we can only work with epiphany */
+       if (!g_file_test ("/usr/bin/epiphany", G_FILE_TEST_EXISTS)) {
+               gs_plugin_set_enabled (plugin, FALSE);
+               g_warning ("disabling '%s' as epiphany does not exist",
+                          plugin->name);
+       }
+}
+
+/**
+ * gs_plugin_get_priority:
+ */
+gdouble
+gs_plugin_get_priority (GsPlugin *plugin)
+{
+       return 1.0f;
+}
+
+/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+       if (plugin->priv->session != NULL)
+               g_object_unref (plugin->priv->session);
+       gs_plugin_list_free (plugin->priv->list);
+}
+
+/**
+ * gs_plugin_add_installed_file:
+ */
+static gboolean
+gs_plugin_add_installed_file (GsPlugin *plugin,
+                             const gchar *filename,
+                             GsApp **app,
+                             GError **error)
+{
+       GKeyFile *kf;
+       gboolean no_display;
+       gboolean ret;
+       gchar *app_id = NULL;
+       gchar *comment = NULL;
+       gchar *icon = NULL;
+       gchar *name = NULL;
+       gchar *path;
+       gchar *tmp;
+
+       /* load keyfile */
+       path = g_build_filename (g_get_user_data_dir (),
+                                "applications",
+                                filename,
+                                NULL);
+       kf = g_key_file_new ();
+       ret = g_key_file_load_from_file (kf, path, G_KEY_FILE_NONE, error);
+       if (!ret)
+               goto out;
+
+       /* check we're showing this */
+       no_display = g_key_file_get_boolean (kf,
+                                            G_KEY_FILE_DESKTOP_GROUP,
+                                            G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,
+                                            NULL);
+
+       /* get name */
+       name = g_key_file_get_locale_string (kf,
+                                            G_KEY_FILE_DESKTOP_GROUP,
+                                            G_KEY_FILE_DESKTOP_KEY_NAME,
+                                            NULL,
+                                            error);
+       if (name == NULL) {
+               ret = FALSE;
+               goto out;
+       }
+
+       /* get icon */
+       icon = g_key_file_get_locale_string (kf,
+                                            G_KEY_FILE_DESKTOP_GROUP,
+                                            G_KEY_FILE_DESKTOP_KEY_ICON,
+                                            NULL,
+                                            error);
+       if (icon == NULL) {
+               ret = FALSE;
+               goto out;
+       }
+
+       /* get comment */
+       comment = g_key_file_get_locale_string (kf,
+                                               G_KEY_FILE_DESKTOP_GROUP,
+                                               G_KEY_FILE_DESKTOP_KEY_COMMENT,
+                                               NULL,
+                                               NULL);
+       if (comment == NULL) {
+               /* TRANSLATORS: this is when a webapp has no comment */
+               comment = g_strdup_printf (_("Web app"));
+       }
+
+       /* create application */
+       app_id = g_strdup (filename);
+       tmp = g_strrstr (app_id, ".");
+       if (tmp != NULL)
+               *tmp = '\0';
+       *app = gs_app_new (app_id);
+       gs_app_set_name (*app, name);
+       gs_app_set_summary (*app, comment);
+       /* TRANSLATORS: this is the licence of the web-app */
+       gs_app_set_licence (*app, _("Proprietary"));
+       gs_app_set_state (*app, no_display ? GS_APP_STATE_AVAILABLE :
+                                            GS_APP_STATE_INSTALLED);
+       gs_app_set_kind (*app, GS_APP_KIND_NORMAL);
+       gs_app_set_id_kind (*app, GS_APP_ID_KIND_WEBAPP);
+       gs_app_set_metadata (*app, "Epiphany::desktop-filename", path);
+       ret = gs_app_set_icon (*app, icon, error);
+       if (!ret)
+               goto out;
+out:
+       g_key_file_free (kf);
+       g_free (app_id);
+       g_free (path);
+       g_free (icon);
+       g_free (name);
+       g_free (comment);
+       return ret;
+}
+
+/**
+ * gs_plugin_epiphany_load_db:
+ */
+static gboolean
+gs_plugin_epiphany_load_db (GsPlugin *plugin, GError **error)
+{
+       GDir *dir;
+       GsApp *app = NULL;
+       const gchar *filename;
+       gboolean ret = TRUE;
+       gchar *path;
+
+       /* find any web apps */
+       path = g_build_filename (g_get_user_data_dir (), "applications", NULL);
+       dir = g_dir_open (path, 0, error);
+       if (dir == NULL) {
+               ret = FALSE;
+               goto out;
+       }
+       while ((filename = g_dir_read_name (dir)) != NULL) {
+               if (!g_str_has_prefix (filename, "epiphany"))
+                       continue;
+               if (!g_str_has_suffix (filename, ".desktop"))
+                       continue;
+               ret = gs_plugin_add_installed_file (plugin,
+                                                   filename,
+                                                   &app,
+                                                   error);
+               if (!ret)
+                       goto out;
+               if (app != NULL) {
+                       gs_plugin_add_app (&plugin->priv->list, app);
+                       g_clear_object (&app);
+               }
+       }
+out:
+       g_free (path);
+       if (dir != NULL)
+               g_dir_close (dir);
+       return ret;
+}
+
+/**
+ * gs_plugin_add_installed:
+ */
+gboolean
+gs_plugin_add_installed (GsPlugin *plugin,
+                        GList **list,
+                        GCancellable *cancellable,
+                        GError **error)
+{
+       GList *l;
+       GsApp *app;
+       gboolean ret = TRUE;
+
+       /* already loaded */
+       if (g_once_init_enter (&plugin->priv->loaded)) {
+               ret = gs_plugin_epiphany_load_db (plugin, error);
+               g_once_init_leave (&plugin->priv->loaded, TRUE);
+               if (!ret)
+                       goto out;
+       }
+
+       /* add all installed apps */
+       for (l = plugin->priv->list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               if (gs_app_get_state (app) != GS_APP_STATE_INSTALLED)
+                       continue;
+               gs_plugin_add_app (list, app);
+       }
+out:
+       return ret;
+}
+
+/**
+ * gs_plugin_add_search:
+ */
+gboolean
+gs_plugin_add_search (GsPlugin *plugin,
+                     const gchar *value,
+                     GList **list,
+                     GCancellable *cancellable,
+                     GError **error)
+{
+       GList *l;
+       GsApp *app;
+       gboolean ret = TRUE;
+
+       /* already loaded */
+       if (g_once_init_enter (&plugin->priv->loaded)) {
+               ret = gs_plugin_epiphany_load_db (plugin, error);
+               g_once_init_leave (&plugin->priv->loaded, TRUE);
+               if (!ret)
+                       goto out;
+       }
+
+       /* add any matching apps */
+       for (l = plugin->priv->list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               if (strcasestr (gs_app_get_name (app), value) != NULL ||
+                   strcasestr (gs_app_get_summary (app), value) != NULL)
+                       gs_plugin_add_app (list, app);
+       }
+out:
+       return ret;
+}
+
+/**
+ * gs_plugin_app_set_enabled:
+ */
+static gboolean
+gs_plugin_app_set_enabled (const gchar *filename, gboolean enabled, GError **error)
+{
+       GKeyFile *kf;
+       gboolean ret;
+       gchar *data = NULL;
+       gsize length;
+
+       /* load file */
+       kf = g_key_file_new ();
+       ret = g_key_file_load_from_file (kf, filename, G_KEY_FILE_NONE, error);
+       if (!ret)
+               goto out;
+
+       /* change value */
+       g_key_file_set_boolean (kf,
+                               G_KEY_FILE_DESKTOP_GROUP,
+                               G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,
+                               !enabled);
+
+       /* save value */
+       data = g_key_file_to_data (kf, &length, error);
+       if (data == NULL) {
+               ret = FALSE;
+               goto out;
+       }
+       ret = g_file_set_contents (filename, data, length, error);
+       if (!ret)
+               goto out;
+out:
+       g_free (data);
+       g_key_file_free (kf);
+       return ret;
+}
+
+/**
+ * gs_plugin_app_install:
+ */
+gboolean
+gs_plugin_app_install (GsPlugin *plugin,
+                      GsApp *app,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       const gchar *filename;
+       gboolean ret = TRUE;
+
+       /* is this a web app */
+       filename = gs_app_get_metadata_item (app, "Epiphany::desktop-filename");
+       if (filename != NULL) {
+               ret = gs_plugin_app_set_enabled (filename, TRUE, error);
+               if (!ret)
+                       goto out;
+               gs_app_set_state (app, GS_APP_STATE_INSTALLED);
+       }
+out:
+       return ret;
+}
+
+/**
+ * gs_plugin_app_remove:
+ */
+gboolean
+gs_plugin_app_remove (GsPlugin *plugin,
+                     GsApp *app,
+                     GCancellable *cancellable,
+                     GError **error)
+{
+       const gchar *filename;
+       gboolean ret = TRUE;
+
+       /* is this a web app */
+       filename = gs_app_get_metadata_item (app, "Epiphany::desktop-filename");
+       if (filename != NULL) {
+               ret = gs_plugin_app_set_enabled (filename, FALSE, error);
+               if (!ret)
+                       goto out;
+               gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
+       }
+out:
+       return ret;
+}
+
+/**
+ * gs_plugin_write_file:
+ */
+static gboolean
+gs_plugin_write_file (GsApp *app, const gchar *filename, GError **error)
+{
+       GKeyFile *kf;
+       const gchar *url;
+       gboolean ret;
+       gchar *data;
+       gchar *exec;
+       gchar *profile;
+       gchar *wmclass;
+       gsize length;
+
+       kf = g_key_file_new ();
+       g_key_file_set_string (kf,
+                              G_KEY_FILE_DESKTOP_GROUP,
+                              G_KEY_FILE_DESKTOP_KEY_NAME,
+                              gs_app_get_name (app));
+       g_key_file_set_string (kf,
+                              G_KEY_FILE_DESKTOP_GROUP,
+                              G_KEY_FILE_DESKTOP_KEY_COMMENT,
+                              gs_app_get_summary (app));
+
+       url = gs_app_get_url (app, GS_APP_URL_KIND_HOMEPAGE);
+       wmclass = g_strdup_printf ("%s-%s",
+                                  gs_app_get_id (app),
+                                  gs_app_get_metadata_item (app, "Epiphany::hash"));
+       profile = g_strdup_printf ("%s/epiphany/app-%s",
+                                  g_get_user_config_dir (), wmclass);
+       exec = g_strdup_printf ("epiphany --application-mode "
+                               "--profile=\"%s\" %s", profile, url);
+       g_key_file_set_string (kf,
+                              G_KEY_FILE_DESKTOP_GROUP,
+                              G_KEY_FILE_DESKTOP_KEY_EXEC,
+                              exec);
+       g_key_file_set_boolean (kf,
+                               G_KEY_FILE_DESKTOP_GROUP,
+                               G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY,
+                               TRUE);
+       g_key_file_set_boolean (kf,
+                               G_KEY_FILE_DESKTOP_GROUP,
+                               G_KEY_FILE_DESKTOP_KEY_TERMINAL,
+                               FALSE);
+       g_key_file_set_boolean (kf,
+                               G_KEY_FILE_DESKTOP_GROUP,
+                               G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,
+                               gs_app_get_state (app) == GS_APP_STATE_INSTALLED ? FALSE : TRUE);
+       g_key_file_set_string (kf,
+                              G_KEY_FILE_DESKTOP_GROUP,
+                              G_KEY_FILE_DESKTOP_KEY_TYPE,
+                              G_KEY_FILE_DESKTOP_TYPE_APPLICATION);
+       g_key_file_set_string (kf,
+                              G_KEY_FILE_DESKTOP_GROUP,
+                              G_KEY_FILE_DESKTOP_KEY_ICON,
+                              gs_app_get_icon (app));
+       g_key_file_set_string (kf,
+                              G_KEY_FILE_DESKTOP_GROUP,
+                              G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS,
+                              wmclass);
+
+       /* save keyfile */
+       data = g_key_file_to_data (kf, &length, error);
+       if (data == NULL) {
+               ret = FALSE;
+               goto out;
+       }
+       ret = g_file_set_contents (filename, data, length, error);
+       if (!ret)
+               goto out;
+out:
+       g_free (profile);
+       g_free (exec);
+       g_free (wmclass);
+       g_key_file_free (kf);
+       return ret;
+}
+
+/**
+ * gs_plugin_setup_networking:
+ */
+static gboolean
+gs_plugin_setup_networking (GsPlugin *plugin, GError **error)
+{
+       gboolean ret = TRUE;
+
+       /* already set up */
+       if (plugin->priv->session != NULL)
+               goto out;
+
+       /* set up a session */
+       plugin->priv->session = soup_session_sync_new_with_options (SOUP_SESSION_USER_AGENT,
+                                                                   "gnome-software",
+                                                                   SOUP_SESSION_TIMEOUT, 5000,
+                                                                   NULL);
+       if (plugin->priv->session == NULL) {
+               ret = FALSE;
+               g_set_error (error,
+                            GS_PLUGIN_ERROR,
+                            GS_PLUGIN_ERROR_FAILED,
+                            "%s: failed to setup networking",
+                            plugin->name);
+               goto out;
+       }
+       soup_session_add_feature_by_type (plugin->priv->session,
+                                         SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
+out:
+       return ret;
+}
+
+/**
+ * gs_plugin_epiphany_download:
+ */
+static gboolean
+gs_plugin_epiphany_download (GsPlugin *plugin, const gchar *uri, const gchar *filename, GError **error)
+{
+       SoupMessage *msg = NULL;
+       gboolean ret = TRUE;
+       guint status_code;
+
+       /* create the GET data */
+       msg = soup_message_new (SOUP_METHOD_GET, uri);
+
+       /* ensure networking is set up */
+       ret = gs_plugin_setup_networking (plugin, error);
+       if (!ret)
+               goto out;
+
+       /* set sync request */
+       status_code = soup_session_send_message (plugin->priv->session, msg);
+       if (status_code != SOUP_STATUS_OK) {
+               ret = FALSE;
+               g_set_error (error,
+                            GS_PLUGIN_ERROR,
+                            GS_PLUGIN_ERROR_FAILED,
+                            "Failed to set rating on fedora-tagger: %s",
+                            soup_status_get_phrase (status_code));
+               goto out;
+       }
+
+       /* process the tab-delimited data */
+       ret = g_file_set_contents (filename,
+                                  msg->response_body->data,
+                                  msg->response_body->length,
+                                  error);
+       if (!ret)
+               goto out;
+out:
+       if (msg != NULL)
+               g_object_unref (msg);
+       return ret;
+}
+
+/**
+ * gs_plugin_refine_app:
+ */
+static gboolean
+gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
+{
+       gboolean ret;
+       gchar *filename = NULL;
+       gchar *path = NULL;
+       gchar *filename_icon = NULL;
+       gchar *hash;
+
+       /* this is not yet installed */
+       gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
+
+       /* calculate SHA1 hash of name */
+       hash = g_compute_checksum_for_string (G_CHECKSUM_SHA1, gs_app_get_name (app), -1);
+       gs_app_set_metadata (app, "Epiphany::hash", hash);
+
+       /* download icon */
+       filename_icon = g_strdup_printf ("%s/epiphany/app-%s-%s/app-icon.png",
+                                        g_get_user_config_dir (),
+                                        gs_app_get_id (app),
+                                        hash);
+       ret = gs_mkdir_parent (filename_icon, error);
+       if (!ret)
+               goto out;
+       ret = gs_plugin_epiphany_download (plugin,
+                                          gs_app_get_icon (app),
+                                          filename_icon,
+                                          error);
+       if (!ret)
+               goto out;
+
+       /* set local icon name */
+       ret = gs_app_set_icon (app, filename_icon, error);
+       if (!ret)
+               goto out;
+
+       /* save file */
+       filename = g_strdup_printf ("%s.desktop", gs_app_get_id (app));
+       path = g_build_filename (g_get_user_data_dir (),
+                                "applications",
+                                filename,
+                                NULL);
+       ret = gs_plugin_write_file (app, path, error);
+       if (!ret)
+               goto out;
+       gs_app_set_metadata (app, "Epiphany::desktop-filename", path);
+out:
+       g_free (hash);
+       g_free (path);
+       g_free (filename);
+       g_free (filename_icon);
+       return ret;
+}
+
+/**
+ * gs_plugin_refine:
+ */
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+                 GList *list,
+                 GsPluginRefineFlags flags,
+                 GCancellable *cancellable,
+                 GError **error)
+{
+       GList *l;
+       GsApp *app;
+       const gchar *tmp;
+       gboolean ret = TRUE;
+
+       for (l = list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               if (gs_app_get_id_kind (app) != GS_APP_ID_KIND_WEBAPP)
+                       continue;
+               gs_app_set_source (app, "");
+               gs_app_set_size (app, 4096);
+               tmp = gs_app_get_metadata_item (app, "Epiphany::desktop-filename");
+               if (tmp != NULL)
+                       continue;
+               ret = gs_plugin_refine_app (plugin, app, error);
+               if (!ret)
+                       goto out;
+       }
+out:
+       return ret;
+}
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index b32db38..ce986e1 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -566,6 +566,8 @@ gs_plugin_refine (GsPlugin *plugin,
                app = GS_APP (l->data);
                if (gs_app_get_metadata_item (app, "PackageKit::package-id") != NULL)
                        continue;
+               if (gs_app_get_id_kind (app) == GS_APP_ID_KIND_WEBAPP)
+                       continue;
                tmp = gs_app_get_source (app);
                if (tmp != NULL)
                        resolve_all = g_list_prepend (resolve_all, app);


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