diff options
Diffstat (limited to 'main/src/ui/add_conversation')
5 files changed, 94 insertions, 46 deletions
diff --git a/main/src/ui/add_conversation/accounts_combo_box.vala b/main/src/ui/add_conversation/accounts_combo_box.vala new file mode 100644 index 00000000..b1c929bd --- /dev/null +++ b/main/src/ui/add_conversation/accounts_combo_box.vala @@ -0,0 +1,57 @@ +using Gee; +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui { + +class AccountComboBox : ComboBox { + + public Account? selected { + get { + TreeIter selected; + if (get_active_iter(out selected)) { + Value value; + list_store.get_value(selected, 1, out value); + return value as Account; + } + return null; + } + set { + TreeIter iter; + if (list_store.get_iter_first(out iter)) { + int i = 0; + do { + Value val; + list_store.get_value(iter, 1, out val); + if ((val as Account).equals(value)) { + active = i; + break; + } + i++; + } while (list_store.iter_next(ref iter)); + } + } + } + + private StreamInteractor? stream_interactor; + private Gtk.ListStore list_store = new Gtk.ListStore(2, typeof(string), typeof(Account)); + + public void initialize(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + + CellRendererText renderer = new Gtk.CellRendererText(); + pack_start(renderer, true); + add_attribute(renderer, "text", 0); + + TreeIter iter; + foreach (Account account in stream_interactor.get_accounts()) { + list_store.append(out iter); + list_store.set(iter, 0, account.bare_jid.to_string(), 1, account); + } + set_model(list_store); + active = 0; + } +} + +}
\ No newline at end of file diff --git a/main/src/ui/add_conversation/chat/add_contact_dialog.vala b/main/src/ui/add_conversation/chat/add_contact_dialog.vala index 88bfe2be..f07f9659 100644 --- a/main/src/ui/add_conversation/chat/add_contact_dialog.vala +++ b/main/src/ui/add_conversation/chat/add_contact_dialog.vala @@ -8,7 +8,17 @@ namespace Dino.Ui.AddConversation.Chat { [GtkTemplate (ui = "/org/dino-im/add_conversation/add_contact_dialog.ui")] protected class AddContactDialog : Gtk.Dialog { - [GtkChild] private ComboBoxText accounts_comboboxtext; + public Account? account { + get { return account_combobox.selected; } + set { account_combobox.selected = value; } + } + + public string jid { + get { return jid_entry.text; } + set { jid_entry.text = value; } + } + + [GtkChild] private AccountComboBox account_combobox; [GtkChild] private Button ok_button; [GtkChild] private Button cancel_button; [GtkChild] private Entry jid_entry; @@ -20,11 +30,7 @@ protected class AddContactDialog : Gtk.Dialog { public AddContactDialog(StreamInteractor stream_interactor) { Object(use_header_bar : 1); this.stream_interactor = stream_interactor; - - foreach (Account account in stream_interactor.get_accounts()) { - accounts_comboboxtext.append_text(account.bare_jid.to_string()); - } - accounts_comboboxtext.set_active(0); + account_combobox.initialize(stream_interactor); cancel_button.clicked.connect(() => { close(); }); ok_button.clicked.connect(on_ok_button_clicked); @@ -33,14 +39,7 @@ protected class AddContactDialog : Gtk.Dialog { private void on_ok_button_clicked() { string? alias = alias_entry.text == "" ? null : alias_entry.text; - Account? account = null; Jid jid = new Jid(jid_entry.text); - foreach (Account account2 in stream_interactor.get_accounts()) { - print(account2.bare_jid.to_string() + "\n"); - if (accounts_comboboxtext.get_active_text() == account2.bare_jid.to_string()) { - account = account2; - } - } stream_interactor.get_module(RosterManager.IDENTITY).add_jid(account, jid, alias); if (subscribe_checkbutton.active) { stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(account, jid); @@ -50,7 +49,10 @@ protected class AddContactDialog : Gtk.Dialog { private void on_jid_entry_changed() { Jid parsed_jid = Jid.parse(jid_entry.text); - ok_button.set_sensitive(parsed_jid != null && parsed_jid.resourcepart == null); + bool sensitive = parsed_jid != null && parsed_jid.resourcepart == null && + stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(account, parsed_jid) == null; + ok_button.set_sensitive(sensitive); } } + }
\ No newline at end of file diff --git a/main/src/ui/add_conversation/conference/add_groupchat_dialog.vala b/main/src/ui/add_conversation/conference/add_groupchat_dialog.vala index c097ef06..96d44000 100644 --- a/main/src/ui/add_conversation/conference/add_groupchat_dialog.vala +++ b/main/src/ui/add_conversation/conference/add_groupchat_dialog.vala @@ -9,7 +9,7 @@ namespace Dino.Ui.AddConversation.Conference { protected class AddGroupchatDialog : Gtk.Dialog { [GtkChild] private Stack accounts_stack; - [GtkChild] private ComboBoxText accounts_comboboxtext; + [GtkChild] private AccountComboBox account_combobox; [GtkChild] private Label account_label; [GtkChild] private Button ok_button; [GtkChild] private Button cancel_button; @@ -28,10 +28,7 @@ protected class AddGroupchatDialog : Gtk.Dialog { ok_button.label = "Add"; ok_button.get_style_context().add_class("suggested-action"); // TODO why doesn't it work in XML accounts_stack.set_visible_child_name("combobox"); - foreach (Account account in stream_interactor.get_accounts()) { - accounts_comboboxtext.append_text(account.bare_jid.to_string()); - } - accounts_comboboxtext.set_active(0); + account_combobox.initialize(stream_interactor); cancel_button.clicked.connect(() => { close(); }); ok_button.clicked.connect(on_ok_button_clicked); @@ -69,20 +66,14 @@ protected class AddGroupchatDialog : Gtk.Dialog { } private void on_ok_button_clicked() { - Account? account = null; - foreach (Account account2 in stream_interactor.get_accounts()) { - if (accounts_comboboxtext.get_active_text() == account2.bare_jid.to_string()) { - account = account2; - } - } Xmpp.Xep.Bookmarks.Conference conference = new Xmpp.Xep.Bookmarks.Conference(jid_entry.text); conference.nick = nick_entry.text; conference.name = alias_entry.text; conference.autojoin = autojoin_checkbutton.active; if (edit_confrence == null) { - stream_interactor.get_module(MucManager.IDENTITY).add_bookmark(account, conference); + stream_interactor.get_module(MucManager.IDENTITY).add_bookmark(account_combobox.selected, conference); } else { - stream_interactor.get_module(MucManager.IDENTITY).replace_bookmark(account, edit_confrence, conference); + stream_interactor.get_module(MucManager.IDENTITY).replace_bookmark(account_combobox.selected, edit_confrence, conference); } close(); } diff --git a/main/src/ui/add_conversation/conference/conference_details_fragment.vala b/main/src/ui/add_conversation/conference/conference_details_fragment.vala index d42c79bd..fe57e6da 100644 --- a/main/src/ui/add_conversation/conference/conference_details_fragment.vala +++ b/main/src/ui/add_conversation/conference/conference_details_fragment.vala @@ -18,17 +18,10 @@ protected class ConferenceDetailsFragment : Box { } public Account account { - owned get { - foreach (Account account in stream_interactor.get_accounts()) { - if (accounts_comboboxtext.get_active_text() == account.bare_jid.to_string()) { - return account; - } - } - return null; - } + owned get { return account_combobox.selected; } set { accounts_label.label = value.bare_jid.to_string(); - accounts_comboboxtext.set_active_id(value.bare_jid.to_string()); + account_combobox.selected = value; } } public string jid { @@ -56,7 +49,7 @@ protected class ConferenceDetailsFragment : Box { [GtkChild] private Stack accounts_stack; [GtkChild] private Button accounts_button; [GtkChild] private Label accounts_label; - [GtkChild] private ComboBoxText accounts_comboboxtext; + [GtkChild] private AccountComboBox account_combobox; [GtkChild] private Stack jid_stack; [GtkChild] private Button jid_button; @@ -77,6 +70,7 @@ protected class ConferenceDetailsFragment : Box { public ConferenceDetailsFragment(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; + account_combobox.initialize(stream_interactor); accounts_stack.set_visible_child_name("label"); jid_stack.set_visible_child_name("label"); @@ -88,30 +82,32 @@ protected class ConferenceDetailsFragment : Box { nick_button.clicked.connect(() => { set_active_stack(nick_stack); }); password_button.clicked.connect(() => { set_active_stack(password_stack); }); - accounts_comboboxtext.changed.connect(() => {accounts_label.label = accounts_comboboxtext.get_active_text(); }); + account_combobox.changed.connect(() => { accounts_label.label = account_combobox.selected.bare_jid.to_string(); }); jid_entry.key_release_event.connect(on_jid_key_release_event); nick_entry.key_release_event.connect(on_nick_key_release_event); password_entry.key_release_event.connect(on_password_key_release_event); jid_entry.key_release_event.connect(() => { done = true; return false; }); // just for notifying nick_entry.key_release_event.connect(() => { done = true; return false; }); - - foreach (Account account in stream_interactor.get_accounts()) { - accounts_comboboxtext.append_text(account.bare_jid.to_string()); - } - accounts_comboboxtext.set_active(0); } public void set_editable() { - accounts_stack.set_visible_child_name("entry"); nick_stack.set_visible_child_name("entry"); password_stack.set_visible_child_name("entry"); } + public void reset_editable() { + jid_stack.set_visible_child_name("label"); + accounts_stack.set_visible_child_name("label"); + nick_stack.set_visible_child_name("label"); + password_stack.set_visible_child_name("label"); + } + public void clear() { jid = ""; nick = ""; password = ""; + reset_editable(); } private bool on_jid_key_release_event(EventKey event) { diff --git a/main/src/ui/add_conversation/conference/dialog.vala b/main/src/ui/add_conversation/conference/dialog.vala index bfb25888..d766a5a8 100644 --- a/main/src/ui/add_conversation/conference/dialog.vala +++ b/main/src/ui/add_conversation/conference/dialog.vala @@ -38,7 +38,7 @@ public class Dialog : Gtk.Dialog { } private void show_jid_add_view() { - cancel_button.remove(cancel_image); + if (cancel_image.get_parent() != null) cancel_button.remove(cancel_image); cancel_button.add(cancel_label); cancel_button.clicked.disconnect(show_jid_add_view); cancel_button.clicked.connect(close); @@ -53,7 +53,7 @@ public class Dialog : Gtk.Dialog { } private void show_conference_details_view() { - cancel_button.remove(cancel_label); + if (cancel_label.get_parent() != null) cancel_button.remove(cancel_label); cancel_button.add(cancel_image); cancel_button.clicked.disconnect(close); cancel_button.clicked.connect(show_jid_add_view); @@ -125,11 +125,13 @@ public class Dialog : Gtk.Dialog { ListRow? row = conference_list.get_selected_row() as ListRow; ConferenceListRow? conference_row = conference_list.get_selected_row() as ConferenceListRow; if (conference_row != null) { + details_fragment.account = conference_row.account; details_fragment.jid = conference_row.bookmark.jid; details_fragment.nick = conference_row.bookmark.nick; if (conference_row.bookmark.password != null) details_fragment.password = conference_row.bookmark.password; ok_button.grab_focus(); } else if (row != null) { + details_fragment.account = row.account; details_fragment.jid = row.jid.to_string(); details_fragment.set_editable(); } |