[shotwell/wip/gtk4] Fix set background dialogs



commit 64f09f46afe243eb45dfc4c460594029ec72d2ae
Author: Jens Georg <mail jensge org>
Date:   Mon Apr 18 20:00:53 2022 +0200

    Fix set background dialogs

 data/ui/set_background_dialog.ui           | 102 +++++----------------
 data/ui/set_background_slideshow_dialog.ui | 138 ++++++-----------------------
 src/CollectionPage.vala                    |  31 ++++---
 src/PhotoPage.vala                         |  11 ++-
 src/dialogs/SetBackground.vala             |  16 +++-
 src/dialogs/SetBackgroundSlideshow.vala    |  17 +++-
 6 files changed, 99 insertions(+), 216 deletions(-)
---
diff --git a/data/ui/set_background_dialog.ui b/data/ui/set_background_dialog.ui
index d00125e1..34d15046 100644
--- a/data/ui/set_background_dialog.ui
+++ b/data/ui/set_background_dialog.ui
@@ -1,114 +1,56 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.0 -->
 <interface domain="shotwell">
-  <requires lib="gtk+" version="3.18"/>
+  <requires lib="gtk" version="4.0"/>
   <template class="SetBackgroundPhotoDialog" parent="GtkDialog">
     <property name="width_request">400</property>
-    <property name="can_focus">False</property>
-    <property name="border_width">5</property>
     <property name="title" translatable="yes">Set as Desktop Background</property>
-    <property name="type_hint">normal</property>
-    <property name="skip_taskbar_hint">True</property>
-    <child internal-child="vbox">
+    <child internal-child="content_area">
       <object class="GtkBox" id="dialog-vbox2">
-        <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_area2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="cancel_button">
-                <property name="label">_Cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_underline">True</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="ok_button">
-                <property name="label">_OK</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="has_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
         <child>
           <object class="GtkBox" id="hbox2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <property name="orientation">vertical</property>
             <child>
               <object class="GtkCheckButton" id="desktop_background_checkbox">
                 <property name="label" translatable="yes">Use for Desktop</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
+                <property name="focusable">1</property>
                 <property name="halign">start</property>
-                <property name="active">True</property>
-                <property name="draw_indicator">True</property>
+                <property name="active">1</property>
                 <signal name="toggled" handler="on_checkbox_clicked" swapped="no"/>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
             </child>
             <child>
               <object class="GtkCheckButton" id="screensaver_checkbox">
                 <property name="label" translatable="yes">Use for Lock Screen</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
+                <property name="focusable">1</property>
                 <property name="halign">start</property>
-                <property name="draw_indicator">True</property>
                 <signal name="toggled" handler="on_checkbox_clicked" swapped="no"/>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
             </child>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">3</property>
-          </packing>
         </child>
       </object>
     </child>
     <action-widgets>
-      <action-widget response="-6">cancel_button</action-widget>
+      <action-widget response="-6" default="true">cancel_button</action-widget>
       <action-widget response="-5">ok_button</action-widget>
     </action-widgets>
+    <child type="action">
+      <object class="GtkButton" id="cancel_button">
+        <property name="label">_Cancel</property>
+        <property name="focusable">1</property>
+        <property name="receives_default">1</property>
+        <property name="use_underline">1</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="ok_button">
+        <property name="label">_OK</property>
+        <property name="focusable">1</property>
+        <property name="receives_default">1</property>
+        <property name="use_underline">1</property>
+      </object>
+    </child>
   </template>
 </interface>
diff --git a/data/ui/set_background_slideshow_dialog.ui b/data/ui/set_background_slideshow_dialog.ui
index 93c3a99b..03d3c20d 100644
--- a/data/ui/set_background_slideshow_dialog.ui
+++ b/data/ui/set_background_slideshow_dialog.ui
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.0 -->
 <interface domain="shotwell">
-  <requires lib="gtk+" version="3.18"/>
+  <requires lib="gtk" version="4.0"/>
   <object class="GtkAdjustment" id="adjustment1">
     <property name="upper">100</property>
     <property name="value">50</property>
@@ -11,167 +10,82 @@
   </object>
   <template class="SetBackgroundSlideshowDialog" parent="GtkDialog">
     <property name="width_request">400</property>
-    <property name="can_focus">False</property>
-    <property name="border_width">5</property>
     <property name="title" translatable="yes">Set as Desktop Slideshow</property>
