43 #include <QStringList> |
43 #include <QStringList> |
44 #include <QByteArray> |
44 #include <QByteArray> |
45 #include <QVariant> |
45 #include <QVariant> |
46 #include <QtDebug> |
46 #include <QtDebug> |
47 |
47 |
48 #include "gconfitem.h" |
48 #include "gconfitem_p.h" |
49 |
49 |
50 #include <glib.h> |
50 #include <glib.h> |
51 #include <gconf/gconf-value.h> |
51 #include <gconf/gconf-value.h> |
52 #include <gconf/gconf-client.h> |
52 #include <gconf/gconf-client.h> |
53 |
53 |
54 struct GConfItemPrivate { |
54 struct GConfItemPrivate { |
55 QString key; |
55 QString key; |
56 QVariant value; |
56 QVariant value; |
|
57 bool monitor; |
57 guint notify_id; |
58 guint notify_id; |
58 |
59 |
59 static void notify_trampoline(GConfClient*, guint, GConfEntry *, gpointer); |
60 static void notify_trampoline(GConfClient*, guint, GConfEntry *, gpointer); |
60 }; |
61 }; |
61 |
62 |
224 return 1; |
225 return 1; |
225 } |
226 } |
226 |
227 |
227 void GConfItemPrivate::notify_trampoline (GConfClient*, |
228 void GConfItemPrivate::notify_trampoline (GConfClient*, |
228 guint, |
229 guint, |
229 GConfEntry *, |
230 GConfEntry *entry, |
230 gpointer data) |
231 gpointer data) |
231 { |
232 { |
232 GConfItem *item = (GConfItem *)data; |
233 GConfItem *item = (GConfItem *)data; |
233 item->update_value (true); |
234 |
234 } |
235 |
235 |
236 item->update_value (true, entry->key, convertValue(entry->value)); |
236 void GConfItem::update_value (bool emit_signal) |
237 } |
|
238 |
|
239 void GConfItem::update_value (bool emit_signal, const QString& key, const QVariant& value) |
237 { |
240 { |
238 QVariant new_value; |
241 QVariant new_value; |
|
242 |
|
243 if (emit_signal) { |
|
244 emit subtreeChanged(key, value); |
|
245 } |
239 |
246 |
240 withClient(client) { |
247 withClient(client) { |
241 GError *error = NULL; |
248 GError *error = NULL; |
242 QByteArray k = convertKey(priv->key); |
249 QByteArray k = convertKey(priv->key); |
243 GConfValue *v = gconf_client_get(client, k.data(), &error); |
250 GConfValue *v = gconf_client_get(client, k.data(), &error); |
342 } |
349 } |
343 |
350 |
344 return children; |
351 return children; |
345 } |
352 } |
346 |
353 |
347 GConfItem::GConfItem(const QString &key, QObject *parent) |
354 GConfItem::GConfItem(const QString &key, bool monitor, QObject *parent) |
348 : QObject (parent) |
355 : QObject (parent) |
349 { |
356 { |
350 priv = new GConfItemPrivate; |
357 priv = new GConfItemPrivate; |
351 priv->key = key; |
358 priv->key = key; |
352 withClient(client) { |
359 priv->monitor = monitor; |
353 update_value (false); |
360 withClient(client) { |
354 QByteArray k = convertKey(priv->key); |
361 update_value (false, "", QVariant()); |
355 gconf_client_add_dir (client, k.data(), GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); |
362 if (priv->monitor) { |
356 priv->notify_id = gconf_client_notify_add (client, k.data(), |
363 QByteArray k = convertKey(priv->key); |
357 GConfItemPrivate::notify_trampoline, this, |
364 gconf_client_add_dir (client, k.data(), GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); |
358 NULL, NULL); |
365 priv->notify_id = gconf_client_notify_add (client, k.data(), |
|
366 GConfItemPrivate::notify_trampoline, this, |
|
367 NULL, NULL); |
|
368 } |
359 } |
369 } |
360 } |
370 } |
361 |
371 |
362 GConfItem::~GConfItem() |
372 GConfItem::~GConfItem() |
363 { |
373 { |
364 withClient(client) { |
374 withClient(client) { |
365 QByteArray k = convertKey(priv->key); |
375 QByteArray k = convertKey(priv->key); |
366 gconf_client_notify_remove (client, priv->notify_id); |
376 if (priv->monitor) { |
367 gconf_client_remove_dir (client, k.data(), NULL); |
377 gconf_client_notify_remove (client, priv->notify_id); |
|
378 gconf_client_remove_dir (client, k.data(), NULL); |
|
379 } |
368 } |
380 } |
369 delete priv; |
381 delete priv; |
370 } |
382 } |