1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Merge branch 'master' into osx-functional

This commit is contained in:
James Booth 2016-08-02 23:21:43 +01:00
commit 95cf4aec07
14 changed files with 351 additions and 4 deletions

1
.gitignore vendored
View File

@ -71,6 +71,7 @@ apidocs/python/src/prof.pyc
apidocs/python/plugin.rst
apidocs/python/src/plugin.pyc
apidocs/c/html/
apidocs/c/doxygen_sqlite3.db
# Temp Vim files
**/*.swp

View File

@ -1 +1 @@
rm -rf html && doxygen c-prof.conf && open html/index.html
rm -rf html && doxygen c-prof.conf

View File

@ -193,7 +193,7 @@ int prof_win_show(PROF_WIN_TAG win, char *message);
/**
Show a message in the plugin window, using the specified theme.
Themes must be specified in ~/.local/share/profanity/plugin_themes
@param win The {@link PROF_WIN_TAG} of the window to display the message
@param tag The {@link PROF_WIN_TAG} of the window to display the message
@param group the group name in the themes file
@param key the item name within the group
@param def default colour if the theme cannot be found or NULL
@ -247,6 +247,45 @@ Settings must be specified in ~/.local/share/profanity/plugin_settings
*/
void prof_settings_set_string(char *group, char *key, char *value);
/**
Get a string list setting
Settings must be specified in ~/.local/share/profanity/plugin_settings
The string list setting items are separated by semicolons.
@param group the group name in the settings file
@param key the item name within the group
@return the list setting
*/
char** prof_settings_get_string_list(char *group, char *key);
/**
Add an item to a string list setting
Settings must be specified in ~/.local/share/profanity/plugin_settings
If the list does not exist, a new one will be created with the element added
@param group the group name in the settings file
@param key the item name within the group
@param value item to add
*/
void prof_settings_string_list_add(char *group, char *key, char *value);
/**
Remove an item from a string list setting
Settings must be specified in ~/.local/share/profanity/plugin_settings
@param group the group name in the settings file
@param key the item name within the group
@param value item to remove
@return 1 if the item was removed, or is not in the list, 0 if the list does not exist
*/
int prof_settings_string_list_remove(char *group, char *key, char *value);
/**
Remove all items from a string list setting
Settings must be specified in ~/.local/share/profanity/plugin_settings
@param group the group name in the settings file
@param key the item name within the group
@return 1 if the list was cleared, 0 if the list does not exist
*/
int prof_settings_string_list_remove_all(char *group, char *key);
/**
Get an integer setting
Settings must be specified in ~/.local/share/profanity/plugin_settings

View File

@ -110,7 +110,7 @@ todo_include_todos = False
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
# html_theme = 'sphinx_rtd_theme'
html_theme = 'classic'
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the

View File

@ -1 +1 @@
sphinx-apidoc -f -o . src && make html && open _build/html/prof.html
sphinx-apidoc -f -o . src && make html

View File

@ -460,6 +460,78 @@ def settings_set_string(group, key, value):
pass
def settings_get_string_list(group, key):
"""Get a string list setting\n
Settings must be specified in ``~/.local/share/profanity/plugin_settings``\n
The string list setting items are separated by semicolons.
:param group: the group name in the settings file
:param key: the item name within the group
:type group: str or unicode
:type key: str or unicode
:return: the list setting
:rtype: list of str or unicode
Example:
::
prof.settings_get_string_list("someplugin", "somelist")
"""
def settings_string_list_add(group, key, value):
"""Add an item to a string list setting\n
Settings must be specified in ``~/.local/share/profanity/plugin_settings``\n
If the list does not exist, a new one will be created with the element added
:param group: the group name in the settings file
:param key: the item name within the group
:param value: item to add
:type group: str or unicode
:type key: str or unicode
:type value: str
Example:
::
prof.settings_string_list_add("someplugin", "somelist", "anelement")
"""
def settings_string_list_remove(group, key, value):
"""Remove an item from a string list setting\n
Settings must be specified in ``~/.local/share/profanity/plugin_settings``\n
:param group: the group name in the settings file
:param key: the item name within the group
:param value: item to remove
:type group: str or unicode
:type key: str or unicode
:type value: str
:return: ``True`` if the item was removed, or is not in the list, ``False`` if the list does not exist
:rtype: boolean
Example:
::
prof.settings_string_list_remove("someplugin", "somelist", "anelement")
"""
def settings_string_list_remove_all(group, key):
"""Remove all items from a string list setting\n
Settings must be specified in ``~/.local/share/profanity/plugin_settings``\n
:param group: the group name in the settings file
:param key: the item name within the group
:type group: str or unicode
:type key: str or unicode
:return: ``True`` if the list was cleared, ``False`` if the list does not exist
:rtype: boolean
Example:
::
prof.settings_string_list_remove_all("someplugin", "somelist")
"""
def settings_get_int(group, key, default):
"""Get an integer setting\n
Settings must be specified in ``~/.local/share/profanity/plugin_settings``

View File

@ -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);
}
int
api_settings_string_list_remove_all(const char *const group, const char *const key)
{
return plugin_settings_string_list_remove_all(group, key);
}
int
api_settings_get_int(const char *const group, const char *const key, int def)
{

View File

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

View File

@ -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 int
c_api_settings_string_list_remove_all(char *group, char *key)
{
return 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;
}

View File

@ -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;
int (*prof_settings_string_list_remove_all)(char *group, char *key) = NULL;
void (*prof_incoming_message)(char *barejid, char *resource, char *message) = NULL;

View File

@ -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);
int (*prof_settings_string_list_remove_all)(char *group, char *key);
void (*prof_incoming_message)(char *barejid, char *resource, char *message);

View File

@ -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) {
Py_RETURN_NONE;
}
int len = g_strv_length(c_list);
PyObject *py_list = PyList_New(0);
int i = 0;
for (i = 0; i < len; i++) {
PyObject *py_curr = Py_BuildValue("s", c_list[i]);
int res = PyList_Append(py_list, py_curr);
if (res != 0) {
g_strfreev(c_list);
Py_RETURN_NONE;
}
}
g_strfreev(c_list);
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)) {
return Py_BuildValue("O", Py_False);
}
char *group_str = python_str_or_unicode_to_string(group);
char *key_str = python_str_or_unicode_to_string(key);
allow_python_threads();
int res = api_settings_string_list_remove_all(group_str, key_str);
free(group_str);
free(key_str);
disable_python_threads();
if (res) {
return Py_BuildValue("O", Py_True);
} else {
return Py_BuildValue("O", Py_False);
}
}
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 }

View File

@ -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,47 @@ 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;
}
int
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 0;
}
g_key_file_remove_key(settings, group, key, NULL);
_save_settings();
return 1;
}
static void
_save_settings(void)
{

View File

@ -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);
int plugin_settings_string_list_remove_all(const char *const group, const char *const key);
#endif