aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-16 15:10:39 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-16 15:10:39 -0600
commitbcff13b6bce18604472e5954eb5ab7af4bb43b0f (patch)
tree3490b944b2f8be1e93312b643f21489d97ca84a9
parentee64bb2698adfe27e55615a8856b0e2c78ad8469 (diff)
downloadayatana-indicator-datetime-bcff13b6bce18604472e5954eb5ab7af4bb43b0f.tar.gz
ayatana-indicator-datetime-bcff13b6bce18604472e5954eb5ab7af4bb43b0f.tar.bz2
ayatana-indicator-datetime-bcff13b6bce18604472e5954eb5ab7af4bb43b0f.zip
Implement Settings, a properties-cpp wrapper around GSettings
-rw-r--r--include/datetime/settings-live.h19
-rw-r--r--include/datetime/settings.h16
-rw-r--r--src/settings-live.cpp410
-rw-r--r--tests/CMakeLists.txt14
-rw-r--r--tests/test-settings.cc197
5 files changed, 423 insertions, 233 deletions
diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h
index 44e27b0..202c998 100644
--- a/include/datetime/settings-live.h
+++ b/include/datetime/settings-live.h
@@ -38,10 +38,23 @@ public:
virtual ~LiveSettings();
private:
- void update_show_clock();
-
- void update_key(const std::string& key);
static void on_changed(GSettings*, gchar*, gpointer);
+ void update_key(const std::string& key);
+
+ void update_custom_time_format();
+ void update_locations();
+ void update_show_calendar();
+ void update_show_clock();
+ void update_show_date();
+ void update_show_day();
+ void update_show_detected_locations();
+ void update_show_events();
+ void update_show_locations();
+ void update_show_seconds();
+ void update_show_week_numbers();
+ void update_show_year();
+ void update_time_format_mode();
+ void update_timezone_name();
GSettings* m_settings;
diff --git a/include/datetime/settings.h b/include/datetime/settings.h
index 3d4bc33..418bc33 100644
--- a/include/datetime/settings.h
+++ b/include/datetime/settings.h
@@ -42,17 +42,19 @@ public:
Settings() =default;
virtual ~Settings() =default;
- core::Property<TimeFormatMode> time_format_mode;
- core::Property<bool> show_clock;
- core::Property<bool> show_day;
- core::Property<bool> show_year;
- core::Property<bool> show_seconds;
core::Property<std::string> custom_time_format;
+ core::Property<std::vector<std::string>> locations;
core::Property<bool> show_calendar;
+ core::Property<bool> show_clock;
+ core::Property<bool> show_date;
+ core::Property<bool> show_day;
+ core::Property<bool> show_detected_location;
core::Property<bool> show_events;
core::Property<bool> show_locations;
- core::Property<bool> show_auto_detected_location;
- core::Property<std::vector<std::string>> locations;
+ core::Property<bool> show_seconds;
+ core::Property<bool> show_week_numbers;
+ core::Property<bool> show_year;
+ core::Property<TimeFormatMode> time_format_mode;
core::Property<std::string> timezone_name;
};
diff --git a/src/settings-live.cpp b/src/settings-live.cpp
index 74085a9..2305c93 100644
--- a/src/settings-live.cpp
+++ b/src/settings-live.cpp
@@ -37,257 +37,221 @@ LiveSettings::LiveSettings():
{
g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed), this);
+ // init the Properties from the GSettings backend
+ update_custom_time_format();
+ update_locations();
+ update_show_calendar();
update_show_clock();
+ update_show_date();
+ update_show_day();
+ update_show_detected_locations();
+ update_show_events();
+ update_show_locations();
+ update_show_seconds();
+ update_show_week_numbers();
+ update_show_year();
+ update_time_format_mode();
+ update_timezone_name();
+
+ // now listen for clients to change the properties s.t. we can sync update GSettings
+
+ custom_time_format.changed().connect([this](const std::string& value){
+ g_settings_set_string(m_settings, SETTINGS_CUSTOM_TIME_FORMAT_S, value.c_str());
+ });
+
+ locations.changed().connect([this](const std::vector<std::string>& value){
+ const int n = value.size();
+ gchar** strv = g_new0(gchar*, n+1);
+ for(int i=0; i<n; i++)
+ strv[i] = const_cast<char*>(value[i].c_str());
+ g_settings_set_strv(m_settings, SETTINGS_LOCATIONS_S, strv);
+ g_free(strv);
+ });
+
+ show_calendar.changed().connect([this](bool value){
+ g_settings_set_boolean(m_settings, SETTINGS_SHOW_CALENDAR_S, value);
+ });
+
+ show_clock.changed().connect([this](bool value){
+ g_settings_set_boolean(m_settings, SETTINGS_SHOW_CLOCK_S, value);
+ });
+
+ show_date.changed().connect([this](bool value){
+ g_settings_set_boolean(m_settings, SETTINGS_SHOW_DATE_S, value);
+ });
+
+ show_day.changed().connect([this](bool value){
+ g_settings_set_boolean(m_settings, SETTINGS_SHOW_DAY_S, value);
+ });
+
+ show_detected_location.changed().connect([this](bool value){
+ g_settings_set_boolean(m_settings, SETTINGS_SHOW_DETECTED_S, value);
+ });
+
+ show_events.changed().connect([this](bool value){
+ g_settings_set_boolean(m_settings, SETTINGS_SHOW_EVENTS_S, value);
+ });
+
+ show_locations.changed().connect([this](bool value){
+ g_settings_set_boolean(m_settings, SETTINGS_SHOW_LOCATIONS_S, value);
+ });
+
+ show_seconds.changed().connect([this](bool value){
+ g_settings_set_boolean(m_settings, SETTINGS_SHOW_SECONDS_S, value);
+ });
+
+ show_week_numbers.changed().connect([this](bool value){
+ g_settings_set_boolean(m_settings, SETTINGS_SHOW_WEEK_NUMBERS_S, value);
+ });
+
+ show_year.changed().connect([this](bool value){
+ g_settings_set_boolean(m_settings, SETTINGS_SHOW_YEAR_S, value);
+ });
+
+ time_format_mode.changed().connect([this](TimeFormatMode value){
+ g_settings_set_enum(m_settings, SETTINGS_TIME_FORMAT_S, gint(value));
+ });
+
+ timezone_name.changed().connect([this](const std::string& value){
+ g_settings_set_string(m_settings, SETTINGS_TIMEZONE_NAME_S, value.c_str());
+ });
}
-void LiveSettings::update_show_clock()
+/***
+****
+***/
+
+void LiveSettings::update_custom_time_format()
{
- auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_CLOCK_S);
- show_clock.set(val);
+ auto val = g_settings_get_string(m_settings, SETTINGS_CUSTOM_TIME_FORMAT_S);
+ custom_time_format.set(val);
+ g_free(val);
}
-void LiveSettings::on_changed(GSettings* /*settings*/,
- gchar* key,
- gpointer gself)
+void LiveSettings::update_locations()
{
- static_cast<LiveSettings*>(gself)->update_key(key);
+ auto strv = g_settings_get_strv(m_settings, SETTINGS_LOCATIONS_S);
+ std::vector<std::string> l;
+ for(int i=0; strv && strv[i]; i++)
+ l.push_back(strv[i]);
+ g_strfreev(strv);
+ locations.set(l);
}
-void LiveSettings::update_key(const std::string& key)
+void LiveSettings::update_show_calendar()
{
- if (key == SETTINGS_SHOW_CLOCK_S)
- {
- update_show_clock();
- }
+ const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_CALENDAR_S);
+ show_calendar.set(val);
}
-/***
-****
-***/
-
-} // namespace datetime
-} // namespace indicator
-} // namespace unity
-
-#if 0
- else if (!g_strcmp0(key, TIME_FORMAT_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_TIME_FORMAT_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_SHOW_SECONDS_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_SHOW_DAY_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_SHOW_DATE_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_SHOW_YEAR_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_SHOW_CUSTOM_TIME_FORMAT_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_SHOW_CALENDAR_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_SHOW_WEEK_NUMBERS_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_SHOW_EVENTS_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_SHOW_LOCATIONS_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_TIMEZONE_NAME_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_SHOW_DETECTED_S))
- {
- }
- else if (!g_strcmp0(key, SETTINGS_LOCATIONS_S))
- {
- }
-#define SETTINGS_SHOW_DETECTED_S "show-auto-detected-location"
-#define SETTINGS_LOCATIONS_S "locations"
-#define SETTINGS_TIMEZONE_NAME_S "timezone-name"
- zzz
- "show-clock"
-
-void user_function (GSettings *settings,
- gchar *key,
- gpointer user_data) : Has Details
-
- for (i=0, n=G_N_ELEMENTS(header_settings); i<n; i++)
- {
- g_string_printf (gstr, "changed::%s", header_settings[i]);
- g_signal_connect_swapped (p->settings, gstr->str,
- G_CALLBACK(rebuild_header_soon), self);
- }
-
-
- const char * const calendar_settings[] = {
- SETTINGS_SHOW_CALENDAR_S,
- SETTINGS_SHOW_WEEK_NUMBERS_S
- };
- const char * const appointment_settings[] = {
- SETTINGS_SHOW_EVENTS_S,
- SETTINGS_TIME_FORMAT_S,
- SETTINGS_SHOW_SECONDS_S
- };
- const char * const location_settings[] = {
- SETTINGS_TIME_FORMAT_S,
- SETTINGS_SHOW_SECONDS_S,
- SETTINGS_CUSTOM_TIME_FORMAT_S,
- SETTINGS_SHOW_LOCATIONS_S,
- SETTINGS_LOCATIONS_S,
- SETTINGS_SHOW_DETECTED_S,
- SETTINGS_TIMEZONE_NAME_S
- };
- const char * const time_format_string_settings[] = {
- SETTINGS_TIME_FORMAT_S,
- SETTINGS_SHOW_SECONDS_S,
- SETTINGS_CUSTOM_TIME_FORMAT_S
- };
-
-
- /***
- **** Listen for settings changes
- ***/
-
- for (i=0, n=G_N_ELEMENTS(header_settings); i<n; i++)
- {
- g_string_printf (gstr, "changed::%s", header_settings[i]);
- g_signal_connect_swapped (p->settings, gstr->str,
- G_CALLBACK(rebuild_header_soon), self);
- }
-
+void LiveSettings::update_show_clock()
+{
+ show_clock.set(g_settings_get_boolean(m_settings, SETTINGS_SHOW_CLOCK_S));
}
+void LiveSettings::update_show_date()
+{
+ show_date.set(g_settings_get_boolean(m_settings, SETTINGS_SHOW_DATE_S));
+}
-#ifndef INDICATOR_DATETIME_SETTINGS_LIVE_H
-#define INDICATOR_DATETIME_SETTINGS_LIVE_H
-
-#include <datetime/settings.h> // parent class
-
-#include <glib.h> // GSettings
-
-namespace unity {
-namespace indicator {
-namespace datetime {
-
-/**
- * \brief #Settings implementation which uses GSettings.
- */
-class LiveSettings
+void LiveSettings::update_show_day()
{
-public:
- LiveSettings();
- virtual ~LiveSettings();
+ show_day.set(g_settings_get_boolean(m_settings, SETTINGS_SHOW_DAY_S));
+}
-private:
- GSettings* m_settings;
+void LiveSettings::update_show_detected_locations()
+{
+ const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_DETECTED_S);
+ show_detected_location.set(val);
+}
- // we've got a raw pointer here, so disable copying
- LiveSettings(const LiveSettings&) =delete;
- LiveSettings& operator=(const LiveSettings&) =delete;
-};
+void LiveSettings::update_show_events()
+{
+ const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_EVENTS_S);
+ show_events.set(val);
+}
+void LiveSettings::update_show_locations()
+{
+ const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_LOCATIONS_S);
+ show_locations.set(val);
+}
-#endif // INDICATOR_DATETIME_SETTINGS_LIVE_H
-/*
- * Copyright 2010 Canonical Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Ted Gould <ted@canonical.com>
- * Charles Kerr <charles.kerr@canonical.com>
- */
+void LiveSettings::update_show_seconds()
+{
+ show_seconds.set(g_settings_get_boolean(m_settings, SETTINGS_SHOW_SECONDS_S));
+}
-#ifndef INDICATOR_DATETIME_SETTINGS_SHARED
-#define INDICATOR_DATETIME_SETTINGS_SHARED
+void LiveSettings::update_show_week_numbers()
+{
+ const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_WEEK_NUMBERS_S);
+ show_week_numbers.set(val);
+}
-typedef enum
+void LiveSettings::update_show_year()
{
- TIME_FORMAT_MODE_LOCALE_DEFAULT,
- TIME_FORMAT_MODE_12_HOUR,
- TIME_FORMAT_MODE_24_HOUR,
- TIME_FORMAT_MODE_CUSTOM
+ show_year.set(g_settings_get_boolean(m_settings, SETTINGS_SHOW_YEAR_S));
}
-TimeFormatMode;
+void LiveSettings::update_time_format_mode()
+{
+ time_format_mode.set((TimeFormatMode)g_settings_get_enum(m_settings, SETTINGS_TIME_FORMAT_S));
+}
-#endif // INDICATOR_DATETIME_SETTINGS_SHARED
-/*
- * Copyright 2013 Canonical Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- */
+void LiveSettings::update_timezone_name()
+{
+ auto val = g_settings_get_string(m_settings, SETTINGS_TIMEZONE_NAME_S);
+ timezone_name.set(val);
+ g_free(val);
+}
-#ifndef INDICATOR_DATETIME_SETTINGS_H
-#define INDICATOR_DATETIME_SETTINGS_H
+/***
+****
+***/
-#include <datetime/settings-shared.h>
+void LiveSettings::on_changed(GSettings* /*settings*/,
+ gchar* key,
+ gpointer gself)
+{
+ static_cast<LiveSettings*>(gself)->update_key(key);
+}
-#include <core/property.h>
+void LiveSettings::update_key(const std::string& key)
+{
+ if (key == SETTINGS_SHOW_CLOCK_S)
+ update_show_clock();
+ else if (key == SETTINGS_LOCATIONS_S)
+ update_locations();
+ else if (key == SETTINGS_TIME_FORMAT_S)
+ update_time_format_mode();
+ else if (key == SETTINGS_SHOW_SECONDS_S)
+ update_show_seconds();
+ else if (key == SETTINGS_SHOW_DAY_S)
+ update_show_day();
+ else if (key == SETTINGS_SHOW_DATE_S)
+ update_show_date();
+ else if (key == SETTINGS_SHOW_YEAR_S)
+ update_show_year();
+ else if (key == SETTINGS_CUSTOM_TIME_FORMAT_S)
+ update_custom_time_format();
+ else if (key == SETTINGS_SHOW_CALENDAR_S)
+ update_show_calendar();
+ else if (key == SETTINGS_SHOW_WEEK_NUMBERS_S)
+ update_show_week_numbers();
+ else if (key == SETTINGS_SHOW_EVENTS_S)
+ update_show_events();
+ else if (key == SETTINGS_SHOW_LOCATIONS_S)
+ update_show_locations();
+ else if (key == SETTINGS_SHOW_DETECTED_S)
+ update_show_detected_locations();
+ else if (key == SETTINGS_TIMEZONE_NAME_S)
+ update_timezone_name();
+}
-namespace unity {
-namespace indicator {
-namespace datetime {
+/***
+****
+***/
-/**
- * \brief Interface that represents user-configurable settings.
- *
- * See the descriptions in data/com.canonical.indicator.datetime.gschema.xml
- * For more information.
- */
-class Settings
-{
-public:
- Settings() =default;
- virtual ~Settings =default;
-
- core::Property<TimeFormatMode> time_format_mode;
- core::Property<bool> show_clock;
- core::Property<bool> show_day;
- core::Property<bool> show_year;
- core::Property<bool> show_seconds;
- core::Property<std::string> custom_time_format;
- core::Property<bool> show_calendar;
- core::Property<bool> show_events;
- core::Property<bool> show_locations;
- core::Property<bool> show_auto_detected_location;
- core::Property<std::vector<std::string>> locations;
- core::Property<std::string> timezone_name;
-};
-
-#endif // INDICATOR_DATETIME_SETTINGS_H
-#endif
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index fb55f5a..a908801 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -91,6 +91,20 @@ add_test (${TEST_NAME} ${TEST_NAME})
add_dependencies (${TEST_NAME} libindicatordatetimeservice)
target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS})
+# test-utils
+set (TEST_NAME test-utils)
+add_executable (${TEST_NAME} ${TEST_NAME}.cc)
+add_test (${TEST_NAME} ${TEST_NAME})
+add_dependencies (${TEST_NAME} libindicatordatetimeservice)
+target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS})
+
+# test-utils
+set (TEST_NAME test-settings)
+add_executable (${TEST_NAME} ${TEST_NAME}.cc)
+add_test (${TEST_NAME} ${TEST_NAME})
+add_dependencies (${TEST_NAME} libindicatordatetimeservice)
+target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS})
+
# test-desktop
#set (TEST_NAME test-desktop)
#add_executable (${TEST_NAME} ${TEST_NAME}.cc)
diff --git a/tests/test-settings.cc b/tests/test-settings.cc
new file mode 100644
index 0000000..9e52197
--- /dev/null
+++ b/tests/test-settings.cc
@@ -0,0 +1,197 @@
+/*
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "glib-fixture.h"
+
+#include <datetime/settings-live.h>
+#include <datetime/settings-shared.h>
+
+using namespace unity::indicator::datetime;
+
+/***
+****
+***/
+
+class SettingsFixture: public GlibFixture
+{
+private:
+ typedef GlibFixture super;
+
+protected:
+
+ std::shared_ptr<LiveSettings> m_live;
+ std::shared_ptr<Settings> m_settings;
+ GSettings * m_gsettings;
+
+ virtual void SetUp()
+ {
+ super::SetUp();
+
+ m_gsettings = g_settings_new(SETTINGS_INTERFACE);
+ m_live.reset(new LiveSettings);
+ m_settings = std::dynamic_pointer_cast<Settings>(m_live);
+ }
+
+ virtual void TearDown()
+ {
+ g_clear_object(&m_gsettings);
+ m_settings.reset();
+ m_live.reset();
+
+ super::TearDown();
+ }
+
+ void TestBoolProperty(core::Property<bool>& property, const gchar* key)
+ {
+ EXPECT_EQ(g_settings_get_boolean(m_gsettings, key), property.get());
+ g_settings_set_boolean(m_gsettings, key, false);
+ EXPECT_EQ(false, property.get());
+ g_settings_set_boolean(m_gsettings, key, true);
+ EXPECT_EQ(true, property.get());
+
+ property.set(false);
+ EXPECT_EQ(false, g_settings_get_boolean(m_gsettings, key));
+ property.set(true);
+ EXPECT_EQ(true, g_settings_get_boolean(m_gsettings, key));
+ }
+
+ void TestStringProperty(core::Property<std::string>& property, const gchar* key)
+ {
+ gchar* tmp;
+ std::string str;
+
+ tmp = g_settings_get_string(m_gsettings, key);
+ EXPECT_EQ(tmp, property.get());
+ g_clear_pointer(&tmp, g_free);
+
+ str = "a";
+ g_settings_set_string(m_gsettings, key, str.c_str());
+ EXPECT_EQ(str, property.get());
+
+ str = "b";
+ g_settings_set_string(m_gsettings, key, str.c_str());
+ EXPECT_EQ(str, property.get());
+
+ str = "a";
+ property.set(str);
+ tmp = g_settings_get_string(m_gsettings, key);
+ EXPECT_EQ(str, tmp);
+ g_clear_pointer(&tmp, g_free);
+
+ str = "b";
+ property.set(str);
+ tmp = g_settings_get_string(m_gsettings, key);
+ EXPECT_EQ(str, tmp);
+ g_clear_pointer(&tmp, g_free);
+ }
+};
+
+/***
+****
+***/
+
+TEST_F(SettingsFixture, HelloWorld)
+{
+ EXPECT_TRUE(true);
+}
+
+TEST_F(SettingsFixture, BoolProperties)
+{
+ TestBoolProperty(m_settings->show_seconds, SETTINGS_SHOW_SECONDS_S);
+ TestBoolProperty(m_settings->show_calendar, SETTINGS_SHOW_CALENDAR_S);
+ TestBoolProperty(m_settings->show_clock, SETTINGS_SHOW_CLOCK_S);
+ TestBoolProperty(m_settings->show_date, SETTINGS_SHOW_DATE_S);
+ TestBoolProperty(m_settings->show_day, SETTINGS_SHOW_DAY_S);
+ TestBoolProperty(m_settings->show_detected_location, SETTINGS_SHOW_DETECTED_S);
+ TestBoolProperty(m_settings->show_events, SETTINGS_SHOW_EVENTS_S);
+ TestBoolProperty(m_settings->show_locations, SETTINGS_SHOW_LOCATIONS_S);
+ TestBoolProperty(m_settings->show_week_numbers, SETTINGS_SHOW_WEEK_NUMBERS_S);
+ TestBoolProperty(m_settings->show_year, SETTINGS_SHOW_YEAR_S);
+}
+
+TEST_F(SettingsFixture, StringProperties)
+{
+ TestStringProperty(m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S);
+ TestStringProperty(m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S);
+}
+
+TEST_F(SettingsFixture, TimeFormatMode)
+{
+ const auto key = SETTINGS_TIME_FORMAT_S;
+ const TimeFormatMode modes[] = { TIME_FORMAT_MODE_LOCALE_DEFAULT,
+ TIME_FORMAT_MODE_12_HOUR,
+ TIME_FORMAT_MODE_24_HOUR,
+ TIME_FORMAT_MODE_CUSTOM };
+
+ for(const auto& mode : modes)
+ {
+ g_settings_set_enum(m_gsettings, key, mode);
+ EXPECT_EQ(mode, m_settings->time_format_mode.get());
+ }
+
+ for(const auto& mode : modes)
+ {
+ m_settings->time_format_mode.set(mode);
+ EXPECT_EQ(mode, g_settings_get_enum(m_gsettings, key));
+ }
+}
+
+namespace
+{
+ std::vector<std::string> strv_to_vector(const gchar** strv)
+ {
+ std::vector<std::string> v;
+ for(int i=0; strv && strv[i]; i++)
+ v.push_back(strv[i]);
+ return v;
+ }
+};
+
+TEST_F(SettingsFixture, Locations)
+{
+ const auto key = SETTINGS_LOCATIONS_S;
+
+ const gchar* astrv[] = {"America/Los_Angeles Oakland", "America/Chicago Oklahoma City", "Europe/London London", NULL};
+ const gchar* bstrv[] = {"America/Denver", "Europe/London London", "Europe/Berlin Berlin", NULL};
+ const std::vector<std::string> av = strv_to_vector(astrv);
+ const std::vector<std::string> bv = strv_to_vector(bstrv);
+
+ g_settings_set_strv(m_gsettings, key, astrv);
+ EXPECT_EQ(av, m_settings->locations.get());
+ g_settings_set_strv(m_gsettings, key, bstrv);
+ EXPECT_EQ(bv, m_settings->locations.get());
+
+ m_settings->locations.set(av);
+ auto tmp = g_settings_get_strv(m_gsettings, key);
+ auto vtmp = strv_to_vector((const gchar**)tmp);
+ g_strfreev(tmp);
+ EXPECT_EQ(av, vtmp);
+
+ m_settings->locations.set(bv);
+ tmp = g_settings_get_strv(m_gsettings, key);
+ vtmp = strv_to_vector((const gchar**)tmp);
+ g_strfreev(tmp);
+ EXPECT_EQ(bv, vtmp);
+}
+
+#if 0
+ core::Property<std::vector<std::string>> locations;
+ core::Property<TimeFormatMode> time_format_mode;
+
+#endif