diff options
-rw-r--r-- | libdino/src/service/presence_manager.vala | 5 | ||||
-rw-r--r-- | main/CMakeLists.txt | 1 | ||||
-rw-r--r-- | main/data/add_conversation/add_contact_dialog.ui | 2 | ||||
-rw-r--r-- | main/data/add_conversation/add_groupchat_dialog.ui | 2 | ||||
-rw-r--r-- | main/data/add_conversation/conference_details_fragment.ui | 2 | ||||
-rw-r--r-- | main/src/ui/add_conversation/accounts_combo_box.vala | 57 | ||||
-rw-r--r-- | main/src/ui/add_conversation/chat/add_contact_dialog.vala | 30 | ||||
-rw-r--r-- | main/src/ui/add_conversation/conference/add_groupchat_dialog.vala | 17 | ||||
-rw-r--r-- | main/src/ui/add_conversation/conference/conference_details_fragment.vala | 30 | ||||
-rw-r--r-- | main/src/ui/add_conversation/conference/dialog.vala | 6 | ||||
-rw-r--r-- | main/src/ui/notifications.vala | 9 | ||||
-rw-r--r-- | qlite/src/query_builder.vala | 2 | ||||
-rw-r--r-- | qlite/src/row.vala | 3 |
13 files changed, 114 insertions, 52 deletions
diff --git a/libdino/src/service/presence_manager.vala b/libdino/src/service/presence_manager.vala index effeb59f..5dfb2cf6 100644 --- a/libdino/src/service/presence_manager.vala +++ b/libdino/src/service/presence_manager.vala @@ -74,6 +74,11 @@ public class PresenceManager : StreamInteractionModule, Object { if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).deny_subscription(stream, jid.bare_jid.to_string()); } + public void cancel_subscription(Account account, Jid jid) { + Core.XmppStream stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).cancel_subscription(stream, jid.bare_jid.to_string()); + } + private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_available_show.connect((stream, jid, show) => on_received_available_show(account, new Jid(jid), show) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index db3e05cd..76f5e507 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -71,6 +71,7 @@ SOURCES src/ui/add_conversation/conference/conference_details_fragment.vala src/ui/add_conversation/conference/conference_list.vala src/ui/add_conversation/conference/dialog.vala + src/ui/add_conversation/accounts_combo_box.vala src/ui/add_conversation/list_row.vala src/ui/add_conversation/select_jid_fragment.vala src/ui/avatar_generator.vala diff --git a/main/data/add_conversation/add_contact_dialog.ui b/main/data/add_conversation/add_contact_dialog.ui index 1ac2745c..533591f5 100644 --- a/main/data/add_conversation/add_contact_dialog.ui +++ b/main/data/add_conversation/add_contact_dialog.ui @@ -57,7 +57,7 @@ </packing> </child> <child> - <object class="GtkComboBoxText" id="accounts_comboboxtext"> + <object class="DinoUiAccountComboBox" id="account_combobox"> <property name="hexpand">True</property> <property name="width_request">200</property> <property name="visible">True</property> diff --git a/main/data/add_conversation/add_groupchat_dialog.ui b/main/data/add_conversation/add_groupchat_dialog.ui index 4c58ed89..6654e23b 100644 --- a/main/data/add_conversation/add_groupchat_dialog.ui +++ b/main/data/add_conversation/add_groupchat_dialog.ui @@ -61,7 +61,7 @@ <object class="GtkStack" id="accounts_stack"> <property name="visible">True</property> <child> - <object class="GtkComboBoxText" id="accounts_comboboxtext"> + <object class="DinoUiAccountComboBox" id="account_combobox"> <property name="hexpand">True</property> <property name="width_request">200</property> <property name="visible">True</property> diff --git a/main/data/add_conversation/conference_details_fragment.ui b/main/data/add_conversation/conference_details_fragment.ui index c9431728..41cbb6c7 100644 --- a/main/data/add_conversation/conference_details_fragment.ui +++ b/main/data/add_conversation/conference_details_fragment.ui @@ -46,7 +46,7 @@ </packing> </child> <child> - <object class="GtkComboBoxText" id="accounts_comboboxtext"> + <object class="DinoUiAccountComboBox" id="account_combobox"> <property name="hexpand">True</property> <property name="width_request">200</property> <property name="visible">True</property> 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(); } diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala index 18e33c56..3efa7dc7 100644 --- a/main/src/ui/notifications.vala +++ b/main/src/ui/notifications.vala @@ -3,7 +3,7 @@ using Xmpp; namespace Dino.Ui { -public class Notifications : GLib.Object { +public class Notifications : Object { private StreamInteractor stream_interactor; private Notify.Notification notification = new Notify.Notification("", null, null); @@ -38,6 +38,13 @@ public class Notifications : GLib.Object { notification.set_image_from_pixbuf((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account)); notification.add_action("accept", "Accept", () => { stream_interactor.get_module(PresenceManager.IDENTITY).approve_subscription(account, jid); + + if (stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(account, jid) == null) { + AddConversation.Chat.AddContactDialog dialog = new AddConversation.Chat.AddContactDialog(stream_interactor); + dialog.jid = jid.bare_jid.to_string(); + dialog.account = account; + dialog.show(); + } try { notification.close(); } catch (Error error) { } diff --git a/qlite/src/query_builder.vala b/qlite/src/query_builder.vala index 37f9b261..7259eddf 100644 --- a/qlite/src/query_builder.vala +++ b/qlite/src/query_builder.vala @@ -156,7 +156,7 @@ public class QueryBuilder : StatementBuilder { } public RowIterator iterator() throws DatabaseError { - return new RowIterator.from_query_builder(this); + return new RowIterator.from_query_builder(db, this); } class OrderingTerm { diff --git a/qlite/src/row.vala b/qlite/src/row.vala index ed0552a0..60c7b666 100644 --- a/qlite/src/row.vala +++ b/qlite/src/row.vala @@ -56,7 +56,8 @@ public class RowIterator { private Database db; private Statement stmt; - public RowIterator.from_query_builder(QueryBuilder query) throws DatabaseError { + public RowIterator.from_query_builder(Database db, QueryBuilder query) throws DatabaseError { + this.db = db; this.stmt = query.prepare(); } |