1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

Allow chat prefix char to be set by plugins

This commit is contained in:
James Booth 2017-01-20 21:03:55 +00:00
parent ab1441a25c
commit c8874cd2e0
13 changed files with 373 additions and 4 deletions

View File

@ -349,9 +349,38 @@ Set the text to display in the titlebar encryption indicator.
int prof_chat_set_titlebar_enctext(char *barejid, char *enctext);
/**
Let profanity decide what to show in the titlebar encryption indicator
Let profanity decide what to show in the titlebar encryption indicator.
@param barejid Jabber ID of the recipient
@return 1 on success, 0 on failure
*/
int prof_chat_unset_titlebar_enctext(char *barejid);
/**
Set the incoming message prefix character for specified contact.
@param barejid Jabber ID of the recipient
@param ch The character to display
@return 1 on success, 0 on failure
*/
int prof_chat_set_incoming_char(char *barejid, char *ch);
/**
Reset the incoming message prefix character for specified contact.
@param barejid Jabber ID of the recipient
@return 1 on success, 0 on failure
*/
int prof_chat_unset_incoming_char(char *barejid);
/**
Set the outgoing message prefix character for specified contact.
@param barejid Jabber ID of the recipient
@param ch The character to display
@return 1 on success, 0 on failure
*/
int prof_chat_set_outgoing_char(char *barejid, char *ch);
/**
Reset the outgoing message prefix character for specified contact.
@param barejid Jabber ID of the recipient
@return 1 on success, 0 on failure
*/
int prof_chat_unset_outgoing_char(char *barejid);

View File

