diff options
author | Stefano Karapetsas <[email protected]> | 2014-04-23 19:52:58 +0200 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2014-04-23 19:52:58 +0200 |
commit | d5f84c22d8b1917ea29a90c44fe7154d5a549a5c (patch) | |
tree | a98d6c5479ec23560066b2d8328238441af18834 /libmate-desktop | |
parent | 612be2533ef5b5b7f5ffc497ff928bd57de71b30 (diff) | |
download | mate-desktop-d5f84c22d8b1917ea29a90c44fe7154d5a549a5c.tar.bz2 mate-desktop-d5f84c22d8b1917ea29a90c44fe7154d5a549a5c.tar.xz |
Add mate_gsettings_is_valid_keyname function from mate-panel
Diffstat (limited to 'libmate-desktop')
-rw-r--r-- | libmate-desktop/mate-gsettings.c | 67 | ||||
-rw-r--r-- | libmate-desktop/mate-gsettings.h | 3 |
2 files changed, 70 insertions, 0 deletions
diff --git a/libmate-desktop/mate-gsettings.c b/libmate-desktop/mate-gsettings.c index 2fb5921..e37bc91 100644 --- a/libmate-desktop/mate-gsettings.c +++ b/libmate-desktop/mate-gsettings.c @@ -54,6 +54,73 @@ mate_gsettings_schema_exists (const gchar* schema) return schema_exists; } +/* (copied from gnome-panel) + * Adapted from is_valid_keyname() in glib (gio/glib-compile-schemas.c) + * Differences: + * - gettext support removed (we don't need translations here) + * - remove support for allow_any_name + */ +gboolean +mate_gsettings_is_valid_keyname (const gchar *key, + GError **error) +{ + gint i; + + if (key[0] == '\0') + { + g_set_error_literal (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + "empty names are not permitted"); + return FALSE; + } + + if (!g_ascii_islower (key[0])) + { + g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + "invalid name '%s': names must begin " + "with a lowercase letter", key); + return FALSE; + } + + for (i = 1; key[i]; i++) + { + if (key[i] != '-' && + !g_ascii_islower (key[i]) && + !g_ascii_isdigit (key[i])) + { + g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + "invalid name '%s': invalid character '%c'; " + "only lowercase letters, numbers and dash ('-') " + "are permitted.", key, key[i]); + return FALSE; + } + + if (key[i] == '-' && key[i + 1] == '-') + { + g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + "invalid name '%s': two successive dashes ('--') " + "are not permitted.", key); + return FALSE; + } + } + + if (key[i - 1] == '-') + { + g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + "invalid name '%s': the last character may not be a " + "dash ('-').", key); + return FALSE; + } + + if (i > 32) + { + g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + "invalid name '%s': maximum length is 32", key); + return FALSE; + } + + return TRUE; +} + gboolean mate_gsettings_append_strv (GSettings *settings, const gchar *key, diff --git a/libmate-desktop/mate-gsettings.h b/libmate-desktop/mate-gsettings.h index 8b6dd30..1cc1ba0 100644 --- a/libmate-desktop/mate-gsettings.h +++ b/libmate-desktop/mate-gsettings.h @@ -32,6 +32,9 @@ G_BEGIN_DECLS gboolean mate_gsettings_schema_exists (const gchar* schema); +gboolean mate_gsettings_is_valid_keyname (const gchar *key, + GError **error); + gboolean mate_gsettings_append_strv (GSettings *settings, const gchar *key, const gchar *value); |