[gnome-software] Use the new url_to_app() functionality from the GApplication::open handler
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Use the new url_to_app() functionality from the GApplication::open handler
- Date: Thu, 2 Feb 2017 12:51:06 +0000 (UTC)
commit 755934434eba2eb6b73c8225698a4666da51eb38
Author: Richard Hughes <richard hughsie com>
Date: Thu Feb 2 12:39:48 2017 +0000
Use the new url_to_app() functionality from the GApplication::open handler
This is much cleaner than setting the source and/or management plugin from the
GsApplication instance.
src/gs-application.c | 47 +++++++++++++++++++------------------
src/plugins/gs-plugin-appstream.c | 30 +++++++++++++++++++++++
src/plugins/gs-plugin-snap.c | 23 ++++++++++++++++++
3 files changed, 77 insertions(+), 23 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 43d8fe7..0f6ace1 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -572,6 +572,26 @@ details_pkg_activated (GSimpleAction *action,
}
static void
+details_url_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer data)
+{
+ GsApplication *app = GS_APPLICATION (data);
+ const gchar *url;
+ g_autoptr (GsApp) a = NULL;
+
+ initialize_ui_and_present_window (app, NULL);
+
+ g_variant_get (parameter, "(&s)", &url);
+
+ /* this is only used as a wrapper to transport the URL to
+ * the gs_shell_change_mode() function -- not in the GsAppList */
+ a = gs_app_new (NULL);
+ gs_app_set_metadata (a, "GnomeSoftware::from-url", url);
+ gs_shell_show_app (app->shell, a);
+}
+
+static void
install_activated (GSimpleAction *action,
GVariant *parameter,
gpointer data)
@@ -702,6 +722,7 @@ static GActionEntry actions[] = {
{ "search", search_activated, "s", NULL, NULL },
{ "details", details_activated, "(ss)", NULL, NULL },
{ "details-pkg", details_pkg_activated, "(ss)", NULL, NULL },
+ { "details-url", details_url_activated, "(s)", NULL, NULL },
{ "install", install_activated, "(su)", NULL, NULL },
{ "filename", filename_activated, "(s)", NULL, NULL },
{ "launch", launch_activated, "s", NULL, NULL },
@@ -913,29 +934,9 @@ gs_application_open (GApplication *application,
for (i = 0; i < n_files; i++) {
g_autofree gchar *str = g_file_get_uri (files[i]);
- g_autofree gchar *scheme = NULL;
- g_autofree gchar *path = NULL;
-
- scheme = gs_utils_get_url_scheme (str);
- if (scheme == NULL)
- continue;
- path = gs_utils_get_url_path (str);
- if (path == NULL)
- continue;
-
- if (g_strcmp0 (scheme, "appstream") == 0) {
- g_action_group_activate_action (G_ACTION_GROUP (app),
- "details",
- g_variant_new ("(ss)", path, ""));
- } else if (g_strcmp0 (scheme, "apt") == 0) {
- g_action_group_activate_action (G_ACTION_GROUP (app),
- "details-pkg",
- g_variant_new ("(ss)", path, "apt"));
- } else if (g_strcmp0 (scheme, "snap") == 0) {
- g_action_group_activate_action (G_ACTION_GROUP (app),
- "details-pkg",
- g_variant_new ("(ss)", path, "snap"));
- }
+ g_action_group_activate_action (G_ACTION_GROUP (app),
+ "details-url",
+ g_variant_new ("(s)", str));
}
}
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index d793a17..7b54cb9 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -319,6 +319,36 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
return TRUE;
}
+gboolean
+gs_plugin_url_to_app (GsPlugin *plugin,
+ GsAppList *list,
+ const gchar *url,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ AsApp *item;
+ g_autofree gchar *path = NULL;
+ g_autofree gchar *scheme = NULL;
+ g_autoptr(GsApp) app = NULL;
+
+ /* not us */
+ scheme = gs_utils_get_url_scheme (url);
+ if (g_strcmp0 (scheme, "appstream") != 0)
+ return TRUE;
+
+ /* create app */
+ path = gs_utils_get_url_path (url);
+ item = as_store_get_app_by_id (priv->store, path);
+ if (item == NULL)
+ return TRUE;
+ app = gs_appstream_create_app (plugin, item, error);
+ if (app == NULL)
+ return FALSE;
+ gs_app_list_add (list, app);
+ return TRUE;
+}
+
static gboolean
gs_plugin_refine_from_id (GsPlugin *plugin,
GsApp *app,
diff --git a/src/plugins/gs-plugin-snap.c b/src/plugins/gs-plugin-snap.c
index 101a6f5..50f8bcb 100644
--- a/src/plugins/gs-plugin-snap.c
+++ b/src/plugins/gs-plugin-snap.c
@@ -74,6 +74,29 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
return TRUE;
}
+gboolean
+gs_plugin_url_to_app (GsPlugin *plugin,
+ GsAppList *list,
+ const gchar *url,
+ GCancellable *cancellable,
+ GError **error)
+{
+// g_autofree gchar *path = NULL;
+ g_autofree gchar *scheme = NULL;
+// g_autoptr(GsApp) app = NULL;
+
+ /* not us */
+ scheme = gs_utils_get_url_scheme (url);
+ if (g_strcmp0 (scheme, "snap") != 0)
+ return TRUE;
+
+ /* create app */
+// path = gs_utils_get_url_path (url);
+//FIXME: find/create an app using the URL path
+// gs_app_list_add (list, app);
+ return TRUE;
+}
+
static void
get_macaroon (GsPlugin *plugin, gchar **macaroon, gchar ***discharges)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]