[gnome-software] Add a 'filename' action that can display details about a local file
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add a 'filename' action that can display details about a local file
- Date: Wed, 29 Jan 2014 11:42:33 +0000 (UTC)
commit 66db1fa5e64521fe13ac049ef2aedbb25ea20660
Author: Richard Hughes <richard hughsie com>
Date: Wed Jan 29 11:37:43 2014 +0000
Add a 'filename' action that can display details about a local file
src/gs-application.c | 24 +++++++++++++++++-
src/gs-shell-details.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
src/gs-shell-details.h | 2 +
src/gs-shell.c | 16 +++++++++++-
src/gs-shell.h | 2 +
5 files changed, 103 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 9013c81..5d9382a 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -341,6 +341,20 @@ details_activated (GSimpleAction *action,
}
static void
+filename_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer data)
+{
+ GsApplication *app = GS_APPLICATION (data);
+ const gchar *filename;
+
+ gs_application_initialize_ui (app);
+
+ g_variant_get (parameter, "(&s)", &filename);
+ gs_shell_show_filename (app->shell, filename);
+}
+
+static void
launch_activated (GSimpleAction *action,
GVariant *parameter,
gpointer data)
@@ -392,6 +406,7 @@ static GActionEntry actions[] = {
{ "set-mode", set_mode_activated, "s", NULL, NULL },
{ "search", search_activated, "s", NULL, NULL },
{ "details", details_activated, "(ss)", NULL, NULL },
+ { "filename", filename_activated, "(s)", NULL, NULL },
{ "launch", launch_activated, "s", NULL, NULL },
{ "clear-offline-updates", clear_offline_updates, NULL, NULL, NULL },
{ "show-offline-update-error", show_offline_updates_error, NULL, NULL, NULL },
@@ -450,6 +465,7 @@ gs_application_local_command_line (GApplication *app, gchar ***args, gint *statu
gboolean gapplication_service = FALSE;
gchar *mode = NULL;
gchar *search = NULL;
+ gchar *local_filename = NULL;
gchar *id = NULL;
gboolean activate_ui = TRUE;
gboolean version = FALSE;
@@ -466,6 +482,8 @@ gs_application_local_command_line (GApplication *app, gchar ***args, gint *statu
_("Search for applications"), _("SEARCH") },
{ "details", '\0', 0, G_OPTION_ARG_STRING, &id,
_("Show application details"), _("ID") },
+ { "local-filename", '\0', 0, G_OPTION_ARG_FILENAME, &local_filename,
+ _("Show application details"), _("ID") },
{ "verbose", '\0', 0, G_OPTION_ARG_NONE, &verbose,
_("Set the specified debugging level"), _("ID") },
{ "profile", 0, 0, G_OPTION_ARG_NONE, &profile,
@@ -529,6 +547,10 @@ gs_application_local_command_line (GApplication *app, gchar ***args, gint *statu
g_action_group_activate_action (G_ACTION_GROUP (app),
"details",
g_variant_new ("(ss)", id, ""));
+ } else if (local_filename != NULL) {
+ g_action_group_activate_action (G_ACTION_GROUP (app),
+ "filename",
+ g_variant_new ("(s)", local_filename));
} else if (activate_ui) {
g_application_activate (app);
}
@@ -537,7 +559,7 @@ gs_application_local_command_line (GApplication *app, gchar ***args, gint *statu
out:
g_option_context_free (context);
-
+ g_free (local_filename);
return TRUE;
}
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index c75c304..6c12dde 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -688,6 +688,68 @@ gs_shell_details_app_refine_cb (GObject *source,
}
/**
+ * gs_shell_details_filename_to_app_cb:
+ **/
+static void
+gs_shell_details_filename_to_app_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ gchar *tmp;
+ GError *error = NULL;
+ GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
+ GsShellDetails *shell_details = GS_SHELL_DETAILS (user_data);
+ GsShellDetailsPrivate *priv = shell_details->priv;
+
+ if (priv->app != NULL)
+ g_object_unref (priv->app);
+ priv->app = gs_plugin_loader_filename_to_app_finish(plugin_loader,
+ res,
+ &error);
+ if (priv->app == NULL) {
+ g_warning ("failed to convert to GsApp: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ /* save app */
+ g_signal_connect_object (priv->app, "notify::state",
+ G_CALLBACK (gs_shell_details_notify_state_changed_cb),
+ shell_details, 0);
+ g_signal_connect_object (priv->app, "notify::size",
+ G_CALLBACK (gs_shell_details_notify_state_changed_cb),
+ shell_details, 0);
+ g_signal_connect_object (priv->app, "notify::licence",
+ G_CALLBACK (gs_shell_details_notify_state_changed_cb),
+ shell_details, 0);
+
+ /* print what we've got */
+ tmp = gs_app_to_string (priv->app);
+ g_debug ("%s", tmp);
+ g_free (tmp);
+
+ /* change widgets */
+ gs_shell_details_refresh (shell_details);
+ gs_shell_details_refresh_all (shell_details);
+}
+
+/**
+ * gs_shell_details_set_filename:
+ **/
+void
+gs_shell_details_set_filename (GsShellDetails *shell_details, const gchar *filename)
+{
+ GsShellDetailsPrivate *priv = shell_details->priv;
+ gs_plugin_loader_filename_to_app_async (priv->plugin_loader,
+ filename,
+ GS_PLUGIN_REFINE_FLAGS_DEFAULT |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING,
+ priv->cancellable,
+ gs_shell_details_filename_to_app_cb,
+ shell_details);
+}
+
+/**
* gs_shell_details_set_app:
**/
void
diff --git a/src/gs-shell-details.h b/src/gs-shell-details.h
index b0c45fa..37e2af8 100644
--- a/src/gs-shell-details.h
+++ b/src/gs-shell-details.h
@@ -57,6 +57,8 @@ GsShellDetails *gs_shell_details_new (void);
void gs_shell_details_invalidate (GsShellDetails *shell_details);
void gs_shell_details_set_app (GsShellDetails *shell_details,
GsApp *app);
+void gs_shell_details_set_filename (GsShellDetails *shell_details,
+ const gchar *filename);
GsApp *gs_shell_details_get_app (GsShellDetails *shell_details);
void gs_shell_details_refresh (GsShellDetails *shell_details);
void gs_shell_details_setup (GsShellDetails *shell_details,
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 0162f7b..8a0b795 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -197,8 +197,12 @@ gs_shell_change_mode (GsShell *shell,
gs_shell_updates_refresh (priv->shell_updates, TRUE, scroll_up);
break;
case GS_SHELL_MODE_DETAILS:
- gs_shell_details_set_app (priv->shell_details, app);
- gs_shell_details_refresh (priv->shell_details);
+ if (app != NULL) {
+ gs_shell_details_set_app (priv->shell_details, app);
+ gs_shell_details_refresh (priv->shell_details);
+ }
+ if (data != NULL)
+ gs_shell_details_set_filename (priv->shell_details, data);
break;
case GS_SHELL_MODE_CATEGORY:
gs_shell_category_set_category (priv->shell_category,
@@ -621,6 +625,14 @@ gs_shell_show_search (GsShell *shell, const gchar *search)
gs_shell_change_mode (shell, GS_SHELL_MODE_SEARCH, NULL, NULL, TRUE);
}
+void
+gs_shell_show_filename (GsShell *shell, const gchar *filename)
+{
+ save_back_entry (shell);
+ gs_shell_change_mode (shell, GS_SHELL_MODE_DETAILS, NULL, (gpointer) filename, TRUE);
+ gs_shell_activate (shell);
+}
+
typedef struct {
GsShell *shell;
GsApp *app;
diff --git a/src/gs-shell.h b/src/gs-shell.h
index 3bef5ca..6d48e01 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -79,6 +79,8 @@ void gs_shell_show_category (GsShell *shell,
GsCategory *category);
void gs_shell_show_search (GsShell *shell,
const gchar *search);
+void gs_shell_show_filename (GsShell *shell,
+ const gchar *filename);
void gs_shell_show_search_result (GsShell *shell,
const gchar *id,
const gchar *search);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]