From 50f97ccbf3f672ecd6d37cab3fa8c59ead9d1631 Mon Sep 17 00:00:00 2001 From: Miquel Lionel Date: Sun, 15 Sep 2024 17:54:59 +0200 Subject: Enable setting your own presence - added 1 new icon for xa (extended away/unavailable) --- main/CMakeLists.txt | 2 ++ main/data/conversation_list_titlebar.ui | 13 ++++++++++ main/data/gresource.xml | 1 + main/data/icons/scalable/status/dino-status-xa.svg | 6 +++++ main/data/menu_presence.ui | 23 +++++++++++++++++ main/src/ui/application.vala | 29 ++++++++++++++++++++++ main/src/ui/conversation_list_titlebar.vala | 18 +++++++++++--- main/src/ui/main_window.vala | 7 ++++++ 8 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 main/data/icons/scalable/status/dino-status-xa.svg create mode 100644 main/data/menu_presence.ui (limited to 'main') diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 13111de8..4f76ac2b 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -45,6 +45,7 @@ set(RESOURCE_LIST icons/scalable/status/dino-double-tick-symbolic.svg icons/scalable/status/dino-party-popper-symbolic.svg icons/scalable/status/dino-security-high-symbolic.svg + icons/scalable/status/dino-status-xa.svg icons/scalable/status/dino-status-away.svg icons/scalable/status/dino-status-chat.svg icons/scalable/status/dino-status-dnd.svg @@ -83,6 +84,7 @@ set(RESOURCE_LIST conversation_content_view/item_metadata_header.ui conversation_content_view/view.ui menu_add.ui + menu_presence.ui menu_app.ui menu_conversation.ui menu_encryption.ui diff --git a/main/data/conversation_list_titlebar.ui b/main/data/conversation_list_titlebar.ui index afe10926..9d02bad7 100644 --- a/main/data/conversation_list_titlebar.ui +++ b/main/data/conversation_list_titlebar.ui @@ -29,5 +29,18 @@ + + + end + True + False + + + dino-status-chat + normal + + + + diff --git a/main/data/gresource.xml b/main/data/gresource.xml index 304fa7a4..817c796b 100644 --- a/main/data/gresource.xml +++ b/main/data/gresource.xml @@ -65,6 +65,7 @@ join_room_dialog2.ui menu_add.ui menu_app.ui + menu_presence.ui menu_conversation.ui menu_encryption.ui message_item_widget_edit_mode.ui diff --git a/main/data/icons/scalable/status/dino-status-xa.svg b/main/data/icons/scalable/status/dino-status-xa.svg new file mode 100644 index 00000000..35bac866 --- /dev/null +++ b/main/data/icons/scalable/status/dino-status-xa.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/main/data/menu_presence.ui b/main/data/menu_presence.ui new file mode 100644 index 00000000..71ca8677 --- /dev/null +++ b/main/data/menu_presence.ui @@ -0,0 +1,23 @@ + + + +
+ + app.presence_online + Online + + + app.presence_dnd + Do not disturb + + + app.presence_away + Away + + + app.presence_xaway + Unavailable + +
+
+
diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala index 706a61e6..ba8d411e 100644 --- a/main/src/ui/application.vala +++ b/main/src/ui/application.vala @@ -231,6 +231,35 @@ public class Dino.Ui.Application : Adw.Application, Dino.Application { call_state.reject(); }); add_action(deny_call_action); + + SimpleAction p_online_action = new SimpleAction("presence_online", null); + p_online_action.activate.connect( () => { + stream_interactor.get_module(PresenceManager.IDENTITY).send_presence(Xmpp.Presence.Stanza.SHOW_ONLINE); + window.refresh_presence_button(Xmpp.Presence.Stanza.SHOW_ONLINE); + }); + add_action(p_online_action); + + SimpleAction p_dnd_action = new SimpleAction("presence_dnd", null); + p_dnd_action.activate.connect( () => { + stream_interactor.get_module(PresenceManager.IDENTITY).send_presence(Xmpp.Presence.Stanza.SHOW_DND); + window.refresh_presence_button(Xmpp.Presence.Stanza.SHOW_DND); + }); + add_action(p_dnd_action); + + SimpleAction p_away_action = new SimpleAction("presence_away", null); + p_away_action.activate.connect( () => { + stream_interactor.get_module(PresenceManager.IDENTITY).send_presence(Xmpp.Presence.Stanza.SHOW_AWAY); + window.refresh_presence_button(Xmpp.Presence.Stanza.SHOW_AWAY); + }); + add_action(p_away_action); + + SimpleAction p_xaway_action = new SimpleAction("presence_xaway", null); + p_xaway_action.activate.connect( () => { + stream_interactor.get_module(PresenceManager.IDENTITY).send_presence(Xmpp.Presence.Stanza.SHOW_XA); + window.refresh_presence_button(Xmpp.Presence.Stanza.SHOW_XA); + }); + add_action(p_xaway_action); + } private void show_preferences_window() { diff --git a/main/src/ui/conversation_list_titlebar.vala b/main/src/ui/conversation_list_titlebar.vala index 51dbdcf6..340a6389 100644 --- a/main/src/ui/conversation_list_titlebar.vala +++ b/main/src/ui/conversation_list_titlebar.vala @@ -4,21 +4,33 @@ using Dino.Entities; namespace Dino.Ui { -public static Adw.HeaderBar get_conversation_list_titlebar() { +public static Adw.HeaderBar get_conversation_list_titlebar(string presence = "") { Builder builder = new Builder.from_resource("/im/dino/Dino/conversation_list_titlebar.ui"); MenuButton add_button = (MenuButton) builder.get_object("add_button"); + MenuButton presence_button = (MenuButton) builder.get_object("presence_button"); MenuButton menu_button = (MenuButton) builder.get_object("menu_button"); - create_add_menu(add_button, menu_button); + switch(presence) { + case Xmpp.Presence.Stanza.SHOW_AWAY: presence_button.set_icon_name("dino-status-away"); break; + case Xmpp.Presence.Stanza.SHOW_DND: presence_button.set_icon_name("dino-status-dnd"); break; + case Xmpp.Presence.Stanza.SHOW_XA: presence_button.set_icon_name("dino-status-xa"); break; + case "offline": presence_button.set_icon_name("dino-status-offline"); break; + default: presence_button.set_icon_name("dino-status-online"); break; + } + create_add_menu(add_button, presence_button, menu_button); return (Adw.HeaderBar) builder.get_object("header_bar"); } -private static void create_add_menu(MenuButton add_button, MenuButton menu_button) { +private static void create_add_menu(MenuButton add_button, MenuButton presence_button, MenuButton menu_button) { add_button.tooltip_text = Util.string_if_tooltips_active(_("Start Conversation")); Builder add_builder = new Builder.from_resource("/im/dino/Dino/menu_add.ui"); MenuModel add_menu_model = add_builder.get_object("menu_add") as MenuModel; add_button.set_menu_model(add_menu_model); + Builder presence_builder = new Builder.from_resource("/im/dino/Dino/menu_presence.ui"); + MenuModel presence_menu_model = presence_builder.get_object("menu_presence") as MenuModel; + presence_button.set_menu_model(presence_menu_model); + Builder menu_builder = new Builder.from_resource("/im/dino/Dino/menu_app.ui"); MenuModel menu_menu_model = menu_builder.get_object("menu_app") as MenuModel; menu_button.set_menu_model(menu_menu_model); diff --git a/main/src/ui/main_window.vala b/main/src/ui/main_window.vala index e3110336..765ecc25 100644 --- a/main/src/ui/main_window.vala +++ b/main/src/ui/main_window.vala @@ -87,6 +87,13 @@ public class MainWindow : Adw.ApplicationWindow { conversation_titlebar.back_pressed.connect(() => leaflet.navigate(Adw.NavigationDirection.BACK)); } + public void refresh_presence_button(string presence = "") { + conversation_list_titlebar.unparent(); + conversation_list_titlebar = get_conversation_list_titlebar(presence); + leaflet.bind_property("folded", conversation_list_titlebar, "show-end-title-buttons", BindingFlags.SYNC_CREATE); + left_box.prepend(conversation_list_titlebar); + } + private void setup_stack() { stack.add_named(box, "main"); stack.add_named(welcome_placeholder, "welcome_placeholder"); -- cgit v1.2.3-70-g09d2