Port PidginAddChatDialog to GTK4 gtk4

Fri, 19 Aug 2022 00:37:34 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 19 Aug 2022 00:37:34 -0500
branch
gtk4
changeset 41563
17c8c3d42aa0
parent 41562
bfd0330f09fb
child 41564
661f4b3b8298

Port PidginAddChatDialog to GTK4

Testing Done:
Compiled.

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

pidgin/pidginaddchatdialog.c file | annotate | diff | comparison | revisions
pidgin/resources/Dialogs/addchat.ui file | annotate | diff | comparison | revisions
--- a/pidgin/pidginaddchatdialog.c	Mon Aug 15 23:43:18 2022 -0500
+++ b/pidgin/pidginaddchatdialog.c	Fri Aug 19 00:37:34 2022 -0500
@@ -51,7 +51,6 @@
 G_DEFINE_TYPE(PidginAddChatDialog, pidgin_add_chat_dialog, GTK_TYPE_DIALOG)
 
 /* ugh, prototypes... */
-static void pidgin_add_chat_dialog_remove_widget_cb(GtkWidget *child, gpointer data);
 static void pidgin_add_chat_dialog_input_changed_cb(GtkEditable *editable, gpointer data);
 
 /******************************************************************************
@@ -68,7 +67,7 @@
 		if(required) {
 			const gchar *value = NULL;
 
-			value = gtk_entry_get_text(GTK_ENTRY(data));
+			value = gtk_editable_get_text(GTK_EDITABLE(data));
 			if(value == NULL || *value == '\0') {
 				*valid = FALSE;
 			}
@@ -96,6 +95,7 @@
 	PurpleAccount *account = NULL;
 	PurpleConnection *connection = NULL;
 	PurpleProtocol *protocol = NULL;
+	GtkWidget *child = NULL;
 	GList *info = NULL;
 	GHashTable *defaults = NULL;
 	gboolean focus_set = FALSE;
@@ -105,9 +105,9 @@
 	protocol = purple_account_get_protocol(account);
 
 	/* Clean up the dynamic box and our list of entires. */
-	gtk_container_foreach(GTK_CONTAINER(dialog->dynamic_box),
-	                      pidgin_add_chat_dialog_remove_widget_cb,
-	                      dialog->dynamic_box);
+	while((child = gtk_widget_get_first_child(dialog->dynamic_box)) != NULL) {
+		gtk_box_remove(GTK_BOX(dialog->dynamic_box), child);
+	}
 	g_clear_pointer(&dialog->inputs, g_list_free);
 
 	info = purple_protocol_chat_info(PURPLE_PROTOCOL_CHAT(protocol),
@@ -134,7 +134,7 @@
 
 			value = g_hash_table_lookup(defaults, pce->identifier);
 			if(value != NULL) {
-				gtk_entry_set_text(GTK_ENTRY(input), value);
+				gtk_editable_set_text(GTK_EDITABLE(input), value);
 			}
 
 			if(pce->secret) {
@@ -145,15 +145,18 @@
 		}
 
 		box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
-		gtk_box_pack_start(GTK_BOX(dialog->dynamic_box), box, FALSE, FALSE, 0);
+		gtk_box_append(GTK_BOX(dialog->dynamic_box), box);
 
 		label = gtk_label_new_with_mnemonic(pce->label);
 		gtk_label_set_xalign(GTK_LABEL(label), 0.0f);
 		gtk_label_set_yalign(GTK_LABEL(label), 0.0f);
-		gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0);
+		gtk_widget_set_halign(label, GTK_ALIGN_FILL);
+		gtk_box_append(GTK_BOX(box), label);
 		gtk_size_group_add_widget(dialog->sg, label);
 
