1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Add titlebar encryption text to plugins api

This commit is contained in:
James Booth 2017-01-19 22:33:29 +00:00
parent 68496db0b4
commit 1b25aa84cb
14 changed files with 219 additions and 14 deletions

View File

@ -339,3 +339,19 @@ End any encrypted session with the specified user.
@param barejid Jabber ID of the recipient @param barejid Jabber ID of the recipient
*/ */
void prof_encryption_reset(char *barejid); void prof_encryption_reset(char *barejid);
/**
Set the text to display in the titlebar encryption indicator.
@param barejid Jabber ID of the recipient
@param enctext The text to display
@return 1 on success, 0 on failure
*/
int prof_chat_set_titlebar_enctext(char *barejid, char *enctext);
/**
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);

View File

@ -630,3 +630,35 @@ def encryption_reset(barejid):
:: ::
prof.encryption_reset("alice@server.org") prof.encryption_reset("alice@server.org")
""" """
def chat_set_titlebar_enctext(barejid, enctext):
"""Set the text to display in the titlebar encryption indicator.
:param barejid: Jabber ID of the recipient
:param enctext: The text to display
:type barejid: str or unicode
:type enctext: str or unicode
:return: ``True`` if the text was set successfully, ``False`` otherwise
:rtype: boolean
Example:
::
prof.chat_set_titlebar_enctext("bob@chat.org", "safe")
"""
def chat_unset_titlebar_enctext(barejid):
"""Let profanity decide what to show in the titlebar encryption indicator.
:param barejid: Jabber ID of the recipient
:type barejid: str or unicode
:return: ``True`` if the text was unset successfully, ``False`` otherwise
:rtype: boolean
Example:
::
prof.chat_unset_titlebar_enctext("bob@chat.org")
"""

View File

@ -523,3 +523,41 @@ api_encryption_reset(const char *const barejid)
} }
#endif #endif
} }
int
api_chat_set_titlebar_enctext(const char *const barejid, const char *const enctext)
{
if (enctext == NULL) {
return 0;
}
if (barejid == NULL) {
return 0;
}
ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin == NULL) {
return 0;
}
chatwin_set_enctext(chatwin, enctext);
return 1;
}
int
api_chat_unset_titlebar_enctext(const char *const barejid)
{
if (barejid == NULL) {
return 0;
}
ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin == NULL) {
return 0;
}
chatwin_unset_enctext(chatwin);
return 1;
}

View File

@ -98,4 +98,7 @@ void api_disco_add_feature(char *plugin_name, char *feature);
void api_encryption_reset(const char *const barejid); 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);
#endif #endif

View File

@ -347,6 +347,18 @@ c_api_encryption_reset(const char *barejid)
api_encryption_reset(barejid); api_encryption_reset(barejid);
} }
static int
c_api_chat_set_titlebar_enctext(const char *barejid, const char *enctext)
{
return api_chat_set_titlebar_enctext(barejid, enctext);
}
static int
c_api_chat_unset_titlebar_enctext(const char *barejid)
{
return api_chat_unset_titlebar_enctext(barejid);
}
void void
c_command_callback(PluginCommand *command, gchar **args) c_command_callback(PluginCommand *command, gchar **args)
{ {
@ -415,6 +427,8 @@ c_api_init(void)
prof_incoming_message = c_api_incoming_message; prof_incoming_message = c_api_incoming_message;
_prof_disco_add_feature = c_api_disco_add_feature; _prof_disco_add_feature = c_api_disco_add_feature;
prof_encryption_reset = c_api_encryption_reset; 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;
} }
static char * static char *

View File

@ -94,3 +94,7 @@ void (*prof_incoming_message)(char *barejid, char *resource, char *message) = NU
void (*_prof_disco_add_feature)(const char *filename, char *feature) = NULL; void (*_prof_disco_add_feature)(const char *filename, char *feature) = NULL;
void (*prof_encryption_reset)(const char *barejid) = NULL; 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;

View File

@ -107,4 +107,7 @@ void (*_prof_disco_add_feature)(const char *filename, char *feature);
void (*prof_encryption_reset)(const char *barejid); 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);
#endif #endif

View File

@ -1049,6 +1049,53 @@ python_api_encryption_reset(PyObject *self, PyObject *args)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject*
python_api_chat_set_titlebar_enctext(PyObject *self, PyObject *args)
{
PyObject *barejid = NULL;
PyObject *enctext = NULL;
if (!PyArg_ParseTuple(args, "OO", &barejid, &enctext)) {
Py_RETURN_NONE;
}
char *barejid_str = python_str_or_unicode_to_string(barejid);
char *enctext_str = python_str_or_unicode_to_string(enctext);
allow_python_threads();
int res = api_chat_set_titlebar_enctext(barejid_str, enctext_str);
free(barejid_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_chat_unset_titlebar_enctext(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_titlebar_enctext(barejid_str);
free(barejid_str);
disable_python_threads();
if (res) {
return Py_BuildValue("O", Py_True);
} else {
return Py_BuildValue("O", Py_False);
}
}
void void
python_command_callback(PluginCommand *command, gchar **args) python_command_callback(PluginCommand *command, gchar **args)
{ {
@ -1158,6 +1205,8 @@ static PyMethodDef apiMethods[] = {
{ "incoming_message", python_api_incoming_message, METH_VARARGS, "Show an incoming message." }, { "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." }, { "disco_add_feature", python_api_disco_add_feature, METH_VARARGS, "Add a feature to disco info response." },
{ "encryption_reset", python_api_encryption_reset, METH_VARARGS, "End encrypted chat session with barejid, if one exists" }, { "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" },
{ NULL, NULL, 0, NULL } { NULL, NULL, 0, NULL }
}; };

View File

@ -385,6 +385,24 @@ chatwin_get_string(ProfChatWin *chatwin)
return resstr; return resstr;
} }
void
chatwin_set_enctext(ProfChatWin *chatwin, const char *const enctext)
{
if (chatwin->enctext) {
free(chatwin->enctext);
}
chatwin->enctext = strdup(enctext);
}
void
chatwin_unset_enctext(ProfChatWin *chatwin)
{
if (chatwin->enctext) {
free(chatwin->enctext);
chatwin->enctext = NULL;
}
}
static void static void
_chatwin_history(ProfChatWin *chatwin, const char *const contact) _chatwin_history(ProfChatWin *chatwin, const char *const contact)
{ {

View File

@ -319,6 +319,20 @@ _show_privacy(ProfChatWin *chatwin)
int trusted_attrs = theme_attrs(THEME_TITLE_TRUSTED); int trusted_attrs = theme_attrs(THEME_TITLE_TRUSTED);
int untrusted_attrs = theme_attrs(THEME_TITLE_UNTRUSTED); int untrusted_attrs = theme_attrs(THEME_TITLE_UNTRUSTED);
if (chatwin->enctext) {
wprintw(win, " ");
wattron(win, bracket_attrs);
wprintw(win, "[");
wattroff(win, bracket_attrs);
wattron(win, encrypted_attrs);
wprintw(win, chatwin->enctext);
wattroff(win, encrypted_attrs);
wattron(win, bracket_attrs);
wprintw(win, "]");
return;
}
if (chatwin->is_otr) { if (chatwin->is_otr) {
wprintw(win, " "); wprintw(win, " ");
wattron(win, bracket_attrs); wattron(win, bracket_attrs);
@ -353,7 +367,11 @@ _show_privacy(ProfChatWin *chatwin)
wprintw(win, "]"); wprintw(win, "]");
wattroff(win, bracket_attrs); wattroff(win, bracket_attrs);
} }
} else if (chatwin->pgp_send || chatwin->pgp_recv) {
return;
}
if (chatwin->pgp_send || chatwin->pgp_recv) {
GString *pgpmsg = g_string_new("PGP "); GString *pgpmsg = g_string_new("PGP ");
if (chatwin->pgp_send && !chatwin->pgp_recv) { if (chatwin->pgp_send && !chatwin->pgp_recv) {
g_string_append(pgpmsg, "send"); g_string_append(pgpmsg, "send");
@ -373,7 +391,10 @@ _show_privacy(ProfChatWin *chatwin)
wprintw(win, "]"); wprintw(win, "]");
wattroff(win, bracket_attrs); wattroff(win, bracket_attrs);
g_string_free(pgpmsg, TRUE); g_string_free(pgpmsg, TRUE);
} else {
return;
}
if (prefs_get_boolean(PREF_ENC_WARN)) { if (prefs_get_boolean(PREF_ENC_WARN)) {
wprintw(win, " "); wprintw(win, " ");
wattron(win, bracket_attrs); wattron(win, bracket_attrs);
@ -386,7 +407,6 @@ _show_privacy(ProfChatWin *chatwin)
wprintw(win, "]"); wprintw(win, "]");
wattroff(win, bracket_attrs); wattroff(win, bracket_attrs);
} }
}
} }
static void static void

View File

@ -140,6 +140,8 @@ void chatwin_otr_trust(ProfChatWin *chatwin);
void chatwin_otr_untrust(ProfChatWin *chatwin); void chatwin_otr_untrust(ProfChatWin *chatwin);
void chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, void *data); void chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, void *data);
#endif #endif
void chatwin_set_enctext(ProfChatWin *chatwin, const char *const enctext);
void chatwin_unset_enctext(ProfChatWin *chatwin);
// MUC window // MUC window
void mucwin_role_change(ProfMucWin *mucwin, const char *const role, const char *const actor, const char *const reason); void mucwin_role_change(ProfMucWin *mucwin, const char *const role, const char *const actor, const char *const reason);

View File

@ -155,6 +155,7 @@ typedef struct prof_chat_win_t {
char *resource_override; char *resource_override;
gboolean history_shown; gboolean history_shown;
unsigned long memcheck; unsigned long memcheck;
char *enctext;
} ProfChatWin; } ProfChatWin;
typedef struct prof_muc_win_t { typedef struct prof_muc_win_t {

View File

@ -146,6 +146,7 @@ win_create_chat(const char *const barejid)
new_win->history_shown = FALSE; new_win->history_shown = FALSE;
new_win->unread = 0; new_win->unread = 0;
new_win->state = chat_state_new(); new_win->state = chat_state_new();
new_win->enctext = NULL;
new_win->memcheck = PROFCHATWIN_MEMCHECK; new_win->memcheck = PROFCHATWIN_MEMCHECK;
@ -430,6 +431,7 @@ win_free(ProfWin* window)
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
free(chatwin->barejid); free(chatwin->barejid);
free(chatwin->resource_override); free(chatwin->resource_override);
free(chatwin->enctext);
chat_state_free(chatwin->state); chat_state_free(chatwin->state);
break; break;
} }

View File

@ -67,6 +67,9 @@ void chatwin_otr_untrust(ProfChatWin *chatwin) {}
void chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, void *data) {} void chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, void *data) {}
#endif #endif
void chatwin_set_enctext(ProfChatWin *chatwin, const char *const enctext) {}
void chatwin_unset_enctext(ProfChatWin *chatwin) {}
void ui_sigwinch_handler(int sig) {} void ui_sigwinch_handler(int sig) {}
unsigned long ui_get_idle_time(void) unsigned long ui_get_idle_time(void)