aboutsummaryrefslogtreecommitdiff
path: root/src/snap.cpp
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2015-01-21 14:25:52 -0600
committerCharles Kerr <charles.kerr@canonical.com>2015-01-21 14:25:52 -0600
commit392487de7ec4357f8f7b68105d9dd667d5b14d62 (patch)
tree7b16c43f779f8cc67de7f10237f19c9dadfb2183 /src/snap.cpp
parenta4ffa788d2f92d1a446f8d6155b111bc79c51a4d (diff)
downloadayatana-indicator-datetime-392487de7ec4357f8f7b68105d9dd667d5b14d62.tar.gz
ayatana-indicator-datetime-392487de7ec4357f8f7b68105d9dd667d5b14d62.tar.bz2
ayatana-indicator-datetime-392487de7ec4357f8f7b68105d9dd667d5b14d62.zip
first stab at AccountsService proxy. WIP; pushing to test on devices
Diffstat (limited to 'src/snap.cpp')
-rw-r--r--src/snap.cpp63
1 files changed, 57 insertions, 6 deletions
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 <charles.kerr@canonical.com>
*/
+#include "dbus-accounts-sound.h"
+
#include <datetime/snap.h>
#include <datetime/utils.h> // is_locale_12h()
@@ -32,6 +34,9 @@
#include <set>
#include <string>
+#include <unistd.h> // getuid()
+#include <sys/types.h> // getuid()
+
namespace uin = unity::indicator::notifications;
namespace unity {
@@ -49,12 +54,26 @@ public:
Impl(const std::shared_ptr<unity::indicator::notifications::Engine>& engine,
const std::shared_ptr<const Settings>& 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<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 = interactive;
- auto sound = std::make_shared<uin::Sound>(uri, volume, loop);
+ // create the sound.
+ // calendar events are muted in silent mode; alarm clocks never are
+ std::shared_ptr<uin::Sound> 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<uin::Sound>(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<Impl*>(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<const Settings>& settings) const
{
@@ -167,6 +216,8 @@ private:
const std::shared_ptr<unity::indicator::notifications::Engine> m_engine;
const std::shared_ptr<const Settings> m_settings;
std::set<int> m_notifications;
+ GCancellable * m_cancellable {nullptr};
+ AccountsServiceSound * m_accounts_service_sound_proxy {nullptr};
};
/***