From 0eaefcd97c91978aaefb2aecffa3d564559c894e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 14 Jul 2014 21:02:55 -0500 Subject: remove use of deprecated API notify_notification_set_hint_string() --- src/snap.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 4495287..11c946a 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -260,12 +260,12 @@ private: m_nn = notify_notification_new(title, body.c_str(), icon_name); if (m_interactive) { - notify_notification_set_hint_string(m_nn, - "x-canonical-snap-decisions", - "true"); - notify_notification_set_hint_string(m_nn, - "x-canonical-private-button-tint", - "true"); + notify_notification_set_hint(m_nn, + "x-canonical-snap-decisions", + g_variant_new_boolean(true)); + notify_notification_set_hint(m_nn, + "x-canonical-private-button-tint", + g_variant_new_boolean(true)); /// alarm popup dialog's button to show the active alarm notify_notification_add_action(m_nn, "show", _("Show"), on_snap_show, this, nullptr); -- cgit v1.2.3 From ff6f8c0c1f9d649fbd46e195d11b535dfe773f8d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 14 Jul 2014 21:09:56 -0500 Subject: add x-canonical-snap-decisions-timeout hint. --- src/snap.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 11c946a..697326f 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -182,7 +182,8 @@ public: void set_clock(const std::shared_ptr& c) {m_clock = c;} void set_uri(const std::string& uri) {m_uri = uri;} void set_volume(const unsigned int v) {m_volume = v;} - void set_duration_minutes(int unsigned i) {m_duration_minutes=i;} + void set_duration_minutes(unsigned int i) {m_duration_minutes=i;} + unsigned int duration_minutes() const {return m_duration_minutes;} void set_looping(bool b) {m_looping=b;} Sound* operator()() { @@ -260,12 +261,15 @@ private: m_nn = notify_notification_new(title, body.c_str(), icon_name); if (m_interactive) { - notify_notification_set_hint(m_nn, - "x-canonical-snap-decisions", + const int32_t duration_secs = m_sound_builder.duration_minutes()*60; + + notify_notification_set_hint(m_nn, HINT_SNAP, g_variant_new_boolean(true)); - notify_notification_set_hint(m_nn, - "x-canonical-private-button-tint", + notify_notification_set_hint(m_nn, HINT_TINT, g_variant_new_boolean(true)); + notify_notification_set_hint(m_nn, HINT_TIMEOUT, + g_variant_new_int32(duration_secs)); + /// alarm popup dialog's button to show the active alarm notify_notification_add_action(m_nn, "show", _("Show"), on_snap_show, this, nullptr); @@ -373,6 +377,10 @@ private: core::Signal m_response; Response m_response_value = RESPONSE_CLOSE; NotifyNotification* m_nn = nullptr; + + static constexpr char const * HINT_SNAP {"x-canonical-snap-decisions"}; + static constexpr char const * HINT_TINT {"x-canonical-private-button-tint"}; + static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"}; }; /** -- cgit v1.2.3 From 5b1f9d5eebb291117945ed4249af32a6a08194b0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 14 Jul 2014 22:03:29 -0500 Subject: x-canonical-snap-decisions-timeout is int32 milliseconds --- src/snap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 697326f..7332b99 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -261,14 +261,14 @@ private: m_nn = notify_notification_new(title, body.c_str(), icon_name); if (m_interactive) { - const int32_t duration_secs = m_sound_builder.duration_minutes()*60; + const int32_t duration_msec = m_sound_builder.duration_minutes()*60*1000; notify_notification_set_hint(m_nn, HINT_SNAP, g_variant_new_boolean(true)); notify_notification_set_hint(m_nn, HINT_TINT, g_variant_new_boolean(true)); notify_notification_set_hint(m_nn, HINT_TIMEOUT, - g_variant_new_int32(duration_secs)); + g_variant_new_int32(duration_msec)); /// alarm popup dialog's button to show the active alarm notify_notification_add_action(m_nn, "show", _("Show"), -- cgit v1.2.3 From eb8054f0ae27ce06b8c152edceddac94b5685c07 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 15 Jul 2014 08:11:11 -0500 Subject: use std::chrono to get the milliseconds for notify_notification_set_hint() --- src/snap.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 7332b99..fe8e7f2 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -29,6 +29,7 @@ #include #include +#include #include // std::call_once() #include #include @@ -261,14 +262,14 @@ private: m_nn = notify_notification_new(title, body.c_str(), icon_name); if (m_interactive) { - const int32_t duration_msec = m_sound_builder.duration_minutes()*60*1000; + const auto duration = std::chrono::minutes(m_sound_builder.duration_minutes()); notify_notification_set_hint(m_nn, HINT_SNAP, g_variant_new_boolean(true)); notify_notification_set_hint(m_nn, HINT_TINT, g_variant_new_boolean(true)); notify_notification_set_hint(m_nn, HINT_TIMEOUT, - g_variant_new_int32(duration_msec)); + g_variant_new_int32(std::chrono::duration_cast(duration).count())); /// alarm popup dialog's button to show the active alarm notify_notification_add_action(m_nn, "show", _("Show"), -- cgit v1.2.3 From d2078fd450a3a631c57dc13c61b35af0ce27d070 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 15 Jul 2014 14:51:22 -0500 Subject: Pair notify_init() with a shutdown call to notify_uninit() when the last Snap Decision is closed. This is needed in the dbusmock tests because libnotify's bus proxy needs to be closed. For production, this doesn't make much change: only that notify_uninit() is called once when the local Snap object goes out of scope in main(). --- src/snap.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index fe8e7f2..45eb14e 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -216,14 +216,6 @@ public: m_interactive(get_interactive()), m_sound_builder(sound_builder) { - // ensure notify_init() is called once - // before we start popping up dialogs - static std::once_flag once; - std::call_once(once, [](){ - if(!notify_init("indicator-datetime-service")) - g_critical("libnotify initialization failed"); - }); - show(); } @@ -421,6 +413,8 @@ std::string get_alarm_uri(const Appointment& appointment, return uri; } +int32_t n_existing_snaps = 0; + } // unnamed namespace /*** @@ -432,10 +426,14 @@ Snap::Snap(const std::shared_ptr& clock, m_clock(clock), m_settings(settings) { + if (!n_existing_snaps++ && !notify_init("indicator-datetime-service")) + g_critical("libnotify initialization failed"); } Snap::~Snap() { + if (!--n_existing_snaps) + notify_uninit(); } void Snap::operator()(const Appointment& appointment, -- cgit v1.2.3