From a85fd44e7b2dc67b3e0712e174e88d0eb6c467e7 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 23 Jun 2014 18:52:52 -0500 Subject: add GSettings support for specifying a default alarm sound and default alarm volume. --- data/com.canonical.indicator.datetime.gschema.xml | 21 ++++++++++ include/datetime/settings-live.h | 2 + include/datetime/settings-shared.h | 12 ++++++ include/datetime/settings.h | 2 + src/settings-live.cpp | 26 ++++++++++++ tests/test-settings.cpp | 51 +++++++++++++++++++++++ 6 files changed, 114 insertions(+) diff --git a/data/com.canonical.indicator.datetime.gschema.xml b/data/com.canonical.indicator.datetime.gschema.xml index 1a5922c..7e74a63 100644 --- a/data/com.canonical.indicator.datetime.gschema.xml +++ b/data/com.canonical.indicator.datetime.gschema.xml @@ -5,6 +5,13 @@ + + + + + + + true @@ -123,5 +130,19 @@ Some timezones can be known by many different cities or names. This setting describes how the current zone prefers to be named. Format is "TIMEZONE NAME" (e.g. "America/New_York Boston" to name the New_York zone Boston). + + '/usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg' + The alarm's default sound file. + + If an alarm doesn't specify its own sound file, this file will be used as the fallback sound. + + + + 'normal' + The alarm's default volume level. + + The volume at which alarms will be played. + + diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h index 202c998..a075a85 100644 --- a/include/datetime/settings-live.h +++ b/include/datetime/settings-live.h @@ -55,6 +55,8 @@ private: void update_show_year(); void update_time_format_mode(); void update_timezone_name(); + void update_alarm_sound(); + void update_alarm_volume(); GSettings* m_settings; diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h index 17a8ef0..b8d7737 100644 --- a/include/datetime/settings-shared.h +++ b/include/datetime/settings-shared.h @@ -30,6 +30,16 @@ typedef enum } TimeFormatMode; +typedef enum +{ + ALARM_VOLUME_VERY_QUIET, + ALARM_VOLUME_QUIET, + ALARM_VOLUME_NORMAL, + ALARM_VOLUME_LOUD, + ALARM_VOLUME_VERY_LOUD +} +AlarmVolume; + #define SETTINGS_INTERFACE "com.canonical.indicator.datetime" #define SETTINGS_SHOW_CLOCK_S "show-clock" #define SETTINGS_TIME_FORMAT_S "time-format" @@ -45,5 +55,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_ALARM_SOUND_S "alarm-default-sound" +#define SETTINGS_ALARM_VOLUME_S "alarm-default-volume" #endif // INDICATOR_DATETIME_SETTINGS_SHARED diff --git a/include/datetime/settings.h b/include/datetime/settings.h index ce234d9..5a0f1eb 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -56,6 +56,8 @@ public: core::Property show_year; core::Property time_format_mode; core::Property timezone_name; + core::Property alarm_sound; + core::Property alarm_volume; }; } // namespace datetime diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 2305c93..ec78feb 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -52,6 +52,8 @@ LiveSettings::LiveSettings(): update_show_year(); update_time_format_mode(); update_timezone_name(); + update_alarm_sound(); + update_alarm_volume(); // now listen for clients to change the properties s.t. we can sync update GSettings @@ -115,6 +117,14 @@ LiveSettings::LiveSettings(): timezone_name.changed().connect([this](const std::string& value){ g_settings_set_string(m_settings, SETTINGS_TIMEZONE_NAME_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()); + }); + + alarm_volume.changed().connect([this](AlarmVolume value){ + g_settings_set_enum(m_settings, SETTINGS_ALARM_VOLUME_S, gint(value)); + }); } /*** @@ -205,6 +215,18 @@ void LiveSettings::update_timezone_name() g_free(val); } +void LiveSettings::update_alarm_sound() +{ + auto val = g_settings_get_string(m_settings, SETTINGS_ALARM_SOUND_S); + alarm_sound.set(val); + g_free(val); +} + +void LiveSettings::update_alarm_volume() +{ + alarm_volume.set((AlarmVolume)g_settings_get_enum(m_settings, SETTINGS_ALARM_VOLUME_S)); +} + /*** **** ***/ @@ -246,6 +268,10 @@ 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_ALARM_SOUND_S) + update_alarm_sound(); + else if (key == SETTINGS_ALARM_VOLUME_S) + update_alarm_volume(); } /*** diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index 707247d..9af803f 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -100,6 +100,31 @@ protected: EXPECT_EQ(str, tmp); g_clear_pointer(&tmp, g_free); } + +#if 0 + void TestIntProperty(core::Property& property, const gchar* key) + { + EXPECT_EQ(g_settings_get_int(m_gsettings, key), property.get()); + + int expected_values[] = { 1, 2, 3 }; + + // modify GSettings and confirm that the new value is propagated + for(const int& expected_value : expected_values) + { + g_settings_set_int(m_gsettings, key, expected_value); + EXPECT_EQ(expected_value, property.get()); + EXPECT_EQ(expected_value, g_settings_get_int(m_gsettings, key)); + } + + // modify the property and confirm that the new value is propagated + for(const int& expected_value : expected_values) + { + property.set(expected_value); + EXPECT_EQ(expected_value, property.get()); + EXPECT_EQ(expected_value, g_settings_get_int(m_gsettings, key)); + } + } +#endif }; /*** @@ -129,6 +154,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); } TEST_F(SettingsFixture, TimeFormatMode) @@ -152,6 +178,31 @@ TEST_F(SettingsFixture, TimeFormatMode) } } +TEST_F(SettingsFixture, AlarmVolume) +{ + const auto key = SETTINGS_ALARM_VOLUME_S; + const AlarmVolume volumes[] = { ALARM_VOLUME_VERY_QUIET, + ALARM_VOLUME_QUIET, + ALARM_VOLUME_NORMAL, + ALARM_VOLUME_LOUD, + ALARM_VOLUME_VERY_LOUD }; + + for(const auto& val : volumes) + { + g_settings_set_enum(m_gsettings, key, val); + EXPECT_EQ(val, m_settings->alarm_volume.get()); + EXPECT_EQ(val, g_settings_get_enum(m_gsettings, key)); + } + + for(const auto& val : volumes) + { + m_settings->alarm_volume.set(val); + EXPECT_EQ(val, m_settings->alarm_volume.get()); + EXPECT_EQ(val, g_settings_get_enum(m_gsettings, key)); + } +} + + namespace { std::vector strv_to_vector(const gchar** strv) -- cgit v1.2.3