-		gtk_box_pack_start(GTK_BOX(box), input, TRUE, TRUE, 0);
+		gtk_widget_set_hexpand(input, TRUE);
+		gtk_widget_set_halign(input, GTK_ALIGN_FILL);
+		gtk_box_append(GTK_BOX(box), input);
 		if(!focus_set) {
 			gtk_widget_grab_focus(input);
 			focus_set = TRUE;
@@ -175,7 +178,7 @@
 
 	g_hash_table_destroy(defaults);
 
-	gtk_widget_show_all(dialog->dynamic_box);
+	gtk_widget_show(dialog->dynamic_box);
 
 	pidgin_add_chat_dialog_validate(dialog);
 }
@@ -223,7 +226,7 @@
 
 		value = g_strdup_printf("%d", int_value);
 	} else {
-		const gchar *str_value = gtk_entry_get_text(GTK_ENTRY(data));
+		const gchar *str_value = gtk_editable_get_text(GTK_EDITABLE(data));
 
 		if(*str_value != '\0') {
 			value = g_strdup(str_value);
@@ -252,13 +255,6 @@
 }
 
 static void
-pidgin_add_chat_dialog_remove_widget_cb(GtkWidget *child, gpointer data) {
-	GtkContainer *parent = data;
-
-	gtk_container_remove(parent, child);
-}
-
-static void
 pidgin_add_chat_dialog_response_cb(GtkDialog *dialog, gint response_id,
                                    G_GNUC_UNUSED gpointer data)
 {
@@ -283,7 +279,7 @@
 		               pidgin_add_chat_dialog_add_input_to_components,
 		               components);
 
-		alias = gtk_entry_get_text(GTK_ENTRY(acdialog->alias));
+		alias = gtk_editable_get_text(GTK_EDITABLE(acdialog->alias));
 
 		chat = purple_chat_new(account, alias, components);
 
@@ -319,7 +315,7 @@
 	}
 
 	if(close) {
-		gtk_widget_destroy(GTK_WIDGET(dialog));
+		gtk_window_destroy(GTK_WINDOW(dialog));
 	}
 }
 
@@ -446,14 +442,15 @@
 	}
 
 	if(alias != NULL) {
-		gtk_entry_set_text(GTK_ENTRY(acdialog->alias), alias);
+		gtk_editable_set_text(GTK_EDITABLE(acdialog->alias), alias);
 	}
 
 	if(PURPLE_IS_GROUP(group)) {
 		GtkWidget *entry = NULL;
 
-		entry = gtk_bin_get_child(GTK_BIN(acdialog->group));
-		gtk_entry_set_text(GTK_ENTRY(entry), purple_group_get_name(group));
+		entry = gtk_combo_box_get_child(GTK_COMBO_BOX(acdialog->group));
+		gtk_editable_set_text(GTK_EDITABLE(entry),
+		                      purple_group_get_name(group));
 	}
 
 	acdialog->default_name = name;
--- a/pidgin/resources/Dialogs/addchat.ui	Mon Aug 15 23:43:18 2022 -0500
+++ b/pidgin/resources/Dialogs/addchat.ui	Fri Aug 19 00:37:34 2022 -0500
@@ -15,12 +15,11 @@
 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, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+along with this program; if not, see <https://www.gnu.org/licenses/>.
 
 -->
 <interface>
-  <requires lib="gtk+" version="3.24"/>
+  <requires lib="gtk" version="4.0"/>
   <requires lib="pidgin" version="3.0"/>
   <!-- interface-license-type gplv2 -->
   <!-- interface-name Pidgin -->
@@ -34,256 +33,147 @@
     <property name="child-model">account_filter_connected</property>
   </object>
   <template class="PidginAddChatDialog" parent="GtkDialog">
-    <property name="can-focus">False</property>
-    <property name="border-width">12</property>
-    <property name="title" translatable="yes">Add Chat</property>
-    <property name="resizable">False</property>
-    <property name="type-hint">dialog</property>
+    <property name="title" translatable="1">Add Chat</property>
+    <property name="resizable">0</property>
     <signal name="response" handler="pidgin_add_chat_dialog_response_cb" swapped="no"/>
