about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/api.c84
-rw-r--r--src/plugins/api.h4
-rw-r--r--src/plugins/c_api.c28
-rw-r--r--src/plugins/profapi.c5
-rw-r--r--src/plugins/profapi.h4
-rw-r--r--src/plugins/python_api.c98
-rw-r--r--src/ui/chatwin.c40
-rw-r--r--src/ui/ui.h4
-rw-r--r--src/ui/win_types.h2
-rw-r--r--src/ui/window.c11
10 files changed, 277 insertions, 3 deletions
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;