mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Add string lists settings to plugins
This commit is contained in:
parent
30e96b2d0f
commit
2518aa5078
@ -422,6 +422,30 @@ api_settings_set_string(const char *const group, const char *const key, const ch
|
||||
plugin_settings_set_string(group, key, value);
|
||||
}
|
||||
|
||||
char**
|
||||
api_settings_get_string_list(const char *const group, const char *const key)
|
||||
{
|
||||
return plugin_settings_get_string_list(group, key);
|
||||
}
|
||||
|
||||
void
|
||||
api_settings_string_list_add(const char *const group, const char *const key, const char *const value)
|
||||
{
|
||||
plugin_settings_string_list_add(group, key, value);
|
||||
}
|
||||
|
||||
int
|
||||
api_settings_string_list_remove(const char *const group, const char *const key, const char *const value)
|
||||
{
|
||||
return plugin_settings_string_list_remove(group, key, value);
|
||||
}
|
||||
|
||||
void
|
||||
api_settings_string_list_remove_all(const char *const group, const char *const key)
|
||||
{
|
||||
plugin_settings_string_list_remove_all(group, key);
|
||||
}
|
||||
|
||||
int
|
||||
api_settings_get_int(const char *const group, const char *const key, int def)
|
||||
{
|
||||
|
@ -84,6 +84,10 @@ char* api_settings_get_string(const char *const group, const char *const key, co
|
||||
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);
|
||||
char** api_settings_get_string_list(const char *const group, const char *const key);
|
||||
void api_settings_string_list_add(const char *const group, const char *const key, const char *const value);
|
||||
int api_settings_string_list_remove(const char *const group, const char *const key, const char *const value);
|
||||
void api_settings_string_list_remove_all(const char *const group, const char *const key);
|
||||
|
||||
void api_incoming_message(const char *const barejid, const char *const resource, const char *const message);
|
||||
|
||||
|
@ -274,6 +274,30 @@ c_api_settings_set_string(char *group, char *key, char *value)
|
||||
api_settings_set_string(group, key, value);
|
||||
}
|
||||
|
||||
static char**
|
||||
c_api_settings_get_string_list(char *group, char *key)
|
||||
{
|
||||
return api_settings_get_string_list(group, key);
|
||||
}
|
||||
|
||||
static void
|
||||
c_api_settings_string_list_add(char *group, char *key, char* value)
|
||||
{
|
||||
api_settings_string_list_add(group, key, value);
|
||||
}
|
||||
|
||||
static int
|
||||
c_api_settings_string_list_remove(char *group, char *key, char *value)
|
||||
{
|
||||
return api_settings_string_list_remove(group, key, value);
|
||||
}
|
||||
|
||||
static void
|
||||
c_api_settings_string_list_remove_all(char *group, char *key)
|
||||
{
|
||||
api_settings_string_list_remove_all(group, key);
|
||||
}
|
||||
|
||||
static int
|
||||
c_api_settings_get_int(char *group, char *key, int def)
|
||||
{
|
||||
@ -357,6 +381,10 @@ c_api_init(void)
|
||||
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;
|
||||
prof_settings_get_string_list = c_api_settings_get_string_list;
|
||||
prof_settings_string_list_add = c_api_settings_string_list_add;
|
||||
prof_settings_string_list_remove = c_api_settings_string_list_remove;
|
||||
prof_settings_string_list_remove_all = c_api_settings_string_list_remove_all;
|
||||
prof_incoming_message = c_api_incoming_message;
|
||||
prof_disco_add_feature = c_api_disco_add_feature;
|
||||
}
|
||||
|
@ -81,6 +81,10 @@ 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;
|
||||
char** (*prof_settings_get_string_list)(char *group, char *key) = NULL;
|
||||
void (*prof_settings_string_list_add)(char *group, char *key, char *value) = NULL;
|
||||
int (*prof_settings_string_list_remove)(char *group, char *key, char *value) = NULL;
|
||||
void (*prof_settings_string_list_remove_all)(char *group, char *key) = NULL;
|
||||
|
||||
void (*prof_incoming_message)(char *barejid, char *resource, char *message) = NULL;
|
||||
|
||||
|
@ -91,6 +91,10 @@ 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);
|
||||
char** (*prof_settings_get_string_list)(char *group, char *key);
|
||||
void (*prof_settings_string_list_add)(char *group, char *key, char *value);
|
||||
int (*prof_settings_string_list_remove)(char *group, char *key, char *value);
|
||||
void (*prof_settings_string_list_remove_all)(char *group, char *key);
|
||||
|
||||
void (*prof_incoming_message)(char *barejid, char *resource, char *message);
|
||||
|
||||
|
@ -819,6 +819,127 @@ python_api_settings_set_int(PyObject *self, PyObject *args)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_settings_get_string_list(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *group = NULL;
|
||||
PyObject *key = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OO", &group, &key)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *group_str = python_str_or_unicode_to_string(group);
|
||||
char *key_str = python_str_or_unicode_to_string(key);
|
||||
|
||||
allow_python_threads();
|
||||
char** c_list = api_settings_get_string_list(group_str, key_str);
|
||||
free(group_str);
|
||||
free(key_str);
|
||||
disable_python_threads();
|
||||
|
||||
if (!c_list) {
|
||||
log_debug("NO ITEMS");
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
int len = g_strv_length(c_list);
|
||||
log_debug("GOT ITEMS: %d", len);
|
||||
PyObject *py_list = PyList_New(0);
|
||||
log_debug("CRETED LIST");
|
||||
int i = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
log_debug("ADDING %s", c_list[i]);
|
||||
PyObject *py_curr = Py_BuildValue("s", c_list[i]);
|
||||
int res = PyList_Append(py_list, py_curr);
|
||||
log_debug("Created object");
|
||||
if (res != 0) {
|
||||
log_debug("ERROR");
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
log_debug("Added");
|
||||
}
|
||||
|
||||
return Py_BuildValue("O", py_list);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_settings_string_list_add(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *group = NULL;
|
||||
PyObject *key = NULL;
|
||||
PyObject *val = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOO", &group, &key, &val)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *group_str = python_str_or_unicode_to_string(group);
|
||||
char *key_str = python_str_or_unicode_to_string(key);
|
||||
char *val_str = python_str_or_unicode_to_string(val);
|
||||
|
||||
allow_python_threads();
|
||||
api_settings_string_list_add(group_str, key_str, val_str);
|
||||
free(group_str);
|
||||
free(key_str);
|
||||
free(val_str);
|
||||
disable_python_threads();
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_settings_string_list_remove(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *group = NULL;
|
||||
PyObject *key = NULL;
|
||||
PyObject *val = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOO", &group, &key, &val)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *group_str = python_str_or_unicode_to_string(group);
|
||||
char *key_str = python_str_or_unicode_to_string(key);
|
||||
char *val_str = python_str_or_unicode_to_string(val);
|
||||
|
||||
allow_python_threads();
|
||||
int res = api_settings_string_list_remove(group_str, key_str, val_str);
|
||||
free(group_str);
|
||||
free(key_str);
|
||||
free(val_str);
|
||||
disable_python_threads();
|
||||
|
||||
if (res) {
|
||||
return Py_BuildValue("O", Py_True);
|
||||
} else {
|
||||
return Py_BuildValue("O", Py_False);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_settings_string_list_remove_all(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *group = NULL;
|
||||
PyObject *key = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OO", &group, &key)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *group_str = python_str_or_unicode_to_string(group);
|
||||
char *key_str = python_str_or_unicode_to_string(key);
|
||||
|
||||
allow_python_threads();
|
||||
api_settings_string_list_remove_all(group_str, key_str);
|
||||
free(group_str);
|
||||
free(key_str);
|
||||
disable_python_threads();
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_incoming_message(PyObject *self, PyObject *args)
|
||||
{
|
||||
@ -962,6 +1083,10 @@ static PyMethodDef apiMethods[] = {
|
||||
{ "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." },
|
||||
{ "settings_get_string_list", python_api_settings_get_string_list, METH_VARARGS, "Get a string list setting." },
|
||||
{ "settings_string_list_add", python_api_settings_string_list_add, METH_VARARGS, "Add item to string list setting." },
|
||||
{ "settings_string_list_remove", python_api_settings_string_list_remove, METH_VARARGS, "Remove item from string list setting." },
|
||||
{ "settings_string_list_remove_all", python_api_settings_string_list_remove_all, METH_VARARGS, "Remove all items from string list setting." },
|
||||
{ "incoming_message", python_api_incoming_message, METH_VARARGS, "Show an incoming message." },
|
||||
{ "disco_add_feature", python_api_disco_add_feature, METH_VARARGS, "Add a feature to disco info response." },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "common.h"
|
||||
#include "config/theme.h"
|
||||
#include "config/files.h"
|
||||
#include "config/conflists.h"
|
||||
|
||||
static GKeyFile *settings;
|
||||
|
||||
@ -126,6 +127,45 @@ plugin_settings_set_int(const char *const group, const char *const key, int valu
|
||||
_save_settings();
|
||||
}
|
||||
|
||||
gchar**
|
||||
plugin_settings_get_string_list(const char *const group, const char *const key)
|
||||
{
|
||||
if (!g_key_file_has_key(settings, group, key, NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_key_file_get_string_list(settings, group, key, NULL, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
plugin_settings_string_list_add(const char *const group, const char *const key, const char *const value)
|
||||
{
|
||||
int res = conf_string_list_add(settings, group, key, value);
|
||||
_save_settings();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
plugin_settings_string_list_remove(const char *const group, const char *const key, const char *const value)
|
||||
{
|
||||
int res = conf_string_list_remove(settings, group, key, value);
|
||||
_save_settings();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
plugin_settings_string_list_remove_all(const char *const group, const char *const key)
|
||||
{
|
||||
if (!g_key_file_has_key(settings, group, key, NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_key_file_remove_key(settings, group, key, NULL);
|
||||
_save_settings();
|
||||
}
|
||||
|
||||
static void
|
||||
_save_settings(void)
|
||||
{
|
||||
|
@ -44,5 +44,9 @@ char* plugin_settings_get_string(const char *const group, const char *const key,
|
||||
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);
|
||||
char** plugin_settings_get_string_list(const char *const group, const char *const key);
|
||||
void plugin_settings_string_list_add(const char *const group, const char *const key, const char *const value);
|
||||
int plugin_settings_string_list_remove(const char *const group, const char *const key, const char *const value);
|
||||
void plugin_settings_string_list_remove_all(const char *const group, const char *const key);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user