[connections/hdy-preferences-window] preferences: Use libhandy for the preference dialogs




commit 63f5b491fcafb343882dd86bb39ebcb12531ac88
Author: Felipe Borges <felipeborges gnome org>
Date:   Mon Jun 28 15:55:12 2021 +0200

    preferences: Use libhandy for the preference dialogs
    
    This also standardizes the way we bind preference widgets to
    Connection properties.
    
    Fixes #49

 src/actions-popover.vala        |   6 +-
 src/connections.gresource.xml   |   3 +-
 src/meson.build                 |   5 +-
 src/preferences-widgets.vala    |  54 ++++++++++++
 src/properties.vala             | 190 ----------------------------------------
 src/rdp-connection.vala         |  11 ---
 src/rdp-preferences-window.vala |  37 ++++++++
 src/topbar.vala                 |   5 +-
 src/ui/properties.ui            | 142 ------------------------------
 src/ui/rdp-preferences.ui       |  53 +++++++++++
 src/ui/vnc-preferences.ui       | 119 +++++++++++++++++++++++++
 src/vnc-preferences-window.vala |  52 +++++++++++
 src/vnc-properties-dialog.vala  |  64 --------------
 src/window.vala                 |   9 ++
 14 files changed, 331 insertions(+), 419 deletions(-)
---
diff --git a/src/actions-popover.vala b/src/actions-popover.vala
index a6c5e5d..b06687b 100644
--- a/src/actions-popover.vala
+++ b/src/actions-popover.vala
@@ -60,11 +60,7 @@ namespace Connections {
         private void properties_activated () {
             debug ("Launch properties for %s", connection.uri);
 
-            if (connection.protocol == "vnc")
-                (new VncPropertiesDialog (connection).run ());
-            else
-                (new RdpPropertiesDialog (connection).run ());
-
+            Application.application.main_window.show_preferences_window (connection);
         }
     }
 }
diff --git a/src/connections.gresource.xml b/src/connections.gresource.xml
index 0dfdb92..52eddd5 100644
--- a/src/connections.gresource.xml
+++ b/src/connections.gresource.xml
@@ -8,7 +8,8 @@
     <file>ui/display-view.ui</file>
     <file>ui/empty-view.ui</file>
     <file>ui/notification.ui</file>
-    <file>ui/properties.ui</file>
+    <file>ui/rdp-preferences.ui</file>
+    <file>ui/vnc-preferences.ui</file>
     <file>ui/style.css</file>
     <file>ui/topbar.ui</file>
     <file>ui/window.ui</file>
diff --git a/src/meson.build b/src/meson.build
index a4443b7..bee8184 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -12,12 +12,13 @@ connections_sources = [
   'notifications.vala',
   'onboarding-dialog.vala',
   'onboarding-dialog-page.vala',
-  'properties.vala',
+  'preferences-widgets.vala',
   'rdp-connection.vala',
+  'rdp-preferences-window.vala',
   'thumbnailer.vala',
   'topbar.vala',
   'vnc-connection.vala',
-  'vnc-properties-dialog.vala',
+  'vnc-preferences-window.vala',
   'window.vala',
 ]
 
diff --git a/src/preferences-widgets.vala b/src/preferences-widgets.vala
new file mode 100644
index 0000000..48cf470
--- /dev/null
+++ b/src/preferences-widgets.vala
@@ -0,0 +1,54 @@
+/* preferences-widgets.vala
+ *
+ * Copyright (C) Red Hat, Inc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Felipe Borges <felipeborges gnome org>
+ *
+ */
+
+namespace Connections {
+    private class PreferencesWindow: Hdy.PreferencesWindow {
+        protected weak Connection connection;
+
+        construct {
+            set_transient_for (Application.application.main_window);
+        }
+
+        protected void bind_widget_property (Gtk.Widget widget, string widget_property, string 
connection_property) {
+            connection.bind_property (connection_property, widget, widget_property, 
BindingFlags.BIDIRECTIONAL);
+
+            var value = GLib.Value (connection.get_class ().find_property (connection_property).value_type);
+            connection.get_property (connection_property, ref value);
+            widget.set_property (widget_property, value);
+        }
+    }
+
+    private class BooleanProperty: Hdy.ActionRow {
+        public bool active { get; set; }
+
+        construct {
+            var widget = new Gtk.Switch () {
+                visible = true,
+                valign = Gtk.Align.CENTER
+            };
+
+            bind_property ("active", widget, "active", BindingFlags.BIDIRECTIONAL);
+
+            add (widget);
+            set_activatable_widget (widget);
+        }
+    }
+}
diff --git a/src/rdp-connection.vala b/src/rdp-connection.vala
index 80ec63d..4806f4c 100644
--- a/src/rdp-connection.vala
+++ b/src/rdp-connection.vala
@@ -113,15 +113,4 @@ namespace Connections {
             return true;
         }
     }
