# HG changeset patch
# Node ID bb5363935f2e
# Parent  a2beb5da0243
diff --git a/pidgin/pidginaccounteditor.c b/pidgin/pidginaccounteditor.c
--- a/pidgin/pidginaccounteditor.c
+++ b/pidgin/pidginaccounteditor.c
@@ -37,6 +37,9 @@
 	GtkWidget *login_options;
 	GtkWidget *protocol;
 	GtkWidget *username;
+	GtkWidget *user_splits;
+	GtkWidget *require_password_row;
+	GtkWidget *require_password;
 
 	GList *user_split_entries;
 	GList *user_split_rows;
@@ -73,7 +76,6 @@
 };
 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
 
-
 /******************************************************************************
  * Prototypes
  *****************************************************************************/
@@ -95,8 +97,7 @@
 
 		row = adw_action_row_new();
 		editor->user_split_rows = g_list_append(editor->user_split_rows, row);
-		adw_preferences_group_add(ADW_PREFERENCES_GROUP(editor->login_options),
-		                          row);
+		gtk_list_box_append(GTK_LIST_BOX(editor->user_splits), row);
 
 		adw_preferences_row_set_title(ADW_PREFERENCES_ROW(row),
 		                              purple_account_user_split_get_text(split));
@@ -116,10 +117,13 @@
 pidgin_account_editor_update_login_options(PidginAccountEditor *editor,
                                            PurpleProtocol *protocol)
 {
+	PurpleProtocolOptions options;
 	GList *user_splits = NULL;
 	GList *split_item = NULL;
 	GList *entry_item = NULL;
 	gchar *username = NULL;
+	gboolean require_password = FALSE;
+	gboolean ret = FALSE;
 
 	/* Clear out the old user splits from our list. */
 	g_clear_pointer(&editor->user_split_entries, g_list_free);
@@ -128,8 +132,8 @@
 	 * constant user split.
 	 */
 	while(editor->user_split_rows != NULL) {
-		adw_preferences_group_remove(ADW_PREFERENCES_GROUP(editor->login_options),
-		                             editor->user_split_rows->data);
+		gtk_list_box_remove(GTK_LIST_BOX(editor->user_splits),
+		                    editor->user_split_rows->data);
 
 		editor->user_split_rows = g_list_delete_link(editor->user_split_rows,
 		                                             editor->user_split_rows);
@@ -200,10 +204,18 @@
 	if(username != NULL) {
 		gtk_editable_set_text(GTK_EDITABLE(editor->username), username);
 		g_free(username);
-		return TRUE;
+		ret = TRUE;
 	}
 
-	return FALSE;
+	options = purple_protocol_get_options(protocol);
+	gtk_widget_set_visible(editor->require_password_row,
+	                       options & OPT_PROTO_PASSWORD_OPTIONAL);
+
+	require_password = purple_account_get_require_password(editor->account);
+	gtk_switch_set_active(GTK_SWITCH(editor->require_password),
+	                      require_password);
+
+	return ret;
 }
 
 static void
@@ -657,6 +669,8 @@
 pidgin_account_editor_login_options_update_editable(PidginAccountEditor *editor)
 {
 	PurpleConnection *connection = NULL;
+	PurpleProtocol *protocol = NULL;
+	PurpleProtocolOptions options;
 	gboolean editable = TRUE;
 
 	if(PURPLE_IS_ACCOUNT(editor->account)) {
@@ -687,6 +701,11 @@
 
 	}
 
+	protocol = purple_account_get_protocol(editor->account);
+	options = purple_protocol_get_options(protocol);
+	gtk_widget_set_visible(editor->require_password_row,
+	                       options & OPT_PROTO_PASSWORD_OPTIONAL);
+
 	gtk_widget_set_sensitive(editor->protocol, editable);
 	gtk_editable_set_editable(GTK_EDITABLE(editor->username), editable);
 	for(GList *l = editor->user_split_entries; l != NULL; l = l->next) {
@@ -694,6 +713,7 @@
 
 		gtk_editable_set_editable(GTK_EDITABLE(widget), editable);
 	}
+	gtk_widget_set_sensitive(editor->require_password, editable);
 }
 
 static void
@@ -720,6 +740,7 @@
 	GString *username = NULL;
 	const gchar *protocol_id = NULL;
 	gboolean new_account = FALSE;
+	gboolean require_password = FALSE;
 
 	protocol = pidgin_protocol_chooser_get_protocol(PIDGIN_PROTOCOL_CHOOSER(editor->protocol));
 	protocol_id = purple_protocol_get_id(protocol);
@@ -761,6 +782,9 @@
 
 	g_string_free(username, TRUE);
 
+	require_password = gtk_switch_get_active(GTK_SWITCH(editor->require_password));
+	purple_account_set_require_password(editor->account, require_password);
+
 	return new_account;
 }
 
@@ -1210,6 +1234,12 @@
 	                                     protocol);
 	gtk_widget_class_bind_template_child(widget_class, PidginAccountEditor,
 	                                     username);
+	gtk_widget_class_bind_template_child(widget_class, PidginAccountEditor,
+	                                     user_splits);
+	gtk_widget_class_bind_template_child(widget_class, PidginAccountEditor,
+	                                     require_password_row);
+	gtk_widget_class_bind_template_child(widget_class, PidginAccountEditor,
+	                                     require_password);
 
 	gtk_widget_class_bind_template_callback(widget_class,
 	                                        pidgin_account_editor_protocol_changed_cb);
diff --git a/pidgin/resources/Accounts/editor.ui b/pidgin/resources/Accounts/editor.ui
--- a/pidgin/resources/Accounts/editor.ui
+++ b/pidgin/resources/Accounts/editor.ui
@@ -50,16 +50,38 @@
                   </object>
                 </child>
                 <child>
-                  <object class="AdwActionRow">
-                    <property name="activatable-widget">username</property>
-                    <property name="title" translatable="1">_Username</property>
-                    <property name="use-underline">1</property>
+                  <object class="AdwPreferencesRow">
                     <child>
-                      <object class="GtkEntry" id="username">
-                        <property name="hexpand">1</property>
+                      <object class="GtkListBox" id="user_splits">
+                        <child>
+                          <object class="AdwActionRow">
+                            <property name="activatable-widget">username</property>
+                            <property name="title" translatable="1">_Username</property>
+                            <property name="use-underline">1</property>
+                            <child>
+                              <object class="GtkEntry" id="username">
+                                <property name="hexpand">1</property>
+                                <property name="valign">center</property>
+                                <property name="truncate-multiline">1</property>
+                                <signal name="changed" handler="pidgin_account_editor_username_changed_cb" object="PidginAccountEditor" swapped="no"/>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="AdwActionRow" id="require_password_row">
+                    <property name="activatable-widget">avatar</property>
+                    <property name="title" translatable="1">Require _password</property>
+                    <property name="subtitle" translatable="1">This account has an optional password, setting this will make it required</property>
+                    <property name="use-underline">1</property>
+                    <property name="visible">0</property>
+                    <child type="suffix">
+                      <object class="GtkSwitch" id="require_password">
                         <property name="valign">center</property>
-                        <property name="truncate-multiline">1</property>
-                        <signal name="changed" handler="pidgin_account_editor_username_changed_cb" object="PidginAccountEditor" swapped="no"/>
                       </object>
                     </child>
                   </object>
