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 +++++++++-------------- 1 file changed, 26 insertions(+), 43 deletions(-) (limited to 'main/src/ui/conversation_titlebar/call_entry.vala') 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; + } } } -- cgit v1.2.3-54-g00ecf