Convert PidginProxyPrefs to Adwaita 1.2

Sat, 29 Oct 2022 01:14:13 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Sat, 29 Oct 2022 01:14:13 -0500
changeset 41859
ed82ab63d15a
parent 41858
38e61d11b89f
child 41860
9315e7772780

Convert PidginProxyPrefs to Adwaita 1.2

Testing Done:
Set all the values via the ui and the config file and tested bad values in the port in both as well. Bad values in the ui will store whatever atoi returned, but bad values in the config file will fallback to the default.

Reviewed at https://reviews.imfreedom.org/r/1996/

pidgin/prefs/pidginproxyprefs.c file | annotate | diff | comparison | revisions
pidgin/resources/Prefs/proxy.ui file | annotate | diff | comparison | revisions
--- a/pidgin/prefs/pidginproxyprefs.c	Sat Oct 29 00:53:33 2022 -0500
+++ b/pidgin/prefs/pidginproxyprefs.c	Sat Oct 29 01:14:13 2022 -0500
@@ -158,6 +158,30 @@
 	return g_variant_new_string(map[position]);
 }
 
+static gboolean
+pidgin_proxy_prefs_get_port_mapping(GValue *value, GVariant *variant,
+                                    G_GNUC_UNUSED gpointer data)
+{
+	g_value_take_string(value,
+	                    g_strdup_printf("%d", g_variant_get_uint16(variant)));
+
+	return TRUE;
+}
+
+static GVariant *
+pidgin_proxy_prefs_set_port_mapping(const GValue *value,
+                                    G_GNUC_UNUSED const GVariantType *expected_type,
+                                    G_GNUC_UNUSED gpointer data)
+{
+	const char *current = g_value_get_string(value);
+
+	if(current != NULL) {
+		return g_variant_new_uint16(atoi(current) & 0xFFFF);
+	}
+
+	return NULL;
+}
+
 static void
 pidgin_proxy_prefs_init_gnome(PidginProxyPrefs *prefs) {
 	gchar *path = NULL;
@@ -205,8 +229,13 @@
 
 	g_settings_bind(settings, "host", prefs->host, "text",
 	                G_SETTINGS_BIND_DEFAULT);
-	g_settings_bind(settings, "port", prefs->port, "value",
-	                G_SETTINGS_BIND_DEFAULT);
+	g_settings_bind_with_mapping(settings, "port",
+	                             prefs->port, "text",
+	                             G_SETTINGS_BIND_DEFAULT,
+	                             pidgin_proxy_prefs_get_port_mapping,
+	                             pidgin_proxy_prefs_set_port_mapping,
+	                             NULL,
+	                             NULL);
 	g_settings_bind(settings, "username", prefs->username, "text",
 	                G_SETTINGS_BIND_DEFAULT);
 	g_settings_bind(settings, "password", prefs->password, "text",
--- a/pidgin/resources/Prefs/proxy.ui	Sat Oct 29 00:53:33 2022 -0500
+++ b/pidgin/resources/Prefs/proxy.ui	Sat Oct 29 01:14:13 2022 -0500
@@ -18,7 +18,7 @@
 -->
 <interface>
   <requires lib="gtk" version="4.0"/>
-  <requires lib="Adw" version="1.0"/>
+  <requires lib="Adw" version="1.2"/>
   <!-- interface-license-type gplv2 -->
   <!-- interface-name Pidgin -->
   <!-- interface-description Internet Messenger -->
@@ -85,73 +85,31 @@
             <child>
               <object class="GtkListBox">
                 <child>
-                  <object class="AdwActionRow">
-                    <property name="activatable-widget">host</property>
+                  <object class="AdwEntryRow" id="host">
                     <property name="title" translatable="1">_Host</property>
                     <property name="use-underline">1</property>
-                    <property name="focusable">0</property>
-                    <child>
-                      <object class="GtkEntry" id="host">
-                        <property name="focusable">1</property>
-                        <property name="hexpand">1</property>
-                        <property name="valign">center</property>
-                      </object>
-                    </child>
                   </object>
                 </child>
                 <child>
-                  <object class="AdwActionRow">
-                    <property name="activatable-widget">port</property>
+                  <object class="AdwEntryRow" id="port">
                     <property name="title" translatable="1">P_ort</property>
                     <property name="use-underline">1</property>
                     <property name="focusable">0</property>
-                    <child>
-                      <object class="GtkSpinButton" id="port">
-                        <property name="focusable">1</property>
-                        <property name="text" translatable="1">0</property>
-                        <property name="adjustment">
-                          <object class="GtkAdjustment">
-                            <property name="upper">65535</property>
-                            <property name="step-increment">1</property>
-                            <property name="page-increment">10</property>
-                          </object>
-                        </property>
-                        <property name="numeric">1</property>
-                        <property name="hexpand">1</property>
-                        <property name="valign">center</property>
-                      </object>
-                    </child>
+                    <property name="input-purpose">number</property>
                   </object>
                 </child>
                 <child>
-                  <object class="AdwActionRow">
-                    <property name="activatable-widget">username</property>
+                  <object class="AdwEntryRow" id="username">
                     <property name="title" translatable="1">User_name</property>
                     <property name="use-underline">1</property>
                     <property name="focusable">0</property>
-                    <child>
-                      <object class="GtkEntry" id="username">
-                        <property name="focusable">1</property>
-                        <property name="hexpand">1</property>
-                        <property name="valign">center</property>
-                      </object>
-                    </child>
                   </object>
                 </child>
                 <child>
-                  <object class="AdwActionRow">
-                    <property name="activatable-widget">password</property>
+                  <object class="AdwPasswordEntryRow" id="password">
                     <property name="title" translatable="1">Pa_ssword</property>
                     <property name="use-underline">1</property>
                     <property name="focusable">0</property>
-                    <child>
-                      <object class="GtkPasswordEntry" id="password">
-                        <property name="focusable">1</property>
-                        <property name="hexpand">1</property>
-                        <property name="show-peek-icon">1</property>
-                        <property name="valign">center</property>
-                      </object>
-                    </child>
                   </object>
                 </child>
               </object>

mercurial