From 4cc4461c0fbf310a329bdc78338c497716073fca Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 8 Jan 2014 20:27:18 +0000 Subject: Removed handle error message function from ProfWin --- src/ui/core.c | 2 +- src/ui/muc_window.c | 39 ----------------------- src/ui/muc_window.h | 33 ------------------- src/ui/window.c | 91 +++++++++++++++++++++++++++-------------------------- src/ui/window.h | 5 +-- 5 files changed, 51 insertions(+), 119 deletions(-) delete mode 100644 src/ui/muc_window.c delete mode 100644 src/ui/muc_window.h (limited to 'src') diff --git a/src/ui/core.c b/src/ui/core.c index 44491d67..afda184a 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -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 - * - * 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 . - * - */ - -#include - -#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 - * - * 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 . - * - */ - -#ifndef UI_MUC_WINDOW_H -#define UI_MUC_WINDOW_H - -#include - -#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 25df66d4..daf9bef0 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -35,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 _win_chat_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) @@ -54,29 +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; - break; - case WIN_CHAT: - new_win->handle_error_message = _default_handle_error_message; - break; - case WIN_MUC: - new_win->handle_error_message = muc_handle_error_message; - break; - case WIN_PRIVATE: - new_win->handle_error_message = _default_handle_error_message; - break; - case WIN_DUCK: - new_win->handle_error_message = _default_handle_error_message; - break; - default: - new_win->handle_error_message = _default_handle_error_message; - break; - } - scrollok(new_win->win, TRUE); return new_win; @@ -319,49 +296,75 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, 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 -_win_chat_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 5cca430e..4c97429a 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -52,8 +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); } ProfWin; ProfWin* win_create(const char * const title, int cols, win_type_t type); @@ -72,5 +70,8 @@ void win_show_status_string(ProfWin *window, const char * const from, 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 -- cgit 1.4.1-2-gfad0