[gnome-software] Add a 'Launch' button to the application details page



commit 499a5692e58914dc3fc31b15f11064cc67e6c99a
Author: Richard Hughes <richard hughsie com>
Date:   Tue Nov 12 09:45:58 2013 +0000

    Add a 'Launch' button to the application details page
    
    Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=708911

 src/gnome-software.ui  |   18 ++++++++++++++++++
 src/gs-shell-details.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-software.ui b/src/gnome-software.ui
index f7339ea..fbc0e33 100644
--- a/src/gnome-software.ui
+++ b/src/gnome-software.ui
@@ -1195,6 +1195,23 @@
                                 <property name="position">1</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkButton" id="button_details_launch">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="label" translatable="yes" comments="Translators: A label for 
a button to execute the selected application.">_Launch</property>
+                                <style>
+                                  <class name="suggested-action"/>
+                                </style>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">2</property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
                             <property name="expand">False</property>
@@ -1605,6 +1622,7 @@
     <widgets>
       <widget name="button_details_website"/>
       <widget name="button_history"/>
+      <widget name="button_details_launch"/>
     </widgets>
   </object>
 </interface>
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 0b73786..15cfdbb 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -24,6 +24,7 @@
 
 #include <string.h>
 #include <glib/gi18n.h>
+#include <gio/gdesktopappinfo.h>
 
 #include "gs-utils.h"
 
@@ -601,6 +602,18 @@ gs_shell_details_refresh_all (GsShellDetails *shell_details)
                break;
        }
 
+       /* only show launch button when the application is installed */
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_details_launch"));
+       switch (gs_app_get_state (priv->app)) {
+       case GS_APP_STATE_INSTALLED:
+       case GS_APP_STATE_UPDATABLE:
+               gtk_widget_set_visible (widget, TRUE);
+               break;
+       default:
+               gtk_widget_set_visible (widget, FALSE);
+               break;
+       }
+
        /* make history button insensitive if there is none */
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_history"));
        switch (gs_app_get_id_kind (priv->app)) {
@@ -859,6 +872,35 @@ gs_shell_details_history_sort_cb (gconstpointer a, gconstpointer b)
 }
 
 /**
+ * gs_shell_details_app_launch_button_cb:
+ **/
+static void
+gs_shell_details_app_launch_button_cb (GtkWidget *widget, GsShellDetails *shell_details)
+{
+       GAppInfo *appinfo;
+       GAppLaunchContext *context;
+       GError *error = NULL;
+       GdkDisplay *display;
+       const gchar *desktop_id;
+
+       desktop_id = gs_app_get_id_full (shell_details->priv->app);
+       display = gdk_display_get_default ();
+       appinfo = G_APP_INFO (g_desktop_app_info_new (desktop_id));
+       if (appinfo == NULL) {
+               g_warning ("no such desktop file: %s", desktop_id);
+               return;
+       }
+       context = G_APP_LAUNCH_CONTEXT (gdk_display_get_app_launch_context (display));
+       if (!g_app_info_launch (appinfo, NULL, context, &error)) {
+               g_warning ("launching %s failed: %s", desktop_id, error->message);
+               g_error_free (error);
+       }
+
+       g_object_unref (appinfo);
+       g_object_unref (context);
+}
+
+/**
  * gs_shell_details_app_history_button_cb:
  **/
 static void
@@ -1119,6 +1161,10 @@ gs_shell_details_setup (GsShellDetails *shell_details,
        g_signal_connect (widget, "clicked",
                          G_CALLBACK (gs_shell_details_app_history_button_cb),
                          shell_details);
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_details_launch"));
+       g_signal_connect (widget, "clicked",
+                         G_CALLBACK (gs_shell_details_app_launch_button_cb),
+                         shell_details);
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_details_website"));
        g_signal_connect (widget, "clicked",
                          G_CALLBACK (gs_shell_details_website_cb),


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