[gnome-software/ADD_SHORTCUT: 2/5] Add button in the details page for creating a shortcut to the app



commit c2a7ed031ae5163b44a34f5f0387ce7bebab356a
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Wed Apr 13 15:39:21 2016 +0200

    Add button in the details page for creating a shortcut to the app

 src/gs-app.h            |    4 ++++
 src/gs-shell-details.c  |   42 ++++++++++++++++++++++++++++++++++++++++--
 src/gs-shell-details.ui |   15 +++++++++++++++
 3 files changed, 59 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-app.h b/src/gs-app.h
index a868b58..a74bdb7 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -82,6 +82,10 @@ typedef enum {
 #define AS_APP_QUIRK_NOT_REVIEWABLE            (1 << 5)
 #endif
 
+#if !AS_CHECK_VERSION(0,5,15)
+#define AS_APP_QUIRK_HAS_SHORTCUT              (1 << 6)
+#endif
+
 GQuark          gs_app_error_quark             (void);
 
 GsApp          *gs_app_new                     (const gchar    *id);
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index f0b3d07..8bcad03 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -70,6 +70,7 @@ struct _GsShellDetails
        GtkWidget               *box_details_screenshot_main;
        GtkWidget               *box_details_screenshot_thumbnails;
        GtkWidget               *button_details_launch;
+       GtkWidget               *button_details_shortcut;
        GtkWidget               *button_details_website;
        GtkWidget               *button_install;
        GtkWidget               *button_remove;
@@ -154,6 +155,22 @@ gs_shell_details_set_state (GsShellDetails *self,
        }
 }
 
+static void
+gs_shell_details_update_shortcut_button (GsShellDetails *self)
+{
+       gboolean enable_shortcut_button;
+       gboolean app_has_shortcut;
+
+       enable_shortcut_button = gs_plugin_loader_get_plugin_supported (self->plugin_loader, 
"gs_plugin_add_shortcut");
+       gtk_widget_set_visible (self->button_details_shortcut, enable_shortcut_button);
+
+       if (!enable_shortcut_button)
+               return;
+
+       app_has_shortcut = gs_app_has_quirk (self->app, AS_APP_QUIRK_HAS_SHORTCUT);
+       gtk_widget_set_sensitive (self->button_details_shortcut, !app_has_shortcut);
+}
+
 /**
  * gs_shell_details_switch_to:
  **/
@@ -267,12 +284,15 @@ gs_shell_details_switch_to (GsPage *page, gboolean scroll_up)
                break;
        default:
                gtk_widget_set_visible (self->button_details_launch, FALSE);
+               gtk_widget_set_visible (self->button_details_shortcut, FALSE);
                break;
        }
 
-       /* don't show the launch button if the app doesn't have a desktop ID */
-       if (gs_app_get_id (self->app) == NULL)
+       /* don't show the launch and shortcut buttons if the app doesn't have a desktop ID */
+       if (gs_app_get_id (self->app) == NULL) {
                gtk_widget_set_visible (self->button_details_launch, FALSE);
+               gtk_widget_set_visible (self->button_details_shortcut, FALSE);
+       }
 
        /* remove button */
        if (gs_app_has_quirk (self->app, AS_APP_QUIRK_COMPULSORY) ||
@@ -292,6 +312,7 @@ gs_shell_details_switch_to (GsPage *page, gboolean scroll_up)
                                gtk_style_context_add_class (gtk_widget_get_style_context 
(self->button_remove), "destructive-action");
                        /* TRANSLATORS: button text in the header when an application can be erased */
                        gtk_button_set_label (GTK_BUTTON (self->button_remove), _("_Remove"));
+                       gs_shell_details_update_shortcut_button (self);
                        break;
                case AS_APP_STATE_REMOVING:
                        gtk_widget_set_visible (self->button_remove, TRUE);
@@ -1433,6 +1454,19 @@ gs_shell_details_app_launch_button_cb (GtkWidget *widget, GsShellDetails *self)
 }
 
 /**
+ * gs_shell_details_app_shortcut_button_cb:
+ **/
+static void
+gs_shell_details_app_shortcut_button_cb (GtkWidget *widget, GsShellDetails *self)
+{
+       if (gs_app_has_quirk (self->app, AS_APP_QUIRK_HAS_SHORTCUT))
+         gs_page_remove_shortcut_to_app (GS_PAGE (self), self->app);
+       else
+         gs_page_add_shortcut_to_app (GS_PAGE (self), self->app);
+       gs_shell_details_update_shortcut_button (self);
+}
+
+/**
  * gs_shell_details_review_response_cb:
  **/
 static void
@@ -1535,6 +1569,9 @@ gs_shell_details_setup (GsShellDetails *self,
        g_signal_connect (self->button_details_launch, "clicked",
                          G_CALLBACK (gs_shell_details_app_launch_button_cb),
                          self);
+       g_signal_connect (self->button_details_shortcut, "clicked",
+                         G_CALLBACK (gs_shell_details_app_shortcut_button_cb),
+                         self);
        g_signal_connect (self->button_details_website, "clicked",
                          G_CALLBACK (gs_shell_details_website_cb),
                          self);
@@ -1599,6 +1636,7 @@ gs_shell_details_class_init (GsShellDetailsClass *klass)
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, box_details_screenshot_main);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, 
box_details_screenshot_thumbnails);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, button_details_launch);
+       gtk_widget_class_bind_template_child (widget_class, GsShellDetails, button_details_shortcut);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, button_details_website);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, button_install);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, button_remove);
diff --git a/src/gs-shell-details.ui b/src/gs-shell-details.ui
index c5f87f6..aefffba 100644
--- a/src/gs-shell-details.ui
+++ b/src/gs-shell-details.ui
@@ -213,6 +213,20 @@
                                     <property name="position">4</property>
                                   </packing>
                                 </child>
+                                <child>
+                                  <object class="GtkButton" id="button_details_shortcut">
+                                    <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 add a shortcut to the selected application.">Add _Shorcut</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">5</property>
+                                  </packing>
+                                </child>
                               </object>
                               <packing>
                                 <property name="expand">False</property>
@@ -1129,6 +1143,7 @@
       <widget name="button_install"/>
       <widget name="button_remove"/>
       <widget name="button_details_launch"/>
+      <widget name="button_details_shortcut"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup" id="sizegroup_details_buttons">


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