From 392487de7ec4357f8f7b68105d9dd667d5b14d62 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 21 Jan 2015 14:25:52 -0600 Subject: first stab at AccountsService proxy. WIP; pushing to test on devices --- src/snap.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 6 deletions(-) (limited to 'src/snap.cpp') diff --git a/src/snap.cpp b/src/snap.cpp index ee96007..e916eff 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -17,6 +17,8 @@ * Charles Kerr */ +#include "dbus-accounts-sound.h" + #include #include // is_locale_12h() @@ -32,6 +34,9 @@ #include #include +#include // getuid() +#include // getuid() + namespace uin = unity::indicator::notifications; namespace unity { @@ -49,12 +54,26 @@ public: Impl(const std::shared_ptr& engine, const std::shared_ptr& settings): m_engine(engine), - m_settings(settings) + m_settings(settings), + m_cancellable(g_cancellable_new()) { + auto object_path = g_strdup_printf("/org/freedesktop/Accounts/User/%lu", (gulong)getuid()); + accounts_service_sound_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, + "org.freedesktop.Accounts", + object_path, + m_cancellable, + on_sound_proxy_ready, + this); + g_free(object_path); } ~Impl() { + g_cancellable_cancel(m_cancellable); + g_clear_object(&m_cancellable); + g_clear_object(&m_accounts_service_sound_proxy); + for (const auto& key : m_notifications) m_engine->close (key); } @@ -72,11 +91,16 @@ public: // force the system to stay awake auto awake = std::make_shared(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 = interactive; - auto sound = std::make_shared(uri, volume, loop); + // create the sound. + // calendar events are muted in silent mode; alarm clocks never are + std::shared_ptr sound; + g_message("silent_mode is %d", (int)silent_mode()); + if (appointment.is_ubuntu_alarm() || !silent_mode()) { + const auto uri = get_alarm_uri(appointment, m_settings); + const auto volume = m_settings->alarm_volume.get(); + const bool loop = interactive; + sound = std::make_shared(uri, volume, loop); + } // create the haptic feedback... const auto haptic_mode = m_settings->alarm_haptic.get(); @@ -131,6 +155,31 @@ public: private: + static void on_sound_proxy_ready(GObject* /*source_object*/, GAsyncResult* res, gpointer gself) + { + GError * error; + + error = nullptr; + auto accounts_service_sound_proxy = accounts_service_sound_proxy_new_for_bus_finish (res, &error); + if (error != nullptr) + { + if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning("%s Couldn't accounts service sound proxy: %s", G_STRLOC, error->message); + } + else + { + static_cast(gself)->m_accounts_service_sound_proxy = accounts_service_sound_proxy; + g_message("got accounts sound service proxy"); + } + } + + bool silent_mode() const + { + g_message("%s %s %p %d", G_STRLOC, G_STRFUNC, m_accounts_service_sound_proxy, (int)accounts_service_sound_get_silent_mode(m_accounts_service_sound_proxy)); + return (m_accounts_service_sound_proxy != nullptr) + && (!accounts_service_sound_get_silent_mode(m_accounts_service_sound_proxy)); + } + std::string get_alarm_uri(const Appointment& appointment, const std::shared_ptr& settings) const { @@ -167,6 +216,8 @@ private: const std::shared_ptr m_engine; const std::shared_ptr m_settings; std::set m_notifications; + GCancellable * m_cancellable {nullptr}; + AccountsServiceSound * m_accounts_service_sound_proxy {nullptr}; }; /*** -- cgit v1.2.3