aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-07-30 14:54:37 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-07-30 14:54:37 -0500
commitd6b290fda978379fb07285aaddfeb31686735667 (patch)
treec3e37b819707b82a0b8a7daf0d1a4ab1f2f4147e /src
parentf6df9730bd512982850b7f234f883eabbd925e7d (diff)
downloadayatana-indicator-datetime-d6b290fda978379fb07285aaddfeb31686735667.tar.gz
ayatana-indicator-datetime-d6b290fda978379fb07285aaddfeb31686735667.tar.bz2
ayatana-indicator-datetime-d6b290fda978379fb07285aaddfeb31686735667.zip
move Snap's guts into an Impl class
Diffstat (limited to 'src')
-rw-r--r--src/snap.cpp185
1 files changed, 105 insertions, 80 deletions
diff --git a/src/snap.cpp b/src/snap.cpp
index e9df256..0eb176c 100644
--- a/src/snap.cpp
+++ b/src/snap.cpp
@@ -27,6 +27,7 @@
#include <glib/gi18n.h>
#include <chrono>
+#include <set>
#include <string>
namespace uin = unity::indicator::notifications;
@@ -39,114 +40,138 @@ namespace datetime {
****
***/
-namespace // unnamed namespace
+class Snap::Impl
{
+public:
-std::string get_alarm_uri(const Appointment& appointment,
- const std::shared_ptr<const Settings>& settings)
-{
- const char* FALLBACK {"/usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg"};
-
- const std::string candidates[] = { appointment.audio_url,
- settings->alarm_sound.get(),
- FALLBACK };
+ Impl(const std::shared_ptr<unity::indicator::notifications::Engine>& engine,
+ const std::shared_ptr<const Settings>& settings):
+ m_engine(engine),
+ m_settings(settings)
+ {
+ }
- std::string uri;
+ ~Impl()
+ {
+ for (const auto& key : m_notifications)
+ m_engine->close (key);
+ }
- for(const auto& candidate : candidates)
+ void operator()(const Appointment& appointment,
+ appointment_func show,
+ appointment_func dismiss)
{
- if (gst_uri_is_valid (candidate.c_str()))
+ if (!appointment.has_alarms)
{
- uri = candidate;
- break;
+ dismiss(appointment);
+ return;
+ }
+
+ // force the system to stay awake
+ auto awake = std::make_shared<uin::Awake>(m_engine->app_name());
+
+ // create the sound...
+ const auto uri = get_alarm_uri(appointment, m_settings);
+ const auto volume = m_settings->alarm_volume.get();
+ const bool loop = m_engine->supports_actions();
+ auto sound = std::make_shared<uin::Sound>(uri, volume, loop);
+
+ // show a notification...
+ const auto minutes = std::chrono::minutes(m_settings->alarm_duration.get());
+ const bool interactive = m_engine->supports_actions();
+ uin::Builder b;
+ b.set_body (appointment.summary);
+ b.set_icon_name ("alarm-clock");
+ b.add_hint (uin::Builder::HINT_SNAP);
+ b.add_hint (uin::Builder::HINT_TINT);
+ const auto timestr = appointment.begin.format (_("%a, %X"));
+ auto title = g_strdup_printf (_("Alarm %s"), timestr.c_str());
+ b.set_title (title);
+ g_free (title);
+ b.set_timeout (std::chrono::duration_cast<std::chrono::seconds>(minutes));
+ if (interactive) {
+ b.add_action ("show", _("Show"));
+ b.add_action ("dismiss", _("Dismiss"));
}
- else if (g_file_test(candidate.c_str(), G_FILE_TEST_EXISTS))
+
+ // add the 'sound' and 'awake' objects to the capture so that
+ // they stay alive until the closed callback is called; i.e.,
+ // for the lifespan of the notficiation
+ b.set_closed_callback([appointment, show, dismiss, sound, awake]
+ (const std::string& action){
+ if (action == "show")
+ show(appointment);
+ else
+ dismiss(appointment);
+ });
+
+ const auto key = m_engine->show(b);
+ if (key)
+ m_notifications.insert (key);
+ else
+ show(appointment);
+ }
+
+private:
+
+ std::string get_alarm_uri(const Appointment& appointment,
+ const std::shared_ptr<const Settings>& settings) const
+ {
+ 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)
{
- gchar* tmp = gst_filename_to_uri(candidate.c_str(), nullptr);
- if (tmp != nullptr)
+ if (gst_uri_is_valid (candidate.c_str()))
{
- uri = tmp;
- g_free (tmp);
+ 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;
-}
+ return uri;
+ }
-} // unnamed namespace
+ const std::shared_ptr<unity::indicator::notifications::Engine> m_engine;
+ const std::shared_ptr<const Settings> m_settings;
+ std::set<int> m_notifications;
+};
/***
****
***/
-Snap::Snap(const std::shared_ptr<uin::Engine>& engine,
+Snap::Snap(const std::shared_ptr<unity::indicator::notifications::Engine>& engine,
const std::shared_ptr<const Settings>& settings):
- m_engine(engine),
- m_settings(settings)
+ impl(new Impl(engine, settings))
{
}
Snap::~Snap()
{
- for (const auto& key : m_notifications)
- m_engine->close (key);
}
-void Snap::operator()(const Appointment& appointment,
- appointment_func show,
- appointment_func dismiss)
+void
+Snap::operator()(const Appointment& appointment,
+ appointment_func show,
+ appointment_func dismiss)
{
- if (!appointment.has_alarms)
- {
- dismiss(appointment);
- return;
- }
-
- // force the system to stay awake
- auto awake = std::make_shared<uin::Awake>(m_engine->app_name());
-
- // create the sound...
- const auto uri = get_alarm_uri(appointment, m_settings);
- const auto volume = m_settings->alarm_volume.get();
- const bool loop = m_engine->supports_actions();
- auto sound = std::make_shared<uin::Sound>(uri, volume, loop);
-
- // show a notification...
- const auto minutes = std::chrono::minutes(m_settings->alarm_duration.get());
- const bool interactive = m_engine->supports_actions();
- uin::Builder b;
- b.set_body (appointment.summary);
- b.set_icon_name ("alarm-clock");
- b.add_hint (uin::Builder::HINT_SNAP);
- b.add_hint (uin::Builder::HINT_TINT);
- const auto timestr = appointment.begin.format (_("%a, %X"));
- auto title = g_strdup_printf (_("Alarm %s"), timestr.c_str());
- b.set_title (title);
- g_free (title);
- b.set_timeout (std::chrono::duration_cast<std::chrono::seconds>(minutes));
- if (interactive) {
- b.add_action ("show", _("Show"));
- b.add_action ("dismiss", _("Dismiss"));
- }
-
- // add the 'sound' and 'awake' objects to the capture so that
- // they stay alive until the closed callback is called; i.e.,
- // for the lifespan of the notficiation
- b.set_closed_callback([appointment, show, dismiss, sound, awake]
- (const std::string& action){
- if (action == "show")
- show(appointment);
- else
- dismiss(appointment);
- });
-
- const auto key = m_engine->show(b);
- if (key)
- m_notifications.insert (key);
- else
- show(appointment);
+ (*impl)(appointment, show, dismiss);
}
/***