-    <property name="type_hint">normal</property>
-    <property name="skip_taskbar_hint">True</property>
-    <child internal-child="vbox">
+    <child internal-child="content_area">
       <object class="GtkBox" id="dialog-vbox2">
-        <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_area2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="cancel_button">
-                <property name="label">_Cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_underline">True</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="ok_button">
-                <property name="label">_OK</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="has_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="has_tooltip">True</property>
-                <property name="tooltip_text" translatable="yes">Generate desktop background 
slideshow</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
         <child>
           <object class="GtkBox" id="hbox1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <property name="spacing">5</property>
             <child>
               <object class="GtkLabel" id="label1">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">Show each photo for</property>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
             </child>
             <child>
               <object class="GtkLabel" id="delay_value_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">period of time</property>
                 <attributes>
-                  <attribute name="weight" value="bold"/>
+                  <attribute name="weight" value="bold"></attribute>
                 </attributes>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
             </child>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
         </child>
         <child>
           <object class="GtkScale" id="delay_scale">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
+            <property name="focusable">1</property>
             <property name="tooltip_text" translatable="yes">How long each photo is shown on the desktop 
background</property>
             <property name="adjustment">adjustment1</property>
-            <property name="draw_value">False</property>
             <signal name="value-changed" handler="on_delay_scale_value_changed" swapped="no"/>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">2</property>
-          </packing>
         </child>
         <child>
           <object class="GtkBox" id="hbox2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <property name="orientation">vertical</property>
             <child>
               <object class="GtkCheckButton" id="desktop_background_checkbox">
                 <property name="label" translatable="yes">Use for Desktop</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
+                <property name="focusable">1</property>
                 <property name="halign">start</property>
-                <property name="active">True</property>
-                <property name="draw_indicator">True</property>
+                <property name="active">1</property>
                 <signal name="toggled" handler="on_checkbox_clicked" swapped="no"/>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
             </child>
             <child>
               <object class="GtkCheckButton" id="screensaver_checkbox">
                 <property name="label" translatable="yes">Use for Lock Screen</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
+                <property name="focusable">1</property>
                 <property name="halign">start</property>
-                <property name="draw_indicator">True</property>
                 <signal name="toggled" handler="on_checkbox_clicked" swapped="no"/>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
             </child>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">3</property>
-          </packing>
         </child>
       </object>
     </child>
     <action-widgets>
       <action-widget response="-6">cancel_button</action-widget>
-      <action-widget response="-5">ok_button</action-widget>
+      <action-widget response="-5" default="true">ok_button</action-widget>
     </action-widgets>
+    <child type="action">
+      <object class="GtkButton" id="cancel_button">
+        <property name="label">_Cancel</property>
+        <property name="focusable">1</property>
+        <property name="receives_default">1</property>
+        <property name="use_underline">1</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="ok_button">
+        <property name="label">_OK</property>
+        <property name="focusable">1</property>
+        <property name="receives_default">1</property>
+        <property name="has_tooltip">1</property>
+        <property name="tooltip_text" translatable="yes">Generate desktop background slideshow</property>
+        <property name="use_underline">1</property>
+      </object>
+    </child>
   </template>
 </interface>
diff --git a/src/CollectionPage.vala b/src/CollectionPage.vala
index 0e8b0b39..e764f1d5 100644
--- a/src/CollectionPage.vala
+++ b/src/CollectionPage.vala
@@ -652,23 +652,28 @@ public abstract class CollectionPage : MediaPage {
         MediaSourceCollection.filter_media((Gee.Collection<MediaSource>) get_view().get_selected_sources(),
             photos, null);
         
-        bool desktop, screensaver;
         if (photos.size == 1) {
             SetBackgroundPhotoDialog dialog = new SetBackgroundPhotoDialog();
-            if (dialog.execute(out desktop, out screensaver)) {
-                AppWindow.get_instance().set_busy_cursor();
-                DesktopIntegration.set_background(photos[0], desktop, screensaver);
-                AppWindow.get_instance().set_normal_cursor();
-            }
+            dialog.execute.begin((source, res) => {
+                bool desktop, screensaver;
+                if (dialog.execute.end(res, out desktop, out screensaver)) {
+                    AppWindow.get_instance().set_busy_cursor();
+                    DesktopIntegration.set_background(photos[0], desktop, screensaver);
+                    AppWindow.get_instance().set_normal_cursor();
+                }
+            });
         } else if (photos.size > 1) {
             SetBackgroundSlideshowDialog dialog = new SetBackgroundSlideshowDialog();
-            int delay;
-            if (dialog.execute(out delay, out desktop, out screensaver)) {
-                AppWindow.get_instance().set_busy_cursor();
-                DesktopIntegration.set_background_slideshow(photos, delay,
-                    DESKTOP_SLIDESHOW_TRANSITION_SEC, desktop, screensaver);
-                AppWindow.get_instance().set_normal_cursor();
-            }
+            dialog.execute.begin((source, res) => {
+                int delay;
+                bool desktop, screensaver;
+                if (dialog.execute.end(res, out delay, out desktop, out screensaver)) {
+                    AppWindow.get_instance().set_busy_cursor();
+                    DesktopIntegration.set_background_slideshow(photos, delay,
+                        DESKTOP_SLIDESHOW_TRANSITION_SEC, desktop, screensaver);
+                    AppWindow.get_instance().set_normal_cursor();
+                }
+            });
         }
     }
     
