diff options
author | fiaxh <git@lightrise.org> | 2022-02-14 14:55:59 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2022-07-27 20:34:20 +0200 |
commit | 7e7dcedaf31ee35499875491c9f569c575d28435 (patch) | |
tree | 0c5fee2b28baf320775fbc92b3c252e97d9d054f /main/src/ui/add_conversation | |
parent | f25bfb00969a7e09996da2d5500e6718f4cc0148 (diff) | |
download | dino-7e7dcedaf31ee35499875491c9f569c575d28435.tar.gz dino-7e7dcedaf31ee35499875491c9f569c575d28435.zip |
Port from GTK3 to GTK4
Diffstat (limited to 'main/src/ui/add_conversation')
8 files changed, 157 insertions, 165 deletions
diff --git a/main/src/ui/add_conversation/add_conference_dialog.vala b/main/src/ui/add_conversation/add_conference_dialog.vala index a03f3db6..e078bc62 100644 --- a/main/src/ui/add_conversation/add_conference_dialog.vala +++ b/main/src/ui/add_conversation/add_conference_dialog.vala @@ -10,14 +10,13 @@ namespace Dino.Ui { public class AddConferenceDialog : Gtk.Dialog { private Stack stack = new Stack(); - private Button cancel_button; + private Button cancel_button = new Button() { visible=true }; private Button ok_button; - private Label cancel_label = new Label(_("Cancel")) {visible=true}; - private Image cancel_image = new Image.from_icon_name("go-previous-symbolic", IconSize.MENU) {visible=true}; private SelectJidFragment select_fragment; private ConferenceDetailsFragment details_fragment; private ConferenceList conference_list; + private ListBox conference_list_box; private StreamInteractor stream_interactor; @@ -29,7 +28,7 @@ public class AddConferenceDialog : Gtk.Dialog { stack.visible = true; stack.vhomogeneous = false; - get_content_area().add(stack); + get_content_area().append(stack); setup_headerbar(); setup_jid_add_view(); @@ -40,8 +39,7 @@ public class AddConferenceDialog : Gtk.Dialog { private void show_jid_add_view() { // Rewire headerbar (if CSD) if (Util.use_csd()) { - if (cancel_image.get_parent() != null) cancel_button.remove(cancel_image); - cancel_button.add(cancel_label); + cancel_button.set_label(_("Cancel")); cancel_button.clicked.disconnect(show_jid_add_view); cancel_button.clicked.connect(on_cancel); ok_button.label = _("Next"); @@ -59,8 +57,7 @@ public class AddConferenceDialog : Gtk.Dialog { private void show_conference_details_view() { // Rewire headerbar (if CSD) if (Util.use_csd()) { - if (cancel_label.get_parent() != null) cancel_button.remove(cancel_label); - cancel_button.add(cancel_image); + cancel_button.set_icon_name("go-previous-symbolic"); cancel_button.clicked.disconnect(on_cancel); cancel_button.clicked.connect(show_jid_add_view); ok_button.label = _("Join"); @@ -73,31 +70,30 @@ public class AddConferenceDialog : Gtk.Dialog { stack.transition_type = StackTransitionType.SLIDE_LEFT; stack.set_visible_child_name("details"); - animate_window_resize(); +// animate_window_resize(); } private void setup_headerbar() { - cancel_button = new Button() { visible=true }; - - ok_button = new Button() { can_focus=true, can_default=true, visible=true }; + ok_button = new Button() { can_focus=true, visible=true }; ok_button.get_style_context().add_class("suggested-action"); if (Util.use_csd()) { HeaderBar header_bar = get_header_bar() as HeaderBar; - header_bar.show_close_button = false; + header_bar.show_title_buttons = false; header_bar.pack_start(cancel_button); header_bar.pack_end(ok_button); - ok_button.has_default = true; +// ok_button.has_default = true; } } private void setup_jid_add_view() { conference_list = new ConferenceList(stream_interactor); - conference_list.row_activated.connect(() => { ok_button.clicked(); }); + conference_list_box = conference_list.get_list_box(); + conference_list_box.row_activated.connect(() => { ok_button.clicked(); }); - select_fragment = new SelectJidFragment(stream_interactor, conference_list, stream_interactor.get_accounts()); + select_fragment = new SelectJidFragment(stream_interactor, conference_list_box, stream_interactor.get_accounts()); select_fragment.add_jid.connect((row) => { AddGroupchatDialog dialog = new AddGroupchatDialog(stream_interactor); dialog.set_transient_for(this); @@ -109,23 +105,23 @@ public class AddConferenceDialog : Gtk.Dialog { }); Box wrap_box = new Box(Orientation.VERTICAL, 0) { visible=true }; - wrap_box.add(select_fragment); + wrap_box.append(select_fragment); stack.add_named(wrap_box, "select"); if (!Util.use_csd()) { Box box = new Box(Orientation.HORIZONTAL, 5) { halign=Align.END, margin_bottom=15, margin_start=80, margin_end=80, visible=true }; - Button ok_button = new Button() { label=_("Next"), sensitive=false, halign = Align.END, can_focus=true, can_default=true, visible=true }; + Button ok_button = new Button.with_label(_("Next")) { sensitive=false, halign = Align.END, can_focus=true, visible=true }; ok_button.get_style_context().add_class("suggested-action"); ok_button.clicked.connect(on_next_button_clicked); select_fragment.notify["done"].connect(() => { ok_button.sensitive = select_fragment.done; }); - Button cancel_button = new Button() { label=_("Cancel"), halign=Align.START, visible=true }; + Button cancel_button = new Button.with_label(_("Cancel")) { halign=Align.START, visible=true }; cancel_button.clicked.connect(on_cancel); - box.add(cancel_button); - box.add(ok_button); - wrap_box.add(box); + box.append(cancel_button); + box.append(ok_button); + wrap_box.append(box); - ok_button.has_default = true; +// ok_button.has_default = true; } } @@ -134,22 +130,22 @@ public class AddConferenceDialog : Gtk.Dialog { details_fragment.joined.connect(() => this.close()); Box wrap_box = new Box(Orientation.VERTICAL, 0) { visible=true }; - wrap_box.add(details_fragment); + wrap_box.append(details_fragment); if (!Util.use_csd()) { Box box = new Box(Orientation.HORIZONTAL, 5) { halign=Align.END, margin_bottom=15, margin_start=80, margin_end=80, visible=true }; - Button ok_button = new Button() { label=_("Join"), halign = Align.END, can_focus=true, can_default=true, visible=true }; + Button ok_button = new Button.with_label(_("Join")) { halign = Align.END, can_focus=true, visible=true }; ok_button.get_style_context().add_class("suggested-action"); details_fragment.notify["done"].connect(() => { ok_button.sensitive = select_fragment.done; }); details_fragment.ok_button = ok_button; - Button cancel_button = new Button() { label=_("Back"), halign=Align.START, visible=true }; + Button cancel_button = new Button.with_label(_("Back")) { halign=Align.START, visible=true }; cancel_button.clicked.connect(show_jid_add_view); - box.add(cancel_button); - box.add(ok_button); + box.append(cancel_button); + box.append(ok_button); - wrap_box.add(box); + wrap_box.append(box); } stack.add_named(wrap_box, "details"); } @@ -164,8 +160,9 @@ public class AddConferenceDialog : Gtk.Dialog { private void on_next_button_clicked() { details_fragment.clear(); - ListRow? row = conference_list.get_selected_row() as ListRow; - ConferenceListRow? conference_row = conference_list.get_selected_row() as ConferenceListRow; + + ListRow? row = conference_list_box.get_selected_row() != null ? conference_list_box.get_selected_row().get_child() as ListRow : null; + ConferenceListRow? conference_row = conference_list_box.get_selected_row() != null ? conference_list_box.get_selected_row() as ConferenceListRow : null; if (conference_row != null) { details_fragment.account = conference_row.account; details_fragment.jid = conference_row.bookmark.jid.to_string(); @@ -184,10 +181,11 @@ public class AddConferenceDialog : Gtk.Dialog { } private void animate_window_resize() { - int def_height, curr_width, curr_height; - get_size(out curr_width, out curr_height); - stack.get_preferred_height(null, out def_height); - int difference = def_height - curr_height; + int curr_height = get_size(Orientation.VERTICAL); + int curr_width = get_size(Orientation.HORIZONTAL); + var natural_size = new Requisition(); + stack.get_preferred_size(null, out natural_size); + int difference = natural_size.height - curr_height; Timer timer = new Timer(); Timeout.add((int) (stack.transition_duration / 30), () => { @@ -195,7 +193,8 @@ public class AddConferenceDialog : Gtk.Dialog { timer.elapsed(out microsec); ulong millisec = microsec / 1000; double partial = double.min(1, (double) millisec / stack.transition_duration); - resize(curr_width, (int) (curr_height + difference * partial)); + var a = this.list_toplevels().nth_data(0); + set_size_request(curr_width, (int) (curr_height + difference * partial)); return millisec < stack.transition_duration; }); } diff --git a/main/src/ui/add_conversation/add_groupchat_dialog.vala b/main/src/ui/add_conversation/add_groupchat_dialog.vala index a71c0a15..786c1a0b 100644 --- a/main/src/ui/add_conversation/add_groupchat_dialog.vala +++ b/main/src/ui/add_conversation/add_groupchat_dialog.vala @@ -30,11 +30,12 @@ protected class AddGroupchatDialog : Gtk.Dialog { cancel_button.clicked.connect(() => { close(); }); ok_button.clicked.connect(on_ok_button_clicked); - jid_entry.key_release_event.connect(on_jid_key_release); - nick_entry.key_release_event.connect(check_ok); + + jid_entry.changed.connect(on_jid_key_release); + nick_entry.changed.connect(check_ok); } - private bool on_jid_key_release() { + private void on_jid_key_release() { check_ok(); if (!alias_entry_changed) { try { @@ -44,17 +45,15 @@ protected class AddGroupchatDialog : Gtk.Dialog { alias_entry.text = jid_entry.text; } } - return false; } - private bool check_ok() { + private void check_ok() { try { Jid parsed_jid = new Jid(jid_entry.text); ok_button.sensitive = parsed_jid != null && parsed_jid.localpart != null && parsed_jid.resourcepart == null; } catch (InvalidJidError e) { ok_button.sensitive = false; } - return false; } private void on_ok_button_clicked() { diff --git a/main/src/ui/add_conversation/conference_details_fragment.vala b/main/src/ui/add_conversation/conference_details_fragment.vala index 88f9cc73..721c660e 100644 --- a/main/src/ui/add_conversation/conference_details_fragment.vala +++ b/main/src/ui/add_conversation/conference_details_fragment.vala @@ -114,12 +114,12 @@ protected class ConferenceDetailsFragment : Box { account_combobox.changed.connect(() => { accounts_label.label = account_combobox.selected.bare_jid.to_string(); }); 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(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; }); +// jid_entry.key_release_event.connect(() => { done = true; return false; }); // just for notifying +// nick_entry.key_release_event.connect(() => { done = true; return false; }); notification_button.clicked.connect(() => { notification_revealer.set_reveal_child(false); }); @@ -195,25 +195,25 @@ protected class ConferenceDetailsFragment : Box { notification_revealer.set_reveal_child(true); } - private bool on_jid_key_release_event(EventKey event) { - jid_label.label = jid_entry.text; - if (event.keyval == Key.Return) jid_stack.set_visible_child_name("label"); - return false; - } - - private bool on_nick_key_release_event(EventKey event) { - nick_label.label = nick_entry.text; - if (event.keyval == Key.Return) nick_stack.set_visible_child_name("label"); - return false; - } - - private bool on_password_key_release_event(EventKey event) { - string filler = ""; - for (int i = 0; i < password_entry.text.length; i++) filler += password_entry.get_invisible_char().to_string(); - password_label.label = filler; - if (event.keyval == Key.Return) password_stack.set_visible_child_name("label"); - return false; - } +// private bool on_jid_key_release_event(EventKey event) { +// jid_label.label = jid_entry.text; +// if (event.keyval == Key.Return) jid_stack.set_visible_child_name("label"); +// return false; +// } +// +// private bool on_nick_key_release_event(EventKey event) { +// nick_label.label = nick_entry.text; +// if (event.keyval == Key.Return) nick_stack.set_visible_child_name("label"); +// return false; +// } +// +// private bool on_password_key_release_event(EventKey event) { +// string filler = ""; +// for (int i = 0; i < password_entry.text.length; i++) filler += password_entry.get_invisible_char().to_string(); +// password_label.label = filler; +// if (event.keyval == Key.Return) password_stack.set_visible_child_name("label"); +// return false; +// } private void set_active_stack(Stack stack) { stack.set_visible_child_name("entry"); diff --git a/main/src/ui/add_conversation/conference_list.vala b/main/src/ui/add_conversation/conference_list.vala index fa71f98f..a19630e4 100644 --- a/main/src/ui/add_conversation/conference_list.vala +++ b/main/src/ui/add_conversation/conference_list.vala @@ -7,20 +7,22 @@ using Dino.Entities; namespace Dino.Ui { -protected class ConferenceList : FilterableList { +protected class ConferenceList { public signal void conversation_selected(Conversation? conversation); private StreamInteractor stream_interactor; + + 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); public ConferenceList(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; - set_filter_func(filter); - set_header_func(header); - set_sort_func(sort); +// list_box.set_filter_func(filter); + list_box.set_header_func(header); +// list_box.set_sort_func(sort); stream_interactor.get_module(MucManager.IDENTITY).bookmarks_updated.connect((account, conferences) => { lists[account] = conferences; @@ -44,18 +46,18 @@ protected class ConferenceList : FilterableList { } var widget = new ConferenceListRow(stream_interactor, conference, account); widgets[account][conference.jid] = widget; - add(widget); + list_box.append(widget); } private void remove_conference(Account account, Jid jid) { if (widgets.has_key(account) && widgets[account].has_key(jid)) { - remove(widgets[account][jid]); + list_box.remove(widgets[account][jid]); widgets[account].unset(jid); } } public void refresh_conferences() { - @foreach((widget) => { remove(widget); }); +// @foreach((widget) => { remove(widget); }); foreach (Account account in lists.keys) { foreach (Conference conference in lists[account]) { add_conference(account, conference); @@ -78,25 +80,8 @@ protected class ConferenceList : FilterableList { } } - private bool filter(ListBoxRow r) { - if (r.get_type().is_a(typeof(ListRow))) { - ListRow row = r as ListRow; - if (filter_values != null) { - foreach (string filter in filter_values) { - if (!(row.name_label.label.down().contains(filter.down()) || - row.jid.to_string().down().contains(filter.down()))) { - return false; - } - } - } - } - return true; - } - - public override int sort(ListBoxRow row1, ListBoxRow row2) { - ListRow c1 = (row1 as ListRow); - ListRow c2 = (row2 as ListRow); - return c1.name_label.label.collate(c2.name_label.label); + public ListBox get_list_box() { + return list_box; } } diff --git a/main/src/ui/add_conversation/list_row.vala b/main/src/ui/add_conversation/list_row.vala index 97c2b2fe..326dba98 100644 --- a/main/src/ui/add_conversation/list_row.vala +++ b/main/src/ui/add_conversation/list_row.vala @@ -6,16 +6,27 @@ using Xmpp; namespace Dino.Ui { -[GtkTemplate (ui = "/im/dino/Dino/add_conversation/list_row.ui")] -public class ListRow : ListBoxRow { +public class ListRow : Widget { - [GtkChild] public unowned AvatarImage image; - [GtkChild] public unowned Label name_label; - [GtkChild] public unowned Label via_label; + public Grid outer_grid; + public AvatarImage image; + public Label name_label; + public Label via_label; public Jid? jid; public Account? account; + construct { + Builder builder = new Builder.from_resource("/im/dino/Dino/add_conversation/list_row.ui"); + outer_grid = (Grid) builder.get_object("outer_grid"); + image = (AvatarImage) builder.get_object("image"); + name_label = (Label) builder.get_object("name_label"); + via_label = (Label) builder.get_object("via_label"); + + this.layout_manager = new BinLayout(); + outer_grid.insert_after(this, null); + } + public ListRow() {} public ListRow.from_jid(StreamInteractor stream_interactor, Jid jid, Account account, bool show_account) { diff --git a/main/src/ui/add_conversation/roster_list.vala b/main/src/ui/add_conversation/roster_list.vala index fd4d4ade..a89d24e8 100644 --- a/main/src/ui/add_conversation/roster_list.vala +++ b/main/src/ui/add_conversation/roster_list.vala @@ -6,22 +6,23 @@ using Xmpp; namespace Dino.Ui { -protected class RosterList : FilterableList { +protected class RosterList { public signal void conversation_selected(Conversation? conversation); private StreamInteractor stream_interactor; private Gee.List<Account> accounts; private ulong[] handler_ids = new ulong[0]; + private ListBox list_box = new ListBox(); private HashMap<Account, HashMap<Jid, ListRow>> rows = new HashMap<Account, HashMap<Jid, ListRow>>(Account.hash_func, Account.equals_func); public RosterList(StreamInteractor stream_interactor, Gee.List<Account> accounts) { this.stream_interactor = stream_interactor; this.accounts = accounts; - set_filter_func(filter); - set_header_func(header); - set_sort_func(sort); +// set_filter_func(filter); + list_box.set_header_func(header); +// set_sort_func(sort); handler_ids += stream_interactor.get_module(RosterManager.IDENTITY).removed_roster_item.connect( (account, jid, roster_item) => { if (accounts.contains(account)) { @@ -33,7 +34,7 @@ protected class RosterList : FilterableList { on_updated_roster_item(account, jid, roster_item); } }); - destroy.connect(() => { + list_box.destroy.connect(() => { foreach (ulong handler_id in handler_ids) stream_interactor.get_module(RosterManager.IDENTITY).disconnect(handler_id); }); @@ -42,7 +43,7 @@ protected class RosterList : FilterableList { private void on_removed_roster_item(Account account, Jid jid, Roster.Item roster_item) { if (rows.has_key(account) && rows[account].has_key(jid)) { - remove(rows[account][jid]); + list_box.remove(rows[account][jid]); rows[account].unset(jid); } } @@ -51,9 +52,9 @@ protected class RosterList : FilterableList { on_removed_roster_item(account, jid, roster_item); ListRow row = new ListRow.from_jid(stream_interactor, roster_item.jid, account, accounts.size > 1); rows[account][jid] = row; - add(row); - invalidate_sort(); - invalidate_filter(); + list_box.append(row); + list_box.invalidate_sort(); + list_box.invalidate_filter(); } private void fetch_roster_items(Account account) { @@ -69,25 +70,8 @@ protected class RosterList : FilterableList { } } - private bool filter(ListBoxRow r) { - if (r.get_type().is_a(typeof(ListRow))) { - ListRow row = r as ListRow; - if (filter_values != null) { - foreach (string filter in filter_values) { - if (!(row.name_label.label.down().contains(filter.down()) || - row.jid.to_string().down().contains(filter.down()))) { - return false; - } - } - } - } - return true; - } - - public override int sort(ListBoxRow row1, ListBoxRow row2) { - ListRow c1 = (row1 as ListRow); - ListRow c2 = (row2 as ListRow); - return c1.name_label.label.collate(c2.name_label.label); + public ListBox get_list_box() { + return list_box; } } diff --git a/main/src/ui/add_conversation/select_contact_dialog.vala b/main/src/ui/add_conversation/select_contact_dialog.vala index d78a17c1..4bf5b193 100644 --- a/main/src/ui/add_conversation/select_contact_dialog.vala +++ b/main/src/ui/add_conversation/select_contact_dialog.vala @@ -14,6 +14,7 @@ public class SelectContactDialog : Gtk.Dialog { public Button ok_button; private RosterList roster_list; + private ListBox roster_list_box; private SelectJidFragment select_jid_fragment; private StreamInteractor stream_interactor; private Gee.List<Account> accounts; @@ -45,7 +46,7 @@ public class SelectContactDialog : Gtk.Dialog { if (Util.use_csd()) { HeaderBar header_bar = get_header_bar() as HeaderBar; - header_bar.show_close_button = false; + header_bar.show_title_buttons = false; header_bar.pack_start(cancel_button); header_bar.pack_end(ok_button); @@ -54,15 +55,15 @@ public class SelectContactDialog : Gtk.Dialog { cancel_button.halign = Align.START; ok_button.halign = Align.END; - box.add(cancel_button); - box.add(ok_button); + box.append(cancel_button); + box.append(ok_button); - get_content_area().add(box); + get_content_area().append(box); } cancel_button.clicked.connect(() => { close(); }); ok_button.clicked.connect(() => { - ListRow? selected_row = roster_list.get_selected_row() as ListRow; + ListRow? selected_row = roster_list_box.get_selected_row() != null ? roster_list_box.get_selected_row().get_child() as ListRow : null; if (selected_row != null) selected(selected_row.account, selected_row.jid); close(); }); @@ -70,21 +71,22 @@ public class SelectContactDialog : Gtk.Dialog { private void setup_view() { roster_list = new RosterList(stream_interactor, accounts); - roster_list.row_activated.connect(() => { ok_button.clicked(); }); - select_jid_fragment = new SelectJidFragment(stream_interactor, roster_list, accounts); + roster_list_box = roster_list.get_list_box(); + roster_list_box.row_activated.connect(() => { ok_button.clicked(); }); + select_jid_fragment = new SelectJidFragment(stream_interactor, roster_list_box, accounts); select_jid_fragment.add_jid.connect((row) => { AddContactDialog add_contact_dialog = new AddContactDialog(stream_interactor); add_contact_dialog.set_transient_for(this); add_contact_dialog.present(); }); select_jid_fragment.remove_jid.connect((row) => { - ListRow list_row = roster_list.get_selected_row() as ListRow; + ListRow list_row = roster_list_box.get_selected_row() as ListRow; stream_interactor.get_module(RosterManager.IDENTITY).remove_jid(list_row.account, list_row.jid); }); select_jid_fragment.notify["done"].connect(() => { ok_button.sensitive = select_jid_fragment.done; }); - get_content_area().add(select_jid_fragment); + get_content_area().append(select_jid_fragment); } } diff --git a/main/src/ui/add_conversation/select_jid_fragment.vala b/main/src/ui/add_conversation/select_jid_fragment.vala index bc349b6c..58f019c1 100644 --- a/main/src/ui/add_conversation/select_jid_fragment.vala +++ b/main/src/ui/add_conversation/select_jid_fragment.vala @@ -12,7 +12,7 @@ public class SelectJidFragment : Gtk.Box { public signal void add_jid(); public signal void remove_jid(ListRow row); public bool done { - get { return filterable_list.get_selected_row() != null; } + get { return list.get_selected_row() != null; } private set {} } @@ -22,43 +22,45 @@ public class SelectJidFragment : Gtk.Box { [GtkChild] private unowned Button remove_button; private StreamInteractor stream_interactor; - private FilterableList filterable_list; private Gee.List<Account> accounts; - private ArrayList<AddListRow> added_rows = new ArrayList<AddListRow>(); - public SelectJidFragment(StreamInteractor stream_interactor, FilterableList filterable_list, Gee.List<Account> accounts) { + private ListBox list; + private string[]? filter_values; + + public SelectJidFragment(StreamInteractor stream_interactor, ListBox list, Gee.List<Account> accounts) { this.stream_interactor = stream_interactor; - this.filterable_list = filterable_list; + this.list = list; this.accounts = accounts; - filterable_list.visible = true; - filterable_list.activate_on_single_click = false; - filterable_list.vexpand = true; - box.add(filterable_list); + list.activate_on_single_click = false; + list.vexpand = true; + box.append(list); - filterable_list.set_sort_func(sort); - filterable_list.row_selected.connect(check_buttons_active); - filterable_list.row_selected.connect(() => { done = true; }); // just for notifying + list.set_sort_func(sort); + list.set_filter_func(filter); + list.row_selected.connect(check_buttons_active); + 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(filterable_list.get_selected_row() as ListRow); }); + remove_button.clicked.connect(() => { remove_jid(list.get_selected_row() as ListRow); }); } public void set_filter(string str) { if (entry.text != str) entry.text = str; - foreach (AddListRow row in added_rows) filterable_list.remove(row); + foreach (AddListRow row in added_rows) list.remove(row); added_rows.clear(); - string[] ? values = str == "" ? null : str.split(" "); - filterable_list.set_filter_values(values); + filter_values = str == "" ? null : str.split(" "); + list.invalidate_filter(); + try { Jid parsed_jid = new Jid(str); if (parsed_jid != null && parsed_jid.localpart != null) { foreach (Account account in accounts) { AddListRow row = new AddListRow(stream_interactor, parsed_jid, account); - filterable_list.add(row); + list.append(row); added_rows.add(row); } } @@ -68,7 +70,7 @@ public class SelectJidFragment : Gtk.Box { } private void check_buttons_active() { - ListBoxRow? row = filterable_list.get_selected_row(); + ListBoxRow? row = list.get_selected_row(); bool active = row != null && !row.get_type().is_a(typeof(AddListRow)); remove_button.sensitive = active; } @@ -81,7 +83,29 @@ public class SelectJidFragment : Gtk.Box { } else if (al2 != null && al1 == null) { return 1; } - return filterable_list.sort(row1, row2); + + ListRow? c1 = (row1.child as ListRow); + ListRow? c2 = (row2.child as ListRow); + if (c1 != null && c2 != null) { + return c1.name_label.label.collate(c2.name_label.label); + } + + return 0; + } + + private bool filter(ListBoxRow r) { + ListRow? row = (r.child as ListRow); + if (row == null) return true; + + if (filter_values != null) { + foreach (string filter in filter_values) { + if (!(row.name_label.label.down().contains(filter.down()) || + row.jid.to_string().down().contains(filter.down()))) { + return false; + } + } + } + return true; } private class AddListRow : ListRow { @@ -101,16 +125,4 @@ public class SelectJidFragment : Gtk.Box { } } -public abstract class FilterableList : Gtk.ListBox { - public string[]? filter_values; - - public void set_filter_values(string[] values) { - if (filter_values == values) return; - filter_values = values; - invalidate_filter(); - } - - public abstract int sort(ListBoxRow row1, ListBoxRow row2); -} - } |