1
0
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Added integer settings for plugins

This commit is contained in:
James Booth 2016-03-26 02:19:30 +00:00
parent e2b02733df
commit ce9b0836a0
8 changed files with 90 additions and 0 deletions

View File

@ -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); 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);
}

View File

@ -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); 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); 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); 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 #endif

View File

@ -218,6 +218,18 @@ c_api_settings_set_string(char *group, char *key, char *value)
api_settings_set_string(group, key, 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 void
c_command_callback(PluginCommand *command, gchar **args) 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_set_boolean = c_api_settings_set_boolean;
prof_settings_get_string = c_api_settings_get_string; prof_settings_get_string = c_api_settings_get_string;
prof_settings_set_string = c_api_settings_set_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;
} }

View File

@ -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; void (*prof_settings_set_boolean)(char *group, char *key, int value) = NULL;
char* (*prof_settings_get_string)(char *group, char *key, char *def) = 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; 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;

View File

@ -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); void (*prof_settings_set_boolean)(char *group, char *key, int value);
char* (*prof_settings_get_string)(char *group, char *key, char *def); char* (*prof_settings_get_string)(char *group, char *key, char *def);
void (*prof_settings_set_string)(char *group, char *key, char *value); 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 #endif

View File

@ -535,6 +535,42 @@ python_api_settings_set_string(PyObject *self, PyObject *args)
return Py_BuildValue(""); 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 void
python_command_callback(PluginCommand *command, gchar **args) 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_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_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_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 } { NULL, NULL, 0, NULL }
}; };

View File

@ -111,6 +111,23 @@ plugin_settings_set_string(const char *const group, const char *const key, const
_save_settings(); _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 static void
_save_settings(void) _save_settings(void)
{ {

View File

@ -37,9 +37,12 @@
void plugin_settings_init(void); void plugin_settings_init(void);
void plugin_settings_close(void); void plugin_settings_close(void);
gboolean plugin_settings_get_boolean(const char *const group, const char *const key, gboolean def); 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); 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); 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); 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 #endif