[goobox] cover chooser: use the headerbar



commit fc7f098787355757cbe1b4b560df9ea2ea27aab0
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Dec 29 09:48:38 2018 +0100

    cover chooser: use the headerbar

 src/dlg-cover-chooser.c |  80 +++++++++++++++--------
 src/ui/cover-chooser.ui | 169 ++++++++++++------------------------------------
 2 files changed, 96 insertions(+), 153 deletions(-)
---
diff --git a/src/dlg-cover-chooser.c b/src/dlg-cover-chooser.c
index 0086050..33a49e5 100644
--- a/src/dlg-cover-chooser.c
+++ b/src/dlg-cover-chooser.c
@@ -37,6 +37,7 @@
 #define COVER_BACKUP_FILENAME "original_cover.png"
 #define MAX_IMAGES 20
 #define GET_WIDGET(x) _gtk_builder_get_widget (data->builder, (x))
+#define _GTK_RESPONSE_RESET 10
 
 
 enum {
@@ -373,16 +374,7 @@ start_searching (DialogData *data)
 
 
 static void
-revert_button_clicked_cb (GtkWidget  *widget,
-                         DialogData *data)
-{
-       goo_window_set_cover_image_from_pixbuf (data->window, data->cover_backup);
-}
-
-
-static void
-ok_button_clicked_cb (GtkWidget  *widget,
-                     DialogData *data)
+ok_button_clicked (DialogData *data)
 {
        GList *list;
 
@@ -416,7 +408,7 @@ icon_view_selection_changed_cb (GtkIconView *icon_view,
        GList *list;
 
        list = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (data->icon_view));
-       gtk_widget_set_sensitive (GET_WIDGET ("ok_button"), list != NULL);
+       gtk_widget_set_sensitive (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), 
GTK_RESPONSE_OK), list != NULL);
 
        g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
        g_list_free (list);
@@ -428,7 +420,7 @@ icon_view_item_activated_cb (GtkIconView *icon_view,
                             GtkTreePath *path,
                             DialogData  *data)
 {
-       ok_button_clicked_cb (NULL, data);
+       ok_button_clicked (data);
 }
 
 
@@ -446,7 +438,7 @@ backup_cover_image (DialogData *data)
        char *cover_filename;
 
        cover_filename = goo_window_get_cover_filename (data->window);
-       gtk_widget_set_sensitive (GET_WIDGET ("revert_button"), cover_filename != NULL);
+       gtk_widget_set_sensitive (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), 
_GTK_RESPONSE_RESET), cover_filename != NULL);
        if (cover_filename != NULL)
                data->cover_backup = gdk_pixbuf_new_from_file (cover_filename, NULL);
 
@@ -454,6 +446,28 @@ backup_cover_image (DialogData *data)
 }
 
 
