This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch main
in repository elaro.

View the commit online.

commit 95e53eba318fbacb2204cecb921a58b34a644cb6
Author: Alastair Poole <[email protected]>
AuthorDate: Sat Nov 28 17:57:15 2026 +0000

    launcher: show unread PM count
    
    Publish the unread PM count to Unity LauncherEntry over the session
    bus using Eldbus. Subtract a conversation's unread PMs when it is
    opened or closed, and hide the badge at zero.
---
 NEWS                              |  6 +++
 src/fe-efl/meson.build            |  3 +-
 src/fe-efl/ui/elaro_ui.c          |  2 +
 src/fe-efl/ui/elaro_ui_buffers.c  | 13 +++++++
 src/fe-efl/ui/elaro_ui_launcher.c | 79 +++++++++++++++++++++++++++++++++++++++
 src/fe-efl/ui/elaro_ui_private.h  | 10 +++++
 src/fe-efl/ui/meson.build         |  1 +
 tests/fe-efl/meson.build          |  3 +-
 tests/fe-efl/test-ui-state.c      |  9 +++++
 9 files changed, 124 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 38b6a06..ecc81fd 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+========================
+Elaro 0.1.5 (Unreleased)
+========================
+
+  * The Unity launcher badge counts unread private messages and clears them when you open the conversation.
+
 ===========
 Elaro 0.1.4
 ===========
diff --git a/src/fe-efl/meson.build b/src/fe-efl/meson.build
index 96bce11..856c81c 100644
--- a/src/fe-efl/meson.build
+++ b/src/fe-efl/meson.build
@@ -1,5 +1,6 @@
 elementary_dep = declare_dependency(dependencies : [
   dependency('elementary', version : '>=1.26'), dependency('ecore-evas'), intl_dep])
+eldbus_dep = dependency('eldbus')
 eet_dep = dependency('eet')
 ecore_file_dep = dependency('ecore-file')
 efreet_dep = dependency('efreet')
