From 12cd56612dd6edd056e2cd8aae59ea3ae8f05d1e Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 29 Mar 2020 20:23:47 +0200 Subject: Store entity identity info, use it in conversation list tooltips --- main/CMakeLists.txt | 6 +- main/data/conversation_row.ui | 148 +++++++++++++++++++++ .../data/conversation_selector/chat_row_tooltip.ui | 22 --- .../data/conversation_selector/conversation_row.ui | 148 --------------------- main/data/icons/dino-device-desktop-symbolic.svg | 5 + main/data/icons/dino-device-phone-symbolic.svg | 6 + .../conversation_selector_row.vala | 90 ++++++++----- 7 files changed, 220 insertions(+), 205 deletions(-) create mode 100644 main/data/conversation_row.ui delete mode 100644 main/data/conversation_selector/chat_row_tooltip.ui delete mode 100644 main/data/conversation_selector/conversation_row.ui create mode 100644 main/data/icons/dino-device-desktop-symbolic.svg create mode 100644 main/data/icons/dino-device-phone-symbolic.svg (limited to 'main') diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 5f5b7831..5dc69dcb 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -28,6 +28,9 @@ set(RESOURCE_LIST icons/im.dino.Dino-symbolic.svg icons/dino-tick-symbolic.svg + icons/dino-device-desktop-symbolic.svg + icons/dino-device-phone-symbolic.svg + icons/dino-file-document-symbolic.svg icons/dino-file-download-symbolic.svg icons/dino-file-image-symbolic.svg @@ -45,11 +48,10 @@ set(RESOURCE_LIST contact_details_dialog.ui conversation_list_titlebar.ui conversation_list_titlebar_csd.ui + conversation_row.ui conversation_view.ui emojichooser.ui global_search.ui - conversation_selector/chat_row_tooltip.ui - conversation_selector/conversation_row.ui conversation_content_view/image_toolbar.ui conversation_content_view/item_metadata_header.ui conversation_content_view/view.ui diff --git a/main/data/conversation_row.ui b/main/data/conversation_row.ui new file mode 100644 index 00000000..7772c907 --- /dev/null +++ b/main/data/conversation_row.ui @@ -0,0 +1,148 @@ + + + + diff --git a/main/data/conversation_selector/chat_row_tooltip.ui b/main/data/conversation_selector/chat_row_tooltip.ui deleted file mode 100644 index 6596cd62..00000000 --- a/main/data/conversation_selector/chat_row_tooltip.ui +++ /dev/null @@ -1,22 +0,0 @@ - - - - vertical - True - - - 0 - True - - - - - - - - vertical - True - - - - diff --git a/main/data/conversation_selector/conversation_row.ui b/main/data/conversation_selector/conversation_row.ui deleted file mode 100644 index 7772c907..00000000 --- a/main/data/conversation_selector/conversation_row.ui +++ /dev/null @@ -1,148 +0,0 @@ - - - - diff --git a/main/data/icons/dino-device-desktop-symbolic.svg b/main/data/icons/dino-device-desktop-symbolic.svg new file mode 100644 index 00000000..4e4e02ab --- /dev/null +++ b/main/data/icons/dino-device-desktop-symbolic.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/main/data/icons/dino-device-phone-symbolic.svg b/main/data/icons/dino-device-phone-symbolic.svg new file mode 100644 index 00000000..64a69e17 --- /dev/null +++ b/main/data/icons/dino-device-phone-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/main/src/ui/conversation_selector/conversation_selector_row.vala b/main/src/ui/conversation_selector/conversation_selector_row.vala index 80257a6d..6234e9c8 100644 --- a/main/src/ui/conversation_selector/conversation_selector_row.vala +++ b/main/src/ui/conversation_selector/conversation_selector_row.vala @@ -9,7 +9,7 @@ using Xmpp; namespace Dino.Ui { -[GtkTemplate (ui = "/im/dino/Dino/conversation_selector/conversation_row.ui")] +[GtkTemplate (ui = "/im/dino/Dino/conversation_row.ui")] public class ConversationSelectorRow : ListBoxRow { [GtkChild] protected AvatarImage image; @@ -217,29 +217,6 @@ public class ConversationSelectorRow : ListBoxRow { message_label.label = message_label.label; } - protected Box get_fulljid_box(Jid full_jid) { - Box box = new Box(Orientation.HORIZONTAL, 5) { visible=true }; - - Show show = stream_interactor.get_module(PresenceManager.IDENTITY).get_last_show(full_jid, conversation.account); - Image image = new Image() { visible=true }; - if (show.as == Show.AWAY) { - image.set_from_icon_name("dino-status-away", IconSize.SMALL_TOOLBAR); - } else if (show.as == Show.XA || show.as == Show.DND) { - image.set_from_icon_name("dino-status-dnd", IconSize.SMALL_TOOLBAR); - } else if (show.as == Show.CHAT) { - image.set_from_icon_name("dino-status-chat", IconSize.SMALL_TOOLBAR); - } else { - image.set_from_icon_name("dino-status-online", IconSize.SMALL_TOOLBAR); - } - box.add(image); - - Label resource = new Label(full_jid.resourcepart) { visible=true }; - resource.xalign = 0; - box.add(resource); - box.show_all(); - return box; - } - public override void state_flags_changed(StateFlags flags) { StateFlags curr_flags = get_state_flags(); if ((curr_flags & StateFlags.PRELIGHT) != 0) { @@ -251,21 +228,68 @@ public class ConversationSelectorRow : ListBoxRow { } } + private static Regex dino_resource_regex = /^dino\.[a-f0-9]{8}$/; + private Widget generate_tooltip() { - Builder builder = new Builder.from_resource("/im/dino/Dino/conversation_selector/chat_row_tooltip.ui"); - Box main_box = builder.get_object("main_box") as Box; - Box inner_box = builder.get_object("inner_box") as Box; - Label jid_label = builder.get_object("jid_label") as Label; + Grid grid = new Grid() { row_spacing=5, column_homogeneous=false, column_spacing=2, margin_start=5, margin_end=5, margin_top=2, margin_bottom=2, visible=true }; - jid_label.label = conversation.counterpart.to_string(); + Label label = new Label(conversation.counterpart.to_string()) { valign=Align.START, xalign=0, visible=true }; + label.attributes = new AttrList(); + label.attributes.insert(attr_weight_new(Weight.BOLD)); + + grid.attach(label, 0, 0, 2, 1); Gee.List? full_jids = stream_interactor.get_module(PresenceManager.IDENTITY).get_full_jids(conversation.counterpart, conversation.account); - if (full_jids != null) { - for (int i = 0; i < full_jids.size; i++) { - inner_box.add(get_fulljid_box(full_jids[i])); + if (full_jids == null) return grid; + + for (int i = 0; i < full_jids.size; i++) { + Jid full_jid = full_jids[i]; + Show show = stream_interactor.get_module(PresenceManager.IDENTITY).get_last_show(full_jid, conversation.account); + Xep.ServiceDiscovery.Identity? identity = stream_interactor.get_module(EntityInfo.IDENTITY).get_identity(conversation.account, full_jid); + + Image image = new Image() { hexpand=false, valign=Align.START, visible=true }; + grid.attach(image, 0, i + 1, 1, 1); + if (identity != null && identity.type_ == Xep.ServiceDiscovery.Identity.TYPE_PHONE || identity.type_ == Xep.ServiceDiscovery.Identity.TYPE_TABLET) { + image.set_from_icon_name("dino-device-phone-symbolic", IconSize.SMALL_TOOLBAR); + } else { + image.set_from_icon_name("dino-device-desktop-symbolic", IconSize.SMALL_TOOLBAR); } + + if (show.as == Show.AWAY) { + Util.force_color(image, "#FF9800"); + } else if (show.as == Show.XA || show.as == Show.DND) { + Util.force_color(image, "#FF5722"); + } else { + Util.force_color(image, "#4CAF50"); + } + + string? status = null; + if (show.as == Show.AWAY) { + status = "away"; + } else if (show.as == Show.XA) { + status = "not available"; + } else if (show.as == Show.DND) { + status = "do not disturb"; + } + + var sb = new StringBuilder(); + if (identity.name != null) { + sb.append(identity.name); + } else if (dino_resource_regex.match(full_jid.resourcepart)) { + sb.append("Dino"); + } else { + sb.append(full_jid.resourcepart); + } + if (status != null) { + sb.append(" ("); + sb.append(status); + sb.append(")"); + } + + Label resource = new Label(sb.str) { use_markup=true, hexpand=true, xalign=0, visible=true }; + grid.attach(resource, 1, i + 1, 1, 1); } - return main_box; + return grid; } private static string get_relative_time(DateTime datetime) { -- cgit v1.2.3-54-g00ecf