Merge lp:~azzar1/unity/gsettings-property into lp:unity

Proposed by Andrea Azzarone
Status: Work in progress
Proposed branch: lp:~azzar1/unity/gsettings-property
Merge into: lp:unity
Diff against target: 1297 lines (+882/-144)
15 files modified
UnityCore/CMakeLists.txt (+3/-0)
UnityCore/GSettingsProperty-inl.h (+129/-0)
UnityCore/GSettingsProperty.cpp (+118/-0)
UnityCore/GSettingsProperty.h (+85/-0)
UnityCore/GSettingsScopes.cpp (+1/-1)
UnityCore/GnomeSessionManager.cpp (+3/-5)
UnityCore/Variant.cpp (+39/-0)
UnityCore/Variant.h (+2/-0)
launcher/DevicesSettingsImp.cpp (+14/-59)
lockscreen/LockScreenAcceleratorController.cpp (+12/-26)
plugins/unityshell/src/WindowMinimizeSpeedController.cpp (+17/-40)
plugins/unityshell/src/WindowMinimizeSpeedController.h (+5/-13)
tests/CMakeLists.txt (+1/-0)
tests/data/external.gschema.xml (+30/-0)
tests/test_gsettings_property.cpp (+423/-0)
To merge this branch: bzr merge lp:~azzar1/unity/gsettings-property
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+248368@code.launchpad.net
To post a comment you must log in.
lp:~azzar1/unity/gsettings-property updated
3915. By Andrea Azzarone

Actually connect to changed::* signal in MenuManager.cpp. Fixes: #1411620
Approved by: PS Jenkins bot, Marco Trevisan (Treviño)

3916. By Andrea Azzarone

Actually connect to changed::* signal in UnitySettings.cpp. Fixes: #1408212
Approved by: PS Jenkins bot, Marco Trevisan (Treviño)

3917. By Brandon Schaefer

Try to set the folder permission otherwise Handle permission error. Fixes: #1418255
Approved by: PS Jenkins bot, Andrea Azzarone, Marco Trevisan (Treviño)

3918. By CI Train Bot Account

Releasing 7.3.1+15.04.20150205-0ubuntu1

3919. By Stephen M. Webb

Release 7.3.1

3920. By Marco Trevisan (Treviño)

Decorations, Panel: add menus for unfocused windows as well

Now the indicator-appmenu exports the menus for all the windows,
then it's up to us to filter them based on their parent window and
show on relevant place.
Also, set LIM as default now. Fixes: #1309778
Approved by: Andrea Azzarone, PS Jenkins bot

3921. By CI Train Bot Account

Releasing 7.3.1+15.04.20150219.2-0ubuntu1

3922. By Andrea Azzarone

Merge with trunk and change API.

3923. By Andrea Azzarone

Use GSettingsProperty in GnomeSessionManager.cpp

3924. By Andrea Azzarone

Lazy initialize GSettingsProperty.

3925. By Andrea Azzarone

Use GsettingsProperty in DevicesSettingsImp.cpp

3926. By Andrea Azzarone

Move template specialiazation in a cpp file.

3927. By Andrea Azzarone

Use GSettingsProperty in LockScreenAcceleratorController.cpp

3928. By Andrea Azzarone

Commit to save changes.

Unmerged revisions

3928. By Andrea Azzarone

Commit to save changes.

3927. By Andrea Azzarone

Use GSettingsProperty in LockScreenAcceleratorController.cpp

3926. By Andrea Azzarone

Move template specialiazation in a cpp file.

3925. By Andrea Azzarone

Use GsettingsProperty in DevicesSettingsImp.cpp

3924. By Andrea Azzarone

Lazy initialize GSettingsProperty.

3923. By Andrea Azzarone

Use GSettingsProperty in GnomeSessionManager.cpp

3922. By Andrea Azzarone