-    <child internal-child="vbox">
+    <child internal-child="content_area">
       <object class="GtkBox">
-        <property name="can-focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">12</property>
         <child>
+          <object class="GtkLabel">
+            <property name="label" translatable="1">Please enter an alias, and the appropriate information about the chat you would like to add to your buddy list.</property>
+            <property name="wrap">1</property>
+            <property name="xalign">0</property>
+            <property name="yalign">0</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="spacer"/>
+        </child>
+        <child>
           <object class="GtkBox">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="orientation">vertical</property>
-            <property name="spacing">12</property>
+            <property name="spacing">5</property>
             <child>
-              <object class="GtkLabel">
-                <property name="visible">True</property>
-                <property name="can-focus">False</property>
-                <property name="label" translatable="yes">Please enter an alias, and the appropriate information about the chat you would like to add to your buddy list.</property>
-                <property name="wrap">True</property>
+              <object class="GtkLabel" id="label1">
+                <property name="label" translatable="1">A_ccount:</property>
+                <property name="use-underline">1</property>
+                <property name="mnemonic-widget">account</property>
                 <property name="xalign">0</property>
                 <property name="yalign">0</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="spacer">
-                <property name="visible">True</property>
-                <property name="can-focus">False</property>
+                <property name="halign">fill</property>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkBox">
-                <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">A_ccount:</property>
-                    <property name="use-underline">True</property>
-                    <property name="mnemonic-widget">account</property>
-                    <property name="xalign">0</property>
-                    <property name="yalign">0</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="PidginAccountChooser" id="account">
-                    <property name="visible">True</property>
-                    <property name="can-focus">False</property>
-                    <property name="model">filter</property>
-                    <signal name="changed" handler="pidgin_add_chat_dialog_account_changed_cb" object="PidginAddChatDialog" swapped="no"/>
-                  </object>
-                  <packing>
-                    <property name="expand">True</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">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkBox" id="dynamic_box">
-                <property name="visible">True</property>
-                <property name="can-focus">False</property>
-                <property name="orientation">vertical</property>
-                <property name="spacing">6</property>
-                <child>
-                  <placeholder/>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">3</property>
-              </packing>
             </child>
             <child>
-              <object class="GtkBox">
-                <property name="visible">True</property>
-                <property name="can-focus">False</property>
-                <property name="spacing">5</property>
-                <child>
-                  <object class="GtkLabel" id="label4">
-                    <property name="visible">True</property>
-                    <property name="can-focus">False</property>
-                    <property name="label" translatable="yes">A_lias:</property>
-                    <property name="use-underline">True</property>
-                    <property name="mnemonic-widget">alias</property>
-                    <property name="xalign">0</property>
-                    <property name="yalign">0</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkEntry" id="alias">
-                    <property name="visible">True</property>
-                    <property name="can-focus">True</property>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
+              <object class="PidginAccountChooser" id="account">
+                <property name="hexpand">1</property>
+                <property name="hfill">1</property>
+                <property name="model">filter</property>
+                <signal name="changed" handler="pidgin_add_chat_dialog_account_changed_cb" object="PidginAddChatDialog" swapped="no"/>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">4</property>
-              </packing>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox" id="dynamic_box">
+            <property name="orientation">vertical</property>
+            <property name="spacing">6</property>
+            <property name="hexpand">1</property>
+            <property name="hfill">1</property>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="spacing">5</property>
+            <child>
+              <object class="GtkLabel" id="label4">
+                <property name="label" translatable="1">A_lias:</property>
+                <property name="use-underline">1</property>
+                <property name="mnemonic-widget">alias</property>
+                <property name="xalign">0</property>
+                <property name="yalign">0</property>
+                <property name="halign">fill</property>
+              </object>
             </child>
             <child>
