diff options
author | Arthur Mello <arthur.mello@canonical.com> | 2016-07-04 16:30:18 -0300 |
---|---|---|
committer | Robert Tari <robert@tari.in> | 2021-07-08 02:23:04 +0200 |
commit | d61975b6145c245bf8df5322942395b101ca57c9 (patch) | |
tree | 559cd8fb730c13535d3fb0faa2e9f3b7ed7df9e4 | |
parent | 46b0ac44948f06f37d93886996e21c0ed9e014cd (diff) | |
download | ayatana-indicator-datetime-d61975b6145c245bf8df5322942395b101ca57c9.tar.gz ayatana-indicator-datetime-d61975b6145c245bf8df5322942395b101ca57c9.tar.bz2 ayatana-indicator-datetime-d61975b6145c245bf8df5322942395b101ca57c9.zip |
If in silent mode should only vibrate if the settings say so
-rw-r--r-- | include/datetime/settings-live.h | 4 | ||||
-rw-r--r-- | include/datetime/settings-shared.h | 2 | ||||
-rw-r--r-- | include/datetime/settings.h | 1 | ||||
-rw-r--r-- | src/settings-live.cpp | 38 | ||||
-rw-r--r-- | src/snap.cpp | 20 |
5 files changed, 56 insertions, 9 deletions
diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h index 4aeaa9b..85071ce 100644 --- a/include/datetime/settings-live.h +++ b/include/datetime/settings-live.h @@ -40,8 +40,10 @@ public: private: static void on_changed_ccid(GSettings*, gchar*, gpointer); static void on_changed_cal_notification(GSettings*, gchar*, gpointer); + static void on_changed_general_notification(GSettings*, gchar*, gpointer); void update_key_ccid(const std::string& key); void update_key_cal_notification(const std::string& key); + void update_key_general_notification(const std::string& key); void update_custom_time_format(); void update_locations(); @@ -67,9 +69,11 @@ private: void update_cal_notification_vibrations(); void update_cal_notification_bubbles(); void update_cal_notification_list(); + void update_vibrate_silent_mode(); GSettings* m_settings; GSettings* m_settings_cal_notification; + GSettings* m_settings_general_notification; // we've got a raw pointer here, so disable copying LiveSettings(const LiveSettings&) =delete; diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h index 236b8f1..7280c16 100644 --- a/include/datetime/settings-shared.h +++ b/include/datetime/settings-shared.h @@ -51,6 +51,8 @@ TimeFormatMode; #define SETTINGS_ALARM_HAPTIC_S "alarm-haptic-feedback" #define SETTINGS_SNOOZE_DURATION_S "snooze-duration-minutes" +#define SETTINGS_NOTIFY_APPS_SCHEMA_ID "com.lomiri.notifications.settings.applications" +#define SETTINGS_VIBRATE_SILENT_KEY "vibrate-silent-mode" #define SETTINGS_NOTIFY_SCHEMA_ID "com.lomiri.notifications.settings" #define SETTINGS_NOTIFY_CALENDAR_PATH "/com/lomiri/NotificationSettings/com.lomiri.calendar/calendar/" #define SETTINGS_NOTIFY_ENABLED_KEY "enable-notifications" diff --git a/include/datetime/settings.h b/include/datetime/settings.h index 5ae00f6..af9227d 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -66,6 +66,7 @@ public: core::Property<bool> cal_notification_vibrations; core::Property<bool> cal_notification_bubbles; core::Property<bool> cal_notification_list; + core::Property<bool> vibrate_silent_mode; }; } // namespace datetime diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 01de7b8..66590e0 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -34,14 +34,19 @@ namespace datetime { LiveSettings::~LiveSettings() { + g_clear_object(&m_settings_general_notification); g_clear_object(&m_settings_cal_notification); g_clear_object(&m_settings); } -LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_settings_cal_notification(g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH)) +LiveSettings::LiveSettings(): + m_settings(g_settings_new(SETTINGS_INTERFACE)), + m_settings_cal_notification(g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH)), + m_settings_general_notification(g_settings_new(SETTINGS_NOTIFY_APPS_SCHEMA_ID)) { - g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); - g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); + g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); + g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); + g_signal_connect (m_settings_general_notification, "changed", G_CALLBACK(on_changed_general_notification), this); // init the Properties from the GSettings backend update_custom_time_format(); @@ -68,6 +73,7 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_ update_cal_notification_vibrations(); update_cal_notification_bubbles(); update_cal_notification_list(); + update_vibrate_silent_mode(); // now listen for clients to change the properties s.t. we can sync update GSettings @@ -171,6 +177,10 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_ cal_notification_list.changed().connect([this](bool value){ g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY, value); }); + + vibrate_silent_mode.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_general_notification, SETTINGS_VIBRATE_SILENT_KEY, value); + }); } /*** @@ -317,6 +327,11 @@ void LiveSettings::update_cal_notification_list() cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); } +void LiveSettings::update_vibrate_silent_mode() +{ + vibrate_silent_mode.set(g_settings_get_boolean(m_settings_general_notification, SETTINGS_VIBRATE_SILENT_KEY)); +} + /*** **** ***/ @@ -347,6 +362,23 @@ void LiveSettings::update_key_cal_notification(const std::string& key) **** ***/ +void LiveSettings::on_changed_general_notification(GSettings* /*settings*/, + gchar* key, + gpointer gself) +{ + static_cast<LiveSettings*>(gself)->update_key_general_notification(key); +} + +void LiveSettings::update_key_general_notification(const std::string& key) +{ + if (key == SETTINGS_VIBRATE_SILENT_KEY) + update_vibrate_silent_mode(); +} + +/*** +**** +***/ + void LiveSettings::on_changed_ccid(GSettings* /*settings*/, gchar* key, gpointer gself) diff --git a/src/snap.cpp b/src/snap.cpp index d0c12a0..363e0df 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -97,9 +97,9 @@ public: // force the system to stay awake std::shared_ptr<ain::Awake> awake; - if (appointment.is_ubuntu_alarm() || calendar_bubbles_enabled()) { - awake = std::make_shared<ain::Awake>(m_engine->app_name()); - } + if (appointment.is_ubuntu_alarm() || calendar_bubbles_enabled() || calendar_list_enabled()) { + awake = std::make_shared<ain::Awake>(m_engine->app_name()); + } // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr<ain::Sound> sound; @@ -115,9 +115,12 @@ public: // create the haptic feedback... std::shared_ptr<ain::Haptic> haptic; if (should_vibrate() && (appointment.is_ubuntu_alarm() || calendar_vibrations_enabled())) { - const auto haptic_mode = m_settings->alarm_haptic.get(); - if (haptic_mode == "pulse") - haptic = std::make_shared<ain::Haptic>(ain::Haptic::MODE_PULSE, appointment.is_ubuntu_alarm()); + // when in silent mode should only vibrate if user defined so + if (!silent_mode() || vibrate_in_silent_mode_enabled()) { + const auto haptic_mode = m_settings->alarm_haptic.get(); + if (haptic_mode == "pulse") + haptic = std::make_shared<ain::Haptic>(ain::Haptic::MODE_PULSE, appointment.is_ubuntu_alarm()); + } } // show a notification... @@ -218,6 +221,11 @@ private: return m_settings->cal_notification_list.get(); } + bool vibrate_in_silent_mode_enabled() const + { + return m_settings->vibrate_silent_mode.get(); + } + static void on_sound_proxy_ready(GObject* /*source_object*/, GAsyncResult* res, gpointer gself) { GError * error; |