summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2013-05-10 11:04:59 +0200
committerportix <portix@gmx.net>2013-05-10 11:04:59 +0200
commitcb6f11fc56e2ca90ae58fd3299b7280f047c7c0f (patch)
tree9b568cbca7410f954b0030c21970c804c76478eb
parent605e966f73f6b4fac1548e76c86001b4e7f360c9 (diff)
downloaddwb-cb6f11fc56e2ca90ae58fd3299b7280f047c7c0f.zip
Implementing general keyfile action 'util_keyfile_do'
-rw-r--r--src/dwb.c27
-rw-r--r--src/util.c24
-rw-r--r--src/util.h2
3 files changed, 31 insertions, 22 deletions
diff --git a/src/dwb.c b/src/dwb.c
index 5fa1a2ce..62a8998e 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -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);
diff --git a/src/util.c b/src/util.c
index 5ba32aa9..696c2e0d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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;
+}
diff --git a/src/util.h b/src/util.h
index d270dd1a..d3e30fe5 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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