aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-06-27 09:46:21 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-06-27 09:46:21 -0500
commiteebf8f911cedf5124ada2f91576f821da6f421b0 (patch)
tree446610632a4c784cc5f8cae8d588818c8da84f55
parenta872431f78e5518419c6af5e365db972f362ba9a (diff)
downloadayatana-indicator-datetime-eebf8f911cedf5124ada2f91576f821da6f421b0.tar.gz
ayatana-indicator-datetime-eebf8f911cedf5124ada2f91576f821da6f421b0.tar.bz2
ayatana-indicator-datetime-eebf8f911cedf5124ada2f91576f821da6f421b0.zip
use unsigned ints for the alarm volume, duration properties
-rw-r--r--data/com.canonical.indicator.datetime.gschema.xml.in4
-rw-r--r--include/datetime/settings.h4
-rw-r--r--src/exporter.cpp24
-rw-r--r--src/settings-live.cpp12
-rw-r--r--src/snap.cpp18
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/test-settings.cpp22
7 files changed, 45 insertions, 43 deletions
diff --git a/data/com.canonical.indicator.datetime.gschema.xml.in b/data/com.canonical.indicator.datetime.gschema.xml.in
index 776f6c7..62b42c1 100644
--- a/data/com.canonical.indicator.datetime.gschema.xml.in
+++ b/data/com.canonical.indicator.datetime.gschema.xml.in
@@ -130,7 +130,7 @@
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" type="i">
+ <key name="alarm-default-volume" type="u">
<range min="1" max="100"/>
<default>50</default>
<_summary>The alarm's default volume level.</_summary>
@@ -138,7 +138,7 @@
The volume at which alarms will be played.
</_description>
</key>
- <key name="alarm-duration-minutes" type="i">
+ <key name="alarm-duration-minutes" type="u">
<range min="1" max="60"/>
<default>30</default>
<_summary>The alarm's duration.</_summary>
diff --git a/include/datetime/settings.h b/include/datetime/settings.h
index 26d4ed0..e5f885e 100644
--- a/include/datetime/settings.h
+++ b/include/datetime/settings.h
@@ -57,8 +57,8 @@ public:
core::Property<TimeFormatMode> time_format_mode;
core::Property<std::string> timezone_name;
core::Property<std::string> alarm_sound;
- core::Property<int> alarm_volume;
- core::Property<int> alarm_duration;
+ core::Property<unsigned int> alarm_volume;
+ core::Property<unsigned int> alarm_duration;
};
} // namespace datetime
diff --git a/src/exporter.cpp b/src/exporter.cpp
index a5a059d..e2b60f2 100644
--- a/src/exporter.cpp
+++ b/src/exporter.cpp
@@ -107,20 +107,22 @@ private:
G_CALLBACK(on_gobject_notify_string), &p);
// when the Settings changes, update the GObject
- p.changed().connect([o, propname](const std::string& s){
- g_object_set(o, propname, s.c_str(), nullptr);
+ p.changed().connect([o, propname](const std::string& val){
+ g_object_set(o, propname, val.c_str(), nullptr);
});
}
static void
- on_gobject_notify_int(GObject* o, GParamSpec* pspec, gpointer p)
+ on_gobject_notify_uint(GObject* o, GParamSpec* pspec, gpointer p)
{
- int val = 0;
+ uint val = 0;
g_object_get (o, pspec->name, &val, nullptr);
- static_cast<core::Property<int>*>(p)->set(val);
+ static_cast<core::Property<unsigned int>*>(p)->set(val);
}
- void bind_int_property(gpointer o, const char* propname, core::Property<int>& p)
+ void bind_uint_property(gpointer o,
+ const char* propname,
+ core::Property<unsigned int>& p)
{
// initialize the GObject property from the Settings
g_object_set(o, propname, p.get(), nullptr);
@@ -128,19 +130,19 @@ private:
// when the GObject changes, update the Settings
const std::string notify_propname = std::string("notify::") + propname;
g_signal_connect(o, notify_propname.c_str(),
- G_CALLBACK(on_gobject_notify_int), &p);
+ G_CALLBACK(on_gobject_notify_uint), &p);
// when the Settings changes, update the GObject
- p.changed().connect([o, propname](int i){
- g_object_set(o, propname, i, nullptr);
+ p.changed().connect([o, propname](unsigned int val){
+ g_object_set(o, propname, val, nullptr);
});
}
void alarm_properties_init()
{
- bind_int_property(m_alarm_props, "duration", m_settings->alarm_duration);
- bind_int_property(m_alarm_props, "default-volume", m_settings->alarm_volume);
+ bind_uint_property(m_alarm_props, "duration", m_settings->alarm_duration);
+ bind_uint_property(m_alarm_props, "default-volume", m_settings->alarm_volume);
bind_string_property(m_alarm_props, "default-sound", m_settings->alarm_sound);
}
diff --git a/src/settings-live.cpp b/src/settings-live.cpp
index 369d2d6..71bbd96 100644
--- a/src/settings-live.cpp
+++ b/src/settings-live.cpp
@@ -123,12 +123,12 @@ LiveSettings::LiveSettings():
g_settings_set_string(m_settings, SETTINGS_ALARM_SOUND_S, value.c_str());
});
- alarm_volume.changed().connect([this](int value){
- g_settings_set_int(m_settings, SETTINGS_ALARM_VOLUME_S, value);
+ alarm_volume.changed().connect([this](unsigned int value){
+ g_settings_set_uint(m_settings, SETTINGS_ALARM_VOLUME_S, value);
});
- alarm_duration.changed().connect([this](int value){
- g_settings_set_int(m_settings, SETTINGS_ALARM_DURATION_S, value);
+ alarm_duration.changed().connect([this](unsigned int value){
+ g_settings_set_uint(m_settings, SETTINGS_ALARM_DURATION_S, value);
});
}
@@ -229,12 +229,12 @@ void LiveSettings::update_alarm_sound()
void LiveSettings::update_alarm_volume()
{
- alarm_volume.set(g_settings_get_int(m_settings, SETTINGS_ALARM_VOLUME_S));
+ alarm_volume.set(g_settings_get_uint(m_settings, SETTINGS_ALARM_VOLUME_S));
}
void LiveSettings::update_alarm_duration()
{
- alarm_duration.set(g_settings_get_int(m_settings, SETTINGS_ALARM_DURATION_S));
+ alarm_duration.set(g_settings_get_uint(m_settings, SETTINGS_ALARM_DURATION_S));
}
/***
diff --git a/src/snap.cpp b/src/snap.cpp
index 40fd541..eab7001 100644
--- a/src/snap.cpp
+++ b/src/snap.cpp
@@ -54,8 +54,8 @@ public:
Sound(const std::shared_ptr<Clock>& clock,
const std::string& filename,
- int volume,
- int duration_minutes,
+ unsigned int volume,
+ unsigned int duration_minutes,
bool loop):
m_clock(clock),
m_filename(filename),
@@ -132,9 +132,9 @@ private:
g_clear_pointer(&props, ca_proplist_destroy);
}
- static float get_gain_level(int volume)
+ static float get_gain_level(unsigned int volume)
{
- const int clamped_volume = CLAMP(volume, 1, 100);
+ const unsigned int clamped_volume = CLAMP(volume, 1, 100);
/* This range isn't set in stone --
arrived at from manual tests on Nextus 4 */
@@ -181,7 +181,7 @@ private:
const std::shared_ptr<Clock> m_clock;
const std::string m_filename;
- const int m_volume;
+ const unsigned int m_volume;
const bool m_loop;
const int32_t m_canberra_id;
const DateTime m_loop_end_time;
@@ -194,8 +194,8 @@ class SoundBuilder
public:
void set_clock(const std::shared_ptr<Clock>& c) {m_clock = c;}
void set_filename(const std::string& s) {m_filename = s;}
- void set_volume(const int v) {m_volume = v;}
- void set_duration_minutes(int i) {m_duration_minutes=i;}
+ void set_volume(const unsigned int v) {m_volume = v;}
+ void set_duration_minutes(int unsigned i) {m_duration_minutes=i;}
void set_looping(bool b) {m_looping=b;}
Sound* operator()() {
@@ -209,8 +209,8 @@ public:
private:
std::shared_ptr<Clock> m_clock;
std::string m_filename;
- int m_volume = 50;
- int m_duration_minutes = 30;
+ unsigned int m_volume = 50;
+ unsigned int m_duration_minutes = 30;
bool m_looping = true;
};
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 26b326d..958e1cc 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -21,8 +21,8 @@ execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compil
OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_command (OUTPUT gschemas.compiled
- DEPENDS ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.datetime.gschema.xml
- COMMAND cp -f ${CMAKE_SOURCE_DIR}/data/*gschema.xml ${SCHEMA_DIR}
+ DEPENDS ${CMAKE_BINARY_DIR}/data/com.canonical.indicator.datetime.gschema.xml
+ COMMAND cp -f ${CMAKE_BINARY_DIR}/data/*gschema.xml ${SCHEMA_DIR}
COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR})
# look for headers in our src dir, and also in the directories where we autogenerate files...
diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp
index e4aeef7..44a0252 100644
--- a/tests/test-settings.cpp
+++ b/tests/test-settings.cpp
@@ -101,26 +101,26 @@ protected:
g_clear_pointer(&tmp, g_free);
}
- void TestIntProperty(core::Property<int>& property, const gchar* key)
+ void TestUIntProperty(core::Property<unsigned int>& property, const gchar* key)
{
- EXPECT_EQ(g_settings_get_int(m_gsettings, key), property.get());
+ EXPECT_EQ(g_settings_get_uint(m_gsettings, key), property.get());
- int expected_values[] = { 1, 2, 3 };
+ unsigned int expected_values[] = { 1, 2, 3 };
// modify GSettings and confirm that the new value is propagated
- for(const int& expected_value : expected_values)
+ for(const auto& expected_value : expected_values)
{
- g_settings_set_int(m_gsettings, key, expected_value);
+ g_settings_set_uint(m_gsettings, key, expected_value);
EXPECT_EQ(expected_value, property.get());
- EXPECT_EQ(expected_value, g_settings_get_int(m_gsettings, key));
+ EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key));
}
// modify the property and confirm that the new value is propagated
- for(const int& expected_value : expected_values)
+ for(const auto& 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));
+ EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key));
}
}
};
@@ -148,10 +148,10 @@ TEST_F(SettingsFixture, BoolProperties)
TestBoolProperty(m_settings->show_year, SETTINGS_SHOW_YEAR_S);
}
-TEST_F(SettingsFixture, IntProperties)
+TEST_F(SettingsFixture, UIntProperties)
{
- TestIntProperty(m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S);
- TestIntProperty(m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S);
+ TestUIntProperty(m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S);
+ TestUIntProperty(m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S);
}
TEST_F(SettingsFixture, StringProperties)