diff --git a/src/PhotoPage.vala b/src/PhotoPage.vala
index bdeeb86c..085da25b 100644
--- a/src/PhotoPage.vala
+++ b/src/PhotoPage.vala
@@ -2006,15 +2006,18 @@ public abstract class EditingHostPage : SinglePhotoPage {
     }
     
     public void on_set_background() {
-        if (has_photo()) {
-            SetBackgroundPhotoDialog dialog = new SetBackgroundPhotoDialog();
+        if (!has_photo())
+            return;
+
+        SetBackgroundPhotoDialog dialog = new SetBackgroundPhotoDialog();
+        dialog.execute.begin((source, res) => {
             bool desktop, screensaver;
-            if (dialog.execute(out desktop, out screensaver)) {
+            if (dialog.execute.end(res, out desktop, out screensaver)) {
                 AppWindow.get_instance().set_busy_cursor();
                 DesktopIntegration.set_background(get_photo(), desktop, screensaver);
                 AppWindow.get_instance().set_normal_cursor();
             }
-        }
+        });
     }
 
 #if 0
diff --git a/src/dialogs/SetBackground.vala b/src/dialogs/SetBackground.vala
index 161163a1..b6a911dd 100644
--- a/src/dialogs/SetBackground.vala
+++ b/src/dialogs/SetBackground.vala
@@ -24,10 +24,20 @@ public class SetBackgroundPhotoDialog : Gtk.Dialog {
                                 screensaver_checkbox.active);
     }
 
-    public bool execute(out bool desktop_background, out bool screensaver) {
+    public async bool execute(out bool desktop_background, out bool screensaver) {
         this.show();
-        var result = false; //this.run() == Gtk.ResponseType.OK;
-        this.hide ();
+
+        SourceFunc continue_cb = execute.callback;
+        int response = 0;
+        this.response.connect((source, res) => {
+            this.hide();
+            res = response;
+            continue_cb();
+        });
+        
+        yield;
+
+        var result = response == Gtk.ResponseType.OK;
 
         desktop_background = desktop_background_checkbox.active;
         screensaver = screensaver_checkbox.active;
diff --git a/src/dialogs/SetBackgroundSlideshow.vala b/src/dialogs/SetBackgroundSlideshow.vala
index aed74dbd..572aef3c 100644
--- a/src/dialogs/SetBackgroundSlideshow.vala
+++ b/src/dialogs/SetBackgroundSlideshow.vala
@@ -63,12 +63,21 @@ public class SetBackgroundSlideshowDialog : Gtk.Dialog {
         delay_value_label.label = text;
     }
 
-    public bool execute(out int delay_value, out bool desktop_background, out bool screensaver) {
+    public async bool execute(out int delay_value, out bool desktop_background, out bool screensaver) {
         this.show();
-        var result = false; //this.run() == Gtk.ResponseType.OK;
-        this.hide ();
 
-        delay_value = this.delay_value;
+        SourceFunc continue_cb = execute.callback;
+        int response = 0;
+        this.response.connect((source, res) => {
+            this.hide();
+            res = response;
+            continue_cb();
+        });
+        
+        yield;
+
+        var result = response == Gtk.ResponseType.OK;
+
         desktop_background = desktop_background_checkbox.active;
         screensaver = screensaver_checkbox.active;
 


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