diff options
author | James Booth <boothj5@gmail.com> | 2014-01-08 20:50:00 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-01-08 20:50:00 +0000 |
commit | 49deb932e6b9f835ed44afa9d49fe30f84979027 (patch) | |
tree | 0c4a6cd308eb415a91966afcd6cc32da8cd7de71 | |
parent | 0776c574b6b75781547a475a7a420b5b6266d57f (diff) | |
parent | 4cc4461c0fbf310a329bdc78338c497716073fca (diff) | |
download | profani-tty-49deb932e6b9f835ed44afa9d49fe30f84979027.tar.gz |
Merge branch 'master' into otr
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | src/ui/core.c | 6 | ||||
-rw-r--r-- | src/ui/muc_window.c | 39 | ||||
-rw-r--r-- | src/ui/muc_window.h | 33 | ||||
-rw-r--r-- | src/ui/window.c | 117 | ||||
-rw-r--r-- | src/ui/window.h | 9 |
7 files changed, 76 insertions, 130 deletions
diff --git a/.gitignore b/.gitignore index f5e02c37..2050cb77 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ libprofanity.la libtool runvalgrind.sh src/prof_config.h +clean.sh diff --git a/Makefile.am b/Makefile.am index c9e4d9db..17cf94dd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,6 @@ core_sources = \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/console.c src/ui/notifier.c \ src/ui/windows.c src/ui/windows.h \ - src/ui/muc_window.c src/ui/muc_window.h \ src/command/command.h src/command/command.c src/command/history.c \ src/command/commands.h src/command/commands.c \ src/command/history.h src/tools/parser.c \ diff --git a/src/ui/core.c b/src/ui/core.c index c06f025e..afda184a 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -252,7 +252,7 @@ _ui_incoming_msg(const char * const from, const char * const message, // currently viewing chat window with sender if (wins_is_current(window)) { - window->print_incoming_message(window, tv_stamp, display_from, message); + win_print_incoming_message(window, tv_stamp, display_from, message); title_bar_set_typing(FALSE); title_bar_draw(); status_bar_active(num); @@ -278,7 +278,7 @@ _ui_incoming_msg(const char * const from, const char * const message, } } - window->print_incoming_message(window, tv_stamp, display_from, message); + win_print_incoming_message(window, tv_stamp, display_from, message); } int ui_index = num; @@ -341,7 +341,7 @@ _ui_handle_error_message(const char * const from, const char * const err_msg) cons_show_error("Unknown error received from service."); } else { ProfWin *current = wins_get_current(); - gboolean handled = current->handle_error_message(current, from, err_msg); + gboolean handled = win_handle_error_message(current, from, err_msg); if (handled != TRUE) { cons_show_error("Error received from server: %s", err_msg); } diff --git a/src/ui/muc_window.c b/src/ui/muc_window.c deleted file mode 100644 index 72382032..00000000 --- a/src/ui/muc_window.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * muc_window.c - * - * Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com> - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#include <glib.h> - -#include "ui/window.h" - -gboolean -muc_handle_error_message(ProfWin *self, const char * const from, - const char * const err_msg) -{ - gboolean handled = FALSE; - if (g_strcmp0(err_msg, "conflict") == 0) { - win_print_line(self, '-', 0, "Nickname already in use."); - win_refresh(self); - handled = TRUE; - } - - return handled; -} diff --git a/src/ui/muc_window.h b/src/ui/muc_window.h deleted file mode 100644 index 0b1f13ab..00000000 --- a/src/ui/muc_window.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * muc_window.h - * - * Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com> - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef UI_MUC_WINDOW_H -#define UI_MUC_WINDOW_H - -#include <glib.h> - -#include "ui/window.h" - -gboolean muc_handle_error_message(ProfWin *self, const char * const from, - const char * const err_msg); - -#endif diff --git a/src/ui/window.c b/src/ui/window.c index 135eac17..daf9bef0 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -24,6 +24,7 @@ #include <stdlib.h> #include <string.h> +#include <assert.h> #include <glib.h> #ifdef HAVE_NCURSESW_NCURSES_H @@ -34,12 +35,12 @@ #include "config/theme.h" #include "ui/window.h" -#include "ui/muc_window.h" -static gboolean _default_handle_error_message(ProfWin *self, const char * const from, - const char * const err_msg); -static void _print_incoming_message(ProfWin *self, GTimeVal *tv_stamp, +static void _win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, const char * const from, const char * const message); +static gboolean +_muc_handle_error_message(ProfWin *window, const char * const from, + const char * const err_msg); ProfWin* win_create(const char * const title, int cols, win_type_t type) @@ -53,35 +54,6 @@ win_create(const char * const title, int cols, win_type_t type) new_win->unread = 0; new_win->history_shown = 0; new_win->type = 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; - } - scrollok(new_win->win, TRUE); return new_win; @@ -314,40 +286,85 @@ win_show_status_string(ProfWin *window, const char * const from, } } +void +win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, + const char * const from, const char * const message) +{ + switch (window->type) + { + case WIN_CHAT: + case WIN_PRIVATE: + _win_chat_print_incoming_message(window, tv_stamp, from, message); + break; + default: + assert(FALSE); + break; + } +} + +gboolean +win_handle_error_message(ProfWin *window, const char * const from, + const char * const err_msg) +{ + gboolean handled = FALSE; + switch (window->type) + { + case WIN_CHAT: + case WIN_PRIVATE: + case WIN_DUCK: + case WIN_CONSOLE: + handled = FALSE; + case WIN_MUC: + handled = _muc_handle_error_message(window, from, err_msg); + default: + assert(FALSE); + break; + } + + return handled; +} + static gboolean -_default_handle_error_message(ProfWin *self, const char * const from, +_muc_handle_error_message(ProfWin *window, const char * const from, const char * const err_msg) { - return FALSE; + gboolean handled = FALSE; + if (g_strcmp0(err_msg, "conflict") == 0) { + win_print_line(window, '-', 0, "Nickname already in use."); + win_refresh(window); + handled = TRUE; + } + + return handled; } static void -_print_incoming_message(ProfWin *self, GTimeVal *tv_stamp, +_win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, const char * const from, const char * const message) { if (tv_stamp == NULL) { - win_print_time(self, '-'); + win_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(self->win, COLOUR_TIME); - wprintw(self->win, "%s - ", date_fmt); - wattroff(self->win, COLOUR_TIME); + 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(self->win, COLOUR_THEM); - wprintw(self->win, "*%s ", from); - waddstr(self->win, message + 4); - wprintw(self->win, "\n"); - wattroff(self->win, COLOUR_THEM); + wattron(window->win, COLOUR_THEM); + wprintw(window->win, "*%s ", from); + waddstr(window->win, message + 4); + wprintw(window->win, "\n"); + wattroff(window->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"); + wattron(window->win, COLOUR_THEM); + wprintw(window->win, "%s: ", from); + wattroff(window->win, COLOUR_THEM); + waddstr(window->win, message); + wprintw(window->win, "\n"); } } diff --git a/src/ui/window.h b/src/ui/window.h index 69e446fa..4c97429a 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -52,10 +52,6 @@ typedef struct prof_win_t { int paged; int unread; int history_shown; - 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); @@ -72,5 +68,10 @@ void win_show_status_string(ProfWin *window, const char * const from, const char * const show, const char * const status, GDateTime *last_activity, const char * const pre, const char * const default_show); +void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, + const char * const from, const char * const message); +gboolean +win_handle_error_message(ProfWin *window, const char * const from, + const char * const err_msg); #endif |