diff options
Diffstat (limited to 'main/src/view_model')
-rw-r--r-- | main/src/view_model/account_details.vala | 21 | ||||
-rw-r--r-- | main/src/view_model/conversation_details.vala | 13 | ||||
-rw-r--r-- | main/src/view_model/preferences_window.vala | 109 |
3 files changed, 140 insertions, 3 deletions
diff --git a/main/src/view_model/account_details.vala b/main/src/view_model/account_details.vala new file mode 100644 index 00000000..a9ddeca5 --- /dev/null +++ b/main/src/view_model/account_details.vala @@ -0,0 +1,21 @@ +using Dino; +using Dino.Entities; +using Xmpp; +using Xmpp.Xep; + +public class Dino.Ui.ViewModel.AccountDetails : Object { + public Entities.Account account { get; set; } + public string bare_jid { owned get { return account.bare_jid.to_string(); } } + public CompatAvatarPictureModel avatar_model { get; set; } + public ConnectionManager.ConnectionState connection_state { get; set; } + public ConnectionManager.ConnectionError? connection_error { get; set; } + + public AccountDetails(Account account, StreamInteractor stream_interactor) { + var account_conv = new Conversation(account.bare_jid, account, Conversation.Type.CHAT); + + this.account = account; + this.avatar_model = new ViewModel.CompatAvatarPictureModel(stream_interactor).set_conversation(account_conv); + this.connection_state = stream_interactor.connection_manager.get_state(account); + this.connection_error = stream_interactor.connection_manager.get_error(account); + } +}
\ No newline at end of file diff --git a/main/src/view_model/conversation_details.vala b/main/src/view_model/conversation_details.vala index 15bf7535..75fc9669 100644 --- a/main/src/view_model/conversation_details.vala +++ b/main/src/view_model/conversation_details.vala @@ -6,10 +6,16 @@ using Gtk; public class Dino.Ui.ViewModel.ConversationDetails : Object { public signal void pin_changed(); - public signal void block_changed(); + public signal void block_changed(BlockState action); public signal void notification_flipped(); public signal void notification_changed(NotificationSetting setting); + public enum BlockState { + USER, + DOMAIN, + UNBLOCK + } + public enum NotificationOptions { ON_OFF, ON_HIGHLIGHT_OFF @@ -31,7 +37,7 @@ public class Dino.Ui.ViewModel.ConversationDetails : Object { public bool notification_is_default { get; set; } public bool show_blocked { get; set; } - public bool blocked { get; set; } + public BlockState blocked { get; set; } public GLib.ListStore preferences_rows = new GLib.ListStore(typeof(PreferencesRow.Any)); public GLib.ListStore about_rows = new GLib.ListStore(typeof(PreferencesRow.Any)); @@ -46,4 +52,5 @@ public class Dino.Ui.Model.ConversationDetails : Object { public DataForms.DataForm? data_form { get; set; } public string? data_form_bak; public bool blocked { get; set; } -}
\ No newline at end of file + public bool domain_blocked { get; set; } +} diff --git a/main/src/view_model/preferences_window.vala b/main/src/view_model/preferences_window.vala new file mode 100644 index 00000000..9cc5a80e --- /dev/null +++ b/main/src/view_model/preferences_window.vala @@ -0,0 +1,109 @@ +using Dino.Entities; +using Xmpp; +using Xmpp.Xep; +using Gee; + +public class Dino.Ui.ViewModel.PreferencesWindow : Object { + public signal void update(); + + public HashMap<Account, AccountDetails> account_details = new HashMap<Account, AccountDetails>(Account.hash_func, Account.equals_func); + public AccountDetails selected_account { get; set; } + public Gtk.SingleSelection active_accounts_selection { get; default=new Gtk.SingleSelection(new GLib.ListStore(typeof(ViewModel.AccountDetails))); } + + public StreamInteractor stream_interactor; + public Database db; + + public GeneralPreferencesPage general_page { get; set; default=new GeneralPreferencesPage(); } + + public void populate(Database db, StreamInteractor stream_interactor) { + this.db = db; + this.stream_interactor = stream_interactor; + + stream_interactor.connection_manager.connection_error.connect((account, error) => { + var account_detail = account_details[account]; + if (account_details != null) { + account_detail.connection_error = error; + } + }); + stream_interactor.connection_manager.connection_state_changed.connect((account, state) => { + var account_detail = account_details[account]; + if (account_details != null) { + account_detail.connection_state = state; + account_detail.connection_error = stream_interactor.connection_manager.get_error(account); + } + }); + stream_interactor.account_added.connect(update_data); + stream_interactor.account_removed.connect(update_data); + + bind_general_page(); + update_data(); + } + + private void update_data() { + // account_details should hold the correct set of accounts (add or remove some if needed), but do not override remaining ones (would destroy bindings) + var current_accounts = db.get_accounts(); + var remove_accounts = new ArrayList<Account>(); + foreach (var account in account_details.keys) { + if (!current_accounts.contains(account)) remove_accounts.add(account); + } + foreach (var account in remove_accounts) { + account_details.unset(account); + } + foreach (var account in current_accounts) { + if (!account_details.has_key(account)) { + account_details[account] = new AccountDetails(account, stream_interactor); + } + if (selected_account == null && account.enabled) selected_account = account_details[account]; + } + + // Update account picker model with currently active accounts + var list_model = (GLib.ListStore) active_accounts_selection.model; + list_model.remove_all(); + foreach (var account in stream_interactor.get_accounts()) { + list_model.append(new ViewModel.AccountDetails(account, stream_interactor)); + } + + update(); + } + + public void set_avatar_uri(Account account, string uri) { + stream_interactor.get_module(AvatarManager.IDENTITY).publish(account, uri); + } + + public void remove_avatar(Account account) { + stream_interactor.get_module(AvatarManager.IDENTITY).unset_avatar(account); + } + + public void remove_account(Account account) { + stream_interactor.disconnect_account.begin(account, () => { + account.remove(); + update_data(); + }); + } + + public void reconnect_account(Account account) { + stream_interactor.disconnect_account.begin(account, () => { + stream_interactor.connect_account(account); + }); + } + + public void enable_disable_account(Account account) { + if (account.enabled) { + account.enabled = false; + stream_interactor.disconnect_account.begin(account); + } else { + account.enabled = true; + stream_interactor.connect_account(account); + } + update_data(); + } + + private void bind_general_page() { + var settings = Dino.Application.get_default().settings; + settings.bind_property("send-typing", general_page, "send-typing", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + settings.bind_property("send-marker", general_page, "send-marker", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + settings.bind_property("notifications", general_page, "notifications", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + settings.bind_property("convert-utf8-smileys", general_page, "convert-emojis", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + } +} + |