New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dconf] added MGConfItem::listItems() #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,6 +171,94 @@ QStringList MGConfItem::listDirs() const | |
| return children; | ||
| } | ||
|
|
||
| QStringList MGConfItem::listKeys() const | ||
| { | ||
| QStringList children; | ||
| gint length = 0; | ||
| QByteArray k = convertKey(priv->key); | ||
| if (!k.endsWith("/")) { | ||
| k.append("/"); | ||
| } | ||
|
|
||
| gchar **dirs = dconf_client_list(priv->client, k.data(), &length); | ||
| GError *error = NULL; | ||
|
|
||
| for (gint x = 0; x < length; x++) { | ||
| const gchar *dir = g_strdup_printf ("%s%s", k.data(), dirs[x]); | ||
| if (dconf_is_key(dir, &error)) { | ||
| // We have to mimic how gconf was behaving. | ||
| // so we need to chop off trailing slashes. | ||
| // dconf will also barf if it gets a "path" with 2 slashes. | ||
| QString d = convertKey(dir); | ||
| if (d.endsWith("/")) { | ||
| d.chop(1); | ||
| } | ||
|
|
||
| children.append(d); | ||
| } | ||
|
|
||
| g_free ((gpointer)dir); | ||
|
|
||
| // If we have error set then dconf_is_key() has returned false so we should be safe here | ||
| if (error) { | ||
| qWarning() << "MGConfItem" << error->message; | ||
| g_error_free(error); | ||
| error = NULL; | ||
| } | ||
| } | ||
|
|
||
| g_strfreev(dirs); | ||
|
|
||
| return children; | ||
| } | ||
|
|
||
| QVariantMap MGConfItem::listValues() const | ||
| { | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: Remove empty line here |
||
| QVariantMap children; | ||
| gint length = 0; | ||
| QByteArray k = convertKey(priv->key); | ||
| if (!k.endsWith("/")) { | ||
| k.append("/"); | ||
| } | ||
|
|
||
| gchar **items = dconf_client_list(priv->client, k.data(), &length); | ||
| GError *error = NULL; | ||
|
|
||
| for (gint x = 0; x < length; x++) { | ||
| const gchar *item = g_strdup_printf ("%s%s", k.data(), items[x]); | ||
| if (dconf_is_key(item, &error)) { | ||
| QString k = convertKey(item); | ||
| QVariant val; | ||
| GVariant *v = dconf_client_read(priv->client, item); | ||
| if (!v) { | ||
| qWarning() << "MGConfItem Failed to read" << priv->key; | ||
| val = priv->value; | ||
| } | ||
|
|
||
| val = MDConf::convertValue(v); | ||
|
|
||
| children[k] = val; | ||
|
|
||
| if (v) { | ||
| g_variant_unref(v); | ||
| } | ||
| } | ||
| g_free ((gpointer)item); | ||
|
|
||
| // If we have error set then dconf_is_key() has returned false so we should be safe here | ||
| if (error) { | ||
| qWarning() << "MGConfItem::listItems()" << error->message; | ||
| g_error_free(error); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and the next line can be replaced with: |
||
| error = NULL; | ||
| } | ||
| } | ||
|
|
||
| g_strfreev(items); | ||
|
|
||
| return children; | ||
| } | ||
|
|
||
| bool MGConfItem::sync() | ||
| { | ||
| dconf_client_sync(priv->client); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,12 +122,31 @@ class MLITESHARED_EXPORT MGConfItem : public QObject | |
| */ | ||
| QStringList listDirs() const; | ||
|
|
||
| /*! Return a map of the keys inside this directory. The | ||
| returned strings are absolute key names like | ||
| "/myapp/settings". | ||
|
|
||
| A directory is a key that has children. The same key might | ||
| also have a value, but that is confusing and best avoided. | ||
| */ | ||
|
|
||
| QStringList listKeys() const; | ||
|
|
||
| /*! Return a map of the keys with it's values inside this directory. | ||
|
|
||
| A directory is a key that has children. The same key might | ||
| also have a value, but that is confusing and best avoided. | ||
| */ | ||
|
|
||
| QVariantMap listValues() const; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't This way, getting only values of interest is easily possible: If so, we might want to not provide a |
||
|
|
||
| /*! Request dconf to sync value(s) which are not yet synced to the cache. | ||
| Sometimes values may not be synced because eventually this just hints | ||
| dconf to start sync. | ||
|
|
||
| Returns true if there's no errors and false on error. | ||
| */ | ||
|
|
||
| bool sync(); | ||
|
|
||
| Q_SIGNALS: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here - replace these two lines with
g_clear_error(&error);