-
-    private class RdpPropertiesDialog : PropertiesDialog {
-        public RdpPropertiesDialog (Connection connection) {
-            this.connection = connection;
-
-            var scaling = new BooleanProperty (connection, "scaling") {
-                label = _("Scaling")
-            };
-            add_property (scaling);
-        }
-    }
 }
diff --git a/src/rdp-preferences-window.vala b/src/rdp-preferences-window.vala
new file mode 100644
index 0000000..267356e
--- /dev/null
+++ b/src/rdp-preferences-window.vala
@@ -0,0 +1,37 @@
+/* rdp-preferences-window.vala
+ *
+ * Copyright (C) Red Hat, Inc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Felipe Borges <felipeborges gnome org>
+ *
+ */
+
+namespace Connections {
+    [GtkTemplate (ui = "/org/gnome/Connections/ui/rdp-preferences.ui")]
+    private class RdpPreferencesWindow : Connections.PreferencesWindow {
+        [GtkChild]
+        private unowned Gtk.Entry connection_name_entry;
+        [GtkChild]
+        private unowned Gtk.Label host_address_label;
+
+        public RdpPreferencesWindow (Connection connection) {
+            this.connection = connection;
+
+            bind_widget_property (connection_name_entry, "text", "display_name");
+            bind_widget_property (host_address_label, "label", "uri");
+        }
+    }
+}
diff --git a/src/topbar.vala b/src/topbar.vala
index d1da4b0..5007b5e 100644
--- a/src/topbar.vala
+++ b/src/topbar.vala
@@ -73,10 +73,7 @@ namespace Connections {
         }
 
         private void properties_activated () {
-            if (connection.protocol == "vnc")
-                (new VncPropertiesDialog (connection).run ());
-            else
-                (new RdpPropertiesDialog (connection).run ());
+            Application.application.main_window.show_preferences_window (connection);
         }
 
         private void take_screenshot_activated () {
diff --git a/src/ui/rdp-preferences.ui b/src/ui/rdp-preferences.ui
new file mode 100644
index 0000000..78e93f2
--- /dev/null
+++ b/src/ui/rdp-preferences.ui
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+    <template class="ConnectionsRdpPreferencesWindow" parent="ConnectionsPreferencesWindow">
+      <property name="modal">True</property>
+      <property name="type-hint">dialog</property>
+      <property name="valign">start</property>
+      <property name="default-width">540</property>
+      <property name="title" translatable="yes">Connection preferences</property>
+
+      <child>
+        <object class="HdyPreferencesPage">
+          <property name="visible">True</property>
+
+          <child>
+            <object class="HdyPreferencesGroup">
+              <property name="visible">True</property>
+
+              <child>
+                <object class="HdyActionRow">
+                  <property name="activatable-widget">host_address_label</property>
+                  <property name="visible">True</property>
+                  <property name="title" translatable="yes">Address</property>
+
+                  <child>
+                    <object class="GtkLabel" id="host_address_label">
+                      <property name="visible">True</property>
+                      <property name="selectable">True</property>
+                    </object>
+                  </child>
+                </object>
+              </child>
+
+              <child>
+                <object class="HdyActionRow">
+                  <property name="activatable-widget">connection_name_entry</property>
+                  <property name="visible">True</property>
+                  <property name="title" translatable="yes">Name</property>
+
+                  <child>
+                    <object class="GtkEntry" id="connection_name_entry">
+                      <property name="visible">True</property>
+                      <property name="valign">center</property>
+                    </object>
+                  </child>
+                </object>
+              </child>
+            </object>
+          </child>
+        </object>
+      </child>
+    </template>
+  </interface>
diff --git a/src/ui/vnc-preferences.ui b/src/ui/vnc-preferences.ui
new file mode 100644
index 0000000..3451495
--- /dev/null
+++ b/src/ui/vnc-preferences.ui
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+    <template class="ConnectionsVncPreferencesWindow" parent="ConnectionsPreferencesWindow">
+      <property name="modal">True</property>
+      <property name="type-hint">dialog</property>
+      <property name="valign">start</property>
+      <property name="default-width">540</property>
+      <property name="title" translatable="yes">Connection preferences</property>
+
+      <child>
+        <object class="HdyPreferencesPage">
+          <property name="visible">True</property>
+
+          <child>
+            <object class="HdyPreferencesGroup">
+              <property name="visible">True</property>
+
+              <child>
+                <object class="HdyActionRow">
+                  <property name="activatable-widget">host_address_label</property>
+                  <property name="visible">True</property>
+                  <property name="title" translatable="yes">Address</property>
+
+                  <child>
+                    <object class="GtkLabel" id="host_address_label">
+                      <property name="visible">True</property>
+                      <property name="selectable">True</property>
+                    </object>
+                  </child>
+                </object>
+              </child>
+
+              <child>
+                <object class="HdyActionRow">
+                  <property name="activatable-widget">connection_name_entry</property>
+                  <property name="visible">True</property>
+                  <property name="title" translatable="yes">Name</property>
+
+                  <child>
+                    <object class="GtkEntry" id="connection_name_entry">
+                      <property name="visible">True</property>
+                      <property name="valign">center</property>
+                    </object>
+                  </child>
+                </object>
+              </child>
+            </object>
+          </child>
+
+          <child>
+            <object class="HdyPreferencesGroup">
+              <property name="visible">True</property>
+              <property name="title" translatable="yes">Display</property>
+
+              <child>
+                <object class="ConnectionsBooleanProperty" id="scaling">
+                  <property name="visible">True</property>
+                  <property name="title" translatable="yes">Scaling</property>
+                </object>
+              </child>
+
+              <child>
+                <object class="ConnectionsBooleanProperty" id="view_only">
+                  <property name="visible">True</property>
+                  <property name="title" translatable="yes">View only</property>
+                </object>
+              </child>
+
+              <child>
+                <object class="ConnectionsBooleanProperty" id="show_local_pointer">
+                  <property name="visible">True</property>
+                  <property name="title" translatable="yes">Show local pointer</property>
+                </object>
+              </child>
+
+              <child>
+                <object class="HdyActionRow">
+                  <property name="activatable-widget">bandwidth_combo</property>
+                  <property name="visible">True</property>
+                  <property name="title" translatable="yes">Bandwidth</property>
+
+                  <child>
+                    <object class="GtkComboBoxText" id="bandwidth_combo">
+                      <property name="visible">True</property>
+                      <property name="valign">center</property>
+                      <items>
+                        <item id="high-qualiy" translatable="yes">High quality</item>
+                        <item id="fast-refresh" translatable="yes">Fast refresh</item>
+                      </items>
+                    </object>
+                  </child>
+                </object>
+              </child>
+
+              <child>
+                <object class="HdyActionRow">
+                  <property name="activatable-widget">scale_mode_combo</property>
+                  <property name="visible">True</property>
+                  <property name="title" translatable="yes">Scale mode</property>
+
+                  <child>
+                    <object class="GtkComboBoxText" id="scale_mode_combo">
+                      <property name="visible">True</property>
+                      <property name="valign">center</property>
+                      <items>
+                        <item id="fit-window" translatable="yes">Fit window</item>
+                        <item id="original" translatable="yes">Original size</item>
+                      </items>
+                    </object>
+                  </child>
+                </object>
+              </child>
+            </object>
+          </child>
+        </object>
+      </child>
+    </template>
+  </interface>
diff --git a/src/vnc-preferences-window.vala b/src/vnc-preferences-window.vala
new file mode 100644
index 0000000..5d816ee
--- /dev/null
+++ b/src/vnc-preferences-window.vala
@@ -0,0 +1,52 @@
+/* vnc-preferences-window.vala
+ *
+ * Copyright (C) Red Hat, Inc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Felipe Borges <felipeborges gnome org>
+ *
+ */
+
+namespace Connections {
+    [GtkTemplate (ui = "/org/gnome/Connections/ui/vnc-preferences.ui")]
+    private class VncPreferencesWindow : Connections.PreferencesWindow {
+        [GtkChild]
+        private unowned Gtk.Entry connection_name_entry;
+        [GtkChild]
+        private unowned Gtk.Label host_address_label;
+        [GtkChild]
+        private unowned BooleanProperty scaling;
+        [GtkChild]
+        private unowned BooleanProperty view_only;
+        [GtkChild]
+        private unowned BooleanProperty show_local_pointer;
+        [GtkChild]
+        private unowned Gtk.ComboBoxText bandwidth_combo;
+        [GtkChild]
+        private unowned Gtk.ComboBoxText scale_mode_combo;
+
+        public VncPreferencesWindow (Connection connection) {
+            this.connection = connection;
+
+            bind_widget_property (connection_name_entry, "text", "display_name");
+            bind_widget_property (host_address_label, "label", "uri");
+            bind_widget_property (scaling, "active", "scaling");
+            bind_widget_property (view_only, "active", "view-only");
+            bind_widget_property (show_local_pointer, "active", "show-local-pointer");
+            bind_widget_property (bandwidth_combo, "active_id", "bandwidth");
+            bind_widget_property (scale_mode_combo, "active_id", "scale-mode");
+        }
+    }
+}
diff --git a/src/window.vala b/src/window.vala
index 95bfb04..034037d 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -105,6 +105,15 @@ namespace Connections {
             stack.set_visible_child (collection_view);
         }
 
+        public void show_preferences_window (Connection connection) {
+            if (connection is VncConnection)
+                (new VncPreferencesWindow (connection)).present ();
+            else if (connection is RdpConnection)
+                (new RdpPreferencesWindow (connection)).present ();
+            else
+                debug ("Failed to launch preferences window for %s", connection.uri);
+        }
+
         [GtkCallback]
         private bool on_key_pressed (Gtk.Widget widget, Gdk.EventKey event) {
             var default_modifiers = Gtk.accelerator_get_default_mod_mask ();


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