diff options
author | James Booth <boothj5@gmail.com> | 2016-03-26 01:48:42 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-03-26 01:48:42 +0000 |
commit | e2b02733df157f0ec6a04713f89680332068e8f8 (patch) | |
tree | 89a04edd49156f8f0f1fe968970e971f357d0816 | |
parent | a4e6d50a4016fa025f72bf42d3da2d4fe3f4b2dc (diff) | |
download | profani-tty-e2b02733df157f0ec6a04713f89680332068e8f8.tar.gz |
Added plugin string settings
-rw-r--r-- | src/plugins/api.c | 12 | ||||
-rw-r--r-- | src/plugins/api.h | 2 | ||||
-rw-r--r-- | src/plugins/c_api.c | 14 | ||||
-rw-r--r-- | src/plugins/profapi.c | 2 | ||||
-rw-r--r-- | src/plugins/profapi.h | 2 | ||||
-rw-r--r-- | src/plugins/python_api.c | 42 | ||||
-rw-r--r-- | src/plugins/settings.c | 19 | ||||
-rw-r--r-- | src/plugins/settings.h | 2 |
8 files changed, 95 insertions, 0 deletions
diff --git a/src/plugins/api.c b/src/plugins/api.c index dec8bcb8..86d1ca08 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -344,3 +344,15 @@ api_settings_set_boolean(const char *const group, const char *const key, gboolea { plugin_settings_set_boolean(group, key, value); } + +char* +api_settings_get_string(const char *const group, const char *const key, const char *const def) +{ + return plugin_settings_get_string(group, key, def); +} + +void +api_settings_set_string(const char *const group, const char *const key, const char *const value) +{ + plugin_settings_set_string(group, key, value); +} diff --git a/src/plugins/api.h b/src/plugins/api.h index 8212eb65..82ba2b58 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -74,5 +74,7 @@ int api_send_stanza(const char *const stanza); gboolean api_settings_get_boolean(const char *const group, const char *const key, gboolean def); void api_settings_set_boolean(const char *const group, const char *const key, gboolean value); +char* api_settings_get_string(const char *const group, const char *const key, const char *const def); +void api_settings_set_string(const char *const group, const char *const key, const char *const value); #endif diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 309a3492..52799a4e 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -206,6 +206,18 @@ c_api_settings_set_boolean(char *group, char *key, int value) api_settings_set_boolean(group, key, value); } +static char* +c_api_settings_get_string(char *group, char *key, char *def) +{ + return api_settings_get_string(group, key, def); +} + +static void +c_api_settings_set_string(char *group, char *key, char *value) +{ + api_settings_set_string(group, key, value); +} + void c_command_callback(PluginCommand *command, gchar **args) { @@ -257,4 +269,6 @@ c_api_init(void) prof_send_stanza = c_api_send_stanza; prof_settings_get_boolean = c_api_settings_get_boolean; prof_settings_set_boolean = c_api_settings_set_boolean; + prof_settings_get_string = c_api_settings_get_string; + prof_settings_set_string = c_api_settings_set_string; } diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index e8b64b60..1f69981e 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -73,3 +73,5 @@ int (*prof_send_stanza)(char *stanza) = NULL; int (*prof_settings_get_boolean)(char *group, char *key, int def) = NULL; void (*prof_settings_set_boolean)(char *group, char *key, int value) = NULL; +char* (*prof_settings_get_string)(char *group, char *key, char *def) = NULL; +void (*prof_settings_set_string)(char *group, char *key, char *value) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index 30197279..f32ebb3a 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -73,5 +73,7 @@ int (*prof_send_stanza)(char *stanza); int (*prof_settings_get_boolean)(char *group, char *key, int def); void (*prof_settings_set_boolean)(char *group, char *key, int value); +char* (*prof_settings_get_string)(char *group, char *key, char *def); +void (*prof_settings_set_string)(char *group, char *key, char *value); #endif diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index bc45c10c..9c1e79aa 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -495,6 +495,46 @@ python_api_settings_set_boolean(PyObject *self, PyObject *args) return Py_BuildValue(""); } +static PyObject* +python_api_settings_get_string(PyObject *self, PyObject *args) +{ + char *group = NULL; + char *key = NULL; + char *def = NULL; + + if (!PyArg_ParseTuple(args, "ssz", &group, &key, &def)) { + return Py_BuildValue(""); + } + + allow_python_threads(); + char *res = api_settings_get_string(group, key, def); + disable_python_threads(); + + if (res) { + return Py_BuildValue("s", res); + } else { + return Py_BuildValue(""); + } +} + +static PyObject* +python_api_settings_set_string(PyObject *self, PyObject *args) +{ + char *group = NULL; + char *key = NULL; + char *val = NULL; + + if (!PyArg_ParseTuple(args, "sss", &group, &key, &val)) { + return Py_BuildValue(""); + } + + allow_python_threads(); + api_settings_set_string(group, key, val); + disable_python_threads(); + + return Py_BuildValue(""); +} + void python_command_callback(PluginCommand *command, gchar **args) { @@ -587,6 +627,8 @@ static PyMethodDef apiMethods[] = { { "send_stanza", python_api_send_stanza, METH_VARARGS, "Send an XMPP stanza." }, { "settings_get_boolean", python_api_settings_get_boolean, METH_VARARGS, "Get a boolean setting" }, { "settings_set_boolean", python_api_settings_set_boolean, METH_VARARGS, "Set a boolean setting" }, + { "settings_get_string", python_api_settings_get_string, METH_VARARGS, "Get a string setting" }, + { "settings_set_string", python_api_settings_set_string, METH_VARARGS, "Set a string setting" }, { NULL, NULL, 0, NULL } }; diff --git a/src/plugins/settings.c b/src/plugins/settings.c index 7d915e9b..dcaf2270 100644 --- a/src/plugins/settings.c +++ b/src/plugins/settings.c @@ -92,6 +92,25 @@ plugin_settings_set_boolean(const char *const group, const char *const key, gboo _save_settings(); } +char* +plugin_settings_get_string(const char *const group, const char *const key, const char *const def) +{ + if (group && key && g_key_file_has_key(settings, group, key, NULL)) { + return g_key_file_get_string(settings, group, key, NULL); + } else if (def) { + return strdup(def); + } else { + return NULL; + } +} + +void +plugin_settings_set_string(const char *const group, const char *const key, const char *const value) +{ + g_key_file_set_string(settings, group, key, value); + _save_settings(); +} + static void _save_settings(void) { diff --git a/src/plugins/settings.h b/src/plugins/settings.h index 65486ea3..889c202c 100644 --- a/src/plugins/settings.h +++ b/src/plugins/settings.h @@ -39,5 +39,7 @@ void plugin_settings_init(void); void plugin_settings_close(void); gboolean plugin_settings_get_boolean(const char *const group, const char *const key, gboolean def); void plugin_settings_set_boolean(const char *const group, const char *const key, gboolean value); +char* plugin_settings_get_string(const char *const group, const char *const key, const char *const def); +void plugin_settings_set_string(const char *const group, const char *const key, const char *const value); #endif |