aboutsummaryrefslogtreecommitdiff
path: root/main/src/windows/preferences_window
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/windows/preferences_window')
-rw-r--r--main/src/windows/preferences_window/account_preferences_subpage.vala263
-rw-r--r--main/src/windows/preferences_window/accounts_preferences_page.vala75
-rw-r--r--main/src/windows/preferences_window/add_account_dialog.vala406
-rw-r--r--main/src/windows/preferences_window/change_password_dialog.vala66
-rw-r--r--main/src/windows/preferences_window/encryption_preferences_page.vala72
-rw-r--r--main/src/windows/preferences_window/general_preferences_page.vala39
-rw-r--r--main/src/windows/preferences_window/preferences_window.vala29
7 files changed, 950 insertions, 0 deletions
diff --git a/main/src/windows/preferences_window/account_preferences_subpage.vala b/main/src/windows/preferences_window/account_preferences_subpage.vala
new file mode 100644
index 00000000..1a7d5696
--- /dev/null
+++ b/main/src/windows/preferences_window/account_preferences_subpage.vala
@@ -0,0 +1,263 @@
+using Dino.Entities;
+using Xmpp;
+using Xmpp.Xep;
+using Gee;
+using Gtk;
+using Gdk;
+
+[GtkTemplate (ui = "/im/dino/Dino/preferences_window/account_preferences_subpage.ui")]
+public class Dino.Ui.AccountPreferencesSubpage : Gtk.Box {
+
+ [GtkChild] public unowned Adw.HeaderBar headerbar;
+ [GtkChild] public unowned Button back_button;
+ [GtkChild] public unowned AvatarPicture avatar;
+ [GtkChild] public unowned Adw.ActionRow xmpp_address;
+ [GtkChild] public unowned Adw.EntryRow local_alias;
+ [GtkChild] public unowned Adw.ActionRow password_change;
+ [GtkChild] public unowned Adw.ActionRow connection_status;
+ [GtkChild] public unowned Button enter_password_button;
+ [GtkChild] public unowned Box avatar_menu_box;
+ [GtkChild] public unowned Button edit_avatar_button;
+ [GtkChild] public unowned Button remove_avatar_button;
+ [GtkChild] public unowned Widget button_container;
+ [GtkChild] public unowned Button remove_account_button;
+ [GtkChild] public unowned Button disable_account_button;
+
+ public Account account { get { return model.selected_account.account; } }
+ public ViewModel.PreferencesWindow model { get; set; }
+
+ private Binding[] bindings = new Binding[0];
+ private ulong[] account_notify_ids = new ulong[0];
+ private ulong alias_entry_changed = 0;
+
+ construct {
+#if Adw_1_4
+ headerbar.show_title = false;
+#endif
+ button_container.layout_manager = new NaturalDirectionBoxLayout((BoxLayout)button_container.layout_manager);
+ back_button.clicked.connect(() => {
+ var window = (Adw.PreferencesWindow) this.get_root();
+ window.close_subpage();
+ });
+ edit_avatar_button.clicked.connect(() => {
+ show_select_avatar();
+ });
+ remove_avatar_button.clicked.connect(() => {
+ model.remove_avatar(account);
+ });
+ disable_account_button.clicked.connect(() => {
+ model.enable_disable_account(account);
+ });
+ remove_account_button.clicked.connect(() => {
+ show_remove_account_dialog();
+ });
+ password_change.activatable_widget = new Label("");
+ password_change.activated.connect(() => {
+ var dialog = new ChangePasswordDialog(model.get_change_password_dialog_model());
+ dialog.set_transient_for((Gtk.Window)this.get_root());
+ dialog.present();
+ });
+ enter_password_button.clicked.connect(() => {
+ var dialog = new Adw.MessageDialog((Window)this.get_root(), "Enter password for %s".printf(account.bare_jid.to_string()), null);
+ var password = new PasswordEntry() { show_peek_icon=true };
+ dialog.response.connect((response) => {
+ if (response == "connect") {
+ account.password = password.text;
+ model.reconnect_account(account);
+ }
+ });
+ dialog.set_default_response("connect");
+ dialog.set_extra_child(password);
+ dialog.add_response("cancel", _("Cancel"));
+ dialog.add_response("connect", _("Connect"));
+
+ dialog.present();
+ });
+
+ this.notify["model"].connect(() => {
+ model.notify["selected-account"].connect(() => {
+ foreach (var binding in bindings) {
+ binding.unbind();
+ }
+
+ avatar.model = model.selected_account.avatar_model;
+ xmpp_address.subtitle = account.bare_jid.to_string();
+
+ if (alias_entry_changed != 0) local_alias.disconnect(alias_entry_changed);
+ local_alias.text = account.alias ?? "";
+ alias_entry_changed = local_alias.changed.connect(() => {
+ account.alias = local_alias.text;
+ });
+
+ bindings += account.bind_property("enabled", disable_account_button, "label", BindingFlags.SYNC_CREATE, (binding, from, ref to) => {
+ bool enabled_bool = (bool) from;
+ to = enabled_bool ? _("Disable account") : _("Enable account");
+ return true;
+ });
+ bindings += account.bind_property("enabled", avatar_menu_box, "visible", BindingFlags.SYNC_CREATE);
+ bindings += account.bind_property("enabled", password_change, "visible", BindingFlags.SYNC_CREATE);
+ bindings += account.bind_property("enabled", connection_status, "visible", BindingFlags.SYNC_CREATE);
+ bindings += model.selected_account.bind_property("connection-state", connection_status, "subtitle", BindingFlags.SYNC_CREATE, (binding, from, ref to) => {
+ to = get_status_label();
+ return true;
+ });
+ bindings += model.selected_account.bind_property("connection-error", connection_status, "subtitle", BindingFlags.SYNC_CREATE, (binding, from, ref to) => {
+ to = get_status_label();
+ return true;
+ });
+ bindings += model.selected_account.bind_property("connection-error", enter_password_button, "visible", BindingFlags.SYNC_CREATE, (binding, from, ref to) => {
+ var error = (ConnectionManager.ConnectionError) from;
+ to = error != null && error.source == ConnectionManager.ConnectionError.Source.SASL;
+ return true;
+ });
+
+ // Only show avatar removal button if an avatar is set
+ var avatar_model = model.selected_account.avatar_model.tiles.get_item(0) as ViewModel.AvatarPictureTileModel;
+ avatar_model.notify["image-file"].connect(() => {
+ remove_avatar_button.visible = avatar_model.image_file != null;
+ });
+ remove_avatar_button.visible = avatar_model.image_file != null;
+
+ model.selected_account.notify["connection-error"].connect(() => {
+ if (model.selected_account.connection_error != null) {
+ connection_status.add_css_class("error");
+ } else {
+ connection_status.remove_css_class("error");
+ }
+ });
+ if (model.selected_account.connection_error != null) {
+ connection_status.add_css_class("error");
+ } else {
+ connection_status.remove_css_class("error");
+ }
+ });
+ });
+ }
+
+ private void show_select_avatar() {
+ FileChooserNative chooser = new FileChooserNative(_("Select avatar"), (Window)this.get_root(), FileChooserAction.OPEN, _("Select"), _("Cancel"));
+ FileFilter filter = new FileFilter();
+ foreach (PixbufFormat pixbuf_format in Pixbuf.get_formats()) {
+ foreach (string mime_type in pixbuf_format.get_mime_types()) {
+ filter.add_mime_type(mime_type);
+ }
+ }
+ filter.set_filter_name(_("Images"));
+ chooser.add_filter(filter);
+
+ filter = new FileFilter();
+ filter.set_filter_name(_("All files"));
+ filter.add_pattern("*");
+ chooser.add_filter(filter);
+
+ chooser.response.connect(() => {
+ string uri = chooser.get_file().get_path();
+ model.set_avatar_uri(account, uri);
+ });
+
+ chooser.show();
+ }
+
+ private void show_remove_account_dialog() {
+ Adw.MessageDialog dialog = new Adw.MessageDialog (
+ (Window)this.get_root(),
+ _("Remove account %s?".printf(account.bare_jid.to_string())),
+ "You won't be able to access your conversation history anymore."
+ );
+ // TODO remove history!
+ dialog.add_response("cancel", "Cancel");
+ dialog.add_response("remove", "Remove");
+ dialog.set_response_appearance("remove", Adw.ResponseAppearance.DESTRUCTIVE);
+ dialog.response.connect((response) => {
+ if (response == "remove") {
+ model.remove_account(account);
+ // Close the account subpage
+ var window = (Adw.PreferencesWindow) this.get_root();
+ window.close_subpage();
+// window.pop_subpage();
+ }
+ dialog.close();
+ });
+ dialog.present();
+ }
+
+ private string get_status_label() {
+ string? error_label = get_connection_error_description();
+ if (error_label != null) return error_label;
+
+ ConnectionManager.ConnectionState state = model.selected_account.connection_state;
+ switch (state) {
+ case ConnectionManager.ConnectionState.CONNECTING:
+ return _("Connecting…");
+ case ConnectionManager.ConnectionState.CONNECTED:
+ return _("Connected");
+ case ConnectionManager.ConnectionState.DISCONNECTED:
+ return _("Disconnected");
+ }
+ assert_not_reached();
+ }
+
+ private string? get_connection_error_description() {
+ ConnectionManager.ConnectionError? error = model.selected_account.connection_error;
+ if (error == null) return null;
+
+ switch (error.source) {
+ case ConnectionManager.ConnectionError.Source.SASL:
+ return _("Wrong password");
+ case ConnectionManager.ConnectionError.Source.TLS:
+ return _("Invalid TLS certificate");
+ }
+ if (error.identifier != null) {
+ return _("Error") + ": " + error.identifier;
+ } else {
+ return _("Error");
+ }
+ }
+}
+
+public class Dino.Ui.NaturalDirectionBoxLayout : LayoutManager {
+ private BoxLayout original;
+ private BoxLayout alternative;
+
+ public NaturalDirectionBoxLayout(BoxLayout original) {
+ this.original = original;
+ if (original.orientation == Orientation.HORIZONTAL) {
+ this.alternative = new BoxLayout(Orientation.VERTICAL);
+ this.alternative.spacing = this.original.spacing / 2;
+ }
+ }
+
+ public override SizeRequestMode get_request_mode(Widget widget) {
+ return original.orientation == Orientation.HORIZONTAL ? SizeRequestMode.HEIGHT_FOR_WIDTH : SizeRequestMode.WIDTH_FOR_HEIGHT;
+ }
+
+ public override void allocate(Widget widget, int width, int height, int baseline) {
+ int blind_minimum, blind_natural, blind_minimum_baseline, blind_natural_baseline;
+ original.measure(widget, original.orientation, -1, out blind_minimum, out blind_natural, out blind_minimum_baseline, out blind_natural_baseline);
+ int for_size = (original.orientation == Orientation.HORIZONTAL ? width : height);
+ if (for_size >= blind_minimum) {
+ original.allocate(widget, width, height, baseline);
+ } else {
+ alternative.allocate(widget, width, height, baseline);
+ }
+ }
+
+ public override void measure(Widget widget, Orientation orientation, int for_size, out int minimum, out int natural, out int minimum_baseline, out int natural_baseline) {
+ if (for_size == -1) {
+ original.measure(widget, orientation, -1, out minimum, out natural, out minimum_baseline, out natural_baseline);
+ int alt_minimum, alt_natural, alt_minimum_baseline, alt_natural_baseline;
+ alternative.measure(widget, orientation, -1, out alt_minimum, out alt_natural, out alt_minimum_baseline, out alt_natural_baseline);
+ if (alt_minimum < minimum && alt_minimum != -1) minimum = alt_minimum;
+ if (alt_minimum_baseline < minimum_baseline && alt_minimum_baseline != -1) minimum = alt_minimum_baseline;
+ } else {
+ Orientation other_orientation = orientation == Orientation.HORIZONTAL ? Orientation.VERTICAL : Orientation.HORIZONTAL;
+ int blind_minimum, blind_natural, blind_minimum_baseline, blind_natural_baseline;
+ original.measure(widget, other_orientation, -1, out blind_minimum, out blind_natural, out blind_minimum_baseline, out blind_natural_baseline);
+ if (for_size >= blind_minimum) {
+ original.measure(widget, orientation, for_size, out minimum, out natural, out minimum_baseline, out natural_baseline);
+ } else {
+ alternative.measure(widget, orientation, for_size, out minimum, out natural, out minimum_baseline, out natural_baseline);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/main/src/windows/preferences_window/accounts_preferences_page.vala b/main/src/windows/preferences_window/accounts_preferences_page.vala
new file mode 100644
index 00000000..7f4c2f1b
--- /dev/null
+++ b/main/src/windows/preferences_window/accounts_preferences_page.vala
@@ -0,0 +1,75 @@
+using Dino.Entities;
+using Gee;
+using Gtk;
+
+public class Dino.Ui.PreferencesWindowAccounts : Adw.PreferencesPage {
+
+ public signal void account_chosen(Account account);
+
+ public Adw.PreferencesGroup active_accounts;
+ public Adw.PreferencesGroup disabled_accounts;
+
+ public ViewModel.PreferencesWindow model { get; set; }
+
+ construct {
+ this.title = _("Accounts");
+ this.icon_name = "system-users-symbolic";
+
+ this.notify["model"].connect(() => {
+ model.update.connect(refresh);
+ });
+ }
+
+ private void refresh() {
+ if (active_accounts != null) this.remove(active_accounts);
+ if (disabled_accounts != null) this.remove(disabled_accounts);
+
+ active_accounts = new Adw.PreferencesGroup() { title=_("Accounts")};
+ disabled_accounts = new Adw.PreferencesGroup() { title=_("Disabled accounts")};
+ Button add_account_button = new Button.from_icon_name("list-add-symbolic");
+ add_account_button.add_css_class("flat");
+ add_account_button.tooltip_text = _("Add Account");
+ active_accounts.header_suffix = add_account_button;
+
+ this.add(active_accounts);
+ this.add(disabled_accounts);
+
+ add_account_button.clicked.connect(() => {
+ Ui.ManageAccounts.AddAccountDialog add_account_dialog = new Ui.ManageAccounts.AddAccountDialog(model.stream_interactor, model.db);
+ add_account_dialog.set_transient_for((Window)this.get_root());
+ add_account_dialog.added.connect((account) => {
+ refresh();
+ });
+ add_account_dialog.present();
+ });
+
+ disabled_accounts.visible = false; // Only display disabled section if it contains accounts
+ var enabled_account_added = false;
+
+ foreach (ViewModel.AccountDetails account_details in model.account_details.values) {
+ var row = new Adw.ActionRow() {
+ title = account_details.bare_jid.to_string()
+ };
+ row.add_prefix(new AvatarPicture() { valign=Align.CENTER, height_request=35, width_request=35, model = account_details.avatar_model });
+ row.add_suffix(new Image.from_icon_name("go-next-symbolic"));
+ row.activatable = true;
+
+ if (account_details.account.enabled) {
+ active_accounts.add(row);
+ enabled_account_added = true;
+ } else {
+ disabled_accounts.add(row);
+ disabled_accounts.visible = true;
+ }
+
+ row.activated.connect(() => {
+ account_chosen(account_details.account);
+ });
+ }
+
+ // We always have to show the active accounts group for the add new button. Display placeholder if there are no active accounts
+ if (!enabled_account_added) {
+ active_accounts.add(new Adw.ActionRow() { title=_("No active accounts") });
+ }
+ }
+}
diff --git a/main/src/windows/preferences_window/add_account_dialog.vala b/main/src/windows/preferences_window/add_account_dialog.vala
new file mode 100644
index 00000000..00acb6aa
--- /dev/null
+++ b/main/src/windows/preferences_window/add_account_dialog.vala
@@ -0,0 +1,406 @@
+using Gee;
+using Gtk;
+using Pango;
+
+using Dino.Entities;
+using Xmpp;
+
+namespace Dino.Ui.ManageAccounts {
+
+[GtkTemplate (ui = "/im/dino/Dino/preferences_window/add_account_dialog.ui")]
+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_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 Button sign_in_tls_back_button;
+
+ // Select Server
+ [GtkChild] private unowned Box create_account_box;
+ [GtkChild] private unowned Button login_button;
+ [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 Box form_box;
+ [GtkChild] private unowned Spinner register_form_continue_spinner;
+ [GtkChild] private unowned Button register_form_continue;
+
+ // Success
+ [GtkChild] private unowned Box success_box;
+ [GtkChild] private unowned Label success_description;
+ [GtkChild] private unowned Button success_continue_button;
+
+ private static string[] server_list = new string[]{
+ "5222.de",
+ "jabber.fr",
+ "movim.eu",
+ "yax.im"
+ };
+
+ private StreamInteractor stream_interactor;
+ private Database db;
+ private HashMap<ListBoxRow, string> list_box_jids = new HashMap<ListBoxRow, string>();
+ private Jid? server_jid = null;
+ private Jid? login_jid = null;
+ private Xep.InBandRegistration.Form? form = null;
+
+ public AddAccountDialog(StreamInteractor stream_interactor, Database db) {
+ this.stream_interactor = stream_interactor;
+ this.db = db;
+ this.title = _("Add Account");
+
+ // Sign in - Jid
+ jid_entry.changed.connect(on_jid_entry_changed);
+ 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() );
+
+ // Select Server
+ server_entry.changed.connect(() => {
+ try {
+ Jid jid = new Jid(server_entry.text);
+ select_server_continue.sensitive = jid != null && jid.localpart == null && jid.resourcepart == null;
+ } catch (InvalidJidError e) {
+ select_server_continue.sensitive = false;
+ }
+ });
+ select_server_continue.clicked.connect(on_select_server_continue);
+ login_button.clicked.connect(() => show_sign_in() );
+
+ foreach (string server in server_list) {
+ ListBoxRow list_box_row = new ListBoxRow();
+ list_box_row.set_child(new Label(server) { xalign=0, margin_start=7, margin_end=7 });
+ list_box_jids[list_box_row] = server;
+ server_list_box.append(list_box_row);
+ }
+
+ // Register Form
+ register_form_continue.clicked.connect(on_register_form_continue_clicked);
+ back_button.clicked.connect(() => {
+ show_select_server();
+ back_button.visible = false;
+ });
+
+ // Success
+ success_continue_button.clicked.connect(() => close());
+
+ show_sign_in();
+ }
+
+ 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) {
+ 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) {
+ error_desc += " " + _("Its security certificate is not trusted by your operating system.");
+ } else if (TlsCertificateFlags.BAD_IDENTITY in error_flags) {
+ error_desc += " " + _("Its security certificate is issued to another domain.");
+ } else if (TlsCertificateFlags.NOT_ACTIVATED in error_flags) {
+ error_desc += " " + _("Its security certificate will only become valid in the future.");
+ } else if (TlsCertificateFlags.EXPIRED in error_flags) {
+ error_desc += " " + _("Its security certificate is expired.");
+ }
+ sign_in_tls_label.label = error_desc;
+ }
+
+ 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);
+
+ 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);
+ }
+
+ private void show_register_form() {
+ switch_stack_page(Page.CREATE_ACCOUNT_REGISTER_FORM);
+
+ set_default_widget(register_form_continue);
+ }
+
+ private void show_success(Account account) {
+ 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);
+ }
+
+ private void on_jid_entry_changed() {
+ try {
+ login_jid = new Jid(jid_entry.text);
+ if (login_jid.localpart != null && login_jid.resourcepart == null) {
+ sign_in_continue_button.sensitive = true;
+ } else {
+ sign_in_continue_button.sensitive = false;
+ }
+ } catch (InvalidJidError e) {
+ sign_in_continue_button.sensitive = false;
+ }
+ }
+
+ private async void on_sign_in_continue_button_clicked() {
+ try {
+ login_jid = new Jid(jid_entry.text);
+ sign_in_tls_label.label = "";
+ 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 {
+ // 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 {
+ 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_error_label.visible = true;
+ sign_in_error_label.label = _("Invalid address");
+ }
+ }
+
+ private void on_select_server_continue() {
+ try {
+ server_jid = new Jid(server_entry.text);
+ request_show_register_form.begin(server_jid);
+ } catch (InvalidJidError e) {
+ warning("Invalid address from interface allowed server: %s", e.message);
+ display_notification(_("Invalid address"));
+ }
+ }
+
+ private void on_server_list_row_activated(ListBox box, ListBoxRow row) {
+ try {
+ server_jid = new Jid(list_box_jids[row]);
+ request_show_register_form.begin(server_jid);
+ } catch (InvalidJidError e) {
+ warning("Invalid address from selected server: %s", e.message);
+ display_notification(_("Invalid address"));
+ }
+ }
+
+ private async void request_show_register_form(Jid server_jid) {
+ select_server_continue_spinner.visible = true;
+ Register.RegistrationFormReturn form_return = yield Register.get_registration_form(server_jid);
+ if (select_server_continue_spinner == null) {
+ return;
+ }
+ select_server_continue_spinner.visible = false;
+ if (form_return.form != null) {
+ form = form_return.form;
+ set_register_form(server_jid, form);
+ show_register_form();
+ } else if (form_return.error_flags != null) {
+ show_tls_error(server_jid.domainpart, form_return.error_flags);
+ } else {
+ display_notification(_("No response from server"));
+ }
+ }
+
+ private void set_register_form(Jid server, Xep.InBandRegistration.Form form) {
+ Widget widget = form_box.get_first_child();
+ while (widget != null) {
+ form_box.remove(widget);
+ widget = form_box.get_first_child();
+ }
+
+ 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")));
+ form_box.append(new Label(@"<a href=\"$(form.oob)\">$(form.oob)</a>") { use_markup=true });
+ register_form_continue_label.label = _("Open website");
+ register_form_continue.visible = true;
+ register_form_continue.grab_focus();
+ } 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, 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 {
+ form_box.append(new Label(_("Check %s for information on how to sign up").printf(@"<a href=\"http://$(server)\">$(server)</a>")) { use_markup=true });
+ register_form_continue.visible = false;
+ }
+ }
+
+ private async void on_register_form_continue_clicked() {
+ notification_revealer.set_reveal_child(false);
+ // Button is opening a registration website
+ if (form.oob != null) {
+ try {
+ AppInfo.launch_default_for_uri(form.oob, null);
+ } catch (Error e) { }
+ show_sign_in();
+ return;
+ }
+
+ register_form_continue_spinner.visible = true;
+ string? error = yield Register.submit_form(server_jid, form);
+ if (register_form_continue_spinner == null) {
+ return;
+ }
+ register_form_continue_spinner.visible = false;
+ if (error == null) {
+ string? username = null, password = null;
+ foreach (Xep.DataForms.DataForm.Field field in form.fields) {
+ switch (field.var) {
+ case "username": username = field.get_value_string(); break;
+ case "password": password = field.get_value_string(); break;
+ }
+ }
+ try {
+ Account account = new Account(new Jid.components(username, server_jid.domainpart, null), null, password, null);
+ add_activate_account(account);
+ show_success(account);
+ } catch (InvalidJidError e) {
+ warning("Invalid address from components of registration: %s", e.message);
+ display_notification(_("Invalid address"));
+ }
+ } else {
+ display_notification(error);
+ }
+ }
+
+ private void display_notification(string text) {
+ notification_label.label = text;
+ notification_revealer.set_reveal_child(true);
+ Timeout.add_seconds(5, () => {
+ notification_revealer.set_reveal_child(false);
+ return false;
+ });
+ }
+
+ private void add_activate_account(Account account) {
+ account.enabled = true;
+ account.persist(db);
+ stream_interactor.connect_account(account);
+ added(account);
+ }
+
+ 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/windows/preferences_window/change_password_dialog.vala b/main/src/windows/preferences_window/change_password_dialog.vala
new file mode 100644
index 00000000..f0c7dcf9
--- /dev/null
+++ b/main/src/windows/preferences_window/change_password_dialog.vala
@@ -0,0 +1,66 @@
+using Gee;
+using Gtk;
+
+using Dino.Entities;
+using Xmpp;
+
+namespace Dino.Ui{
+
+ [GtkTemplate (ui = "/im/dino/Dino/preferences_window/change_password_dialog.ui")]
+ public class ChangePasswordDialog : Gtk.Dialog {
+
+ [GtkChild] private unowned Button change_password_button;
+ [GtkChild] private unowned Stack change_password_stack;
+ [GtkChild] private unowned Button cancel_button;
+ [GtkChild] private unowned Adw.PasswordEntryRow current_password_entry;
+ [GtkChild] private unowned Adw.PasswordEntryRow new_password_entry;
+ [GtkChild] private unowned Adw.PasswordEntryRow confirm_new_password_entry;
+ [GtkChild] private unowned Label change_password_error_label;
+
+ private ViewModel.ChangePasswordDialog model;
+
+ public ChangePasswordDialog(ViewModel.ChangePasswordDialog model) {
+ Object(use_header_bar : 1);
+ this.model = model;
+
+ Util.force_error_color(change_password_error_label);
+ cancel_button.clicked.connect(() => { close(); });
+ current_password_entry.changed.connect(is_form_filled);
+ new_password_entry.changed.connect(is_form_filled);
+ confirm_new_password_entry.changed.connect(is_form_filled);
+ change_password_button.clicked.connect(on_change_password_button_clicked);
+ }
+
+ private void is_form_filled(){
+ if (current_password_entry.get_text().length > 0
+ && new_password_entry.get_text().length > 0
+ && confirm_new_password_entry.get_text().length > 0
+ && new_password_entry.get_text() == confirm_new_password_entry.get_text()){
+ change_password_button.sensitive = true;
+ } else {
+ change_password_button.sensitive = false;
+ }
+ }
+
+ private async void on_change_password_button_clicked(){
+ string? pw_input = current_password_entry.get_text();
+ string? new_pw_input = new_password_entry.get_text();
+
+ if (pw_input != null && model.account.password == pw_input){
+ change_password_button.sensitive = false;
+ change_password_stack.visible_child_name = "spinner";
+ string? ret = yield model.change_password(new_pw_input);
+ change_password_button.sensitive = true;
+ change_password_stack.visible_child_name = "label";
+ if (ret == null) {
+ close();
+ }
+
+ change_password_error_label.label = "Error: %s".printf(ret);
+
+ } else {
+ change_password_error_label.label = "Wrong current password";
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/main/src/windows/preferences_window/encryption_preferences_page.vala b/main/src/windows/preferences_window/encryption_preferences_page.vala
new file mode 100644
index 00000000..eec38908
--- /dev/null
+++ b/main/src/windows/preferences_window/encryption_preferences_page.vala
@@ -0,0 +1,72 @@
+using Dino.Entities;
+using Xmpp;
+using Xmpp.Xep;
+using Gee;
+using Gtk;
+
+public class Dino.Ui.PreferencesWindowEncryption : Adw.PreferencesPage {
+
+ private DropDown drop_down = null;
+ private Adw.PreferencesGroup accounts_group = new Adw.PreferencesGroup();
+ private ArrayList<Adw.PreferencesGroup> added_widgets = new ArrayList<Adw.PreferencesGroup>();
+
+ public ViewModel.PreferencesWindow model { get; set; }
+
+ construct {
+ this.add(accounts_group);
+
+ this.notify["model"].connect(() => {
+ this.model.update.connect(() => {
+ repopulate_account_selector();
+ });
+ });
+ }
+
+ private void repopulate_account_selector() {
+ // Remove current selector
+ if (drop_down != null) {
+ accounts_group.remove(drop_down);
+ drop_down = null;
+ }
+
+ // Don't show selector if the user has only one account (active + inactive)
+ accounts_group.visible = model.account_details.size != 1;
+
+ // Populate selector
+ if (model.active_accounts_selection.get_n_items() > 0) {
+ drop_down = new DropDown(model.active_accounts_selection, null) { halign=Align.CENTER };
+ drop_down.factory = new BuilderListItemFactory.from_resource(null, "/im/dino/Dino/account_picker_row.ui");
+
+ drop_down.notify["selected-item"].connect(() => {
+ var account_details = (ViewModel.AccountDetails) drop_down.selected_item;
+ if (account_details == null) return;
+ set_account(account_details.account);
+ });
+
+ drop_down.selected = 0;
+ set_account(((ViewModel.AccountDetails)model.active_accounts_selection.get_item(0)).account);
+ } else {
+ drop_down = new DropDown.from_strings(new string[] { _("No active accounts")}) { halign=Align.CENTER };
+ unset_account();
+ }
+ accounts_group.add(drop_down);
+ }
+
+ private void unset_account() {
+ foreach (var widget in added_widgets) {
+ this.remove(widget);
+ }
+ added_widgets.clear();
+ }
+
+ private void set_account(Account account) {
+ unset_account();
+
+ Application app = GLib.Application.get_default() as Application;
+ foreach (Plugins.EncryptionPreferencesEntry e in app.plugin_registry.encryption_preferences_entries) {
+ var widget = (Adw.PreferencesGroup) e.get_widget(account, Plugins.WidgetType.GTK4);
+ this.add(widget);
+ this.added_widgets.add(widget);
+ }
+ }
+} \ No newline at end of file
diff --git a/main/src/windows/preferences_window/general_preferences_page.vala b/main/src/windows/preferences_window/general_preferences_page.vala
new file mode 100644
index 00000000..6f8dd771
--- /dev/null
+++ b/main/src/windows/preferences_window/general_preferences_page.vala
@@ -0,0 +1,39 @@
+using Gtk;
+
+public class Dino.Ui.ViewModel.GeneralPreferencesPage : Object {
+ public bool send_typing { get; set; }
+ public bool send_marker { get; set; }
+ public bool notifications { get; set; }
+ public bool convert_emojis { get; set; }
+}
+
+[GtkTemplate (ui = "/im/dino/Dino/preferences_window/general_preferences_page.ui")]
+public class Dino.Ui.GeneralPreferencesPage : Adw.PreferencesPage {
+ [GtkChild] private unowned Switch typing_switch;
+ [GtkChild] private unowned Switch marker_switch;
+ [GtkChild] private unowned Switch notification_switch;
+ [GtkChild] private unowned Switch emoji_switch;
+
+ public ViewModel.GeneralPreferencesPage model { get; set; default = new ViewModel.GeneralPreferencesPage(); }
+ private Binding[] model_bindings = new Binding[0];
+
+ construct {
+ this.notify["model"].connect(on_model_changed);
+ }
+
+ private void on_model_changed() {
+ foreach (Binding binding in model_bindings) {
+ binding.unbind();
+ }
+ if (model != null) {
+ model_bindings = new Binding[] {
+ model.bind_property("send-typing", typing_switch, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL),
+ model.bind_property("send-marker", marker_switch, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL),
+ model.bind_property("notifications", notification_switch, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL),
+ model.bind_property("convert-emojis", emoji_switch, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL)
+ };
+ } else {
+ model_bindings = new Binding[0];
+ }
+ }
+}
diff --git a/main/src/windows/preferences_window/preferences_window.vala b/main/src/windows/preferences_window/preferences_window.vala
new file mode 100644
index 00000000..662a6924
--- /dev/null
+++ b/main/src/windows/preferences_window/preferences_window.vala
@@ -0,0 +1,29 @@
+using Gdk;
+using Dino.Entities;
+using Xmpp;
+using Xmpp.Xep;
+using Gee;
+using Gtk;
+
+[GtkTemplate (ui = "/im/dino/Dino/preferences_window/preferences_window.ui")]
+public class Dino.Ui.PreferencesWindow : Adw.PreferencesWindow {
+ [GtkChild] public unowned Dino.Ui.PreferencesWindowAccounts accounts_page;
+ [GtkChild] public unowned Dino.Ui.PreferencesWindowEncryption encryption_page;
+ [GtkChild] public unowned Dino.Ui.GeneralPreferencesPage general_page;
+ public Dino.Ui.AccountPreferencesSubpage account_page = new Dino.Ui.AccountPreferencesSubpage();
+
+ [GtkChild] public unowned ViewModel.PreferencesWindow model { get; }
+
+ construct {
+ this.can_navigate_back = true; // remove once we require Adw > 1.4
+ this.bind_property("model", accounts_page, "model", BindingFlags.SYNC_CREATE);
+ this.bind_property("model", account_page, "model", BindingFlags.SYNC_CREATE);
+ this.bind_property("model", encryption_page, "model", BindingFlags.SYNC_CREATE);
+
+ accounts_page.account_chosen.connect((account) => {
+ model.selected_account = model.account_details[account];
+ this.present_subpage(account_page);
+// this.present_subpage(new Adw.NavigationPage(account_page, "Account: %s".printf(account.bare_jid.to_string())));
+ });
+ }
+} \ No newline at end of file