From 909ccbc93d9fa21075cf5001887e69159e621f5d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 23 Jul 2014 22:56:36 -0500 Subject: move the powerd and screen bus name, path, and interface strings into dbus-shared --- include/datetime/dbus-shared.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/dbus-shared.h b/include/datetime/dbus-shared.h index c5ff6ab..4b71ce5 100644 --- a/include/datetime/dbus-shared.h +++ b/include/datetime/dbus-shared.h @@ -18,8 +18,18 @@ * Charles Kerr */ +#ifndef _DBUS_SHARED_H_ +#define _DBUS_SHARED_H_ -#define BUS_NAME "com.canonical.indicator.datetime" +#define BUS_DATETIME_NAME "com.canonical.indicator.datetime" +#define BUS_DATETIME_PATH "/com/canonical/indicator/datetime" -#define BUS_PATH "/com/canonical/indicator/datetime" +#define BUS_SCREEN_NAME "com.canonical.Unity.Screen" +#define BUS_SCREEN_PATH "/com/canonical/Unity/Screen" +#define BUS_SCREEN_INTERFACE "com.canonical.Unity.Screen" +#define BUS_POWERD_NAME "com.canonical.powerd" +#define BUS_POWERD_PATH "/com/canonical/powerd" +#define BUS_POWERD_INTERFACE "com.canonical.powerd" + +#endif /* _DBUS_SHARED_H_ */ -- cgit v1.2.3 From b9b3cfea551b5c7e12e6bb9904cffe2873b328c7 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 Jul 2014 01:18:10 -0500 Subject: when a Snap object is destructed, delete any active Popups that it owns. This cleaner shutdown doesn't have any effect in production, but is needed to shut down the bus cleanly in the tests. --- include/datetime/snap.h | 7 +++- src/snap.cpp | 94 +++++++++++++++++++++++++++---------------------- 2 files changed, 57 insertions(+), 44 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/snap.h b/include/datetime/snap.h index 9b45b3f..1c90496 100644 --- a/include/datetime/snap.h +++ b/include/datetime/snap.h @@ -24,8 +24,9 @@ #include #include -#include #include +#include +#include namespace unity { namespace indicator { @@ -49,6 +50,10 @@ public: private: const std::shared_ptr m_clock; const std::shared_ptr m_settings; + + class Popup; + friend class Popup; + std::set m_pending; }; } // namespace datetime diff --git a/src/snap.cpp b/src/snap.cpp index 566dfae..c21a398 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -207,11 +207,52 @@ private: bool m_looping = true; }; +/** +*** libnotify -- snap decisions +**/ + +std::string get_alarm_uri(const Appointment& appointment, + const std::shared_ptr& settings) +{ + const char* FALLBACK {"/usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg"}; + + const std::string candidates[] = { appointment.audio_url, + settings->alarm_sound.get(), + FALLBACK }; + + std::string uri; + + for(const auto& candidate : candidates) + { + if (gst_uri_is_valid (candidate.c_str())) + { + uri = candidate; + break; + } + else if (g_file_test(candidate.c_str(), G_FILE_TEST_EXISTS)) + { + gchar* tmp = gst_filename_to_uri(candidate.c_str(), nullptr); + if (tmp != nullptr) + { + uri = tmp; + g_free (tmp); + break; + } + } + } + + return uri; +} + +int32_t n_existing_snaps = 0; + +} // unnamed namespace + /** * A popup notification (with optional sound) * that emits a Response signal when done. */ -class Popup +class Snap::Popup { public: @@ -561,47 +602,6 @@ private: static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"}; }; -/** -*** libnotify -- snap decisions -**/ - -std::string get_alarm_uri(const Appointment& appointment, - const std::shared_ptr& settings) -{ - const char* FALLBACK {"/usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg"}; - - const std::string candidates[] = { appointment.audio_url, - settings->alarm_sound.get(), - FALLBACK }; - - std::string uri; - - for(const auto& candidate : candidates) - { - if (gst_uri_is_valid (candidate.c_str())) - { - uri = candidate; - break; - } - else if (g_file_test(candidate.c_str(), G_FILE_TEST_EXISTS)) - { - gchar* tmp = gst_filename_to_uri(candidate.c_str(), nullptr); - if (tmp != nullptr) - { - uri = tmp; - g_free (tmp); - break; - } - } - } - - return uri; -} - -int32_t n_existing_snaps = 0; - -} // unnamed namespace - /*** **** ***/ @@ -617,6 +617,9 @@ Snap::Snap(const std::shared_ptr& clock, Snap::~Snap() { + for (auto popup : m_pending) + delete popup; + if (!--n_existing_snaps) notify_uninit(); } @@ -638,12 +641,17 @@ void Snap::operator()(const Appointment& appointment, sound_builder.set_clock(m_clock); sound_builder.set_duration_minutes(m_settings->alarm_duration.get()); auto popup = new Popup(appointment, sound_builder); + + m_pending.insert(popup); // listen for it to finish... - popup->response().connect([appointment, + popup->response().connect([this, + appointment, show, dismiss, popup](Popup::Response response){ + + m_pending.erase(popup); // we can't delete the Popup inside its response() signal handler // because core::signal deadlocks, so push that to an idle func -- cgit v1.2.3