diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2014-06-23 18:52:52 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2014-06-23 18:52:52 -0500 |
commit | a85fd44e7b2dc67b3e0712e174e88d0eb6c467e7 (patch) | |
tree | 222a1f286be139627a89d31a9db414b2d174f423 | |
parent | f6778e1cc3e3881225e967c94de4685c732755db (diff) | |
download | ayatana-indicator-datetime-a85fd44e7b2dc67b3e0712e174e88d0eb6c467e7.tar.gz ayatana-indicator-datetime-a85fd44e7b2dc67b3e0712e174e88d0eb6c467e7.tar.bz2 ayatana-indicator-datetime-a85fd44e7b2dc67b3e0712e174e88d0eb6c467e7.zip |
add GSettings support for specifying a default alarm sound and default alarm volume.
-rw-r--r-- | data/com.canonical.indicator.datetime.gschema.xml | 21 | ||||
-rw-r--r-- | include/datetime/settings-live.h | 2 | ||||
-rw-r--r-- | include/datetime/settings-shared.h | 12 | ||||
-rw-r--r-- | include/datetime/settings.h | 2 | ||||
-rw-r--r-- | src/settings-live.cpp | 26 | ||||
-rw-r--r-- | tests/test-settings.cpp | 51 |
6 files changed, 114 insertions, 0 deletions
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 @@ <value nick="24-hour" value="2" /> <value nick="custom" value="3" /> </enum> + <enum id="alarm-volume-enum"> + <value nick="very-quiet" value="0" /> + <value nick="quiet" value="1" /> + <value nick="normal" value="2" /> + <value nick="loud" value="3" /> + <value nick="very-loud" value="4" /> + </enum> <schema id="com.canonical.indicator.datetime" path="/com/canonical/indicator/datetime/" gettext-domain="indicator-datetime"> <key name="show-clock" type="b"> <default>true</default> @@ -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). </description> </key> + <key name="alarm-default-sound" type="s"> + <default>'/usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg'</default> + <summary>The alarm's default sound file.</summary> + <description> + If an alarm doesn't specify its own sound file, this file will be used as the fallback sound. + </description> + </key> + <key name="alarm-default-volume" enum="alarm-volume-enum"> + <default>'normal'</default> + <summary>The alarm's default volume level.</summary> + <description> + The volume at which alarms will be played. + </description> + </key> </schema> </schemalist> 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<bool> show_year; core::Property<TimeFormatMode> time_format_mode; core::Property<std::string> timezone_name; + core::Property<std::string> alarm_sound; + core::Property<AlarmVolume> 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<int>& 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<std::string> strv_to_vector(const gchar** strv) |