@ -662,3 +662,65 @@ def chat_unset_titlebar_enctext(barejid):
prof.chat_unset_titlebar_enctext("bob@chat.org")
"""
def chat_set_incoming_char(barejid, ch):
"""Set the incoming message prefix character for specified contact.
:param barejid: Jabber ID of the recipient
:param enctext: The character to display
:type barejid: str or unicode
:type enctext: str or unicode
:return: ``True`` if the character was set successfully, ``False`` otherwise
:rtype: boolean
Example:
::
prof.chat_set_incoming_char("kristine@chat.org", "*")
"""
def chat_unset_incoming_char(barejid):
"""Reset the incoming message prefix character for specified contact.
:param barejid: Jabber ID of the recipient
:type barejid: str or unicode
:return: ``True`` if the char was unset successfully, ``False`` otherwise
:rtype: boolean
Example:
::
prof.chat_unset_incoming_char("kristine@chat.org")
"""
def chat_set_outgoing_char(barejid, ch):
"""Set the outgoing message prefix character for specified contact.
:param barejid: Jabber ID of the recipient
:param enctext: The character to display
:type barejid: str or unicode
:type enctext: str or unicode
:return: ``True`` if the character was set successfully, ``False`` otherwise
:rtype: boolean
Example:
::
prof.chat_set_outgoing_char("david@chat.org", "+")
"""
def chat_unset_outgoing_char(barejid):
"""Reset the outgoing message prefix character for specified contact.
:param barejid: Jabber ID of the recipient
:type barejid: str or unicode
:return: ``True`` if the char was unset successfully, ``False`` otherwise
:rtype: boolean
Example:
::
prof.chat_unset_outgoing_char("david@chat.org")
"""

View File

@ -561,3 +561,87 @@ api_chat_unset_titlebar_enctext(const char *const barejid)
return 1;
}
int
api_chat_set_incoming_char(const char *const barejid, const char *const ch)
{
if (ch == NULL) {
return 0;
}
if (strlen(ch) != 1) {
return 0;
}
if (barejid == NULL) {
return 0;
}
ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin == NULL) {
return 0;
}
chatwin_set_incoming_char(chatwin, ch);
return 1;
}
int
api_chat_unset_incoming_char(const char *const barejid)
{
if (barejid == NULL) {
return 0;
}
ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin == NULL) {
return 0;
}
chatwin_unset_incoming_char(chatwin);
return 1;
}
int
api_chat_set_outgoing_char(const char *const barejid, const char *const ch)
{
if (ch == NULL) {
return 0;
}
if (strlen(ch) != 1) {
return 0;
}
if (barejid == NULL) {
return 0;
}
ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin == NULL) {
return 0;
}
chatwin_set_outgoing_char(chatwin, ch);
return 1;
}
int
api_chat_unset_outgoing_char(const char *const barejid)
{
if (barejid == NULL) {
return 0;
}
ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin == NULL) {
return 0;
}
chatwin_unset_outgoing_char(chatwin);
return 1;
}

View File

@ -100,5 +100,9 @@ void api_encryption_reset(const char *const barejid);
int api_chat_set_titlebar_enctext(const char *const barejid, const char *const enctext);
int api_chat_unset_titlebar_enctext(const char *const barejid);
int api_chat_set_incoming_char(const char *const barejid, const char *const ch);
int api_chat_unset_incoming_char(const char *const barejid);
int api_chat_set_outgoing_char(const char *const barejid, const char *const ch);
int api_chat_unset_outgoing_char(const char *const barejid);
#endif

View File

@ -359,6 +359,30 @@ c_api_chat_unset_titlebar_enctext(const char *barejid)
return api_chat_unset_titlebar_enctext(barejid);
}
static int
c_api_chat_set_incoming_char(const char *barejid, const char *ch)
{
return api_chat_set_incoming_char(barejid, ch);
}
static int
c_api_chat_unset_incoming_char(const char *barejid)
{
return api_chat_unset_incoming_char(barejid);
}
static int
c_api_chat_set_outgoing_char(const char *barejid, const char *ch)
{
return api_chat_set_outgoing_char(barejid, ch);
}
static int
c_api_chat_unset_outgoing_char(const char *barejid)
{
return api_chat_unset_outgoing_char(barejid);
}
void
c_command_callback(PluginCommand *command, gchar **args)
{
@ -429,6 +453,10 @@ c_api_init(void)
prof_encryption_reset = c_api_encryption_reset;
prof_chat_set_titlebar_enctext = c_api_chat_set_titlebar_enctext;
prof_chat_unset_titlebar_enctext = c_api_chat_unset_titlebar_enctext;
prof_chat_set_incoming_char = c_api_chat_set_incoming_char;
prof_chat_unset_incoming_char = c_api_chat_unset_incoming_char;
prof_chat_set_outgoing_char = c_api_chat_set_outgoing_char;
prof_chat_unset_outgoing_char = c_api_chat_unset_outgoing_char;
}
static char *

View File

@ -97,4 +97,7 @@ void (*prof_encryption_reset)(const char *barejid) = NULL;
int (*prof_chat_set_titlebar_enctext)(const char *barejid, const char *enctext) = NULL;
int (*prof_chat_unset_titlebar_enctext)(const char *barejid) = NULL;
int (*prof_chat_set_incoming_char)(const char *barejid, const char *ch) = NULL;
int (*prof_chat_unset_incoming_char)(const char *barejid) = NULL;
int (*prof_chat_set_outgoing_char)(const char *barejid, const char *ch) = NULL;
int (*prof_chat_unset_outgoing_char)(const char *barejid) = NULL;

View File

@ -109,5 +109,9 @@ void (*prof_encryption_reset)(const char *barejid);
int (*prof_chat_set_titlebar_enctext)(const char *barejid, const char *enctext);
int (*prof_chat_unset_titlebar_enctext)(const char *barejid);
int (*prof_chat_set_incoming_char)(const char *barejid, const char *ch);
int (*prof_chat_unset_incoming_char)(const char *barejid);
int (*prof_chat_set_outgoing_char)(const char *barejid, const char *ch);
int (*prof_chat_unset_outgoing_char)(const char *barejid);
#endif

View File

@ -1096,6 +1096,100 @@ python_api_chat_unset_titlebar_enctext(PyObject *self, PyObject *args)
}
}
static PyObject*
python_api_chat_set_incoming_char(PyObject *self, PyObject *args)
{
PyObject *barejid = NULL;
PyObject *ch = NULL;
if (!PyArg_ParseTuple(args, "OO", &barejid, &ch)) {
Py_RETURN_NONE;
}
char *barejid_str = python_str_or_unicode_to_string(barejid);
char *ch_str = python_str_or_unicode_to_string(ch);
allow_python_threads();
int res = api_chat_set_incoming_char(barejid_str, ch_str);
free(barejid_str);
free(ch_str);
disable_python_threads();
if (res) {
return Py_BuildValue("O", Py_True);
} else {
return Py_BuildValue("O", Py_False);
}
}
static PyObject*
python_api_chat_unset_incoming_char(PyObject *self, PyObject *args)
{
PyObject *barejid = NULL;
if (!PyArg_ParseTuple(args, "O", &barejid)) {
Py_RETURN_NONE;
}
char *barejid_str = python_str_or_unicode_to_string(barejid);
allow_python_threads();
int res = api_chat_unset_incoming_char(barejid_str);
free(barejid_str);
disable_python_threads();
if (res) {
return Py_BuildValue("O", Py_True);
} else {
return Py_BuildValue("O", Py_False);
}
}
static PyObject*
python_api_chat_set_outgoing_char(PyObject *self, PyObject *args)
{
PyObject *barejid = NULL;
PyObject *ch = NULL;
if (!PyArg_ParseTuple(args, "OO", &barejid, &ch)) {
Py_RETURN_NONE;
}
char *barejid_str = python_str_or_unicode_to_string(barejid);
char *ch_str = python_str_or_unicode_to_string(ch);
allow_python_threads();
int res = api_chat_set_outgoing_char(barejid_str, ch_str);
free(barejid_str);
free(ch_str);
disable_python_threads();
if (res) {
return Py_BuildValue("O", Py_True);
} else {
return Py_BuildValue("O", Py_False);
}
}
static PyObject*
python_api_chat_unset_outgoing_char(PyObject *self, PyObject *args)
{
PyObject *barejid = NULL;
if (!PyArg_ParseTuple(args, "O", &barejid)) {
Py_RETURN_NONE;
}
char *barejid_str = python_str_or_unicode_to_string(barejid);
allow_python_threads();
int res = api_chat_unset_outgoing_char(barejid_str);
free(barejid_str);
disable_python_threads();
if (res) {
return Py_BuildValue("O", Py_True);
} else {
return Py_BuildValue("O", Py_False);
}
}
void
python_command_callback(PluginCommand *command, gchar **args)
{
@ -1207,6 +1301,10 @@ static PyMethodDef apiMethods[] = {
{ "encryption_reset", python_api_encryption_reset, METH_VARARGS, "End encrypted chat session with barejid, if one exists" },
{ "chat_set_titlebar_enctext", python_api_chat_set_titlebar_enctext, METH_VARARGS, "Set the encryption status in the title bar for the specified contact" },
{ "chat_unset_titlebar_enctext", python_api_chat_unset_titlebar_enctext, METH_VARARGS, "Reset the encryption status in the title bar for the specified recipient" },
{ "chat_set_incoming_char", python_api_chat_set_incoming_char, METH_VARARGS, "Set the incoming message prefix character for specified contact" },
{ "chat_unset_incoming_char", python_api_chat_unset_incoming_char, METH_VARARGS, "Reset the incoming message prefix character for specified contact" },
{ "chat_set_outgoing_char", python_api_chat_set_outgoing_char, METH_VARARGS, "Set the outgoing message prefix character for specified contact" },
{ "chat_unset_outgoing_char", python_api_chat_unset_outgoing_char, METH_VARARGS, "Reset the outgoing message prefix character for specified contact" },
{ NULL, NULL, 0, NULL }
};

View File

@ -299,7 +299,9 @@ chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id,
assert(chatwin != NULL);
char enc_char = '-';
if (enc_mode == PROF_MSG_OTR) {
if (chatwin->outgoing_char) {
enc_char = chatwin->outgoing_char[0];
} else if (enc_mode == PROF_MSG_OTR) {
enc_char = prefs_get_otr_char();
} else if (enc_mode == PROF_MSG_PGP) {
enc_char = prefs_get_pgp_char();
@ -403,6 +405,42 @@ chatwin_unset_enctext(ProfChatWin *chatwin)
}
}
void
chatwin_set_incoming_char(ProfChatWin *chatwin, const char *const ch)
{
if (chatwin->incoming_char) {
free(chatwin->incoming_char);
}
chatwin->incoming_char = strdup(ch);
}
void
chatwin_unset_incoming_char(ProfChatWin *chatwin)
{
if (chatwin->incoming_char) {
free(chatwin->incoming_char);
chatwin->incoming_char = NULL;
}
}
void
chatwin_set_outgoing_char(ProfChatWin *chatwin, const char *const ch)
{
if (chatwin->outgoing_char) {
free(chatwin->outgoing_char);
}
chatwin->outgoing_char = strdup(ch);
}
void
chatwin_unset_outgoing_char(ProfChatWin *chatwin)
{
if (chatwin->outgoing_char) {
free(chatwin->outgoing_char);
chatwin->outgoing_char = NULL;
}
}
static void
_chatwin_history(ProfChatWin *chatwin, const char *const contact)
{

View File

@ -142,6 +142,10 @@ void chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, voi
#endif
void chatwin_set_enctext(ProfChatWin *chatwin, const char *const enctext);
void chatwin_unset_enctext(ProfChatWin *chatwin);
void chatwin_set_incoming_char(ProfChatWin *chatwin, const char *const ch);
void chatwin_unset_incoming_char(ProfChatWin *chatwin);
void chatwin_set_outgoing_char(ProfChatWin *chatwin, const char *const ch);
void chatwin_unset_outgoing_char(ProfChatWin *chatwin);
// MUC window
void mucwin_role_change(ProfMucWin *mucwin, const char *const role, const char *const actor, const char *const reason);

View File

@ -156,6 +156,8 @@ typedef struct prof_chat_win_t {
gboolean history_shown;
unsigned long memcheck;
char *enctext;
char *incoming_char;
char *outgoing_char;
} ProfChatWin;
typedef struct prof_muc_win_t {

View File

@ -147,6 +147,8 @@ win_create_chat(const char *const barejid)
new_win->unread = 0;
new_win->state = chat_state_new();
new_win->enctext = NULL;
new_win->incoming_char = NULL;
new_win->outgoing_char = NULL;
new_win->memcheck = PROFCHATWIN_MEMCHECK;
@ -432,6 +434,8 @@ win_free(ProfWin* window)
free(chatwin->barejid);
free(chatwin->resource_override);
free(chatwin->enctext);
free(chatwin->incoming_char);
free(chatwin->outgoing_char);
chat_state_free(chatwin->state);
break;
}
@ -996,13 +1000,18 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp,
switch (window->type)
{
case WIN_CHAT:
if (enc_mode == PROF_MSG_OTR) {
{
ProfChatWin *chatwin = (ProfChatWin*)window;
if (chatwin->incoming_char) {
enc_char = chatwin->incoming_char[0];
} else if (enc_mode == PROF_MSG_OTR) {
enc_char = prefs_get_otr_char();
} else if (enc_mode == PROF_MSG_PGP) {
enc_char = prefs_get_pgp_char();
}
_win_printf(window, enc_char, 0, timestamp, NO_ME, THEME_TEXT_THEM, from, "%s", message);
break;
}
case WIN_PRIVATE:
_win_printf(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, from, "%s", message);
break;

View File

@ -69,6 +69,10 @@ void chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, voi
void chatwin_set_enctext(ProfChatWin *chatwin, const char *const enctext) {}
void chatwin_unset_enctext(ProfChatWin *chatwin) {}
void chatwin_set_incoming_char(ProfChatWin *chatwin, const char *const ch) {}
void chatwin_unset_incoming_char(ProfChatWin *chatwin) {}
void chatwin_set_outgoing_char(ProfChatWin *chatwin, const char *const ch) {}
void chatwin_unset_outgoing_char(ProfChatWin *chatwin) {}
void ui_sigwinch_handler(int sig) {}