-              <object class="GtkBox">
-                <property name="visible">True</property>
-                <property name="can-focus">False</property>
-                <property name="spacing">5</property>
-                <child>
-                  <object class="GtkLabel" id="label5">
-                    <property name="visible">True</property>
-                    <property name="can-focus">False</property>
-                    <property name="label" translatable="yes">_Group:</property>
-                    <property name="use-underline">True</property>
-                    <property name="xalign">0</property>
-                    <property name="yalign">0</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkComboBoxText" id="group">
-                    <property name="visible">True</property>
-                    <property name="can-focus">False</property>
-                    <property name="has-entry">True</property>
-                    <child internal-child="entry">
-                      <object class="GtkEntry">
-                        <property name="can-focus">True</property>
-                      </object>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
+              <object class="GtkEntry" id="alias">
+                <property name="hexpand">1</property>
+                <property name="hfill">1</property>
+                <property name="focusable">1</property>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">5</property>
-              </packing>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="spacing">5</property>
+            <child>
+              <object class="GtkLabel" id="label5">
+                <property name="label" translatable="1">_Group:</property>
+                <property name="use-underline">1</property>
+                <property name="xalign">0</property>
+                <property name="yalign">0</property>
+                <property name="halign">fill</property>
+              </object>
             </child>
             <child>
-              <object class="GtkCheckButton" id="autojoin">
-                <property name="label" translatable="yes">Automatically _join when account connects</property>
-                <property name="visible">True</property>
-                <property name="can-focus">True</property>
-                <property name="receives-default">False</property>
-                <property name="halign">start</property>
-                <property name="use-underline">True</property>
-                <property name="draw-indicator">True</property>
+              <object class="GtkComboBoxText" id="group">
+                <property name="hexpand">1</property>
+                <property name="hfill">1</property>
+                <property name="has-entry">1</property>
+                <property name="child">
+                  <object class="GtkEntry">
+                    <property name="focusable">1</property>
+                  </object>
+                </property>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">6</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkCheckButton" id="persistent">
-                <property name="label" translatable="yes">_Remain in chat after window is closed</property>
-                <property name="visible">True</property>
-                <property name="can-focus">True</property>
-                <property name="receives-default">False</property>
-                <property name="halign">start</property>
-                <property name="use-underline">True</property>
-                <property name="draw-indicator">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">7</property>
-              </packing>
             </child>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="autojoin">
+            <property name="label" translatable="1">Automatically _join when account connects</property>
+            <property name="focusable">1</property>
+            <property name="halign">start</property>
+            <property name="use-underline">1</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="persistent">
+            <property name="label" translatable="1">_Remain in chat after window is closed</property>
+            <property name="focusable">1</property>
+            <property name="halign">start</property>
+            <property name="use-underline">1</property>
+          </object>
         </child>
       </object>
     </child>
     <child type="action">
       <object class="GtkButton" id="button3">
-        <property name="label" translatable="yes">Room List</property>
-        <property name="visible">True</property>
-        <property name="can-focus">True</property>
-        <property name="receives-default">True</property>
+        <property name="label" translatable="1">Room List</property>
+        <property name="focusable">1</property>
+        <property name="receives-default">1</property>
       </object>
     </child>
     <child type="action">
       <object class="GtkButton" id="button1">
-        <property name="label" translatable="yes">_Cancel</property>
-        <property name="visible">True</property>
-        <property name="can-focus">True</property>
-        <property name="receives-default">True</property>
-        <property name="use-underline">True</property>
+        <property name="label" translatable="1">_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="button2">
-        <property name="label" translatable="yes">_Add</property>
-        <property name="visible">True</property>
-        <property name="sensitive">False</property>
-        <property name="can-focus">True</property>
+        <property name="label" translatable="1">_Add</property>
+        <property name="sensitive">0</property>
+        <property name="focusable">1</property>
         <property name="can-default">True</property>
-        <property name="receives-default">True</property>
-        <property name="use-underline">True</property>
+        <property name="receives-default">1</property>
+        <property name="use-underline">1</property>
       </object>
     </child>
     <action-widgets>

mercurial