mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Added plugin string settings
This commit is contained in:
parent
a4e6d50a40
commit
e2b02733df
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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 }
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user