From 7e7dcedaf31ee35499875491c9f569c575d28435 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 14 Feb 2022 14:55:59 +0100 Subject: Port from GTK3 to GTK4 --- main/src/ui/conversation_titlebar/call_entry.vala | 69 ++++++++-------------- .../conversation_titlebar.vala | 69 +++++++++++++--------- main/src/ui/conversation_titlebar/menu_entry.vala | 44 +++++--------- .../ui/conversation_titlebar/occupants_entry.vala | 42 +++++-------- .../src/ui/conversation_titlebar/search_entry.vala | 20 +++---- 5 files changed, 104 insertions(+), 140 deletions(-) (limited to 'main/src/ui/conversation_titlebar') diff --git a/main/src/ui/conversation_titlebar/call_entry.vala b/main/src/ui/conversation_titlebar/call_entry.vala index 1b8b2a05..72376126 100644 --- a/main/src/ui/conversation_titlebar/call_entry.vala +++ b/main/src/ui/conversation_titlebar/call_entry.vala @@ -8,65 +8,42 @@ namespace Dino.Ui { public class CallTitlebarEntry : Plugins.ConversationTitlebarEntry, Object { public string id { get { return "call"; } } - - public CallButton call_button; - - private StreamInteractor stream_interactor; - - public CallTitlebarEntry(StreamInteractor stream_interactor) { - this.stream_interactor = stream_interactor; - - call_button = new CallButton(stream_interactor) { tooltip_text=_("Start call") }; - call_button.set_image(new Gtk.Image.from_icon_name("dino-phone-symbolic", Gtk.IconSize.MENU) { visible=true }); - } - public double order { get { return 4; } } - public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) { - if (type == Plugins.WidgetType.GTK) { - return call_button; - } - return null; - } - } - public class CallButton : Plugins.ConversationTitlebarWidget, Gtk.MenuButton { + private MenuButton button = new MenuButton() { tooltip_text=_("Start call") }; private StreamInteractor stream_interactor; private Conversation conversation; - private ModelButton audio_button = new ModelButton() { text=_("Audio call"), visible=true }; - private ModelButton video_button = new ModelButton() { text=_("Video call"), visible=true }; - - public CallButton(StreamInteractor stream_interactor) { + public CallTitlebarEntry(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; - use_popover = true; - image = new Gtk.Image.from_icon_name("dino-phone-symbolic", Gtk.IconSize.MENU) { visible=true }; + button.set_icon_name("dino-phone-symbolic"); - Gtk.PopoverMenu popover_menu = new Gtk.PopoverMenu(); - Box box = new Box(Orientation.VERTICAL, 0) { margin=10, visible=true }; - audio_button.clicked.connect(() => { + Menu menu_model = new Menu(); + menu_model.append(_("Audio call"), "call.audio"); + menu_model.append(_("Video call"), "call.video"); + Gtk.PopoverMenu popover_menu = new Gtk.PopoverMenu.from_model(menu_model); + button.popover = popover_menu; + + SimpleActionGroup action_group = new SimpleActionGroup(); + SimpleAction audio_call_action = new SimpleAction("audio", null); + audio_call_action.activate.connect((parameter) => { stream_interactor.get_module(Calls.IDENTITY).initiate_call.begin(conversation, false, (_, res) => { CallState call_state = stream_interactor.get_module(Calls.IDENTITY).initiate_call.end(res); open_call_window(call_state); }); }); - box.add(audio_button); - - video_button.clicked.connect(() => { + action_group.insert(audio_call_action); + SimpleAction video_call_action = new SimpleAction("video", null); + video_call_action.activate.connect((parameter) => { stream_interactor.get_module(Calls.IDENTITY).initiate_call.begin(conversation, true, (_, res) => { CallState call_state = stream_interactor.get_module(Calls.IDENTITY).initiate_call.end(res); open_call_window(call_state); }); }); - box.add(video_button); - popover_menu.add(box); - - popover = popover_menu; - - clicked.connect(() => { - popover_menu.visible = true; - }); + action_group.insert(video_call_action); + button.insert_action_group("call", action_group); stream_interactor.get_module(Calls.IDENTITY).call_incoming.connect((call, state,conversation) => { update_button_state(); @@ -96,6 +73,7 @@ namespace Dino.Ui { } public new void set_conversation(Conversation conversation) { + print(@"set_conversation $(conversation.counterpart)\n"); this.conversation = conversation; update_visibility.begin(); @@ -103,12 +81,12 @@ namespace Dino.Ui { } private void update_button_state() { - this.sensitive = !stream_interactor.get_module(Calls.IDENTITY).is_call_in_progress(); + button.sensitive = !stream_interactor.get_module(Calls.IDENTITY).is_call_in_progress(); } private async void update_visibility() { if (conversation == null) { - visible = false; + button.visible = false; return; } @@ -116,10 +94,15 @@ namespace Dino.Ui { bool can_do_calls = yield stream_interactor.get_module(Calls.IDENTITY).can_conversation_do_calls(conversation); if (conv_bak != conversation) return; - visible = video_button.visible = can_do_calls; + button.visible = can_do_calls; } public new void unset_conversation() { } + + public Object? get_widget(Plugins.WidgetType type) { + if (type != Plugins.WidgetType.GTK4) return null; + return button; + } } } diff --git a/main/src/ui/conversation_titlebar/conversation_titlebar.vala b/main/src/ui/conversation_titlebar/conversation_titlebar.vala index 60d8286b..0d13e48b 100644 --- a/main/src/ui/conversation_titlebar/conversation_titlebar.vala +++ b/main/src/ui/conversation_titlebar/conversation_titlebar.vala @@ -6,14 +6,17 @@ using Dino.Entities; namespace Dino.Ui { -public interface ConversationTitlebar : Widget { +public interface ConversationTitlebar : Object { public abstract string? subtitle { get; set; } public abstract string? title { get; set; } - public abstract void insert_entry(Plugins.ConversationTitlebarEntry entry); + public abstract void insert_button(Widget button); + public abstract Widget get_widget(); } -public class ConversationTitlebarNoCsd : ConversationTitlebar, Gtk.Box { +public class ConversationTitlebarNoCsd : ConversationTitlebar, Object { + + public Box main = new Box(Orientation.HORIZONTAL, 0); public string? title { get { return title_label.label; } @@ -33,49 +36,61 @@ public class ConversationTitlebarNoCsd : ConversationTitlebar, Gtk.Box { private Label subtitle_label = new Label("") { use_markup=true, ellipsize=EllipsizeMode.END, visible=false }; construct { - Box content_box = new Box(Orientation.HORIZONTAL, 0) { margin=5, margin_start=15, margin_end=10, hexpand=true, visible=true }; - this.add(content_box); + Box content_box = new Box(Orientation.HORIZONTAL, 0) { margin_start=15, margin_end=10, hexpand=true, visible=true }; + main.append(content_box); Box titles_box = new Box(Orientation.VERTICAL, 0) { valign=Align.CENTER, hexpand=true, visible=true }; - content_box.add(titles_box); + content_box.append(titles_box); - titles_box.add(title_label); + titles_box.append(title_label); subtitle_label.attributes = new AttrList(); subtitle_label.get_style_context().add_class("dim-label"); - titles_box.add(subtitle_label); + titles_box.append(subtitle_label); - content_box.add(widgets_box); + content_box.append(widgets_box); } public ConversationTitlebarNoCsd() { - this.get_style_context().add_class("dino-header-right"); + main.get_style_context().add_class("dino-header-right"); } - public void insert_entry(Plugins.ConversationTitlebarEntry entry) { - Plugins.ConversationTitlebarWidget widget = entry.get_widget(Plugins.WidgetType.GTK); - if (widget != null) { - Button gtk_widget = (Gtk.Button) widget; - gtk_widget.relief = ReliefStyle.NONE; - widgets_box.pack_end(gtk_widget); - } + public void insert_button(Widget button) { + widgets_box.prepend(button); + } + + public Widget get_widget() { + return main; } } -public class ConversationTitlebarCsd : ConversationTitlebar, Gtk.HeaderBar { +public class ConversationTitlebarCsd : ConversationTitlebar, Object { + + public new string? title { get { return title_label.label; } set { title_label.label = value; } } + public new string? subtitle { get { return subtitle_label.label; } set { subtitle_label.label = value; subtitle_label.visible = (value != null); } } - public new string? title { get { return this.get_title(); } set { base.set_title(value); } } - public new string? subtitle { get { return this.get_subtitle(); } set { base.set_subtitle(value); } } + public HeaderBar header_bar = new HeaderBar(); + private Label title_label = new Label("") { ellipsize=EllipsizeMode.END }; + private Label subtitle_label = new Label("") { ellipsize=EllipsizeMode.END, visible=false }; public ConversationTitlebarCsd() { - this.get_style_context().add_class("dino-right"); - show_close_button = true; - hexpand = true; + Box titles_box = new Box(Orientation.VERTICAL, 0) { valign=Align.CENTER }; + title_label.attributes = new AttrList(); + title_label.attributes.insert(Pango.attr_weight_new(Weight.BOLD)); + titles_box.append(title_label); + subtitle_label.attributes = new AttrList(); + subtitle_label.attributes.insert(Pango.attr_scale_new(Pango.Scale.SMALL)); + subtitle_label.get_style_context().add_class("dim-label"); + titles_box.append(subtitle_label); + + header_bar.set_title_widget(titles_box); + } + + public void insert_button(Widget button) { + header_bar.pack_end(button); } - public void insert_entry(Plugins.ConversationTitlebarEntry entry) { - Plugins.ConversationTitlebarWidget widget = entry.get_widget(Plugins.WidgetType.GTK); - Button gtk_widget = (Gtk.Button)widget; - this.pack_end(gtk_widget); + public Widget get_widget() { + return header_bar; } } diff --git a/main/src/ui/conversation_titlebar/menu_entry.vala b/main/src/ui/conversation_titlebar/menu_entry.vala index 9b3b6ee2..28a06c24 100644 --- a/main/src/ui/conversation_titlebar/menu_entry.vala +++ b/main/src/ui/conversation_titlebar/menu_entry.vala @@ -6,58 +6,42 @@ namespace Dino.Ui { class MenuEntry : Plugins.ConversationTitlebarEntry, Object { public string id { get { return "menu"; } } - - StreamInteractor stream_interactor; - MenuWidget widget; - - public MenuEntry(StreamInteractor stream_interactor) { - this.stream_interactor = stream_interactor; - } - public double order { get { return 0; } } - public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) { - if (type == Plugins.WidgetType.GTK) { - if (widget == null) { - widget = new MenuWidget(stream_interactor) { visible=true, sensitive=false }; - } - return widget; - } - return null; - } -} -class MenuWidget : Button, Plugins.ConversationTitlebarWidget { - - private StreamInteractor stream_interactor; + StreamInteractor stream_interactor; private Conversation? conversation; - public MenuWidget(StreamInteractor stream_interactor) { + Button button = new Button() { icon_name="open-menu-symbolic" }; + + public MenuEntry(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; - image = new Image.from_icon_name("open-menu-symbolic", IconSize.MENU); - clicked.connect(on_clicked); + button.clicked.connect(on_clicked); } public new void set_conversation(Conversation conversation) { - this.sensitive = true; + button.sensitive = true; this.conversation = conversation; if (conversation.type_ == Conversation.Type.GROUPCHAT) { - tooltip_text = "Channel details"; + button.tooltip_text = "Channel details"; } else { - tooltip_text = "Conversation details"; + button.tooltip_text = "Conversation details"; } } public new void unset_conversation() { - this.sensitive = false; + button.sensitive = false; } private void on_clicked() { ContactDetails.Dialog contact_details_dialog = new ContactDetails.Dialog(stream_interactor, conversation); - contact_details_dialog.set_transient_for((Window) get_toplevel()); + contact_details_dialog.set_transient_for((Window) button.get_root()); contact_details_dialog.present(); } + public Object? get_widget(Plugins.WidgetType type) { + if (type != Plugins.WidgetType.GTK4) return null; + return button; + } } - } diff --git a/main/src/ui/conversation_titlebar/occupants_entry.vala b/main/src/ui/conversation_titlebar/occupants_entry.vala index a316be20..5c0da99b 100644 --- a/main/src/ui/conversation_titlebar/occupants_entry.vala +++ b/main/src/ui/conversation_titlebar/occupants_entry.vala @@ -6,53 +6,39 @@ namespace Dino.Ui { class OccupantsEntry : Plugins.ConversationTitlebarEntry, Object { public string id { get { return "occupants"; } } + public double order { get { return 3; } } StreamInteractor stream_interactor; - OccupantsWidget widget; - - public OccupantsEntry(StreamInteractor stream_interactor) { - this.stream_interactor = stream_interactor; - } - - public double order { get { return 3; } } - public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) { - if (type == Plugins.WidgetType.GTK) { - if (widget == null) { - widget = new OccupantsWidget(stream_interactor); - } - return widget; - } - return null; - } -} + private Conversation? conversation; -class OccupantsWidget : MenuButton, Plugins.ConversationTitlebarWidget { + private MenuButton button = new MenuButton() { icon_name="system-users-symbolic", tooltip_text=_("Members") }; - private Conversation? conversation; - private StreamInteractor stream_interactor; private OccupantMenu.View menu = null; - public OccupantsWidget(StreamInteractor stream_interactor) { - image = new Image.from_icon_name("system-users-symbolic", IconSize.MENU); - tooltip_text = _("Members"); - + public OccupantsEntry(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; - set_use_popover(true); } public new void set_conversation(Conversation conversation) { this.conversation = conversation; - visible = conversation.type_ == Conversation.Type.GROUPCHAT; if (conversation.type_ == Conversation.Type.GROUPCHAT) { + button.visible = true; OccupantMenu.View new_menu = new OccupantMenu.View(stream_interactor, conversation); - set_popover(new_menu); + button.set_popover(new_menu); menu = new_menu; + } else { + button.visible = false; } } public new void unset_conversation() { - visible = false; + button.visible = false; + } + + public Object? get_widget(Plugins.WidgetType type) { + if (type != Plugins.WidgetType.GTK4) return null; + return button; } } diff --git a/main/src/ui/conversation_titlebar/search_entry.vala b/main/src/ui/conversation_titlebar/search_entry.vala index 109c54d7..a51d7d43 100644 --- a/main/src/ui/conversation_titlebar/search_entry.vala +++ b/main/src/ui/conversation_titlebar/search_entry.vala @@ -7,25 +7,21 @@ namespace Dino.Ui { public class SearchMenuEntry : Plugins.ConversationTitlebarEntry, Object { public string id { get { return "search"; } } + public double order { get { return 1; } } - public GlobalSearchButton search_button = new GlobalSearchButton() { tooltip_text=_("Search messages"), visible = true }; + public ToggleButton button = new ToggleButton() { tooltip_text=_("Search messages") }; public SearchMenuEntry() { - search_button.set_image(new Gtk.Image.from_icon_name("system-search-symbolic", Gtk.IconSize.MENU) { visible = true }); + button.set_icon_name("system-search-symbolic"); } - public double order { get { return 1; } } - public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) { - if (type == Plugins.WidgetType.GTK) { - return search_button; - } - return null; - } -} - -public class GlobalSearchButton : Plugins.ConversationTitlebarWidget, Gtk.ToggleButton { public new void set_conversation(Conversation conversation) { } public new void unset_conversation() { } + + public Object? get_widget(Plugins.WidgetType type) { + if (type != Plugins.WidgetType.GTK4) return null; + return button; + } } } -- cgit v1.2.3-54-g00ecf