diff options
-rw-r--r-- | src/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/com.ubuntu.touch.AccountsService.Sound.xml | 42 | ||||
-rw-r--r-- | src/snap.cpp | 63 |
3 files changed, 102 insertions, 6 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 512cc5c..5fc822c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,6 +47,9 @@ set(SERVICE_GENERATED_SOURCES) add_gdbus_codegen(SERVICE_GENERATED_SOURCES dbus-alarm-properties com.canonical.indicator ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.datetime.AlarmProperties.xml) +add_gdbus_codegen(SERVICE_GENERATED_SOURCES dbus-accounts-sound + com.ubuntu.touch + ${CMAKE_SOURCE_DIR}/src/com.ubuntu.touch.AccountsService.Sound.xml) # add warnings/coverage info on handwritten files # but not the autogenerated ones... diff --git a/src/com.ubuntu.touch.AccountsService.Sound.xml b/src/com.ubuntu.touch.AccountsService.Sound.xml new file mode 100644 index 0000000..91d71dc --- /dev/null +++ b/src/com.ubuntu.touch.AccountsService.Sound.xml @@ -0,0 +1,42 @@ +<node> + <interface name="com.ubuntu.touch.AccountsService.Sound"> + + <annotation name="org.freedesktop.Accounts.VendorExtension" value="true"/> + + <!-- Muted is all sound, SilentMode is only non-user-initiated sounds --> + <property name="SilentMode" type="b" access="readwrite"> + <annotation name="org.freedesktop.Accounts.DefaultValue" value="false"/> + </property> + + <property name="IncomingCallSound" type="s" access="readwrite"> + <annotation name="org.freedesktop.Accounts.DefaultValue.String" + value="/usr/share/sounds/ubuntu/ringtones/Ubuntu.ogg"/> + </property> + + <property name="IncomingMessageSound" type="s" access="readwrite"> + <annotation name="org.freedesktop.Accounts.DefaultValue.String" + value="/usr/share/sounds/ubuntu/notifications/Xylo.ogg"/> + </property> + + <property name="IncomingCallVibrate" type="b" access="readwrite"> + <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/> + </property> + + <property name="IncomingCallVibrateSilentMode" type="b" access="readwrite"> + <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/> + </property> + + <property name="IncomingMessageVibrate" type="b" access="readwrite"> + <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/> + </property> + + <property name="IncomingMessageVibrateSilentMode" type="b" access="readwrite"> + <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/> + </property> + + <property name="DialpadSoundsEnabled" type="b" access="readwrite"> + <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/> + </property> + + </interface> +</node> 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}; }; /*** |