diff options
author | fiaxh <git@lightrise.org> | 2022-08-22 13:08:31 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2022-08-22 13:16:46 +0200 |
commit | 117f19381233207e4b5aef03c82e7dd4b2d1debd (patch) | |
tree | 4accf7d771a74b8cc7ee57d486cafc281f127059 /main | |
parent | 14bc3d6717515e0b34b02ef5b5ad4c3ec52ccdc2 (diff) | |
download | dino-117f19381233207e4b5aef03c82e7dd4b2d1debd.tar.gz dino-117f19381233207e4b5aef03c82e7dd4b2d1debd.zip |
Fix crashes and warning in Join Conference dialog
fixes #1262
Diffstat (limited to 'main')
-rw-r--r-- | main/src/ui/add_conversation/conference_list.vala | 26 | ||||
-rw-r--r-- | main/src/ui/add_conversation/select_jid_fragment.vala | 6 |
2 files changed, 25 insertions, 7 deletions
diff --git a/main/src/ui/add_conversation/conference_list.vala b/main/src/ui/add_conversation/conference_list.vala index 181c6219..454362d0 100644 --- a/main/src/ui/add_conversation/conference_list.vala +++ b/main/src/ui/add_conversation/conference_list.vala @@ -15,12 +15,14 @@ protected class ConferenceList { private ListBox list_box = new ListBox(); private HashMap<Account, Set<Conference>> lists = new HashMap<Account, Set<Conference>>(Account.hash_func, Account.equals_func); - private HashMap<Account, HashMap<Jid, Widget>> widgets = new HashMap<Account, HashMap<Jid, Widget>>(Account.hash_func, Account.equals_func); + private HashMap<Account, HashMap<Jid, ListBoxRow>> widgets = new HashMap<Account, HashMap<Jid, ListBoxRow>>(Account.hash_func, Account.equals_func); + + ulong bookmarks_updated_handler_id = -1; public ConferenceList(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; - stream_interactor.get_module(MucManager.IDENTITY).bookmarks_updated.connect((account, conferences) => { + bookmarks_updated_handler_id = stream_interactor.get_module(MucManager.IDENTITY).bookmarks_updated.connect((account, conferences) => { lists[account] = conferences; refresh_conferences(); }); @@ -36,13 +38,21 @@ protected class ConferenceList { stream_interactor.get_module(MucManager.IDENTITY).conference_removed.connect(remove_conference); } + ~ConferenceList() { + stream_interactor.get_module(MucManager.IDENTITY).disconnect(bookmarks_updated_handler_id); + stream_interactor.get_module(MucManager.IDENTITY).conference_added.disconnect(add_conference); + stream_interactor.get_module(MucManager.IDENTITY).conference_removed.disconnect(remove_conference); + } + private void add_conference(Account account, Conference conference) { if (!widgets.has_key(account)) { - widgets[account] = new HashMap<Jid, Widget>(Jid.hash_func, Jid.equals_func); + widgets[account] = new HashMap<Jid, ListBoxRow>(Jid.hash_func, Jid.equals_func); } var widget = new ConferenceListRow(stream_interactor, conference, account); - widgets[account][conference.jid] = widget; - list_box.append(widget); + var list_box_row = new ListBoxRow(); + list_box_row.set_child(widget); + widgets[account][conference.jid] = list_box_row; + list_box.append(list_box_row); } private void remove_conference(Account account, Jid jid) { @@ -54,7 +64,11 @@ protected class ConferenceList { public void refresh_conferences() { foreach (Account account in widgets.keys) { - foreach (Jid jid in widgets[account].keys) { + + var account_widgets_cpy = new HashMap<Jid, ListBoxRow>(); + account_widgets_cpy.set_all(widgets[account]); + + foreach (Jid jid in account_widgets_cpy.keys) { remove_conference(account, jid); } } diff --git a/main/src/ui/add_conversation/select_jid_fragment.vala b/main/src/ui/add_conversation/select_jid_fragment.vala index a6cf0864..25b0b11f 100644 --- a/main/src/ui/add_conversation/select_jid_fragment.vala +++ b/main/src/ui/add_conversation/select_jid_fragment.vala @@ -44,7 +44,11 @@ public class SelectJidFragment : Gtk.Box { list.row_selected.connect(() => { done = true; }); // just for notifying entry.changed.connect(() => { set_filter(entry.text); }); add_button.clicked.connect(() => { add_jid(); }); - remove_button.clicked.connect(() => { remove_jid(list.get_selected_row() as ListRow); }); + remove_button.clicked.connect(() => { + var list_row = list.get_selected_row(); + if (list_row == null) return; + remove_jid(list_row.child as ListRow); + }); } public void set_filter(string str) { |