diff options
-rw-r--r-- | src/ui/core.c | 23 | ||||
-rw-r--r-- | src/ui/window.c | 51 | ||||
-rw-r--r-- | src/ui/window.h | 2 |
3 files changed, 54 insertions, 22 deletions
diff --git a/src/ui/core.c b/src/ui/core.c index 8e84274f..1fac0dc3 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -279,28 +279,7 @@ ui_incoming_msg(const char * const from, const char * const message, // currently viewing chat window with sender if (wins_is_current(window)) { - if (tv_stamp == NULL) { - window->print_time(window, '-'); - } else { - GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp); - gchar *date_fmt = g_date_time_format(time, "%H:%M:%S"); - wattron(window->win, COLOUR_TIME); - wprintw(window->win, "%s - ", date_fmt); - wattroff(window->win, COLOUR_TIME); - g_date_time_unref(time); - g_free(date_fmt); - } - - if (strncmp(message, "/me ", 4) == 0) { - wattron(window->win, COLOUR_THEM); - wprintw(window->win, "*%s ", display_from); - waddstr(window->win, message + 4); - wprintw(window->win, "\n"); - wattroff(window->win, COLOUR_THEM); - } else { - _win_show_user(window->win, display_from, 1); - _win_show_message(window->win, message); - } + window->print_incoming_message(window, tv_stamp, display_from, message); title_bar_set_typing(FALSE); title_bar_draw(); status_bar_active(num); diff --git a/src/ui/window.c b/src/ui/window.c index 3ba49fff..fa881df0 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -42,6 +42,8 @@ static void _win_print_time(ProfWin *self, char show_char); static void _win_presence_colour_on(ProfWin *self, const char * const presence); static void _win_presence_colour_off(ProfWin *self, const char * const presence); static void _win_show_contact(ProfWin *self, PContact contact); +static void _print_incoming_message(ProfWin *self, GTimeVal *tv_stamp, + const char * const from, const char * const message); ProfWin* win_create(const char * const title, int cols, win_type_t type) @@ -65,11 +67,29 @@ win_create(const char * const title, int cols, win_type_t type) switch (new_win->type) { + case WIN_CONSOLE: + new_win->handle_error_message = _default_handle_error_message; + new_win->print_incoming_message = NULL; + break; + case WIN_CHAT: + new_win->handle_error_message = _default_handle_error_message; + new_win->print_incoming_message = _print_incoming_message; + break; case WIN_MUC: new_win->handle_error_message = muc_handle_error_message; + new_win->print_incoming_message = NULL; + break; + case WIN_PRIVATE: + new_win->handle_error_message = _default_handle_error_message; + new_win->print_incoming_message = _print_incoming_message; + break; + case WIN_DUCK: + new_win->handle_error_message = _default_handle_error_message; + new_win->print_incoming_message = NULL; break; default: new_win->handle_error_message = _default_handle_error_message; + new_win->print_incoming_message = NULL; break; } @@ -213,3 +233,34 @@ _default_handle_error_message(ProfWin *self, const char * const from, { return FALSE; } + +static void +_print_incoming_message(ProfWin *self, GTimeVal *tv_stamp, + const char * const from, const char * const message) +{ + if (tv_stamp == NULL) { + self->print_time(self, '-'); + } else { + GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp); + gchar *date_fmt = g_date_time_format(time, "%H:%M:%S"); + wattron(self->win, COLOUR_TIME); + wprintw(self->win, "%s - ", date_fmt); + wattroff(self->win, COLOUR_TIME); + g_date_time_unref(time); + g_free(date_fmt); + } + + if (strncmp(message, "/me ", 4) == 0) { + wattron(self->win, COLOUR_THEM); + wprintw(self->win, "*%s ", from); + waddstr(self->win, message + 4); + wprintw(self->win, "\n"); + wattroff(self->win, COLOUR_THEM); + } else { + wattron(self->win, COLOUR_THEM); + wprintw(self->win, "%s: ", from); + wattroff(self->win, COLOUR_THEM); + waddstr(self->win, message); + wprintw(self->win, "\n"); + } +} diff --git a/src/ui/window.h b/src/ui/window.h index 9be3a7fd..ccf68dab 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -61,6 +61,8 @@ typedef struct prof_win_t { void (*show_contact)(struct prof_win_t *self, PContact contact); gboolean (*handle_error_message)(struct prof_win_t *self, const char * const from, const char * const err_msg); + void (*print_incoming_message)(struct prof_win_t *self, GTimeVal *tv_stamp, + const char * const from, const char * const message); } ProfWin; ProfWin* win_create(const char * const title, int cols, win_type_t type); |