+static void
+dialog_response_cb (GtkWidget  *dialog,
+                   int         response_id,
+                   DialogData *data)
+{
+       switch (response_id) {
+       case GTK_RESPONSE_OK:
+               ok_button_clicked (data);
+               gtk_widget_destroy (dialog);
+               break;
+
+       case _GTK_RESPONSE_RESET:
+               goo_window_set_cover_image_from_pixbuf (data->window, data->cover_backup);
+               break;
+
+       default:
+               gtk_widget_destroy (dialog);
+               break;
+       }
+}
+
+
 void
 dlg_cover_chooser (GooWindow  *window,
                   const char *album,
@@ -472,7 +486,29 @@ dlg_cover_chooser (GooWindow  *window,
 
        /* Get the widgets. */
 
-       data->dialog = GET_WIDGET ("cover_chooser_dialog");
+       data->dialog = g_object_new (GTK_TYPE_DIALOG,
+                                    "title", _("Choose a CD Cover"),
+                                    "transient-for", GTK_WINDOW (window),
+                                    "modal", TRUE,
+                                    "use-header-bar", _gtk_settings_get_dialogs_use_header (),
+                                    NULL);
+       gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))),
+                          GET_WIDGET ("cover_chooser_dialog"));
+       gtk_dialog_add_buttons (GTK_DIALOG (data->dialog),
+                               _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
+                               _GTK_LABEL_OK, GTK_RESPONSE_OK,
+                               NULL);
+
+       {
+               GtkWidget *button;
+
+               button = gtk_button_new_from_icon_name ("edit-undo-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR);
+               gtk_widget_show (button);
+               gtk_dialog_add_action_widget (GTK_DIALOG (data->dialog), button, _GTK_RESPONSE_RESET);
+       }
+
+       gtk_style_context_add_class (gtk_widget_get_style_context (gtk_dialog_get_widget_for_response 
(GTK_DIALOG (data->dialog), GTK_RESPONSE_OK)),
+                                    GTK_STYLE_CLASS_SUGGESTED_ACTION);
 
        model = gtk_list_store_new (N_COLUMNS,
                                    G_TYPE_STRING,
@@ -497,7 +533,7 @@ dlg_cover_chooser (GooWindow  *window,
 
        backup_cover_image (data);
 
-       gtk_widget_set_sensitive (GET_WIDGET ("ok_button"), FALSE);
+       gtk_widget_set_sensitive (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), 
GTK_RESPONSE_OK), FALSE);
 
        /* Set the signals handlers. */
 
@@ -505,17 +541,9 @@ dlg_cover_chooser (GooWindow  *window,
                          "destroy",
                          G_CALLBACK (destroy_cb),
                          data);
-       g_signal_connect_swapped (GET_WIDGET ("cancel_button"),
-                                 "clicked",
-                                 G_CALLBACK (gtk_widget_destroy),
-                                 G_OBJECT (data->dialog));
-       g_signal_connect (GET_WIDGET ("ok_button"),
-                         "clicked",
-                         G_CALLBACK (ok_button_clicked_cb),
-                         data);
-       g_signal_connect (GET_WIDGET ("revert_button"),
-                         "clicked",
-                         G_CALLBACK (revert_button_clicked_cb),
+       g_signal_connect (G_OBJECT (data->dialog),
+                         "response",
+                         G_CALLBACK (dialog_response_cb),
                          data);
        g_signal_connect (G_OBJECT (data->icon_view),
                          "selection-changed",
diff --git a/src/ui/cover-chooser.ui b/src/ui/cover-chooser.ui
index 66d73f2..49ba064 100644
--- a/src/ui/cover-chooser.ui
+++ b/src/ui/cover-chooser.ui
@@ -1,169 +1,84 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.1 -->
+<!-- Generated with glade 3.22.1 -->
 <interface>
-  <requires lib="gtk+" version="3.10"/>
-  <object class="GtkDialog" id="cover_chooser_dialog">
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkVBox" id="cover_chooser_dialog">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="border_width">5</property>
-    <property name="title" translatable="yes">Choose a CD Cover</property>
-    <property name="window_position">center-on-parent</property>
-    <property name="type_hint">dialog</property>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox1">
+    <property name="border_width">15</property>
+    <property name="spacing">12</property>
+    <child>
+      <object class="GtkVBox" id="vbox1">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
         <property name="spacing">6</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area1">
+        <child>
+          <object class="GtkHBox" id="hbox1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
+            <property name="spacing">6</property>
             <child>
-              <object class="GtkButton" id="revert_button">
-                <property name="label" translatable="yes">_Reset</property>
+              <object class="GtkLabel" id="label1">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_underline">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Found images:</property>
+                <property name="xalign">0</property>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">1</property>
+                <property name="position">0</property>
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="ok_button">
-                <property name="label">gtk-apply</property>
+              <object class="GtkButton" id="cancel_search_button">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="can_default">True</property>
                 <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
+                <property name="relief">none</property>
+                <child>
+                  <object class="GtkImage" id="image1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="icon_name">process-stop-symbolic</property>
+                  </object>
+                </child>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">2</property>
+                <property name="pack_type">end</property>
+                <property name="position">1</property>
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="cancel_button">
-                <property name="label">gtk-close</property>
+              <object class="GtkLabel" id="progress_label">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
+                <property name="can_focus">False</property>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">3</property>
+                <property name="position">2</property>
               </packing>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
+            <property name="fill">False</property>
             <property name="position">0</property>
           </packing>
         </child>
         <child>
-          <object class="GtkVBox" id="image_list_box">
+          <object class="GtkScrolledWindow" id="icon_view_scrolledwindow">
+            <property name="width_request">554</property>
+            <property name="height_request">390</property>
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="border_width">5</property>
-            <property name="spacing">12</property>
+            <property name="can_focus">True</property>
+            <property name="vexpand">True</property>
+            <property name="shadow_type">in</property>
             <child>
-              <object class="GtkVBox" id="vbox1">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="spacing">6</property>
-                <child>
-                  <object class="GtkHBox" id="hbox1">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="spacing">6</property>
-                    <child>
-                      <object class="GtkLabel" id="label1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
-                        <property name="label" translatable="yes">Found images:</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkButton" id="cancel_search_button">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="relief">none</property>
-                        <child>
-                          <object class="GtkImage" id="image1">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="icon_name">process-stop-symbolic</property>
-                          </object>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="pack_type">end</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="progress_label">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                      </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>
-                    <property name="fill">False</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkScrolledWindow" id="icon_view_scrolledwindow">
-                    <property name="width_request">554</property>
-                    <property name="height_request">390</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="shadow_type">in</property>
-                    <child>
-                      <placeholder/>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
+              <placeholder/>
             </child>
           </object>
           <packing>
@@ -173,11 +88,11 @@
           </packing>
         </child>
       </object>
+      <packing>
+        <property name="expand">True</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
     </child>
-    <action-widgets>
-      <action-widget response="-7">revert_button</action-widget>
-      <action-widget response="-10">ok_button</action-widget>
-      <action-widget response="-7">cancel_button</action-widget>
-    </action-widgets>
   </object>
 </interface>


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