From bb7b522ef52b240718f33f37b577bacc4fea2db6 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Mon, 18 Apr 2016 23:42:53 -0300 Subject: Post message on messaging menu if the notification get timeout. --- src/notifications.cpp | 127 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 122 insertions(+), 5 deletions(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index 051653d..2d22087 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -21,10 +21,18 @@ #include +#include +#include + + +#include + #include #include #include #include +#include + namespace ayatana { namespace indicator { @@ -45,9 +53,11 @@ public: std::string m_body; std::string m_icon_name; std::chrono::seconds m_duration; + gint64 m_start_time; std::set m_string_hints; std::vector> m_actions; std::function m_closed_callback; + std::function m_missed_click_callback; }; Builder::Builder(): @@ -101,6 +111,18 @@ Builder::set_closed_callback (std::function cb) impl->m_closed_callback.swap (cb); } +void +Builder::set_missed_click_callback (std::function cb) +{ + impl->m_missed_click_callback.swap (cb); +} + +void +Builder::set_start_time (uint64_t time) +{ + impl->m_start_time = time; +} + /*** **** ***/ @@ -110,23 +132,39 @@ class Engine::Impl struct notification_data { std::shared_ptr nn; - std::function closed_callback; + Builder::Impl data; + }; + + struct messaging_menu_data + { + std::shared_ptr mm; + std::function callback; }; public: Impl(const std::string& app_name): + m_messaging_app(messaging_menu_app_new(DATETIME_INDICATOR_DESKTOP_FILE), g_object_unref), m_app_name(app_name) { if (!notify_init(app_name.c_str())) g_critical("Unable to initialize libnotify!"); + + // messaging menu + GIcon *icon = g_themed_icon_new("calendar-app"); + + messaging_menu_app_register(m_messaging_app.get()); + messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), icon, "Calendar"); + g_object_unref(icon); } ~Impl() { close_all (); + remove_all (); notify_uninit (); + messaging_menu_app_unregister (m_messaging_app.get()); } const std::string& app_name() const @@ -217,7 +255,7 @@ public: notification_key_quark(), GINT_TO_POINTER(key)); - m_notifications[key] = { nn, info.m_closed_callback }; + m_notifications[key] = { nn, info }; g_signal_connect (nn.get(), "closed", G_CALLBACK(on_notification_closed), this); @@ -238,6 +276,59 @@ public: return ret; } + std::string post(const Builder::Impl& data) + { + uuid_t message_uuid; + uuid_generate(message_uuid); + + char message_id[37]; + uuid_unparse(message_uuid, message_id); + + GIcon *icon = g_themed_icon_new(data.m_icon_name.c_str()); + std::shared_ptr msg (messaging_menu_message_new(message_id, + icon, + data.m_title.c_str(), + nullptr, + data.m_body.c_str(), + data.m_start_time * 1000000), // secs -> microsecs + g_object_ref); + g_object_unref(icon); + if (msg) + { + m_messaging_messages[std::string(message_id)] = { msg, data.m_missed_click_callback }; + g_signal_connect(msg.get(), "activate", + G_CALLBACK(on_message_activated), this); + messaging_menu_app_append_message(m_messaging_app.get(), msg.get(), m_app_name.c_str(), false); + return message_id; + } else { + g_warning("Fail to create messaging menu message"); + } + return ""; + } + + void remove (const std::string &key) + { + auto it = m_messaging_messages.find(key); + if (it != m_messaging_messages.end()) + { + // tell the server to remove message + messaging_menu_app_remove_message(m_messaging_app.get(), it->second.mm.get()); + m_messaging_messages.erase(it); + } + } + + void remove_all () + { + // call remove() on all our keys + + std::set keys; + for (const auto& it : m_messaging_messages) + keys.insert (it.first); + + for (const std::string &key : keys) + remove (key); + } + private: const std::set& server_caps() const @@ -279,6 +370,22 @@ private: static_cast(gself)->remove_closed_notification(GPOINTER_TO_INT(gkey)); } + static void on_message_activated (MessagingMenuMessage *, + const char *actionId, + GVariant *, + gpointer gself) + { + auto self = static_cast(gself); + auto it = self->m_messaging_messages.find(actionId); + g_return_if_fail (it != self->m_messaging_messages.end()); + const auto& ndata = it->second; + + if (ndata.callback) + ndata.callback(); + + self->m_messaging_messages.erase(it); + } + void remove_closed_notification (int key) { auto it = m_notifications.find(key); @@ -286,16 +393,20 @@ private: const auto& ndata = it->second; auto nn = ndata.nn.get(); - if (ndata.closed_callback) + + if (ndata.data.m_closed_callback) { std::string action; - const GQuark q = notification_action_quark(); const gpointer p = g_object_get_qdata(G_OBJECT(nn), q); if (p != nullptr) action = static_cast(p); - ndata.closed_callback (action); + ndata.data.m_closed_callback (action); + // empty action means that the notification got timeout + // post a message on messaging menu + if (action.empty()) + post(ndata.data); } m_notifications.erase(it); @@ -305,6 +416,10 @@ private: **** ***/ + // messaging menu + std::shared_ptr m_messaging_app; + std::map m_messaging_messages; + const std::string m_app_name; // key-to-data @@ -315,6 +430,8 @@ private: mutable std::set m_lazy_caps; static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"}; + static constexpr char const * DATETIME_INDICATOR_DESKTOP_FILE {"indicator-datetime.desktop"}; + static constexpr char const * DATETIME_INDICATOR_SOURCE_ID {"indicator-datetime"}; }; /*** -- cgit v1.2.3 From 8d5fb6cbdab5c7b12441fbce68821b91e1645132 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 19 Apr 2016 12:09:03 -0300 Subject: Fixed crash when clicking on messaging menu. --- src/notifications.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index 2d22087..5b64471 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -291,7 +291,7 @@ public: nullptr, data.m_body.c_str(), data.m_start_time * 1000000), // secs -> microsecs - g_object_ref); + g_object_unref); g_object_unref(icon); if (msg) { @@ -370,13 +370,13 @@ private: static_cast(gself)->remove_closed_notification(GPOINTER_TO_INT(gkey)); } - static void on_message_activated (MessagingMenuMessage *, - const char *actionId, + static void on_message_activated (MessagingMenuMessage *msg, + const char *, GVariant *, gpointer gself) { auto self = static_cast(gself); - auto it = self->m_messaging_messages.find(actionId); + auto it = self->m_messaging_messages.find(messaging_menu_message_get_id(msg)); g_return_if_fail (it != self->m_messaging_messages.end()); const auto& ndata = it->second; -- cgit v1.2.3 From 605ece31c05b571e8855bcec57550cd067c2f7bb Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 20 Apr 2016 11:00:35 -0300 Subject: Fix memory leak on messaging_menu. --- src/notifications.cpp | 68 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 27 deletions(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index 5b64471..076ad13 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -137,8 +137,9 @@ class Engine::Impl struct messaging_menu_data { - std::shared_ptr mm; + std::string msg_id; std::function callback; + Engine::Impl *self; }; public: @@ -151,11 +152,7 @@ public: g_critical("Unable to initialize libnotify!"); // messaging menu - GIcon *icon = g_themed_icon_new("calendar-app"); - messaging_menu_app_register(m_messaging_app.get()); - messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), icon, "Calendar"); - g_object_unref(icon); } ~Impl() @@ -285,20 +282,31 @@ public: uuid_unparse(message_uuid, message_id); GIcon *icon = g_themed_icon_new(data.m_icon_name.c_str()); - std::shared_ptr msg (messaging_menu_message_new(message_id, - icon, - data.m_title.c_str(), - nullptr, - data.m_body.c_str(), - data.m_start_time * 1000000), // secs -> microsecs - g_object_unref); + + // check if source exists + if (!messaging_menu_app_has_source(m_messaging_app.get(), m_app_name.c_str())) + messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), icon, "Calendar"); + + auto msg = messaging_menu_message_new(message_id, + icon, + data.m_title.c_str(), + nullptr, + data.m_body.c_str(), + data.m_start_time * 1000000); // secs -> microsecs g_object_unref(icon); if (msg) { - m_messaging_messages[std::string(message_id)] = { msg, data.m_missed_click_callback }; - g_signal_connect(msg.get(), "activate", - G_CALLBACK(on_message_activated), this); - messaging_menu_app_append_message(m_messaging_app.get(), msg.get(), m_app_name.c_str(), false); + std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_missed_click_callback, this}); + m_messaging_messages[std::string(message_id)] = msg_data; + g_signal_connect(G_OBJECT(msg), "activate", + G_CALLBACK(on_message_activated), msg_data.get()); + messaging_menu_app_append_message(m_messaging_app.get(), msg, m_app_name.c_str(), false); + + // we use that to keep track of messaging, in case of message get cleared from menu + g_object_set_data_full(G_OBJECT(msg), "destroy-notify", msg_data.get(), on_message_destroyed); + // keep the message control with message_menu + g_object_unref(msg); + return message_id; } else { g_warning("Fail to create messaging menu message"); @@ -312,8 +320,8 @@ public: if (it != m_messaging_messages.end()) { // tell the server to remove message - messaging_menu_app_remove_message(m_messaging_app.get(), it->second.mm.get()); - m_messaging_messages.erase(it); + messaging_menu_app_remove_message_by_id(m_messaging_app.get(), it->second->msg_id.c_str()); + // message will be remove by on_message_destroyed cb. } } @@ -370,20 +378,26 @@ private: static_cast(gself)->remove_closed_notification(GPOINTER_TO_INT(gkey)); } - static void on_message_activated (MessagingMenuMessage *msg, + static void on_message_activated (MessagingMenuMessage *, const char *, GVariant *, - gpointer gself) + gpointer data) { - auto self = static_cast(gself); - auto it = self->m_messaging_messages.find(messaging_menu_message_get_id(msg)); - g_return_if_fail (it != self->m_messaging_messages.end()); + auto msg_data = static_cast(data); + auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id.c_str()); + g_return_if_fail (it != msg_data->self->m_messaging_messages.end()); const auto& ndata = it->second; - if (ndata.callback) - ndata.callback(); + if (ndata->callback) + ndata->callback(); + } - self->m_messaging_messages.erase(it); + static void on_message_destroyed(gpointer data) + { + auto msg_data = static_cast(data); + auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id.c_str()); + if (it != msg_data->self->m_messaging_messages.end()) + msg_data->self->m_messaging_messages.erase(it); } void remove_closed_notification (int key) @@ -418,7 +432,7 @@ private: // messaging menu std::shared_ptr m_messaging_app; - std::map m_messaging_messages; + std::map > m_messaging_messages; const std::string m_app_name; -- cgit v1.2.3 From 0c654b464fa215190c5fef74e8aa6e0d951224e7 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 26 Apr 2016 12:02:03 -0300 Subject: Fixed as reviewer requested. --- src/notifications.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index 076ad13..f3dcb14 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -278,8 +278,9 @@ public: uuid_t message_uuid; uuid_generate(message_uuid); - char message_id[37]; - uuid_unparse(message_uuid, message_id); + char uuid_buf[37]; + uuid_unparse(message_uuid, uuid_buf); + const std::string message_id(uuid_buf); GIcon *icon = g_themed_icon_new(data.m_icon_name.c_str()); @@ -287,7 +288,7 @@ public: if (!messaging_menu_app_has_source(m_messaging_app.get(), m_app_name.c_str())) messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), icon, "Calendar"); - auto msg = messaging_menu_message_new(message_id, + auto msg = messaging_menu_message_new(message_id.c_str(), icon, data.m_title.c_str(), nullptr, @@ -297,7 +298,7 @@ public: if (msg) { std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_missed_click_callback, this}); - m_messaging_messages[std::string(message_id)] = msg_data; + m_messaging_messages[message_id] = msg_data; g_signal_connect(G_OBJECT(msg), "activate", G_CALLBACK(on_message_activated), msg_data.get()); messaging_menu_app_append_message(m_messaging_app.get(), msg, m_app_name.c_str(), false); -- cgit v1.2.3 From 47668a01943088e23bd586f5bb26110ad2867727 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 26 Apr 2016 15:34:30 -0300 Subject: Make use of G_USEC_PER_SEC. --- src/notifications.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index f3dcb14..f59a421 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -293,7 +293,7 @@ public: data.m_title.c_str(), nullptr, data.m_body.c_str(), - data.m_start_time * 1000000); // secs -> microsecs + data.m_start_time * G_USEC_PER_SEC); // secs -> microsecs g_object_unref(icon); if (msg) { -- cgit v1.2.3 From 02ea97a63928c5da4ca1882d34ae61076b06c945 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 27 Apr 2016 14:01:28 -0300 Subject: Use calendar app icon. --- src/notifications.cpp | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index f59a421..dc42534 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -24,9 +24,14 @@ #include #include +#ifdef HAS_LOMIRIAPPLAUNCH +#include +#endif #include +#include + #include #include #include @@ -145,7 +150,7 @@ class Engine::Impl public: Impl(const std::string& app_name): - m_messaging_app(messaging_menu_app_new(DATETIME_INDICATOR_DESKTOP_FILE), g_object_unref), + m_messaging_app(messaging_menu_app_new(calendar_app_id().c_str()), g_object_unref), m_app_name(app_name) { if (!notify_init(app_name.c_str())) @@ -282,11 +287,15 @@ public: uuid_unparse(message_uuid, uuid_buf); const std::string message_id(uuid_buf); - GIcon *icon = g_themed_icon_new(data.m_icon_name.c_str()); + // use full icon path name, "calendar-app" does not work with themed icons + auto icon_file = g_file_new_for_path(calendar_app_icon().c_str()); + // messaging_menu_message_new: will take control of icon object + GIcon *icon = g_file_icon_new(icon_file); + g_object_unref(icon_file); // check if source exists if (!messaging_menu_app_has_source(m_messaging_app.get(), m_app_name.c_str())) - messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), icon, "Calendar"); + messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), nullptr, "Calendar"); auto msg = messaging_menu_message_new(message_id.c_str(), icon, @@ -294,7 +303,6 @@ public: nullptr, data.m_body.c_str(), data.m_start_time * G_USEC_PER_SEC); // secs -> microsecs - g_object_unref(icon); if (msg) { std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_missed_click_callback, this}); @@ -427,6 +435,31 @@ private: m_notifications.erase(it); } + static std::string calendar_app_id() + { + #ifdef HAS_LOMIRIAPPLAUNCH + auto app_id = lomiri::app_launch::AppID::discover("com.lomiri.calendar"); + return std::string(app_id) + ".desktop"; + #else + return ""; + #endif + } + + static std::string calendar_app_icon() + { + auto app_desktop = g_desktop_app_info_new(calendar_app_id().c_str()); + if (app_desktop != nullptr) { + auto icon_name = g_desktop_app_info_get_string(app_desktop, "Icon"); + g_object_unref(app_desktop); + std::string result(icon_name); + g_free(icon_name); + return result; + } else { + g_warning("Fail to get calendar icon"); + return std::string(); + } + } + /*** **** ***/ -- cgit v1.2.3 From 7ecfadf5eb61fe32332293ec6de2fe18bfedf0fa Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 27 Apr 2016 14:31:28 -0300 Subject: Only creates messaging menu if calendar app is instaled. Update tests. --- src/notifications.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index dc42534..9817686 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -150,14 +150,17 @@ class Engine::Impl public: Impl(const std::string& app_name): - m_messaging_app(messaging_menu_app_new(calendar_app_id().c_str()), g_object_unref), m_app_name(app_name) { if (!notify_init(app_name.c_str())) g_critical("Unable to initialize libnotify!"); // messaging menu - messaging_menu_app_register(m_messaging_app.get()); + auto app_id = calendar_app_id(); + if (!app_id.empty()) { + m_messaging_app.reset(messaging_menu_app_new(app_id.c_str()), g_object_unref); + messaging_menu_app_register(m_messaging_app.get()); + } } ~Impl() @@ -166,7 +169,8 @@ public: remove_all (); notify_uninit (); - messaging_menu_app_unregister (m_messaging_app.get()); + if (m_messaging_app) + messaging_menu_app_unregister (m_messaging_app.get()); } const std::string& app_name() const @@ -280,6 +284,9 @@ public: std::string post(const Builder::Impl& data) { + if (!m_messaging_app) { + return std::string(); + } uuid_t message_uuid; uuid_generate(message_uuid); @@ -439,9 +446,14 @@ private: { #ifdef HAS_LOMIRIAPPLAUNCH auto app_id = lomiri::app_launch::AppID::discover("com.lomiri.calendar"); - return std::string(app_id) + ".desktop"; + + if (!app_id.empty()) + return std::string(app_id) + ".desktop"; + else + return std::string(); + #else - return ""; + return std::string(); #endif } -- cgit v1.2.3 From 0fb4679e9043ba2591055f46445294cf508be0fb Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 28 Apr 2016 09:35:05 -0300 Subject: Small fixes requeted by charles during the review. --- src/notifications.cpp | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index 9817686..3c90e57 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -58,11 +58,11 @@ public: std::string m_body; std::string m_icon_name; std::chrono::seconds m_duration; - gint64 m_start_time; + gint64 m_start_time {}; std::set m_string_hints; std::vector> m_actions; std::function m_closed_callback; - std::function m_missed_click_callback; + std::function m_timeout_callback; }; Builder::Builder(): @@ -117,9 +117,9 @@ Builder::set_closed_callback (std::function cb) } void -Builder::set_missed_click_callback (std::function cb) +Builder::set_timeout_callback (std::function cb) { - impl->m_missed_click_callback.swap (cb); + impl->m_timeout_callback.swap (cb); } void @@ -312,7 +312,7 @@ public: data.m_start_time * G_USEC_PER_SEC); // secs -> microsecs if (msg) { - std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_missed_click_callback, this}); + std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_timeout_callback, this}); m_messaging_messages[message_id] = msg_data; g_signal_connect(G_OBJECT(msg), "activate", G_CALLBACK(on_message_activated), msg_data.get()); @@ -344,13 +344,8 @@ public: void remove_all () { // call remove() on all our keys - - std::set keys; - for (const auto& it : m_messaging_messages) - keys.insert (it.first); - - for (const std::string &key : keys) - remove (key); + while (!m_messaging_messages.empty()) + remove(m_messaging_messages.begin()->first); } private: @@ -400,7 +395,7 @@ private: gpointer data) { auto msg_data = static_cast(data); - auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id.c_str()); + auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id); g_return_if_fail (it != msg_data->self->m_messaging_messages.end()); const auto& ndata = it->second; @@ -411,7 +406,7 @@ private: static void on_message_destroyed(gpointer data) { auto msg_data = static_cast(data); - auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id.c_str()); + auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id); if (it != msg_data->self->m_messaging_messages.end()) msg_data->self->m_messaging_messages.erase(it); } @@ -448,6 +443,7 @@ private: auto app_id = lomiri::app_launch::AppID::discover("com.lomiri.calendar"); if (!app_id.empty()) + // Due the use of old API by messaging_menu we need append a extra ".desktop" to the app_id. return std::string(app_id) + ".desktop"; else return std::string(); @@ -463,13 +459,14 @@ private: if (app_desktop != nullptr) { auto icon_name = g_desktop_app_info_get_string(app_desktop, "Icon"); g_object_unref(app_desktop); - std::string result(icon_name); - g_free(icon_name); - return result; - } else { - g_warning("Fail to get calendar icon"); - return std::string(); + if (icon_name) { + std::string result(icon_name); + g_free(icon_name); + return result; + } } + g_warning("Fail to get calendar icon"); + return std::string(); } /*** @@ -490,8 +487,6 @@ private: mutable std::set m_lazy_caps; static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"}; - static constexpr char const * DATETIME_INDICATOR_DESKTOP_FILE {"indicator-datetime.desktop"}; - static constexpr char const * DATETIME_INDICATOR_SOURCE_ID {"indicator-datetime"}; }; /*** -- cgit v1.2.3 From f42d0a01dcbd66920f65d1e5bd784914a797d773 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Wed, 29 Jun 2016 21:37:56 -0300 Subject: Fix notifications so it respects if it should or not show bubbles or add to notification list --- src/notifications.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index 3c90e57..4a2c846 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -63,6 +63,8 @@ public: std::vector> m_actions; std::function m_closed_callback; std::function m_timeout_callback; + bool m_show_notification_bubble; + bool m_post_to_messaging_menu; }; Builder::Builder(): @@ -128,6 +130,18 @@ Builder::set_start_time (uint64_t time) impl->m_start_time = time; } +void +Builder::set_show_notification_bubble (bool show) +{ + impl->m_show_notification_bubble = show; +} + +void +Builder::set_post_to_messaging_menu (bool post) +{ + impl->m_post_to_messaging_menu = post; +} + /*** **** ***/ @@ -265,6 +279,11 @@ public: g_signal_connect (nn.get(), "closed", G_CALLBACK(on_notification_closed), this); + if (!info.m_show_notification_bubble) { + post(info); + return ret; + } + GError * error = nullptr; if (notify_notification_show(nn.get(), &error)) { @@ -284,6 +303,10 @@ public: std::string post(const Builder::Impl& data) { + if (!data.m_post_to_messaging_menu) { + return ""; + } + if (!m_messaging_app) { return std::string(); } -- cgit v1.2.3 From 231168012760d2161318bc31498e72ada7a82716 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 21 Sep 2016 17:07:33 -0500 Subject: Use an explicit registry object so that it gets free'd when the function exits --- src/notifications.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index 4a2c846..a0ceb6f 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -26,6 +26,7 @@ #ifdef HAS_LOMIRIAPPLAUNCH #include +#include #endif #include @@ -463,7 +464,8 @@ private: static std::string calendar_app_id() { #ifdef HAS_LOMIRIAPPLAUNCH - auto app_id = lomiri::app_launch::AppID::discover("com.lomiri.calendar"); + auto registry = std::make_shared(); + auto app_id = lomiri::app_launch::AppID::discover(registry, "com.lomiri.calendar"); if (!app_id.empty()) // Due the use of old API by messaging_menu we need append a extra ".desktop" to the app_id. -- cgit v1.2.3 From 5b5755d1c4f3fc9823e98be43c18201740393679 Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Wed, 1 Feb 2017 16:55:16 -0500 Subject: Update app name usage to match snaps. --- src/notifications.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index a0ceb6f..49300d8 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -465,7 +465,7 @@ private: { #ifdef HAS_LOMIRIAPPLAUNCH auto registry = std::make_shared(); - auto app_id = lomiri::app_launch::AppID::discover(registry, "com.lomiri.calendar"); + auto app_id = lomiri::app_launch::AppID::discover(registry, "lomiri-calendar-app"); if (!app_id.empty()) // Due the use of old API by messaging_menu we need append a extra ".desktop" to the app_id. -- cgit v1.2.3 From f557230cf66dd2278729201140c2d6812d9e3c72 Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Wed, 31 Oct 2018 21:56:05 -0400 Subject: Replace ual with url-dispatcher. We don't really hneed ubuntu-app-launch here directly, as the API provided by url-dispatcher gives us a way to query what app handles the calendar URL, as the indicator is a trusted process. This removes the extra dependency and simplifies building slightly. --- src/notifications.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index 49300d8..7098cfc 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -24,9 +24,8 @@ #include #include -#ifdef HAS_LOMIRIAPPLAUNCH -#include -#include +#ifdef HAS_URLDISPATCHER +#include #endif #include @@ -463,16 +462,17 @@ private: static std::string calendar_app_id() { - #ifdef HAS_LOMIRIAPPLAUNCH - auto registry = std::make_shared(); - auto app_id = lomiri::app_launch::AppID::discover(registry, "lomiri-calendar-app"); - - if (!app_id.empty()) + #ifdef HAS_URLDISPATCHER + auto urls = g_strsplit("calendar://", ",", 0); + auto appids = lomiri_url_dispatch_url_appid(const_cast(urls)); + g_strfreev(urls); + std::string result; + if (appids != nullptr) { // Due the use of old API by messaging_menu we need append a extra ".desktop" to the app_id. - return std::string(app_id) + ".desktop"; - else - return std::string(); - + result = std::string(appids[0]) + ".desktop"; + g_strfreev(appids); + } + return result; #else return std::string(); #endif -- cgit v1.2.3 From e5f9e40b6d934b427eeb2cb6e83c40f3f3b5135a Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Sun, 29 Aug 2021 13:53:48 +0200 Subject: src/notifications.cpp: No indentation of #ifdef-#else-#endif compiler macro. --- src/notifications.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/notifications.cpp') diff --git a/src/notifications.cpp b/src/notifications.cpp index 7098cfc..b36227b 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -462,7 +462,7 @@ private: static std::string calendar_app_id() { - #ifdef HAS_URLDISPATCHER +#ifdef HAS_URLDISPATCHER auto urls = g_strsplit("calendar://", ",", 0); auto appids = lomiri_url_dispatch_url_appid(const_cast(urls)); g_strfreev(urls); @@ -473,9 +473,9 @@ private: g_strfreev(appids); } return result; - #else +#else return std::string(); - #endif +#endif } static std::string calendar_app_icon() -- cgit v1.2.3