diff options
-rw-r--r-- | include/datetime/settings-live.h | 1 | ||||
-rw-r--r-- | include/datetime/settings-shared.h | 1 | ||||
-rw-r--r-- | include/datetime/settings.h | 1 | ||||
-rw-r--r-- | src/settings-live.cpp | 14 | ||||
-rw-r--r-- | src/snap.cpp | 18 | ||||
-rw-r--r-- | tests/test-settings.cpp | 1 |
6 files changed, 28 insertions, 8 deletions
diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h index af99596..ead1dc2 100644 --- a/include/datetime/settings-live.h +++ b/include/datetime/settings-live.h @@ -55,6 +55,7 @@ private: void update_show_year(); void update_time_format_mode(); void update_timezone_name(); + void update_calendar_sound(); void update_alarm_sound(); void update_alarm_volume(); void update_alarm_duration(); diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h index 59a9da1..2ce556a 100644 --- a/include/datetime/settings-shared.h +++ b/include/datetime/settings-shared.h @@ -45,6 +45,7 @@ TimeFormatMode; #define SETTINGS_SHOW_DETECTED_S "show-auto-detected-location" #define SETTINGS_LOCATIONS_S "locations" #define SETTINGS_TIMEZONE_NAME_S "timezone-name" +#define SETTINGS_CALENDAR_SOUND_S "calendar-default-sound" #define SETTINGS_ALARM_SOUND_S "alarm-default-sound" #define SETTINGS_ALARM_VOLUME_S "alarm-default-volume" #define SETTINGS_ALARM_DURATION_S "alarm-duration-minutes" diff --git a/include/datetime/settings.h b/include/datetime/settings.h index 343cd81..fa64724 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -56,6 +56,7 @@ public: core::Property<bool> show_year; core::Property<TimeFormatMode> time_format_mode; core::Property<std::string> timezone_name; + core::Property<std::string> calendar_sound; core::Property<std::string> alarm_sound; core::Property<std::string> alarm_haptic; core::Property<unsigned int> alarm_volume; diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 3475d5e..206b762 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -52,6 +52,7 @@ LiveSettings::LiveSettings(): update_show_year(); update_time_format_mode(); update_timezone_name(); + update_calendar_sound(); update_alarm_sound(); update_alarm_volume(); update_alarm_duration(); @@ -121,6 +122,10 @@ LiveSettings::LiveSettings(): g_settings_set_string(m_settings, SETTINGS_TIMEZONE_NAME_S, value.c_str()); }); + calendar_sound.changed().connect([this](const std::string& value){ + g_settings_set_string(m_settings, SETTINGS_CALENDAR_SOUND_S, value.c_str()); + }); + alarm_sound.changed().connect([this](const std::string& value){ g_settings_set_string(m_settings, SETTINGS_ALARM_SOUND_S, value.c_str()); }); @@ -230,6 +235,13 @@ void LiveSettings::update_timezone_name() g_free(val); } +void LiveSettings::update_calendar_sound() +{ + auto val = g_settings_get_string(m_settings, SETTINGS_CALENDAR_SOUND_S); + calendar_sound.set(val); + g_free(val); +} + void LiveSettings::update_alarm_sound() { auto val = g_settings_get_string(m_settings, SETTINGS_ALARM_SOUND_S); @@ -300,6 +312,8 @@ void LiveSettings::update_key(const std::string& key) update_show_detected_locations(); else if (key == SETTINGS_TIMEZONE_NAME_S) update_timezone_name(); + else if (key == SETTINGS_CALENDAR_SOUND_S) + update_calendar_sound(); else if (key == SETTINGS_ALARM_SOUND_S) update_alarm_sound(); else if (key == SETTINGS_ALARM_VOLUME_S) diff --git a/src/snap.cpp b/src/snap.cpp index 326e676..f0300af 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -98,8 +98,7 @@ public: if (appointment.is_ubuntu_alarm() || !silent_mode()) { // create the sound. const auto role = appointment.is_ubuntu_alarm() ? "alarm" : "alert"; - const auto default_sound = appointment.is_ubuntu_alarm() ? ALARM_DEFAULT_SOUND : CALENDAR_DEFAULT_SOUND; - const auto uri = get_alarm_uri(alarm, m_settings, default_sound); + const auto uri = get_alarm_uri(appointment, alarm, m_settings); const auto volume = m_settings->alarm_volume.get(); const bool loop = interactive; sound = std::make_shared<ain::Sound>(role, uri, volume, loop); @@ -191,13 +190,16 @@ private: && (accounts_service_sound_get_other_vibrate(m_accounts_service_sound_proxy)); } - std::string get_alarm_uri(const Alarm& alarm, - const std::shared_ptr<const Settings>& settings, - const std::string& default_sound ) const + std::string get_alarm_uri(const Appointment& appointment, + const Alarm& alarm, + const std::shared_ptr<const Settings>& settings) const { - const std::string candidates[] = { alarm.audio_url, - settings->alarm_sound.get(), - default_sound }; + const auto is_alarm = appointment.is_ubuntu_alarm(); + const std::string candidates[] = { + alarm.audio_url, + is_alarm ? settings->alarm_sound.get() : settings->calendar_sound.get(), + is_alarm ? ALARM_DEFAULT_SOUND : CALENDAR_DEFAULT_SOUND + }; std::string uri; diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index fabb6f7..dff9487 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -160,6 +160,7 @@ TEST_F(SettingsFixture, StringProperties) TestStringProperty(m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S); TestStringProperty(m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S); TestStringProperty(m_settings->alarm_sound, SETTINGS_ALARM_SOUND_S); + TestStringProperty(m_settings->calendar_sound, SETTINGS_CALENDAR_SOUND_S); TestStringProperty(m_settings->alarm_haptic, SETTINGS_ALARM_HAPTIC_S); } |