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/occupant_menu | |
parent | f25bfb00969a7e09996da2d5500e6718f4cc0148 (diff) | |
download | dino-7e7dcedaf31ee35499875491c9f569c575d28435.tar.gz dino-7e7dcedaf31ee35499875491c9f569c575d28435.zip |
Port from GTK3 to GTK4
Diffstat (limited to 'main/src/ui/occupant_menu')
-rw-r--r-- | main/src/ui/occupant_menu/list.vala | 53 | ||||
-rw-r--r-- | main/src/ui/occupant_menu/list_row.vala | 19 | ||||
-rw-r--r-- | main/src/ui/occupant_menu/view.vala | 44 |
3 files changed, 64 insertions, 52 deletions
diff --git a/main/src/ui/occupant_menu/list.vala b/main/src/ui/occupant_menu/list.vala index fcb039d7..20a98cf6 100644 --- a/main/src/ui/occupant_menu/list.vala +++ b/main/src/ui/occupant_menu/list.vala @@ -4,7 +4,7 @@ using Gtk; using Dino.Entities; using Xmpp; -namespace Dino.Ui.OccupantMenu{ +namespace Dino.Ui.OccupantMenu { [GtkTemplate (ui = "/im/dino/Dino/occupant_list.ui")] public class List : Box { @@ -17,7 +17,8 @@ public class List : Box { private Conversation conversation; private string[]? filter_values; - private HashMap<Jid, ListRow> rows = new HashMap<Jid, ListRow>(Jid.hash_func, Jid.equals_func); + private HashMap<Jid, Widget> rows = new HashMap<Jid, Widget>(Jid.hash_func, Jid.equals_func); + public HashMap<Widget, ListRow> row_wrappers = new HashMap<Widget, ListRow>(); public List(StreamInteractor stream_interactor, Conversation conversation) { this.stream_interactor = stream_interactor; @@ -53,8 +54,12 @@ public class List : Box { } public void add_occupant(Jid jid) { - rows[jid] = new ListRow(stream_interactor, conversation, jid); - list_box.add(rows[jid]); + var row_wrapper = new ListRow(stream_interactor, conversation, jid); + var widget = row_wrapper.get_widget(); + + row_wrappers[widget] = row_wrapper; + rows[jid] = widget; + list_box.append(widget); } public void remove_occupant(Jid jid) { @@ -81,13 +86,13 @@ public class List : Box { } private void header(ListBoxRow row, ListBoxRow? before_row) { - ListRow c1 = row as ListRow; - Xmpp.Xep.Muc.Affiliation? a1 = stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, c1.jid, c1.conversation.account); + ListRow row_wrapper1 = row_wrappers[row.get_child()]; + Xmpp.Xep.Muc.Affiliation? a1 = stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, row_wrapper1.jid, row_wrapper1.conversation.account); if (a1 == null) return; if (before_row != null) { - ListRow c2 = (ListRow) before_row; - Xmpp.Xep.Muc.Affiliation? a2 = stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, c2.jid, c2.conversation.account); + ListRow row_wrapper2 = row_wrappers[before_row.get_child()]; + Xmpp.Xep.Muc.Affiliation? a2 = stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, row_wrapper2.jid, row_wrapper2.conversation.account); if (a1 != a2) { row.set_header(generate_header_widget(a1, false)); } else if (row.get_header() != null){ @@ -112,7 +117,7 @@ public class List : Box { } int count = 0; - foreach (ListRow row in rows.values) { + foreach (ListRow row in row_wrappers.values) { Xmpp.Xep.Muc.Affiliation aff = stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, row.jid, conversation.account); if (aff == affiliation) count++; } @@ -120,36 +125,34 @@ public class List : Box { Label title_label = new Label("") { margin_start=10, xalign=0, visible=true }; title_label.set_markup(@"<b>$(Markup.escape_text(aff_str))</b>"); - Label count_label = new Label(@"$count") { xalign=0, margin_end=7, expand=true, visible=true }; + Label count_label = new Label(@"$count") { xalign=0, margin_end=7, hexpand=true, visible=true }; count_label.get_style_context().add_class("dim-label"); Grid grid = new Grid() { margin_top=top?5:15, column_spacing=5, hexpand=true, visible=true }; grid.attach(title_label, 0, 0, 1, 1); grid.attach(count_label, 1, 0, 1, 1); - grid.attach(new Separator(Orientation.HORIZONTAL) { expand=true, visible=true }, 0, 1, 2, 1); + grid.attach(new Separator(Orientation.HORIZONTAL) { hexpand=true, vexpand=true, visible=true }, 0, 1, 2, 1); return grid; } private bool filter(ListBoxRow r) { - if (r.get_type().is_a(typeof(ListRow))) { - ListRow row = r as ListRow; - foreach (string filter in filter_values) { - return row.name_label.label.down().contains(filter.down()); - } + ListRow row_wrapper = row_wrappers[r.get_child()]; + foreach (string filter in filter_values) { + return row_wrapper.name_label.label.down().contains(filter.down()); } return true; } private int sort(ListBoxRow row1, ListBoxRow row2) { - if (row1.get_type().is_a(typeof(ListRow)) && row2.get_type().is_a(typeof(ListRow))) { - ListRow c1 = row1 as ListRow; - ListRow c2 = row2 as ListRow; - int affiliation1 = get_affiliation_ranking(stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, c1.jid, c1.conversation.account) ?? Xmpp.Xep.Muc.Affiliation.NONE); - int affiliation2 = get_affiliation_ranking(stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, c2.jid, c2.conversation.account) ?? Xmpp.Xep.Muc.Affiliation.NONE); - if (affiliation1 < affiliation2) return -1; - else if (affiliation1 > affiliation2) return 1; - else return c1.name_label.label.collate(c2.name_label.label); - } + ListRow row_wrapper1 = row_wrappers[row1.get_child()]; + ListRow row_wrapper2 = row_wrappers[row2.get_child()]; + + int affiliation1 = get_affiliation_ranking(stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, row_wrapper1.jid, row_wrapper1.conversation.account) ?? Xmpp.Xep.Muc.Affiliation.NONE); + int affiliation2 = get_affiliation_ranking(stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, row_wrapper2.jid, row_wrapper2.conversation.account) ?? Xmpp.Xep.Muc.Affiliation.NONE); + + if (affiliation1 < affiliation2) return -1; + else if (affiliation1 > affiliation2) return 1; + else return row_wrapper1.name_label.label.collate(row_wrapper2.name_label.label); return 0; } diff --git a/main/src/ui/occupant_menu/list_row.vala b/main/src/ui/occupant_menu/list_row.vala index e0fb3f14..6b43fe7f 100644 --- a/main/src/ui/occupant_menu/list_row.vala +++ b/main/src/ui/occupant_menu/list_row.vala @@ -5,15 +5,22 @@ using Xmpp; namespace Dino.Ui.OccupantMenu { -[GtkTemplate (ui = "/im/dino/Dino/occupant_list_item.ui")] -public class ListRow : ListBoxRow { +public class ListRow : Object { - [GtkChild] private unowned AvatarImage image; - [GtkChild] public unowned Label name_label; + private Grid main_grid; + private AvatarImage image; + public Label name_label; public Conversation? conversation; public Jid? jid; + construct { + Builder builder = new Builder.from_resource("/im/dino/Dino/occupant_list_item.ui"); + main_grid = (Grid) builder.get_object("main_grid"); + image = (AvatarImage) builder.get_object("image"); + name_label = (Label) builder.get_object("name_label"); + } + public ListRow(StreamInteractor stream_interactor, Conversation conversation, Jid jid) { this.conversation = conversation; this.jid = jid; @@ -26,6 +33,10 @@ public class ListRow : ListBoxRow { name_label.label = text; image.set_text(c); } + + public Widget get_widget() { + return main_grid; + } } } diff --git a/main/src/ui/occupant_menu/view.vala b/main/src/ui/occupant_menu/view.vala index 428d2c99..35aa95f4 100644 --- a/main/src/ui/occupant_menu/view.vala +++ b/main/src/ui/occupant_menu/view.vala @@ -22,15 +22,14 @@ public class View : Popover { this.stream_interactor = stream_interactor; this.conversation = conversation; - this.show.connect(initialize_list); - invite_list.add(new ListRow.label("+", _("Invite")) {visible=true}); - list_box.add(invite_list); + invite_list.append(new ListRow.label("+", _("Invite")).get_widget()); + list_box.append(invite_list); invite_list.row_activated.connect(on_invite_clicked); stack.add_named(list_box, "list"); - add(stack); + set_child(stack); stack.visible_child_name = "list"; hide.connect(reset); @@ -46,12 +45,11 @@ public class View : Popover { private void initialize_list() { if (list == null) { list = new List(stream_interactor, conversation) { visible=true }; - list_box.add(list); - list_box.reorder_child(list, 0); + list_box.prepend(list); list.list_box.row_activated.connect((row) => { - ListRow list_row = row as ListRow; - show_menu(list_row.jid, list_row.name_label.label); + ListRow row_wrapper = list.row_wrappers[row.get_child()]; + show_menu(row_wrapper.jid, row_wrapper.name_label.label); }); } } @@ -71,37 +69,37 @@ public class View : Popover { if (real_jid != null) name += "\n<span font=\'8\'>%s</span>".printf(Markup.escape_text(real_jid.bare_jid.to_string())); Box header_box = new Box(Orientation.HORIZONTAL, 5) { visible=true }; - header_box.add(new Image.from_icon_name("pan-start-symbolic", IconSize.SMALL_TOOLBAR) { visible=true }); - header_box.add(new Label(name) { xalign=0, use_markup=true, hexpand=true, visible=true }); - Button header_button = new Button() { relief=ReliefStyle.NONE, visible=true }; - header_button.add(header_box); + header_box.append(new Image.from_icon_name("pan-start-symbolic") { visible=true }); + header_box.append(new Label(name) { xalign=0, use_markup=true, hexpand=true, visible=true }); + Button header_button = new Button() { has_frame=false, visible=true }; + header_button.child = header_box; - Box outer_box = new Box(Orientation.VERTICAL, 5) { margin=10, visible=true }; - outer_box.add(header_button); + Box outer_box = new Box(Orientation.VERTICAL, 5) { visible=true }; + outer_box.append(header_button); header_button.clicked.connect(show_list); - ModelButton private_button = new ModelButton() { active=true, text=_("Start private conversation"), visible=true }; - outer_box.add(private_button); + Button private_button = new Button.with_label(_("Start private conversation")) { visible=true }; + outer_box.append(private_button); private_button.clicked.connect(private_conversation_button_clicked); Jid? own_jid = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account); Xmpp.Xep.Muc.Role? role = stream_interactor.get_module(MucManager.IDENTITY).get_role(own_jid, conversation.account); if (role == Xmpp.Xep.Muc.Role.MODERATOR && stream_interactor.get_module(MucManager.IDENTITY).kick_possible(conversation.account, jid)) { - ModelButton kick_button = new ModelButton() { active=true, text=_("Kick"), visible=true }; - outer_box.add(kick_button); + Button kick_button = new Button.with_label(_("Kick")) { visible=true }; + outer_box.append(kick_button); kick_button.clicked.connect(kick_button_clicked); } if (stream_interactor.get_module(MucManager.IDENTITY).is_moderated_room(conversation.account, conversation.counterpart) && role == Xmpp.Xep.Muc.Role.MODERATOR){ if (stream_interactor.get_module(MucManager.IDENTITY).get_role(selected_jid, conversation.account) == Xmpp.Xep.Muc.Role.VISITOR) { - ModelButton voice_button = new ModelButton() { active=true, text=_("Grant write permission"), visible=true }; - outer_box.add(voice_button); + Button voice_button = new Button.with_label(_("Grant write permission")) { visible=true }; + outer_box.append(voice_button); voice_button.clicked.connect(() => voice_button_clicked("participant")); } else if (stream_interactor.get_module(MucManager.IDENTITY).get_role(selected_jid, conversation.account) == Xmpp.Xep.Muc.Role.PARTICIPANT){ - ModelButton voice_button = new ModelButton() { active=true, text=_("Revoke write permission"), visible=true }; - outer_box.add(voice_button); + Button voice_button = new Button.with_label(_("Revoke write permission")) { visible=true }; + outer_box.append(voice_button); voice_button.clicked.connect(() => voice_button_clicked("visitor")); } @@ -141,7 +139,7 @@ public class View : Popover { Gee.List<Account> acc_list = new ArrayList<Account>(Account.equals_func); acc_list.add(conversation.account); SelectContactDialog add_chat_dialog = new SelectContactDialog(stream_interactor, acc_list); - add_chat_dialog.set_transient_for((Window) get_toplevel()); + add_chat_dialog.set_transient_for((Window) get_root()); add_chat_dialog.title = _("Invite to Conference"); add_chat_dialog.ok_button.label = _("Invite"); add_chat_dialog.selected.connect((account, jid) => { |