diff options
author | Murray Cumming <murrayc@murrayc.com> | 2010-07-22 22:10:07 +0200 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2010-07-22 22:10:07 +0200 |
commit | 7d45142dfc6c25b34532c8dffef58b79546d70bc (patch) | |
tree | 22de7450e96918dd320c5c2806278b624bc07923 /examples | |
parent | e72781ad7be77919b019130c80d194c5ae7b0268 (diff) | |
download | glibmm-7d45142dfc6c25b34532c8dffef58b79546d70bc.tar.gz |
Variant: Added some methods.
* glib/src/variant.[hg|ccg]: ValueBase: Wrap some simple functions
with _WRAP_METHOD().
* glib/src/variant_basictypes.h.m4: Syntax changes, and make the castitem
constructor explicit.
* tools/m4/convert_gio.m4: Added necessary conversion.
We need to decide how to use this in get*() methods and add some tests.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/settings/settings.cc | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/examples/settings/settings.cc b/examples/settings/settings.cc index a42e1061..b7d6228b 100644 --- a/examples/settings/settings.cc +++ b/examples/settings/settings.cc @@ -27,42 +27,54 @@ const char *const INT_KEY = "test-int"; static void on_key_changed(const Glib::ustring& key, const Glib::RefPtr<Gio::Settings>& settings) { - std::cout << Glib::ustring::compose("'%1' changed\n", key); - if (key.raw() == STRING_KEY) - std::cout << Glib::ustring::compose("New value of '%1': '%2'\n", - key, settings->get_string(key)); - else if (key.raw() == INT_KEY) - std::cout << Glib::ustring::compose("New value of '%1': '%2'\n", - key, settings->get_int(key)); - else - std::cerr << "Unknown key\n"; + std::cout << Glib::ustring::compose("'%1' changed\n", key); + if (key.raw() == STRING_KEY) + { + Glib::ustring str = settings->get_string(key); + std::cout << Glib::ustring::compose("New value of '%1': '%2'\n", + key, str); + + //Or: + Glib::Variant<Glib::ustring> variant = settings->get_value(key); + str = variant.get(); + std::cout << Glib::ustring::compose("New value, via Variant, of '%1': '%2'\n", + key, str); + + } + else if (key.raw() == INT_KEY) + { + std::cout << Glib::ustring::compose("New value of '%1': '%2'\n", + key, settings->get_int(key)); + } + else + std::cerr << "Unknown key\n"; } int main(int, char**) { - std::locale::global(std::locale("")); - Gio::init(); + std::locale::global(std::locale("")); + Gio::init(); - // this is only a demo so we don't want to rely on an installed schema. - // Instead we set some environment variables that allow us to test things - // from the source directory. We need to strip off the .libs/ directory - // first (thus the '..'). Generally you would install your schemas to the system schema - // directory - Glib::setenv("GSETTINGS_SCHEMA_DIR", ".", true); - Glib::setenv("GSETTINGS_BACKEND", "memory", true); + // this is only a demo so we don't want to rely on an installed schema. + // Instead we set some environment variables that allow us to test things + // from the source directory. We need to strip off the .libs/ directory + // first (thus the '..'). Generally you would install your schemas to the system schema + // directory + Glib::setenv("GSETTINGS_SCHEMA_DIR", ".", true); + Glib::setenv("GSETTINGS_BACKEND", "memory", true); - const Glib::RefPtr<Gio::Settings> settings = - Gio::Settings::create("org.gtkmm.demo"); + const Glib::RefPtr<Gio::Settings> settings = + Gio::Settings::create("org.gtkmm.demo"); - settings->signal_changed().connect(sigc::bind(sigc::ptr_fun(&on_key_changed), settings)); + settings->signal_changed().connect(sigc::bind(sigc::ptr_fun(&on_key_changed), settings)); - std::cout << Glib::ustring::compose("Initial value of '%1': '%2'\n", - STRING_KEY, settings->get_string(STRING_KEY)); - settings->set_string(STRING_KEY, "Hoopoe"); + std::cout << Glib::ustring::compose("Initial value of '%1': '%2'\n", + STRING_KEY, settings->get_string(STRING_KEY)); + settings->set_string(STRING_KEY, "Hoopoe"); - std::cout << Glib::ustring::compose("Initial value of '%1': '%2'\n", - INT_KEY, settings->get_int(INT_KEY)); - settings->set_int(INT_KEY, 18); + std::cout << Glib::ustring::compose("Initial value of '%1': '%2'\n", + INT_KEY, settings->get_int(INT_KEY)); + settings->set_int(INT_KEY, 18); - return 0; + return 0; } |