From c8874cd2e0c7a62eff66cb19acd40e36750d1b50 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 20 Jan 2017 21:03:55 +0000 Subject: [PATCH 1/2] Allow chat prefix char to be set by plugins --- apidocs/c/profapi.h | 31 +++++++++++- apidocs/python/src/prof.py | 62 +++++++++++++++++++++++ src/plugins/api.c | 84 +++++++++++++++++++++++++++++++ src/plugins/api.h | 4 ++ src/plugins/c_api.c | 28 +++++++++++ src/plugins/profapi.c | 5 +- src/plugins/profapi.h | 4 ++ src/plugins/python_api.c | 98 ++++++++++++++++++++++++++++++++++++ src/ui/chatwin.c | 40 ++++++++++++++- src/ui/ui.h | 4 ++ src/ui/win_types.h | 2 + src/ui/window.c | 11 +++- tests/unittests/ui/stub_ui.c | 4 ++ 13 files changed, 373 insertions(+), 4 deletions(-) diff --git a/apidocs/c/profapi.h b/apidocs/c/profapi.h index 9ef1a795..9751069f 100644 --- a/apidocs/c/profapi.h +++ b/apidocs/c/profapi.h @@ -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); diff --git a/apidocs/python/src/prof.py b/apidocs/python/src/prof.py index 64468eb0..d65aa580 100644 --- a/apidocs/python/src/prof.py +++ b/apidocs/python/src/prof.py @@ -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") + """ + diff --git a/src/plugins/api.c b/src/plugins/api.c index e0b2afb1..d4109937 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -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; +} diff --git a/src/plugins/api.h b/src/plugins/api.h index 64784924..465365a0 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -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 diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 3721c726..6968657f 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -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 * diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index b9dd9e6f..c0085d64 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -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; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index 291f8958..ac71293a 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -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 diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index 27b4adf8..4e6f4bb5 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -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 } }; diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 74acd79b..646ef578 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -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) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 56f9f4a3..336e820b 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -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); diff --git a/src/ui/win_types.h b/src/ui/win_types.h index 56e6d129..b19822d5 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -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 { diff --git a/src/ui/window.c b/src/ui/window.c index 83172bbf..85e2b73f 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -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; diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 04c6300c..9ca9ab5e 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -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) {} From 9cfd17821c427ae2c129842b5f626fbdb3a73a67 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 20 Jan 2017 23:26:14 +0000 Subject: [PATCH 2/2] Allow room display properies to be set by plugins --- apidocs/c/profapi.h | 34 ++++++++++++- apidocs/python/src/prof.py | 83 ++++++++++++++++++++++++++++-- src/plugins/api.c | 80 +++++++++++++++++++++++++++++ src/plugins/api.h | 4 ++ src/plugins/c_api.c | 28 +++++++++++ src/plugins/profapi.c | 4 ++ src/plugins/profapi.h | 4 ++ src/plugins/python_api.c | 98 ++++++++++++++++++++++++++++++++++++ src/ui/mucwin.c | 49 ++++++++++++++++-- src/ui/titlebar.c | 26 ++++++++++ src/ui/ui.h | 4 ++ src/ui/win_types.h | 2 + src/ui/window.c | 20 +++++--- src/ui/window.h | 6 +-- tests/unittests/ui/stub_ui.c | 5 ++ 15 files changed, 425 insertions(+), 22 deletions(-) diff --git a/apidocs/c/profapi.h b/apidocs/c/profapi.h index 9751069f..fd872dd1 100644 --- a/apidocs/c/profapi.h +++ b/apidocs/c/profapi.h @@ -341,7 +341,7 @@ End any encrypted session with the specified user. void prof_encryption_reset(char *barejid); /** -Set the text to display in the titlebar encryption indicator. +Set the text to display in the titlebar encryption indicator for recipient. @param barejid Jabber ID of the recipient @param enctext The text to display @return 1 on success, 0 on failure @@ -349,7 +349,7 @@ 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 for recipient. @param barejid Jabber ID of the recipient @return 1 on success, 0 on failure */ @@ -384,3 +384,33 @@ Reset the outgoing message prefix character for specified contact. @return 1 on success, 0 on failure */ int prof_chat_unset_outgoing_char(char *barejid); + +/** +Set the text to display in the titlebar encryption indicator for room. +@param roomjid Jabber ID of the room +@param enctext The text to display +@return 1 on success, 0 on failure +*/ +int prof_room_set_titlebar_enctext(char *roomjid, char *enctext); + +/** +Let profanity decide what to show in the titlebar encryption indicator for room. +@param roomjid Jabber ID of the room +@return 1 on success, 0 on failure +*/ +int prof_room_unset_titlebar_enctext(char *roomjid); + +/** +Set the message prefix character for specified room. +@param roomjid Jabber ID of the room +@param ch The character to display +@return 1 on success, 0 on failure +*/ +int prof_room_set_message_char(char *roomjid, char *ch); + +/** +Reset the message prefix character for specified room. +@param roomjid Jabber ID of the room +@return 1 on success, 0 on failure +*/ +int prof_room_unset_message_char(char *roomjid); diff --git a/apidocs/python/src/prof.py b/apidocs/python/src/prof.py index d65aa580..35981473 100644 --- a/apidocs/python/src/prof.py +++ b/apidocs/python/src/prof.py @@ -268,6 +268,7 @@ def get_room_nick(barejid): :return: Room nickname. :rtype: str """ + pass def current_win_is_console(): @@ -498,6 +499,7 @@ def settings_string_list_get(group, key): :: prof.settings_get_string_list("someplugin", "somelist") """ + pass def settings_string_list_add(group, key, value): @@ -516,6 +518,7 @@ def settings_string_list_add(group, key, value): :: prof.settings_string_list_add("someplugin", "somelist", "anelement") """ + pass def settings_string_list_remove(group, key, value): @@ -535,6 +538,7 @@ def settings_string_list_remove(group, key, value): :: prof.settings_string_list_remove("someplugin", "somelist", "anelement") """ + pass def settings_string_list_clear(group, key): @@ -552,6 +556,7 @@ def settings_string_list_clear(group, key): :: prof.settings_string_list_remove_all("someplugin", "somelist") """ + pass def settings_int_get(group, key, default): @@ -604,6 +609,7 @@ def incoming_message(barejid, resource, message): :: prof.incoming_message("bob@server.org", "laptop", "Hello there") """ + pass def disco_add_feature(feature): @@ -630,10 +636,11 @@ def encryption_reset(barejid): :: prof.encryption_reset("alice@server.org") """ + pass def chat_set_titlebar_enctext(barejid, enctext): - """Set the text to display in the titlebar encryption indicator. + """Set the text to display in the titlebar encryption indicator for recipient. :param barejid: Jabber ID of the recipient :param enctext: The text to display @@ -642,15 +649,15 @@ def chat_set_titlebar_enctext(barejid, enctext): :return: ``True`` if the text was set successfully, ``False`` otherwise :rtype: boolean - Example: :: prof.chat_set_titlebar_enctext("bob@chat.org", "safe") """ + pass def chat_unset_titlebar_enctext(barejid): - """Let profanity decide what to show in the titlebar encryption indicator. + """Let profanity decide what to show in the titlebar encryption indicator for recipient. :param barejid: Jabber ID of the recipient :type barejid: str or unicode @@ -661,6 +668,7 @@ def chat_unset_titlebar_enctext(barejid): :: prof.chat_unset_titlebar_enctext("bob@chat.org") """ + pass def chat_set_incoming_char(barejid, ch): @@ -673,11 +681,11 @@ def chat_set_incoming_char(barejid, ch): :return: ``True`` if the character was set successfully, ``False`` otherwise :rtype: boolean - Example: :: prof.chat_set_incoming_char("kristine@chat.org", "*") """ + pass def chat_unset_incoming_char(barejid): @@ -692,6 +700,7 @@ def chat_unset_incoming_char(barejid): :: prof.chat_unset_incoming_char("kristine@chat.org") """ + pass def chat_set_outgoing_char(barejid, ch): @@ -704,11 +713,11 @@ def chat_set_outgoing_char(barejid, ch): :return: ``True`` if the character was set successfully, ``False`` otherwise :rtype: boolean - Example: :: prof.chat_set_outgoing_char("david@chat.org", "+") """ + pass def chat_unset_outgoing_char(barejid): @@ -723,4 +732,68 @@ def chat_unset_outgoing_char(barejid): :: prof.chat_unset_outgoing_char("david@chat.org") """ + pass + +def room_set_titlebar_enctext(roomjid, enctext): + """Set the text to display in the titlebar encryption indicator for room. + + :param roomjid: Jabber ID of the room + :param enctext: The text to display + :type roomjid: str or unicode + :type enctext: str or unicode + :return: ``True`` if the text was set successfully, ``False`` otherwise + :rtype: boolean + + Example: + :: + prof.room_set_titlebar_enctext("generalchat@conference.service.com", "secret") + """ + pass + + +def room_unset_titlebar_enctext(roomjid): + """Let profanity decide what to show in the titlebar encryption indicator for room. + + :param roomjid: Jabber ID of the room + :type roomjid: str or unicode + :return: ``True`` if the text was unset successfully, ``False`` otherwise + :rtype: boolean + + Example: + :: + prof.room_unset_titlebar_enctext("generalchat@conference.service.com") + """ + pass + + +def room_set_message_char(roomjid, ch): + """Set the message prefix character for specified room. + + :param roomjid: Jabber ID of the room + :param enctext: The character to display + :type roomjid: str or unicode + :type enctext: str or unicode + :return: ``True`` if the character was set successfully, ``False`` otherwise + :rtype: boolean + + Example: + :: + prof.room_set_message_char("ohnoes@conference.chat.org", "^") + """ + pass + + +def room_unset_message_char(roomjid): + """Reset the message prefix character for specified room. + + :param roomjid: Jabber ID of the room + :type roomjid: str or unicode + :return: ``True`` if the char was unset successfully, ``False`` otherwise + :rtype: boolean + + Example: + :: + prof.room_unset_message_char("ohnoes@conference.chat.org") + """ + pass diff --git a/src/plugins/api.c b/src/plugins/api.c index d4109937..a1cbd35e 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -645,3 +645,83 @@ api_chat_unset_outgoing_char(const char *const barejid) return 1; } + +int +api_room_set_titlebar_enctext(const char *const roomjid, const char *const enctext) +{ + if (enctext == NULL) { + return 0; + } + + if (roomjid == NULL) { + return 0; + } + + ProfMucWin *mucwin = wins_get_muc(roomjid); + if (mucwin == NULL) { + return 0; + } + + mucwin_set_enctext(mucwin, enctext); + + return 1; +} + +int +api_room_unset_titlebar_enctext(const char *const roomjid) +{ + if (roomjid == NULL) { + return 0; + } + + ProfMucWin *mucwin = wins_get_muc(roomjid); + if (mucwin == NULL) { + return 0; + } + + mucwin_unset_enctext(mucwin); + + return 1; +} + +int +api_room_set_message_char(const char *const roomjid, const char *const ch) +{ + if (ch == NULL) { + return 0; + } + + if (strlen(ch) != 1) { + return 0; + } + + if (roomjid == NULL) { + return 0; + } + + ProfMucWin *mucwin = wins_get_muc(roomjid); + if (mucwin == NULL) { + return 0; + } + + mucwin_set_message_char(mucwin, ch); + + return 1; +} + +int +api_room_unset_message_char(const char *const roomjid) +{ + if (roomjid == NULL) { + return 0; + } + + ProfMucWin *mucwin = wins_get_muc(roomjid); + if (mucwin == NULL) { + return 0; + } + + mucwin_unset_message_char(mucwin); + + return 1; +} diff --git a/src/plugins/api.h b/src/plugins/api.h index 465365a0..75c159a3 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -104,5 +104,9 @@ 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); +int api_room_set_titlebar_enctext(const char *const roomjid, const char *const enctext); +int api_room_unset_titlebar_enctext(const char *const roomjid); +int api_room_set_message_char(const char *const roomjid, const char *const ch); +int api_room_unset_message_char(const char *const roomjid); #endif diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 6968657f..5cd23732 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -383,6 +383,30 @@ c_api_chat_unset_outgoing_char(const char *barejid) return api_chat_unset_outgoing_char(barejid); } +static int +c_api_room_set_titlebar_enctext(const char *roomjid, const char *enctext) +{ + return api_room_set_titlebar_enctext(roomjid, enctext); +} + +static int +c_api_room_unset_titlebar_enctext(const char *roomjid) +{ + return api_room_unset_titlebar_enctext(roomjid); +} + +static int +c_api_room_set_message_char(const char *roomjid, const char *ch) +{ + return api_room_set_message_char(roomjid, ch); +} + +static int +c_api_room_unset_message_char(const char *roomjid) +{ + return api_room_unset_message_char(roomjid); +} + void c_command_callback(PluginCommand *command, gchar **args) { @@ -457,6 +481,10 @@ c_api_init(void) 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; + prof_room_set_titlebar_enctext = c_api_room_set_titlebar_enctext; + prof_room_unset_titlebar_enctext = c_api_room_unset_titlebar_enctext; + prof_room_set_message_char = c_api_room_set_message_char; + prof_room_unset_message_char = c_api_room_unset_message_char; } static char * diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index c0085d64..e9d3cff6 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -101,3 +101,7 @@ 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; +int (*prof_room_set_titlebar_enctext)(const char *roomjid, const char *enctext) = NULL; +int (*prof_room_unset_titlebar_enctext)(const char *roomjid) = NULL; +int (*prof_room_set_message_char)(const char *roomjid, const char *ch) = NULL; +int (*prof_room_unset_message_char)(const char *roomjid) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index ac71293a..d17152fc 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -113,5 +113,9 @@ 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); +int (*prof_room_set_titlebar_enctext)(const char *roomjid, const char *enctext); +int (*prof_room_unset_titlebar_enctext)(const char *roomjid); +int (*prof_room_set_message_char)(const char *roomjid, const char *ch); +int (*prof_room_unset_message_char)(const char *roomjid); #endif diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index 4e6f4bb5..4e5bdfb5 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -1190,6 +1190,100 @@ python_api_chat_unset_outgoing_char(PyObject *self, PyObject *args) } } +static PyObject* +python_api_room_set_titlebar_enctext(PyObject *self, PyObject *args) +{ + PyObject *roomjid = NULL; + PyObject *enctext = NULL; + if (!PyArg_ParseTuple(args, "OO", &roomjid, &enctext)) { + Py_RETURN_NONE; + } + + char *roomjid_str = python_str_or_unicode_to_string(roomjid); + char *enctext_str = python_str_or_unicode_to_string(enctext); + + allow_python_threads(); + int res = api_room_set_titlebar_enctext(roomjid_str, enctext_str); + free(roomjid_str); + free(enctext_str); + disable_python_threads(); + + if (res) { + return Py_BuildValue("O", Py_True); + } else { + return Py_BuildValue("O", Py_False); + } +} + +static PyObject* +python_api_room_unset_titlebar_enctext(PyObject *self, PyObject *args) +{ + PyObject *roomjid = NULL; + if (!PyArg_ParseTuple(args, "O", &roomjid)) { + Py_RETURN_NONE; + } + + char *roomjid_str = python_str_or_unicode_to_string(roomjid); + + allow_python_threads(); + int res = api_room_unset_titlebar_enctext(roomjid_str); + free(roomjid_str); + disable_python_threads(); + + if (res) { + return Py_BuildValue("O", Py_True); + } else { + return Py_BuildValue("O", Py_False); + } +} + +static PyObject* +python_api_room_set_message_char(PyObject *self, PyObject *args) +{ + PyObject *roomjid = NULL; + PyObject *ch = NULL; + if (!PyArg_ParseTuple(args, "OO", &roomjid, &ch)) { + Py_RETURN_NONE; + } + + char *roomjid_str = python_str_or_unicode_to_string(roomjid); + char *ch_str = python_str_or_unicode_to_string(ch); + + allow_python_threads(); + int res = api_room_set_message_char(roomjid_str, ch_str); + free(roomjid_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_room_unset_message_char(PyObject *self, PyObject *args) +{ + PyObject *roomjid = NULL; + if (!PyArg_ParseTuple(args, "O", &roomjid)) { + Py_RETURN_NONE; + } + + char *roomjid_str = python_str_or_unicode_to_string(roomjid); + + allow_python_threads(); + int res = api_room_unset_message_char(roomjid_str); + free(roomjid_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) { @@ -1305,6 +1399,10 @@ static PyMethodDef apiMethods[] = { { "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" }, + { "room_set_titlebar_enctext", python_api_room_set_titlebar_enctext, METH_VARARGS, "Set the encryption status in the title bar for the specified room" }, + { "room_unset_titlebar_enctext", python_api_room_unset_titlebar_enctext, METH_VARARGS, "Reset the encryption status in the title bar for the specified room" }, + { "room_set_message_char", python_api_room_set_message_char, METH_VARARGS, "Set the message prefix character for specified room" }, + { "room_unset_message_char", python_api_room_unset_message_char, METH_VARARGS, "Reset the message prefix character for specified room" }, { NULL, NULL, 0, NULL } }; diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index 676e3aed..e532871c 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -478,18 +478,23 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes ProfWin *window = (ProfWin*)mucwin; char *mynick = muc_nick(mucwin->roomjid); + char ch = '-'; + if (mucwin->message_char) { + ch = mucwin->message_char[0]; + } + if (g_strcmp0(nick, mynick) != 0) { if (g_slist_length(mentions) > 0) { - win_print_them(window, THEME_ROOMMENTION, nick); + win_print_them(window, THEME_ROOMMENTION, ch, nick); _mucwin_print_mention(window, message, mynick, mentions); } else if (triggers) { - win_print_them(window, THEME_ROOMTRIGGER, nick); + win_print_them(window, THEME_ROOMTRIGGER, ch, nick); _mucwin_print_triggers(window, message, triggers); } else { - win_println_them_message(window, nick, "%s", message); + win_println_them_message(window, ch, nick, "%s", message); } } else { - win_println_me_message(window, mynick, "%s", message); + win_println_me_message(window, ch, mynick, "%s", message); } } @@ -860,3 +865,39 @@ mucwin_get_string(ProfMucWin *mucwin) return resstr; } + +void +mucwin_set_enctext(ProfMucWin *mucwin, const char *const enctext) +{ + if (mucwin->enctext) { + free(mucwin->enctext); + } + mucwin->enctext = strdup(enctext); +} + +void +mucwin_unset_enctext(ProfMucWin *mucwin) +{ + if (mucwin->enctext) { + free(mucwin->enctext); + mucwin->enctext = NULL; + } +} + +void +mucwin_set_message_char(ProfMucWin *mucwin, const char *const ch) +{ + if (mucwin->message_char) { + free(mucwin->message_char); + } + mucwin->message_char = strdup(ch); +} + +void +mucwin_unset_message_char(ProfMucWin *mucwin) +{ + if (mucwin->message_char) { + free(mucwin->message_char); + mucwin->message_char = NULL; + } +} diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 39624a0a..77360ec5 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -62,6 +62,7 @@ static void _title_bar_draw(void); static void _show_self_presence(void); static void _show_contact_presence(ProfChatWin *chatwin); static void _show_privacy(ProfChatWin *chatwin); +static void _show_muc_privacy(ProfMucWin *mucwin); void create_title_bar(void) @@ -202,6 +203,10 @@ _title_bar_draw(void) if (typing) { wprintw(win, " (typing...)"); } + } else if (current && current->type == WIN_MUC) { + ProfMucWin *mucwin = (ProfMucWin*) current; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + _show_muc_privacy(mucwin); } _show_self_presence(); @@ -310,6 +315,27 @@ _show_self_presence(void) } } +static void +_show_muc_privacy(ProfMucWin *mucwin) +{ + int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); + int encrypted_attrs = theme_attrs(THEME_TITLE_ENCRYPTED); + + if (mucwin->enctext) { + wprintw(win, " "); + wattron(win, bracket_attrs); + wprintw(win, "["); + wattroff(win, bracket_attrs); + wattron(win, encrypted_attrs); + wprintw(win, mucwin->enctext); + wattroff(win, encrypted_attrs); + wattron(win, bracket_attrs); + wprintw(win, "]"); + + return; + } +} + static void _show_privacy(ProfChatWin *chatwin) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 336e820b..608059de 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -193,6 +193,10 @@ void mucwin_role_list_error(ProfMucWin *mucwin, const char *const role, const ch void mucwin_handle_role_list(ProfMucWin *mucwin, const char *const role, GSList *nicks); void mucwin_kick_error(ProfMucWin *mucwin, const char *const nick, const char *const error); char* mucwin_get_string(ProfMucWin *mucwin); +void mucwin_set_enctext(ProfMucWin *mucwin, const char *const enctext); +void mucwin_unset_enctext(ProfMucWin *mucwin); +void mucwin_set_message_char(ProfMucWin *mucwin, const char *const ch); +void mucwin_unset_message_char(ProfMucWin *mucwin); // MUC private chat window void privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDateTime *timestamp); diff --git a/src/ui/win_types.h b/src/ui/win_types.h index b19822d5..462e177e 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -168,6 +168,8 @@ typedef struct prof_muc_win_t { gboolean unread_triggers; gboolean showjid; unsigned long memcheck; + char *enctext; + char *message_char; } ProfMucWin; typedef struct prof_mucconf_win_t { diff --git a/src/ui/window.c b/src/ui/window.c index 85e2b73f..6b8ae06e 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -194,6 +194,8 @@ win_create_muc(const char *const roomjid) } else { new_win->showjid = FALSE; } + new_win->enctext = NULL; + new_win->message_char = NULL; new_win->memcheck = PROFMUCWIN_MEMCHECK; @@ -443,6 +445,8 @@ win_free(ProfWin* window) { ProfMucWin *mucwin = (ProfMucWin*)window; free(mucwin->roomjid); + free(mucwin->enctext); + free(mucwin->message_char); break; } case WIN_MUC_CONFIG: @@ -1022,13 +1026,13 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp, } void -win_print_them(ProfWin *window, theme_item_t theme_item, const char *const them) +win_print_them(ProfWin *window, theme_item_t theme_item, char ch, const char *const them) { - _win_printf(window, '-', 0, NULL, NO_ME | NO_EOL, theme_item, them, ""); + _win_printf(window, ch, 0, NULL, NO_ME | NO_EOL, theme_item, them, ""); } void -win_println_them_message(ProfWin *window, const char *const them, const char *const message, ...) +win_println_them_message(ProfWin *window, char ch, const char *const them, const char *const message, ...) { GDateTime *timestamp = g_date_time_new_now_local(); @@ -1037,9 +1041,9 @@ win_println_them_message(ProfWin *window, const char *const them, const char *co GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_append(window->layout->buffer, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL); + buffer_append(window->layout->buffer, ch, 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL); - _win_print(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL); + _win_print(window, ch, 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL); inp_nonblocking(TRUE); g_date_time_unref(timestamp); @@ -1048,7 +1052,7 @@ win_println_them_message(ProfWin *window, const char *const them, const char *co } void -win_println_me_message(ProfWin *window, const char *const me, const char *const message, ...) +win_println_me_message(ProfWin *window, char ch, const char *const me, const char *const message, ...) { GDateTime *timestamp = g_date_time_new_now_local(); @@ -1057,9 +1061,9 @@ win_println_me_message(ProfWin *window, const char *const me, const char *const GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_append(window->layout->buffer, '-', 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL); + buffer_append(window->layout->buffer, ch, 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL); - _win_print(window, '-', 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL); + _win_print(window, ch, 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL); inp_nonblocking(TRUE); g_date_time_unref(timestamp); diff --git a/src/ui/window.h b/src/ui/window.h index 21c9154a..31ccd7e3 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -60,9 +60,9 @@ void win_show_status_string(ProfWin *window, const char *const from, GDateTime *last_activity, const char *const pre, const char *const default_show); -void win_print_them(ProfWin *window, theme_item_t theme_item, const char *const them); -void win_println_them_message(ProfWin *window, const char *const them, const char *const message, ...); -void win_println_me_message(ProfWin *window, const char *const me, const char *const message, ...); +void win_print_them(ProfWin *window, theme_item_t theme_item, char ch, const char *const them); +void win_println_them_message(ProfWin *window, char ch, const char *const them, const char *const message, ...); +void win_println_me_message(ProfWin *window, char ch, const char *const me, const char *const message, ...); void win_print_outgoing(ProfWin *window, const char ch, const char *const message, ...); void win_print_incoming(ProfWin *window, GDateTime *timestamp, diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 9ca9ab5e..7452e581 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -219,6 +219,11 @@ void mucwin_occupant_presence(ProfMucWin *mucwin, const char * const nick, const void mucwin_update_occupants(ProfMucWin *mucwin) {} void mucwin_show_occupants(ProfMucWin *mucwin) {} void mucwin_hide_occupants(ProfMucWin *mucwin) {} +void mucwin_set_enctext(ProfMucWin *mucwin, const char *const enctext) {} +void mucwin_unset_enctext(ProfMucWin *mucwin) {} +void mucwin_set_message_char(ProfMucWin *mucwin, const char *const ch) {} +void mucwin_unset_message_char(ProfMucWin *mucwin) {} + void ui_show_roster(void) {} void ui_hide_roster(void) {} void ui_roster_add(const char * const barejid, const char * const name) {}