diff options
author | fiaxh <git@lightrise.org> | 2024-09-15 19:20:41 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2024-09-15 19:35:00 +0200 |
commit | 63ba0bc93636de557ced29c19b2b61eeeab57bf8 (patch) | |
tree | f96a3bbde2887feb14103b98431c687ff6a7d0b7 /main | |
parent | 13123dced135746b74f1f40148bfa9cef0c57dc0 (diff) | |
download | dino-63ba0bc93636de557ced29c19b2b61eeeab57bf8.tar.gz dino-63ba0bc93636de557ced29c19b2b61eeeab57bf8.zip |
Refresh "Add account" UI
Diffstat (limited to 'main')
-rw-r--r-- | main/CMakeLists.txt | 1 | ||||
-rw-r--r-- | main/data/manage_accounts/add_account_dialog.ui | 418 | ||||
-rw-r--r-- | main/meson.build | 1 | ||||
-rw-r--r-- | main/src/ui/manage_accounts/add_account_dialog.vala | 310 | ||||
-rw-r--r-- | main/src/ui/util/data_forms.vala | 65 | ||||
-rw-r--r-- | main/src/ui/util/preference_group.vala | 106 | ||||
-rw-r--r-- | main/src/view_model/preferences_row.vala | 5 | ||||
-rw-r--r-- | main/src/windows/conversation_details.vala | 103 |
8 files changed, 410 insertions, 599 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 39b1320e..7e4a246d 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -228,6 +228,7 @@ SOURCES src/ui/util/data_forms.vala src/ui/util/helper.vala src/ui/util/label_hybrid.vala + src/ui/util/preference_group.vala src/ui/util/sizing_bin.vala src/ui/util/size_request_box.vala diff --git a/main/data/manage_accounts/add_account_dialog.ui b/main/data/manage_accounts/add_account_dialog.ui index d37a98f5..243004d6 100644 --- a/main/data/manage_accounts/add_account_dialog.ui +++ b/main/data/manage_accounts/add_account_dialog.ui @@ -2,17 +2,34 @@ <interface> <requires lib="gtk" version="4.0"/> <template class="DinoUiManageAccountsAddAccountDialog"> - <property name="default_width">400</property> + <property name="default_width">450</property> + <property name="default_height">260</property> <property name="modal">True</property> - <child internal-child="content_area"> + <child> <object class="GtkBox"> + <property name="orientation">vertical</property> + <property name="spacing">20</property> <child> - <object class="GtkOverlay"> - <property name="child"> - <object class="GtkBox"> - <property name="hexpand">1</property> - <property name="vexpand">1</property> - <child> + <object class="AdwHeaderBar"> + <style> + <class name="flat"/> + </style> + <child> + <object class="GtkButton" id="back_button"> + <property name="icon-name">go-previous-symbolic</property> + <property name="visible">False</property> + </object> + </child> + </object> + </child> + <child> + <object class="AdwClamp"> + <property name="maximum-size">400</property> + <property name="tightening-threshold">200</property> + <property name="margin-bottom">24</property> + <child> + <object class="GtkOverlay"> + <property name="child"> <object class="GtkStack" id="stack"> <property name="transition_type">slide-left</property> <property name="hexpand">1</property> @@ -21,93 +38,81 @@ <object class="GtkStackPage"> <property name="name">login_jid</property> <property name="child"> - <object class="GtkBox" id="sign_in_jid_box"> + <object class="GtkBox" id="sign_in_box"> <property name="orientation">vertical</property> - <property name="margin-start">20</property> - <property name="margin-end">20</property> - <property name="margin-top">20</property> - <property name="margin-bottom">20</property> - <property name="margin-start">50</property> - <property name="margin-end">50</property> <property name="spacing">20</property> <child> - <object class="GtkLabel"> - <property name="label" translatable="1">Sign in</property> - <attributes> - <attribute name="scale" value="1.3"></attribute> - </attributes> - </object> - </child> - <child> - <object class="GtkBox" id="info_grid"> - <property name="orientation">vertical</property> + <object class="AdwPreferencesGroup"> <child> - <object class="GtkLabel"> - <property name="label">JID</property> - <property name="xalign">0</property> - <attributes> - <attribute name="scale" value="0.9"></attribute> - </attributes> - </object> - </child> - <child> - <object class="GtkEntry" id="jid_entry"> + <object class="AdwEntryRow" id="jid_entry"> + <property name="title">XMPP Address</property> <property name="activates_default">1</property> - <property name="hexpand">1</property> - <property name="width_request">200</property> </object> </child> + </object> + </child> + <child> + <object class="AdwPreferencesGroup" id="password_group"> + <property name="visible">False</property> <child> - <object class="GtkLabel" id="sign_in_jid_error_label"> - <property name="xalign">0</property> - <property name="margin-top">7</property> - <attributes> - <attribute name="scale" value="0.9"></attribute> - </attributes> + <object class="AdwPasswordEntryRow" id="password_entry"> + <property name="title">Password</property> + <property name="activates_default">1</property> </object> </child> </object> </child> <child> + <object class="GtkLabel" id="sign_in_error_label"> + <property name="visible">False</property> + <style> + <class name="error"/> + </style> + <attributes> + <attribute name="scale" value="0.9"></attribute> + </attributes> + </object> + </child> + <child> <object class="GtkBox"> + <property name="halign">center</property> + <property name="spacing">8</property> + <property name="orientation">vertical</property> + <property name="margin-top">16</property> <child> - <object class="GtkButton" id="sign_in_jid_serverlist_button"> - <property name="label" translatable="1">Create account</property> - </object> - </child> - <child> - <object class="GtkButton" id="sign_in_jid_continue_button"> - <property name="halign">end</property> - <property name="hexpand">True</property> - <property name="sensitive">0</property> - <style> - <class name="text-button"/> - <class name="suggested-action"/> - </style> + <object class="GtkButton" id="sign_in_continue_button"> + <property name="sensitive">False</property> <child> - <object class="GtkStack" id="sign_in_jid_continue_stack"> + <object class="GtkBox"> + <property name="spacing">4</property> + <property name="halign">center</property> + <property name="orientation">horizontal</property> <child> - <object class="GtkStackPage"> - <property name="name">label</property> - <property name="child"> - <object class="GtkLabel"> - <property name="label" translatable="1">Next</property> - </object> - </property> + <object class="GtkLabel"> + <property name="label" translatable="1">Login</property> </object> </child> <child> - <object class="GtkStackPage"> - <property name="name">spinner</property> - <property name="child"> - <object class="GtkSpinner"> - <property name="spinning">True</property> - </object> - </property> + <object class="GtkSpinner" id="sign_in_continue_spinner"> + <property name="visible">false</property> + <property name="spinning">True</property> </object> </child> </object> </child> + <style> + <class name="pill"/> + <class name="suggested-action"/> + </style> + </object> + </child> + <child> + <object class="GtkButton" id="sign_in_serverlist_button"> + <property name="label" translatable="1">Create account</property> + <style> + <class name="pill"/> + <class name="flat"/> + </style> </object> </child> </object> @@ -168,126 +173,10 @@ </child> <child> <object class="GtkStackPage"> - <property name="name">login_password</property> - <property name="child"> - <object class="GtkBox" id="sign_in_password_box"> - <property name="orientation">vertical</property> - <property name="margin-start">20</property> - <property name="margin-end">20</property> - <property name="margin-top">20</property> - <property name="margin-bottom">20</property> - <property name="margin-start">50</property> - <property name="margin-end">50</property> - <property name="spacing">20</property> - <child> - <object class="GtkLabel" id="sign_in_password_title"> - <attributes> - <attribute name="scale" value="1.3"></attribute> - </attributes> - </object> - </child> - <child> - <object class="GtkBox"> - <property name="orientation">vertical</property> - <child> - <object class="GtkLabel"> - <property name="label" translatable="1">Password</property> - <property name="xalign">0</property> - <property name="margin-top">7</property> - <attributes> - <attribute name="scale" value="0.9"></attribute> - </attributes> - </object> - </child> - <child> - <object class="GtkEntry" id="password_entry"> - <property name="activates_default">1</property> - <property name="hexpand">1</property> - <property name="input_purpose">password</property> - <property name="width_request">200</property> - <property name="visibility">0</property> - </object> - </child> - <child> - <object class="GtkLabel" id="sign_in_password_error_label"> - <property name="xalign">0</property> - <property name="margin-top">7</property> - <attributes> - <attribute name="scale" value="0.9"></attribute> - </attributes> - </object> - </child> - </object> - </child> - <child> - <object class="GtkBox"> - <child> - <object class="GtkButton" id="sign_in_password_back_button"> - <property name="label" translatable="1">Back</property> - </object> - </child> - <child> - <object class="GtkButton" id="sign_in_password_continue_button"> - <property name="halign">end</property> - <property name="hexpand">True</property> - <property name="sensitive">0</property> - <style> - <class name="text-button"/> - <class name="suggested-action"/> - </style> - <child> - <object class="GtkStack" id="sign_in_password_continue_stack"> - <child> - <object class="GtkStackPage"> - <property name="name">label</property> - <property name="child"> - <object class="GtkLabel"> - <property name="label" translatable="1">Connect</property> - </object> - </property> - </object> - </child> - <child> - <object class="GtkStackPage"> - <property name="name">spinner</property> - <property name="child"> - <object class="GtkSpinner"> - <property name="spinning">True</property> - </object> - </property> - </object> - </child> - </object> - </child> - </object> - </child> - </object> - </child> - </object> - </property> - </object> - </child> - <child> - <object class="GtkStackPage"> <property name="name">server</property> <property name="child"> <object class="GtkBox" id="create_account_box"> <property name="orientation">vertical</property> - <property name="margin-start">20</property> - <property name="margin-end">20</property> - <property name="margin-top">20</property> - <property name="margin-bottom">20</property> - <property name="margin-start">50</property> - <property name="margin-end">50</property> - <child> - <object class="GtkLabel"> - <property name="label" translatable="1">Create account</property> - <property name="margin-bottom">20</property> - <attributes> - <attribute name="scale" value="1.3"></attribute> - </attributes> - </object> - </child> <child> <object class="GtkLabel"> <property name="xalign">0</property> @@ -328,41 +217,39 @@ </child> <child> <object class="GtkBox"> + <property name="halign">center</property> + <property name="spacing">8</property> <property name="margin-top">30</property> <child> <object class="GtkButton" id="login_button"> <property name="label" translatable="1">Sign in instead</property> + <style> + <class name="pill"/> + </style> </object> </child> <child> <object class="GtkButton" id="select_server_continue"> - <property name="halign">end</property> <property name="hexpand">True</property> + <property name="halign">center</property> <property name="sensitive">0</property> <style> - <class name="text-button"/> + <class name="pill"/> <class name="suggested-action"/> </style> <child> - <object class="GtkStack" id="select_server_continue_stack"> + <object class="GtkBox"> + <property name="spacing">4</property> + <property name="orientation">horizontal</property> <child> - <object class="GtkStackPage"> - <property name="name">label</property> - <property name="child"> - <object class="GtkLabel"> - <property name="label" translatable="1">Next</property> - </object> - </property> + <object class="GtkLabel"> + <property name="label" translatable="1">Next</property> </object> </child> <child> - <object class="GtkStackPage"> - <property name="name">spinner</property> - <property name="child"> - <object class="GtkSpinner"> - <property name="spinning">True</property> - </object> - </property> + <object class="GtkSpinner" id="select_server_continue_spinner"> + <property name="spinning">True</property> + <property name="visible">False</property> </object> </child> </object> @@ -380,64 +267,37 @@ <property name="name">form</property> <property name="child"> <object class="GtkBox" id="register_box"> - <property name="margin-start">20</property> - <property name="margin-end">20</property> - <property name="margin-top">20</property> - <property name="margin-bottom">20</property> - <property name="margin-start">50</property> - <property name="margin-end">50</property> + <property name="spacing">30</property> <property name="orientation">vertical</property> - <child> - <object class="GtkLabel" id="register_title"> - <property name="margin-bottom">10</property> - <attributes> - <attribute name="scale" value="1.3"></attribute> - </attributes> - </object> - </child> + <property name="valign">center</property> <child> <object class="GtkBox" id="form_box"> + <property name="spacing">12</property> <property name="orientation">vertical</property> </object> </child> <child> - <object class="GtkBox"> - <property name="margin-top">30</property> - <child> - <object class="GtkButton" id="register_form_back"> - <property name="label" translatable="1">Pick another server</property> - </object> - </child> + <object class="GtkButton" id="register_form_continue"> + <property name="halign">center</property> + <property name="hexpand">True</property> + <style> + <class name="pill"/> + <class name="suggested-action"/> + </style> <child> - <object class="GtkButton" id="register_form_continue"> - <property name="halign">end</property> - <property name="hexpand">True</property> - <style> - <class name="text-button"/> - <class name="suggested-action"/> - </style> + <object class="GtkBox"> + <property name="spacing">4</property> + <property name="halign">center</property> + <property name="orientation">horizontal</property> <child> - <object class="GtkStack" id="register_form_continue_stack"> - <child> - <object class="GtkStackPage"> - <property name="name">label</property> - <property name="child"> - <object class="GtkLabel" id="register_form_continue_label"> - <property name="label" translatable="1">Next</property> - </object> - </property> - </object> - </child> - <child> - <object class="GtkStackPage"> - <property name="name">spinner</property> - <property name="child"> - <object class="GtkSpinner"> - <property name="spinning">True</property> - </object> - </property> - </object> - </child> + <object class="GtkLabel" id="register_form_continue_label"> + <property name="label" translatable="1">Register</property> + </object> + </child> + <child> + <object class="GtkSpinner" id="register_form_continue_spinner"> + <property name="spinning">True</property> + <property name="visible">False</property> </object> </child> </object> @@ -453,12 +313,6 @@ <property name="name">success</property> <property name="child"> <object class="GtkBox" id="success_box"> - <property name="margin-start">50</property> - <property name="margin-end">50</property> - <property name="margin-top">50</property> - <property name="margin-bottom">50</property> - <property name="margin-top">10</property> - <property name="margin-bottom">10</property> <property name="orientation">vertical</property> <property name="valign">center</property> <child> @@ -486,8 +340,6 @@ <child> <object class="GtkLabel" id="success_description"> <property name="wrap">1</property> - <property name="margin-start">5</property> - <property name="margin-end">5</property> <property name="margin-top">5</property> <property name="margin-bottom">5</property> <property name="use-markup">1</property> @@ -501,11 +353,12 @@ <object class="GtkBox"> <property name="halign">center</property> <property name="margin-top">20</property> + <property name="margin-bottom">10</property> <child> <object class="GtkButton" id="success_continue_button"> <property name="label" translatable="1">Finish</property> <style> - <class name="text-button"/> + <class name="pill"/> <class name="suggested-action"/> </style> </object> @@ -517,32 +370,31 @@ </object> </child> </object> - </child> - </object> - </property> - <child type="overlay"> - <object class="GtkRevealer" id="notification_revealer"> - <property name="halign">center</property> - <property name="valign">start</property> - <property name="child"> - <object class="GtkFrame" id="frame2"> -<!-- <property name="shadow_type">none</property>--> - <style> - <class name="app-notification"/> - </style> + </property> + <child type="overlay"> + <object class="GtkRevealer" id="notification_revealer"> + <property name="halign">center</property> + <property name="valign">start</property> <property name="child"> - <object class="GtkBox" id="box2"> - <property name="spacing">20</property> - <child> - <object class="GtkLabel" id="notification_label"/> + <object class="GtkFrame" id="frame2"> + <style> + <class name="app-notification"/> + </style> + <property name="child"> + <object class="GtkBox" id="box2"> + <property name="spacing">20</property> + <child> + <object class="GtkLabel" id="notification_label"/> + </child> + </object> + </property> + <child type="label_item"> + <placeholder/> </child> </object> </property> - <child type="label_item"> - <placeholder/> - </child> </object> - </property> + </child> </object> </child> </object> diff --git a/main/meson.build b/main/meson.build index 69044a1f..9292fbac 100644 --- a/main/meson.build +++ b/main/meson.build @@ -82,6 +82,7 @@ sources = files( 'src/ui/util/data_forms.vala', 'src/ui/util/helper.vala', 'src/ui/util/label_hybrid.vala', + 'src/ui/util/preference_group.vala', 'src/ui/util/size_request_box.vala', 'src/ui/util/sizing_bin.vala', 'src/ui/widgets/avatar_picture.vala', diff --git a/main/src/ui/manage_accounts/add_account_dialog.vala b/main/src/ui/manage_accounts/add_account_dialog.vala index d7bbe66b..3700849f 100644 --- a/main/src/ui/manage_accounts/add_account_dialog.vala +++ b/main/src/ui/manage_accounts/add_account_dialog.vala @@ -8,53 +8,52 @@ using Xmpp; namespace Dino.Ui.ManageAccounts { [GtkTemplate (ui = "/im/dino/Dino/manage_accounts/add_account_dialog.ui")] -public class AddAccountDialog : Gtk.Dialog { +public class AddAccountDialog : Adw.Window { public signal void added(Account account); + enum Page { + SIGN_IN, + SIGN_IN_TLS_ERROR, + CREATE_ACCOUNT_SELECT_SERVER, + CREATE_ACCOUNT_REGISTER_FORM, + SUCCESS + } + [GtkChild] private unowned Stack stack; [GtkChild] private unowned Revealer notification_revealer; [GtkChild] private unowned Label notification_label; // Sign in - JID - [GtkChild] private unowned Box sign_in_jid_box; - [GtkChild] private unowned Label sign_in_jid_error_label; - [GtkChild] private unowned Entry jid_entry; - [GtkChild] private unowned Stack sign_in_jid_continue_stack; - [GtkChild] private unowned Button sign_in_jid_continue_button; - [GtkChild] private unowned Button sign_in_jid_serverlist_button; + [GtkChild] private unowned Box sign_in_box; + [GtkChild] private unowned Label sign_in_error_label; + [GtkChild] private unowned Adw.EntryRow jid_entry; + [GtkChild] private unowned Adw.PreferencesGroup password_group; + [GtkChild] private unowned Adw.PasswordEntryRow password_entry; + [GtkChild] private unowned Button sign_in_continue_button; + [GtkChild] private unowned Spinner sign_in_continue_spinner; + [GtkChild] private unowned Button sign_in_serverlist_button; // Sign in - TLS error [GtkChild] private unowned Box sign_in_tls_box; [GtkChild] private unowned Label sign_in_tls_label; - [GtkChild] private unowned Stack sign_in_password_continue_stack; [GtkChild] private unowned Button sign_in_tls_back_button; - // Sign in - Password - [GtkChild] private unowned Box sign_in_password_box; - [GtkChild] private unowned Label sign_in_password_title; - [GtkChild] private unowned Label sign_in_password_error_label; - - [GtkChild] private unowned Entry password_entry; - [GtkChild] private unowned Button sign_in_password_continue_button; - [GtkChild] private unowned Button sign_in_password_back_button; - // Select Server [GtkChild] private unowned Box create_account_box; [GtkChild] private unowned Button login_button; - [GtkChild] private unowned Stack select_server_continue_stack; + [GtkChild] private unowned Spinner select_server_continue_spinner; [GtkChild] private unowned Button select_server_continue; [GtkChild] private unowned Label register_form_continue_label; [GtkChild] private unowned ListBox server_list_box; [GtkChild] private unowned Entry server_entry; // Register Form + [GtkChild] private unowned Button back_button; [GtkChild] private unowned Box register_box; - [GtkChild] private unowned Label register_title; [GtkChild] private unowned Box form_box; - [GtkChild] private unowned Button register_form_back; - [GtkChild] private unowned Stack register_form_continue_stack; + [GtkChild] private unowned Spinner register_form_continue_spinner; [GtkChild] private unowned Button register_form_continue; // Success @@ -82,19 +81,12 @@ public class AddAccountDialog : Gtk.Dialog { this.title = _("Add Account"); // Sign in - Jid - Util.force_error_color(sign_in_jid_error_label); jid_entry.changed.connect(on_jid_entry_changed); - sign_in_jid_continue_button.clicked.connect(on_sign_in_jid_continue_button_clicked); - sign_in_jid_serverlist_button.clicked.connect(show_select_server); + sign_in_continue_button.clicked.connect(on_sign_in_continue_button_clicked); + sign_in_serverlist_button.clicked.connect(show_select_server); // Sign in - TLS error - sign_in_tls_back_button.clicked.connect(show_sign_in_jid); - - // Sign in - Password - Util.force_error_color(sign_in_password_error_label); - password_entry.changed.connect(() => { sign_in_password_continue_button.set_sensitive(password_entry.text.length > 0); }); - sign_in_password_continue_button.clicked.connect(on_sign_in_password_continue_button_clicked); - sign_in_password_back_button.clicked.connect(show_sign_in_jid); + sign_in_tls_back_button.clicked.connect(() => show_sign_in() ); // Select Server server_entry.changed.connect(() => { @@ -106,7 +98,7 @@ public class AddAccountDialog : Gtk.Dialog { } }); select_server_continue.clicked.connect(on_select_server_continue); - login_button.clicked.connect(show_sign_in_jid); + login_button.clicked.connect(() => show_sign_in() ); foreach (string server in server_list) { ListBoxRow list_box_row = new ListBoxRow(); @@ -117,38 +109,36 @@ public class AddAccountDialog : Gtk.Dialog { // Register Form register_form_continue.clicked.connect(on_register_form_continue_clicked); - register_form_back.clicked.connect(show_select_server); + back_button.clicked.connect(() => { + show_select_server(); + back_button.visible = false; + }); // Success success_continue_button.clicked.connect(() => close()); - show_sign_in_jid(); + show_sign_in(); } - private void show_sign_in_jid() { - sign_in_jid_box.visible = true; - jid_entry.grab_focus(); - stack.visible_child_name = "login_jid"; - sign_in_tls_box.visible = false; - sign_in_password_box.visible = false; - create_account_box.visible = false; - register_box.visible = false; - success_box.visible = false; - set_default_widget(sign_in_jid_continue_button); - - sign_in_jid_error_label.label = ""; - jid_entry.sensitive = true; - animate_window_resize(sign_in_jid_box); + private void show_sign_in(bool keep_jid = false) { + switch_stack_page(Page.SIGN_IN); + + this.title = _("Sign in"); + + set_default_widget(sign_in_continue_button); + sign_in_error_label.visible = false; + sign_in_continue_spinner.visible = false; + if (!keep_jid) { + jid_entry.text = ""; + jid_entry.grab_focus(); + } + password_entry.text = ""; + password_group.visible = false; + sign_in_serverlist_button.visible = true; } private void show_tls_error(string domain, TlsCertificateFlags error_flags) { - sign_in_tls_box.visible = true; - stack.visible_child_name = "tls_error"; - sign_in_jid_box.visible = false; - sign_in_password_box.visible = false; - create_account_box.visible = false; - register_box.visible = false; - success_box.visible = false; + switch_stack_page(Page.SIGN_IN_TLS_ERROR); string error_desc = _("The server could not prove that it is %s.").printf("<b>" + domain + "</b>"); if (TlsCertificateFlags.UNKNOWN_CA in error_flags) { @@ -161,27 +151,12 @@ public class AddAccountDialog : Gtk.Dialog { error_desc += " " + _("Its security certificate is expired."); } sign_in_tls_label.label = error_desc; - - animate_window_resize(sign_in_tls_box); - } - - private void show_sign_in_password() { - sign_in_password_box.visible = true; - password_entry.grab_focus(); - stack.visible_child_name = "login_password"; - sign_in_jid_box.visible = false; - sign_in_tls_box.visible = false; - create_account_box.visible = false; - register_box.visible = false; - success_box.visible = false; - set_default_widget(sign_in_password_continue_button); - - sign_in_password_error_label.label = ""; - sign_in_password_title.label = _("Sign in to %s").printf(login_jid.to_string()); - animate_window_resize(sign_in_password_box); } private void show_select_server() { + switch_stack_page(Page.CREATE_ACCOUNT_SELECT_SERVER); + + this.title = _("Create account"); server_entry.text = ""; server_entry.grab_focus(); set_default_widget(select_server_continue); @@ -189,38 +164,17 @@ public class AddAccountDialog : Gtk.Dialog { server_list_box.row_activated.disconnect(on_server_list_row_activated); server_list_box.unselect_all(); server_list_box.row_activated.connect(on_server_list_row_activated); - - create_account_box.visible = true; - stack.visible_child_name = "server"; - sign_in_jid_box.visible = false; - sign_in_tls_box.visible = false; - register_box.visible = false; - success_box.visible = false; - - animate_window_resize(create_account_box); } private void show_register_form() { - register_box.visible = true; - stack.visible_child_name = "form"; - sign_in_jid_box.visible = false; - sign_in_tls_box.visible = false; - sign_in_password_box.visible = false; - create_account_box.visible = false; - success_box.visible = false; + switch_stack_page(Page.CREATE_ACCOUNT_REGISTER_FORM); set_default_widget(register_form_continue); - animate_window_resize(register_box); } private void show_success(Account account) { - success_box.visible = true; - stack.visible_child_name = "success"; - sign_in_jid_box.visible = false; - sign_in_tls_box.visible = false; - sign_in_password_box.visible = false; - create_account_box.visible = false; - register_box.visible = false; + switch_stack_page(Page.SUCCESS); + success_description.label = _("You can now use the account %s.").printf("<b>" + Markup.escape_text(account.bare_jid.to_string()) + "</b>"); set_default_widget(success_continue_button); @@ -230,63 +184,75 @@ public class AddAccountDialog : Gtk.Dialog { try { login_jid = new Jid(jid_entry.text); if (login_jid.localpart != null && login_jid.resourcepart == null) { - sign_in_jid_continue_button.sensitive = true; - jid_entry.secondary_icon_name = null; + sign_in_continue_button.sensitive = true; } else { - sign_in_jid_continue_button.sensitive = false; + sign_in_continue_button.sensitive = false; } } catch (InvalidJidError e) { - sign_in_jid_continue_button.sensitive = false; + sign_in_continue_button.sensitive = false; } } - private async void on_sign_in_jid_continue_button_clicked() { + private async void on_sign_in_continue_button_clicked() { try { login_jid = new Jid(jid_entry.text); - jid_entry.sensitive = false; sign_in_tls_label.label = ""; - sign_in_jid_error_label.label = ""; - sign_in_jid_continue_button.sensitive = false; - sign_in_jid_continue_stack.visible_child_name = "spinner"; - Register.ServerAvailabilityReturn server_status = yield Register.check_server_availability(login_jid); - sign_in_jid_continue_stack.visible_child_name = "label"; - sign_in_jid_continue_button.sensitive = true; - if (server_status.available) { - show_sign_in_password(); + sign_in_error_label.visible = false; + sign_in_continue_button.sensitive = false; + sign_in_continue_spinner.visible = true; + + ulong jid_entry_changed_handler_id = -1; + jid_entry_changed_handler_id = jid_entry.changed.connect(() => { + jid_entry.disconnect(jid_entry_changed_handler_id); + show_sign_in(true); + return; + }); + + if (password_group.visible) { + // JID + Psw fields were visible: Try to log in + string password = password_entry.text; + Account account = new Account(login_jid, null, password, null); + + ConnectionManager.ConnectionError.Source? error = yield stream_interactor.get_module(Register.IDENTITY).add_check_account(account); + sign_in_continue_spinner.visible = false; + sign_in_continue_button.sensitive = true; + + if (error != null) { + sign_in_error_label.visible = true; + switch (error) { + case ConnectionManager.ConnectionError.Source.SASL: + sign_in_error_label.label = _("Wrong username or password"); + break; + default: + sign_in_error_label.label = _("Something went wrong"); + break; + } + } else { + add_activate_account(account); + show_success(account); + } } else { - jid_entry.sensitive = true; - if (server_status.error_flags != null) { - show_tls_error(login_jid.domainpart, server_status.error_flags); + // Only JID field was visible: Check if server exists + Register.ServerAvailabilityReturn server_status = yield Register.check_server_availability(login_jid); + sign_in_continue_spinner.visible = false; + sign_in_continue_button.sensitive = true; + if (server_status.available) { + password_group.visible = true; + password_entry.grab_focus(); + sign_in_serverlist_button.visible = false; } else { - sign_in_jid_error_label.label = _("Could not connect to %s").printf(login_jid.domainpart); + if (server_status.error_flags != null) { + show_tls_error(login_jid.domainpart, server_status.error_flags); + } else { + sign_in_error_label.visible = true; + sign_in_error_label.label = _("Could not connect to %s").printf(login_jid.domainpart); + } } } } catch (InvalidJidError e) { warning("Invalid address from interface allowed login: %s", e.message); - sign_in_jid_error_label.label = _("Invalid address"); - } - } - - private async void on_sign_in_password_continue_button_clicked() { - string password = password_entry.text; - Account account = new Account(login_jid, null, password, null); - - sign_in_password_continue_stack.visible_child_name = "spinner"; - ConnectionManager.ConnectionError.Source? error = yield stream_interactor.get_module(Register.IDENTITY).add_check_account(account); - sign_in_password_continue_stack.visible_child_name = "label"; - - if (error != null) { - switch (error) { - case ConnectionManager.ConnectionError.Source.SASL: - sign_in_password_error_label.label = _("Wrong username or password"); - break; - default: - sign_in_password_error_label.label = _("Something went wrong"); - break; - } - } else { - add_activate_account(account); - show_success(account); + sign_in_error_label.visible = true; + sign_in_error_label.label = _("Invalid address"); } } @@ -311,12 +277,12 @@ public class AddAccountDialog : Gtk.Dialog { } private async void request_show_register_form(Jid server_jid) { - select_server_continue_stack.visible_child_name = "spinner"; + select_server_continue_spinner.visible = true; Register.RegistrationFormReturn form_return = yield Register.get_registration_form(server_jid); - if (select_server_continue_stack == null) { + if (select_server_continue_spinner == null) { return; } - select_server_continue_stack.visible_child_name = "label"; + select_server_continue_spinner.visible = false; if (form_return.form != null) { form = form_return.form; set_register_form(server_jid, form); @@ -335,7 +301,7 @@ public class AddAccountDialog : Gtk.Dialog { widget = form_box.get_first_child(); } - register_title.label = _("Register on %s").printf(server.to_string()); + this.title = _("Register on %s").printf(server.to_string()); if (form.oob != null) { form_box.append(new Label(_("The server requires to sign up through a website"))); @@ -346,20 +312,11 @@ public class AddAccountDialog : Gtk.Dialog { } else if (form.fields.size > 0) { if (form.instructions != null && form.instructions != "") { string markup_instructions = Util.parse_add_markup(form.instructions, null, true, false); - form_box.append(new Label(markup_instructions) { use_markup=true, halign=Align.CENTER, xalign=0, margin_top=7, + form_box.append(new Label(markup_instructions) { use_markup=true, xalign=0, margin_top=7, wrap=true, wrap_mode=Pango.WrapMode.WORD_CHAR }); } - foreach (Xep.DataForms.DataForm.Field field in form.fields) { - Widget? field_widget = Util.get_data_form_field_widget(field); - if (field.label != null && field.label != "" && field_widget != null) { - form_box.append(new Label(field.label) { xalign=0, margin_top=7 }); - form_box.append(field_widget); - } else if (field.type_ == Xep.DataForms.DataForm.Type.FIXED && field.get_value_string() != "") { - string markup_fixed_field = Util.parse_add_markup(field.get_value_string(), null, true, false); - form_box.append(new Label(markup_fixed_field) { use_markup=true, xalign=0, margin_top=7, - wrap=true, wrap_mode=Pango.WrapMode.WORD_CHAR }); - } - } + var form_preference_group = Util.rows_to_preference_group(Util.get_data_form_view_model(form), ""); + form_box.append(form_preference_group); register_form_continue.visible = true; register_form_continue_label.label = _("Register"); } else { @@ -375,16 +332,16 @@ public class AddAccountDialog : Gtk.Dialog { try { AppInfo.launch_default_for_uri(form.oob, null); } catch (Error e) { } - show_sign_in_jid(); + show_sign_in(); return; } - register_form_continue_stack.visible_child_name = "spinner"; + register_form_continue_spinner.visible = true; string? error = yield Register.submit_form(server_jid, form); - if (register_form_continue_stack == null) { + if (register_form_continue_spinner == null) { return; } - register_form_continue_stack.visible_child_name = "label"; + register_form_continue_spinner.visible = false; if (error == null) { string? username = null, password = null; foreach (Xep.DataForms.DataForm.Field field in form.fields) { @@ -422,20 +379,27 @@ public class AddAccountDialog : Gtk.Dialog { added(account); } - private void animate_window_resize(Widget widget) { // TODO code duplication - int curr_height = widget.get_size(Orientation.VERTICAL); - var natural_size = Requisition(); - stack.get_preferred_size(null, out natural_size); - int difference = natural_size.height + 5 - curr_height; - Timer timer = new Timer(); - Timeout.add((int) (stack.transition_duration / 30), () => { - ulong microsec; - timer.elapsed(out microsec); - ulong millisec = microsec / 1000; - double partial = double.min(1, (double) millisec / stack.transition_duration); - default_height = (int) (curr_height + difference * partial); - return millisec < stack.transition_duration; - }); + private void switch_stack_page(Page page) { + sign_in_box.visible = page == SIGN_IN; + sign_in_tls_box.visible = page == SIGN_IN_TLS_ERROR; + create_account_box.visible = page == CREATE_ACCOUNT_SELECT_SERVER; + register_box.visible = page == CREATE_ACCOUNT_REGISTER_FORM; + success_box.visible = page == SUCCESS; + + stack.visible_child_name = get_visible_stack_child_name(page); + + back_button.visible = page == CREATE_ACCOUNT_REGISTER_FORM; + } + + private string get_visible_stack_child_name(Page page) { + switch (page) { + case SIGN_IN: return "login_jid"; + case SIGN_IN_TLS_ERROR: return "tls_error"; + case CREATE_ACCOUNT_SELECT_SERVER: return "server"; + case CREATE_ACCOUNT_REGISTER_FORM: return "form"; + case SUCCESS: return "success"; + default: assert_not_reached(); + } } } diff --git a/main/src/ui/util/data_forms.vala b/main/src/ui/util/data_forms.vala index 39dce3ee..1b8d3271 100644 --- a/main/src/ui/util/data_forms.vala +++ b/main/src/ui/util/data_forms.vala @@ -5,6 +5,17 @@ using Dino.Entities; using Xmpp.Xep; namespace Dino.Ui.Util { + public static GLib.ListStore get_data_form_view_model(DataForms.DataForm data_form) { + var list_store = new GLib.ListStore(typeof(ViewModel.PreferencesRow.Any)); + + foreach (var field in data_form.fields) { + var field_view_model = Util.get_data_form_field_view_model(field); + if (field_view_model != null) { + list_store.append(field_view_model); + } + } + return list_store; + } public static ViewModel.PreferencesRow.Any? get_data_form_field_view_model(DataForms.DataForm.Field field) { if (field.type_ == null) return null; @@ -58,6 +69,11 @@ public static ViewModel.PreferencesRow.Any? get_data_form_field_view_model(DataF if (label == null) label = field.label; switch (field.type_) { + case DataForms.DataForm.Type.FIXED: + var fixed_field = field as DataForms.DataForm.FixedField; + var fixed_model = new ViewModel.PreferencesRow.Text() { text=fixed_field.value }; + view_model = fixed_model; + break; case DataForms.DataForm.Type.BOOLEAN: DataForms.DataForm.BooleanField boolean_field = field as DataForms.DataForm.BooleanField; var toggle_model = new ViewModel.PreferencesRow.Toggle() { subtitle = desc, state = boolean_field.value }; @@ -84,7 +100,11 @@ public static ViewModel.PreferencesRow.Any? get_data_form_field_view_model(DataF case DataForms.DataForm.Type.LIST_MULTI: return null; case DataForms.DataForm.Type.TEXT_PRIVATE: - return null; + DataForms.DataForm.TextPrivateField text_private_field = field as DataForms.DataForm.TextPrivateField; + var private_entry_model = new ViewModel.PreferencesRow.PrivateText() { text = text_private_field.value }; + text_private_field.bind_property("value", private_entry_model, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + view_model = private_entry_model; + break; case DataForms.DataForm.Type.TEXT_SINGLE: DataForms.DataForm.TextSingleField text_single_field = field as DataForms.DataForm.TextSingleField; var entry_model = new ViewModel.PreferencesRow.Entry() { text = text_single_field.value }; @@ -98,47 +118,4 @@ public static ViewModel.PreferencesRow.Any? get_data_form_field_view_model(DataF view_model.title = label; return view_model; } - -public static Widget? get_data_form_field_widget(DataForms.DataForm.Field field) { - if (field.type_ == null) return null; - switch (field.type_) { - case DataForms.DataForm.Type.BOOLEAN: - DataForms.DataForm.BooleanField boolean_field = field as DataForms.DataForm.BooleanField; - Switch sw = new Switch() { active=boolean_field.value, halign=Align.START, valign=Align.CENTER }; - sw.state_set.connect((state) => { - boolean_field.value = state; - return false; - }); - return sw; - case DataForms.DataForm.Type.JID_MULTI: - return null; - case DataForms.DataForm.Type.LIST_SINGLE: - DataForms.DataForm.ListSingleField list_single_field = field as DataForms.DataForm.ListSingleField; - ComboBoxText combobox = new ComboBoxText() { valign=Align.CENTER }; - for (int i = 0; i < list_single_field.options.size; i++) { - DataForms.DataForm.Option option = list_single_field.options[i]; - combobox.append(option.value, option.label); - if (option.value == list_single_field.value) combobox.active = i; - } - combobox.changed.connect(() => { - list_single_field.value = combobox.get_active_id(); - }); - return combobox; - case DataForms.DataForm.Type.LIST_MULTI: - return null; - case DataForms.DataForm.Type.TEXT_PRIVATE: - DataForms.DataForm.TextPrivateField text_private_field = field as DataForms.DataForm.TextPrivateField; - PasswordEntry entry = new PasswordEntry() { text=text_private_field.value ?? "", valign=Align.CENTER }; - entry.changed.connect(() => { text_private_field.value = entry.text; }); - return entry; - case DataForms.DataForm.Type.TEXT_SINGLE: - DataForms.DataForm.TextSingleField text_single_field = field as DataForms.DataForm.TextSingleField; - Entry entry = new Entry() { text=text_single_field.value ?? "", valign=Align.CENTER }; - entry.changed.connect(() => { text_single_field.value = entry.text; }); - return entry; - default: - return null; - } -} - } diff --git a/main/src/ui/util/preference_group.vala b/main/src/ui/util/preference_group.vala new file mode 100644 index 00000000..8f3a34f3 --- /dev/null +++ b/main/src/ui/util/preference_group.vala @@ -0,0 +1,106 @@ +using Gee; +using Gtk; + +using Dino.Entities; +using Xmpp.Xep; + +namespace Dino.Ui.Util { + public Adw.PreferencesGroup rows_to_preference_group(GLib.ListStore row_view_models, string title) { + var preference_group = new Adw.PreferencesGroup() { title=title }; + + for (int preference_group_i = 0; preference_group_i < row_view_models.get_n_items(); preference_group_i++) { + var preferences_row = (ViewModel.PreferencesRow.Any) row_view_models.get_item(preference_group_i); + + Widget? w = null; + + var entry_view_model = preferences_row as ViewModel.PreferencesRow.Entry; + if (entry_view_model != null) { + Adw.EntryRow view = new Adw.EntryRow() { title = entry_view_model.title, show_apply_button=true }; + entry_view_model.bind_property("text", view, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL, (_, from, ref to) => { + var str = (string) from; + to = str ?? ""; + return true; + }); + view.apply.connect(() => { + entry_view_model.changed(); + }); + w = view; + } + + var password_view_model = preferences_row as ViewModel.PreferencesRow.PrivateText; + if (password_view_model != null) { + Adw.PasswordEntryRow view = new Adw.PasswordEntryRow() { title = password_view_model.title, show_apply_button=true }; + password_view_model.bind_property("text", view, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL, (_, from, ref to) => { + var str = (string) from; + to = str ?? ""; + return true; + }); + view.apply.connect(() => { + password_view_model.changed(); + }); + + w = view; + } + + var row_text = preferences_row as ViewModel.PreferencesRow.Text; + if (row_text != null) { + w = new Adw.ActionRow() { + title = row_text.title, + subtitle = row_text.text, +#if Adw_1_3 + subtitle_selectable = true, +#endif + }; + w.add_css_class("property"); + + Util.force_css(w, "row.property > box.header > box.title > .title { font-weight: 400; font-size: 9pt; opacity: 0.55; }"); + Util.force_css(w, "row.property > box.header > box.title > .subtitle { font-size: inherit; opacity: 1; }"); + } + + var toggle_view_model = preferences_row as ViewModel.PreferencesRow.Toggle; + if (toggle_view_model != null) { + var view = new Adw.ActionRow() { title = toggle_view_model.title, subtitle = toggle_view_model.subtitle }; + var toggle = new Switch() { valign = Align.CENTER }; + view.activatable_widget = toggle; + view.add_suffix(toggle); + toggle_view_model.bind_property("state", toggle, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + w = view; + } + + var combobox_view_model = preferences_row as ViewModel.PreferencesRow.ComboBox; + if (combobox_view_model != null) { + var string_list = new StringList(null); + foreach (string text in combobox_view_model.items) { + string_list.append(text); + } +#if Adw_1_4 + var view = new Adw.ComboRow() { title = combobox_view_model.title }; + view.model = string_list; + combobox_view_model.bind_property("active-item", view, "selected", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); +#else + var view = new Adw.ActionRow() { title = combobox_view_model.title }; + var drop_down = new DropDown(string_list, null) { valign = Align.CENTER }; + combobox_view_model.bind_property("active-item", drop_down, "selected", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + view.activatable_widget = drop_down; + view.add_suffix(drop_down); +#endif + w = view; + } + + var widget_view_model = preferences_row as ViewModel.PreferencesRow.WidgetDeprecated; + if (widget_view_model != null) { + var view = new Adw.ActionRow() { title = widget_view_model.title }; + view.add_suffix(widget_view_model.widget); + w = view; + } + + if (w == null) { + continue; + } + + preference_group.add(w); + } + + return preference_group; + } +}
\ No newline at end of file diff --git a/main/src/view_model/preferences_row.vala b/main/src/view_model/preferences_row.vala index 3a04ee1e..624be6e6 100644 --- a/main/src/view_model/preferences_row.vala +++ b/main/src/view_model/preferences_row.vala @@ -18,6 +18,11 @@ namespace Dino.Ui.ViewModel.PreferencesRow { public string text { get; set; } } + public class PrivateText : Any { + public signal void changed(); + public string text { get; set; } + } + public class Toggle : Any { public string subtitle { get; set; } public bool state { get; set; } diff --git a/main/src/windows/conversation_details.vala b/main/src/windows/conversation_details.vala index 7ffa01f1..c2484db8 100644 --- a/main/src/windows/conversation_details.vala +++ b/main/src/windows/conversation_details.vala @@ -153,112 +153,17 @@ namespace Dino.Ui.ConversationDetails { } if (model.about_rows.get_n_items() > 0) { - about_box.append(rows_to_preference_group(model.about_rows, _("About"))); + about_box.append(Util.rows_to_preference_group(model.about_rows, _("About"))); } if (model.encryption_rows.get_n_items() > 0) { - about_box.append(rows_to_preference_group(model.encryption_rows, _("Encryption"))); + about_box.append(Util.rows_to_preference_group(model.encryption_rows, _("Encryption"))); } if (model.settings_rows.get_n_items() > 0) { - about_box.append(rows_to_preference_group(model.settings_rows, _("Settings"))); + about_box.append(Util.rows_to_preference_group(model.settings_rows, _("Settings"))); } if (model.room_configuration_rows != null && model.room_configuration_rows.get_n_items() > 0) { - about_box.append(rows_to_preference_group(model.room_configuration_rows, _("Room Configuration"))); + about_box.append(Util.rows_to_preference_group(model.room_configuration_rows, _("Room Configuration"))); } } - - private Adw.PreferencesGroup rows_to_preference_group(GLib.ListStore row_view_models, string title) { - var preference_group = new Adw.PreferencesGroup() { title=title }; - - for (int preference_group_i = 0; preference_group_i < row_view_models.get_n_items(); preference_group_i++) { - var preferences_row = (ViewModel.PreferencesRow.Any) row_view_models.get_item(preference_group_i); - - Widget? w = null; - - var entry_view_model = preferences_row as ViewModel.PreferencesRow.Entry; - if (entry_view_model != null) { -#if Adw_1_2 - Adw.EntryRow view = new Adw.EntryRow() { title = entry_view_model.title, show_apply_button=true }; - entry_view_model.bind_property("text", view, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL, (_, from, ref to) => { - var str = (string) from; - to = str ?? ""; - return true; - }); - view.apply.connect(() => { - entry_view_model.changed(); - }); -#else - var view = new Adw.ActionRow() { title = entry_view_model.title }; - var entry = new Entry() { text=entry_view_model.text, valign=Align.CENTER }; - entry_view_model.bind_property("text", entry, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); - entry.changed.connect(() => { - entry_view_model.changed(); - }); - view.activatable_widget = entry; - view.add_suffix(entry); -#endif - w = view; - } - - var row_text = preferences_row as ViewModel.PreferencesRow.Text; - if (row_text != null) { - w = new Adw.ActionRow() { - title = row_text.title, - subtitle = row_text.text, -#if Adw_1_3 - subtitle_selectable = true -#endif - }; - w.add_css_class("property"); - - Util.force_css(w, "row.property > box.header > box.title > .title { font-weight: 400; font-size: 9pt; opacity: 0.55; }"); - Util.force_css(w, "row.property > box.header > box.title > .subtitle { font-size: inherit; opacity: 1; }"); - } - - var toggle_view_model = preferences_row as ViewModel.PreferencesRow.Toggle; - if (toggle_view_model != null) { - var view = new Adw.ActionRow() { title = toggle_view_model.title, subtitle = toggle_view_model.subtitle }; - var toggle = new Switch() { valign = Align.CENTER }; - view.activatable_widget = toggle; - view.add_suffix(toggle); - toggle_view_model.bind_property("state", toggle, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); - w = view; - } - - var combobox_view_model = preferences_row as ViewModel.PreferencesRow.ComboBox; - if (combobox_view_model != null) { - var string_list = new StringList(null); - foreach (string text in combobox_view_model.items) { - string_list.append(text); - } -#if Adw_1_4 - var view = new Adw.ComboRow() { title = combobox_view_model.title }; - view.model = string_list; - combobox_view_model.bind_property("active-item", view, "selected", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); -#else - var view = new Adw.ActionRow() { title = combobox_view_model.title }; - var drop_down = new DropDown(string_list, null) { valign = Align.CENTER }; - combobox_view_model.bind_property("active-item", drop_down, "selected", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); - view.activatable_widget = drop_down; - view.add_suffix(drop_down); -#endif - w = view; - } - - var widget_view_model = preferences_row as ViewModel.PreferencesRow.WidgetDeprecated; - if (widget_view_model != null) { - var view = new Adw.ActionRow() { title = widget_view_model.title }; - view.add_suffix(widget_view_model.widget); - w = view; - } - - if (w == null) { - continue; - } - - preference_group.add(w); - } - - return preference_group; - } } } |