@@ -15,7 +16,7 @@ subdir('ui')
 elaro_efl = executable('elaro', 'elaro_main.c', 'elaro_music_backend.c', ui_sources,
   include_directories : rootinc,
   link_with : [config_lib, engine_lib, libconfig_a, libcore_a, libirc_a],
-  dependencies : [elementary_dep, eet_dep, ecore_file_dep, efreet_dep],
+  dependencies : [elementary_dep, eet_dep, ecore_file_dep, efreet_dep, eldbus_dep],
   c_args : ['-DELARO_BUILD_DIR="' + meson.project_build_root() + '"'],
   link_depends : elaro_assets,
   export_dynamic : true,
diff --git a/src/fe-efl/ui/elaro_ui.c b/src/fe-efl/ui/elaro_ui.c
index b7ed42f..1d17ca2 100644
--- a/src/fe-efl/ui/elaro_ui.c
+++ b/src/fe-efl/ui/elaro_ui.c
@@ -442,7 +442,9 @@ elaro_ui_run(int argc, char **argv)
    evas_object_show(ui.win);
 
    if (argc == 2 && !strcmp(argv[1], "--smoke-test")) ecore_timer_add(2.0, _smoke_done_cb, NULL);
+   elaro_ui_launcher_init(&ui);
    if (events) elm_run();
+   elaro_ui_launcher_shutdown(&ui);
    if (events) ecore_main_fd_handler_del(events);
 
    elaro_ui_layout_capture(&ui);
diff --git a/src/fe-efl/ui/elaro_ui_buffers.c b/src/fe-efl/ui/elaro_ui_buffers.c
index 1bce217..c21f4f5 100644
--- a/src/fe-efl/ui/elaro_ui_buffers.c
+++ b/src/fe-efl/ui/elaro_ui_buffers.c
@@ -544,6 +544,11 @@ _select_buffer(void *data, Evas_Object *obj, void *info)
    free(safe);
    ui->current = b;
 
+   if (b->unread_private_messages)
+     {
+        elaro_ui_launcher_count_add(ui, -b->unread_private_messages);
+        b->unread_private_messages = 0;
+     }
    if (b->unread)
      {
         b->unread = EINA_FALSE;
@@ -738,6 +743,8 @@ _buffer_free(void *data)
    char *text;
 
    b = data;
+   if (b->unread_private_messages)
+      elaro_ui_launcher_count_add(b->app, -b->unread_private_messages);
    EINA_LIST_FREE (b->input_history, text)
      {
         free(text);
@@ -993,6 +1000,12 @@ elaro_ui_buffer_event(Elaro_Ui *ui, const Elaro_Engine_Event *e)
      {
         b = elaro_ui_buffer_get(ui, e->server, e->target);
         if (!b) return;
+        if (e->type == ELARO_ENGINE_LINE && e->private_message && !b->channel
+            && *b->target && b != ui->current)
+          {
+             b->unread_private_messages++;
+             elaro_ui_launcher_count_add(ui, 1);
+          }
         if (e->type == ELARO_ENGINE_LINE && e->private_message && ui->config
             && b != ui->current)
           {
diff --git a/src/fe-efl/ui/elaro_ui_launcher.c b/src/fe-efl/ui/elaro_ui_launcher.c
new file mode 100644
index 0000000..fde3f06
--- /dev/null
+++ b/src/fe-efl/ui/elaro_ui_launcher.c
@@ -0,0 +1,79 @@
+#include <Eldbus.h>
+#include "elaro_ui_private.h"
+
+static Eina_Bool
+_property_append(Eldbus_Message_Iter *array, const char *name, const char *signature,
+                 const void *value)
+{
+   Eldbus_Message_Iter *entry, *variant;
+
+   entry = eldbus_message_iter_container_new(array, 'e', NULL);
+   if (!entry || !eldbus_message_iter_basic_append(entry, 's', name)) return EINA_FALSE;
+   variant = eldbus_message_iter_container_new(entry, 'v', signature);
+   if (!variant) return EINA_FALSE;
+   if (*signature == 'x')
+     {
+        if (!eldbus_message_iter_basic_append(variant, 'x', *(const int64_t *)value))
+           return EINA_FALSE;
+     }
+   else if (!eldbus_message_iter_basic_append(variant, 'b', *(const Eina_Bool *)value))
+      return EINA_FALSE;
+
+   return eldbus_message_iter_container_close(entry, variant)
+      && eldbus_message_iter_container_close(array, entry);
+}
+
+static void
+_count_publish(Eldbus_Connection *bus, int64_t count)
+{
+   Eldbus_Message *message;
+   Eldbus_Message_Iter *root, *properties;
+   Eina_Bool visible = count > 0;
+
+   message = eldbus_message_signal_new("/com/canonical/Unity/LauncherEntry/elaro",
+                                       "com.canonical.Unity.LauncherEntry", "Update");
+   if (!message) return;
+   root = eldbus_message_iter_get(message);
+   if (eldbus_message_iter_basic_append(root, 's', "application://elaro.desktop"))
+     {
+        properties = eldbus_message_iter_container_new(root, 'a', "{sv}");
+        if (properties && _property_append(properties, "count", "x", &count)
+            && _property_append(properties, "count-visible", "b", &visible)
+            && eldbus_message_iter_container_close(root, properties))
+          {
+             eldbus_connection_send(bus, message, NULL, NULL, -1);
+             return;
+          }
+     }
+   eldbus_message_unref(message);
+}
+
+void
+elaro_ui_launcher_init(Elaro_Ui *ui)
+{
+   if (!eldbus_init()) return;
+   ui->launcher_bus = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
+   if (!ui->launcher_bus)
+     {
+        eldbus_shutdown();
+        return;
+     }
+   _count_publish(ui->launcher_bus, ui->unread_private_messages);
+}
+
+void
+elaro_ui_launcher_shutdown(Elaro_Ui *ui)
+{
+   if (!ui->launcher_bus) return;
+   _count_publish(ui->launcher_bus, 0);
+   eldbus_connection_unref(ui->launcher_bus);
+   ui->launcher_bus = NULL;
+   eldbus_shutdown();
+}
+
+void
+elaro_ui_launcher_count_add(Elaro_Ui *ui, int64_t difference)
+{
+   ui->unread_private_messages += difference;
+   if (ui->launcher_bus) _count_publish(ui->launcher_bus, ui->unread_private_messages);
+}
diff --git a/src/fe-efl/ui/elaro_ui_private.h b/src/fe-efl/ui/elaro_ui_private.h
index cfcfa43..c073e0a 100644
--- a/src/fe-efl/ui/elaro_ui_private.h
+++ b/src/fe-efl/ui/elaro_ui_private.h
@@ -2,6 +2,9 @@
 #define ELARO_UI_PRIVATE_H
 
 #include "elaro_ui.h"
+#include <stdint.h>
+
+typedef struct _Eldbus_Connection Eldbus_Connection;
 #include "../elaro_intl.h"
 #include "../../engine/elaro_engine.h"
 #include "../elaro_config.h"
@@ -20,6 +23,7 @@ struct _Elaro_Ui_Buffer
    int connection_port;
    Eina_Bool connected;
    Eina_Bool channel, unread, mention, user_count_known, away;
+   int64_t unread_private_messages;
    unsigned int user_count;
    unsigned int user_scroll_index; /* First visible row, one-based. */
    Eina_Strbuf *history;
@@ -33,6 +37,8 @@ struct _Elaro_Ui_Buffer
 /* Main-loop state only. The worker sees copied commands and events. */
 struct _Elaro_Ui
 {
+   Eldbus_Connection *launcher_bus;
+   int64_t unread_private_messages;
    Elaro_Config *config;
    char *config_error, *binary;
    Elaro_Engine *engine;
@@ -101,4 +107,8 @@ struct _Elaro_Ui
 #include "elaro_ui_links.h"
 #include "elaro_ui_notify.h"
 
+void elaro_ui_launcher_init(Elaro_Ui *ui);
+void elaro_ui_launcher_shutdown(Elaro_Ui *ui);
+void elaro_ui_launcher_count_add(Elaro_Ui *ui, int64_t difference);
+
 #endif
diff --git a/src/fe-efl/ui/meson.build b/src/fe-efl/ui/meson.build
index 3f1dc7e..0fa393b 100644
--- a/src/fe-efl/ui/meson.build
+++ b/src/fe-efl/ui/meson.build
@@ -13,6 +13,7 @@ ui_sources = files(
   'elaro_ui_links.c',
   'elaro_ui_music.c',
   'elaro_ui_notify.c',
+  'elaro_ui_launcher.c',
   'elaro_ui_text.c',
   'elaro_ui_theme.c',
   'elaro_ui_users.c',
diff --git a/tests/fe-efl/meson.build b/tests/fe-efl/meson.build
index 914634d..4666c33 100644
--- a/tests/fe-efl/meson.build
+++ b/tests/fe-efl/meson.build
@@ -96,11 +96,12 @@ test('EFL strings and process arguments', efl_util_test, timeout : 10,
 ui_state_test = executable('test-ui-state', 'test-ui-state.c',
   '../../src/engine/elaro_command.c',
   '../../src/fe-efl/ui/elaro_ui_buffers.c', '../../src/fe-efl/ui/elaro_ui_users.c',
+  '../../src/fe-efl/ui/elaro_ui_launcher.c',
   '../../src/fe-efl/ui/elaro_ui_avatar.c', '../../src/fe-efl/ui/elaro_ui_history.c',
   '../../src/fe-efl/ui/elaro_ui_util.c', '../../src/fe-efl/ui/elaro_ui_text.c',
   include_directories : rootinc,
   link_with : frontend_support,
-  dependencies : [elementary_dep, ecore_file_dep])
+  dependencies : [elementary_dep, ecore_file_dep, eldbus_dep])
 test('EFL conversations and user state', python,
   args : [files('isolated.py'), ui_state_test], timeout : 15,
   env : ['ELM_ENGINE=buffer', 'ECORE_NO_SYSTEM_MODULES=1', 'EINA_LOG_LEVEL=0'])
diff --git a/tests/fe-efl/test-ui-state.c b/tests/fe-efl/test-ui-state.c
index 1609565..2477b14 100644
--- a/tests/fe-efl/test-ui-state.c
+++ b/tests/fe-efl/test-ui-state.c
@@ -1175,6 +1175,7 @@ int main(int argc, char **argv)
                                  .private_message = true };
         elm_genlist_item_selected_set(elaro_ui_buffer_get(&ui, "test", "#active")->item, EINA_TRUE);
         ui.config = &config;
+        int64_t unread_before = ui.unread_private_messages;
         elaro_ui_buffer_event(&ui, &pm);
         assert(notifications == 1 && sounds == 0);
         config.enable_sounds = 1;
@@ -1198,6 +1199,14 @@ int main(int argc, char **argv)
         config.enable_sounds = 1;
         elaro_ui_buffer_event(&ui, &pm);
         assert(notifications == 3 && sounds == 2);
+        assert(ui.unread_private_messages == unread_before + 4);
+        pm.target = "#mention";
+        pm.channel_message = true;
+        pm.mention = true;
+        elaro_ui_buffer_event(&ui, &pm);
+        assert(ui.unread_private_messages == unread_before + 4);
+        elaro_ui_buffer_select(elaro_ui_buffer_get(&ui, "test", "Someone"));
+        assert(ui.unread_private_messages == unread_before);
         ui.config = NULL;
     }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to