diff options
author | portix <portix@gmx.net> | 2013-05-10 11:04:59 +0200 |
---|---|---|
committer | portix <portix@gmx.net> | 2013-05-10 11:04:59 +0200 |
commit | cb6f11fc56e2ca90ae58fd3299b7280f047c7c0f (patch) | |
tree | 9b568cbca7410f954b0030c21970c804c76478eb | |
parent | 605e966f73f6b4fac1548e76c86001b4e7f360c9 (diff) | |
download | dwb-cb6f11fc56e2ca90ae58fd3299b7280f047c7c0f.zip |
Implementing general keyfile action 'util_keyfile_do'
-rw-r--r-- | src/dwb.c | 27 | ||||
-rw-r--r-- | src/util.c | 24 | ||||
-rw-r--r-- | src/util.h | 2 |
3 files changed, 31 insertions, 22 deletions
@@ -4988,28 +4988,11 @@ dwb_parse_commands(const char *line) } /*}}}*/ + static gboolean -dwb_remove_group(const char *path, const char *group) +dwb_remove_key_group(GKeyFile *kf, const char *group) { - gboolean result = false; - char *data; - GKeyFile *kf = g_key_file_new(); - if (kf == NULL) - return result; - if (g_key_file_load_from_file(kf, path, G_KEY_FILE_KEEP_COMMENTS, NULL)) - { - if (g_key_file_remove_group(kf, group, NULL)) - { - if ((data = g_key_file_to_data(kf, NULL, NULL)) != NULL) - { - util_set_file_content(path, data); - g_free(data); - result = true; - } - } - } - g_key_file_free(kf); - return result; + return g_key_file_remove_group(kf, group, NULL); } gboolean dwb_delete_profile(const char *profile) @@ -5018,11 +5001,11 @@ dwb_delete_profile(const char *profile) char *path = util_build_path(); char *filename = g_build_filename(path, "keys", NULL); - success = dwb_remove_group(filename, profile) || success; + success = util_keyfile_do(filename, (KeyFileAction)dwb_remove_key_group, profile) || success; g_free(filename); filename = g_build_filename(path, "settings", NULL); - success = dwb_remove_group(filename, profile) || success; + success = util_keyfile_do(filename, (KeyFileAction)dwb_remove_key_group, profile) || success; g_free(filename); filename = g_build_filename(path, profile, NULL); @@ -959,3 +959,27 @@ util_resolve_symlink(char *path) } return ret; } +gboolean +util_keyfile_do(char *path, KeyFileAction action, const void *data) +{ + char *content; + gboolean result = false; + GKeyFile *kf = g_key_file_new(); + if (kf == NULL) + return result; + + if (g_key_file_load_from_file(kf, path, G_KEY_FILE_KEEP_COMMENTS, NULL)) + { + if (action(kf, data)) + { + if ((content = g_key_file_to_data(kf, NULL, NULL)) != NULL) + { + util_set_file_content(path, content); + g_free(content); + result = true; + } + } + } + g_key_file_free(kf); + return result; +} @@ -19,6 +19,7 @@ #ifndef UTIL_H #define UTIL_H +typedef gboolean (*KeyFileAction)(GKeyFile *, const void *data); // strings char * util_string_replace(const char *haystack, const char *needle, const char *replacemant); @@ -103,6 +104,7 @@ Sanitize util_string_to_sanitize(const char *); char *util_create_json(int, ...); int util_modulo(int, int); char *util_resolve_symlink(char *path); +gboolean util_keyfile_do(char *path, KeyFileAction action, const void *data); #endif |