diff --git a/src/plugins/api.c b/src/plugins/api.c index 86d1ca08..5851ed91 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -356,3 +356,15 @@ api_settings_set_string(const char *const group, const char *const key, const ch { plugin_settings_set_string(group, key, value); } + +int +api_settings_get_int(const char *const group, const char *const key, int def) +{ + return plugin_settings_get_int(group, key, def); +} + +void +api_settings_set_int(const char *const group, const char *const key, int value) +{ + plugin_settings_set_int(group, key, value); +} diff --git a/src/plugins/api.h b/src/plugins/api.h index 82ba2b58..82223c08 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -76,5 +76,7 @@ gboolean api_settings_get_boolean(const char *const group, const char *const key 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); +int api_settings_get_int(const char *const group, const char *const key, int def); +void api_settings_set_int(const char *const group, const char *const key, int value); #endif diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 52799a4e..2427b46a 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -218,6 +218,18 @@ c_api_settings_set_string(char *group, char *key, char *value) api_settings_set_string(group, key, value); } +static int +c_api_settings_get_int(char *group, char *key, int def) +{ + return api_settings_get_int(group, key, def); +} + +static void +c_api_settings_set_int(char *group, char *key, int value) +{ + api_settings_set_int(group, key, value); +} + void c_command_callback(PluginCommand *command, gchar **args) { @@ -271,4 +283,6 @@ c_api_init(void) 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; + prof_settings_get_int = c_api_settings_get_int; + prof_settings_set_int = c_api_settings_set_int; } diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index 1f69981e..3ea3bded 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -75,3 +75,5 @@ 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; +int (*prof_settings_get_int)(char *group, char *key, int def) = NULL; +void (*prof_settings_set_int)(char *group, char *key, int value) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index f32ebb3a..e7bcd1aa 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -75,5 +75,7 @@ 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); +int (*prof_settings_get_int)(char *group, char *key, int def); +void (*prof_settings_set_int)(char *group, char *key, int value); #endif diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index 9c1e79aa..148a7eb0 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -535,6 +535,42 @@ python_api_settings_set_string(PyObject *self, PyObject *args) return Py_BuildValue(""); } +static PyObject* +python_api_settings_get_int(PyObject *self, PyObject *args) +{ + char *group = NULL; + char *key = NULL; + int def = 0; + + if (!PyArg_ParseTuple(args, "ssi", &group, &key, &def)) { + return Py_BuildValue(""); + } + + allow_python_threads(); + int res = api_settings_get_int(group, key, def); + disable_python_threads(); + + return Py_BuildValue("i", res); +} + +static PyObject* +python_api_settings_set_int(PyObject *self, PyObject *args) +{ + char *group = NULL; + char *key = NULL; + int val = 0; + + if (!PyArg_ParseTuple(args, "ssi", &group, &key, &val)) { + return Py_BuildValue(""); + } + + allow_python_threads(); + api_settings_set_int(group, key, val); + disable_python_threads(); + + return Py_BuildValue(""); +} + void python_command_callback(PluginCommand *command, gchar **args) { @@ -629,6 +665,8 @@ static PyMethodDef apiMethods[] = { { "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" }, + { "settings_get_int", python_api_settings_get_int, METH_VARARGS, "Get a integer setting" }, + { "settings_set_int", python_api_settings_set_int, METH_VARARGS, "Set a integer setting" }, { NULL, NULL, 0, NULL } }; diff --git a/src/plugins/settings.c b/src/plugins/settings.c index dcaf2270..08d982d0 100644 --- a/src/plugins/settings.c +++ b/src/plugins/settings.c @@ -111,6 +111,23 @@ plugin_settings_set_string(const char *const group, const char *const key, const _save_settings(); } +int +plugin_settings_get_int(const char *const group, const char *const key, int def) +{ + if (group && key && g_key_file_has_key(settings, group, key, NULL)) { + return g_key_file_get_integer(settings, group, key, NULL); + } else { + return def; + } +} + +void +plugin_settings_set_int(const char *const group, const char *const key, int value) +{ + g_key_file_set_integer(settings, group, key, value); + _save_settings(); +} + static void _save_settings(void) { diff --git a/src/plugins/settings.h b/src/plugins/settings.h index 889c202c..6fb66844 100644 --- a/src/plugins/settings.h +++ b/src/plugins/settings.h @@ -37,9 +37,12 @@ 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); +int plugin_settings_get_int(const char *const group, const char *const key, int def); +void plugin_settings_set_int(const char *const group, const char *const key, int value); #endif