5
* Copyright (C) 2000-2003 gnomemm Development Team
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; if not, write to the Free
19
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
#include "window_test.h"
25
#include <gtkmm/window.h>
26
#include <gtkmm/box.h>
28
Window_Test::Window_Test()
30
m_Label("Maindir added 1 times\nSubdir added 0 times"),
31
m_Button_Quit("Quit"),
32
m_Button_RemoveSubDir("Remove subdir"),
33
m_Button_AddSubDir("Add subdir"),
34
m_Button_RemoveMainDir("Remove maindir"),
35
m_Button_AddMainDir("Add maindir")
37
m_bBlockEntryHandlers = false;
42
set_title("Gnome::Conf::Client Demo");
43
set_default_size(200, 200);
45
m_strMainDir = "/apps/gnome/testgconfclient";
46
m_refClient = Gnome::Conf::Client::get_default_client();
48
#ifdef GLIBMM_EXCEPTIONS_ENABLED
49
m_refClient->add_dir(m_strMainDir);
51
std::auto_ptr<Glib::Error> error;
52
m_refClient->add_dir(m_strMainDir, Gnome::Conf::CLIENT_PRELOAD_NONE, error);
54
std::cerr << error->what() << std::endl;
55
#endif //GLIBMM_EXCEPTIONS_ENABLED
57
// test code to figure out show that list of floats work:
59
Glib::ustring testkey = m_strMainDir + "/test_floattype_list";
60
typedef gdouble floattype;
62
std::list<floattype> testListFloat;
63
testListFloat.push_back(1.1);
64
testListFloat.push_back(2.2);
65
testListFloat.push_back(3.3);
66
m_refClient->set_float_list(testkey, testListFloat);
68
std::list<floattype> testListFloatFromGet = m_refClient->get_float_list(testkey);
69
for(std::list<floattype>::iterator iter = testListFloatFromGet.begin(); iter != testListFloatFromGet.end(); ++iter)
72
//std::cout << "float list item:" << a << std::endl;
73
g_warning("floattype list item: %f", a);
81
m_VBox.pack_end(m_Label, Gtk::PACK_SHRINK);
83
m_VBox.pack_end(m_Button_Quit, Gtk::PACK_SHRINK);
84
m_VBox.pack_end(m_Button_RemoveSubDir, Gtk::PACK_SHRINK);
85
m_VBox.pack_end(m_Button_AddSubDir, Gtk::PACK_SHRINK);
86
m_VBox.pack_end(m_Button_RemoveMainDir, Gtk::PACK_SHRINK);
87
m_VBox.pack_end(m_Button_AddMainDir, Gtk::PACK_SHRINK);
89
//Connect button signals:
90
m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this, &Window_Test::on_Button_Quit));
91
m_Button_RemoveSubDir.signal_clicked().connect(sigc::mem_fun(*this, &Window_Test::on_Button_RemoveSubDir));
92
m_Button_AddSubDir.signal_clicked().connect(sigc::mem_fun(*this, &Window_Test::on_Button_AddSubDir));
93
m_Button_RemoveMainDir.signal_clicked().connect(sigc::mem_fun(*this, &Window_Test::on_Button_RemoveMainDir));
94
m_Button_AddMainDir.signal_clicked().connect(sigc::mem_fun(*this, &Window_Test::on_Button_AddMainDir));
98
pBox = create_entry_attached_to(m_strMainDir + "/blah");
99
m_VBox.pack_start(*pBox, Gtk::PACK_SHRINK);
101
pBox = create_entry_attached_to(m_strMainDir + "/foo");
102
m_VBox.pack_start(*pBox, Gtk::PACK_SHRINK);
104
pBox = create_entry_attached_to(m_strMainDir + "/bar");
105
m_VBox.pack_start(*pBox, Gtk::PACK_SHRINK);
107
pBox = create_entry_attached_to(m_strMainDir + "/subdir/testsub1");
108
m_VBox.pack_start(*pBox, Gtk::PACK_SHRINK);
110
pBox = create_entry_attached_to(m_strMainDir + "/subdir/testsub2");
111
m_VBox.pack_start(*pBox, Gtk::PACK_SHRINK);
116
Window_Test::~Window_Test()
120
//Remove callbacks (Is this really necessary)
121
for(type_listNotifyIDs::iterator iter = m_listNotifyIDs.begin(); iter != m_listNotifyIDs.end(); iter++)
123
guint notify_id = *iter;
125
#ifdef GLIBMM_EXCEPTIONS_ENABLED
126
m_refClient->notify_remove(notify_id);
128
std::auto_ptr<Glib::Error> error;
129
m_refClient->notify_remove(notify_id, error);
131
std::cerr << error->what() << std::endl;
132
#endif //GLIBMM_EXCEPTIONS_ENABLED
134
m_listNotifyIDs.clear();
138
void Window_Test::on_Button_Quit()
143
void Window_Test::on_Entry_changed(Gtk::Entry* pEntry, Glib::ustring key)
145
if(!m_bBlockEntryHandlers)
149
const Glib::ustring text = pEntry->get_text();
151
#ifdef GLIBMM_EXCEPTIONS_ENABLED
152
m_refClient->set(key, text);
154
std::auto_ptr<Glib::Error> error;
155
m_refClient->set(key, text, error);
157
std::cerr << error->what() << std::endl;
158
#endif //GLIBMM_EXCEPTIONS_ENABLED
163
Gtk::HBox* Window_Test::create_entry_attached_to(const Glib::ustring& key)
165
Gtk::HBox* pHBox = Gtk::manage(new Gtk::HBox(false, 10));
166
Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(key));
168
pHBox->pack_start(*pLabel, Gtk::PACK_SHRINK);
170
Gtk::Entry* pEntry = Gtk::manage(new Gtk::Entry());
172
#ifdef GLIBMM_EXCEPTIONS_ENABLED
173
pEntry->set_text( m_refClient->get_string(key) );
175
std::auto_ptr<Glib::Error> error;
176
pEntry->set_text( m_refClient->get_string(key, error ) );
178
std::cerr << error->what() << std::endl;
179
#endif //GLIBMM_EXCEPTIONS_ENABLED
181
//Connect callback and remember the ID for later:
182
guint notify_id = m_refClient->notify_add(key, sigc::bind<Gtk::Entry*>(sigc::mem_fun(*this, &Window_Test::Client_notify_func), pEntry));
183
m_listNotifyIDs.push_back(notify_id);
185
pEntry->signal_changed().connect(sigc::bind(
186
sigc::mem_fun(*this, &Window_Test::on_Entry_changed),
191
/* Set sensitive according to whether the key is writable or not. */
192
#ifdef GLIBMM_EXCEPTIONS_ENABLED
193
pEntry->set_sensitive( m_refClient->key_is_writable(key) );
196
std::auto_ptr<Glib::Error> error;
197
pEntry->set_sensitive( m_refClient->key_is_writable(key, error) );
199
std::cerr << error->what() << std::endl;
201
#endif //GLIBMM_EXCEPTIONS_ENABLED
203
pHBox->pack_end(*pEntry, Gtk::PACK_SHRINK);
208
void Window_Test::update_label_text()
210
gchar* s = g_strdup_printf("Maindir added %d times\nSubdir added %d times", m_iMainDir, m_iSubDir);
211
Glib::ustring str = s;
214
m_Label.set_text(str);
217
void Window_Test::on_Button_RemoveSubDir()
221
#ifdef GLIBMM_EXCEPTIONS_ENABLED
222
m_refClient->remove_dir(m_strMainDir + "/subdir");
224
std::auto_ptr<Glib::Error> error;
225
m_refClient->remove_dir(m_strMainDir + "/subdir", error);
227
std::cerr << error->what() << std::endl;
228
#endif //GLIBMM_EXCEPTIONS_ENABLED
235
void Window_Test::on_Button_AddSubDir()
239
#ifdef GLIBMM_EXCEPTIONS_ENABLED
240
m_refClient->add_dir(m_strMainDir + "/subdir");
242
std::auto_ptr<Glib::Error> error;
243
m_refClient->add_dir(m_strMainDir + "/subdir", Gnome::Conf::CLIENT_PRELOAD_NONE, error);
245
std::cerr << error->what() << std::endl;
246
#endif //GLIBMM_EXCEPTIONS_ENABLED
251
void Window_Test::on_Button_RemoveMainDir()
255
#ifdef GLIBMM_EXCEPTIONS_ENABLED
256
m_refClient->remove_dir(m_strMainDir);
258
std::auto_ptr<Glib::Error> error;
259
m_refClient->remove_dir(m_strMainDir, error);
261
std::cerr << error->what() << std::endl;
262
#endif //GLIBMM_EXCEPTIONS_ENABLED
267
void Window_Test::on_Button_AddMainDir()
271
#ifdef GLIBMM_EXCEPTIONS_ENABLED
272
m_refClient->add_dir(m_strMainDir);
274
std::auto_ptr<Glib::Error> error;
275
m_refClient->add_dir(m_strMainDir, Gnome::Conf::CLIENT_PRELOAD_NONE, error);
277
std::cerr << error->what() << std::endl;
278
#endif //GLIBMM_EXCEPTIONS_ENABLED
284
//The Gtk::Entry* pEntry callback is extra. I used sigc::bind in the connection.
285
void Window_Test::Client_notify_func(guint cnxn_id, Gnome::Conf::Entry conf_entry, Gtk::Entry* pEntry)
289
//gtk_signal_handler_block_by_data(GTK_OBJECT(pEntry->gtkobj()), m_refClient);
290
//Our alternative to gtk_signal_handler_block_by_data(),
291
//Because we couldn't have connected the signal handler with that data:
292
m_bBlockEntryHandlers = true;
294
pEntry->set_text(conf_entry.get_value().get_string());
296
//gtk_signal_handler_unblock_by_data(GTK_OBJECT(pEntry->gtkobj()), m_refClient);
297
m_bBlockEntryHandlers = false;