Merge with trunk and change API.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UnityCore/CMakeLists.txt'
--- UnityCore/CMakeLists.txt 2014-12-19 16:37:49 +0000
+++ UnityCore/CMakeLists.txt 2015-02-27 17:17:17 +0000
@@ -33,6 +33,8 @@
33 GLibWrapper.h33 GLibWrapper.h
34 GLibWrapper-inl.h34 GLibWrapper-inl.h
35 GnomeSessionManager.h35 GnomeSessionManager.h
36 GSettingsProperty.h
37 GSettingsProperty-inl.h
36 GSettingsScopes.h38 GSettingsScopes.h
37 Hud.h39 Hud.h
38 IndicatorEntry.h40 IndicatorEntry.h
@@ -86,6 +88,7 @@
86 GLibSource.cpp88 GLibSource.cpp
87 GLibWrapper.cpp89 GLibWrapper.cpp
88 GnomeSessionManager.cpp90 GnomeSessionManager.cpp
91 GSettingsProperty.cpp
89 GSettingsScopes.cpp92 GSettingsScopes.cpp
90 Hud.cpp93 Hud.cpp
91 Indicator.cpp94 Indicator.cpp
9295
=== added file 'UnityCore/GSettingsProperty-inl.h'
--- UnityCore/GSettingsProperty-inl.h 1970-01-01 00:00:00 +0000
+++ UnityCore/GSettingsProperty-inl.h 2015-02-27 17:17:17 +0000
@@ -0,0 +1,129 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2015 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more detais.
13 *
14 * You shoud have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
18 */
19
20#ifndef UNITY_GSETTINGS_PROPERTY_INL_H
21#define UNITY_GSETTINGS_PROPERTY_INL_H
22
23#include <type_traits>
24
25namespace unity
26{
27
28template<typename VALUE_TYPE>
29GSettingsProperty<VALUE_TYPE>::GSettingsProperty(glib::Object<GSettings> const& gsettings,
30 std::string const& key,
31 CallbackType const& cb)
32 : gsettings_(gsettings)
33 , key_(key)
34 , cb_(cb)
35 , loaded_(false)
36{
37 if (cb_)
38 key_changed_.Connect(gsettings_, "changed::"+key, [this] (GSettings*, gchar*) { OnChangedCb(); });
39}
40
41template<typename VALUE_TYPE>
42GSettingsProperty<VALUE_TYPE>::GSettingsProperty(std::string const& schema_id,
43 std::string const& key,
44 CallbackType const& cb)
45 : GSettingsProperty(glib::Object<GSettings>(g_settings_new(schema_id.c_str())), key, cb)
46{}
47
48template <typename VALUE_TYPE>
49VALUE_TYPE GSettingsProperty<VALUE_TYPE>::operator=(VALUE_TYPE const& value)
50{
51 return Set(value);
52}
53
54template <typename VALUE_TYPE>
55GSettingsProperty<VALUE_TYPE>::operator VALUE_TYPE() const
56{
57 return Get();
58}
59
60template <typename VALUE_TYPE>
61VALUE_TYPE GSettingsProperty<VALUE_TYPE>::operator()() const
62{
63 return Get();
64}
65
66template <typename VALUE_TYPE>
67VALUE_TYPE GSettingsProperty<VALUE_TYPE>::operator()(VALUE_TYPE const& value)
68{
69 return Set(value);
70}
71
72template <typename VALUE_TYPE>
73VALUE_TYPE GSettingsProperty<VALUE_TYPE>::Get() const
74{
75 if (cb_ && loaded_)
76 {
77 return value_;
78 }
79 else
80 {
81 loaded_ = true;
82 return getter_function<VALUE_TYPE>();
83 }
84}
85
86template <typename VALUE_TYPE>
87VALUE_TYPE GSettingsProperty<VALUE_TYPE>::Set(VALUE_TYPE const& value)
88{
89 if (cb_ && loaded_ && value != value_)
90 {
91 if (setter_function<VALUE_TYPE>(value))
92 value_ = value;
93 return value_;
94 }
95 else
96 {
97 setter_function<VALUE_TYPE>(value);
98 return value;
99 }
100}
101
102template<typename VALUE_TYPE>
103void GSettingsProperty<VALUE_TYPE>::OnChangedCb()
104{
105 auto value = getter_function<VALUE_TYPE>();
106
107 if (value_ != value)
108 cb_(value_ = value);
109}
110
111// enum
112template<typename VALUE_TYPE> template<typename X>
113typename std::enable_if<std::is_enum<X>::value, bool>::type
114GSettingsProperty<VALUE_TYPE>::setter_function(X const& value)
115{
116 return g_settings_set_enum(gsettings_, key_.c_str(), static_cast<int>(value)) != FALSE;
117}
118
119template<typename VALUE_TYPE> template<typename X>
120typename std::enable_if<std::is_enum<X>::value, X>::type
121GSettingsProperty<VALUE_TYPE>::getter_function() const
122{
123 return static_cast<X>(g_settings_get_enum(gsettings_, key_.c_str()));
124}
125
126
127}
128
129#endif
0\ No newline at end of file130\ No newline at end of file
1131
=== added file 'UnityCore/GSettingsProperty.cpp'
--- UnityCore/GSettingsProperty.cpp 1970-01-01 00:00:00 +0000
+++ UnityCore/GSettingsProperty.cpp 2015-02-27 17:17:17 +0000
@@ -0,0 +1,118 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3* Copyright (C) 2015 Canonical Ltd
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 3 as
7* published by the Free Software Foundation.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*
17* Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
18*/
19
20#include "GSettingsProperty.h"
21#include <vector>
22
23namespace unity
24{
25
26// bool
27template<>template<>
28bool GSettingsProperty<bool>::setter_function<bool>(bool const& value)
29{
30 return g_settings_set_boolean(gsettings_, key_.c_str(), value != 0 ? TRUE : FALSE) != FALSE;
31}
32
33template<>template<>
34bool GSettingsProperty<bool>::getter_function<bool>() const
35{
36 return g_settings_get_boolean(gsettings_, key_.c_str()) != FALSE;
37}
38
39// int
40template<>template<>
41bool GSettingsProperty<int32_t>::setter_function<int32_t>(int32_t const& value)
42{
43 return g_settings_set_int(gsettings_, key_.c_str(), value) != FALSE;
44}
45
46template<>template<>
47int32_t GSettingsProperty<int32_t>::getter_function<int32_t>() const
48{
49 return g_settings_get_int(gsettings_, key_.c_str());
50}
51
52// uint
53template<>template<>
54bool GSettingsProperty<uint32_t>::setter_function<uint32_t>(uint32_t const& value)
55{
56 return g_settings_set_uint(gsettings_, key_.c_str(), value) != FALSE;
57}
58
59template<>template<>
60uint32_t GSettingsProperty<uint32_t>::getter_function<uint32_t>() const
61{
62 return g_settings_get_uint(gsettings_, key_.c_str());
63}
64
65// double
66template<>template<>
67bool GSettingsProperty<double>::setter_function<double>(double const& value)
68{
69 return g_settings_set_double(gsettings_, key_.c_str(), value) != FALSE;
70}
71
72template<>template<>
73double GSettingsProperty<double>::getter_function<double>() const
74{
75 return g_settings_get_double(gsettings_, key_.c_str());
76}
77
78// std::string
79template<>template<>
80bool GSettingsProperty<std::string>::setter_function<std::string>(std::string const& value)
81{
82 return g_settings_set_string(gsettings_, key_.c_str(), value.c_str()) != FALSE;
83}
84
85template<>template<>
86std::string GSettingsProperty<std::string>::getter_function<std::string>() const
87{
88 glib::String ret(g_settings_get_string(gsettings_, key_.c_str()));
89 return ret.Str();
90}
91
92// std::vector<std::string>
93template<>template<>
94bool GSettingsProperty<std::vector<std::string>>::setter_function(std::vector<std::string> const& value)
95{
96 std::vector<char const*> c_style_value;
97 c_style_value.reserve(value.size()+1);
98
99 for (auto const & str : value)
100 c_style_value.push_back(str.c_str());
101 c_style_value.push_back(nullptr);
102
103 return g_settings_set_strv(gsettings_, key_.c_str(), c_style_value.data()) != FALSE;
104}
105
106template<>template<>
107std::vector<std::string> GSettingsProperty<std::vector<std::string>>::getter_function<std::vector<std::string>>() const
108{
109 std::shared_ptr<gchar*> c_style_ret(g_settings_get_strv(gsettings_, key_.c_str()), g_strfreev);
110 std::vector<std::string> ret;
111
112 for (int i = 0; c_style_ret.get()[i]; ++i)
113 ret.push_back(c_style_ret.get()[i]);
114
115 return ret;
116}
117
118}
0119
=== added file 'UnityCore/GSettingsProperty.h'
--- UnityCore/GSettingsProperty.h 1970-01-01 00:00:00 +0000
+++ UnityCore/GSettingsProperty.h 2015-02-27 17:17:17 +0000
@@ -0,0 +1,85 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2015 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more detais.
13 *
14 * You shoud have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
18 */
19
20#ifndef UNITY_GSETTING_PROPERTY
21#define UNITY_GSETTING_PROPERTY
22
23#include <boost/noncopyable.hpp>
24#include <string>
25
26#include <UnityCore/GLibWrapper.h>
27#include <UnityCore/GLibSignal.h>
28
29namespace unity
30{
31
32template <typename VALUE_TYPE>
33class GSettingsProperty : private boost::noncopyable
34{
35public:
36 typedef std::function<void(VALUE_TYPE const&)> CallbackType;
37
38 GSettingsProperty(std::string const& schema_id, std::string const& key, CallbackType const& cb = nullptr);
39 GSettingsProperty(glib::Object<GSettings> const& gsettings, std::string const& key, CallbackType const& cb = nullptr);
40
41 VALUE_TYPE operator=(VALUE_TYPE const& value);
42 operator VALUE_TYPE() const;
43
44 // function call access
45 VALUE_TYPE operator()() const;
46 VALUE_TYPE operator()(VALUE_TYPE const& value);
47
48 // get and set access
49 VALUE_TYPE Get() const;
50 VALUE_TYPE Set(VALUE_TYPE const& value);
51
52private:
53 void OnChangedCb();
54
55 template<typename X>
56 typename std::enable_if<!std::is_enum<X>::value, bool>::type
57 setter_function(X const& value);
58
59 template<typename X>
60 typename std::enable_if<std::is_enum<X>::value, bool>::type
61 setter_function(X const& value);
62
63 template<typename X>
64 typename std::enable_if<!std::is_enum<X>::value, X>::type
65 getter_function() const;
66
67 template<typename X>
68 typename std::enable_if<std::is_enum<X>::value, X>::type
69 getter_function() const;
70
71private:
72 glib::Object<GSettings> gsettings_;
73 std::string key_;
74 CallbackType cb_;
75 mutable bool loaded_;
76
77 glib::Signal<void, GSettings*, gchar*> key_changed_;
78 VALUE_TYPE value_;
79};
80
81}
82
83#include "GSettingsProperty-inl.h"
84
85#endif
086
=== modified file 'UnityCore/GSettingsScopes.cpp'
--- UnityCore/GSettingsScopes.cpp 2013-11-14 03:00:29 +0000
+++ UnityCore/GSettingsScopes.cpp 2015-02-27 17:17:17 +0000
@@ -78,7 +78,7 @@
78 {78 {
79 LoadScopes();79 LoadScopes();
80 owner_->scopes_changed.emit(scopes_order_);80 owner_->scopes_changed.emit(scopes_order_);
81 } 81 }
82 };82 };
8383
84 scopes_changed.Connect(settings_, "changed::"+SCOPE_SETTINGS_KEY, change_func);84 scopes_changed.Connect(settings_, "changed::"+SCOPE_SETTINGS_KEY, change_func);
8585
=== modified file 'UnityCore/GnomeSessionManager.cpp'
--- UnityCore/GnomeSessionManager.cpp 2015-01-24 00:56:37 +0000
+++ UnityCore/GnomeSessionManager.cpp 2015-02-27 17:17:17 +0000
@@ -20,6 +20,7 @@
20#include "GnomeSessionManagerImpl.h"20#include "GnomeSessionManagerImpl.h"
2121
22#include <NuxCore/Logger.h>22#include <NuxCore/Logger.h>
23#include "GSettingsProperty.h"
23#include "Variant.h"24#include "Variant.h"
2425
25#include <grp.h>26#include <grp.h>
@@ -218,8 +219,7 @@
218 if (!schema_found)219 if (!schema_found)
219 return true;220 return true;
220221
221 glib::Object<GSettings> setting(g_settings_new(SESSION_OPTIONS.c_str()));222 return !GSettingsProperty<bool>(SESSION_OPTIONS, SUPPRESS_DIALOGS_KEY)();
222 return g_settings_get_boolean(setting, SUPPRESS_DIALOGS_KEY.c_str()) != TRUE;
223}223}
224224
225GVariant* GnomeManager::Impl::OnShellMethodCall(std::string const& method, GVariant* parameters)225GVariant* GnomeManager::Impl::OnShellMethodCall(std::string const& method, GVariant* parameters)
@@ -665,9 +665,7 @@
665 if (is_locked())665 if (is_locked())
666 return true;666 return true;
667667
668 glib::Object<GSettings> lockdown_settings(g_settings_new(GNOME_LOCKDOWN_OPTIONS.c_str()));668 if (GSettingsProperty<bool>(GNOME_LOCKDOWN_OPTIONS, DISABLE_LOCKSCREEN_KEY)() ||
669
670 if (g_settings_get_boolean(lockdown_settings, DISABLE_LOCKSCREEN_KEY.c_str()) ||
671 UserName().find("guest-") == 0 ||669 UserName().find("guest-") == 0 ||
672 impl_->IsUserInGroup(UserName(), "nopasswdlogin"))670 impl_->IsUserInGroup(UserName(), "nopasswdlogin"))
673 {671 {
674672
=== modified file 'UnityCore/Variant.cpp'
--- UnityCore/Variant.cpp 2013-11-19 20:28:13 +0000
+++ UnityCore/Variant.cpp 2015-02-27 17:17:17 +0000
@@ -58,6 +58,18 @@
58 : Variant(g_variant_new_string(value.c_str()))58 : Variant(g_variant_new_string(value.c_str()))
59{}59{}
6060
61Variant::Variant(std::vector<std::string> const& strings)
62{
63 GVariantBuilder b;
64 g_variant_builder_init(&b, G_VARIANT_TYPE("as"));
65
66 for (auto const& str : strings)
67 g_variant_builder_add(&b, "s", str.c_str());
68
69 variant_ = g_variant_builder_end(&b);
70 g_variant_ref_sink(variant_);
71}
72
61Variant::Variant(unsigned char value)73Variant::Variant(unsigned char value)
62 : Variant(g_variant_new_byte(value))74 : Variant(g_variant_new_byte(value))
63{}75{}
@@ -174,6 +186,33 @@
174 return result ? result : "";186 return result ? result : "";
175}187}
176188
189bool Variant::ASToVectorOfStrings(std::vector<std::string>& vector) const
190{
191 GVariantIter* iter;
192 gchar* value = nullptr;
193
194 if (!variant_)
195 return false;
196
197 if (!g_variant_is_of_type (variant_, G_VARIANT_TYPE ("(av)")) &&
198 !g_variant_is_of_type (variant_, G_VARIANT_TYPE ("as")))
199 {
200 return false;
201 }
202
203 g_variant_get(variant_, g_variant_get_type_string(variant_), &iter);
204
205 vector.clear();
206 while (g_variant_iter_loop(iter, "s", &value))
207 {
208 vector.push_back(value);
209 }
210
211 g_variant_iter_free(iter);
212
213 return true;
214}
215
177template <typename TYPE, typename GTYPE>216template <typename TYPE, typename GTYPE>
178TYPE get_numeric_value(GVariant *variant_, const char *type_str, const char *fallback_type_str)217TYPE get_numeric_value(GVariant *variant_, const char *type_str, const char *fallback_type_str)
179{218{
180219
=== modified file 'UnityCore/Variant.h'
--- UnityCore/Variant.h 2013-11-19 20:28:13 +0000
+++ UnityCore/Variant.h 2015-02-27 17:17:17 +0000
@@ -48,6 +48,7 @@
48 Variant(HintsMap const& hints);48 Variant(HintsMap const& hints);
49 explicit Variant(std::nullptr_t);49 explicit Variant(std::nullptr_t);
50 explicit Variant(std::string const&);50 explicit Variant(std::string const&);
51 explicit Variant(std::vector<std::string> const&);
51 explicit Variant(const char*);52 explicit Variant(const char*);
52 explicit Variant(unsigned char);53 explicit Variant(unsigned char);
53 explicit Variant(int16_t);54 explicit Variant(int16_t);
@@ -80,6 +81,7 @@
80 float GetFloat() const;81 float GetFloat() const;
81 Variant GetVariant() const;82 Variant GetVariant() const;
8283
84 bool ASToVectorOfStrings(std::vector<std::string>&) const;
83 bool ASVToHints(HintsMap& hints) const;85 bool ASVToHints(HintsMap& hints) const;
8486
85 template <typename T>87 template <typename T>
8688
=== modified file 'launcher/DevicesSettingsImp.cpp'
--- launcher/DevicesSettingsImp.cpp 2012-10-29 09:34:54 +0000
+++ launcher/DevicesSettingsImp.cpp 2015-02-27 17:17:17 +0000
@@ -17,25 +17,19 @@
17 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>17 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
18 */18 */
1919
20#include <list>
21
22#include <gio/gio.h>
23#include <NuxCore/Logger.h>
24
25#include "DevicesSettingsImp.h"20#include "DevicesSettingsImp.h"
26#include <UnityCore/GLibSignal.h>21
27#include <UnityCore/GLibWrapper.h>22#include <vector>
23#include <UnityCore/GSettingsProperty.h>
2824
29namespace unity25namespace unity
30{26{
31namespace launcher27namespace launcher
32{28{
33DECLARE_LOGGER(logger, "unity.device.settings");
34namespace29namespace
35{30{
36const std::string SETTINGS_NAME = "com.canonical.Unity.Devices";31const std::string SETTINGS_NAME = "com.canonical.Unity.Devices";
37const std::string KEY_NAME = "blacklist";32const std::string KEY_NAME = "blacklist";
38
39}33}
4034
41//35//
@@ -46,51 +40,13 @@
46public:40public:
47 Impl(DevicesSettingsImp* parent)41 Impl(DevicesSettingsImp* parent)
48 : parent_(parent)42 : parent_(parent)
49 , settings_(g_settings_new(SETTINGS_NAME.c_str()))43 , blacklist_(SETTINGS_NAME, KEY_NAME, sigc::hide(sigc::mem_fun(&parent_->changed, &sigc::signal<void>::emit)))
50 {44 {}
51 DownloadBlacklist();
52 ConnectSignals();
53 }
54
55 void ConnectSignals()
56 {
57 settings_changed_signal_.Connect(settings_, "changed::" + KEY_NAME, [this] (GSettings*, gchar*) {
58 DownloadBlacklist();
59 parent_->changed.emit();
60 });
61 }
62
63 void DownloadBlacklist()
64 {
65 std::shared_ptr<gchar*> downloaded_blacklist(g_settings_get_strv(settings_, KEY_NAME.c_str()), g_strfreev);
66
67 blacklist_.clear();
68
69 auto downloaded_blacklist_raw = downloaded_blacklist.get();
70 for (int i = 0; downloaded_blacklist_raw[i]; ++i)
71 blacklist_.push_back(downloaded_blacklist_raw[i]);
72 }
73
74 void UploadBlacklist()
75 {
76 const int size = blacklist_.size();
77 const char* blacklist_to_be_uploaded[size+1];
78
79 int index = 0;
80 for (auto item : blacklist_)
81 blacklist_to_be_uploaded[index++] = item.c_str();
82 blacklist_to_be_uploaded[index] = nullptr;
83
84 if (!g_settings_set_strv(settings_, KEY_NAME.c_str(), blacklist_to_be_uploaded))
85 {
86 LOG_WARNING(logger) << "Saving blacklist failed.";
87 }
88 }
8945
90 bool IsABlacklistedDevice(std::string const& uuid) const46 bool IsABlacklistedDevice(std::string const& uuid) const
91 {47 {
92 auto begin = std::begin(blacklist_);48 auto begin = std::begin(blacklist_());
93 auto end = std::end(blacklist_);49 auto end = std::end(blacklist_());
94 return std::find(begin, end, uuid) != end;50 return std::find(begin, end, uuid) != end;
95 }51 }
9652
@@ -99,8 +55,9 @@
99 if (uuid.empty() || IsABlacklistedDevice(uuid))55 if (uuid.empty() || IsABlacklistedDevice(uuid))
100 return;56 return;
10157
102 blacklist_.push_back(uuid);58 auto temp = blacklist_();
103 UploadBlacklist();59 temp.push_back(uuid);
60 blacklist_ = temp;
104 }61 }
10562
106 void TryToUnblacklist(std::string const& uuid)63 void TryToUnblacklist(std::string const& uuid)
@@ -108,15 +65,13 @@
108 if (uuid.empty() || !IsABlacklistedDevice(uuid))65 if (uuid.empty() || !IsABlacklistedDevice(uuid))
109 return;66 return;
11067
111 blacklist_.remove(uuid);68 auto temp = blacklist_();
112 UploadBlacklist();69 temp.erase(std::remove(std::begin(temp), std::end(temp), uuid), std::end(temp));
70 blacklist_ = temp;
113 }71 }
11472
115 DevicesSettingsImp* parent_;73 DevicesSettingsImp* parent_;
116 glib::Object<GSettings> settings_;74 GSettingsProperty<std::vector<std::string>> blacklist_;
117 std::list<std::string> blacklist_;
118 glib::Signal<void, GSettings*, gchar*> settings_changed_signal_;
119
120};75};
12176
122//77//
12378
=== modified file 'lockscreen/LockScreenAcceleratorController.cpp'
--- lockscreen/LockScreenAcceleratorController.cpp 2014-05-16 04:51:34 +0000
+++ lockscreen/LockScreenAcceleratorController.cpp 2015-02-27 17:17:17 +0000
@@ -20,6 +20,7 @@
20#include "LockScreenAcceleratorController.h"20#include "LockScreenAcceleratorController.h"
2121
22#include <UnityCore/GLibDBusProxy.h>22#include <UnityCore/GLibDBusProxy.h>
23#include <UnityCore/GSettingsProperty.h>
2324
24namespace unity25namespace unity
25{26{
@@ -103,8 +104,7 @@
103104
104void PowerAction(session::Manager::Ptr const& session, const char *action_key)105void PowerAction(session::Manager::Ptr const& session, const char *action_key)
105{106{
106 glib::Object<GSettings> settings(g_settings_new(POWER_SCHEMA));107 auto const& action = GSettingsProperty<std::string>(POWER_SCHEMA, action_key)();
107 auto const& action = glib::String(g_settings_get_string(settings, action_key)).Str();
108108
109 if (action == "interactive")109 if (action == "interactive")
110 session->shutdown_requested.emit(session->HasInhibitors());110 session->shutdown_requested.emit(session->HasInhibitors());
@@ -124,15 +124,15 @@
124{124{
125 auto settings = glib::Object<GSettings>(g_settings_new(MEDIA_KEYS_SCHEMA));125 auto settings = glib::Object<GSettings>(g_settings_new(MEDIA_KEYS_SCHEMA));
126126
127 auto accelerator = std::make_shared<Accelerator>(glib::String(g_settings_get_string(settings, MEDIA_KEYS_KEY_VOLUME_MUTE)));127 auto accelerator = std::make_shared<Accelerator>(GSettingsProperty<std::string>(settings, MEDIA_KEYS_KEY_VOLUME_MUTE));
128 accelerator->activated.connect(std::function<void()>(MuteIndicatorSound));128 accelerator->activated.connect(std::function<void()>(MuteIndicatorSound));
129 accelerators_->Add(accelerator);129 accelerators_->Add(accelerator);
130130
131 accelerator = std::make_shared<Accelerator>(glib::String(g_settings_get_string(settings, MEDIA_KEYS_KEY_VOLUME_DOWN)));131 accelerator = std::make_shared<Accelerator>(GSettingsProperty<std::string>(settings, MEDIA_KEYS_KEY_VOLUME_DOWN));
132 accelerator->activated.connect(std::bind(ScrollIndicatorSound, -1));132 accelerator->activated.connect(std::bind(ScrollIndicatorSound, -1));
133 accelerators_->Add(accelerator);133 accelerators_->Add(accelerator);
134134
135 accelerator = std::make_shared<Accelerator>(glib::String(g_settings_get_string(settings, MEDIA_KEYS_KEY_VOLUME_UP)));135 accelerator = std::make_shared<Accelerator>(GSettingsProperty<std::string>(settings, MEDIA_KEYS_KEY_VOLUME_UP));
136 accelerator->activated.connect(std::bind(ScrollIndicatorSound, +1));136 accelerator->activated.connect(std::bind(ScrollIndicatorSound, +1));
137 accelerators_->Add(accelerator);137 accelerators_->Add(accelerator);
138138
@@ -154,31 +154,17 @@
154154
155 settings = glib::Object<GSettings>(g_settings_new(INPUT_SWITCH_SCHEMA));155 settings = glib::Object<GSettings>(g_settings_new(INPUT_SWITCH_SCHEMA));
156156
157 auto variant = glib::Variant(g_settings_get_value(settings, INPUT_SWITCH_KEY_PREVIOUS_SOURCE), glib::StealRef());157 auto strings = GSettingsProperty<std::vector<std::string>>(settings, INPUT_SWITCH_KEY_PREVIOUS_SOURCE)();
158158 std::for_each(std::begin(strings), std::end(strings), [&](std::string const& string) {
159 if (g_variant_n_children(variant) > 0)
160 {
161 const gchar* string;
162
163 g_variant_get_child(variant, 0, "&s", &string);
164
165 accelerator = std::make_shared<Accelerator>(string);159 accelerator = std::make_shared<Accelerator>(string);
166 accelerator->activated.connect(std::bind(ScrollIndicatorKeyboard, -1));160 accelerator->activated.connect(std::bind(ScrollIndicatorKeyboard, -1));
167 accelerators_->Add(accelerator);161 });
168 }162
169163 strings = GSettingsProperty<std::vector<std::string>>(settings, INPUT_SWITCH_KEY_NEXT_SOURCE)();
170 variant = glib::Variant(g_settings_get_value(settings, INPUT_SWITCH_KEY_NEXT_SOURCE), glib::StealRef());164 std::for_each(std::begin(strings), std::end(strings), [&](std::string const& string) {
171
172 if (g_variant_n_children(variant) > 0)
173 {
174 const gchar* string;
175
176 g_variant_get_child(variant, 0, "&s", &string);
177
178 accelerator = std::make_shared<Accelerator>(string);165 accelerator = std::make_shared<Accelerator>(string);
179 accelerator->activated.connect(std::bind(ScrollIndicatorKeyboard, +1));166 accelerator->activated.connect(std::bind(ScrollIndicatorKeyboard, +1));
180 accelerators_->Add(accelerator);167 });
181 }
182}168}
183169
184Accelerators::Ptr const& AcceleratorController::GetAccelerators() const170Accelerators::Ptr const& AcceleratorController::GetAccelerators() const
185171
=== modified file 'plugins/unityshell/src/WindowMinimizeSpeedController.cpp'
--- plugins/unityshell/src/WindowMinimizeSpeedController.cpp 2013-11-14 03:00:29 +0000
+++ plugins/unityshell/src/WindowMinimizeSpeedController.cpp 2015-02-27 17:17:17 +0000
@@ -35,39 +35,18 @@
3535
36WindowMinimizeSpeedController::WindowMinimizeSpeedController()36WindowMinimizeSpeedController::WindowMinimizeSpeedController()
37 : _settings(g_settings_new(local::UNITY_SCHEMA.c_str()))37 : _settings(g_settings_new(local::UNITY_SCHEMA.c_str()))
38 , _minimize_count(g_settings_get_int(_settings, "minimize-count"))38 , _minimize_count(_settings, "minimize-count", sigc::hide(sigc::mem_fun(this, &WindowMinimizeSpeedController::SetDuration)))
39 , _minimize_speed_threshold(g_settings_get_int(_settings, "minimize-speed-threshold"))39 , _minimize_speed_threshold(_settings, "minimize-speed-threshold", sigc::hide(sigc::mem_fun(this, &WindowMinimizeSpeedController::SetDuration)))
40 , _minimize_slow_duration(g_settings_get_int(_settings, "minimize-slow-duration"))40 , _minimize_slow_duration(_settings, "minimize-slow-duration", sigc::hide(sigc::mem_fun(this, &WindowMinimizeSpeedController::SetDuration)))
41 , _minimize_fast_duration(g_settings_get_int(_settings, "minimize-fast-duration"))41 , _minimize_fast_duration(_settings, "minimize-fast-duration", sigc::hide(sigc::mem_fun(this, &WindowMinimizeSpeedController::SetDuration)))
42 , _duration(200) // going to be overridden anyway, but at least it is initialised42 , _duration(200) // going to be overridden anyway, but at least it is initialised
43{43{}
44 _minimize_count_changed.Connect(_settings, "changed::minimize-count",
45 [this] (GSettings*, gchar* name) {
46 _minimize_count = g_settings_get_int(_settings, name);
47 SetDuration();
48 });
49 _minimize_speed_threshold_changed.Connect(_settings, "changed::minimize-speed-threshold",
50 [this] (GSettings*, gchar* name) {
51 _minimize_speed_threshold = g_settings_get_int(_settings, name);
52 SetDuration();
53 });
54 _minimize_fast_duration_changed.Connect(_settings, "changed::minimize-fast-duration",
55 [this] (GSettings*, gchar* name) {
56 _minimize_fast_duration = g_settings_get_int(_settings, name);
57 SetDuration();
58 });
59 _minimize_slow_duration_changed.Connect(_settings, "changed::minimize-slow-duration",
60 [this] (GSettings*, gchar* name) {
61 _minimize_slow_duration = g_settings_get_int(_settings, name);
62 SetDuration();
63 });
64}
6544
66void WindowMinimizeSpeedController::UpdateCount()45void WindowMinimizeSpeedController::UpdateCount()
67{46{
68 if (_minimize_count < _minimize_speed_threshold) {47 if (_minimize_count() < _minimize_speed_threshold()) {
69 _minimize_count += 1;48 auto temp = _minimize_count();
70 g_settings_set_int(_settings, "minimize-count", _minimize_count);49 _minimize_count = ++temp;
71 }50 }
72}51}
7352
@@ -79,26 +58,24 @@
79void WindowMinimizeSpeedController::SetDuration()58void WindowMinimizeSpeedController::SetDuration()
80{59{
81 /* Perform some sanity checks on the configuration values */60 /* Perform some sanity checks on the configuration values */
82 if (_minimize_fast_duration > _minimize_slow_duration)61 if (_minimize_fast_duration() > _minimize_slow_duration())
83 {62 {
84 LOG_WARN(logger) << "Configuration mismatch: minimize-fast-duration ("63 LOG_WARN(logger) << "Configuration mismatch: minimize-fast-duration ("
85 << _minimize_fast_duration64 << _minimize_fast_duration()
86 << ") is longer than minimize-slow-duration ("65 << ") is longer than minimize-slow-duration ("
87 << _minimize_slow_duration << "). Not changing speed.";66 << _minimize_slow_duration() << "). Not changing speed.";
88 return;67 return;
89 }68 }
9069
91 if (_minimize_count < 0)70 auto minimize_count = _minimize_count();
92 _minimize_count = 0;71 minimize_count = std::max(0, std::min(minimize_count, _minimize_speed_threshold()));
93 if (_minimize_count > _minimize_speed_threshold)
94 _minimize_count = _minimize_speed_threshold;
9572
96 /* Adjust the speed so that it gets linearly closer to maximum speed as we73 /* Adjust the speed so that it gets linearly closer to maximum speed as we
97 approach the threshold */74 approach the threshold */
98 int speed_range = _minimize_slow_duration - _minimize_fast_duration;75 int speed_range = _minimize_slow_duration() - _minimize_fast_duration();
99 float position = (_minimize_speed_threshold <= 0) ? 1.0 :76 float position = (_minimize_speed_threshold() <= 0) ? 1.0 :
100 static_cast<float>(_minimize_count) / _minimize_speed_threshold;77 static_cast<float>(_minimize_count) / _minimize_speed_threshold();
101 int duration = _minimize_slow_duration - std::ceil(position * speed_range);78 int duration = _minimize_slow_duration() - std::ceil(position * speed_range);
10279
103 if (duration != _duration) {80 if (duration != _duration) {
104 _duration = duration;81 _duration = duration;
10582
=== modified file 'plugins/unityshell/src/WindowMinimizeSpeedController.h'
--- plugins/unityshell/src/WindowMinimizeSpeedController.h 2012-09-12 04:08:06 +0000
+++ plugins/unityshell/src/WindowMinimizeSpeedController.h 2015-02-27 17:17:17 +0000
@@ -22,13 +22,9 @@
22#ifndef WINDOWMINIMIZESPEEDCONTROLLER_H22#ifndef WINDOWMINIMIZESPEEDCONTROLLER_H
23#define WINDOWMINIMIZESPEEDCONTROLLER_H23#define WINDOWMINIMIZESPEEDCONTROLLER_H
2424
25#include <core/core.h>25#include <UnityCore/GSettingsProperty.h>
26#include <UnityCore/GLibWrapper.h>
27#include <UnityCore/GLibSignal.h>
28#include <sigc++/sigc++.h>26#include <sigc++/sigc++.h>
2927
30typedef struct _GSettings GSettings;
31
32using namespace unity;28using namespace unity;
3329
34class WindowMinimizeSpeedController30class WindowMinimizeSpeedController
@@ -43,14 +39,10 @@
43 void SetDuration();39 void SetDuration();
4440
45 glib::Object<GSettings> _settings;41 glib::Object<GSettings> _settings;
46 int _minimize_count;42 GSettingsProperty<int> _minimize_count;
47 int _minimize_speed_threshold;43 GSettingsProperty<int> _minimize_speed_threshold;
48 int _minimize_slow_duration;44 GSettingsProperty<int> _minimize_slow_duration;
49 int _minimize_fast_duration;45 GSettingsProperty<int> _minimize_fast_duration;
50 glib::Signal<void, GSettings*, gchar* > _minimize_count_changed;
51 glib::Signal<void, GSettings*, gchar* > _minimize_speed_threshold_changed;
52 glib::Signal<void, GSettings*, gchar* > _minimize_slow_duration_changed;
53 glib::Signal<void, GSettings*, gchar* > _minimize_fast_duration_changed;
54 int _duration;46 int _duration;
55};47};
5648
5749
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2014-11-04 19:00:40 +0000
+++ tests/CMakeLists.txt 2015-02-27 17:17:17 +0000
@@ -119,6 +119,7 @@
119 test_glib_source.cpp119 test_glib_source.cpp
120 test_glib_variant.cpp120 test_glib_variant.cpp
121 test_grabhandle.cpp121 test_grabhandle.cpp
122 test_gsettings_property.cpp
122 test_gsettings_scopes.cpp123 test_gsettings_scopes.cpp
123 test_desktop_utilities.cpp124 test_desktop_utilities.cpp
124 test_desktop_application_subject.cpp125 test_desktop_application_subject.cpp
125126
=== modified file 'tests/data/external.gschema.xml'
--- tests/data/external.gschema.xml 2014-04-18 11:45:59 +0000
+++ tests/data/external.gschema.xml 2015-02-27 17:17:17 +0000
@@ -142,4 +142,34 @@
142 <default>["&lt;Super&gt;space"]</default>142 <default>["&lt;Super&gt;space"]</default>
143 </key>143 </key>
144 </schema>144 </schema>
145
146 <enum id='com.canonical.unity.test.enum'>
147 <value nick='e1' value='0'/>
148 <value nick='e2' value='1'/>
149 <value nick='e3' value='2'/>
150 </enum>
151
152 <schema path = "/com/canonical/unity/test/" id="com.canonical.unity.test">
153 <key type="b" name="bool">
154 <default>true</default>
155 </key>
156 <key type="i" name="int">
157 <default>-123</default>
158 </key>
159 <key type="u" name="uint">
160 <default>123</default>
161 </key>
162 <key type="d" name="double">
163 <default>123.456</default>
164 </key>
165 <key type="s" name="string">
166 <default>'abcdef'</default>
167 </key>
168 <key name='enum' enum='com.canonical.unity.test.enum'>
169 <default>'e1'</default>
170 </key>
171 <key type="as" name='vector-string'>
172 <default>['a', 'b', 'c']</default>
173 </key>
174 </schema>
145</schemalist>175</schemalist>
146176
=== added file 'tests/test_gsettings_property.cpp'
--- tests/test_gsettings_property.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_gsettings_property.cpp 2015-02-27 17:17:17 +0000
@@ -0,0 +1,423 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2015 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
18 */
19
20#include <gtest/gtest.h>
21using namespace testing;
22
23#include <UnityCore/GSettingsProperty.h>
24#include <UnityCore/Variant.h>
25
26namespace
27{
28
29const gchar* SETTINGS_NAME = "com.canonical.unity.test";
30
31/* Define setter and getter external functions. For the getter functions we need to be more specific
32 * because unity::glib::Variant is not templated.
33 */
34template<typename T>
35typename std::enable_if<!std::is_enum<T>::value, void>::type
36setter_function(unity::glib::Object<GSettings> gsettings, std::string const& key, T const& value)
37{
38 g_settings_set_value(gsettings, key.c_str(), unity::glib::Variant(value));
39}
40
41template<typename T>
42typename std::enable_if<std::is_enum<T>::value, void>::type
43setter_function(unity::glib::Object<GSettings> gsettings, std::string const& key, T const& value)
44{
45 g_settings_set_enum(gsettings, key.c_str(), static_cast<int>(value));
46}
47
48template<typename T>
49typename std::enable_if<std::is_same<T, bool>::value, T>::type
50getter_function(unity::glib::Object<GSettings> gsettings, std::string const& key)
51{
52 return g_settings_get_boolean(gsettings, key.c_str());
53}
54
55template<typename T>
56typename std::enable_if<std::is_same<T, int>::value, T>::type
57 getter_function(unity::glib::Object<GSettings> gsettings, std::string const& key)
58{
59 return g_settings_get_int(gsettings, key.c_str());
60}
61
62template<typename T>
63typename std::enable_if<std::is_same<T, uint>::value, T>::type
64getter_function(unity::glib::Object<GSettings> gsettings, std::string const& key)
65{
66 return g_settings_get_uint(gsettings, key.c_str());
67}
68
69template<typename T>
70typename std::enable_if<std::is_same<T, double>::value, T>::type
71getter_function(unity::glib::Object<GSettings> gsettings, std::string const& key)
72{
73 return g_settings_get_double(gsettings, key.c_str());
74}
75
76template<typename T>
77typename std::enable_if<std::is_same<T, std::string>::value, T>::type
78getter_function(unity::glib::Object<GSettings> gsettings, std::string const& key)
79{
80 unity::glib::Variant ret(g_settings_get_value(gsettings, key.c_str()));
81 return ret.GetString();
82}
83
84template<typename T>
85typename std::enable_if<std::is_same<T, std::vector<std::string>>::value, T>::type
86getter_function(unity::glib::Object<GSettings> gsettings, std::string const& key)
87{
88 std::vector<std::string> vec;
89
90 unity::glib::Variant variant(g_settings_get_value(gsettings, key.c_str()));
91 variant.ASToVectorOfStrings(vec);
92
93 return vec;
94}
95
96template<typename T>
97typename std::enable_if<std::is_enum<T>::value, T>::type
98getter_function(unity::glib::Object<GSettings> gsettings, std::string const& key)
99{
100 return static_cast<T>(g_settings_get_enum(gsettings, key.c_str()));
101}
102
103// End defintion setter/getter functions
104
105template<typename T>
106class TestGSettingsProperty : public Test
107{
108public:
109 unity::glib::Object<GSettings> gsettings_;
110
111 static T initial_value;
112 static T target_value;
113 static std::string key;
114
115 void SetUp()
116 {
117 // Setting the test values
118 gsettings_ = g_settings_new(SETTINGS_NAME);
119 setter_function<T>(gsettings_, key, initial_value);
120 }
121};
122
123TYPED_TEST_CASE_P(TestGSettingsProperty);
124
125TYPED_TEST_P(TestGSettingsProperty, ConstructionSchemaId)
126{
127 {
128 unity::GSettingsProperty<TypeParam> prop(SETTINGS_NAME, this->key);
129 EXPECT_EQ(this->initial_value, prop());
130 }
131
132 {
133 unity::GSettingsProperty<TypeParam> prop(SETTINGS_NAME, this->key, [](TypeParam const&) {});
134 EXPECT_EQ(this->initial_value, prop());
135 }
136}
137
138TYPED_TEST_P(TestGSettingsProperty, ConstructionGSetting)
139{
140 {
141 ASSERT_EQ(1, G_OBJECT(this->gsettings_.RawPtr())->ref_count);
142
143 unity::GSettingsProperty<TypeParam> prop(this->gsettings_, this->key);
144
145 ASSERT_EQ(2, G_OBJECT(this->gsettings_.RawPtr())->ref_count);
146 EXPECT_EQ(this->initial_value, prop());
147 }
148
149 {
150 ASSERT_EQ(1, G_OBJECT(this->gsettings_.RawPtr())->ref_count);
151
152 unity::GSettingsProperty<TypeParam> prop(this->gsettings_, this->key, [](TypeParam const&) {});
153
154 ASSERT_EQ(2, G_OBJECT(this->gsettings_.RawPtr())->ref_count);
155 EXPECT_EQ(this->initial_value, prop());
156 }
157
158 ASSERT_EQ(1, G_OBJECT(this->gsettings_.RawPtr())->ref_count);
159}
160
161TYPED_TEST_P(TestGSettingsProperty, Cast)
162{
163 {
164 unity::GSettingsProperty<TypeParam> prop(this->gsettings_,this->key);
165 EXPECT_EQ(this->initial_value, static_cast<TypeParam>(prop));
166 }
167
168 {
169 unity::GSettingsProperty<TypeParam> prop(this->gsettings_,this->key, [](TypeParam const&) {});
170 EXPECT_EQ(this->initial_value, static_cast<TypeParam>(prop));
171 }
172}
173
174TYPED_TEST_P(TestGSettingsProperty, ChangedSignal)
175{
176 bool signal_received = false;
177 TypeParam signal_value = this->initial_value;
178
179 // Make sure we get the changed signal if the settings key is modified by an external agent
180 unity::GSettingsProperty<TypeParam> prop(this->gsettings_, this->key, [&] (TypeParam value) {
181 signal_received = true;
182 signal_value = value;
183 });
184
185 setter_function(this->gsettings_, this->key.c_str(), this->target_value);
186
187 ASSERT_TRUE(signal_received);
188 EXPECT_EQ(this->target_value, signal_value);
189}
190
191
192TYPED_TEST_P(TestGSettingsProperty, OperatorEqCb)
193{
194 bool signal_received = false;
195 TypeParam signal_value = this->initial_value;
196
197 unity::GSettingsProperty<TypeParam> prop(this->gsettings_, this->key, [&](TypeParam value) {
198 signal_received = true;
199 signal_value = value;
200 });
201
202 // Make sure ::opertor= works:
203 // - when old_value != new_value
204 prop = this->target_value;
205
206 ASSERT_TRUE(signal_received);
207 EXPECT_EQ(this->target_value, signal_value);
208 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
209 EXPECT_EQ(this->target_value, prop());
210
211 // - when old_value == new_value
212 signal_received = false;
213 prop = this->target_value;
214
215 ASSERT_FALSE(signal_received);
216 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
217 EXPECT_EQ(this->target_value, prop());
218}
219
220TYPED_TEST_P(TestGSettingsProperty, OperatorEqNoCb)
221{
222 unity::GSettingsProperty<TypeParam> prop(this->gsettings_, this->key);
223
224 // Make sure ::opertor= works:
225 // - when old_value != new_value
226 prop = this->target_value;
227
228 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
229 EXPECT_EQ(this->target_value, prop());
230
231 // - when old_value == new_value
232 prop = this->target_value;
233
234 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
235 EXPECT_EQ(this->target_value, prop());
236}
237
238
239TYPED_TEST_P(TestGSettingsProperty, OperatorCallCb)
240{
241 bool signal_received = false;
242 TypeParam signal_value = this->initial_value;
243
244 unity::GSettingsProperty<TypeParam> prop(this->gsettings_, this->key, [&](TypeParam value) {
245 signal_received = true;
246 signal_value = value;
247 });
248
249 // Make sure ::opertor() works:
250 // - when old_value != new_value
251 prop(this->target_value);
252
253 ASSERT_TRUE(signal_received);
254 EXPECT_EQ(this->target_value, signal_value);
255 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
256 EXPECT_EQ(this->target_value, prop());
257
258 // - when old_value == new_value
259 signal_received = false;
260 prop(this->target_value);
261
262 ASSERT_FALSE(signal_received);
263 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
264 EXPECT_EQ(this->target_value, prop());
265}
266
267TYPED_TEST_P(TestGSettingsProperty, OperatorCallNoCb)
268{
269 unity::GSettingsProperty<TypeParam> prop(this->gsettings_, this->key);
270
271 // Make sure ::opertor() works:
272 // - when old_value != new_value
273 prop(this->target_value);
274
275 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
276 EXPECT_EQ(this->target_value, prop());
277
278 // - when old_value == new_value
279 prop(this->target_value);
280
281 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
282 EXPECT_EQ(this->target_value, prop());
283}
284
285TYPED_TEST_P(TestGSettingsProperty, GetCb)
286{
287 // Make sure ::Get works:
288 // - after construction
289 unity::GSettingsProperty<TypeParam> prop(this->gsettings_, this->key, [](TypeParam const&){});
290 EXPECT_EQ(this->initial_value, prop.Get());
291
292 // - after operator=
293 prop = this->target_value;
294 EXPECT_EQ(this->target_value, prop.Get());
295
296 // - after extenal editing
297 setter_function(this->gsettings_, this->key, this->initial_value);
298 EXPECT_EQ(this->initial_value, prop.Get());
299}
300
301TYPED_TEST_P(TestGSettingsProperty, GetNoCb)
302{
303 // Make sure ::Get works:
304 // - after construction
305 unity::GSettingsProperty<TypeParam> prop(this->gsettings_, this->key);
306 EXPECT_EQ(this->initial_value, prop.Get());
307
308 // - after operator=
309 prop = this->target_value;
310 EXPECT_EQ(this->target_value, prop.Get());
311
312 // - after extenal editing
313 setter_function(this->gsettings_, this->key, this->initial_value);
314 EXPECT_EQ(this->initial_value, prop.Get());
315}
316
317TYPED_TEST_P(TestGSettingsProperty, SetCb)
318{
319 bool signal_received = false;
320 TypeParam signal_value = this->initial_value;
321
322 unity::GSettingsProperty<TypeParam> prop(this->gsettings_, this->key, [&](TypeParam value){
323 signal_received = true;
324 signal_value = value;
325 });
326
327 // Make sure ::Set works:
328 // - when old_value != new_value
329 prop.Set(this->target_value);
330
331 ASSERT_TRUE(signal_received);
332 EXPECT_EQ(this->target_value, signal_value);
333 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
334 EXPECT_EQ(this->target_value, prop());
335
336 // - when old_value == new_value
337 signal_received = false;
338 prop.Set(this->target_value);
339
340 ASSERT_FALSE(signal_received);
341 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
342 EXPECT_EQ(this->target_value, prop());
343}
344
345TYPED_TEST_P(TestGSettingsProperty, SetNoCb)
346{
347 unity::GSettingsProperty<TypeParam> prop(this->gsettings_, this->key);
348
349 // Make sure ::Set works:
350 // - when old_value != new_value
351 prop.Set(this->target_value);
352
353 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
354 EXPECT_EQ(this->target_value, prop());
355
356 // - when old_value == new_value
357 prop.Set(this->target_value);
358
359 EXPECT_EQ(this->target_value, getter_function<TypeParam>(this->gsettings_, this->key));
360 EXPECT_EQ(this->target_value, prop());
361}
362
363
364REGISTER_TYPED_TEST_CASE_P(TestGSettingsProperty,
365 ConstructionSchemaId, ConstructionGSetting,
366 Cast, ChangedSignal,
367 OperatorEqCb, OperatorEqNoCb,
368 OperatorCallCb, OperatorCallNoCb,
369 GetCb, GetNoCb,
370 SetCb, SetNoCb);
371
372enum class EC {
373 E1 = 0, E2, E3
374};
375
376enum E {
377 E1 = 0, E2, E3
378};
379
380typedef ::testing::Types<bool, int, uint, double, std::string, std::vector<std::string>, EC, E> MyTypes;
381INSTANTIATE_TYPED_TEST_CASE_P(TestGSettingsProperty, TestGSettingsProperty, MyTypes);
382
383// bool
384template<> bool TestGSettingsProperty<bool>::initial_value = true;
385template<> bool TestGSettingsProperty<bool>::target_value = false;
386template<> std::string TestGSettingsProperty<bool>::key = "bool";
387
388// int
389template<> int TestGSettingsProperty<int>::initial_value = -123;
390template<> int TestGSettingsProperty<int>::target_value = 456;
391template<> std::string TestGSettingsProperty<int>::key = "int";
392
393// uint
394template<> uint TestGSettingsProperty<uint>::initial_value = 123;
395template<> uint TestGSettingsProperty<uint>::target_value = 456;
396template<> std::string TestGSettingsProperty<uint>::key = "uint";
397
398// double
399template<> double TestGSettingsProperty<double>::initial_value = 123.456;
400template<> double TestGSettingsProperty<double>::target_value = 456.123;
401template<> std::string TestGSettingsProperty<double>::key = "double";
402
403// std::string
404template<> std::string TestGSettingsProperty<std::string>::initial_value = "abcdef";
405template<> std::string TestGSettingsProperty<std::string>::target_value = "dlkasdf";
406template<> std::string TestGSettingsProperty<std::string>::key = "string";
407
408// std::vector<std::string>
409template<> std::vector<std::string> TestGSettingsProperty<std::vector<std::string>>::initial_value = {"a", "b", "c"};
410template<> std::vector<std::string> TestGSettingsProperty<std::vector<std::string>>::target_value = {"d", "e", "f"};
411template<> std::string TestGSettingsProperty<std::vector<std::string>>::key = "vector-string";
412
413// enum class
414template<> EC TestGSettingsProperty<EC>::initial_value = EC::E1;
415template<> EC TestGSettingsProperty<EC>::target_value = EC::E2;
416template<> std::string TestGSettingsProperty<EC>::key = "enum";
417
418// enum
419template<> E TestGSettingsProperty<E>::initial_value = E::E1;
420template<> E TestGSettingsProperty<E>::target_value = E::E2;
421template<> std::string TestGSettingsProperty<E>::key = "enum";
422
423}