aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ui/mucwin.c24
-rw-r--r--src/ui/ui.h6
-rw-r--r--src/ui/window.c126
-rw-r--r--src/ui/window.h4
4 files changed, 126 insertions, 34 deletions
diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c
index 6d1891d4..676e3aed 100644
--- a/src/ui/mucwin.c
+++ b/src/ui/mucwin.c
@@ -370,10 +370,10 @@ _mucwin_print_mention(ProfWin *window, const char *const message, const char *co
pos = GPOINTER_TO_INT(curr->data);
char *before_str = g_strndup(message + last_pos, pos - last_pos);
- win_printf(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION, "", "%s", before_str);
+ win_append_highlight(window, THEME_ROOMMENTION, "%s", before_str);
g_free(before_str);
char *nick_str = g_strndup(message + pos, strlen(nick));
- win_printf(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION_TERM, "", "%s", nick_str);
+ win_append_highlight(window, THEME_ROOMMENTION_TERM, "%s", nick_str);
g_free(nick_str);
last_pos = pos + strlen(nick);
@@ -381,9 +381,9 @@ _mucwin_print_mention(ProfWin *window, const char *const message, const char *co
curr = g_slist_next(curr);
}
if (last_pos < strlen(message)) {
- win_printf(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMMENTION, "", "%s", &message[last_pos]);
+ win_appendln_highlight(window, THEME_ROOMMENTION, "%s", &message[last_pos]);
} else {
- win_printf(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMMENTION, "", "");
+ win_appendln_highlight(window, THEME_ROOMMENTION, "");
}
}
@@ -441,7 +441,7 @@ _mucwin_print_triggers(ProfWin *window, const char *const message, GList *trigge
// no triggers found
if (first_trigger_pos == -1) {
- win_printf(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMTRIGGER, "", "%s", message);
+ win_appendln_highlight(window, THEME_ROOMTRIGGER, "%s", message);
} else {
if (first_trigger_pos > 0) {
char message_section[strlen(message) + 1];
@@ -451,7 +451,7 @@ _mucwin_print_triggers(ProfWin *window, const char *const message, GList *trigge
i++;
}
message_section[i] = '\0';
- win_printf(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMTRIGGER, "", "%s", message_section);
+ win_append_highlight(window, THEME_ROOMTRIGGER, "%s", message_section);
}
char trigger_section[first_trigger_len + 1];
int i = 0;
@@ -462,10 +462,10 @@ _mucwin_print_triggers(ProfWin *window, const char *const message, GList *trigge
trigger_section[i] = '\0';
if (first_trigger_pos + first_trigger_len < strlen(message)) {
- win_printf(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMTRIGGER_TERM, "", "%s", trigger_section);
+ win_append_highlight(window, THEME_ROOMTRIGGER_TERM, "%s", trigger_section);
_mucwin_print_triggers(window, &message[first_trigger_pos + first_trigger_len], triggers);
} else {
- win_printf(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMTRIGGER_TERM, "", "%s", trigger_section);
+ win_appendln_highlight(window, THEME_ROOMTRIGGER_TERM, "%s", trigger_section);
}
}
}
@@ -480,16 +480,16 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes
if (g_strcmp0(nick, mynick) != 0) {
if (g_slist_length(mentions) > 0) {
- win_printf(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMMENTION, nick, "");
+ win_print_them(window, THEME_ROOMMENTION, nick);
_mucwin_print_mention(window, message, mynick, mentions);
} else if (triggers) {
- win_printf(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMTRIGGER, nick, "");
+ win_print_them(window, THEME_ROOMTRIGGER, nick);
_mucwin_print_triggers(window, message, triggers);
} else {
- win_printf(window, '-', 0, NULL, NO_ME, THEME_TEXT_THEM, nick, "%s", message);
+ win_println_them_message(window, nick, "%s", message);
}
} else {
- win_printf(window, '-', 0, NULL, 0, THEME_TEXT_ME, nick, "%s", message);
+ win_println_me_message(window, mynick, "%s", message);
}
}
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 6fb97b3e..55f21eea 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -356,9 +356,6 @@ void win_show_subwin(ProfWin *window);
void win_refresh_without_subwin(ProfWin *window);
void win_refresh_with_subwin(ProfWin *window);
-void win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp, int flags,
- theme_item_t theme_item, const char *const from, const char *const message, ...);
-
void win_print(ProfWin *window, theme_item_t theme_item, const char ch, const char *const message, ...);
void win_println(ProfWin *window, theme_item_t theme_item, const char ch, const char *const message, ...);
void win_println_indent(ProfWin *window, int pad, const char *const message, ...);
@@ -366,6 +363,9 @@ void win_println_indent(ProfWin *window, int pad, const char *const message, ...
void win_append(ProfWin *window, theme_item_t theme_item, const char *const message, ...);
void win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message, ...);
+void win_append_highlight(ProfWin *window, theme_item_t theme_item, const char *const message, ...);
+void win_appendln_highlight(ProfWin *window, theme_item_t theme_item, const char *const message, ...);
+
char* win_get_title(ProfWin *window);
void win_show_occupant(ProfWin *window, Occupant *occupant);
void win_show_occupant_info(ProfWin *window, const char *const room, Occupant *occupant);
diff --git a/src/ui/window.c b/src/ui/window.c
index 6630c60b..71a4f3ae 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -61,6 +61,8 @@
#define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X))
+static void _win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp,
+ int flags, theme_item_t theme_item, const char *const from, const char *const message, ...);
static void _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *time,
int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt);
static void _win_print_wrapped(WINDOW *win, const char *const message, size_t indent, int pad_indent);
@@ -997,10 +999,10 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp,
} 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);
+ _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);
+ _win_printf(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, from, "%s", message);
break;
default:
assert(FALSE);
@@ -1009,7 +1011,13 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp,
}
void
-win_print_outgoing(ProfWin *window, const char ch, const char *const message, ...)
+win_print_them(ProfWin *window, theme_item_t theme_item, const char *const them)
+{
+ _win_printf(window, '-', 0, NULL, NO_ME | NO_EOL, theme_item, them, "");
+}
+
+void
+win_println_them_message(ProfWin *window, const char *const them, const char *const message, ...)
{
GDateTime *timestamp = g_date_time_new_now_local();
@@ -1018,9 +1026,9 @@ win_print_outgoing(ProfWin *window, const char ch, const char *const message, ..
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
- buffer_push(window->layout->buffer, ch, 0, timestamp, 0, THEME_TEXT_ME, "me", fmt_msg->str, NULL);
+ buffer_push(window->layout->buffer, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL);
- _win_print(window, ch, 0, timestamp, 0, THEME_TEXT_ME, "me", fmt_msg->str, NULL);
+ _win_print(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(timestamp);
@@ -1029,18 +1037,18 @@ win_print_outgoing(ProfWin *window, const char ch, const char *const message, ..
}
void
-win_print_history(ProfWin *window, GDateTime *timestamp, const char *const message, ...)
+win_println_me_message(ProfWin *window, const char *const me, const char *const message, ...)
{
- g_date_time_ref(timestamp);
+ GDateTime *timestamp = g_date_time_new_now_local();
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
- buffer_push(window->layout->buffer, '-', 0, timestamp, NO_COLOUR_DATE, THEME_DEFAULT, "", fmt_msg->str, NULL);
+ buffer_push(window->layout->buffer, '-', 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL);
- _win_print(window, '-', 0, timestamp, NO_COLOUR_DATE, THEME_DEFAULT, "", fmt_msg->str, NULL);
+ _win_print(window, '-', 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(timestamp);
@@ -1049,23 +1057,38 @@ win_print_history(ProfWin *window, GDateTime *timestamp, const char *const messa
}
void
-win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp,
- int flags, theme_item_t theme_item, const char *const from, const char *const message, ...)
+win_print_outgoing(ProfWin *window, const char ch, const char *const message, ...)
{
- if (timestamp == NULL) {
- timestamp = g_date_time_new_now_local();
- } else {
- g_date_time_ref(timestamp);
- }
+ GDateTime *timestamp = g_date_time_new_now_local();
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
- buffer_push(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL);
+ buffer_push(window->layout->buffer, ch, 0, timestamp, 0, THEME_TEXT_ME, "me", fmt_msg->str, NULL);
- _win_print(window, show_char, pad_indent, timestamp, flags, theme_item, from, 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);
+
+ g_string_free(fmt_msg, TRUE);
+ va_end(arg);
+}
+
+void
+win_print_history(ProfWin *window, GDateTime *timestamp, const char *const message, ...)
+{
+ g_date_time_ref(timestamp);
+
+ va_list arg;
+ va_start(arg, message);
+ GString *fmt_msg = g_string_new(NULL);
+ g_string_vprintf(fmt_msg, message, arg);
+
+ buffer_push(window->layout->buffer, '-', 0, timestamp, NO_COLOUR_DATE, THEME_DEFAULT, "", fmt_msg->str, NULL);
+
+ _win_print(window, '-', 0, timestamp, NO_COLOUR_DATE, THEME_DEFAULT, "", fmt_msg->str, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(timestamp);
@@ -1163,7 +1186,7 @@ win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
- buffer_push(window->layout->buffer, '-', 0, timestamp, NO_EOL, theme_item, "", fmt_msg->str, NULL);
+ buffer_push(window->layout->buffer, '-', 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL);
_win_print(window, '-', 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL);
inp_nonblocking(TRUE);
@@ -1174,6 +1197,46 @@ win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message
}
void
+win_append_highlight(ProfWin *window, theme_item_t theme_item, const char *const message, ...)
+{
+ GDateTime *timestamp = g_date_time_new_now_local();
+
+ va_list arg;
+ va_start(arg, message);
+ GString *fmt_msg = g_string_new(NULL);
+ g_string_vprintf(fmt_msg, message, arg);
+
+ buffer_push(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL);
+
+ _win_print(window, '-', 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL);
+ inp_nonblocking(TRUE);
+ g_date_time_unref(timestamp);
+
+ g_string_free(fmt_msg, TRUE);
+ va_end(arg);
+}
+
+void
+win_appendln_highlight(ProfWin *window, theme_item_t theme_item, const char *const message, ...)
+{
+ GDateTime *timestamp = g_date_time_new_now_local();
+
+ va_list arg;
+ va_start(arg, message);
+ GString *fmt_msg = g_string_new(NULL);
+ g_string_vprintf(fmt_msg, message, arg);
+
+ buffer_push(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL);
+
+ _win_print(window, '-', 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL);
+ inp_nonblocking(TRUE);
+ g_date_time_unref(timestamp);
+
+ g_string_free(fmt_msg, TRUE);
+ va_end(arg);
+}
+
+void
win_print_http_upload(ProfWin *window, const char *const message, char *url)
{
win_print_with_receipt(window, '!', NULL, message, url);
@@ -1233,6 +1296,31 @@ win_newline(ProfWin *window)
}
static void
+_win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp,
+ int flags, theme_item_t theme_item, const char *const from, const char *const message, ...)
+{
+ if (timestamp == NULL) {
+ timestamp = g_date_time_new_now_local();
+ } else {
+ g_date_time_ref(timestamp);
+ }
+
+ va_list arg;
+ va_start(arg, message);
+ GString *fmt_msg = g_string_new(NULL);
+ g_string_vprintf(fmt_msg, message, arg);
+
+ buffer_push(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL);
+
+ _win_print(window, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL);
+ inp_nonblocking(TRUE);
+ g_date_time_unref(timestamp);
+
+ g_string_free(fmt_msg, TRUE);
+ va_end(arg);
+}
+
+static void
_win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *time,
int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt)
{
diff --git a/src/ui/window.h b/src/ui/window.h
index cdc18dfe..e29cd62f 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -60,6 +60,10 @@ 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_outgoing(ProfWin *window, const char ch, const char *const message, ...);
void win_print_incoming(ProfWin *window, GDateTime *timestamp,
const char *const from, const char *const message, prof_enc_t enc_mode);