From 3e66b0a9d2d17d17dd599e3747b34492ac8c6e9f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 20 Apr 2013 21:42:39 +0100 Subject: [PATCH 01/37] Added ui/console module --- Makefile.am | 1 + src/ui/console.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/ui/console.h | 31 +++++++++++++++++++++++++++++++ src/ui/windows.c | 20 ++++++-------------- 4 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 src/ui/console.c create mode 100644 src/ui/console.h diff --git a/Makefile.am b/Makefile.am index 697d2e6a..dcd43704 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,6 +10,7 @@ profanity_SOURCES = src/contact.c src/contact.h src/log.c src/common.c \ src/xmpp/capabilities.h src/xmpp/connection.h \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/windows.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ + src/ui/console.h src/ui/console.c \ src/command/command.h src/command/command.c src/command/history.c \ src/command/history.h src/command/parser.c \ src/command/parser.h \ diff --git a/src/ui/console.c b/src/ui/console.c new file mode 100644 index 00000000..30c3a047 --- /dev/null +++ b/src/ui/console.c @@ -0,0 +1,43 @@ +/* + * console.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 . + * + */ + +#ifdef HAVE_NCURSESW_NCURSES_H +#include +#elif HAVE_NCURSES_H +#include +#endif + +#include "ui/window.h" + +#define CONS_WIN_TITLE "_cons" + +static ProfWin* console; + +ProfWin * +console_create(void) +{ + int cols = getmaxx(stdscr); + console = window_create(CONS_WIN_TITLE, cols, WIN_CONSOLE); + return console; +} + + diff --git a/src/ui/console.h b/src/ui/console.h new file mode 100644 index 00000000..7b28684b --- /dev/null +++ b/src/ui/console.h @@ -0,0 +1,31 @@ +/* + * console.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 CONSOLE_H +#define CONSOLE_H + +#include "ui/window.h" + +ProfWin* console_create(void); + +#endif + diff --git a/src/ui/windows.c b/src/ui/windows.c index 9a10557c..9d232373 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -50,10 +50,10 @@ #include "jid.h" #include "log.h" #include "muc.h" +#include "ui/console.h" #include "ui/ui.h" #include "ui/window.h" -#define CONS_WIN_TITLE "_cons" #define NUM_WINS 10 // holds console at index 0 and chat wins 1 through to 9 @@ -79,7 +79,6 @@ static Display *display; static GTimer *ui_idle_time; static void _set_current(int index); -static void _create_windows(void); static void _cons_splash_logo(void); static void _cons_show_basic_help(void); static void _win_show_contact(ProfWin *window, PContact contact); @@ -132,7 +131,11 @@ ui_init(void) create_status_bar(); status_bar_active(0); create_input_window(); - _create_windows(); + max_cols = getmaxx(stdscr); + windows[0] = console_create(); + console = windows[0]; + current = console; + cons_about(); #ifdef HAVE_LIBXSS display = XOpenDisplay(0); #endif @@ -2238,17 +2241,6 @@ _notify_typing(const char * const from) _notify(message, 10000, "Incoming message"); } -static void -_create_windows(void) -{ - int cols = getmaxx(stdscr); - max_cols = cols; - windows[0] = window_create(CONS_WIN_TITLE, cols, WIN_CONSOLE); - console = windows[0]; - current = console; - cons_about(); -} - static gboolean _new_release(char *found_version) { From c7100203e464ebc684eadb83020564b1d51e4e43 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 20 Apr 2013 23:39:17 +0100 Subject: [PATCH 02/37] Moved cons_about() to console module --- src/command/command.c | 7 + src/common.c | 27 ++ src/common.h | 1 + src/ui/console.c | 162 +++++++++++- src/ui/console.h | 6 +- src/ui/window.c | 12 + src/ui/window.h | 2 + src/ui/windows.c | 569 ++++++++++++++---------------------------- 8 files changed, 404 insertions(+), 382 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 1a0596b6..5ceb004a 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1550,6 +1550,9 @@ _cmd_about(gchar **args, struct cmd_help_t help) { cons_show(""); cons_about(); + if (!win_current_is_console()) { + status_bar_new(0); + } return TRUE; } @@ -1808,6 +1811,10 @@ _cmd_who(gchar **args, struct cmd_help_t help) } } + if (!win_current_is_console()) { + status_bar_new(0); + } + return TRUE; } diff --git a/src/common.c b/src/common.c index 641151db..94b2872c 100644 --- a/src/common.c +++ b/src/common.c @@ -19,6 +19,7 @@ * along with Profanity. If not, see . * */ +#include "config.h" #include #include @@ -260,6 +261,32 @@ release_get_latest() } } +gboolean +release_is_new(char *found_version) +{ + int curr_maj, curr_min, curr_patch, found_maj, found_min, found_patch; + + int parse_curr = sscanf(PACKAGE_VERSION, "%d.%d.%d", &curr_maj, &curr_min, + &curr_patch); + int parse_found = sscanf(found_version, "%d.%d.%d", &found_maj, &found_min, + &found_patch); + + if (parse_found == 3 && parse_curr == 3) { + if (found_maj > curr_maj) { + return TRUE; + } else if (found_maj == curr_maj && found_min > curr_min) { + return TRUE; + } else if (found_maj == curr_maj && found_min == curr_min + && found_patch > curr_patch) { + return TRUE; + } else { + return FALSE; + } + } else { + return FALSE; + } +} + gboolean valid_resource_presence_string(const char * const str) { diff --git a/src/common.h b/src/common.h index 59307b35..96c5d08c 100644 --- a/src/common.h +++ b/src/common.h @@ -83,6 +83,7 @@ char* encode_xml(const char * const xml); char * prof_getline(FILE *stream); int octet_compare(unsigned char *str1, unsigned char *str2); char* release_get_latest(void); +gboolean release_is_new(char *found_version); gchar * xdg_get_config_home(void); gchar * xdg_get_data_home(void); diff --git a/src/ui/console.c b/src/ui/console.c index 30c3a047..c28eb4e0 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -20,24 +20,184 @@ * */ +#include +#include + #ifdef HAVE_NCURSESW_NCURSES_H #include #elif HAVE_NCURSES_H #include #endif +#include "common.h" +#include "config/preferences.h" +#include "config/theme.h" #include "ui/window.h" #define CONS_WIN_TITLE "_cons" static ProfWin* console; +static int dirty; + +static void _cons_splash_logo(void); ProfWin * -console_create(void) +cons_create(void) { int cols = getmaxx(stdscr); console = window_create(CONS_WIN_TITLE, cols, WIN_CONSOLE); + dirty = FALSE; return console; } +void +cons_refresh(void) +{ + int rows, cols; + if (dirty == TRUE) { + getmaxyx(stdscr, rows, cols); + prefresh(console->win, console->y_pos, 0, 1, 0, rows-3, cols-1); + dirty = FALSE; + } +} + +void +cons_show(const char * const msg, ...) +{ + va_list arg; + va_start(arg, msg); + GString *fmt_msg = g_string_new(NULL); + g_string_vprintf(fmt_msg, msg, arg); + window_show_time(console, '-'); + wprintw(console->win, "%s\n", fmt_msg->str); + g_string_free(fmt_msg, TRUE); + va_end(arg); + + dirty = TRUE; +} + +void +cons_about(void) +{ + int rows, cols; + getmaxyx(stdscr, rows, cols); + + if (prefs_get_boolean(PREF_SPLASH)) { + _cons_splash_logo(); + } else { + window_show_time(console, '-'); + + if (strcmp(PACKAGE_STATUS, "development") == 0) { + wprintw(console->win, "Welcome to Profanity, version %sdev\n", PACKAGE_VERSION); + } else { + wprintw(console->win, "Welcome to Profanity, version %s\n", PACKAGE_VERSION); + } + } + + window_show_time(console, '-'); + wprintw(console->win, "Copyright (C) 2012, 2013 James Booth <%s>.\n", PACKAGE_BUGREPORT); + window_show_time(console, '-'); + wprintw(console->win, "License GPLv3+: GNU GPL version 3 or later \n"); + window_show_time(console, '-'); + wprintw(console->win, "\n"); + window_show_time(console, '-'); + wprintw(console->win, "This is free software; you are free to change and redistribute it.\n"); + window_show_time(console, '-'); + wprintw(console->win, "There is NO WARRANTY, to the extent permitted by law.\n"); + window_show_time(console, '-'); + wprintw(console->win, "\n"); + window_show_time(console, '-'); + wprintw(console->win, "Type '/help' to show complete help.\n"); + window_show_time(console, '-'); + wprintw(console->win, "\n"); + + if (prefs_get_boolean(PREF_VERCHECK)) { + cons_check_version(FALSE); + } + + prefresh(console->win, 0, 0, 1, 0, rows-3, cols-1); + + dirty = TRUE; +} + +void +cons_check_version(gboolean not_available_msg) +{ + char *latest_release = release_get_latest(); + + if (latest_release != NULL) { + gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); + + if (relase_valid) { + if (release_is_new(latest_release)) { + window_show_time(console, '-'); + wprintw(console->win, "A new version of Profanity is available: %s", latest_release); + window_show_time(console, '-'); + wprintw(console->win, "Check for details.\n"); + free(latest_release); + window_show_time(console, '-'); + wprintw(console->win, "\n"); + } else { + if (not_available_msg) { + cons_show("No new version available."); + cons_show(""); + } + } + + dirty = TRUE; + } + } +} + +static void +_cons_splash_logo(void) +{ + window_show_time(console, '-'); + wprintw(console->win, "Welcome to\n"); + + window_show_time(console, '-'); + wattron(console->win, COLOUR_SPLASH); + wprintw(console->win, " ___ _ \n"); + wattroff(console->win, COLOUR_SPLASH); + + window_show_time(console, '-'); + wattron(console->win, COLOUR_SPLASH); + wprintw(console->win, " / __) (_)_ \n"); + wattroff(console->win, COLOUR_SPLASH); + + window_show_time(console, '-'); + wattron(console->win, COLOUR_SPLASH); + wprintw(console->win, " ____ ____ ___ | |__ ____ ____ _| |_ _ _ \n"); + wattroff(console->win, COLOUR_SPLASH); + + window_show_time(console, '-'); + wattron(console->win, COLOUR_SPLASH); + wprintw(console->win, "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |\n"); + wattroff(console->win, COLOUR_SPLASH); + + window_show_time(console, '-'); + wattron(console->win, COLOUR_SPLASH); + wprintw(console->win, "| | | | | | |_| | | ( ( | | | | | | |_| |_| |\n"); + wattroff(console->win, COLOUR_SPLASH); + + window_show_time(console, '-'); + wattron(console->win, COLOUR_SPLASH); + wprintw(console->win, "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |\n"); + wattroff(console->win, COLOUR_SPLASH); + + window_show_time(console, '-'); + wattron(console->win, COLOUR_SPLASH); + wprintw(console->win, "|_| (____/ \n"); + wattroff(console->win, COLOUR_SPLASH); + + window_show_time(console, '-'); + wprintw(console->win, "\n"); + window_show_time(console, '-'); + if (strcmp(PACKAGE_STATUS, "development") == 0) { + wprintw(console->win, "Version %sdev\n", PACKAGE_VERSION); + } else { + wprintw(console->win, "Version %s\n", PACKAGE_VERSION); + } +} + diff --git a/src/ui/console.h b/src/ui/console.h index 7b28684b..6b24dee7 100644 --- a/src/ui/console.h +++ b/src/ui/console.h @@ -25,7 +25,11 @@ #include "ui/window.h" -ProfWin* console_create(void); +ProfWin* cons_create(void); +void cons_refresh(void); +void cons_show(const char * const msg, ...); +void cons_about(void); +void cons_check_version(gboolean not_available_msg); #endif diff --git a/src/ui/window.c b/src/ui/window.c index 85648814..8bf3311c 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -64,3 +64,15 @@ window_free(ProfWin* window) free(window); window = NULL; } + +void +window_show_time(ProfWin* window, char show_char) +{ + GDateTime *time = g_date_time_new_now_local(); + gchar *date_fmt = g_date_time_format(time, "%H:%M:%S"); + wattron(window->win, COLOUR_TIME); + wprintw(window->win, "%s %c ", date_fmt, show_char); + wattroff(window->win, COLOUR_TIME); + g_date_time_unref(time); + g_free(date_fmt); +} diff --git a/src/ui/window.h b/src/ui/window.h index ce980dd6..16428c6b 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -39,4 +39,6 @@ typedef struct prof_win_t { ProfWin* window_create(const char * const title, int cols, win_type_t type); void window_free(ProfWin *window); +void window_show_time(ProfWin* window, char show_char); + #endif diff --git a/src/ui/windows.c b/src/ui/windows.c index 9d232373..8aaab1d1 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -79,17 +79,15 @@ static Display *display; static GTimer *ui_idle_time; static void _set_current(int index); -static void _cons_splash_logo(void); static void _cons_show_basic_help(void); static void _win_show_contact(ProfWin *window, PContact contact); static int _find_prof_win_index(const char * const contact); static int _new_prof_win(const char * const contact, win_type_t type); static void _current_window_refresh(void); -static void _win_show_time(WINDOW *win, char showchar); static void _win_show_user(WINDOW *win, const char * const user, const int colour); static void _win_show_message(WINDOW *win, const char * const message); static void _win_show_error_msg(WINDOW *win, const char * const message); -static void _show_status_string(WINDOW *win, const char * const from, +static void _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); @@ -102,8 +100,7 @@ static void _win_resize_all(void); static gint _win_get_unread(void); static void _win_show_history(WINDOW *win, int win_index, const char * const contact); -static void _win_show_info(WINDOW *win, PContact pcontact); -static gboolean _new_release(char *found_version); +static void _win_show_info(ProfWin *window, PContact pcontact); static void _ui_draw_win_title(void); static void _presence_colour_on(WINDOW *win, const char * const presence); static void _presence_colour_off(WINDOW *win, const char * const presence); @@ -132,7 +129,7 @@ ui_init(void) status_bar_active(0); create_input_window(); max_cols = getmaxx(stdscr); - windows[0] = console_create(); + windows[0] = cons_create(); console = windows[0]; current = console; cons_about(); @@ -150,6 +147,7 @@ ui_refresh(void) title_bar_refresh(); status_bar_refresh(); + cons_refresh(); if (dirty) { _current_window_refresh(); @@ -347,7 +345,7 @@ ui_show_incoming_msg(const char * const from, const char * const message, // no spare windows left if (win_index == 0) { if (tv_stamp == NULL) { - _win_show_time(console->win, '-'); + window_show_time(console, '-'); } else { GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp); gchar *date_fmt = g_date_time_format(time, "%H:%M:%S"); @@ -379,31 +377,31 @@ ui_show_incoming_msg(const char * const from, const char * const message, // window found or created } else { - WINDOW *win = windows[win_index]->win; + ProfWin *window = windows[win_index]; // currently viewing chat window with sender if (win_index == current_index) { if (tv_stamp == NULL) { - _win_show_time(win, '-'); + window_show_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(win, COLOUR_TIME); - wprintw(win, "%s - ", date_fmt); - wattroff(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(win, COLOUR_THEM); - wprintw(win, "*%s ", display_from); - wprintw(win, "%s", message + 4); - wprintw(win, "\n"); - wattroff(win, COLOUR_THEM); + wattron(window->win, COLOUR_THEM); + wprintw(window->win, "*%s ", display_from); + wprintw(window->win, "%s", message + 4); + wprintw(window->win, "\n"); + wattroff(window->win, COLOUR_THEM); } else { - _win_show_user(win, display_from, 1); - _win_show_message(win, message); + _win_show_user(window->win, display_from, 1); + _win_show_message(window->win, message); } title_bar_set_typing(FALSE); title_bar_draw(); @@ -419,30 +417,30 @@ ui_show_incoming_msg(const char * const from, const char * const message, windows[win_index]->unread++; if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(win, win_index, from); + _win_show_history(window->win, win_index, from); } if (tv_stamp == NULL) { - _win_show_time(win, '-'); + window_show_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(win, COLOUR_TIME); - wprintw(win, "%s - ", date_fmt); - wattroff(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(win, COLOUR_THEM); - wprintw(win, "*%s ", display_from); - wprintw(win, "%s", message + 4); - wprintw(win, "\n"); - wattroff(win, COLOUR_THEM); + wattron(window->win, COLOUR_THEM); + wprintw(window->win, "*%s ", display_from); + wprintw(window->win, "%s", message + 4); + wprintw(window->win, "\n"); + wattroff(window->win, COLOUR_THEM); } else { - _win_show_user(win, display_from, 1); - _win_show_message(win, message); + _win_show_user(window->win, display_from, 1); + _win_show_message(window->win, message); } } } @@ -468,13 +466,13 @@ ui_contact_online(const char * const barejid, const char * const resource, display_str = jid->fulljid; } - _show_status_string(console->win, display_str, show, status, last_activity, "++", + _show_status_string(console, display_str, show, status, last_activity, "++", "online"); int win_index = _find_prof_win_index(barejid); if (win_index != NUM_WINS) { - WINDOW *win = windows[win_index]->win; - _show_status_string(win, display_str, show, status, last_activity, "++", + ProfWin *window = windows[win_index]; + _show_status_string(window, display_str, show, status, last_activity, "++", "online"); } @@ -497,12 +495,12 @@ ui_contact_offline(const char * const from, const char * const show, display_str = jidp->fulljid; } - _show_status_string(console->win, display_str, show, status, NULL, "--", "offline"); + _show_status_string(console, display_str, show, status, NULL, "--", "offline"); int win_index = _find_prof_win_index(from); if (win_index != NUM_WINS) { - WINDOW *win = windows[win_index]->win; - _show_status_string(win, display_str, show, status, NULL, "--", "offline"); + ProfWin *window = windows[win_index]; + _show_status_string(window, display_str, show, status, NULL, "--", "offline"); } if (win_index == current_index) @@ -516,11 +514,11 @@ ui_disconnected(void) // show message in all active chats for (i = 1; i < NUM_WINS; i++) { if (windows[i] != NULL) { - WINDOW *win = windows[i]->win; - _win_show_time(win, '-'); - wattron(win, COLOUR_ERROR); - wprintw(win, "%s\n", "Lost connection."); - wattroff(win, COLOUR_ERROR); + ProfWin *window = windows[i]; + window_show_time(window, '-'); + wattron(window->win, COLOUR_ERROR); + wprintw(window->win, "%s\n", "Lost connection."); + wattroff(window->win, COLOUR_ERROR); // if current win, set dirty if (i == current_index) { @@ -631,7 +629,7 @@ win_current_show(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - _win_show_time(current->win, '-'); + window_show_time(current, '-'); wprintw(current->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); @@ -642,11 +640,10 @@ win_current_show(const char * const msg, ...) void win_current_bad_show(const char * const msg) { - WINDOW *win = current->win; - _win_show_time(win, '-'); - wattron(win, COLOUR_ERROR); - wprintw(win, "%s\n", msg); - wattroff(win, COLOUR_ERROR); + window_show_time(current, '-'); + wattron(current->win, COLOUR_ERROR); + wprintw(current->win, "%s\n", msg); + wattroff(current->win, COLOUR_ERROR); dirty = TRUE; } @@ -674,7 +671,7 @@ void win_show_error_msg(const char * const from, const char *err_msg) { int win_index; - WINDOW *win; + ProfWin *window; if (from == NULL || err_msg == NULL) return; @@ -682,9 +679,9 @@ win_show_error_msg(const char * const from, const char *err_msg) win_index = _find_prof_win_index(from); // chat window exists if (win_index < NUM_WINS) { - win = windows[win_index]->win; - _win_show_time(win, '-'); - _win_show_error_msg(win, err_msg); + window = windows[win_index]; + window_show_time(window, '-'); + _win_show_error_msg(window->win, err_msg); if (win_index == current_index) { dirty = TRUE; } @@ -695,7 +692,7 @@ void win_show_system_msg(const char * const from, const char *message) { int win_index; - WINDOW *win; + ProfWin *window; char from_cpy[strlen(from) + 1]; char *bare_jid; @@ -711,10 +708,10 @@ win_show_system_msg(const char * const from, const char *message) status_bar_active(win_index); dirty = TRUE; } - win = windows[win_index]->win; + window = windows[win_index]; - _win_show_time(win, '-'); - wprintw(win, "*%s %s\n", bare_jid, message); + window_show_time(window, '-'); + wprintw(window->win, "*%s %s\n", bare_jid, message); // this is the current window if (win_index == current_index) { @@ -726,7 +723,7 @@ void win_show_gone(const char * const from) { int win_index; - WINDOW *win; + ProfWin *window; if (from == NULL) return; @@ -734,13 +731,13 @@ win_show_gone(const char * const from) win_index = _find_prof_win_index(from); // chat window exists if (win_index < NUM_WINS) { - win = windows[win_index]->win; - _win_show_time(win, '-'); - wattron(win, COLOUR_GONE); - wprintw(win, "*%s ", from); - wprintw(win, "has left the conversation."); - wprintw(win, "\n"); - wattroff(win, COLOUR_GONE); + window = windows[win_index]; + window_show_time(window, '-'); + wattron(window->win, COLOUR_GONE); + wprintw(window->win, "*%s ", from); + wprintw(window->win, "has left the conversation."); + wprintw(window->win, "\n"); + wattroff(window->win, COLOUR_GONE); if (win_index == current_index) { dirty = TRUE; } @@ -753,7 +750,7 @@ win_new_chat_win(const char * const to) // if the contact is offline, show a message PContact contact = contact_list_get_contact(to); int win_index = _find_prof_win_index(to); - WINDOW *win = NULL; + ProfWin *window = NULL; // create new window if (win_index == NUM_WINS) { @@ -767,23 +764,23 @@ win_new_chat_win(const char * const to) jid_destroy(jid); - win = windows[win_index]->win; + window = windows[win_index]; if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(win, win_index, to); + _win_show_history(window->win, win_index, to); } if (contact != NULL) { if (strcmp(p_contact_presence(contact), "offline") == 0) { const char const *show = p_contact_presence(contact); const char const *status = p_contact_status(contact); - _show_status_string(win, to, show, status, NULL, "--", "offline"); + _show_status_string(window, to, show, status, NULL, "--", "offline"); } } // use existing window } else { - win = windows[win_index]->win; + window = windows[win_index]; } ui_switch_win(win_index); @@ -796,7 +793,7 @@ win_show_outgoing_msg(const char * const from, const char * const to, // if the contact is offline, show a message PContact contact = contact_list_get_contact(to); int win_index = _find_prof_win_index(to); - WINDOW *win = NULL; + ProfWin *window = NULL; // create new window if (win_index == NUM_WINS) { @@ -810,35 +807,35 @@ win_show_outgoing_msg(const char * const from, const char * const to, jid_destroy(jid); - win = windows[win_index]->win; + window = windows[win_index]; if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(win, win_index, to); + _win_show_history(window->win, win_index, to); } if (contact != NULL) { if (strcmp(p_contact_presence(contact), "offline") == 0) { const char const *show = p_contact_presence(contact); const char const *status = p_contact_status(contact); - _show_status_string(win, to, show, status, NULL, "--", "offline"); + _show_status_string(window, to, show, status, NULL, "--", "offline"); } } // use existing window } else { - win = windows[win_index]->win; + window = windows[win_index]; } - _win_show_time(win, '-'); + window_show_time(window, '-'); if (strncmp(message, "/me ", 4) == 0) { - wattron(win, COLOUR_ME); - wprintw(win, "*%s ", from); - wprintw(win, "%s", message + 4); - wprintw(win, "\n"); - wattroff(win, COLOUR_ME); + wattron(window->win, COLOUR_ME); + wprintw(window->win, "*%s ", from); + wprintw(window->win, "%s", message + 4); + wprintw(window->win, "\n"); + wattroff(window->win, COLOUR_ME); } else { - _win_show_user(win, from, 0); - _win_show_message(win, message); + _win_show_user(window->win, from, 0); + _win_show_message(window->win, message); } ui_switch_win(win_index); } @@ -860,45 +857,45 @@ void win_show_room_roster(const char * const room, GList *roster, const char * const presence) { int win_index = _find_prof_win_index(room); - WINDOW *win = windows[win_index]->win; + ProfWin *window = windows[win_index]; - _win_show_time(win, '!'); + window_show_time(window, '!'); if ((roster == NULL) || (g_list_length(roster) == 0)) { - wattron(win, COLOUR_ROOMINFO); + wattron(window->win, COLOUR_ROOMINFO); if (presence == NULL) { - wprintw(win, "Room is empty.\n"); + wprintw(window->win, "Room is empty.\n"); } else { - wprintw(win, "No participants are %s.\n", presence); + wprintw(window->win, "No participants are %s.\n", presence); } - wattroff(win, COLOUR_ROOMINFO); + wattroff(window->win, COLOUR_ROOMINFO); } else { - wattron(win, COLOUR_ROOMINFO); + wattron(window->win, COLOUR_ROOMINFO); if (presence == NULL) { - wprintw(win, "Participants: "); + wprintw(window->win, "Participants: "); } else { - wprintw(win, "Participants (%s): ", presence); + wprintw(window->win, "Participants (%s): ", presence); } - wattroff(win, COLOUR_ROOMINFO); - wattron(win, COLOUR_ONLINE); + wattroff(window->win, COLOUR_ROOMINFO); + wattron(window->win, COLOUR_ONLINE); while (roster != NULL) { PContact member = roster->data; const char const *nick = p_contact_barejid(member); const char const *show = p_contact_presence(member); - _presence_colour_on(win, show); - wprintw(win, "%s", nick); - _presence_colour_off(win, show); + _presence_colour_on(window->win, show); + wprintw(window->win, "%s", nick); + _presence_colour_off(window->win, show); if (roster->next != NULL) { - wprintw(win, ", "); + wprintw(window->win, ", "); } roster = g_list_next(roster); } - wprintw(win, "\n"); - wattroff(win, COLOUR_ONLINE); + wprintw(window->win, "\n"); + wattroff(window->win, COLOUR_ONLINE); } if (win_index == current_index) @@ -909,12 +906,12 @@ void win_show_room_member_offline(const char * const room, const char * const nick) { int win_index = _find_prof_win_index(room); - WINDOW *win = windows[win_index]->win; + ProfWin *window = windows[win_index]; - _win_show_time(win, '!'); - wattron(win, COLOUR_OFFLINE); - wprintw(win, "<- %s has left the room.\n", nick); - wattroff(win, COLOUR_OFFLINE); + window_show_time(window, '!'); + wattron(window->win, COLOUR_OFFLINE); + wprintw(window->win, "<- %s has left the room.\n", nick); + wattroff(window->win, COLOUR_OFFLINE); if (win_index == current_index) dirty = TRUE; @@ -925,12 +922,12 @@ win_show_room_member_online(const char * const room, const char * const nick, const char * const show, const char * const status) { int win_index = _find_prof_win_index(room); - WINDOW *win = windows[win_index]->win; + ProfWin *window = windows[win_index]; - _win_show_time(win, '!'); - wattron(win, COLOUR_ONLINE); - wprintw(win, "-> %s has joined the room.\n", nick); - wattroff(win, COLOUR_ONLINE); + window_show_time(window, '!'); + wattron(window->win, COLOUR_ONLINE); + wprintw(window->win, "-> %s has joined the room.\n", nick); + wattroff(window->win, COLOUR_ONLINE); if (win_index == current_index) dirty = TRUE; @@ -942,8 +939,8 @@ win_show_room_member_presence(const char * const room, const char * const nick, { int win_index = _find_prof_win_index(room); if (win_index != NUM_WINS) { - WINDOW *win = windows[win_index]->win; - _show_status_string(win, nick, show, status, NULL, "++", "online"); + ProfWin *window = windows[win_index]; + _show_status_string(window, nick, show, status, NULL, "++", "online"); } if (win_index == current_index) @@ -955,12 +952,12 @@ win_show_room_member_nick_change(const char * const room, const char * const old_nick, const char * const nick) { int win_index = _find_prof_win_index(room); - WINDOW *win = windows[win_index]->win; + ProfWin *window = windows[win_index]; - _win_show_time(win, '!'); - wattron(win, COLOUR_THEM); - wprintw(win, "** %s is now known as %s\n", old_nick, nick); - wattroff(win, COLOUR_THEM); + window_show_time(window, '!'); + wattron(window->win, COLOUR_THEM); + wprintw(window->win, "** %s is now known as %s\n", old_nick, nick); + wattroff(window->win, COLOUR_THEM); if (win_index == current_index) dirty = TRUE; @@ -970,12 +967,12 @@ void win_show_room_nick_change(const char * const room, const char * const nick) { int win_index = _find_prof_win_index(room); - WINDOW *win = windows[win_index]->win; + ProfWin *window = windows[win_index]; - _win_show_time(win, '!'); - wattron(win, COLOUR_ME); - wprintw(win, "** You are now known as %s\n", nick); - wattroff(win, COLOUR_ME); + window_show_time(window, '!'); + wattron(window->win, COLOUR_ME); + wprintw(window->win, "** You are now known as %s\n", nick); + wattroff(window->win, COLOUR_ME); if (win_index == current_index) dirty = TRUE; @@ -1012,31 +1009,31 @@ win_show_room_message(const char * const room_jid, const char * const nick, const char * const message) { int win_index = _find_prof_win_index(room_jid); - WINDOW *win = windows[win_index]->win; + ProfWin *window = windows[win_index]; - _win_show_time(win, '-'); + window_show_time(window, '-'); if (strcmp(nick, muc_get_room_nick(room_jid)) != 0) { if (strncmp(message, "/me ", 4) == 0) { - wattron(win, COLOUR_THEM); - wprintw(win, "*%s ", nick); - wprintw(win, "%s", message + 4); - wprintw(win, "\n"); - wattroff(win, COLOUR_THEM); + wattron(window->win, COLOUR_THEM); + wprintw(window->win, "*%s ", nick); + wprintw(window->win, "%s", message + 4); + wprintw(window->win, "\n"); + wattroff(window->win, COLOUR_THEM); } else { - _win_show_user(win, nick, 1); - _win_show_message(win, message); + _win_show_user(window->win, nick, 1); + _win_show_message(window->win, message); } } else { if (strncmp(message, "/me ", 4) == 0) { - wattron(win, COLOUR_ME); - wprintw(win, "*%s ", nick); - wprintw(win, "%s", message + 4); - wprintw(win, "\n"); - wattroff(win, COLOUR_ME); + wattron(window->win, COLOUR_ME); + wprintw(window->win, "*%s ", nick); + wprintw(window->win, "%s", message + 4); + wprintw(window->win, "\n"); + wattroff(window->win, COLOUR_ME); } else { - _win_show_user(win, nick, 0); - _win_show_message(win, message); + _win_show_user(window->win, nick, 0); + _win_show_message(window->win, message); } } @@ -1076,13 +1073,13 @@ void win_show_room_subject(const char * const room_jid, const char * const subject) { int win_index = _find_prof_win_index(room_jid); - WINDOW *win = windows[win_index]->win; + ProfWin *window = windows[win_index]; - _win_show_time(win, '!'); - wattron(win, COLOUR_ROOMINFO); - wprintw(win, "Room subject: "); - wattroff(win, COLOUR_ROOMINFO); - wprintw(win, "%s\n", subject); + window_show_time(window, '!'); + wattron(window->win, COLOUR_ROOMINFO); + wprintw(window->win, "Room subject: "); + wattroff(window->win, COLOUR_ROOMINFO); + wprintw(window->win, "%s\n", subject); // currently in groupchat window if (win_index == current_index) { @@ -1099,13 +1096,13 @@ void win_show_room_broadcast(const char * const room_jid, const char * const message) { int win_index = _find_prof_win_index(room_jid); - WINDOW *win = windows[win_index]->win; + ProfWin *window = windows[win_index]; - _win_show_time(win, '!'); - wattron(win, COLOUR_ROOMINFO); - wprintw(win, "Room message: "); - wattroff(win, COLOUR_ROOMINFO); - wprintw(win, "%s\n", message); + window_show_time(window, '!'); + wattron(window->win, COLOUR_ROOMINFO); + wprintw(window->win, "Room message: "); + wattroff(window->win, COLOUR_ROOMINFO); + wprintw(window->win, "%s\n", message); // currently in groupchat window if (win_index == current_index) { @@ -1121,7 +1118,7 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) void cons_show_login_success(ProfAccount *account) { - _win_show_time(console->win, '-'); + window_show_time(console, '-'); wprintw(console->win, "%s logged in successfully, ", account->jid); resource_presence_t presence = accounts_get_login_presence(account->name); @@ -1144,7 +1141,7 @@ cons_show_wins(void) cons_show(""); cons_show("Active windows:"); - _win_show_time(console->win, '-'); + window_show_time(console, '-'); wprintw(console->win, "1: Console\n"); for (i = 1; i < NUM_WINS; i++) { @@ -1157,7 +1154,7 @@ cons_show_wins(void) for (i = 1; i < NUM_WINS; i++) { if (windows[i] != NULL) { ProfWin *window = windows[i]; - _win_show_time(console->win, '-'); + window_show_time(console, '-'); switch (window->type) { @@ -1211,11 +1208,9 @@ cons_show_wins(void) void cons_show_info(PContact pcontact) { - _win_show_info(console->win, pcontact); + _win_show_info(console, pcontact); - if (current_index == 0) { - dirty = TRUE; - } else { + if (current_index != 0) { status_bar_new(0); } } @@ -1226,9 +1221,9 @@ cons_show_caps(const char * const contact, Resource *resource) WINDOW *win = console->win; cons_show(""); const char *resource_presence = string_from_resource_presence(resource->presence); - _win_show_time(win, '-'); + window_show_time(console, '-'); _presence_colour_on(win, resource_presence); - wprintw(win, "%s", contact); + wprintw(console->win, "%s", contact); _presence_colour_off(win, resource_presence); wprintw(win, ":\n"); @@ -1238,7 +1233,7 @@ cons_show_caps(const char * const contact, Resource *resource) if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - _win_show_time(win, '-'); + window_show_time(console, '-'); wprintw(win, "Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); @@ -1258,7 +1253,7 @@ cons_show_caps(const char * const contact, Resource *resource) wprintw(win, "\n"); } if (caps->software != NULL) { - _win_show_time(win, '-'); + window_show_time(console, '-'); wprintw(win, "Software: %s", caps->software); } if (caps->software_version != NULL) { @@ -1268,7 +1263,7 @@ cons_show_caps(const char * const contact, Resource *resource) wprintw(win, "\n"); } if (caps->os != NULL) { - _win_show_time(win, '-'); + window_show_time(console, '-'); wprintw(win, "OS: %s", caps->os); } if (caps->os_version != NULL) { @@ -1279,11 +1274,11 @@ cons_show_caps(const char * const contact, Resource *resource) } if (caps->features != NULL) { - _win_show_time(win, '-'); + window_show_time(console, '-'); wprintw(win, "Features:\n"); GSList *feature = caps->features; while (feature != NULL) { - _win_show_time(win, '-'); + window_show_time(console, '-'); wprintw(win, " %s\n", feature->data); feature = g_slist_next(feature); } @@ -1306,7 +1301,7 @@ cons_show_software_version(const char * const jid, const char * const presence, { if ((name != NULL) || (version != NULL) || (os != NULL)) { cons_show(""); - _win_show_time(console->win, '-'); + window_show_time(console, '-'); _presence_colour_on(console->win, presence); wprintw(console->win, "%s", jid); _presence_colour_off(console->win, presence); @@ -1330,7 +1325,7 @@ cons_show_room_list(GSList *rooms, const char * const conference_node) cons_show("Chat rooms at %s:", conference_node); while (rooms != NULL) { DiscoItem *room = rooms->data; - _win_show_time(console->win, '-'); + window_show_time(console, '-'); wprintw(console->win, " %s", room->jid); if (room->name != NULL) { wprintw(console->win, ", (%s)", room->name); @@ -1391,7 +1386,7 @@ cons_show_disco_items(GSList *items, const char * const jid) cons_show("Service discovery items for %s:", jid); while (items != NULL) { DiscoItem *item = items->data; - _win_show_time(console->win, '-'); + window_show_time(console, '-'); wprintw(console->win, " %s", item->jid); if (item->name != NULL) { wprintw(console->win, ", (%s)", item->name); @@ -1459,7 +1454,7 @@ cons_show_account_list(gchar **accounts) if ((jabber_get_connection_status() == JABBER_CONNECTED) && (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) { resource_presence_t presence = accounts_get_last_presence(accounts[i]); - _win_show_time(console->win, '-'); + window_show_time(console, '-'); _presence_colour_on(console->win, string_from_resource_presence(presence)); wprintw(console->win, "%s\n", accounts[i]); _presence_colour_off(console->win, string_from_resource_presence(presence)); @@ -1508,7 +1503,7 @@ cons_show_account(ProfAccount *account) WINDOW *win = console->win; if (resources != NULL) { - _win_show_time(win, '-'); + window_show_time(console, '-'); wprintw(win, "Resources:\n"); // sort in order of availabiltiy @@ -1523,7 +1518,7 @@ cons_show_account(ProfAccount *account) while (ordered_resources != NULL) { Resource *resource = ordered_resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); - _win_show_time(win, '-'); + window_show_time(console, '-'); _presence_colour_on(win, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { @@ -1537,7 +1532,7 @@ cons_show_account(ProfAccount *account) if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - _win_show_time(win, '-'); + window_show_time(console, '-'); wprintw(win, " Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); @@ -1557,7 +1552,7 @@ cons_show_account(ProfAccount *account) wprintw(win, "\n"); } if (caps->software != NULL) { - _win_show_time(win, '-'); + window_show_time(console, '-'); wprintw(win, " Software: %s", caps->software); } if (caps->software_version != NULL) { @@ -1567,7 +1562,7 @@ cons_show_account(ProfAccount *account) wprintw(win, "\n"); } if (caps->os != NULL) { - _win_show_time(win, '-'); + window_show_time(console, '-'); wprintw(win, " OS: %s", caps->os); } if (caps->os_version != NULL) { @@ -1979,7 +1974,7 @@ cons_bad_show(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - _win_show_time(console->win, '-'); + window_show_time(console, '-'); wattron(console->win, COLOUR_ERROR); wprintw(console->win, "%s\n", fmt_msg->str); wattroff(console->win, COLOUR_ERROR); @@ -1996,26 +1991,7 @@ cons_bad_show(const char * const msg, ...) void cons_show_time(void) { - _win_show_time(console->win, '-'); -} - -void -cons_show(const char * const msg, ...) -{ - va_list arg; - va_start(arg, msg); - GString *fmt_msg = g_string_new(NULL); - g_string_vprintf(fmt_msg, msg, arg); - _win_show_time(console->win, '-'); - wprintw(console->win, "%s\n", fmt_msg->str); - g_string_free(fmt_msg, TRUE); - va_end(arg); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } + window_show_time(console, '-'); } void @@ -2026,7 +2002,7 @@ cons_debug(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - _win_show_time(console->win, '-'); + window_show_time(console, '-'); wprintw(console->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); @@ -2057,7 +2033,7 @@ cons_show_word(const char * const word) void cons_bad_command(const char * const cmd) { - _win_show_time(console->win, '-'); + window_show_time(console, '-'); wprintw(console->win, "Unknown command: %s\n", cmd); if (current_index == 0) { @@ -2067,87 +2043,6 @@ cons_bad_command(const char * const cmd) } } -void -cons_about(void) -{ - int rows, cols; - getmaxyx(stdscr, rows, cols); - - if (prefs_get_boolean(PREF_SPLASH)) { - _cons_splash_logo(); - } else { - _win_show_time(console->win, '-'); - - if (strcmp(PACKAGE_STATUS, "development") == 0) { - wprintw(console->win, "Welcome to Profanity, version %sdev\n", PACKAGE_VERSION); - } else { - wprintw(console->win, "Welcome to Profanity, version %s\n", PACKAGE_VERSION); - } - } - - _win_show_time(console->win, '-'); - wprintw(console->win, "Copyright (C) 2012, 2013 James Booth <%s>.\n", PACKAGE_BUGREPORT); - _win_show_time(console->win, '-'); - wprintw(console->win, "License GPLv3+: GNU GPL version 3 or later \n"); - _win_show_time(console->win, '-'); - wprintw(console->win, "\n"); - _win_show_time(console->win, '-'); - wprintw(console->win, "This is free software; you are free to change and redistribute it.\n"); - _win_show_time(console->win, '-'); - wprintw(console->win, "There is NO WARRANTY, to the extent permitted by law.\n"); - _win_show_time(console->win, '-'); - wprintw(console->win, "\n"); - _win_show_time(console->win, '-'); - wprintw(console->win, "Type '/help' to show complete help.\n"); - _win_show_time(console->win, '-'); - wprintw(console->win, "\n"); - - if (prefs_get_boolean(PREF_VERCHECK)) { - cons_check_version(FALSE); - } - - prefresh(console->win, 0, 0, 1, 0, rows-3, cols-1); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } -} - -void -cons_check_version(gboolean not_available_msg) -{ - char *latest_release = release_get_latest(); - - if (latest_release != NULL) { - gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); - - if (relase_valid) { - if (_new_release(latest_release)) { - _win_show_time(console->win, '-'); - wprintw(console->win, "A new version of Profanity is available: %s", latest_release); - _win_show_time(console->win, '-'); - wprintw(console->win, "Check for details.\n"); - free(latest_release); - _win_show_time(console->win, '-'); - wprintw(console->win, "\n"); - } else { - if (not_available_msg) { - cons_show("No new version available."); - cons_show(""); - } - } - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } - } - } -} - void notify_remind(void) { @@ -2241,83 +2136,6 @@ _notify_typing(const char * const from) _notify(message, 10000, "Incoming message"); } -static gboolean -_new_release(char *found_version) -{ - int curr_maj, curr_min, curr_patch, found_maj, found_min, found_patch; - - int parse_curr = sscanf(PACKAGE_VERSION, "%d.%d.%d", &curr_maj, &curr_min, - &curr_patch); - int parse_found = sscanf(found_version, "%d.%d.%d", &found_maj, &found_min, - &found_patch); - - if (parse_found == 3 && parse_curr == 3) { - if (found_maj > curr_maj) { - return TRUE; - } else if (found_maj == curr_maj && found_min > curr_min) { - return TRUE; - } else if (found_maj == curr_maj && found_min == curr_min - && found_patch > curr_patch) { - return TRUE; - } else { - return FALSE; - } - } else { - return FALSE; - } -} - -static void -_cons_splash_logo(void) -{ - _win_show_time(console->win, '-'); - wprintw(console->win, "Welcome to\n"); - - _win_show_time(console->win, '-'); - wattron(console->win, COLOUR_SPLASH); - wprintw(console->win, " ___ _ \n"); - wattroff(console->win, COLOUR_SPLASH); - - _win_show_time(console->win, '-'); - wattron(console->win, COLOUR_SPLASH); - wprintw(console->win, " / __) (_)_ \n"); - wattroff(console->win, COLOUR_SPLASH); - - _win_show_time(console->win, '-'); - wattron(console->win, COLOUR_SPLASH); - wprintw(console->win, " ____ ____ ___ | |__ ____ ____ _| |_ _ _ \n"); - wattroff(console->win, COLOUR_SPLASH); - - _win_show_time(console->win, '-'); - wattron(console->win, COLOUR_SPLASH); - wprintw(console->win, "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |\n"); - wattroff(console->win, COLOUR_SPLASH); - - _win_show_time(console->win, '-'); - wattron(console->win, COLOUR_SPLASH); - wprintw(console->win, "| | | | | | |_| | | ( ( | | | | | | |_| |_| |\n"); - wattroff(console->win, COLOUR_SPLASH); - - _win_show_time(console->win, '-'); - wattron(console->win, COLOUR_SPLASH); - wprintw(console->win, "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |\n"); - wattroff(console->win, COLOUR_SPLASH); - - _win_show_time(console->win, '-'); - wattron(console->win, COLOUR_SPLASH); - wprintw(console->win, "|_| (____/ \n"); - wattroff(console->win, COLOUR_SPLASH); - - _win_show_time(console->win, '-'); - wprintw(console->win, "\n"); - _win_show_time(console->win, '-'); - if (strcmp(PACKAGE_STATUS, "development") == 0) { - wprintw(console->win, "Version %sdev\n", PACKAGE_VERSION); - } else { - wprintw(console->win, "Version %s\n", PACKAGE_VERSION); - } -} - static int _find_prof_win_index(const char * const contact) { @@ -2350,18 +2168,6 @@ _new_prof_win(const char * const contact, win_type_t type) } } -static void -_win_show_time(WINDOW *win, char showchar) -{ - GDateTime *time = g_date_time_new_now_local(); - gchar *date_fmt = g_date_time_format(time, "%H:%M:%S"); - wattron(win, COLOUR_TIME); - wprintw(win, "%s %c ", date_fmt, showchar); - wattroff(win, COLOUR_TIME); - g_date_time_unref(time); - g_free(date_fmt); -} - static void _win_show_user(WINDOW *win, const char * const user, const int colour) { @@ -2457,15 +2263,17 @@ _presence_colour_off(WINDOW *win, const char * const presence) } static void -_show_status_string(WINDOW *win, const char * const from, +_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) { + WINDOW *win = window->win; + if (!prefs_get_boolean(PREF_STATUSES)) return; - _win_show_time(win, '-'); + window_show_time(window, '-'); if (show != NULL) { if (strcmp(show, "away") == 0) { @@ -2543,7 +2351,7 @@ _show_status_string(WINDOW *win, const char * const from, static void _cons_show_typing(const char * const short_from) { - _win_show_time(console->win, '-'); + window_show_time(console, '-'); wattron(console->win, COLOUR_TYPING); wprintw(console->win, "!! %s is typing a message...\n", short_from); wattroff(console->win, COLOUR_TYPING); @@ -2552,7 +2360,7 @@ _cons_show_typing(const char * const short_from) static void _cons_show_incoming_message(const char * const short_from, const int win_index) { - _win_show_time(console->win, '-'); + window_show_time(console, '-'); wattron(console->win, COLOUR_INCOMING); wprintw(console->win, "<< incoming from %s (%d)\n", short_from, win_index + 1); wattroff(console->win, COLOUR_INCOMING); @@ -2567,7 +2375,7 @@ _win_show_contact(ProfWin *window, PContact contact) const char *status = p_contact_status(contact); GDateTime *last_activity = p_contact_last_activity(contact); - _win_show_time(window->win, '-'); + window_show_time(window, '-'); _presence_colour_on(window->win, presence); wprintw(window->win, "%s", barejid); @@ -2737,7 +2545,7 @@ _win_show_history(WINDOW *win, int win_index, const char * const contact) } static void -_win_show_info(WINDOW *win, PContact pcontact) +_win_show_info(ProfWin *window, PContact pcontact) { const char *barejid = p_contact_barejid(pcontact); const char *name = p_contact_name(pcontact); @@ -2746,10 +2554,11 @@ _win_show_info(WINDOW *win, PContact pcontact) GList *resources = p_contact_get_available_resources(pcontact); GList *ordered_resources = NULL; GDateTime *last_activity = p_contact_last_activity(pcontact); + WINDOW *win = window->win; - _win_show_time(win, '-'); + window_show_time(window, '-'); wprintw(win, "\n"); - _win_show_time(win, '-'); + window_show_time(window, '-'); _presence_colour_on(win, presence); wprintw(win, "%s", barejid); if (name != NULL) { @@ -2759,7 +2568,7 @@ _win_show_info(WINDOW *win, PContact pcontact) wprintw(win, ":\n"); if (sub != NULL) { - _win_show_time(win, '-'); + window_show_time(window, '-'); wprintw(win, "Subscription: %s\n", sub); } @@ -2767,7 +2576,7 @@ _win_show_info(WINDOW *win, PContact pcontact) GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); - _win_show_time(win, '-'); + window_show_time(window, '-'); wprintw(win, "Last activity: "); int hours = span / G_TIME_SPAN_HOUR; @@ -2789,7 +2598,7 @@ _win_show_info(WINDOW *win, PContact pcontact) } if (resources != NULL) { - _win_show_time(win, '-'); + window_show_time(window, '-'); wprintw(win, "Resources:\n"); // sort in order of availabiltiy @@ -2804,7 +2613,7 @@ _win_show_info(WINDOW *win, PContact pcontact) while (ordered_resources != NULL) { Resource *resource = ordered_resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); - _win_show_time(win, '-'); + window_show_time(window, '-'); _presence_colour_on(win, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { @@ -2818,7 +2627,7 @@ _win_show_info(WINDOW *win, PContact pcontact) if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - _win_show_time(win, '-'); + window_show_time(window, '-'); wprintw(win, " Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); @@ -2838,7 +2647,7 @@ _win_show_info(WINDOW *win, PContact pcontact) wprintw(win, "\n"); } if (caps->software != NULL) { - _win_show_time(win, '-'); + window_show_time(window, '-'); wprintw(win, " Software: %s", caps->software); } if (caps->software_version != NULL) { @@ -2848,7 +2657,7 @@ _win_show_info(WINDOW *win, PContact pcontact) wprintw(win, "\n"); } if (caps->os != NULL) { - _win_show_time(win, '-'); + window_show_time(window, '-'); wprintw(win, " OS: %s", caps->os); } if (caps->os_version != NULL) { From a234ba0cd6a3863952fb7aed35ecbee287e70af2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 00:21:30 +0100 Subject: [PATCH 03/37] Moved cons_show_login_success() to console module --- Makefile.am | 2 +- src/ui/console.c | 19 +++++++++++ src/ui/console.h | 35 ------------------- src/ui/ui.h | 26 +++----------- src/ui/window.c | 37 ++++++++++++++++++++ src/ui/window.h | 15 +++++++-- src/ui/windows.c | 88 +++++++++--------------------------------------- 7 files changed, 90 insertions(+), 132 deletions(-) delete mode 100644 src/ui/console.h diff --git a/Makefile.am b/Makefile.am index dcd43704..ef2752b5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ profanity_SOURCES = src/contact.c src/contact.h src/log.c src/common.c \ src/xmpp/capabilities.h src/xmpp/connection.h \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/windows.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ - src/ui/console.h src/ui/console.c \ + src/ui/console.c \ src/command/command.h src/command/command.c src/command/history.c \ src/command/history.h src/command/parser.c \ src/command/parser.h \ diff --git a/src/ui/console.c b/src/ui/console.c index c28eb4e0..52dac651 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -33,6 +33,7 @@ #include "config/preferences.h" #include "config/theme.h" #include "ui/window.h" +#include "ui/ui.h" #define CONS_WIN_TITLE "_cons" @@ -149,6 +150,24 @@ cons_check_version(gboolean not_available_msg) } } +void +cons_show_login_success(ProfAccount *account) +{ + window_show_time(console, '-'); + wprintw(console->win, "%s logged in successfully, ", account->jid); + + resource_presence_t presence = accounts_get_login_presence(account->name); + const char *presence_str = string_from_resource_presence(presence); + + window_presence_colour_on(console, presence_str); + wprintw(console->win, "%s", presence_str); + window_presence_colour_off(console, presence_str); + wprintw(console->win, " (priority %d)", + accounts_get_priority_for_presence_type(account->name, presence)); + wprintw(console->win, ".\n"); +} + + static void _cons_splash_logo(void) { diff --git a/src/ui/console.h b/src/ui/console.h deleted file mode 100644 index 6b24dee7..00000000 --- a/src/ui/console.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * console.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 CONSOLE_H -#define CONSOLE_H - -#include "ui/window.h" - -ProfWin* cons_create(void); -void cons_refresh(void); -void cons_show(const char * const msg, ...); -void cons_about(void); -void cons_check_version(gboolean not_available_msg); - -#endif - diff --git a/src/ui/ui.h b/src/ui/ui.h index 226dadbd..b324f8c3 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -36,28 +36,10 @@ #include "contact.h" #include "jid.h" +#include "ui/window.h" #include "xmpp/xmpp.h" #define INP_WIN_MAX 1000 -#define PAD_SIZE 1000 - -typedef enum { - WIN_UNUSED, - WIN_CONSOLE, - WIN_CHAT, - WIN_MUC, - WIN_PRIVATE -} win_type_t; - -struct prof_win { - char from[100]; - WINDOW *win; - win_type_t type; - int y_pos; - int paged; - int unread; - int history_shown; -}; // gui startup and shutdown, resize void ui_init(void); @@ -140,6 +122,9 @@ void win_show_status(void); void win_private_show_status(void); // console window actions +ProfWin* cons_create(void); +void cons_refresh(void); +void cons_show(const char * const msg, ...); void cons_about(void); void cons_help(void); void cons_basic_help(void); @@ -155,14 +140,12 @@ void cons_show_presence_prefs(void); void cons_show_connection_prefs(void); void cons_show_account(ProfAccount *account); void cons_bad_command(const char * const cmd); -void cons_show(const char * const cmd, ...); void cons_debug(const char * const msg, ...); void cons_show_time(void); void cons_show_word(const char * const word); void cons_bad_show(const char * const cmd, ...); void cons_highlight_show(const char * const cmd); void cons_show_contacts(GSList * list); -void cons_check_version(gboolean not_available_msg); void cons_show_wins(void); void cons_show_status(const char * const contact); void cons_show_info(PContact pcontact); @@ -178,6 +161,7 @@ void cons_show_disco_items(GSList *items, const char * const jid); void cons_show_disco_info(const char *from, GSList *identities, GSList *features); void cons_show_room_invite(const char * const invitor, const char * const room, const char * const reason); +void cons_check_version(gboolean not_available_msg); // status bar actions void status_bar_refresh(void); diff --git a/src/ui/window.c b/src/ui/window.c index 8bf3311c..d07ce989 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -76,3 +76,40 @@ window_show_time(ProfWin* window, char show_char) g_date_time_unref(time); g_free(date_fmt); } + +void +window_presence_colour_on(ProfWin *window, const char * const presence) +{ + if (g_strcmp0(presence, "online") == 0) { + wattron(window->win, COLOUR_ONLINE); + } else if (g_strcmp0(presence, "away") == 0) { + wattron(window->win, COLOUR_AWAY); + } else if (g_strcmp0(presence, "chat") == 0) { + wattron(window->win, COLOUR_CHAT); + } else if (g_strcmp0(presence, "dnd") == 0) { + wattron(window->win, COLOUR_DND); + } else if (g_strcmp0(presence, "xa") == 0) { + wattron(window->win, COLOUR_XA); + } else { + wattron(window->win, COLOUR_OFFLINE); + } +} + +void +window_presence_colour_off(ProfWin *window, const char * const presence) +{ + if (g_strcmp0(presence, "online") == 0) { + wattroff(window->win, COLOUR_ONLINE); + } else if (g_strcmp0(presence, "away") == 0) { + wattroff(window->win, COLOUR_AWAY); + } else if (g_strcmp0(presence, "chat") == 0) { + wattroff(window->win, COLOUR_CHAT); + } else if (g_strcmp0(presence, "dnd") == 0) { + wattroff(window->win, COLOUR_DND); + } else if (g_strcmp0(presence, "xa") == 0) { + wattroff(window->win, COLOUR_XA); + } else { + wattroff(window->win, COLOUR_OFFLINE); + } +} + diff --git a/src/ui/window.h b/src/ui/window.h index 16428c6b..2793cd42 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -23,7 +23,15 @@ #ifndef WINDOW_H #define WINDOW_H -#include "ui/ui.h" +#define PAD_SIZE 1000 + +typedef enum { + WIN_UNUSED, + WIN_CONSOLE, + WIN_CHAT, + WIN_MUC, + WIN_PRIVATE +} win_type_t; typedef struct prof_win_t { char *from; @@ -35,10 +43,11 @@ typedef struct prof_win_t { int history_shown; } ProfWin; - ProfWin* window_create(const char * const title, int cols, win_type_t type); void window_free(ProfWin *window); -void window_show_time(ProfWin* window, char show_char); +void window_show_time(ProfWin *window, char show_char); +void window_presence_colour_on(ProfWin *window, const char * const presence); +void window_presence_colour_off(ProfWin *window, const char * const presence); #endif diff --git a/src/ui/windows.c b/src/ui/windows.c index 8aaab1d1..77390751 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -50,7 +50,6 @@ #include "jid.h" #include "log.h" #include "muc.h" -#include "ui/console.h" #include "ui/ui.h" #include "ui/window.h" @@ -102,8 +101,6 @@ static void _win_show_history(WINDOW *win, int win_index, const char * const contact); static void _win_show_info(ProfWin *window, PContact pcontact); static void _ui_draw_win_title(void); -static void _presence_colour_on(WINDOW *win, const char * const presence); -static void _presence_colour_off(WINDOW *win, const char * const presence); static void _notify(const char * const message, int timeout, const char * const category); @@ -883,9 +880,9 @@ win_show_room_roster(const char * const room, GList *roster, const char * const const char const *nick = p_contact_barejid(member); const char const *show = p_contact_presence(member); - _presence_colour_on(window->win, show); + window_presence_colour_on(window, show); wprintw(window->win, "%s", nick); - _presence_colour_off(window->win, show); + window_presence_colour_off(window, show); if (roster->next != NULL) { wprintw(window->win, ", "); @@ -1115,23 +1112,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } -void -cons_show_login_success(ProfAccount *account) -{ - window_show_time(console, '-'); - wprintw(console->win, "%s logged in successfully, ", account->jid); - - resource_presence_t presence = accounts_get_login_presence(account->name); - const char *presence_str = string_from_resource_presence(presence); - - _presence_colour_on(console->win, presence_str); - wprintw(console->win, "%s", presence_str); - _presence_colour_off(console->win, presence_str); - wprintw(console->win, " (priority %d)", - accounts_get_priority_for_presence_type(account->name, presence)); - wprintw(console->win, ".\n"); -} - void cons_show_wins(void) @@ -1222,9 +1202,9 @@ cons_show_caps(const char * const contact, Resource *resource) cons_show(""); const char *resource_presence = string_from_resource_presence(resource->presence); window_show_time(console, '-'); - _presence_colour_on(win, resource_presence); + window_presence_colour_on(console, resource_presence); wprintw(console->win, "%s", contact); - _presence_colour_off(win, resource_presence); + window_presence_colour_off(console, resource_presence); wprintw(win, ":\n"); if (resource->caps_str != NULL) { @@ -1302,9 +1282,9 @@ cons_show_software_version(const char * const jid, const char * const presence, if ((name != NULL) || (version != NULL) || (os != NULL)) { cons_show(""); window_show_time(console, '-'); - _presence_colour_on(console->win, presence); + window_presence_colour_on(console, presence); wprintw(console->win, "%s", jid); - _presence_colour_off(console->win, presence); + window_presence_colour_off(console, presence); wprintw(console->win, ":\n"); } if (name != NULL) { @@ -1455,9 +1435,9 @@ cons_show_account_list(gchar **accounts) (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) { resource_presence_t presence = accounts_get_last_presence(accounts[i]); window_show_time(console, '-'); - _presence_colour_on(console->win, string_from_resource_presence(presence)); + window_presence_colour_on(console, string_from_resource_presence(presence)); wprintw(console->win, "%s\n", accounts[i]); - _presence_colour_off(console->win, string_from_resource_presence(presence)); + window_presence_colour_off(console, string_from_resource_presence(presence)); } else { cons_show(accounts[i]); } @@ -1519,13 +1499,13 @@ cons_show_account(ProfAccount *account) Resource *resource = ordered_resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); window_show_time(console, '-'); - _presence_colour_on(win, resource_presence); + window_presence_colour_on(console, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { wprintw(win, ", \"%s\"", resource->status); } wprintw(win, "\n"); - _presence_colour_off(win, resource_presence); + window_presence_colour_off(console, resource_presence); if (resource->caps_str != NULL) { Capabilities *caps = caps_get(resource->caps_str); @@ -2226,42 +2206,6 @@ _win_resize_all(void) prefresh(current->win, current->y_pos, 0, 1, 0, rows-3, cols-1); } -static void -_presence_colour_on(WINDOW *win, const char * const presence) -{ - if (g_strcmp0(presence, "online") == 0) { - wattron(win, COLOUR_ONLINE); - } else if (g_strcmp0(presence, "away") == 0) { - wattron(win, COLOUR_AWAY); - } else if (g_strcmp0(presence, "chat") == 0) { - wattron(win, COLOUR_CHAT); - } else if (g_strcmp0(presence, "dnd") == 0) { - wattron(win, COLOUR_DND); - } else if (g_strcmp0(presence, "xa") == 0) { - wattron(win, COLOUR_XA); - } else { - wattron(win, COLOUR_OFFLINE); - } -} - -static void -_presence_colour_off(WINDOW *win, const char * const presence) -{ - if (g_strcmp0(presence, "online") == 0) { - wattroff(win, COLOUR_ONLINE); - } else if (g_strcmp0(presence, "away") == 0) { - wattroff(win, COLOUR_AWAY); - } else if (g_strcmp0(presence, "chat") == 0) { - wattroff(win, COLOUR_CHAT); - } else if (g_strcmp0(presence, "dnd") == 0) { - wattroff(win, COLOUR_DND); - } else if (g_strcmp0(presence, "xa") == 0) { - wattroff(win, COLOUR_XA); - } else { - wattroff(win, COLOUR_OFFLINE); - } -} - static void _show_status_string(ProfWin *window, const char * const from, const char * const show, const char * const status, @@ -2376,7 +2320,7 @@ _win_show_contact(ProfWin *window, PContact contact) GDateTime *last_activity = p_contact_last_activity(contact); window_show_time(window, '-'); - _presence_colour_on(window->win, presence); + window_presence_colour_on(window, presence); wprintw(window->win, "%s", barejid); if (name != NULL) { @@ -2410,7 +2354,7 @@ _win_show_contact(ProfWin *window, PContact contact) } wprintw(window->win, "\n"); - _presence_colour_off(window->win, presence); + window_presence_colour_off(window, presence); } static void @@ -2559,12 +2503,12 @@ _win_show_info(ProfWin *window, PContact pcontact) window_show_time(window, '-'); wprintw(win, "\n"); window_show_time(window, '-'); - _presence_colour_on(win, presence); + window_presence_colour_on(window, presence); wprintw(win, "%s", barejid); if (name != NULL) { wprintw(win, " (%s)", name); } - _presence_colour_off(win, presence); + window_presence_colour_off(window, presence); wprintw(win, ":\n"); if (sub != NULL) { @@ -2614,13 +2558,13 @@ _win_show_info(ProfWin *window, PContact pcontact) Resource *resource = ordered_resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); window_show_time(window, '-'); - _presence_colour_on(win, resource_presence); + window_presence_colour_on(window, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { wprintw(win, ", \"%s\"", resource->status); } wprintw(win, "\n"); - _presence_colour_off(win, resource_presence); + window_presence_colour_off(window, resource_presence); if (resource->caps_str != NULL) { Capabilities *caps = caps_get(resource->caps_str); From 867774ce570b087e1874b0efc58d8f64e3909280 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 00:32:31 +0100 Subject: [PATCH 04/37] Moved cons_show_wins() to console module --- src/ui/console.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ src/ui/ui.h | 4 +++ src/ui/windows.c | 77 --------------------------------------------- 3 files changed, 86 insertions(+), 77 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 52dac651..5d7cc393 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -31,6 +31,7 @@ #include "common.h" #include "config/preferences.h" +#include "contact_list.h" #include "config/theme.h" #include "ui/window.h" #include "ui/ui.h" @@ -119,6 +120,9 @@ cons_about(void) prefresh(console->win, 0, 0, 1, 0, rows-3, cols-1); dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } } void @@ -146,6 +150,9 @@ cons_check_version(gboolean not_available_msg) } dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } } } } @@ -167,6 +174,81 @@ cons_show_login_success(ProfAccount *account) wprintw(console->win, ".\n"); } +void +cons_show_wins(void) +{ + int i = 0; + int count = 0; + + cons_show(""); + cons_show("Active windows:"); + window_show_time(console, '-'); + wprintw(console->win, "1: Console\n"); + + for (i = 1; i < NUM_WINS; i++) { + if (windows[i] != NULL) { + count++; + } + } + + if (count != 0) { + for (i = 1; i < NUM_WINS; i++) { + if (windows[i] != NULL) { + ProfWin *window = windows[i]; + window_show_time(console, '-'); + + switch (window->type) + { + case WIN_CHAT: + wprintw(console->win, "%d: chat %s", i + 1, window->from); + PContact contact = contact_list_get_contact(window->from); + + if (contact != NULL) { + if (p_contact_name(contact) != NULL) { + wprintw(console->win, " (%s)", p_contact_name(contact)); + } + wprintw(console->win, " - %s", p_contact_presence(contact)); + } + + if (window->unread > 0) { + wprintw(console->win, ", %d unread", window->unread); + } + + break; + + case WIN_PRIVATE: + wprintw(console->win, "%d: private %s", i + 1, window->from); + + if (window->unread > 0) { + wprintw(console->win, ", %d unread", window->unread); + } + + break; + + case WIN_MUC: + wprintw(console->win, "%d: room %s", i + 1, window->from); + + if (window->unread > 0) { + wprintw(console->win, ", %d unread", window->unread); + } + + break; + + default: + break; + } + + wprintw(console->win, "\n"); + } + } + } + + cons_show(""); + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} static void _cons_splash_logo(void) diff --git a/src/ui/ui.h b/src/ui/ui.h index b324f8c3..de217006 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -40,6 +40,10 @@ #include "xmpp/xmpp.h" #define INP_WIN_MAX 1000 +#define NUM_WINS 10 + +// holds console at index 0 and chat wins 1 through to 9 +ProfWin* windows[NUM_WINS]; // gui startup and shutdown, resize void ui_init(void); diff --git a/src/ui/windows.c b/src/ui/windows.c index 77390751..d597185d 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -53,11 +53,6 @@ #include "ui/ui.h" #include "ui/window.h" -#define NUM_WINS 10 - -// holds console at index 0 and chat wins 1 through to 9 -static ProfWin* windows[NUM_WINS]; - // the window currently being displayed static int current_index = 0; static ProfWin *current; @@ -1113,78 +1108,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } -void -cons_show_wins(void) -{ - int i = 0; - int count = 0; - - cons_show(""); - cons_show("Active windows:"); - window_show_time(console, '-'); - wprintw(console->win, "1: Console\n"); - - for (i = 1; i < NUM_WINS; i++) { - if (windows[i] != NULL) { - count++; - } - } - - if (count != 0) { - for (i = 1; i < NUM_WINS; i++) { - if (windows[i] != NULL) { - ProfWin *window = windows[i]; - window_show_time(console, '-'); - - switch (window->type) - { - case WIN_CHAT: - wprintw(console->win, "%d: chat %s", i + 1, window->from); - PContact contact = contact_list_get_contact(window->from); - - if (contact != NULL) { - if (p_contact_name(contact) != NULL) { - wprintw(console->win, " (%s)", p_contact_name(contact)); - } - wprintw(console->win, " - %s", p_contact_presence(contact)); - } - - if (window->unread > 0) { - wprintw(console->win, ", %d unread", window->unread); - } - - break; - - case WIN_PRIVATE: - wprintw(console->win, "%d: private %s", i + 1, window->from); - - if (window->unread > 0) { - wprintw(console->win, ", %d unread", window->unread); - } - - break; - - case WIN_MUC: - wprintw(console->win, "%d: room %s", i + 1, window->from); - - if (window->unread > 0) { - wprintw(console->win, ", %d unread", window->unread); - } - - break; - - default: - break; - } - - wprintw(console->win, "\n"); - } - } - } - - cons_show(""); -} - void cons_show_info(PContact pcontact) { From a3c241b3a861e246555c08cdf6f9811082a41017 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 00:39:42 +0100 Subject: [PATCH 05/37] Moved cons_show_info() to console module --- src/ui/console.c | 134 ++++++++++++++++++++++++++++++++++++++++++++ src/ui/windows.c | 141 ----------------------------------------------- 2 files changed, 134 insertions(+), 141 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 5d7cc393..675f4ab0 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -250,6 +250,140 @@ cons_show_wins(void) } } +void +cons_show_info(PContact pcontact) +{ + const char *barejid = p_contact_barejid(pcontact); + const char *name = p_contact_name(pcontact); + const char *presence = p_contact_presence(pcontact); + const char *sub = p_contact_subscription(pcontact); + GList *resources = p_contact_get_available_resources(pcontact); + GList *ordered_resources = NULL; + GDateTime *last_activity = p_contact_last_activity(pcontact); + WINDOW *win = console->win; + + window_show_time(console, '-'); + wprintw(win, "\n"); + window_show_time(console, '-'); + window_presence_colour_on(console, presence); + wprintw(win, "%s", barejid); + if (name != NULL) { + wprintw(win, " (%s)", name); + } + window_presence_colour_off(console, presence); + wprintw(win, ":\n"); + + if (sub != NULL) { + window_show_time(console, '-'); + wprintw(win, "Subscription: %s\n", sub); + } + + if (last_activity != NULL) { + GDateTime *now = g_date_time_new_now_local(); + GTimeSpan span = g_date_time_difference(now, last_activity); + + window_show_time(console, '-'); + wprintw(win, "Last activity: "); + + int hours = span / G_TIME_SPAN_HOUR; + span = span - hours * G_TIME_SPAN_HOUR; + if (hours > 0) { + wprintw(win, "%dh", hours); + } + + int minutes = span / G_TIME_SPAN_MINUTE; + span = span - minutes * G_TIME_SPAN_MINUTE; + wprintw(win, "%dm", minutes); + + int seconds = span / G_TIME_SPAN_SECOND; + wprintw(win, "%ds", seconds); + + wprintw(win, "\n"); + + g_date_time_unref(now); + } + + if (resources != NULL) { + window_show_time(console, '-'); + wprintw(win, "Resources:\n"); + + // sort in order of availabiltiy + while (resources != NULL) { + Resource *resource = resources->data; + ordered_resources = g_list_insert_sorted(ordered_resources, + resource, (GCompareFunc)resource_compare_availability); + resources = g_list_next(resources); + } + } + + while (ordered_resources != NULL) { + Resource *resource = ordered_resources->data; + const char *resource_presence = string_from_resource_presence(resource->presence); + window_show_time(console, '-'); + window_presence_colour_on(console, resource_presence); + wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); + if (resource->status != NULL) { + wprintw(win, ", \"%s\"", resource->status); + } + wprintw(win, "\n"); + window_presence_colour_off(console, resource_presence); + + if (resource->caps_str != NULL) { + Capabilities *caps = caps_get(resource->caps_str); + if (caps != NULL) { + // show identity + if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { + window_show_time(console, '-'); + wprintw(win, " Identity: "); + if (caps->name != NULL) { + wprintw(win, "%s", caps->name); + if ((caps->category != NULL) || (caps->type != NULL)) { + wprintw(win, " "); + } + } + if (caps->type != NULL) { + wprintw(win, "%s", caps->type); + if (caps->category != NULL) { + wprintw(win, " "); + } + } + if (caps->category != NULL) { + wprintw(win, "%s", caps->category); + } + wprintw(win, "\n"); + } + if (caps->software != NULL) { + window_show_time(console, '-'); + wprintw(win, " Software: %s", caps->software); + } + if (caps->software_version != NULL) { + wprintw(win, ", %s", caps->software_version); + } + if ((caps->software != NULL) || (caps->software_version != NULL)) { + wprintw(win, "\n"); + } + if (caps->os != NULL) { + window_show_time(console, '-'); + wprintw(win, " OS: %s", caps->os); + } + if (caps->os_version != NULL) { + wprintw(win, ", %s", caps->os_version); + } + if ((caps->os != NULL) || (caps->os_version != NULL)) { + wprintw(win, "\n"); + } + } + } + + ordered_resources = g_list_next(ordered_resources); + } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + static void _cons_splash_logo(void) { diff --git a/src/ui/windows.c b/src/ui/windows.c index d597185d..8f329cb0 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -94,7 +94,6 @@ static void _win_resize_all(void); static gint _win_get_unread(void); static void _win_show_history(WINDOW *win, int win_index, const char * const contact); -static void _win_show_info(ProfWin *window, PContact pcontact); static void _ui_draw_win_title(void); static void _notify(const char * const message, int timeout, @@ -1107,17 +1106,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } - -void -cons_show_info(PContact pcontact) -{ - _win_show_info(console, pcontact); - - if (current_index != 0) { - status_bar_new(0); - } -} - void cons_show_caps(const char * const contact, Resource *resource) { @@ -2411,135 +2399,6 @@ _win_show_history(WINDOW *win, int win_index, const char * const contact) } } -static void -_win_show_info(ProfWin *window, PContact pcontact) -{ - const char *barejid = p_contact_barejid(pcontact); - const char *name = p_contact_name(pcontact); - const char *presence = p_contact_presence(pcontact); - const char *sub = p_contact_subscription(pcontact); - GList *resources = p_contact_get_available_resources(pcontact); - GList *ordered_resources = NULL; - GDateTime *last_activity = p_contact_last_activity(pcontact); - WINDOW *win = window->win; - - window_show_time(window, '-'); - wprintw(win, "\n"); - window_show_time(window, '-'); - window_presence_colour_on(window, presence); - wprintw(win, "%s", barejid); - if (name != NULL) { - wprintw(win, " (%s)", name); - } - window_presence_colour_off(window, presence); - wprintw(win, ":\n"); - - if (sub != NULL) { - window_show_time(window, '-'); - wprintw(win, "Subscription: %s\n", sub); - } - - if (last_activity != NULL) { - GDateTime *now = g_date_time_new_now_local(); - GTimeSpan span = g_date_time_difference(now, last_activity); - - window_show_time(window, '-'); - wprintw(win, "Last activity: "); - - int hours = span / G_TIME_SPAN_HOUR; - span = span - hours * G_TIME_SPAN_HOUR; - if (hours > 0) { - wprintw(win, "%dh", hours); - } - - int minutes = span / G_TIME_SPAN_MINUTE; - span = span - minutes * G_TIME_SPAN_MINUTE; - wprintw(win, "%dm", minutes); - - int seconds = span / G_TIME_SPAN_SECOND; - wprintw(win, "%ds", seconds); - - wprintw(win, "\n"); - - g_date_time_unref(now); - } - - if (resources != NULL) { - window_show_time(window, '-'); - wprintw(win, "Resources:\n"); - - // sort in order of availabiltiy - while (resources != NULL) { - Resource *resource = resources->data; - ordered_resources = g_list_insert_sorted(ordered_resources, - resource, (GCompareFunc)resource_compare_availability); - resources = g_list_next(resources); - } - } - - while (ordered_resources != NULL) { - Resource *resource = ordered_resources->data; - const char *resource_presence = string_from_resource_presence(resource->presence); - window_show_time(window, '-'); - window_presence_colour_on(window, resource_presence); - wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); - if (resource->status != NULL) { - wprintw(win, ", \"%s\"", resource->status); - } - wprintw(win, "\n"); - window_presence_colour_off(window, resource_presence); - - if (resource->caps_str != NULL) { - Capabilities *caps = caps_get(resource->caps_str); - if (caps != NULL) { - // show identity - if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - window_show_time(window, '-'); - wprintw(win, " Identity: "); - if (caps->name != NULL) { - wprintw(win, "%s", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { - wprintw(win, " "); - } - } - if (caps->type != NULL) { - wprintw(win, "%s", caps->type); - if (caps->category != NULL) { - wprintw(win, " "); - } - } - if (caps->category != NULL) { - wprintw(win, "%s", caps->category); - } - wprintw(win, "\n"); - } - if (caps->software != NULL) { - window_show_time(window, '-'); - wprintw(win, " Software: %s", caps->software); - } - if (caps->software_version != NULL) { - wprintw(win, ", %s", caps->software_version); - } - if ((caps->software != NULL) || (caps->software_version != NULL)) { - wprintw(win, "\n"); - } - if (caps->os != NULL) { - window_show_time(window, '-'); - wprintw(win, " OS: %s", caps->os); - } - if (caps->os_version != NULL) { - wprintw(win, ", %s", caps->os_version); - } - if ((caps->os != NULL) || (caps->os_version != NULL)) { - wprintw(win, "\n"); - } - } - } - - ordered_resources = g_list_next(ordered_resources); - } -} - void _set_current(int index) { From d5bb600a0406cec84c0a5f780b1e39d3f1d44000 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 00:47:05 +0100 Subject: [PATCH 06/37] Moved cons_show_caps() to console module --- src/ui/console.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ src/ui/windows.c | 80 ------------------------------------------------ 2 files changed, 76 insertions(+), 80 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 675f4ab0..54533ec5 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -384,6 +384,82 @@ cons_show_info(PContact pcontact) } } +void +cons_show_caps(const char * const contact, Resource *resource) +{ + WINDOW *win = console->win; + cons_show(""); + const char *resource_presence = string_from_resource_presence(resource->presence); + window_show_time(console, '-'); + window_presence_colour_on(console, resource_presence); + wprintw(console->win, "%s", contact); + window_presence_colour_off(console, resource_presence); + wprintw(win, ":\n"); + + if (resource->caps_str != NULL) { + Capabilities *caps = caps_get(resource->caps_str); + if (caps != NULL) { + // show identity + if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { + window_show_time(console, '-'); + wprintw(win, "Identity: "); + if (caps->name != NULL) { + wprintw(win, "%s", caps->name); + if ((caps->category != NULL) || (caps->type != NULL)) { + wprintw(win, " "); + } + } + if (caps->type != NULL) { + wprintw(win, "%s", caps->type); + if (caps->category != NULL) { + wprintw(win, " "); + } + } + if (caps->category != NULL) { + wprintw(win, "%s", caps->category); + } + wprintw(win, "\n"); + } + if (caps->software != NULL) { + window_show_time(console, '-'); + wprintw(win, "Software: %s", caps->software); + } + if (caps->software_version != NULL) { + wprintw(win, ", %s", caps->software_version); + } + if ((caps->software != NULL) || (caps->software_version != NULL)) { + wprintw(win, "\n"); + } + if (caps->os != NULL) { + window_show_time(console, '-'); + wprintw(win, "OS: %s", caps->os); + } + if (caps->os_version != NULL) { + wprintw(win, ", %s", caps->os_version); + } + if ((caps->os != NULL) || (caps->os_version != NULL)) { + wprintw(win, "\n"); + } + + if (caps->features != NULL) { + window_show_time(console, '-'); + wprintw(win, "Features:\n"); + GSList *feature = caps->features; + while (feature != NULL) { + window_show_time(console, '-'); + wprintw(win, " %s\n", feature->data); + feature = g_slist_next(feature); + } + } + } + } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + static void _cons_splash_logo(void) { diff --git a/src/ui/windows.c b/src/ui/windows.c index 8f329cb0..8dd9c1d1 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1106,86 +1106,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } -void -cons_show_caps(const char * const contact, Resource *resource) -{ - WINDOW *win = console->win; - cons_show(""); - const char *resource_presence = string_from_resource_presence(resource->presence); - window_show_time(console, '-'); - window_presence_colour_on(console, resource_presence); - wprintw(console->win, "%s", contact); - window_presence_colour_off(console, resource_presence); - wprintw(win, ":\n"); - - if (resource->caps_str != NULL) { - log_debug("Getting caps, caps_str: %s", resource->caps_str); - Capabilities *caps = caps_get(resource->caps_str); - if (caps != NULL) { - // show identity - if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - window_show_time(console, '-'); - wprintw(win, "Identity: "); - if (caps->name != NULL) { - wprintw(win, "%s", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { - wprintw(win, " "); - } - } - if (caps->type != NULL) { - wprintw(win, "%s", caps->type); - if (caps->category != NULL) { - wprintw(win, " "); - } - } - if (caps->category != NULL) { - wprintw(win, "%s", caps->category); - } - wprintw(win, "\n"); - } - if (caps->software != NULL) { - window_show_time(console, '-'); - wprintw(win, "Software: %s", caps->software); - } - if (caps->software_version != NULL) { - wprintw(win, ", %s", caps->software_version); - } - if ((caps->software != NULL) || (caps->software_version != NULL)) { - wprintw(win, "\n"); - } - if (caps->os != NULL) { - window_show_time(console, '-'); - wprintw(win, "OS: %s", caps->os); - } - if (caps->os_version != NULL) { - wprintw(win, ", %s", caps->os_version); - } - if ((caps->os != NULL) || (caps->os_version != NULL)) { - wprintw(win, "\n"); - } - - if (caps->features != NULL) { - window_show_time(console, '-'); - wprintw(win, "Features:\n"); - GSList *feature = caps->features; - while (feature != NULL) { - window_show_time(console, '-'); - wprintw(win, " %s\n", feature->data); - feature = g_slist_next(feature); - } - } - } - } else { - log_debug("No caps string found in resource"); - } - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } -} - void cons_show_software_version(const char * const jid, const char * const presence, const char * const name, const char * const version, const char * const os) From b9dedbdc1548c09e515dd1388149c494bf2e4dda Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 00:50:38 +0100 Subject: [PATCH 07/37] Moved cons_show_software_version() to console module --- src/ui/console.c | 28 ++++++++++++++++++++++++++++ src/ui/windows.c | 23 ----------------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 54533ec5..425b6f3a 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -460,6 +460,34 @@ cons_show_caps(const char * const contact, Resource *resource) } } +void +cons_show_software_version(const char * const jid, const char * const presence, + const char * const name, const char * const version, const char * const os) +{ + if ((name != NULL) || (version != NULL) || (os != NULL)) { + cons_show(""); + window_show_time(console, '-'); + window_presence_colour_on(console, presence); + wprintw(console->win, "%s", jid); + window_presence_colour_off(console, presence); + wprintw(console->win, ":\n"); + } + if (name != NULL) { + cons_show("Name : %s", name); + } + if (version != NULL) { + cons_show("Version : %s", version); + } + if (os != NULL) { + cons_show("OS : %s", os); + } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + static void _cons_splash_logo(void) { diff --git a/src/ui/windows.c b/src/ui/windows.c index 8dd9c1d1..529c9a0e 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1106,29 +1106,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } -void -cons_show_software_version(const char * const jid, const char * const presence, - const char * const name, const char * const version, const char * const os) -{ - if ((name != NULL) || (version != NULL) || (os != NULL)) { - cons_show(""); - window_show_time(console, '-'); - window_presence_colour_on(console, presence); - wprintw(console->win, "%s", jid); - window_presence_colour_off(console, presence); - wprintw(console->win, ":\n"); - } - if (name != NULL) { - cons_show("Name : %s", name); - } - if (version != NULL) { - cons_show("Version : %s", version); - } - if (os != NULL) { - cons_show("OS : %s", os); - } -} - void cons_show_room_list(GSList *rooms, const char * const conference_node) { From d6c2bd0c6afbfc2e050a11b95a1d36f88a590188 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 00:54:23 +0100 Subject: [PATCH 08/37] Moved cons_show_room_list() to console module --- src/ui/console.c | 25 +++++++++++++++++++++++++ src/ui/windows.c | 20 -------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 425b6f3a..d9f42e89 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -488,6 +488,31 @@ cons_show_software_version(const char * const jid, const char * const presence, } } +void +cons_show_room_list(GSList *rooms, const char * const conference_node) +{ + if ((rooms != NULL) && (g_slist_length(rooms) > 0)) { + cons_show("Chat rooms at %s:", conference_node); + while (rooms != NULL) { + DiscoItem *room = rooms->data; + window_show_time(console, '-'); + wprintw(console->win, " %s", room->jid); + if (room->name != NULL) { + wprintw(console->win, ", (%s)", room->name); + } + wprintw(console->win, "\n"); + rooms = g_slist_next(rooms); + } + } else { + cons_show("No chat rooms at %s", conference_node); + } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + static void _cons_splash_logo(void) { diff --git a/src/ui/windows.c b/src/ui/windows.c index 529c9a0e..66da6316 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1106,26 +1106,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } -void -cons_show_room_list(GSList *rooms, const char * const conference_node) -{ - if ((rooms != NULL) && (g_slist_length(rooms) > 0)) { - cons_show("Chat rooms at %s:", conference_node); - while (rooms != NULL) { - DiscoItem *room = rooms->data; - window_show_time(console, '-'); - wprintw(console->win, " %s", room->jid); - if (room->name != NULL) { - wprintw(console->win, ", (%s)", room->name); - } - wprintw(console->win, "\n"); - rooms = g_slist_next(rooms); - } - } else { - cons_show("No chat rooms at %s", conference_node); - } -} - void cons_show_disco_info(const char *jid, GSList *identities, GSList *features) { From d7cc54db6302155fe7e1670b510496f8db40c9ac Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:00:03 +0100 Subject: [PATCH 09/37] Moved cons_show_disco_info() and cons_show_disco_items() to console module --- src/ui/console.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ src/ui/windows.c | 62 ------------------------------------------ 2 files changed, 71 insertions(+), 62 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index d9f42e89..41b189c2 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -513,6 +513,77 @@ cons_show_room_list(GSList *rooms, const char * const conference_node) } } +void +cons_show_disco_info(const char *jid, GSList *identities, GSList *features) +{ + if (((identities != NULL) && (g_slist_length(identities) > 0)) || + ((features != NULL) && (g_slist_length(features) > 0))) { + cons_show(""); + cons_show("Service disovery info for %s", jid); + + if (identities != NULL) { + cons_show(" Identities"); + } + while (identities != NULL) { + DiscoIdentity *identity = identities->data; // anme trpe, cat + GString *identity_str = g_string_new(" "); + if (identity->name != NULL) { + identity_str = g_string_append(identity_str, strdup(identity->name)); + identity_str = g_string_append(identity_str, " "); + } + if (identity->type != NULL) { + identity_str = g_string_append(identity_str, strdup(identity->type)); + identity_str = g_string_append(identity_str, " "); + } + if (identity->category != NULL) { + identity_str = g_string_append(identity_str, strdup(identity->category)); + } + cons_show(identity_str->str); + g_string_free(identity_str, FALSE); + identities = g_slist_next(identities); + } + + if (features != NULL) { + cons_show(" Features:"); + } + while (features != NULL) { + cons_show(" %s", features->data); + features = g_slist_next(features); + } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } + } +} + +void +cons_show_disco_items(GSList *items, const char * const jid) +{ + if ((items != NULL) && (g_slist_length(items) > 0)) { + cons_show(""); + cons_show("Service discovery items for %s:", jid); + while (items != NULL) { + DiscoItem *item = items->data; + window_show_time(console, '-'); + wprintw(console->win, " %s", item->jid); + if (item->name != NULL) { + wprintw(console->win, ", (%s)", item->name); + } + wprintw(console->win, "\n"); + items = g_slist_next(items); + } + } else { + cons_show(""); + cons_show("No service discovery items for %s", jid); + } + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + static void _cons_splash_logo(void) { diff --git a/src/ui/windows.c b/src/ui/windows.c index 66da6316..c8252efa 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1106,68 +1106,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } -void -cons_show_disco_info(const char *jid, GSList *identities, GSList *features) -{ - if (((identities != NULL) && (g_slist_length(identities) > 0)) || - ((features != NULL) && (g_slist_length(features) > 0))) { - cons_show(""); - cons_show("Service disovery info for %s", jid); - - if (identities != NULL) { - cons_show(" Identities"); - } - while (identities != NULL) { - DiscoIdentity *identity = identities->data; // anme trpe, cat - GString *identity_str = g_string_new(" "); - if (identity->name != NULL) { - identity_str = g_string_append(identity_str, strdup(identity->name)); - identity_str = g_string_append(identity_str, " "); - } - if (identity->type != NULL) { - identity_str = g_string_append(identity_str, strdup(identity->type)); - identity_str = g_string_append(identity_str, " "); - } - if (identity->category != NULL) { - identity_str = g_string_append(identity_str, strdup(identity->category)); - } - cons_show(identity_str->str); - g_string_free(identity_str, FALSE); - identities = g_slist_next(identities); - } - - if (features != NULL) { - cons_show(" Features:"); - } - while (features != NULL) { - cons_show(" %s", features->data); - features = g_slist_next(features); - } - } -} - -void -cons_show_disco_items(GSList *items, const char * const jid) -{ - if ((items != NULL) && (g_slist_length(items) > 0)) { - cons_show(""); - cons_show("Service discovery items for %s:", jid); - while (items != NULL) { - DiscoItem *item = items->data; - window_show_time(console, '-'); - wprintw(console->win, " %s", item->jid); - if (item->name != NULL) { - wprintw(console->win, ", (%s)", item->name); - } - wprintw(console->win, "\n"); - items = g_slist_next(items); - } - } else { - cons_show(""); - cons_show("No service discovery items for %s", jid); - } -} - void cons_show_status(const char * const contact) { From 688eea083bd25af39d11b6f993b0d1bf02535959 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:13:35 +0100 Subject: [PATCH 10/37] Moved cons_show_status() to console module --- src/ui/console.c | 12 +++++++++ src/ui/window.c | 46 ++++++++++++++++++++++++++++++++ src/ui/window.h | 3 +++ src/ui/windows.c | 68 +++--------------------------------------------- 4 files changed, 65 insertions(+), 64 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 41b189c2..727fb606 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -584,6 +584,18 @@ cons_show_disco_items(GSList *items, const char * const jid) } } +void +cons_show_status(const char * const contact) +{ + PContact pcontact = contact_list_get_contact(contact); + + if (pcontact != NULL) { + window_show_contact(console, pcontact); + } else { + cons_show("No such contact \"%s\" in roster.", contact); + } +} + static void _cons_splash_logo(void) { diff --git a/src/ui/window.c b/src/ui/window.c index d07ce989..01eea071 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -113,3 +113,49 @@ window_presence_colour_off(ProfWin *window, const char * const presence) } } +void +window_show_contact(ProfWin *window, PContact contact) +{ + const char *barejid = p_contact_barejid(contact); + const char *name = p_contact_name(contact); + const char *presence = p_contact_presence(contact); + const char *status = p_contact_status(contact); + GDateTime *last_activity = p_contact_last_activity(contact); + + window_show_time(window, '-'); + window_presence_colour_on(window, presence); + wprintw(window->win, "%s", barejid); + + if (name != NULL) { + wprintw(window->win, " (%s)", name); + } + + wprintw(window->win, " is %s", presence); + + if (last_activity != NULL) { + GDateTime *now = g_date_time_new_now_local(); + GTimeSpan span = g_date_time_difference(now, last_activity); + + wprintw(window->win, ", idle "); + + int hours = span / G_TIME_SPAN_HOUR; + span = span - hours * G_TIME_SPAN_HOUR; + if (hours > 0) { + wprintw(window->win, "%dh", hours); + } + + int minutes = span / G_TIME_SPAN_MINUTE; + span = span - minutes * G_TIME_SPAN_MINUTE; + wprintw(window->win, "%dm", minutes); + + int seconds = span / G_TIME_SPAN_SECOND; + wprintw(window->win, "%ds", seconds); + } + + if (status != NULL) { + wprintw(window->win, ", \"%s\"", p_contact_status(contact)); + } + + wprintw(window->win, "\n"); + window_presence_colour_off(window, presence); +} diff --git a/src/ui/window.h b/src/ui/window.h index 2793cd42..5c2e22d5 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -23,6 +23,8 @@ #ifndef WINDOW_H #define WINDOW_H +#include "contact.h" + #define PAD_SIZE 1000 typedef enum { @@ -49,5 +51,6 @@ void window_free(ProfWin *window); void window_show_time(ProfWin *window, char show_char); void window_presence_colour_on(ProfWin *window, const char * const presence); void window_presence_colour_off(ProfWin *window, const char * const presence); +void window_show_contact(ProfWin *window, PContact contact); #endif diff --git a/src/ui/windows.c b/src/ui/windows.c index c8252efa..9ae361f7 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -74,7 +74,6 @@ static GTimer *ui_idle_time; static void _set_current(int index); static void _cons_show_basic_help(void); -static void _win_show_contact(ProfWin *window, PContact contact); static int _find_prof_win_index(const char * const contact); static int _new_prof_win(const char * const contact, win_type_t type); static void _current_window_refresh(void); @@ -1106,18 +1105,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } -void -cons_show_status(const char * const contact) -{ - PContact pcontact = contact_list_get_contact(contact); - - if (pcontact != NULL) { - _win_show_contact(console, pcontact); - } else { - cons_show("No such contact \"%s\" in roster.", contact); - } -} - void cons_show_room_invite(const char * const invitor, const char * const room, const char * const reason) @@ -1292,7 +1279,7 @@ win_show_status(void) PContact pcontact = contact_list_get_contact(recipient); if (pcontact != NULL) { - _win_show_contact(current, pcontact); + window_show_contact(current, pcontact); } else { win_current_show("Error getting contact info."); } @@ -1306,7 +1293,7 @@ win_private_show_status(void) PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart); if (pcontact != NULL) { - _win_show_contact(current, pcontact); + window_show_contact(current, pcontact); } else { win_current_show("Error getting contact info."); } @@ -1320,7 +1307,7 @@ win_room_show_status(const char * const contact) PContact pcontact = muc_get_participant(win_current_get_recipient(), contact); if (pcontact != NULL) { - _win_show_contact(current, pcontact); + window_show_contact(current, pcontact); } else { win_current_show("No such participant \"%s\" in room.", contact); } @@ -1667,7 +1654,7 @@ cons_show_contacts(GSList *list) while(curr) { PContact contact = curr->data; if (strcmp(p_contact_subscription(contact), "none") != 0) { - _win_show_contact(console, contact); + window_show_contact(console, contact); } curr = g_slist_next(curr); } @@ -2036,53 +2023,6 @@ _cons_show_incoming_message(const char * const short_from, const int win_index) wattroff(console->win, COLOUR_INCOMING); } -static void -_win_show_contact(ProfWin *window, PContact contact) -{ - const char *barejid = p_contact_barejid(contact); - const char *name = p_contact_name(contact); - const char *presence = p_contact_presence(contact); - const char *status = p_contact_status(contact); - GDateTime *last_activity = p_contact_last_activity(contact); - - window_show_time(window, '-'); - window_presence_colour_on(window, presence); - wprintw(window->win, "%s", barejid); - - if (name != NULL) { - wprintw(window->win, " (%s)", name); - } - - wprintw(window->win, " is %s", presence); - - if (last_activity != NULL) { - GDateTime *now = g_date_time_new_now_local(); - GTimeSpan span = g_date_time_difference(now, last_activity); - - wprintw(window->win, ", idle "); - - int hours = span / G_TIME_SPAN_HOUR; - span = span - hours * G_TIME_SPAN_HOUR; - if (hours > 0) { - wprintw(window->win, "%dh", hours); - } - - int minutes = span / G_TIME_SPAN_MINUTE; - span = span - minutes * G_TIME_SPAN_MINUTE; - wprintw(window->win, "%dm", minutes); - - int seconds = span / G_TIME_SPAN_SECOND; - wprintw(window->win, "%ds", seconds); - } - - if (status != NULL) { - wprintw(window->win, ", \"%s\"", p_contact_status(contact)); - } - - wprintw(window->win, "\n"); - window_presence_colour_off(window, presence); -} - static void _win_handle_switch(const wint_t * const ch) { From 60acd4778020fac0e0207f242304323e2aa56cb8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:15:10 +0100 Subject: [PATCH 11/37] Moved cons_show_room_invite() to console module --- src/ui/console.c | 31 +++++++++++++++++++++++++++++++ src/ui/windows.c | 31 ------------------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 727fb606..05be9928 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -596,6 +596,37 @@ cons_show_status(const char * const contact) } } +void +cons_show_room_invite(const char * const invitor, const char * const room, + const char * const reason) +{ + char *display_room = NULL; + char *domain = strdup(jabber_get_domain()); + Jid *room_jid = jid_create(room); + GString *default_service = g_string_new("conference."); + g_string_append(default_service, domain); + + cons_show(""); + cons_show("Chat room invite received:"); + cons_show(" From : %s", invitor); + cons_show(" Room : %s", room); + + if (reason != NULL) { + cons_show(" Message: %s", reason); + } + + if (strcmp(room_jid->domainpart, default_service->str) == 0) { + display_room = room_jid->localpart; + } else { + display_room = room_jid->barejid; + } + + cons_show("Type \"/join %s\" to accept the invitation", display_room); + + jid_destroy(room_jid); + g_string_free(default_service, TRUE); +} + static void _cons_splash_logo(void) { diff --git a/src/ui/windows.c b/src/ui/windows.c index 9ae361f7..f9cd343b 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1105,37 +1105,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } -void -cons_show_room_invite(const char * const invitor, const char * const room, - const char * const reason) -{ - char *display_room = NULL; - char *domain = strdup(jabber_get_domain()); - Jid *room_jid = jid_create(room); - GString *default_service = g_string_new("conference."); - g_string_append(default_service, domain); - - cons_show(""); - cons_show("Chat room invite received:"); - cons_show(" From : %s", invitor); - cons_show(" Room : %s", room); - - if (reason != NULL) { - cons_show(" Message: %s", reason); - } - - if (strcmp(room_jid->domainpart, default_service->str) == 0) { - display_room = room_jid->localpart; - } else { - display_room = room_jid->barejid; - } - - cons_show("Type \"/join %s\" to accept the invitation", display_room); - - jid_destroy(room_jid); - g_string_free(default_service, TRUE); -} - void cons_show_account_list(gchar **accounts) { From 996ba8181be0eece76985dc866daea5b6797e62b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:18:04 +0100 Subject: [PATCH 12/37] Moved cons_show_account_list() to console module --- src/ui/console.c | 36 ++++++++++++++++++++++++++++++++++++ src/ui/windows.c | 26 -------------------------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 05be9928..13a379ab 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -625,6 +625,42 @@ cons_show_room_invite(const char * const invitor, const char * const room, jid_destroy(room_jid); g_string_free(default_service, TRUE); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_show_account_list(gchar **accounts) +{ + int size = g_strv_length(accounts); + if (size > 0) { + cons_show("Accounts:"); + int i = 0; + for (i = 0; i < size; i++) { + if ((jabber_get_connection_status() == JABBER_CONNECTED) && + (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) { + resource_presence_t presence = accounts_get_last_presence(accounts[i]); + window_show_time(console, '-'); + window_presence_colour_on(console, string_from_resource_presence(presence)); + wprintw(console->win, "%s\n", accounts[i]); + window_presence_colour_off(console, string_from_resource_presence(presence)); + } else { + cons_show(accounts[i]); + } + } + cons_show(""); + } else { + cons_show("No accounts created yet."); + cons_show(""); + } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } } static void diff --git a/src/ui/windows.c b/src/ui/windows.c index f9cd343b..b1820dba 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1105,32 +1105,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } -void -cons_show_account_list(gchar **accounts) -{ - int size = g_strv_length(accounts); - if (size > 0) { - cons_show("Accounts:"); - int i = 0; - for (i = 0; i < size; i++) { - if ((jabber_get_connection_status() == JABBER_CONNECTED) && - (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) { - resource_presence_t presence = accounts_get_last_presence(accounts[i]); - window_show_time(console, '-'); - window_presence_colour_on(console, string_from_resource_presence(presence)); - wprintw(console->win, "%s\n", accounts[i]); - window_presence_colour_off(console, string_from_resource_presence(presence)); - } else { - cons_show(accounts[i]); - } - } - cons_show(""); - } else { - cons_show("No accounts created yet."); - cons_show(""); - } -} - void cons_show_account(ProfAccount *account) { From 6253897ea7a8006c95a019578cf1c010c45c145a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:21:21 +0100 Subject: [PATCH 13/37] Moved cons_show_account() to console module --- src/ui/console.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++ src/ui/windows.c | 110 --------------------------------------------- 2 files changed, 115 insertions(+), 110 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 13a379ab..71075785 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -663,6 +663,121 @@ cons_show_account_list(gchar **accounts) } } +void +cons_show_account(ProfAccount *account) +{ + cons_show(""); + cons_show("Account %s:", account->name); + if (account->enabled) { + cons_show ("enabled : TRUE"); + } else { + cons_show ("enabled : FALSE"); + } + cons_show ("jid : %s", account->jid); + if (account->resource != NULL) { + cons_show ("resource : %s", account->resource); + } + if (account->server != NULL) { + cons_show ("server : %s", account->server); + } + if (account->last_presence != NULL) { + cons_show ("Last presence : %s", account->last_presence); + } + if (account->login_presence != NULL) { + cons_show ("Login presence : %s", account->login_presence); + } + cons_show ("Priority : chat:%d, online:%d, away:%d, xa:%d, dnd:%d", + account->priority_chat, account->priority_online, account->priority_away, + account->priority_xa, account->priority_dnd); + + if ((jabber_get_connection_status() == JABBER_CONNECTED) && + (g_strcmp0(jabber_get_account_name(), account->name) == 0)) { + GList *resources = jabber_get_available_resources(); + GList *ordered_resources = NULL; + + WINDOW *win = console->win; + if (resources != NULL) { + window_show_time(console, '-'); + wprintw(win, "Resources:\n"); + + // sort in order of availabiltiy + while (resources != NULL) { + Resource *resource = resources->data; + ordered_resources = g_list_insert_sorted(ordered_resources, + resource, (GCompareFunc)resource_compare_availability); + resources = g_list_next(resources); + } + } + + while (ordered_resources != NULL) { + Resource *resource = ordered_resources->data; + const char *resource_presence = string_from_resource_presence(resource->presence); + window_show_time(console, '-'); + window_presence_colour_on(console, resource_presence); + wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); + if (resource->status != NULL) { + wprintw(win, ", \"%s\"", resource->status); + } + wprintw(win, "\n"); + window_presence_colour_off(console, resource_presence); + + if (resource->caps_str != NULL) { + Capabilities *caps = caps_get(resource->caps_str); + if (caps != NULL) { + // show identity + if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { + window_show_time(console, '-'); + wprintw(win, " Identity: "); + if (caps->name != NULL) { + wprintw(win, "%s", caps->name); + if ((caps->category != NULL) || (caps->type != NULL)) { + wprintw(win, " "); + } + } + if (caps->type != NULL) { + wprintw(win, "%s", caps->type); + if (caps->category != NULL) { + wprintw(win, " "); + } + } + if (caps->category != NULL) { + wprintw(win, "%s", caps->category); + } + wprintw(win, "\n"); + } + if (caps->software != NULL) { + window_show_time(console, '-'); + wprintw(win, " Software: %s", caps->software); + } + if (caps->software_version != NULL) { + wprintw(win, ", %s", caps->software_version); + } + if ((caps->software != NULL) || (caps->software_version != NULL)) { + wprintw(win, "\n"); + } + if (caps->os != NULL) { + window_show_time(console, '-'); + wprintw(win, " OS: %s", caps->os); + } + if (caps->os_version != NULL) { + wprintw(win, ", %s", caps->os_version); + } + if ((caps->os != NULL) || (caps->os_version != NULL)) { + wprintw(win, "\n"); + } + } + } + + ordered_resources = g_list_next(ordered_resources); + } + } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + static void _cons_splash_logo(void) { diff --git a/src/ui/windows.c b/src/ui/windows.c index b1820dba..6a687db1 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1105,116 +1105,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } -void -cons_show_account(ProfAccount *account) -{ - cons_show(""); - cons_show("Account %s:", account->name); - if (account->enabled) { - cons_show ("enabled : TRUE"); - } else { - cons_show ("enabled : FALSE"); - } - cons_show ("jid : %s", account->jid); - if (account->resource != NULL) { - cons_show ("resource : %s", account->resource); - } - if (account->server != NULL) { - cons_show ("server : %s", account->server); - } - if (account->last_presence != NULL) { - cons_show ("Last presence : %s", account->last_presence); - } - if (account->login_presence != NULL) { - cons_show ("Login presence : %s", account->login_presence); - } - cons_show ("Priority : chat:%d, online:%d, away:%d, xa:%d, dnd:%d", - account->priority_chat, account->priority_online, account->priority_away, - account->priority_xa, account->priority_dnd); - - if ((jabber_get_connection_status() == JABBER_CONNECTED) && - (g_strcmp0(jabber_get_account_name(), account->name) == 0)) { - GList *resources = jabber_get_available_resources(); - GList *ordered_resources = NULL; - - WINDOW *win = console->win; - if (resources != NULL) { - window_show_time(console, '-'); - wprintw(win, "Resources:\n"); - - // sort in order of availabiltiy - while (resources != NULL) { - Resource *resource = resources->data; - ordered_resources = g_list_insert_sorted(ordered_resources, - resource, (GCompareFunc)resource_compare_availability); - resources = g_list_next(resources); - } - } - - while (ordered_resources != NULL) { - Resource *resource = ordered_resources->data; - const char *resource_presence = string_from_resource_presence(resource->presence); - window_show_time(console, '-'); - window_presence_colour_on(console, resource_presence); - wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); - if (resource->status != NULL) { - wprintw(win, ", \"%s\"", resource->status); - } - wprintw(win, "\n"); - window_presence_colour_off(console, resource_presence); - - if (resource->caps_str != NULL) { - Capabilities *caps = caps_get(resource->caps_str); - if (caps != NULL) { - // show identity - if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - window_show_time(console, '-'); - wprintw(win, " Identity: "); - if (caps->name != NULL) { - wprintw(win, "%s", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { - wprintw(win, " "); - } - } - if (caps->type != NULL) { - wprintw(win, "%s", caps->type); - if (caps->category != NULL) { - wprintw(win, " "); - } - } - if (caps->category != NULL) { - wprintw(win, "%s", caps->category); - } - wprintw(win, "\n"); - } - if (caps->software != NULL) { - window_show_time(console, '-'); - wprintw(win, " Software: %s", caps->software); - } - if (caps->software_version != NULL) { - wprintw(win, ", %s", caps->software_version); - } - if ((caps->software != NULL) || (caps->software_version != NULL)) { - wprintw(win, "\n"); - } - if (caps->os != NULL) { - window_show_time(console, '-'); - wprintw(win, " OS: %s", caps->os); - } - if (caps->os_version != NULL) { - wprintw(win, ", %s", caps->os_version); - } - if ((caps->os != NULL) || (caps->os_version != NULL)) { - wprintw(win, "\n"); - } - } - } - - ordered_resources = g_list_next(ordered_resources); - } - } -} - void win_show_status(void) { From b3ed4dd0feba6b707b156cc34d5464bc84889cf7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:25:10 +0100 Subject: [PATCH 14/37] Moved preferences display functions to console module --- src/ui/console.c | 243 +++++++++++++++++++++++++++++++++++++++++++++++ src/ui/windows.c | 213 ----------------------------------------- 2 files changed, 243 insertions(+), 213 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 71075785..59aa5df9 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -778,6 +778,249 @@ cons_show_account(ProfAccount *account) } } +void +cons_show_ui_prefs(void) +{ + cons_show("UI preferences:"); + cons_show(""); + + gchar *theme = prefs_get_string(PREF_THEME); + if (theme == NULL) { + cons_show("Theme (/theme) : default"); + } else { + cons_show("Theme (/theme) : %s", theme); + } + + if (prefs_get_boolean(PREF_BEEP)) + cons_show("Terminal beep (/beep) : ON"); + else + cons_show("Terminal beep (/beep) : OFF"); + + if (prefs_get_boolean(PREF_FLASH)) + cons_show("Terminal flash (/flash) : ON"); + else + cons_show("Terminal flash (/flash) : OFF"); + + if (prefs_get_boolean(PREF_INTYPE)) + cons_show("Show typing (/intype) : ON"); + else + cons_show("Show typing (/intype) : OFF"); + + if (prefs_get_boolean(PREF_SPLASH)) + cons_show("Splash screen (/splash) : ON"); + else + cons_show("Splash screen (/splash) : OFF"); + + if (prefs_get_boolean(PREF_HISTORY)) + cons_show("Chat history (/history) : ON"); + else + cons_show("Chat history (/history) : OFF"); + + if (prefs_get_boolean(PREF_VERCHECK)) + cons_show("Version checking (/vercheck) : ON"); + else + cons_show("Version checking (/vercheck) : OFF"); + + if (prefs_get_boolean(PREF_MOUSE)) + cons_show("Mouse handling (/mouse) : ON"); + else + cons_show("Mouse handling (/mouse) : OFF"); + + if (prefs_get_boolean(PREF_STATUSES)) + cons_show("Status (/statuses) : ON"); + else + cons_show("Status (/statuses) : OFF"); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_show_desktop_prefs(void) +{ + cons_show("Desktop notification preferences:"); + cons_show(""); + + if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) + cons_show("Messages (/notify message) : ON"); + else + cons_show("Messages (/notify message) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_TYPING)) + cons_show("Composing (/notify typing) : ON"); + else + cons_show("Composing (/notify typing) : OFF"); + + gint remind_period = prefs_get_notify_remind(); + if (remind_period == 0) { + cons_show("Reminder period (/notify remind) : OFF"); + } else if (remind_period == 1) { + cons_show("Reminder period (/notify remind) : 1 second"); + } else { + cons_show("Reminder period (/notify remind) : %d seconds", remind_period); + } +} + +void +cons_show_chat_prefs(void) +{ + cons_show("Chat preferences:"); + cons_show(""); + + if (prefs_get_boolean(PREF_STATES)) + cons_show("Send chat states (/states) : ON"); + else + cons_show("Send chat states (/states) : OFF"); + + if (prefs_get_boolean(PREF_OUTTYPE)) + cons_show("Send composing (/outtype) : ON"); + else + cons_show("Send composing (/outtype) : OFF"); + + gint gone_time = prefs_get_gone(); + if (gone_time == 0) { + cons_show("Leave conversation (/gone) : OFF"); + } else if (gone_time == 1) { + cons_show("Leave conversation (/gone) : 1 minute"); + } else { + cons_show("Leave conversation (/gone) : %d minutes", gone_time); + } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_show_log_prefs(void) +{ + cons_show("Logging preferences:"); + cons_show(""); + + cons_show("Max log size (/log maxsize) : %d bytes", prefs_get_max_log_size()); + + if (prefs_get_boolean(PREF_CHLOG)) + cons_show("Chat logging (/chlog) : ON"); + else + cons_show("Chat logging (/chlog) : OFF"); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_show_presence_prefs(void) +{ + cons_show("Presence preferences:"); + cons_show(""); + + if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "off") == 0) { + cons_show("Autoaway (/autoaway mode) : OFF"); + } else { + cons_show("Autoaway (/autoaway mode) : %s", prefs_get_string(PREF_AUTOAWAY_MODE)); + } + + cons_show("Autoaway minutes (/autoaway time) : %d minutes", prefs_get_autoaway_time()); + + if ((prefs_get_string(PREF_AUTOAWAY_MESSAGE) == NULL) || + (strcmp(prefs_get_string(PREF_AUTOAWAY_MESSAGE), "") == 0)) { + cons_show("Autoaway message (/autoaway message) : OFF"); + } else { + cons_show("Autoaway message (/autoaway message) : \"%s\"", prefs_get_string(PREF_AUTOAWAY_MESSAGE)); + } + + if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) { + cons_show("Autoaway check (/autoaway check) : ON"); + } else { + cons_show("Autoaway check (/autoaway check) : OFF"); + } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_show_connection_prefs(void) +{ + cons_show("Connection preferences:"); + cons_show(""); + + gint reconnect_interval = prefs_get_reconnect(); + if (reconnect_interval == 0) { + cons_show("Reconnect interval (/reconnect) : OFF"); + } else if (reconnect_interval == 1) { + cons_show("Reconnect interval (/reconnect) : 1 second"); + } else { + cons_show("Reconnect interval (/reconnect) : %d seconds", reconnect_interval); + } + + gint autoping_interval = prefs_get_autoping(); + if (autoping_interval == 0) { + cons_show("Autoping interval (/autoping) : OFF"); + } else if (autoping_interval == 1) { + cons_show("Autoping interval (/autoping) : 1 second"); + } else { + cons_show("Autoping interval (/autoping) : %d seconds", autoping_interval); + } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_show_themes(GSList *themes) +{ + cons_show(""); + + if (themes == NULL) { + cons_show("No available themes."); + } else { + cons_show("Available themes:"); + while (themes != NULL) { + cons_show(themes->data); + themes = g_slist_next(themes); + } + } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_prefs(void) +{ + cons_show(""); + cons_show_ui_prefs(); + cons_show(""); + cons_show_desktop_prefs(); + cons_show(""); + cons_show_chat_prefs(); + cons_show(""); + cons_show_log_prefs(); + cons_show(""); + cons_show_presence_prefs(); + cons_show(""); + cons_show_connection_prefs(); + cons_show(""); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + + static void _cons_splash_logo(void) { diff --git a/src/ui/windows.c b/src/ui/windows.c index 6a687db1..bcba0de5 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1146,219 +1146,6 @@ win_room_show_status(const char * const contact) } } -void -cons_show_ui_prefs(void) -{ - cons_show("UI preferences:"); - cons_show(""); - - gchar *theme = prefs_get_string(PREF_THEME); - if (theme == NULL) { - cons_show("Theme (/theme) : default"); - } else { - cons_show("Theme (/theme) : %s", theme); - } - - if (prefs_get_boolean(PREF_BEEP)) - cons_show("Terminal beep (/beep) : ON"); - else - cons_show("Terminal beep (/beep) : OFF"); - - if (prefs_get_boolean(PREF_FLASH)) - cons_show("Terminal flash (/flash) : ON"); - else - cons_show("Terminal flash (/flash) : OFF"); - - if (prefs_get_boolean(PREF_INTYPE)) - cons_show("Show typing (/intype) : ON"); - else - cons_show("Show typing (/intype) : OFF"); - - if (prefs_get_boolean(PREF_SPLASH)) - cons_show("Splash screen (/splash) : ON"); - else - cons_show("Splash screen (/splash) : OFF"); - - if (prefs_get_boolean(PREF_HISTORY)) - cons_show("Chat history (/history) : ON"); - else - cons_show("Chat history (/history) : OFF"); - - if (prefs_get_boolean(PREF_VERCHECK)) - cons_show("Version checking (/vercheck) : ON"); - else - cons_show("Version checking (/vercheck) : OFF"); - - if (prefs_get_boolean(PREF_MOUSE)) - cons_show("Mouse handling (/mouse) : ON"); - else - cons_show("Mouse handling (/mouse) : OFF"); - - if (prefs_get_boolean(PREF_STATUSES)) - cons_show("Status (/statuses) : ON"); - else - cons_show("Status (/statuses) : OFF"); -} - -void -cons_show_desktop_prefs(void) -{ - cons_show("Desktop notification preferences:"); - cons_show(""); - - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) - cons_show("Messages (/notify message) : ON"); - else - cons_show("Messages (/notify message) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_TYPING)) - cons_show("Composing (/notify typing) : ON"); - else - cons_show("Composing (/notify typing) : OFF"); - - gint remind_period = prefs_get_notify_remind(); - if (remind_period == 0) { - cons_show("Reminder period (/notify remind) : OFF"); - } else if (remind_period == 1) { - cons_show("Reminder period (/notify remind) : 1 second"); - } else { - cons_show("Reminder period (/notify remind) : %d seconds", remind_period); - } -} - -void -cons_show_chat_prefs(void) -{ - cons_show("Chat preferences:"); - cons_show(""); - - if (prefs_get_boolean(PREF_STATES)) - cons_show("Send chat states (/states) : ON"); - else - cons_show("Send chat states (/states) : OFF"); - - if (prefs_get_boolean(PREF_OUTTYPE)) - cons_show("Send composing (/outtype) : ON"); - else - cons_show("Send composing (/outtype) : OFF"); - - gint gone_time = prefs_get_gone(); - if (gone_time == 0) { - cons_show("Leave conversation (/gone) : OFF"); - } else if (gone_time == 1) { - cons_show("Leave conversation (/gone) : 1 minute"); - } else { - cons_show("Leave conversation (/gone) : %d minutes", gone_time); - } -} - -void -cons_show_log_prefs(void) -{ - cons_show("Logging preferences:"); - cons_show(""); - - cons_show("Max log size (/log maxsize) : %d bytes", prefs_get_max_log_size()); - - if (prefs_get_boolean(PREF_CHLOG)) - cons_show("Chat logging (/chlog) : ON"); - else - cons_show("Chat logging (/chlog) : OFF"); -} - -void -cons_show_presence_prefs(void) -{ - cons_show("Presence preferences:"); - cons_show(""); - - if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "off") == 0) { - cons_show("Autoaway (/autoaway mode) : OFF"); - } else { - cons_show("Autoaway (/autoaway mode) : %s", prefs_get_string(PREF_AUTOAWAY_MODE)); - } - - cons_show("Autoaway minutes (/autoaway time) : %d minutes", prefs_get_autoaway_time()); - - if ((prefs_get_string(PREF_AUTOAWAY_MESSAGE) == NULL) || - (strcmp(prefs_get_string(PREF_AUTOAWAY_MESSAGE), "") == 0)) { - cons_show("Autoaway message (/autoaway message) : OFF"); - } else { - cons_show("Autoaway message (/autoaway message) : \"%s\"", prefs_get_string(PREF_AUTOAWAY_MESSAGE)); - } - - if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) { - cons_show("Autoaway check (/autoaway check) : ON"); - } else { - cons_show("Autoaway check (/autoaway check) : OFF"); - } -} - -void -cons_show_connection_prefs(void) -{ - cons_show("Connection preferences:"); - cons_show(""); - - gint reconnect_interval = prefs_get_reconnect(); - if (reconnect_interval == 0) { - cons_show("Reconnect interval (/reconnect) : OFF"); - } else if (reconnect_interval == 1) { - cons_show("Reconnect interval (/reconnect) : 1 second"); - } else { - cons_show("Reconnect interval (/reconnect) : %d seconds", reconnect_interval); - } - - gint autoping_interval = prefs_get_autoping(); - if (autoping_interval == 0) { - cons_show("Autoping interval (/autoping) : OFF"); - } else if (autoping_interval == 1) { - cons_show("Autoping interval (/autoping) : 1 second"); - } else { - cons_show("Autoping interval (/autoping) : %d seconds", autoping_interval); - } -} - -void -cons_show_themes(GSList *themes) -{ - cons_show(""); - - if (themes == NULL) { - cons_show("No available themes."); - } else { - cons_show("Available themes:"); - while (themes != NULL) { - cons_show(themes->data); - themes = g_slist_next(themes); - } - } -} - -void -cons_prefs(void) -{ - cons_show(""); - cons_show_ui_prefs(); - cons_show(""); - cons_show_desktop_prefs(); - cons_show(""); - cons_show_chat_prefs(); - cons_show(""); - cons_show_log_prefs(); - cons_show(""); - cons_show_presence_prefs(); - cons_show(""); - cons_show_connection_prefs(); - cons_show(""); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } -} - static void _cons_show_basic_help(void) { From 9f380dae8e73ef9a72f0e7410c6782788db34b6d Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:31:30 +0100 Subject: [PATCH 15/37] Moved help display functions to console module --- src/ui/console.c | 115 ++++++++++++++++++++++++++++++++++++++++++++ src/ui/windows.c | 121 ----------------------------------------------- 2 files changed, 115 insertions(+), 121 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 59aa5df9..9eac9ec5 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -29,6 +29,7 @@ #include #endif +#include "command/command.h" #include "common.h" #include "config/preferences.h" #include "contact_list.h" @@ -42,6 +43,7 @@ static ProfWin* console; static int dirty; static void _cons_splash_logo(void); +static void _cons_show_basic_help(void); ProfWin * cons_create(void) @@ -1020,6 +1022,105 @@ cons_prefs(void) } } +void +cons_help(void) +{ + cons_show(""); + cons_show("Choose a help option:"); + cons_show(""); + cons_show("/help list - List all commands."); + cons_show("/help basic - Summary of basic usage commands."); + cons_show("/help presence - Summary of online status change commands."); + cons_show("/help settings - Summary of commands for changing Profanity settings."); + cons_show("/help navigation - How to navigate around Profanity."); + cons_show("/help [command] - Detailed help on a specific command."); + cons_show(""); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_basic_help(void) +{ + cons_show(""); + cons_show("Basic Commands:"); + _cons_show_basic_help(); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_settings_help(void) +{ + cons_show(""); + cons_show("Settings:"); + cons_show(""); + + GSList *settings_helpers = cmd_get_settings_help(); + while (settings_helpers != NULL) { + struct cmd_help_t *help = (struct cmd_help_t *)settings_helpers->data; + cons_show("%-27s: %s", help->usage, help->short_help); + settings_helpers = g_slist_next(settings_helpers); + } + + cons_show(""); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_presence_help(void) +{ + cons_show(""); + cons_show("Presence changes:"); + cons_show(""); + + GSList *presence_helpers = cmd_get_presence_help(); + while (presence_helpers != NULL) { + struct cmd_help_t *help = (struct cmd_help_t *)presence_helpers->data; + cons_show("%-25s: %s", help->usage, help->short_help); + presence_helpers = g_slist_next(presence_helpers); + } + + cons_show(""); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_navigation_help(void) +{ + cons_show(""); + cons_show("Navigation:"); + cons_show(""); + cons_show("Alt-1 : This console window."); + cons_show("Alt-2..Alt-0 : Chat windows."); + cons_show("F1 : This console window."); + cons_show("F2..F10 : Chat windows."); + cons_show("UP, DOWN : Navigate input history."); + cons_show("LEFT, RIGHT, HOME, END : Edit current input."); + cons_show("ESC : Clear current input."); + cons_show("TAB : Autocomplete command/recipient/login."); + cons_show("PAGE UP, PAGE DOWN : Page the main window."); + cons_show(""); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} static void _cons_splash_logo(void) @@ -1072,4 +1173,18 @@ _cons_splash_logo(void) } } +static void +_cons_show_basic_help(void) +{ + cons_show(""); + + GSList *basic_helpers = cmd_get_basic_help(); + while (basic_helpers != NULL) { + struct cmd_help_t *help = (struct cmd_help_t *)basic_helpers->data; + cons_show("%-30s: %s", help->usage, help->short_help); + basic_helpers = g_slist_next(basic_helpers); + } + + cons_show(""); +} diff --git a/src/ui/windows.c b/src/ui/windows.c index bcba0de5..732b95bb 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -73,7 +73,6 @@ static Display *display; static GTimer *ui_idle_time; static void _set_current(int index); -static void _cons_show_basic_help(void); static int _find_prof_win_index(const char * const contact); static int _new_prof_win(const char * const contact, win_type_t type); static void _current_window_refresh(void); @@ -1146,126 +1145,6 @@ win_room_show_status(const char * const contact) } } -static void -_cons_show_basic_help(void) -{ - cons_show(""); - - GSList *basic_helpers = cmd_get_basic_help(); - while (basic_helpers != NULL) { - struct cmd_help_t *help = (struct cmd_help_t *)basic_helpers->data; - cons_show("%-30s: %s", help->usage, help->short_help); - basic_helpers = g_slist_next(basic_helpers); - } - - cons_show(""); -} - -void -cons_help(void) -{ - cons_show(""); - cons_show("Choose a help option:"); - cons_show(""); - cons_show("/help list - List all commands."); - cons_show("/help basic - Summary of basic usage commands."); - cons_show("/help presence - Summary of online status change commands."); - cons_show("/help settings - Summary of commands for changing Profanity settings."); - cons_show("/help navigation - How to navigate around Profanity."); - cons_show("/help [command] - Detailed help on a specific command."); - cons_show(""); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } -} - -void -cons_basic_help(void) -{ - cons_show(""); - cons_show("Basic Commands:"); - _cons_show_basic_help(); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } -} - -void -cons_settings_help(void) -{ - cons_show(""); - cons_show("Settings:"); - cons_show(""); - - GSList *settings_helpers = cmd_get_settings_help(); - while (settings_helpers != NULL) { - struct cmd_help_t *help = (struct cmd_help_t *)settings_helpers->data; - cons_show("%-27s: %s", help->usage, help->short_help); - settings_helpers = g_slist_next(settings_helpers); - } - - cons_show(""); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } -} - -void -cons_presence_help(void) -{ - cons_show(""); - cons_show("Presence changes:"); - cons_show(""); - - GSList *presence_helpers = cmd_get_presence_help(); - while (presence_helpers != NULL) { - struct cmd_help_t *help = (struct cmd_help_t *)presence_helpers->data; - cons_show("%-25s: %s", help->usage, help->short_help); - presence_helpers = g_slist_next(presence_helpers); - } - - cons_show(""); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } -} - -void -cons_navigation_help(void) -{ - cons_show(""); - cons_show("Navigation:"); - cons_show(""); - cons_show("Alt-1 : This console window."); - cons_show("Alt-2..Alt-0 : Chat windows."); - cons_show("F1 : This console window."); - cons_show("F2..F10 : Chat windows."); - cons_show("UP, DOWN : Navigate input history."); - cons_show("LEFT, RIGHT, HOME, END : Edit current input."); - cons_show("ESC : Clear current input."); - cons_show("TAB : Autocomplete command/recipient/login."); - cons_show("PAGE UP, PAGE DOWN : Page the main window."); - cons_show(""); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } -} - void cons_show_contacts(GSList *list) { From bb0f4a3fb2a9d3f11e4bd7d62c53e68491fc0f02 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:32:47 +0100 Subject: [PATCH 16/37] Moved cons_show_contacts() to console module --- src/ui/console.c | 14 ++++++++++++++ src/ui/windows.c | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 9eac9ec5..79d15add 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1122,6 +1122,20 @@ cons_navigation_help(void) } } +void +cons_show_contacts(GSList *list) +{ + GSList *curr = list; + + while(curr) { + PContact contact = curr->data; + if (strcmp(p_contact_subscription(contact), "none") != 0) { + window_show_contact(console, contact); + } + curr = g_slist_next(curr); + } +} + static void _cons_splash_logo(void) { diff --git a/src/ui/windows.c b/src/ui/windows.c index 732b95bb..14b4b34e 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1145,20 +1145,6 @@ win_room_show_status(const char * const contact) } } -void -cons_show_contacts(GSList *list) -{ - GSList *curr = list; - - while(curr) { - PContact contact = curr->data; - if (strcmp(p_contact_subscription(contact), "none") != 0) { - window_show_contact(console, contact); - } - curr = g_slist_next(curr); - } -} - void cons_bad_show(const char * const msg, ...) { From 9de4ab6bb953f6f94fce601e28af46352207599d Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:34:43 +0100 Subject: [PATCH 17/37] Moved cons_bad_show() to console module --- src/ui/console.c | 25 +++++++++++++++++++++++++ src/ui/windows.c | 21 --------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 79d15add..1f31248f 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1134,6 +1134,31 @@ cons_show_contacts(GSList *list) } curr = g_slist_next(curr); } + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + +void +cons_bad_show(const char * const msg, ...) +{ + va_list arg; + va_start(arg, msg); + GString *fmt_msg = g_string_new(NULL); + g_string_vprintf(fmt_msg, msg, arg); + window_show_time(console, '-'); + wattron(console->win, COLOUR_ERROR); + wprintw(console->win, "%s\n", fmt_msg->str); + wattroff(console->win, COLOUR_ERROR); + g_string_free(fmt_msg, TRUE); + va_end(arg); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } } static void diff --git a/src/ui/windows.c b/src/ui/windows.c index 14b4b34e..c027eed2 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1145,27 +1145,6 @@ win_room_show_status(const char * const contact) } } -void -cons_bad_show(const char * const msg, ...) -{ - va_list arg; - va_start(arg, msg); - GString *fmt_msg = g_string_new(NULL); - g_string_vprintf(fmt_msg, msg, arg); - window_show_time(console, '-'); - wattron(console->win, COLOUR_ERROR); - wprintw(console->win, "%s\n", fmt_msg->str); - wattroff(console->win, COLOUR_ERROR); - g_string_free(fmt_msg, TRUE); - va_end(arg); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } -} - void cons_show_time(void) { From 3945a72484e3790d2f1259e8c2d418a2258a6721 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:37:44 +0100 Subject: [PATCH 18/37] Moved cons_show_time() to console module --- src/ui/console.c | 46 ++++++++++++++++++++++++++-------------------- src/ui/windows.c | 6 ------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 1f31248f..57fd063f 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -65,6 +65,12 @@ cons_refresh(void) } } +void +cons_show_time(void) +{ + window_show_time(console, '-'); +} + void cons_show(const char * const msg, ...) { @@ -80,6 +86,26 @@ cons_show(const char * const msg, ...) dirty = TRUE; } +void +cons_bad_show(const char * const msg, ...) +{ + va_list arg; + va_start(arg, msg); + GString *fmt_msg = g_string_new(NULL); + g_string_vprintf(fmt_msg, msg, arg); + window_show_time(console, '-'); + wattron(console->win, COLOUR_ERROR); + wprintw(console->win, "%s\n", fmt_msg->str); + wattroff(console->win, COLOUR_ERROR); + g_string_free(fmt_msg, TRUE); + va_end(arg); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + void cons_about(void) { @@ -1141,26 +1167,6 @@ cons_show_contacts(GSList *list) } } -void -cons_bad_show(const char * const msg, ...) -{ - va_list arg; - va_start(arg, msg); - GString *fmt_msg = g_string_new(NULL); - g_string_vprintf(fmt_msg, msg, arg); - window_show_time(console, '-'); - wattron(console->win, COLOUR_ERROR); - wprintw(console->win, "%s\n", fmt_msg->str); - wattroff(console->win, COLOUR_ERROR); - g_string_free(fmt_msg, TRUE); - va_end(arg); - - dirty = TRUE; - if (!win_current_is_console()) { - status_bar_new(0); - } -} - static void _cons_splash_logo(void) { diff --git a/src/ui/windows.c b/src/ui/windows.c index c027eed2..52db5b2c 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1145,12 +1145,6 @@ win_room_show_status(const char * const contact) } } -void -cons_show_time(void) -{ - window_show_time(console, '-'); -} - void cons_debug(const char * const msg, ...) { From 0c912990c773ece4e8dd5b868b86868661009cb7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:39:36 +0100 Subject: [PATCH 19/37] Moved cons_debug() to console module --- src/ui/console.c | 23 +++++++++++++++++++++++ src/ui/windows.c | 24 ------------------------ 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 57fd063f..812fbac1 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -71,6 +71,29 @@ cons_show_time(void) window_show_time(console, '-'); } +void +cons_debug(const char * const msg, ...) +{ + if (strcmp(PACKAGE_STATUS, "development") == 0) { + va_list arg; + va_start(arg, msg); + GString *fmt_msg = g_string_new(NULL); + g_string_vprintf(fmt_msg, msg, arg); + window_show_time(console, '-'); + wprintw(console->win, "%s\n", fmt_msg->str); + g_string_free(fmt_msg, TRUE); + va_end(arg); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } + + win_current_page_off(); + ui_refresh(); + } +} + void cons_show(const char * const msg, ...) { diff --git a/src/ui/windows.c b/src/ui/windows.c index 52db5b2c..ce40eec9 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1145,30 +1145,6 @@ win_room_show_status(const char * const contact) } } -void -cons_debug(const char * const msg, ...) -{ - if (strcmp(PACKAGE_STATUS, "development") == 0) { - va_list arg; - va_start(arg, msg); - GString *fmt_msg = g_string_new(NULL); - g_string_vprintf(fmt_msg, msg, arg); - window_show_time(console, '-'); - wprintw(console->win, "%s\n", fmt_msg->str); - g_string_free(fmt_msg, TRUE); - va_end(arg); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } - - win_current_page_off(); - ui_refresh(); - } -} - void cons_show_word(const char * const word) { From 3011dc63ae573316ff5ac933f8511cc2a85fb15b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:41:36 +0100 Subject: [PATCH 20/37] Moved cons_show_word() to console module --- src/ui/console.c | 11 +++++++++++ src/ui/windows.c | 12 ------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 812fbac1..9600f79f 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -71,6 +71,17 @@ cons_show_time(void) window_show_time(console, '-'); } +void +cons_show_word(const char * const word) +{ + wprintw(console->win, "%s", word); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + void cons_debug(const char * const msg, ...) { diff --git a/src/ui/windows.c b/src/ui/windows.c index ce40eec9..be51a4e3 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1145,18 +1145,6 @@ win_room_show_status(const char * const contact) } } -void -cons_show_word(const char * const word) -{ - wprintw(console->win, "%s", word); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } -} - void cons_bad_command(const char * const cmd) { From 8a280b43cac0e84cede288a1816cd0ee2324782b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:42:57 +0100 Subject: [PATCH 21/37] Moved cons_bad_command() to console module --- src/ui/console.c | 12 ++++++++++++ src/ui/windows.c | 13 ------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 9600f79f..0bea782d 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -140,6 +140,18 @@ cons_bad_show(const char * const msg, ...) } } +void +cons_bad_command(const char * const cmd) +{ + window_show_time(console, '-'); + wprintw(console->win, "Unknown command: %s\n", cmd); + + dirty = TRUE; + if (!win_current_is_console()) { + status_bar_new(0); + } +} + void cons_about(void) { diff --git a/src/ui/windows.c b/src/ui/windows.c index be51a4e3..8d9f6b5d 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1145,19 +1145,6 @@ win_room_show_status(const char * const contact) } } -void -cons_bad_command(const char * const cmd) -{ - window_show_time(console, '-'); - wprintw(console->win, "Unknown command: %s\n", cmd); - - if (current_index == 0) { - dirty = TRUE; - } else { - status_bar_new(0); - } -} - void notify_remind(void) { From e151ce707d822f4e7258353b4f94e154b123b4ad Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 01:47:57 +0100 Subject: [PATCH 22/37] Moved remaining static functions to console module --- src/ui/console.c | 18 ++++++++++++++++++ src/ui/ui.h | 2 ++ src/ui/windows.c | 29 ++++------------------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 0bea782d..aa74f9ec 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -152,6 +152,24 @@ cons_bad_command(const char * const cmd) } } +void +cons_show_typing(const char * const short_from) +{ + window_show_time(console, '-'); + wattron(console->win, COLOUR_TYPING); + wprintw(console->win, "!! %s is typing a message...\n", short_from); + wattroff(console->win, COLOUR_TYPING); +} + +void +cons_show_incoming_message(const char * const short_from, const int win_index) +{ + window_show_time(console, '-'); + wattron(console->win, COLOUR_INCOMING); + wprintw(console->win, "<< incoming from %s (%d)\n", short_from, win_index + 1); + wattroff(console->win, COLOUR_INCOMING); +} + void cons_about(void) { diff --git a/src/ui/ui.h b/src/ui/ui.h index de217006..9ead3848 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -166,6 +166,8 @@ void cons_show_disco_info(const char *from, GSList *identities, GSList *features void cons_show_room_invite(const char * const invitor, const char * const room, const char * const reason); void cons_check_version(gboolean not_available_msg); +void cons_show_typing(const char * const short_from); +void cons_show_incoming_message(const char * const short_from, const int win_index); // status bar actions void status_bar_refresh(void); diff --git a/src/ui/windows.c b/src/ui/windows.c index 8d9f6b5d..31660fc2 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -83,9 +83,6 @@ static void _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); -static void _cons_show_typing(const char * const short_from); -static void _cons_show_incoming_message(const char * const short_from, - const int win_index); static void _win_handle_switch(const wint_t * const ch); static void _win_handle_page(const wint_t * const ch); static void _win_resize_all(void); @@ -266,11 +263,11 @@ ui_show_typing(const char * const from) if (prefs_get_boolean(PREF_INTYPE)) { // no chat window for user if (win_index == NUM_WINS) { - _cons_show_typing(from); + cons_show_typing(from); // have chat window but not currently in it } else if (win_index != current_index) { - _cons_show_typing(from); + cons_show_typing(from); dirty = TRUE; // in chat window with user @@ -400,7 +397,7 @@ ui_show_incoming_msg(const char * const from, const char * const message, // not currently viewing chat window with sender } else { status_bar_new(win_index); - _cons_show_incoming_message(from, win_index); + cons_show_incoming_message(from, win_index); if (prefs_get_boolean(PREF_FLASH)) flash(); @@ -1034,7 +1031,7 @@ win_show_room_message(const char * const room_jid, const char * const nick, // not currenlty on groupchat window } else { status_bar_new(win_index); - _cons_show_incoming_message(nick, win_index); + cons_show_incoming_message(nick, win_index); if (current_index == 0) { dirty = TRUE; } @@ -1414,24 +1411,6 @@ _show_status_string(ProfWin *window, const char * const from, } } -static void -_cons_show_typing(const char * const short_from) -{ - window_show_time(console, '-'); - wattron(console->win, COLOUR_TYPING); - wprintw(console->win, "!! %s is typing a message...\n", short_from); - wattroff(console->win, COLOUR_TYPING); -} - -static void -_cons_show_incoming_message(const char * const short_from, const int win_index) -{ - window_show_time(console, '-'); - wattron(console->win, COLOUR_INCOMING); - wprintw(console->win, "<< incoming from %s (%d)\n", short_from, win_index + 1); - wattroff(console->win, COLOUR_INCOMING); -} - static void _win_handle_switch(const wint_t * const ch) { From a3b861a71143036df15494a2ae734077734ef5b3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 02:10:13 +0100 Subject: [PATCH 23/37] Renamed window_show_time -> window_print_time --- src/ui/console.c | 112 +++++++++++++++++++++++------------------------ src/ui/window.c | 4 +- src/ui/window.h | 2 +- src/ui/windows.c | 38 ++++++++-------- 4 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index aa74f9ec..4931a391 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -68,7 +68,7 @@ cons_refresh(void) void cons_show_time(void) { - window_show_time(console, '-'); + window_print_time(console, '-'); } void @@ -90,7 +90,7 @@ cons_debug(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); @@ -112,7 +112,7 @@ cons_show(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); @@ -127,7 +127,7 @@ cons_bad_show(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - window_show_time(console, '-'); + window_print_time(console, '-'); wattron(console->win, COLOUR_ERROR); wprintw(console->win, "%s\n", fmt_msg->str); wattroff(console->win, COLOUR_ERROR); @@ -143,7 +143,7 @@ cons_bad_show(const char * const msg, ...) void cons_bad_command(const char * const cmd) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "Unknown command: %s\n", cmd); dirty = TRUE; @@ -155,7 +155,7 @@ cons_bad_command(const char * const cmd) void cons_show_typing(const char * const short_from) { - window_show_time(console, '-'); + window_print_time(console, '-'); wattron(console->win, COLOUR_TYPING); wprintw(console->win, "!! %s is typing a message...\n", short_from); wattroff(console->win, COLOUR_TYPING); @@ -164,7 +164,7 @@ cons_show_typing(const char * const short_from) void cons_show_incoming_message(const char * const short_from, const int win_index) { - window_show_time(console, '-'); + window_print_time(console, '-'); wattron(console->win, COLOUR_INCOMING); wprintw(console->win, "<< incoming from %s (%d)\n", short_from, win_index + 1); wattroff(console->win, COLOUR_INCOMING); @@ -179,7 +179,7 @@ cons_about(void) if (prefs_get_boolean(PREF_SPLASH)) { _cons_splash_logo(); } else { - window_show_time(console, '-'); + window_print_time(console, '-'); if (strcmp(PACKAGE_STATUS, "development") == 0) { wprintw(console->win, "Welcome to Profanity, version %sdev\n", PACKAGE_VERSION); @@ -188,21 +188,21 @@ cons_about(void) } } - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "Copyright (C) 2012, 2013 James Booth <%s>.\n", PACKAGE_BUGREPORT); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "License GPLv3+: GNU GPL version 3 or later \n"); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "\n"); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "This is free software; you are free to change and redistribute it.\n"); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "There is NO WARRANTY, to the extent permitted by law.\n"); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "\n"); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "Type '/help' to show complete help.\n"); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "\n"); if (prefs_get_boolean(PREF_VERCHECK)) { @@ -227,12 +227,12 @@ cons_check_version(gboolean not_available_msg) if (relase_valid) { if (release_is_new(latest_release)) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "A new version of Profanity is available: %s", latest_release); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "Check for details.\n"); free(latest_release); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "\n"); } else { if (not_available_msg) { @@ -252,7 +252,7 @@ cons_check_version(gboolean not_available_msg) void cons_show_login_success(ProfAccount *account) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "%s logged in successfully, ", account->jid); resource_presence_t presence = accounts_get_login_presence(account->name); @@ -274,7 +274,7 @@ cons_show_wins(void) cons_show(""); cons_show("Active windows:"); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "1: Console\n"); for (i = 1; i < NUM_WINS; i++) { @@ -287,7 +287,7 @@ cons_show_wins(void) for (i = 1; i < NUM_WINS; i++) { if (windows[i] != NULL) { ProfWin *window = windows[i]; - window_show_time(console, '-'); + window_print_time(console, '-'); switch (window->type) { @@ -354,9 +354,9 @@ cons_show_info(PContact pcontact) GDateTime *last_activity = p_contact_last_activity(pcontact); WINDOW *win = console->win; - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, "\n"); - window_show_time(console, '-'); + window_print_time(console, '-'); window_presence_colour_on(console, presence); wprintw(win, "%s", barejid); if (name != NULL) { @@ -366,7 +366,7 @@ cons_show_info(PContact pcontact) wprintw(win, ":\n"); if (sub != NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, "Subscription: %s\n", sub); } @@ -374,7 +374,7 @@ cons_show_info(PContact pcontact) GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, "Last activity: "); int hours = span / G_TIME_SPAN_HOUR; @@ -396,7 +396,7 @@ cons_show_info(PContact pcontact) } if (resources != NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, "Resources:\n"); // sort in order of availabiltiy @@ -411,7 +411,7 @@ cons_show_info(PContact pcontact) while (ordered_resources != NULL) { Resource *resource = ordered_resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); - window_show_time(console, '-'); + window_print_time(console, '-'); window_presence_colour_on(console, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { @@ -425,7 +425,7 @@ cons_show_info(PContact pcontact) if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, " Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); @@ -445,7 +445,7 @@ cons_show_info(PContact pcontact) wprintw(win, "\n"); } if (caps->software != NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, " Software: %s", caps->software); } if (caps->software_version != NULL) { @@ -455,7 +455,7 @@ cons_show_info(PContact pcontact) wprintw(win, "\n"); } if (caps->os != NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, " OS: %s", caps->os); } if (caps->os_version != NULL) { @@ -482,7 +482,7 @@ cons_show_caps(const char * const contact, Resource *resource) WINDOW *win = console->win; cons_show(""); const char *resource_presence = string_from_resource_presence(resource->presence); - window_show_time(console, '-'); + window_print_time(console, '-'); window_presence_colour_on(console, resource_presence); wprintw(console->win, "%s", contact); window_presence_colour_off(console, resource_presence); @@ -493,7 +493,7 @@ cons_show_caps(const char * const contact, Resource *resource) if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, "Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); @@ -513,7 +513,7 @@ cons_show_caps(const char * const contact, Resource *resource) wprintw(win, "\n"); } if (caps->software != NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, "Software: %s", caps->software); } if (caps->software_version != NULL) { @@ -523,7 +523,7 @@ cons_show_caps(const char * const contact, Resource *resource) wprintw(win, "\n"); } if (caps->os != NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, "OS: %s", caps->os); } if (caps->os_version != NULL) { @@ -534,11 +534,11 @@ cons_show_caps(const char * const contact, Resource *resource) } if (caps->features != NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, "Features:\n"); GSList *feature = caps->features; while (feature != NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, " %s\n", feature->data); feature = g_slist_next(feature); } @@ -558,7 +558,7 @@ cons_show_software_version(const char * const jid, const char * const presence, { if ((name != NULL) || (version != NULL) || (os != NULL)) { cons_show(""); - window_show_time(console, '-'); + window_print_time(console, '-'); window_presence_colour_on(console, presence); wprintw(console->win, "%s", jid); window_presence_colour_off(console, presence); @@ -587,7 +587,7 @@ cons_show_room_list(GSList *rooms, const char * const conference_node) cons_show("Chat rooms at %s:", conference_node); while (rooms != NULL) { DiscoItem *room = rooms->data; - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, " %s", room->jid); if (room->name != NULL) { wprintw(console->win, ", (%s)", room->name); @@ -658,7 +658,7 @@ cons_show_disco_items(GSList *items, const char * const jid) cons_show("Service discovery items for %s:", jid); while (items != NULL) { DiscoItem *item = items->data; - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, " %s", item->jid); if (item->name != NULL) { wprintw(console->win, ", (%s)", item->name); @@ -735,7 +735,7 @@ cons_show_account_list(gchar **accounts) if ((jabber_get_connection_status() == JABBER_CONNECTED) && (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) { resource_presence_t presence = accounts_get_last_presence(accounts[i]); - window_show_time(console, '-'); + window_print_time(console, '-'); window_presence_colour_on(console, string_from_resource_presence(presence)); wprintw(console->win, "%s\n", accounts[i]); window_presence_colour_off(console, string_from_resource_presence(presence)); @@ -789,7 +789,7 @@ cons_show_account(ProfAccount *account) WINDOW *win = console->win; if (resources != NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, "Resources:\n"); // sort in order of availabiltiy @@ -804,7 +804,7 @@ cons_show_account(ProfAccount *account) while (ordered_resources != NULL) { Resource *resource = ordered_resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); - window_show_time(console, '-'); + window_print_time(console, '-'); window_presence_colour_on(console, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { @@ -818,7 +818,7 @@ cons_show_account(ProfAccount *account) if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, " Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); @@ -838,7 +838,7 @@ cons_show_account(ProfAccount *account) wprintw(win, "\n"); } if (caps->software != NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, " Software: %s", caps->software); } if (caps->software_version != NULL) { @@ -848,7 +848,7 @@ cons_show_account(ProfAccount *account) wprintw(win, "\n"); } if (caps->os != NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(win, " OS: %s", caps->os); } if (caps->os_version != NULL) { @@ -1234,47 +1234,47 @@ cons_show_contacts(GSList *list) static void _cons_splash_logo(void) { - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "Welcome to\n"); - window_show_time(console, '-'); + window_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, " ___ _ \n"); wattroff(console->win, COLOUR_SPLASH); - window_show_time(console, '-'); + window_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, " / __) (_)_ \n"); wattroff(console->win, COLOUR_SPLASH); - window_show_time(console, '-'); + window_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, " ____ ____ ___ | |__ ____ ____ _| |_ _ _ \n"); wattroff(console->win, COLOUR_SPLASH); - window_show_time(console, '-'); + window_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |\n"); wattroff(console->win, COLOUR_SPLASH); - window_show_time(console, '-'); + window_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "| | | | | | |_| | | ( ( | | | | | | |_| |_| |\n"); wattroff(console->win, COLOUR_SPLASH); - window_show_time(console, '-'); + window_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |\n"); wattroff(console->win, COLOUR_SPLASH); - window_show_time(console, '-'); + window_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "|_| (____/ \n"); wattroff(console->win, COLOUR_SPLASH); - window_show_time(console, '-'); + window_print_time(console, '-'); wprintw(console->win, "\n"); - window_show_time(console, '-'); + window_print_time(console, '-'); if (strcmp(PACKAGE_STATUS, "development") == 0) { wprintw(console->win, "Version %sdev\n", PACKAGE_VERSION); } else { diff --git a/src/ui/window.c b/src/ui/window.c index 01eea071..7861cc01 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -66,7 +66,7 @@ window_free(ProfWin* window) } void -window_show_time(ProfWin* window, char show_char) +window_print_time(ProfWin* window, char show_char) { GDateTime *time = g_date_time_new_now_local(); gchar *date_fmt = g_date_time_format(time, "%H:%M:%S"); @@ -122,7 +122,7 @@ window_show_contact(ProfWin *window, PContact contact) const char *status = p_contact_status(contact); GDateTime *last_activity = p_contact_last_activity(contact); - window_show_time(window, '-'); + window_print_time(window, '-'); window_presence_colour_on(window, presence); wprintw(window->win, "%s", barejid); diff --git a/src/ui/window.h b/src/ui/window.h index 5c2e22d5..647b0fe3 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -48,7 +48,7 @@ typedef struct prof_win_t { ProfWin* window_create(const char * const title, int cols, win_type_t type); void window_free(ProfWin *window); -void window_show_time(ProfWin *window, char show_char); +void window_print_time(ProfWin *window, char show_char); void window_presence_colour_on(ProfWin *window, const char * const presence); void window_presence_colour_off(ProfWin *window, const char * const presence); void window_show_contact(ProfWin *window, PContact contact); diff --git a/src/ui/windows.c b/src/ui/windows.c index 31660fc2..1c08f943 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -331,7 +331,7 @@ ui_show_incoming_msg(const char * const from, const char * const message, // no spare windows left if (win_index == 0) { if (tv_stamp == NULL) { - window_show_time(console, '-'); + window_print_time(console, '-'); } else { GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp); gchar *date_fmt = g_date_time_format(time, "%H:%M:%S"); @@ -368,7 +368,7 @@ ui_show_incoming_msg(const char * const from, const char * const message, // currently viewing chat window with sender if (win_index == current_index) { if (tv_stamp == NULL) { - window_show_time(window, '-'); + 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"); @@ -407,7 +407,7 @@ ui_show_incoming_msg(const char * const from, const char * const message, } if (tv_stamp == NULL) { - window_show_time(window, '-'); + 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"); @@ -501,7 +501,7 @@ ui_disconnected(void) for (i = 1; i < NUM_WINS; i++) { if (windows[i] != NULL) { ProfWin *window = windows[i]; - window_show_time(window, '-'); + window_print_time(window, '-'); wattron(window->win, COLOUR_ERROR); wprintw(window->win, "%s\n", "Lost connection."); wattroff(window->win, COLOUR_ERROR); @@ -615,7 +615,7 @@ win_current_show(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - window_show_time(current, '-'); + window_print_time(current, '-'); wprintw(current->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); @@ -626,7 +626,7 @@ win_current_show(const char * const msg, ...) void win_current_bad_show(const char * const msg) { - window_show_time(current, '-'); + window_print_time(current, '-'); wattron(current->win, COLOUR_ERROR); wprintw(current->win, "%s\n", msg); wattroff(current->win, COLOUR_ERROR); @@ -666,7 +666,7 @@ win_show_error_msg(const char * const from, const char *err_msg) // chat window exists if (win_index < NUM_WINS) { window = windows[win_index]; - window_show_time(window, '-'); + window_print_time(window, '-'); _win_show_error_msg(window->win, err_msg); if (win_index == current_index) { dirty = TRUE; @@ -696,7 +696,7 @@ win_show_system_msg(const char * const from, const char *message) } window = windows[win_index]; - window_show_time(window, '-'); + window_print_time(window, '-'); wprintw(window->win, "*%s %s\n", bare_jid, message); // this is the current window @@ -718,7 +718,7 @@ win_show_gone(const char * const from) // chat window exists if (win_index < NUM_WINS) { window = windows[win_index]; - window_show_time(window, '-'); + window_print_time(window, '-'); wattron(window->win, COLOUR_GONE); wprintw(window->win, "*%s ", from); wprintw(window->win, "has left the conversation."); @@ -812,7 +812,7 @@ win_show_outgoing_msg(const char * const from, const char * const to, window = windows[win_index]; } - window_show_time(window, '-'); + window_print_time(window, '-'); if (strncmp(message, "/me ", 4) == 0) { wattron(window->win, COLOUR_ME); wprintw(window->win, "*%s ", from); @@ -845,7 +845,7 @@ win_show_room_roster(const char * const room, GList *roster, const char * const int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; - window_show_time(window, '!'); + window_print_time(window, '!'); if ((roster == NULL) || (g_list_length(roster) == 0)) { wattron(window->win, COLOUR_ROOMINFO); if (presence == NULL) { @@ -894,7 +894,7 @@ win_show_room_member_offline(const char * const room, const char * const nick) int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; - window_show_time(window, '!'); + window_print_time(window, '!'); wattron(window->win, COLOUR_OFFLINE); wprintw(window->win, "<- %s has left the room.\n", nick); wattroff(window->win, COLOUR_OFFLINE); @@ -910,7 +910,7 @@ win_show_room_member_online(const char * const room, const char * const nick, int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; - window_show_time(window, '!'); + window_print_time(window, '!'); wattron(window->win, COLOUR_ONLINE); wprintw(window->win, "-> %s has joined the room.\n", nick); wattroff(window->win, COLOUR_ONLINE); @@ -940,7 +940,7 @@ win_show_room_member_nick_change(const char * const room, int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; - window_show_time(window, '!'); + window_print_time(window, '!'); wattron(window->win, COLOUR_THEM); wprintw(window->win, "** %s is now known as %s\n", old_nick, nick); wattroff(window->win, COLOUR_THEM); @@ -955,7 +955,7 @@ win_show_room_nick_change(const char * const room, const char * const nick) int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; - window_show_time(window, '!'); + window_print_time(window, '!'); wattron(window->win, COLOUR_ME); wprintw(window->win, "** You are now known as %s\n", nick); wattroff(window->win, COLOUR_ME); @@ -997,7 +997,7 @@ win_show_room_message(const char * const room_jid, const char * const nick, int win_index = _find_prof_win_index(room_jid); ProfWin *window = windows[win_index]; - window_show_time(window, '-'); + window_print_time(window, '-'); if (strcmp(nick, muc_get_room_nick(room_jid)) != 0) { if (strncmp(message, "/me ", 4) == 0) { wattron(window->win, COLOUR_THEM); @@ -1061,7 +1061,7 @@ win_show_room_subject(const char * const room_jid, const char * const subject) int win_index = _find_prof_win_index(room_jid); ProfWin *window = windows[win_index]; - window_show_time(window, '!'); + window_print_time(window, '!'); wattron(window->win, COLOUR_ROOMINFO); wprintw(window->win, "Room subject: "); wattroff(window->win, COLOUR_ROOMINFO); @@ -1084,7 +1084,7 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) int win_index = _find_prof_win_index(room_jid); ProfWin *window = windows[win_index]; - window_show_time(window, '!'); + window_print_time(window, '!'); wattron(window->win, COLOUR_ROOMINFO); wprintw(window->win, "Room message: "); wattroff(window->win, COLOUR_ROOMINFO); @@ -1336,7 +1336,7 @@ _show_status_string(ProfWin *window, const char * const from, if (!prefs_get_boolean(PREF_STATUSES)) return; - window_show_time(window, '-'); + window_print_time(window, '-'); if (show != NULL) { if (strcmp(show, "away") == 0) { From f110a8fe3baf4149cde34d6c8fd6a3230d6a21b1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 02:42:27 +0100 Subject: [PATCH 24/37] Removed cons_bad_command() --- src/command/command.c | 2 +- src/ui/console.c | 12 ------------ src/ui/ui.h | 1 - 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 5ceb004a..f5e84da9 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1036,7 +1036,7 @@ cmd_execute_default(const char * const inp) free(recipient); } } else { - cons_bad_command(inp); + cons_show("Unknown command: %s", inp); } return TRUE; diff --git a/src/ui/console.c b/src/ui/console.c index 4931a391..cdd8641d 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -140,18 +140,6 @@ cons_bad_show(const char * const msg, ...) } } -void -cons_bad_command(const char * const cmd) -{ - window_print_time(console, '-'); - wprintw(console->win, "Unknown command: %s\n", cmd); - - dirty = TRUE; - if (!win_current_is_console()) { - status_bar_new(0); - } -} - void cons_show_typing(const char * const short_from) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 9ead3848..8a246432 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -143,7 +143,6 @@ void cons_show_log_prefs(void); void cons_show_presence_prefs(void); void cons_show_connection_prefs(void); void cons_show_account(ProfAccount *account); -void cons_bad_command(const char * const cmd); void cons_debug(const char * const msg, ...); void cons_show_time(void); void cons_show_word(const char * const word); From b2c08cfc43966a69dc544db119ee615a20728a10 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 02:49:23 +0100 Subject: [PATCH 25/37] Renamed cons_bad_show -> cons_show_error --- src/command/command.c | 10 +++++----- src/profanity.c | 10 +++++----- src/ui/console.c | 2 +- src/ui/ui.h | 2 +- src/ui/windows.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index f5e84da9..d0f13c8b 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1149,7 +1149,7 @@ _cmd_connect(gchar **args, struct cmd_help_t help) } if (conn_status == JABBER_DISCONNECTED) { - cons_bad_show("Connection attempt for %s failed.", jid); + cons_show_error("Connection attempt for %s failed.", jid); log_debug("Connection attempt for %s failed", jid); } @@ -1832,7 +1832,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help) } if (ui_windows_full()) { - cons_bad_show("Windows all used, close a window and try again."); + cons_show_error("Windows all used, close a window and try again."); return TRUE; } @@ -2096,7 +2096,7 @@ _cmd_join(gchar **args, struct cmd_help_t help) } if (ui_windows_full()) { - cons_bad_show("Windows all used, close a window and try again."); + cons_show_error("Windows all used, close a window and try again."); return TRUE; } @@ -2256,7 +2256,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) if (!tinyurl_valid(url)) { GString *error = g_string_new("/tiny, badly formed URL: "); g_string_append(error, url); - cons_bad_show(error->str); + cons_show_error(error->str); if (!win_current_is_console()) { win_current_bad_show(error->str); } @@ -2290,7 +2290,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) } free(tiny); } else { - cons_bad_show("Couldn't get tinyurl."); + cons_show_error("Couldn't get tinyurl."); } } else { cons_show("/tiny can only be used in chat windows"); diff --git a/src/profanity.c b/src/profanity.c index 2d37b817..0c872261 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -143,15 +143,15 @@ void prof_handle_error_message(const char *from, const char *err_msg) { if (err_msg == NULL) { - cons_bad_show("Unknown error received from service."); + cons_show_error("Unknown error received from service."); } else if (strcmp(err_msg, "conflict") == 0) { if (win_current_is_groupchat()) { win_current_show("Nickname already in use."); } else { - cons_bad_show("Error received from server: %s", err_msg); + cons_show_error("Error received from server: %s", err_msg); } } else { - cons_bad_show("Error received from server: %s", err_msg); + cons_show_error("Error received from server: %s", err_msg); } win_show_error_msg(from, err_msg); @@ -212,7 +212,7 @@ prof_handle_gone(const char * const from) void prof_handle_failed_login(void) { - cons_bad_show("Login failed."); + cons_show_error("Login failed."); log_info("Login failed"); win_current_page_off(); } @@ -220,7 +220,7 @@ prof_handle_failed_login(void) void prof_handle_lost_connection(void) { - cons_bad_show("Lost connection."); + cons_show_error("Lost connection."); contact_list_clear(); chat_sessions_clear(); ui_disconnected(); diff --git a/src/ui/console.c b/src/ui/console.c index cdd8641d..81502599 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -121,7 +121,7 @@ cons_show(const char * const msg, ...) } void -cons_bad_show(const char * const msg, ...) +cons_show_error(const char * const msg, ...) { va_list arg; va_start(arg, msg); diff --git a/src/ui/ui.h b/src/ui/ui.h index 8a246432..e1ecb83b 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -146,7 +146,7 @@ void cons_show_account(ProfAccount *account); void cons_debug(const char * const msg, ...); void cons_show_time(void); void cons_show_word(const char * const word); -void cons_bad_show(const char * const cmd, ...); +void cons_show_error(const char * const cmd, ...); void cons_highlight_show(const char * const cmd); void cons_show_contacts(GSList * list); void cons_show_wins(void); diff --git a/src/ui/windows.c b/src/ui/windows.c index 1c08f943..cf4ac35c 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -353,7 +353,7 @@ ui_show_incoming_msg(const char * const from, const char * const message, _win_show_message(console->win, message); } - cons_bad_show("Windows all used, close a window to respond."); + cons_show("Windows all used, close a window to respond."); if (current_index == 0) { dirty = TRUE; From 6ff5f45ad3fee853a53b9e91f88e40526e4dfa4d Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 17:30:04 +0100 Subject: [PATCH 26/37] Moved static function in windows --- src/ui/windows.c | 84 ++++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/ui/windows.c b/src/ui/windows.c index cf4ac35c..295619af 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -143,48 +143,6 @@ ui_refresh(void) inp_put_back(); } -static void -_ui_draw_win_title(void) -{ - char new_win_title[100]; - - GString *version_str = g_string_new(""); - - if (prefs_get_boolean(PREF_TITLEBARVERSION)) { - g_string_append(version_str, " "); - g_string_append(version_str, PACKAGE_VERSION); - if (strcmp(PACKAGE_STATUS, "development") == 0) { - g_string_append(version_str, "dev"); - } - } - - jabber_conn_status_t status = jabber_get_connection_status(); - - if (status == JABBER_CONNECTED) { - const char * const jid = jabber_get_jid(); - gint unread = _win_get_unread(); - - if (unread != 0) { - snprintf(new_win_title, sizeof(new_win_title), "%c]0;%s%s (%d) - %s%c", '\033', "Profanity", version_str->str, unread, jid, '\007'); - } else { - snprintf(new_win_title, sizeof(new_win_title), "%c]0;%s%s - %s%c", '\033', "Profanity", version_str->str, jid, '\007'); - } - } else { - snprintf(new_win_title, sizeof(new_win_title), "%c]0;%s%s%c", '\033', "Profanity", version_str->str, '\007'); - } - - g_string_free(version_str, TRUE); - - if (g_strcmp0(win_title, new_win_title) != 0) { - // print to x-window title bar - printf("%s", new_win_title); - if (win_title != NULL) { - free(win_title); - } - win_title = strdup(new_win_title); - } -} - unsigned long ui_get_idle_time(void) { @@ -1151,6 +1109,48 @@ notify_remind(void) } } +static void +_ui_draw_win_title(void) +{ + char new_win_title[100]; + + GString *version_str = g_string_new(""); + + if (prefs_get_boolean(PREF_TITLEBARVERSION)) { + g_string_append(version_str, " "); + g_string_append(version_str, PACKAGE_VERSION); + if (strcmp(PACKAGE_STATUS, "development") == 0) { + g_string_append(version_str, "dev"); + } + } + + jabber_conn_status_t status = jabber_get_connection_status(); + + if (status == JABBER_CONNECTED) { + const char * const jid = jabber_get_jid(); + gint unread = _win_get_unread(); + + if (unread != 0) { + snprintf(new_win_title, sizeof(new_win_title), "%c]0;%s%s (%d) - %s%c", '\033', "Profanity", version_str->str, unread, jid, '\007'); + } else { + snprintf(new_win_title, sizeof(new_win_title), "%c]0;%s%s - %s%c", '\033', "Profanity", version_str->str, jid, '\007'); + } + } else { + snprintf(new_win_title, sizeof(new_win_title), "%c]0;%s%s%c", '\033', "Profanity", version_str->str, '\007'); + } + + g_string_free(version_str, TRUE); + + if (g_strcmp0(win_title, new_win_title) != 0) { + // print to x-window title bar + printf("%s", new_win_title); + if (win_title != NULL) { + free(win_title); + } + win_title = strdup(new_win_title); + } +} + static void _notify(const char * const message, int timeout, const char * const category) From 4257fc87e58d43dfc93117e68f0ce4970ffd3e65 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 17:33:12 +0100 Subject: [PATCH 27/37] Renamed windows.c -> core.c --- Makefile.am | 2 +- src/ui/{windows.c => core.c} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/ui/{windows.c => core.c} (99%) diff --git a/Makefile.am b/Makefile.am index ef2752b5..edcdbb83 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ profanity_SOURCES = src/contact.c src/contact.h src/log.c src/common.c \ src/xmpp/iq.c src/xmpp/message.c src/xmpp/presence.c src/xmpp/stanza.c \ src/xmpp/stanza.h src/xmpp/message.h src/xmpp/iq.h src/xmpp/presence.h \ src/xmpp/capabilities.h src/xmpp/connection.h \ - src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/windows.c \ + src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/console.c \ src/command/command.h src/command/command.c src/command/history.c \ diff --git a/src/ui/windows.c b/src/ui/core.c similarity index 99% rename from src/ui/windows.c rename to src/ui/core.c index 295619af..719c8a24 100644 --- a/src/ui/windows.c +++ b/src/ui/core.c @@ -1,5 +1,5 @@ /* - * windows.c + * core.c * * Copyright (C) 2012, 2013 James Booth * From 345c21bbce2596591118ccd459c3104d49557ba0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 17:35:57 +0100 Subject: [PATCH 28/37] Renamed clear and close functions in ui --- src/command/command.c | 4 ++-- src/ui/core.c | 4 ++-- src/ui/ui.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index d0f13c8b..1775de2a 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -2302,7 +2302,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) static gboolean _cmd_clear(gchar **args, struct cmd_help_t help) { - win_current_clear(); + ui_clear_current(); return TRUE; } @@ -2338,7 +2338,7 @@ _cmd_close(gchar **args, struct cmd_help_t help) } // close the window - win_current_close(); + ui_close_current(); return TRUE; } diff --git a/src/ui/core.c b/src/ui/core.c index 719c8a24..846ba5d1 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -513,14 +513,14 @@ ui_switch_win(const int i) } void -win_current_clear(void) +ui_clear_current(void) { wclear(current->win); dirty = TRUE; } void -win_current_close(void) +ui_close_current(void) { window_free(current); windows[current_index] = NULL; diff --git a/src/ui/ui.h b/src/ui/ui.h index e1ecb83b..937ab566 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -84,8 +84,8 @@ void title_bar_set_typing(gboolean is_typing); void title_bar_draw(void); // current window actions -void win_current_close(void); -void win_current_clear(void); +void ui_close_current(void); +void ui_clear_current(void); int win_current_is_console(void); int win_current_is_chat(void); int win_current_is_groupchat(void); From bf740d99974053a1eba0f2a2b7124aeaf657fdb0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 18:40:22 +0100 Subject: [PATCH 29/37] Replace window type functions with single function returning type --- src/command/command.c | 221 +++++++++++++++++++++++++++--------------- src/profanity.c | 19 ++-- src/ui/console.c | 56 +++++------ src/ui/core.c | 24 +---- src/ui/ui.h | 5 +- 5 files changed, 185 insertions(+), 140 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 1775de2a..a0930e25 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -917,7 +917,7 @@ cmd_reset_autocomplete() autocomplete_reset(notify_ac); autocomplete_reset(sub_ac); - if (win_current_is_groupchat()) { + if (ui_current_win_type() == WIN_MUC) { Autocomplete nick_ac = muc_get_roster_ac(win_current_get_recipient()); if (nick_ac != NULL) { autocomplete_reset(nick_ac); @@ -989,7 +989,7 @@ cmd_execute(const char * const command, const char * const inp) gchar **args = cmd->parser(inp, cmd->min_args, cmd->max_args); if (args == NULL) { cons_show("Usage: %s", cmd->help.usage); - if (win_current_is_chat()) { + if (ui_current_win_type() == WIN_CHAT) { char usage[strlen(cmd->help.usage) + 8]; sprintf(usage, "Usage: %s", cmd->help.usage); win_current_show(usage); @@ -1008,35 +1008,54 @@ cmd_execute(const char * const command, const char * const inp) gboolean cmd_execute_default(const char * const inp) { - if (win_current_is_groupchat()) { - jabber_conn_status_t status = jabber_get_connection_status(); - if (status != JABBER_CONNECTED) { - win_current_show("You are not currently connected."); - } else { - char *recipient = win_current_get_recipient(); - message_send_groupchat(inp, recipient); - free(recipient); - } - } else if (win_current_is_chat() || win_current_is_private()) { - jabber_conn_status_t status = jabber_get_connection_status(); - if (status != JABBER_CONNECTED) { - win_current_show("You are not currently connected."); - } else { - char *recipient = win_current_get_recipient(); - message_send(inp, recipient); + win_type_t win_type = ui_current_win_type(); + jabber_conn_status_t status = jabber_get_connection_status(); + char *recipient = win_current_get_recipient(); - if (win_current_is_chat() && prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_jid(); - Jid *jidp = jid_create(jid); - chat_log_chat(jidp->barejid, recipient, inp, PROF_OUT_LOG, NULL); - jid_destroy(jidp); + switch (win_type) + { + case WIN_MUC: + if (status != JABBER_CONNECTED) { + win_current_show("You are not currently connected."); + } else { + message_send_groupchat(inp, recipient); + free(recipient); } + break; - win_show_outgoing_msg("me", recipient, inp); - free(recipient); - } - } else { - cons_show("Unknown command: %s", inp); + case WIN_CHAT: + if (status != JABBER_CONNECTED) { + win_current_show("You are not currently connected."); + } else { + message_send(inp, recipient); + + if (prefs_get_boolean(PREF_CHLOG)) { + const char *jid = jabber_get_jid(); + Jid *jidp = jid_create(jid); + chat_log_chat(jidp->barejid, recipient, inp, PROF_OUT_LOG, NULL); + jid_destroy(jidp); + } + + win_show_outgoing_msg("me", recipient, inp); + free(recipient); + } + break; + + case WIN_PRIVATE: + if (status != JABBER_CONNECTED) { + win_current_show("You are not currently connected."); + } else { + message_send(inp, recipient); + win_show_outgoing_msg("me", recipient, inp); + free(recipient); + } + break; + + case WIN_CONSOLE: + cons_show("Unknown command: %s", inp); + break; + default: + break; } return TRUE; @@ -1068,7 +1087,7 @@ _cmd_complete_parameters(char *input, int *size) _parameter_autocomplete(input, size, "/statuses", prefs_autocomplete_boolean_choice); - if (win_current_is_groupchat()) { + if (ui_current_win_type() == WIN_MUC) { Autocomplete nick_ac = muc_get_roster_ac(win_current_get_recipient()); if (nick_ac != NULL) { _parameter_autocomplete_with_ac(input, size, "/msg", nick_ac); @@ -1333,6 +1352,7 @@ static gboolean _cmd_sub(gchar **args, struct cmd_help_t help) { jabber_conn_status_t conn_status = jabber_get_connection_status(); + win_type_t win_type = ui_current_win_type(); if (conn_status != JABBER_CONNECTED) { cons_show("You are currently not connected."); @@ -1383,7 +1403,7 @@ _cmd_sub(gchar **args, struct cmd_help_t help) return TRUE; } - if (!win_current_is_chat() && (jid == NULL)) { + if ((win_type != WIN_CHAT) && (jid == NULL)) { cons_show("You must specify a contact."); return TRUE; } @@ -1411,13 +1431,13 @@ _cmd_sub(gchar **args, struct cmd_help_t help) } else if (strcmp(subcmd, "show") == 0) { PContact contact = contact_list_get_contact(bare_jid); if ((contact == NULL) || (p_contact_subscription(contact) == NULL)) { - if (win_current_is_chat()) { + if (win_type == WIN_CHAT) { win_current_show("No subscription information for %s.", bare_jid); } else { cons_show("No subscription information for %s.", bare_jid); } } else { - if (win_current_is_chat()) { + if (win_type == WIN_CHAT) { if (p_contact_pending_out(contact)) { win_current_show("%s subscription status: %s, request pending.", bare_jid, p_contact_subscription(contact)); @@ -1550,7 +1570,7 @@ _cmd_about(gchar **args, struct cmd_help_t help) { cons_show(""); cons_about(); - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } return TRUE; @@ -1623,6 +1643,7 @@ static gboolean _cmd_who(gchar **args, struct cmd_help_t help) { jabber_conn_status_t conn_status = jabber_get_connection_status(); + win_type_t win_type = ui_current_win_type(); if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); @@ -1643,7 +1664,7 @@ _cmd_who(gchar **args, struct cmd_help_t help) // valid arg } else { - if (win_current_is_groupchat()) { + if (win_type == WIN_MUC) { char *room = win_current_get_recipient(); GList *list = muc_get_roster(room); @@ -1811,7 +1832,7 @@ _cmd_who(gchar **args, struct cmd_help_t help) } } - if (!win_current_is_console()) { + if (win_type != WIN_CONSOLE) { status_bar_new(0); } @@ -1825,6 +1846,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help) char *msg = args[1]; jabber_conn_status_t conn_status = jabber_get_connection_status(); + win_type_t win_type = ui_current_win_type(); if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); @@ -1836,7 +1858,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help) return TRUE; } - if (win_current_is_groupchat()) { + if (win_type == WIN_MUC) { char *room_name = win_current_get_recipient(); if (muc_nick_in_roster(room_name, usr)) { GString *full_jid = g_string_new(room_name); @@ -1863,7 +1885,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help) message_send(msg, usr); win_show_outgoing_msg("me", usr, msg); - if (win_current_is_chat() && prefs_get_boolean(PREF_CHLOG)) { + if ((win_type == WIN_CHAT) && prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_jid(); Jid *jidp = jid_create(jid); chat_log_chat(jidp->barejid, usr, msg, PROF_OUT_LOG, NULL); @@ -1884,35 +1906,45 @@ _cmd_status(gchar **args, struct cmd_help_t help) char *usr = args[0]; jabber_conn_status_t conn_status = jabber_get_connection_status(); + win_type_t win_type = ui_current_win_type(); if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); - } else { - if (win_current_is_groupchat()) { + return TRUE; + } + + switch (win_type) + { + case WIN_MUC: if (usr != NULL) { win_room_show_status(usr); } else { win_current_show("You must specify a nickname."); } - } else if (win_current_is_chat()) { + break; + case WIN_CHAT: if (usr != NULL) { win_current_show("No parameter required when in chat."); } else { win_show_status(); } - } else if (win_current_is_private()) { + break; + case WIN_PRIVATE: if (usr != NULL) { win_current_show("No parameter required when in chat."); } else { win_private_show_status(); } - } else { + break; + case WIN_CONSOLE: if (usr != NULL) { cons_show_status(usr); } else { cons_show("Usage: %s", help.usage); } - } + break; + default: + break; } return TRUE; @@ -1924,13 +1956,19 @@ _cmd_info(gchar **args, struct cmd_help_t help) char *usr = args[0]; jabber_conn_status_t conn_status = jabber_get_connection_status(); + win_type_t win_type = ui_current_win_type(); + PContact pcontact = NULL; if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); - } else { - if (win_current_is_groupchat()) { + return TRUE; + } + + switch (win_type) + { + case WIN_MUC: if (usr != NULL) { - PContact pcontact = muc_get_participant(win_current_get_recipient(), usr); + pcontact = muc_get_participant(win_current_get_recipient(), usr); if (pcontact != NULL) { cons_show_info(pcontact); } else { @@ -1939,25 +1977,25 @@ _cmd_info(gchar **args, struct cmd_help_t help) } else { cons_show("No nickname supplied to /info in chat room."); } - - } else if (win_current_is_chat()) { + break; + case WIN_CHAT: if (usr != NULL) { cons_show("No parameter required for /info in chat."); } else { - PContact pcontact = contact_list_get_contact(win_current_get_recipient()); + pcontact = contact_list_get_contact(win_current_get_recipient()); if (pcontact != NULL) { cons_show_info(pcontact); } else { cons_show("No such contact \"%s\" in roster.", win_current_get_recipient()); } } - - } else if (win_current_is_private()) { + break; + case WIN_PRIVATE: if (usr != NULL) { win_current_show("No parameter required when in chat."); } else { Jid *jid = jid_create(win_current_get_recipient()); - PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart); + pcontact = muc_get_participant(jid->barejid, jid->resourcepart); if (pcontact != NULL) { cons_show_info(pcontact); } else { @@ -1965,9 +2003,10 @@ _cmd_info(gchar **args, struct cmd_help_t help) } jid_destroy(jid); } - } else { + break; + case WIN_CONSOLE: if (usr != NULL) { - PContact pcontact = contact_list_get_contact(usr); + pcontact = contact_list_get_contact(usr); if (pcontact != NULL) { cons_show_info(pcontact); } else { @@ -1976,7 +2015,9 @@ _cmd_info(gchar **args, struct cmd_help_t help) } else { cons_show("Usage: %s", help.usage); } - } + break; + default: + break; } return TRUE; @@ -1986,13 +2027,19 @@ static gboolean _cmd_caps(gchar **args, struct cmd_help_t help) { jabber_conn_status_t conn_status = jabber_get_connection_status(); + win_type_t win_type = ui_current_win_type(); + PContact pcontact = NULL; if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); - } else { - if (win_current_is_groupchat()) { + return TRUE; + } + + switch (win_type) + { + case WIN_MUC: if (args[0] != NULL) { - PContact pcontact = muc_get_participant(win_current_get_recipient(), args[0]); + pcontact = muc_get_participant(win_current_get_recipient(), args[0]); if (pcontact != NULL) { Resource *resource = p_contact_get_resource(pcontact, args[0]); cons_show_caps(args[0], resource); @@ -2002,14 +2049,16 @@ _cmd_caps(gchar **args, struct cmd_help_t help) } else { cons_show("No nickname supplied to /caps in chat room."); } - } else if (win_current_is_chat() || win_current_is_console()) { + break; + case WIN_CHAT: + case WIN_CONSOLE: if (args[0] != NULL) { Jid *jid = jid_create(args[0]); if (jid->fulljid == NULL) { cons_show("You must provide a full jid to the /caps command."); } else { - PContact pcontact = contact_list_get_contact(jid->barejid); + pcontact = contact_list_get_contact(jid->barejid); if (pcontact == NULL) { cons_show("Contact not found in roster: %s", jid->barejid); } else { @@ -2024,16 +2073,19 @@ _cmd_caps(gchar **args, struct cmd_help_t help) } else { cons_show("You must provide a jid to the /caps command."); } - } else { // private chat + break; + case WIN_PRIVATE: if (args[0] != NULL) { cons_show("No parameter needed to /caps when in private chat."); } else { Jid *jid = jid_create(win_current_get_recipient()); - PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart); + pcontact = muc_get_participant(jid->barejid, jid->resourcepart); Resource *resource = p_contact_get_resource(pcontact, jid->resourcepart); cons_show_caps(jid->resourcepart, resource); } - } + break; + default: + break; } return TRUE; @@ -2044,13 +2096,19 @@ static gboolean _cmd_software(gchar **args, struct cmd_help_t help) { jabber_conn_status_t conn_status = jabber_get_connection_status(); + win_type_t win_type = ui_current_win_type(); + PContact pcontact = NULL; if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); - } else { - if (win_current_is_groupchat()) { + return TRUE; + } + + switch (win_type) + { + case WIN_MUC: if (args[0] != NULL) { - PContact pcontact = muc_get_participant(win_current_get_recipient(), args[0]); + pcontact = muc_get_participant(win_current_get_recipient(), args[0]); if (pcontact != NULL) { Jid *jid = jid_create_from_bare_and_resource(win_current_get_recipient(), args[0]); iq_send_software_version(jid->fulljid); @@ -2061,7 +2119,9 @@ _cmd_software(gchar **args, struct cmd_help_t help) } else { cons_show("No nickname supplied to /software in chat room."); } - } else if (win_current_is_chat() || win_current_is_console()) { + break; + case WIN_CHAT: + case WIN_CONSOLE: if (args[0] != NULL) { Jid *jid = jid_create(args[0]); @@ -2073,13 +2133,16 @@ _cmd_software(gchar **args, struct cmd_help_t help) } else { cons_show("You must provide a jid to the /software command."); } - } else { // private chat + break; + case WIN_PRIVATE: if (args[0] != NULL) { cons_show("No parameter needed to /software when in private chat."); } else { iq_send_software_version(win_current_get_recipient()); } - } + break; + default: + break; } return TRUE; @@ -2155,7 +2218,7 @@ _cmd_invite(gchar **args, struct cmd_help_t help) return TRUE; } - if (!win_current_is_groupchat()) { + if (ui_current_win_type() != WIN_MUC) { cons_show("You must be in a chat room to send an invite."); return TRUE; } @@ -2236,7 +2299,7 @@ _cmd_nick(gchar **args, struct cmd_help_t help) cons_show("You are not currently connected."); return TRUE; } - if (!win_current_is_groupchat()) { + if (ui_current_win_type() != WIN_MUC) { cons_show("You can only change your nickname in a chat room window."); return TRUE; } @@ -2252,20 +2315,21 @@ static gboolean _cmd_tiny(gchar **args, struct cmd_help_t help) { char *url = args[0]; + win_type_t win_type = ui_current_win_type(); if (!tinyurl_valid(url)) { GString *error = g_string_new("/tiny, badly formed URL: "); g_string_append(error, url); cons_show_error(error->str); - if (!win_current_is_console()) { + if (win_type != WIN_CONSOLE) { win_current_bad_show(error->str); } g_string_free(error, TRUE); - } else if (!win_current_is_console()) { + } else if (win_type != WIN_CONSOLE) { char *tiny = tinyurl_get(url); if (tiny != NULL) { - if (win_current_is_chat()) { + if (win_type == WIN_CHAT) { char *recipient = win_current_get_recipient(); message_send(tiny, recipient); @@ -2278,7 +2342,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) win_show_outgoing_msg("me", recipient, tiny); free(recipient); - } else if (win_current_is_private()) { + } else if (win_type == WIN_PRIVATE) { char *recipient = win_current_get_recipient(); message_send(tiny, recipient); win_show_outgoing_msg("me", recipient, tiny); @@ -2310,19 +2374,20 @@ static gboolean _cmd_close(gchar **args, struct cmd_help_t help) { jabber_conn_status_t conn_status = jabber_get_connection_status(); + win_type_t win_type = ui_current_win_type(); // cannot close console window - if (win_current_is_console()) { + if (win_type == WIN_CONSOLE) { cons_show("Cannot close console window."); return TRUE; } // handle leaving rooms, or chat if (conn_status == JABBER_CONNECTED) { - if (win_current_is_groupchat()) { + if (win_type == WIN_MUC) { char *room_jid = win_current_get_recipient(); presence_leave_chat_room(room_jid); - } else if (win_current_is_chat() || win_current_is_private()) { + } else if ((win_type == WIN_CHAT) || (win_type == WIN_PRIVATE)) { if (prefs_get_boolean(PREF_STATES)) { char *recipient = win_current_get_recipient(); diff --git a/src/profanity.c b/src/profanity.c index 0c872261..cf6c9dfa 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -142,10 +142,11 @@ prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp, void prof_handle_error_message(const char *from, const char *err_msg) { + win_type_t win_type = ui_current_win_type(); if (err_msg == NULL) { cons_show_error("Unknown error received from service."); } else if (strcmp(err_msg, "conflict") == 0) { - if (win_current_is_groupchat()) { + if (win_type == WIN_MUC) { win_current_show("Nickname already in use."); } else { cons_show_error("Error received from server: %s", err_msg); @@ -388,15 +389,15 @@ prof_handle_idle(void) void prof_handle_activity(void) { + win_type_t win_type = ui_current_win_type(); jabber_conn_status_t status = jabber_get_connection_status(); - if (status == JABBER_CONNECTED) { - if (win_current_is_chat()) { - char *recipient = win_current_get_recipient(); - chat_session_set_composing(recipient); - if (!chat_session_get_sent(recipient) || - chat_session_is_paused(recipient)) { - message_send_composing(recipient); - } + + if ((status == JABBER_CONNECTED) && (win_type == WIN_CHAT)) { + char *recipient = win_current_get_recipient(); + chat_session_set_composing(recipient); + if (!chat_session_get_sent(recipient) || + chat_session_is_paused(recipient)) { + message_send_composing(recipient); } } } diff --git a/src/ui/console.c b/src/ui/console.c index 81502599..2cb4e8a2 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -77,7 +77,7 @@ cons_show_word(const char * const word) wprintw(console->win, "%s", word); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -96,7 +96,7 @@ cons_debug(const char * const msg, ...) va_end(arg); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } @@ -135,7 +135,7 @@ cons_show_error(const char * const msg, ...) va_end(arg); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -200,7 +200,7 @@ cons_about(void) prefresh(console->win, 0, 0, 1, 0, rows-3, cols-1); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -230,7 +230,7 @@ cons_check_version(gboolean not_available_msg) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -325,7 +325,7 @@ cons_show_wins(void) cons_show(""); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -459,7 +459,7 @@ cons_show_info(PContact pcontact) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -535,7 +535,7 @@ cons_show_caps(const char * const contact, Resource *resource) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -563,7 +563,7 @@ cons_show_software_version(const char * const jid, const char * const presence, } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -588,7 +588,7 @@ cons_show_room_list(GSList *rooms, const char * const conference_node) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -632,7 +632,7 @@ cons_show_disco_info(const char *jid, GSList *identities, GSList *features) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -659,7 +659,7 @@ cons_show_disco_items(GSList *items, const char * const jid) cons_show("No service discovery items for %s", jid); } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -707,7 +707,7 @@ cons_show_room_invite(const char * const invitor, const char * const room, g_string_free(default_service, TRUE); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -738,7 +738,7 @@ cons_show_account_list(gchar **accounts) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -853,7 +853,7 @@ cons_show_account(ProfAccount *account) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -912,7 +912,7 @@ cons_show_ui_prefs(void) cons_show("Status (/statuses) : OFF"); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -969,7 +969,7 @@ cons_show_chat_prefs(void) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -988,7 +988,7 @@ cons_show_log_prefs(void) cons_show("Chat logging (/chlog) : OFF"); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -1021,7 +1021,7 @@ cons_show_presence_prefs(void) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -1051,7 +1051,7 @@ cons_show_connection_prefs(void) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -1072,7 +1072,7 @@ cons_show_themes(GSList *themes) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -1095,7 +1095,7 @@ cons_prefs(void) cons_show(""); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -1115,7 +1115,7 @@ cons_help(void) cons_show(""); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -1128,7 +1128,7 @@ cons_basic_help(void) _cons_show_basic_help(); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -1150,7 +1150,7 @@ cons_settings_help(void) cons_show(""); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -1172,7 +1172,7 @@ cons_presence_help(void) cons_show(""); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -1195,7 +1195,7 @@ cons_navigation_help(void) cons_show(""); dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } @@ -1214,7 +1214,7 @@ cons_show_contacts(GSList *list) } dirty = TRUE; - if (!win_current_is_console()) { + if (ui_current_win_type() != WIN_CONSOLE) { status_bar_new(0); } } diff --git a/src/ui/core.c b/src/ui/core.c index 846ba5d1..f0e7bfda 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -536,28 +536,10 @@ ui_close_current(void) dirty = TRUE; } -int -win_current_is_console(void) +win_type_t +ui_current_win_type(void) { - return (current->type == WIN_CONSOLE); -} - -int -win_current_is_chat(void) -{ - return (current->type == WIN_CHAT); -} - -int -win_current_is_groupchat(void) -{ - return (current->type == WIN_MUC); -} - -int -win_current_is_private(void) -{ - return (current->type == WIN_PRIVATE); + return current->type; } char * diff --git a/src/ui/ui.h b/src/ui/ui.h index 937ab566..a6ad5791 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -86,10 +86,7 @@ void title_bar_draw(void); // current window actions void ui_close_current(void); void ui_clear_current(void); -int win_current_is_console(void); -int win_current_is_chat(void); -int win_current_is_groupchat(void); -int win_current_is_private(void); +win_type_t ui_current_win_type(void); char* win_current_get_recipient(void); void win_current_show(const char * const msg, ...); void win_current_bad_show(const char * const msg); From 954c9ededc3d822eb0b04b501d2e3f9e5c197ffa Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 18:47:37 +0100 Subject: [PATCH 30/37] Renamed win_current_get_recipient -> ui_current_win_recipient --- src/command/command.c | 44 +++++++++++++++++++++---------------------- src/profanity.c | 2 +- src/ui/core.c | 8 ++++---- src/ui/ui.h | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index a0930e25..0999bcaf 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -918,7 +918,7 @@ cmd_reset_autocomplete() autocomplete_reset(sub_ac); if (ui_current_win_type() == WIN_MUC) { - Autocomplete nick_ac = muc_get_roster_ac(win_current_get_recipient()); + Autocomplete nick_ac = muc_get_roster_ac(ui_current_win_recipient()); if (nick_ac != NULL) { autocomplete_reset(nick_ac); } @@ -1010,7 +1010,7 @@ cmd_execute_default(const char * const inp) { win_type_t win_type = ui_current_win_type(); jabber_conn_status_t status = jabber_get_connection_status(); - char *recipient = win_current_get_recipient(); + char *recipient = ui_current_win_recipient(); switch (win_type) { @@ -1088,7 +1088,7 @@ _cmd_complete_parameters(char *input, int *size) prefs_autocomplete_boolean_choice); if (ui_current_win_type() == WIN_MUC) { - Autocomplete nick_ac = muc_get_roster_ac(win_current_get_recipient()); + Autocomplete nick_ac = muc_get_roster_ac(ui_current_win_recipient()); if (nick_ac != NULL) { _parameter_autocomplete_with_ac(input, size, "/msg", nick_ac); _parameter_autocomplete_with_ac(input, size, "/info", nick_ac); @@ -1411,7 +1411,7 @@ _cmd_sub(gchar **args, struct cmd_help_t help) if (jid != NULL) { jid = strdup(jid); } else { - jid = win_current_get_recipient(); + jid = ui_current_win_recipient(); } bare_jid = strtok(jid, "/"); @@ -1665,7 +1665,7 @@ _cmd_who(gchar **args, struct cmd_help_t help) // valid arg } else { if (win_type == WIN_MUC) { - char *room = win_current_get_recipient(); + char *room = ui_current_win_recipient(); GList *list = muc_get_roster(room); // no arg, show all contacts @@ -1859,7 +1859,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help) } if (win_type == WIN_MUC) { - char *room_name = win_current_get_recipient(); + char *room_name = ui_current_win_recipient(); if (muc_nick_in_roster(room_name, usr)) { GString *full_jid = g_string_new(room_name); g_string_append(full_jid, "/"); @@ -1968,7 +1968,7 @@ _cmd_info(gchar **args, struct cmd_help_t help) { case WIN_MUC: if (usr != NULL) { - pcontact = muc_get_participant(win_current_get_recipient(), usr); + pcontact = muc_get_participant(ui_current_win_recipient(), usr); if (pcontact != NULL) { cons_show_info(pcontact); } else { @@ -1982,11 +1982,11 @@ _cmd_info(gchar **args, struct cmd_help_t help) if (usr != NULL) { cons_show("No parameter required for /info in chat."); } else { - pcontact = contact_list_get_contact(win_current_get_recipient()); + pcontact = contact_list_get_contact(ui_current_win_recipient()); if (pcontact != NULL) { cons_show_info(pcontact); } else { - cons_show("No such contact \"%s\" in roster.", win_current_get_recipient()); + cons_show("No such contact \"%s\" in roster.", ui_current_win_recipient()); } } break; @@ -1994,7 +1994,7 @@ _cmd_info(gchar **args, struct cmd_help_t help) if (usr != NULL) { win_current_show("No parameter required when in chat."); } else { - Jid *jid = jid_create(win_current_get_recipient()); + Jid *jid = jid_create(ui_current_win_recipient()); pcontact = muc_get_participant(jid->barejid, jid->resourcepart); if (pcontact != NULL) { cons_show_info(pcontact); @@ -2039,7 +2039,7 @@ _cmd_caps(gchar **args, struct cmd_help_t help) { case WIN_MUC: if (args[0] != NULL) { - pcontact = muc_get_participant(win_current_get_recipient(), args[0]); + pcontact = muc_get_participant(ui_current_win_recipient(), args[0]); if (pcontact != NULL) { Resource *resource = p_contact_get_resource(pcontact, args[0]); cons_show_caps(args[0], resource); @@ -2078,7 +2078,7 @@ _cmd_caps(gchar **args, struct cmd_help_t help) if (args[0] != NULL) { cons_show("No parameter needed to /caps when in private chat."); } else { - Jid *jid = jid_create(win_current_get_recipient()); + Jid *jid = jid_create(ui_current_win_recipient()); pcontact = muc_get_participant(jid->barejid, jid->resourcepart); Resource *resource = p_contact_get_resource(pcontact, jid->resourcepart); cons_show_caps(jid->resourcepart, resource); @@ -2108,9 +2108,9 @@ _cmd_software(gchar **args, struct cmd_help_t help) { case WIN_MUC: if (args[0] != NULL) { - pcontact = muc_get_participant(win_current_get_recipient(), args[0]); + pcontact = muc_get_participant(ui_current_win_recipient(), args[0]); if (pcontact != NULL) { - Jid *jid = jid_create_from_bare_and_resource(win_current_get_recipient(), args[0]); + Jid *jid = jid_create_from_bare_and_resource(ui_current_win_recipient(), args[0]); iq_send_software_version(jid->fulljid); jid_destroy(jid); } else { @@ -2138,7 +2138,7 @@ _cmd_software(gchar **args, struct cmd_help_t help) if (args[0] != NULL) { cons_show("No parameter needed to /software when in private chat."); } else { - iq_send_software_version(win_current_get_recipient()); + iq_send_software_version(ui_current_win_recipient()); } break; default: @@ -2223,7 +2223,7 @@ _cmd_invite(gchar **args, struct cmd_help_t help) return TRUE; } - room = win_current_get_recipient(); + room = ui_current_win_recipient(); message_send_invite(room, contact, reason); if (reason != NULL) { cons_show("Room invite sent, contact: %s, room: %s, reason: \"%s\".", @@ -2304,7 +2304,7 @@ _cmd_nick(gchar **args, struct cmd_help_t help) return TRUE; } - char *room = win_current_get_recipient(); + char *room = ui_current_win_recipient(); char *nick = args[0]; presence_change_room_nick(room, nick); @@ -2330,7 +2330,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) if (tiny != NULL) { if (win_type == WIN_CHAT) { - char *recipient = win_current_get_recipient(); + char *recipient = ui_current_win_recipient(); message_send(tiny, recipient); if (prefs_get_boolean(PREF_CHLOG)) { @@ -2343,12 +2343,12 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) win_show_outgoing_msg("me", recipient, tiny); free(recipient); } else if (win_type == WIN_PRIVATE) { - char *recipient = win_current_get_recipient(); + char *recipient = ui_current_win_recipient(); message_send(tiny, recipient); win_show_outgoing_msg("me", recipient, tiny); free(recipient); } else { // groupchat - char *recipient = win_current_get_recipient(); + char *recipient = ui_current_win_recipient(); message_send_groupchat(tiny, recipient); free(recipient); } @@ -2385,12 +2385,12 @@ _cmd_close(gchar **args, struct cmd_help_t help) // handle leaving rooms, or chat if (conn_status == JABBER_CONNECTED) { if (win_type == WIN_MUC) { - char *room_jid = win_current_get_recipient(); + char *room_jid = ui_current_win_recipient(); presence_leave_chat_room(room_jid); } else if ((win_type == WIN_CHAT) || (win_type == WIN_PRIVATE)) { if (prefs_get_boolean(PREF_STATES)) { - char *recipient = win_current_get_recipient(); + char *recipient = ui_current_win_recipient(); // send chat state before closing if (chat_session_get_recipient_supports(recipient)) { diff --git a/src/profanity.c b/src/profanity.c index cf6c9dfa..0d91313e 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -393,7 +393,7 @@ prof_handle_activity(void) jabber_conn_status_t status = jabber_get_connection_status(); if ((status == JABBER_CONNECTED) && (win_type == WIN_CHAT)) { - char *recipient = win_current_get_recipient(); + char *recipient = ui_current_win_recipient(); chat_session_set_composing(recipient); if (!chat_session_get_sent(recipient) || chat_session_is_paused(recipient)) { diff --git a/src/ui/core.c b/src/ui/core.c index f0e7bfda..9042969f 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -543,7 +543,7 @@ ui_current_win_type(void) } char * -win_current_get_recipient(void) +ui_current_win_recipient(void) { return strdup(current->from); } @@ -1044,7 +1044,7 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) void win_show_status(void) { - char *recipient = win_current_get_recipient(); + char *recipient = ui_current_win_recipient(); PContact pcontact = contact_list_get_contact(recipient); if (pcontact != NULL) { @@ -1057,7 +1057,7 @@ win_show_status(void) void win_private_show_status(void) { - Jid *jid = jid_create(win_current_get_recipient()); + Jid *jid = jid_create(ui_current_win_recipient()); PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart); @@ -1073,7 +1073,7 @@ win_private_show_status(void) void win_room_show_status(const char * const contact) { - PContact pcontact = muc_get_participant(win_current_get_recipient(), contact); + PContact pcontact = muc_get_participant(ui_current_win_recipient(), contact); if (pcontact != NULL) { window_show_contact(current, pcontact); diff --git a/src/ui/ui.h b/src/ui/ui.h index a6ad5791..11c91712 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -87,7 +87,7 @@ void title_bar_draw(void); void ui_close_current(void); void ui_clear_current(void); win_type_t ui_current_win_type(void); -char* win_current_get_recipient(void); +char* ui_current_win_recipient(void); void win_current_show(const char * const msg, ...); void win_current_bad_show(const char * const msg); void win_current_page_off(void); From 1046a00405a9c963974e5fd60e0692a8ce4c720b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 19:44:31 +0100 Subject: [PATCH 31/37] Renamed remaining win_ functions --- src/command/command.c | 106 +++++++++++++++++++++--------------------- src/profanity.c | 104 ++++++++++++++++++++--------------------- src/ui/console.c | 2 +- src/ui/core.c | 66 +++++++++++++------------- src/ui/ui.h | 97 +++++++++++++++++++------------------- 5 files changed, 188 insertions(+), 187 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 0999bcaf..adb831f4 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -918,7 +918,7 @@ cmd_reset_autocomplete() autocomplete_reset(sub_ac); if (ui_current_win_type() == WIN_MUC) { - Autocomplete nick_ac = muc_get_roster_ac(ui_current_win_recipient()); + Autocomplete nick_ac = muc_get_roster_ac(ui_current_recipient()); if (nick_ac != NULL) { autocomplete_reset(nick_ac); } @@ -992,7 +992,7 @@ cmd_execute(const char * const command, const char * const inp) if (ui_current_win_type() == WIN_CHAT) { char usage[strlen(cmd->help.usage) + 8]; sprintf(usage, "Usage: %s", cmd->help.usage); - win_current_show(usage); + ui_current_print_line(usage); } return TRUE; } else { @@ -1010,13 +1010,13 @@ cmd_execute_default(const char * const inp) { win_type_t win_type = ui_current_win_type(); jabber_conn_status_t status = jabber_get_connection_status(); - char *recipient = ui_current_win_recipient(); + char *recipient = ui_current_recipient(); switch (win_type) { case WIN_MUC: if (status != JABBER_CONNECTED) { - win_current_show("You are not currently connected."); + ui_current_print_line("You are not currently connected."); } else { message_send_groupchat(inp, recipient); free(recipient); @@ -1025,7 +1025,7 @@ cmd_execute_default(const char * const inp) case WIN_CHAT: if (status != JABBER_CONNECTED) { - win_current_show("You are not currently connected."); + ui_current_print_line("You are not currently connected."); } else { message_send(inp, recipient); @@ -1036,17 +1036,17 @@ cmd_execute_default(const char * const inp) jid_destroy(jidp); } - win_show_outgoing_msg("me", recipient, inp); + ui_outgoing_msg("me", recipient, inp); free(recipient); } break; case WIN_PRIVATE: if (status != JABBER_CONNECTED) { - win_current_show("You are not currently connected."); + ui_current_print_line("You are not currently connected."); } else { message_send(inp, recipient); - win_show_outgoing_msg("me", recipient, inp); + ui_outgoing_msg("me", recipient, inp); free(recipient); } break; @@ -1088,7 +1088,7 @@ _cmd_complete_parameters(char *input, int *size) prefs_autocomplete_boolean_choice); if (ui_current_win_type() == WIN_MUC) { - Autocomplete nick_ac = muc_get_roster_ac(ui_current_win_recipient()); + Autocomplete nick_ac = muc_get_roster_ac(ui_current_recipient()); if (nick_ac != NULL) { _parameter_autocomplete_with_ac(input, size, "/msg", nick_ac); _parameter_autocomplete_with_ac(input, size, "/info", nick_ac); @@ -1411,7 +1411,7 @@ _cmd_sub(gchar **args, struct cmd_help_t help) if (jid != NULL) { jid = strdup(jid); } else { - jid = ui_current_win_recipient(); + jid = ui_current_recipient(); } bare_jid = strtok(jid, "/"); @@ -1432,17 +1432,17 @@ _cmd_sub(gchar **args, struct cmd_help_t help) PContact contact = contact_list_get_contact(bare_jid); if ((contact == NULL) || (p_contact_subscription(contact) == NULL)) { if (win_type == WIN_CHAT) { - win_current_show("No subscription information for %s.", bare_jid); + ui_current_print_line("No subscription information for %s.", bare_jid); } else { cons_show("No subscription information for %s.", bare_jid); } } else { if (win_type == WIN_CHAT) { if (p_contact_pending_out(contact)) { - win_current_show("%s subscription status: %s, request pending.", + ui_current_print_line("%s subscription status: %s, request pending.", bare_jid, p_contact_subscription(contact)); } else { - win_current_show("%s subscription status: %s.", bare_jid, + ui_current_print_line("%s subscription status: %s.", bare_jid, p_contact_subscription(contact)); } } else { @@ -1665,12 +1665,12 @@ _cmd_who(gchar **args, struct cmd_help_t help) // valid arg } else { if (win_type == WIN_MUC) { - char *room = ui_current_win_recipient(); + char *room = ui_current_recipient(); GList *list = muc_get_roster(room); // no arg, show all contacts if (presence == NULL) { - win_show_room_roster(room, list, NULL); + ui_room_roster(room, list, NULL); // available } else if (strcmp("available", presence) == 0) { @@ -1684,7 +1684,7 @@ _cmd_who(gchar **args, struct cmd_help_t help) list = g_list_next(list); } - win_show_room_roster(room, filtered, "available"); + ui_room_roster(room, filtered, "available"); // unavailable } else if (strcmp("unavailable", presence) == 0) { @@ -1698,7 +1698,7 @@ _cmd_who(gchar **args, struct cmd_help_t help) list = g_list_next(list); } - win_show_room_roster(room, filtered, "unavailable"); + ui_room_roster(room, filtered, "unavailable"); // online, available resources } else if (strcmp("online", presence) == 0) { @@ -1712,7 +1712,7 @@ _cmd_who(gchar **args, struct cmd_help_t help) list = g_list_next(list); } - win_show_room_roster(room, filtered, "online"); + ui_room_roster(room, filtered, "online"); // offline, no available resources } else if (strcmp("offline", presence) == 0) { @@ -1726,7 +1726,7 @@ _cmd_who(gchar **args, struct cmd_help_t help) list = g_list_next(list); } - win_show_room_roster(room, filtered, "offline"); + ui_room_roster(room, filtered, "offline"); // show specific status } else { @@ -1740,7 +1740,7 @@ _cmd_who(gchar **args, struct cmd_help_t help) list = g_list_next(list); } - win_show_room_roster(room, filtered, presence); + ui_room_roster(room, filtered, presence); } // not in groupchat window @@ -1859,7 +1859,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help) } if (win_type == WIN_MUC) { - char *room_name = ui_current_win_recipient(); + char *room_name = ui_current_recipient(); if (muc_nick_in_roster(room_name, usr)) { GString *full_jid = g_string_new(room_name); g_string_append(full_jid, "/"); @@ -1867,15 +1867,15 @@ _cmd_msg(gchar **args, struct cmd_help_t help) if (msg != NULL) { message_send(msg, full_jid->str); - win_show_outgoing_msg("me", full_jid->str, msg); + ui_outgoing_msg("me", full_jid->str, msg); } else { - win_new_chat_win(full_jid->str); + ui_new_chat_win(full_jid->str); } g_string_free(full_jid, TRUE); } else { - win_current_show("No such participant \"%s\" in room.", usr); + ui_current_print_line("No such participant \"%s\" in room.", usr); } return TRUE; @@ -1883,7 +1883,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help) } else { if (msg != NULL) { message_send(msg, usr); - win_show_outgoing_msg("me", usr, msg); + ui_outgoing_msg("me", usr, msg); if ((win_type == WIN_CHAT) && prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_jid(); @@ -1894,7 +1894,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help) return TRUE; } else { - win_new_chat_win(usr); + ui_new_chat_win(usr); return TRUE; } } @@ -1917,23 +1917,23 @@ _cmd_status(gchar **args, struct cmd_help_t help) { case WIN_MUC: if (usr != NULL) { - win_room_show_status(usr); + ui_status_room(usr); } else { - win_current_show("You must specify a nickname."); + ui_current_print_line("You must specify a nickname."); } break; case WIN_CHAT: if (usr != NULL) { - win_current_show("No parameter required when in chat."); + ui_current_print_line("No parameter required when in chat."); } else { - win_show_status(); + ui_status(); } break; case WIN_PRIVATE: if (usr != NULL) { - win_current_show("No parameter required when in chat."); + ui_current_print_line("No parameter required when in chat."); } else { - win_private_show_status(); + ui_status_private(); } break; case WIN_CONSOLE: @@ -1968,7 +1968,7 @@ _cmd_info(gchar **args, struct cmd_help_t help) { case WIN_MUC: if (usr != NULL) { - pcontact = muc_get_participant(ui_current_win_recipient(), usr); + pcontact = muc_get_participant(ui_current_recipient(), usr); if (pcontact != NULL) { cons_show_info(pcontact); } else { @@ -1982,19 +1982,19 @@ _cmd_info(gchar **args, struct cmd_help_t help) if (usr != NULL) { cons_show("No parameter required for /info in chat."); } else { - pcontact = contact_list_get_contact(ui_current_win_recipient()); + pcontact = contact_list_get_contact(ui_current_recipient()); if (pcontact != NULL) { cons_show_info(pcontact); } else { - cons_show("No such contact \"%s\" in roster.", ui_current_win_recipient()); + cons_show("No such contact \"%s\" in roster.", ui_current_recipient()); } } break; case WIN_PRIVATE: if (usr != NULL) { - win_current_show("No parameter required when in chat."); + ui_current_print_line("No parameter required when in chat."); } else { - Jid *jid = jid_create(ui_current_win_recipient()); + Jid *jid = jid_create(ui_current_recipient()); pcontact = muc_get_participant(jid->barejid, jid->resourcepart); if (pcontact != NULL) { cons_show_info(pcontact); @@ -2039,7 +2039,7 @@ _cmd_caps(gchar **args, struct cmd_help_t help) { case WIN_MUC: if (args[0] != NULL) { - pcontact = muc_get_participant(ui_current_win_recipient(), args[0]); + pcontact = muc_get_participant(ui_current_recipient(), args[0]); if (pcontact != NULL) { Resource *resource = p_contact_get_resource(pcontact, args[0]); cons_show_caps(args[0], resource); @@ -2078,7 +2078,7 @@ _cmd_caps(gchar **args, struct cmd_help_t help) if (args[0] != NULL) { cons_show("No parameter needed to /caps when in private chat."); } else { - Jid *jid = jid_create(ui_current_win_recipient()); + Jid *jid = jid_create(ui_current_recipient()); pcontact = muc_get_participant(jid->barejid, jid->resourcepart); Resource *resource = p_contact_get_resource(pcontact, jid->resourcepart); cons_show_caps(jid->resourcepart, resource); @@ -2108,9 +2108,9 @@ _cmd_software(gchar **args, struct cmd_help_t help) { case WIN_MUC: if (args[0] != NULL) { - pcontact = muc_get_participant(ui_current_win_recipient(), args[0]); + pcontact = muc_get_participant(ui_current_recipient(), args[0]); if (pcontact != NULL) { - Jid *jid = jid_create_from_bare_and_resource(ui_current_win_recipient(), args[0]); + Jid *jid = jid_create_from_bare_and_resource(ui_current_recipient(), args[0]); iq_send_software_version(jid->fulljid); jid_destroy(jid); } else { @@ -2138,7 +2138,7 @@ _cmd_software(gchar **args, struct cmd_help_t help) if (args[0] != NULL) { cons_show("No parameter needed to /software when in private chat."); } else { - iq_send_software_version(ui_current_win_recipient()); + iq_send_software_version(ui_current_recipient()); } break; default: @@ -2196,7 +2196,7 @@ _cmd_join(gchar **args, struct cmd_help_t help) if (!muc_room_is_active(room_jid)) { presence_join_room(room_jid); } - win_join_chat(room_jid); + ui_room_join(room_jid); jid_destroy(room_jid); jid_destroy(my_jid); @@ -2223,7 +2223,7 @@ _cmd_invite(gchar **args, struct cmd_help_t help) return TRUE; } - room = ui_current_win_recipient(); + room = ui_current_recipient(); message_send_invite(room, contact, reason); if (reason != NULL) { cons_show("Room invite sent, contact: %s, room: %s, reason: \"%s\".", @@ -2304,7 +2304,7 @@ _cmd_nick(gchar **args, struct cmd_help_t help) return TRUE; } - char *room = ui_current_win_recipient(); + char *room = ui_current_recipient(); char *nick = args[0]; presence_change_room_nick(room, nick); @@ -2322,7 +2322,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) g_string_append(error, url); cons_show_error(error->str); if (win_type != WIN_CONSOLE) { - win_current_bad_show(error->str); + ui_current_error_line(error->str); } g_string_free(error, TRUE); } else if (win_type != WIN_CONSOLE) { @@ -2330,7 +2330,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) if (tiny != NULL) { if (win_type == WIN_CHAT) { - char *recipient = ui_current_win_recipient(); + char *recipient = ui_current_recipient(); message_send(tiny, recipient); if (prefs_get_boolean(PREF_CHLOG)) { @@ -2340,15 +2340,15 @@ _cmd_tiny(gchar **args, struct cmd_help_t help) jid_destroy(jidp); } - win_show_outgoing_msg("me", recipient, tiny); + ui_outgoing_msg("me", recipient, tiny); free(recipient); } else if (win_type == WIN_PRIVATE) { - char *recipient = ui_current_win_recipient(); + char *recipient = ui_current_recipient(); message_send(tiny, recipient); - win_show_outgoing_msg("me", recipient, tiny); + ui_outgoing_msg("me", recipient, tiny); free(recipient); } else { // groupchat - char *recipient = ui_current_win_recipient(); + char *recipient = ui_current_recipient(); message_send_groupchat(tiny, recipient); free(recipient); } @@ -2385,12 +2385,12 @@ _cmd_close(gchar **args, struct cmd_help_t help) // handle leaving rooms, or chat if (conn_status == JABBER_CONNECTED) { if (win_type == WIN_MUC) { - char *room_jid = ui_current_win_recipient(); + char *room_jid = ui_current_recipient(); presence_leave_chat_room(room_jid); } else if ((win_type == WIN_CHAT) || (win_type == WIN_PRIVATE)) { if (prefs_get_boolean(PREF_STATES)) { - char *recipient = ui_current_win_recipient(); + char *recipient = ui_current_recipient(); // send chat state before closing if (chat_session_get_recipient_supports(recipient)) { diff --git a/src/profanity.c b/src/profanity.c index 0d91313e..a0c917f6 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -102,15 +102,15 @@ prof_run(const int disable_tls, char *log_level) void prof_handle_typing(char *from) { - ui_show_typing(from); - win_current_page_off(); + ui_contact_typing(from); + ui_current_page_off(); } void prof_handle_incoming_message(char *from, char *message, gboolean priv) { - ui_show_incoming_msg(from, message, NULL, priv); - win_current_page_off(); + ui_incoming_msg(from, message, NULL, priv); + ui_current_page_off(); if (prefs_get_boolean(PREF_CHLOG) && !priv) { Jid *from_jid = jid_create(from); @@ -126,8 +126,8 @@ void prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp, gboolean priv) { - ui_show_incoming_msg(from, message, &tv_stamp, priv); - win_current_page_off(); + ui_incoming_msg(from, message, &tv_stamp, priv); + ui_current_page_off(); if (prefs_get_boolean(PREF_CHLOG) && !priv) { Jid *from_jid = jid_create(from); @@ -147,7 +147,7 @@ prof_handle_error_message(const char *from, const char *err_msg) cons_show_error("Unknown error received from service."); } else if (strcmp(err_msg, "conflict") == 0) { if (win_type == WIN_MUC) { - win_current_show("Nickname already in use."); + ui_current_print_line("Nickname already in use."); } else { cons_show_error("Error received from server: %s", err_msg); } @@ -155,7 +155,7 @@ prof_handle_error_message(const char *from, const char *err_msg) cons_show_error("Error received from server: %s", err_msg); } - win_show_error_msg(from, err_msg); + ui_print_error_from_recipient(from, err_msg); } void @@ -166,20 +166,20 @@ prof_handle_subscription(const char *from, jabber_subscr_t type) /* TODO: auto-subscribe if needed */ cons_show("Received authorization request from %s", from); log_info("Received authorization request from %s", from); - win_show_system_msg(from, "Authorization request, type '/sub allow' to accept or '/sub deny' to reject"); - win_current_page_off(); + ui_print_system_msg_from_recipient(from, "Authorization request, type '/sub allow' to accept or '/sub deny' to reject"); + ui_current_page_off(); break; case PRESENCE_SUBSCRIBED: cons_show("Subscription received from %s", from); log_info("Subscription received from %s", from); - win_show_system_msg(from, "Subscribed"); - win_current_page_off(); + ui_print_system_msg_from_recipient(from, "Subscribed"); + ui_current_page_off(); break; case PRESENCE_UNSUBSCRIBED: cons_show("%s deleted subscription", from); log_info("%s deleted subscription", from); - win_show_system_msg(from, "Unsubscribed"); - win_current_page_off(); + ui_print_system_msg_from_recipient(from, "Unsubscribed"); + ui_current_page_off(); break; default: /* unknown type */ @@ -196,7 +196,7 @@ prof_handle_login_account_success(char *account_name) cons_show_login_success(account); title_bar_set_status(contact_presence); log_info("%s logged in successfully", account->jid); - win_current_page_off(); + ui_current_page_off(); status_bar_print_message(account->jid); status_bar_refresh(); @@ -206,8 +206,8 @@ prof_handle_login_account_success(char *account_name) void prof_handle_gone(const char * const from) { - win_show_gone(from); - win_current_page_off(); + ui_recipient_gone(from); + ui_current_page_off(); } void @@ -215,7 +215,7 @@ prof_handle_failed_login(void) { cons_show_error("Login failed."); log_info("Login failed"); - win_current_page_off(); + ui_current_page_off(); } void @@ -225,7 +225,7 @@ prof_handle_lost_connection(void) contact_list_clear(); chat_sessions_clear(); ui_disconnected(); - win_current_page_off(); + ui_current_page_off(); } void @@ -236,38 +236,38 @@ prof_handle_disconnect(const char * const jid) contact_list_clear(); chat_sessions_clear(); ui_disconnected(); - win_current_page_off(); + ui_current_page_off(); } void prof_handle_room_history(const char * const room_jid, const char * const nick, GTimeVal tv_stamp, const char * const message) { - win_show_room_history(room_jid, nick, tv_stamp, message); - win_current_page_off(); + ui_room_history(room_jid, nick, tv_stamp, message); + ui_current_page_off(); } void prof_handle_room_message(const char * const room_jid, const char * const nick, const char * const message) { - win_show_room_message(room_jid, nick, message); - win_current_page_off(); + ui_room_message(room_jid, nick, message); + ui_current_page_off(); } void prof_handle_room_subject(const char * const room_jid, const char * const subject) { - win_show_room_subject(room_jid, subject); - win_current_page_off(); + ui_room_subject(room_jid, subject); + ui_current_page_off(); } void prof_handle_room_broadcast(const char *const room_jid, const char * const message) { - win_show_room_broadcast(room_jid, message); - win_current_page_off(); + ui_room_broadcast(room_jid, message); + ui_current_page_off(); } void @@ -275,8 +275,8 @@ prof_handle_room_roster_complete(const char * const room) { muc_set_roster_received(room); GList *roster = muc_get_roster(room); - win_show_room_roster(room, roster, NULL); - win_current_page_off(); + ui_room_roster(room, roster, NULL); + ui_current_page_off(); } void @@ -287,8 +287,8 @@ prof_handle_room_member_presence(const char * const room, gboolean updated = muc_add_to_roster(room, nick, show, status, caps_str); if (updated) { - win_show_room_member_presence(room, nick, show, status); - win_current_page_off(); + ui_room_member_presence(room, nick, show, status); + ui_current_page_off(); } } @@ -298,8 +298,8 @@ prof_handle_room_member_online(const char * const room, const char * const nick, const char * const caps_str) { muc_add_to_roster(room, nick, show, status, caps_str); - win_show_room_member_online(room, nick, show, status); - win_current_page_off(); + ui_room_member_online(room, nick, show, status); + ui_current_page_off(); } void @@ -307,8 +307,8 @@ prof_handle_room_member_offline(const char * const room, const char * const nick const char * const show, const char * const status) { muc_remove_from_roster(room, nick); - win_show_room_member_offline(room, nick); - win_current_page_off(); + ui_room_member_offline(room, nick); + ui_current_page_off(); } void @@ -322,7 +322,7 @@ void prof_handle_room_invite(jabber_invite_t invite_type, const char * const reason) { cons_show_room_invite(invitor, room, reason); - win_current_page_off(); + ui_current_page_off(); } void @@ -337,7 +337,7 @@ prof_handle_contact_online(char *contact, Resource *resource, if (strcmp(p_contact_subscription(result), "none") != 0) { const char *show = string_from_resource_presence(resource->presence); ui_contact_online(contact, resource->name, show, resource->status, last_activity); - win_current_page_off(); + ui_current_page_off(); } } } @@ -354,7 +354,7 @@ prof_handle_contact_offline(char *contact, char *resource, char *status) if (p_contact_subscription(result) != NULL) { if (strcmp(p_contact_subscription(result), "none") != 0) { ui_contact_offline(jid->fulljid, "offline", status); - win_current_page_off(); + ui_current_page_off(); } } jid_destroy(jid); @@ -365,16 +365,16 @@ void prof_handle_room_member_nick_change(const char * const room, const char * const old_nick, const char * const nick) { - win_show_room_member_nick_change(room, old_nick, nick); - win_current_page_off(); + ui_room_member_nick_change(room, old_nick, nick); + ui_current_page_off(); } void prof_handle_room_nick_change(const char * const room, const char * const nick) { - win_show_room_nick_change(room, nick); - win_current_page_off(); + ui_room_nick_change(room, nick); + ui_current_page_off(); } void @@ -393,7 +393,7 @@ prof_handle_activity(void) jabber_conn_status_t status = jabber_get_connection_status(); if ((status == JABBER_CONNECTED) && (win_type == WIN_CHAT)) { - char *recipient = ui_current_win_recipient(); + char *recipient = ui_current_recipient(); chat_session_set_composing(recipient); if (!chat_session_get_sent(recipient) || chat_session_is_paused(recipient)) { @@ -407,28 +407,28 @@ prof_handle_version_result(const char * const jid, const char * const presence, const char * const name, const char * const version, const char * const os) { cons_show_software_version(jid, presence, name, version, os); - win_current_page_off(); + ui_current_page_off(); } void prof_handle_room_list(GSList *rooms, const char *conference_node) { cons_show_room_list(rooms, conference_node); - win_current_page_off(); + ui_current_page_off(); } void prof_handle_disco_items(GSList *items, const char *jid) { cons_show_disco_items(items, jid); - win_current_page_off(); + ui_current_page_off(); } void prof_handle_disco_info(const char *from, GSList *identities, GSList *features) { cons_show_disco_info(from, identities, features); - win_current_page_off(); + ui_current_page_off(); } /* @@ -465,7 +465,7 @@ _process_input(char *inp) inp_win_reset(); contact_list_reset_search_attempts(); - win_current_page_off(); + ui_current_page_off(); return result; } @@ -490,7 +490,7 @@ _handle_idle_time() cons_show("Idle for %d minutes, status set to away (priority %d), \"%s\".", prefs_get_autoaway_time(), pri, prefs_get_string(PREF_AUTOAWAY_MESSAGE)); title_bar_set_status(CONTACT_AWAY); - win_current_page_off(); + ui_current_page_off(); } else { int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), @@ -498,7 +498,7 @@ _handle_idle_time() cons_show("Idle for %d minutes, status set to away (priority %d).", prefs_get_autoaway_time(), pri); title_bar_set_status(CONTACT_AWAY); - win_current_page_off(); + ui_current_page_off(); } // handle idle mode @@ -521,7 +521,7 @@ _handle_idle_time() RESOURCE_ONLINE); cons_show("No longer idle, status set to online (priority %d).", pri); title_bar_set_status(CONTACT_ONLINE); - win_current_page_off(); + ui_current_page_off(); } else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) { presence_update(RESOURCE_ONLINE, NULL, 0); title_bar_set_status(CONTACT_ONLINE); diff --git a/src/ui/console.c b/src/ui/console.c index 2cb4e8a2..6dc31a57 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -100,7 +100,7 @@ cons_debug(const char * const msg, ...) status_bar_new(0); } - win_current_page_off(); + ui_current_page_off(); ui_refresh(); } } diff --git a/src/ui/core.c b/src/ui/core.c index 9042969f..3c3f1f42 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -214,7 +214,7 @@ ui_windows_full(void) } void -ui_show_typing(const char * const from) +ui_contact_typing(const char * const from) { int win_index = _find_prof_win_index(from); @@ -269,7 +269,7 @@ ui_idle(void) } void -ui_show_incoming_msg(const char * const from, const char * const message, +ui_incoming_msg(const char * const from, const char * const message, GTimeVal *tv_stamp, gboolean priv) { char *display_from; @@ -491,11 +491,11 @@ ui_handle_special_keys(const wint_t * const ch, const char * const inp, void ui_switch_win(const int i) { - win_current_page_off(); + ui_current_page_off(); if (windows[i] != NULL) { current_index = i; current = windows[current_index]; - win_current_page_off(); + ui_current_page_off(); current->unread = 0; @@ -543,13 +543,13 @@ ui_current_win_type(void) } char * -ui_current_win_recipient(void) +ui_current_recipient(void) { return strdup(current->from); } void -win_current_show(const char * const msg, ...) +ui_current_print_line(const char * const msg, ...) { va_list arg; va_start(arg, msg); @@ -564,7 +564,7 @@ win_current_show(const char * const msg, ...) } void -win_current_bad_show(const char * const msg) +ui_current_error_line(const char * const msg) { window_print_time(current, '-'); wattron(current->win, COLOUR_ERROR); @@ -575,7 +575,7 @@ win_current_bad_show(const char * const msg) } void -win_current_page_off(void) +ui_current_page_off(void) { int rows = getmaxy(stdscr); ProfWin *window = windows[current_index]; @@ -594,7 +594,7 @@ win_current_page_off(void) } void -win_show_error_msg(const char * const from, const char *err_msg) +ui_print_error_from_recipient(const char * const from, const char *err_msg) { int win_index; ProfWin *window; @@ -615,7 +615,7 @@ win_show_error_msg(const char * const from, const char *err_msg) } void -win_show_system_msg(const char * const from, const char *message) +ui_print_system_msg_from_recipient(const char * const from, const char *message) { int win_index; ProfWin *window; @@ -646,7 +646,7 @@ win_show_system_msg(const char * const from, const char *message) } void -win_show_gone(const char * const from) +ui_recipient_gone(const char * const from) { int win_index; ProfWin *window; @@ -671,7 +671,7 @@ win_show_gone(const char * const from) } void -win_new_chat_win(const char * const to) +ui_new_chat_win(const char * const to) { // if the contact is offline, show a message PContact contact = contact_list_get_contact(to); @@ -713,7 +713,7 @@ win_new_chat_win(const char * const to) } void -win_show_outgoing_msg(const char * const from, const char * const to, +ui_outgoing_msg(const char * const from, const char * const to, const char * const message) { // if the contact is offline, show a message @@ -767,7 +767,7 @@ win_show_outgoing_msg(const char * const from, const char * const to, } void -win_join_chat(Jid *jid) +ui_room_join(Jid *jid) { int win_index = _find_prof_win_index(jid->barejid); @@ -780,7 +780,7 @@ win_join_chat(Jid *jid) } void -win_show_room_roster(const char * const room, GList *roster, const char * const presence) +ui_room_roster(const char * const room, GList *roster, const char * const presence) { int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; @@ -829,7 +829,7 @@ win_show_room_roster(const char * const room, GList *roster, const char * const } void -win_show_room_member_offline(const char * const room, const char * const nick) +ui_room_member_offline(const char * const room, const char * const nick) { int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; @@ -844,7 +844,7 @@ win_show_room_member_offline(const char * const room, const char * const nick) } void -win_show_room_member_online(const char * const room, const char * const nick, +ui_room_member_online(const char * const room, const char * const nick, const char * const show, const char * const status) { int win_index = _find_prof_win_index(room); @@ -860,7 +860,7 @@ win_show_room_member_online(const char * const room, const char * const nick, } void -win_show_room_member_presence(const char * const room, const char * const nick, +ui_room_member_presence(const char * const room, const char * const nick, const char * const show, const char * const status) { int win_index = _find_prof_win_index(room); @@ -874,7 +874,7 @@ win_show_room_member_presence(const char * const room, const char * const nick, } void -win_show_room_member_nick_change(const char * const room, +ui_room_member_nick_change(const char * const room, const char * const old_nick, const char * const nick) { int win_index = _find_prof_win_index(room); @@ -890,7 +890,7 @@ win_show_room_member_nick_change(const char * const room, } void -win_show_room_nick_change(const char * const room, const char * const nick) +ui_room_nick_change(const char * const room, const char * const nick) { int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; @@ -905,7 +905,7 @@ win_show_room_nick_change(const char * const room, const char * const nick) } void -win_show_room_history(const char * const room_jid, const char * const nick, +ui_room_history(const char * const room_jid, const char * const nick, GTimeVal tv_stamp, const char * const message) { int win_index = _find_prof_win_index(room_jid); @@ -931,7 +931,7 @@ win_show_room_history(const char * const room_jid, const char * const nick, } void -win_show_room_message(const char * const room_jid, const char * const nick, +ui_room_message(const char * const room_jid, const char * const nick, const char * const message) { int win_index = _find_prof_win_index(room_jid); @@ -996,7 +996,7 @@ win_show_room_message(const char * const room_jid, const char * const nick, } void -win_show_room_subject(const char * const room_jid, const char * const subject) +ui_room_subject(const char * const room_jid, const char * const subject) { int win_index = _find_prof_win_index(room_jid); ProfWin *window = windows[win_index]; @@ -1019,7 +1019,7 @@ win_show_room_subject(const char * const room_jid, const char * const subject) } void -win_show_room_broadcast(const char * const room_jid, const char * const message) +ui_room_broadcast(const char * const room_jid, const char * const message) { int win_index = _find_prof_win_index(room_jid); ProfWin *window = windows[win_index]; @@ -1042,43 +1042,43 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } void -win_show_status(void) +ui_status(void) { - char *recipient = ui_current_win_recipient(); + char *recipient = ui_current_recipient(); PContact pcontact = contact_list_get_contact(recipient); if (pcontact != NULL) { window_show_contact(current, pcontact); } else { - win_current_show("Error getting contact info."); + ui_current_print_line("Error getting contact info."); } } void -win_private_show_status(void) +ui_status_private(void) { - Jid *jid = jid_create(ui_current_win_recipient()); + Jid *jid = jid_create(ui_current_recipient()); PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart); if (pcontact != NULL) { window_show_contact(current, pcontact); } else { - win_current_show("Error getting contact info."); + ui_current_print_line("Error getting contact info."); } jid_destroy(jid); } void -win_room_show_status(const char * const contact) +ui_status_room(const char * const contact) { - PContact pcontact = muc_get_participant(ui_current_win_recipient(), contact); + PContact pcontact = muc_get_participant(ui_current_recipient(), contact); if (pcontact != NULL) { window_show_contact(current, pcontact); } else { - win_current_show("No such participant \"%s\" in room.", contact); + ui_current_print_line("No such participant \"%s\" in room.", contact); } } diff --git a/src/ui/ui.h b/src/ui/ui.h index 11c91712..47c6fe82 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -45,28 +45,68 @@ // holds console at index 0 and chat wins 1 through to 9 ProfWin* windows[NUM_WINS]; -// gui startup and shutdown, resize +// ui startup and control void ui_init(void); void ui_load_colours(void); void ui_refresh(void); void ui_close(void); void ui_resize(const int ch, const char * const input, const int size); -void ui_show_typing(const char * const from); void ui_idle(void); -void ui_show_incoming_msg(const char * const from, const char * const message, - GTimeVal *tv_stamp, gboolean priv); -void ui_contact_online(const char * const barejid, const char * const resource, - const char * const show, const char * const status, GDateTime *last_activity); -void ui_contact_offline(const char * const from, const char * const show, - const char * const status); -void ui_disconnected(void); void ui_handle_special_keys(const wint_t * const ch, const char * const inp, const int size); void ui_switch_win(const int i); gboolean ui_windows_full(void); unsigned long ui_get_idle_time(void); void ui_reset_idle_time(void); +void ui_new_chat_win(const char * const to); +void ui_print_error_from_recipient(const char * const from, const char *err_msg); +void ui_print_system_msg_from_recipient(const char * const from, const char *message); + +// current window actions +void ui_close_current(void); +void ui_clear_current(void); +win_type_t ui_current_win_type(void); +char* ui_current_recipient(void); +void ui_current_print_line(const char * const msg, ...); +void ui_current_error_line(const char * const msg); +void ui_current_page_off(void); + +// ui events +void ui_contact_typing(const char * const from); +void ui_incoming_msg(const char * const from, const char * const message, + GTimeVal *tv_stamp, gboolean priv); +void ui_contact_online(const char * const barejid, const char * const resource, + const char * const show, const char * const status, GDateTime *last_activity); +void ui_contact_offline(const char * const from, const char * const show, + const char * const status); +void ui_disconnected(void); +void ui_recipient_gone(const char * const from); +void ui_outgoing_msg(const char * const from, const char * const to, + const char * const message); +void ui_room_join(Jid *jid); +void ui_room_roster(const char * const room, GList *roster, const char * const presence); +void ui_room_history(const char * const room_jid, const char * const nick, + GTimeVal tv_stamp, const char * const message); +void ui_room_message(const char * const room_jid, const char * const nick, + const char * const message); +void ui_room_subject(const char * const room_jid, + const char * const subject); +void ui_room_broadcast(const char * const room_jid, + const char * const message); +void ui_room_member_offline(const char * const room, const char * const nick); +void ui_room_member_online(const char * const room, + const char * const nick, const char * const show, const char * const status); +void ui_room_member_nick_change(const char * const room, + const char * const old_nick, const char * const nick); +void ui_room_nick_change(const char * const room, const char * const nick); +void ui_room_member_presence(const char * const room, + const char * const nick, const char * const show, const char * const status); + +// contact status functions +void ui_status_room(const char * const contact); +void ui_status(void); +void ui_status_private(void); // create windows void create_title_bar(void); @@ -83,45 +123,6 @@ void title_bar_set_recipient(char *from); void title_bar_set_typing(gboolean is_typing); void title_bar_draw(void); -// current window actions -void ui_close_current(void); -void ui_clear_current(void); -win_type_t ui_current_win_type(void); -char* ui_current_win_recipient(void); -void win_current_show(const char * const msg, ...); -void win_current_bad_show(const char * const msg); -void win_current_page_off(void); - -void win_show_error_msg(const char * const from, const char *err_msg); -void win_show_gone(const char * const from); -void win_show_system_msg(const char * const from, const char *message); -void win_show_outgoing_msg(const char * const from, const char * const to, - const char * const message); -void win_new_chat_win(const char * const to); - -void win_join_chat(Jid *jid); -void win_show_room_roster(const char * const room, GList *roster, const char * const presence); -void win_show_room_history(const char * const room_jid, const char * const nick, - GTimeVal tv_stamp, const char * const message); -void win_show_room_message(const char * const room_jid, const char * const nick, - const char * const message); -void win_show_room_subject(const char * const room_jid, - const char * const subject); -void win_show_room_broadcast(const char * const room_jid, - const char * const message); -void win_show_room_member_offline(const char * const room, const char * const nick); -void win_show_room_member_online(const char * const room, - const char * const nick, const char * const show, const char * const status); -void win_show_room_member_nick_change(const char * const room, - const char * const old_nick, const char * const nick); -void win_show_room_nick_change(const char * const room, const char * const nick); -void win_show_room_member_presence(const char * const room, - const char * const nick, const char * const show, const char * const status); -void win_room_show_status(const char * const contact); -void win_room_show_info(const char * const contact); -void win_show_status(void); -void win_private_show_status(void); - // console window actions ProfWin* cons_create(void); void cons_refresh(void); From e14cd43af4a0681cff9662bcf0ce33df4215b778 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 19:48:56 +0100 Subject: [PATCH 32/37] Renamed window_ functions win_ --- src/ui/console.c | 144 +++++++++++++++++++++++------------------------ src/ui/core.c | 52 ++++++++--------- src/ui/window.c | 18 +++--- src/ui/window.h | 12 ++-- 4 files changed, 113 insertions(+), 113 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 6dc31a57..52731534 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -49,7 +49,7 @@ ProfWin * cons_create(void) { int cols = getmaxx(stdscr); - console = window_create(CONS_WIN_TITLE, cols, WIN_CONSOLE); + console = win_create(CONS_WIN_TITLE, cols, WIN_CONSOLE); dirty = FALSE; return console; } @@ -68,7 +68,7 @@ cons_refresh(void) void cons_show_time(void) { - window_print_time(console, '-'); + win_print_time(console, '-'); } void @@ -90,7 +90,7 @@ cons_debug(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); @@ -112,7 +112,7 @@ cons_show(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); @@ -127,7 +127,7 @@ cons_show_error(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - window_print_time(console, '-'); + win_print_time(console, '-'); wattron(console->win, COLOUR_ERROR); wprintw(console->win, "%s\n", fmt_msg->str); wattroff(console->win, COLOUR_ERROR); @@ -143,7 +143,7 @@ cons_show_error(const char * const msg, ...) void cons_show_typing(const char * const short_from) { - window_print_time(console, '-'); + win_print_time(console, '-'); wattron(console->win, COLOUR_TYPING); wprintw(console->win, "!! %s is typing a message...\n", short_from); wattroff(console->win, COLOUR_TYPING); @@ -152,7 +152,7 @@ cons_show_typing(const char * const short_from) void cons_show_incoming_message(const char * const short_from, const int win_index) { - window_print_time(console, '-'); + win_print_time(console, '-'); wattron(console->win, COLOUR_INCOMING); wprintw(console->win, "<< incoming from %s (%d)\n", short_from, win_index + 1); wattroff(console->win, COLOUR_INCOMING); @@ -167,7 +167,7 @@ cons_about(void) if (prefs_get_boolean(PREF_SPLASH)) { _cons_splash_logo(); } else { - window_print_time(console, '-'); + win_print_time(console, '-'); if (strcmp(PACKAGE_STATUS, "development") == 0) { wprintw(console->win, "Welcome to Profanity, version %sdev\n", PACKAGE_VERSION); @@ -176,21 +176,21 @@ cons_about(void) } } - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "Copyright (C) 2012, 2013 James Booth <%s>.\n", PACKAGE_BUGREPORT); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "License GPLv3+: GNU GPL version 3 or later \n"); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "\n"); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "This is free software; you are free to change and redistribute it.\n"); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "There is NO WARRANTY, to the extent permitted by law.\n"); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "\n"); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "Type '/help' to show complete help.\n"); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "\n"); if (prefs_get_boolean(PREF_VERCHECK)) { @@ -215,12 +215,12 @@ cons_check_version(gboolean not_available_msg) if (relase_valid) { if (release_is_new(latest_release)) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "A new version of Profanity is available: %s", latest_release); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "Check for details.\n"); free(latest_release); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "\n"); } else { if (not_available_msg) { @@ -240,15 +240,15 @@ cons_check_version(gboolean not_available_msg) void cons_show_login_success(ProfAccount *account) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "%s logged in successfully, ", account->jid); resource_presence_t presence = accounts_get_login_presence(account->name); const char *presence_str = string_from_resource_presence(presence); - window_presence_colour_on(console, presence_str); + win_presence_colour_on(console, presence_str); wprintw(console->win, "%s", presence_str); - window_presence_colour_off(console, presence_str); + win_presence_colour_off(console, presence_str); wprintw(console->win, " (priority %d)", accounts_get_priority_for_presence_type(account->name, presence)); wprintw(console->win, ".\n"); @@ -262,7 +262,7 @@ cons_show_wins(void) cons_show(""); cons_show("Active windows:"); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "1: Console\n"); for (i = 1; i < NUM_WINS; i++) { @@ -275,7 +275,7 @@ cons_show_wins(void) for (i = 1; i < NUM_WINS; i++) { if (windows[i] != NULL) { ProfWin *window = windows[i]; - window_print_time(console, '-'); + win_print_time(console, '-'); switch (window->type) { @@ -342,19 +342,19 @@ cons_show_info(PContact pcontact) GDateTime *last_activity = p_contact_last_activity(pcontact); WINDOW *win = console->win; - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, "\n"); - window_print_time(console, '-'); - window_presence_colour_on(console, presence); + win_print_time(console, '-'); + win_presence_colour_on(console, presence); wprintw(win, "%s", barejid); if (name != NULL) { wprintw(win, " (%s)", name); } - window_presence_colour_off(console, presence); + win_presence_colour_off(console, presence); wprintw(win, ":\n"); if (sub != NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, "Subscription: %s\n", sub); } @@ -362,7 +362,7 @@ cons_show_info(PContact pcontact) GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, "Last activity: "); int hours = span / G_TIME_SPAN_HOUR; @@ -384,7 +384,7 @@ cons_show_info(PContact pcontact) } if (resources != NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, "Resources:\n"); // sort in order of availabiltiy @@ -399,21 +399,21 @@ cons_show_info(PContact pcontact) while (ordered_resources != NULL) { Resource *resource = ordered_resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); - window_print_time(console, '-'); - window_presence_colour_on(console, resource_presence); + win_print_time(console, '-'); + win_presence_colour_on(console, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { wprintw(win, ", \"%s\"", resource->status); } wprintw(win, "\n"); - window_presence_colour_off(console, resource_presence); + win_presence_colour_off(console, resource_presence); if (resource->caps_str != NULL) { Capabilities *caps = caps_get(resource->caps_str); if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, " Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); @@ -433,7 +433,7 @@ cons_show_info(PContact pcontact) wprintw(win, "\n"); } if (caps->software != NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, " Software: %s", caps->software); } if (caps->software_version != NULL) { @@ -443,7 +443,7 @@ cons_show_info(PContact pcontact) wprintw(win, "\n"); } if (caps->os != NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, " OS: %s", caps->os); } if (caps->os_version != NULL) { @@ -470,10 +470,10 @@ cons_show_caps(const char * const contact, Resource *resource) WINDOW *win = console->win; cons_show(""); const char *resource_presence = string_from_resource_presence(resource->presence); - window_print_time(console, '-'); - window_presence_colour_on(console, resource_presence); + win_print_time(console, '-'); + win_presence_colour_on(console, resource_presence); wprintw(console->win, "%s", contact); - window_presence_colour_off(console, resource_presence); + win_presence_colour_off(console, resource_presence); wprintw(win, ":\n"); if (resource->caps_str != NULL) { @@ -481,7 +481,7 @@ cons_show_caps(const char * const contact, Resource *resource) if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, "Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); @@ -501,7 +501,7 @@ cons_show_caps(const char * const contact, Resource *resource) wprintw(win, "\n"); } if (caps->software != NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, "Software: %s", caps->software); } if (caps->software_version != NULL) { @@ -511,7 +511,7 @@ cons_show_caps(const char * const contact, Resource *resource) wprintw(win, "\n"); } if (caps->os != NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, "OS: %s", caps->os); } if (caps->os_version != NULL) { @@ -522,11 +522,11 @@ cons_show_caps(const char * const contact, Resource *resource) } if (caps->features != NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, "Features:\n"); GSList *feature = caps->features; while (feature != NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, " %s\n", feature->data); feature = g_slist_next(feature); } @@ -546,10 +546,10 @@ cons_show_software_version(const char * const jid, const char * const presence, { if ((name != NULL) || (version != NULL) || (os != NULL)) { cons_show(""); - window_print_time(console, '-'); - window_presence_colour_on(console, presence); + win_print_time(console, '-'); + win_presence_colour_on(console, presence); wprintw(console->win, "%s", jid); - window_presence_colour_off(console, presence); + win_presence_colour_off(console, presence); wprintw(console->win, ":\n"); } if (name != NULL) { @@ -575,7 +575,7 @@ cons_show_room_list(GSList *rooms, const char * const conference_node) cons_show("Chat rooms at %s:", conference_node); while (rooms != NULL) { DiscoItem *room = rooms->data; - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, " %s", room->jid); if (room->name != NULL) { wprintw(console->win, ", (%s)", room->name); @@ -646,7 +646,7 @@ cons_show_disco_items(GSList *items, const char * const jid) cons_show("Service discovery items for %s:", jid); while (items != NULL) { DiscoItem *item = items->data; - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, " %s", item->jid); if (item->name != NULL) { wprintw(console->win, ", (%s)", item->name); @@ -670,7 +670,7 @@ cons_show_status(const char * const contact) PContact pcontact = contact_list_get_contact(contact); if (pcontact != NULL) { - window_show_contact(console, pcontact); + win_show_contact(console, pcontact); } else { cons_show("No such contact \"%s\" in roster.", contact); } @@ -723,10 +723,10 @@ cons_show_account_list(gchar **accounts) if ((jabber_get_connection_status() == JABBER_CONNECTED) && (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) { resource_presence_t presence = accounts_get_last_presence(accounts[i]); - window_print_time(console, '-'); - window_presence_colour_on(console, string_from_resource_presence(presence)); + win_print_time(console, '-'); + win_presence_colour_on(console, string_from_resource_presence(presence)); wprintw(console->win, "%s\n", accounts[i]); - window_presence_colour_off(console, string_from_resource_presence(presence)); + win_presence_colour_off(console, string_from_resource_presence(presence)); } else { cons_show(accounts[i]); } @@ -777,7 +777,7 @@ cons_show_account(ProfAccount *account) WINDOW *win = console->win; if (resources != NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, "Resources:\n"); // sort in order of availabiltiy @@ -792,21 +792,21 @@ cons_show_account(ProfAccount *account) while (ordered_resources != NULL) { Resource *resource = ordered_resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); - window_print_time(console, '-'); - window_presence_colour_on(console, resource_presence); + win_print_time(console, '-'); + win_presence_colour_on(console, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { wprintw(win, ", \"%s\"", resource->status); } wprintw(win, "\n"); - window_presence_colour_off(console, resource_presence); + win_presence_colour_off(console, resource_presence); if (resource->caps_str != NULL) { Capabilities *caps = caps_get(resource->caps_str); if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, " Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); @@ -826,7 +826,7 @@ cons_show_account(ProfAccount *account) wprintw(win, "\n"); } if (caps->software != NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, " Software: %s", caps->software); } if (caps->software_version != NULL) { @@ -836,7 +836,7 @@ cons_show_account(ProfAccount *account) wprintw(win, "\n"); } if (caps->os != NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(win, " OS: %s", caps->os); } if (caps->os_version != NULL) { @@ -1208,7 +1208,7 @@ cons_show_contacts(GSList *list) while(curr) { PContact contact = curr->data; if (strcmp(p_contact_subscription(contact), "none") != 0) { - window_show_contact(console, contact); + win_show_contact(console, contact); } curr = g_slist_next(curr); } @@ -1222,47 +1222,47 @@ cons_show_contacts(GSList *list) static void _cons_splash_logo(void) { - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "Welcome to\n"); - window_print_time(console, '-'); + win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, " ___ _ \n"); wattroff(console->win, COLOUR_SPLASH); - window_print_time(console, '-'); + win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, " / __) (_)_ \n"); wattroff(console->win, COLOUR_SPLASH); - window_print_time(console, '-'); + win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, " ____ ____ ___ | |__ ____ ____ _| |_ _ _ \n"); wattroff(console->win, COLOUR_SPLASH); - window_print_time(console, '-'); + win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |\n"); wattroff(console->win, COLOUR_SPLASH); - window_print_time(console, '-'); + win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "| | | | | | |_| | | ( ( | | | | | | |_| |_| |\n"); wattroff(console->win, COLOUR_SPLASH); - window_print_time(console, '-'); + win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |\n"); wattroff(console->win, COLOUR_SPLASH); - window_print_time(console, '-'); + win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "|_| (____/ \n"); wattroff(console->win, COLOUR_SPLASH); - window_print_time(console, '-'); + win_print_time(console, '-'); wprintw(console->win, "\n"); - window_print_time(console, '-'); + win_print_time(console, '-'); if (strcmp(PACKAGE_STATUS, "development") == 0) { wprintw(console->win, "Version %sdev\n", PACKAGE_VERSION); } else { diff --git a/src/ui/core.c b/src/ui/core.c index 3c3f1f42..6bdc3fa0 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -289,7 +289,7 @@ ui_incoming_msg(const char * const from, const char * const message, // no spare windows left if (win_index == 0) { if (tv_stamp == NULL) { - window_print_time(console, '-'); + win_print_time(console, '-'); } else { GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp); gchar *date_fmt = g_date_time_format(time, "%H:%M:%S"); @@ -326,7 +326,7 @@ ui_incoming_msg(const char * const from, const char * const message, // currently viewing chat window with sender if (win_index == current_index) { if (tv_stamp == NULL) { - window_print_time(window, '-'); + 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"); @@ -365,7 +365,7 @@ ui_incoming_msg(const char * const from, const char * const message, } if (tv_stamp == NULL) { - window_print_time(window, '-'); + 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"); @@ -459,7 +459,7 @@ ui_disconnected(void) for (i = 1; i < NUM_WINS; i++) { if (windows[i] != NULL) { ProfWin *window = windows[i]; - window_print_time(window, '-'); + win_print_time(window, '-'); wattron(window->win, COLOUR_ERROR); wprintw(window->win, "%s\n", "Lost connection."); wattroff(window->win, COLOUR_ERROR); @@ -522,7 +522,7 @@ ui_clear_current(void) void ui_close_current(void) { - window_free(current); + win_free(current); windows[current_index] = NULL; // set it as inactive in the status bar @@ -555,7 +555,7 @@ ui_current_print_line(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - window_print_time(current, '-'); + win_print_time(current, '-'); wprintw(current->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); @@ -566,7 +566,7 @@ ui_current_print_line(const char * const msg, ...) void ui_current_error_line(const char * const msg) { - window_print_time(current, '-'); + win_print_time(current, '-'); wattron(current->win, COLOUR_ERROR); wprintw(current->win, "%s\n", msg); wattroff(current->win, COLOUR_ERROR); @@ -606,7 +606,7 @@ ui_print_error_from_recipient(const char * const from, const char *err_msg) // chat window exists if (win_index < NUM_WINS) { window = windows[win_index]; - window_print_time(window, '-'); + win_print_time(window, '-'); _win_show_error_msg(window->win, err_msg); if (win_index == current_index) { dirty = TRUE; @@ -636,7 +636,7 @@ ui_print_system_msg_from_recipient(const char * const from, const char *message) } window = windows[win_index]; - window_print_time(window, '-'); + win_print_time(window, '-'); wprintw(window->win, "*%s %s\n", bare_jid, message); // this is the current window @@ -658,7 +658,7 @@ ui_recipient_gone(const char * const from) // chat window exists if (win_index < NUM_WINS) { window = windows[win_index]; - window_print_time(window, '-'); + win_print_time(window, '-'); wattron(window->win, COLOUR_GONE); wprintw(window->win, "*%s ", from); wprintw(window->win, "has left the conversation."); @@ -752,7 +752,7 @@ ui_outgoing_msg(const char * const from, const char * const to, window = windows[win_index]; } - window_print_time(window, '-'); + win_print_time(window, '-'); if (strncmp(message, "/me ", 4) == 0) { wattron(window->win, COLOUR_ME); wprintw(window->win, "*%s ", from); @@ -785,7 +785,7 @@ ui_room_roster(const char * const room, GList *roster, const char * const presen int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; - window_print_time(window, '!'); + win_print_time(window, '!'); if ((roster == NULL) || (g_list_length(roster) == 0)) { wattron(window->win, COLOUR_ROOMINFO); if (presence == NULL) { @@ -809,9 +809,9 @@ ui_room_roster(const char * const room, GList *roster, const char * const presen const char const *nick = p_contact_barejid(member); const char const *show = p_contact_presence(member); - window_presence_colour_on(window, show); + win_presence_colour_on(window, show); wprintw(window->win, "%s", nick); - window_presence_colour_off(window, show); + win_presence_colour_off(window, show); if (roster->next != NULL) { wprintw(window->win, ", "); @@ -834,7 +834,7 @@ ui_room_member_offline(const char * const room, const char * const nick) int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; - window_print_time(window, '!'); + win_print_time(window, '!'); wattron(window->win, COLOUR_OFFLINE); wprintw(window->win, "<- %s has left the room.\n", nick); wattroff(window->win, COLOUR_OFFLINE); @@ -850,7 +850,7 @@ ui_room_member_online(const char * const room, const char * const nick, int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; - window_print_time(window, '!'); + win_print_time(window, '!'); wattron(window->win, COLOUR_ONLINE); wprintw(window->win, "-> %s has joined the room.\n", nick); wattroff(window->win, COLOUR_ONLINE); @@ -880,7 +880,7 @@ ui_room_member_nick_change(const char * const room, int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; - window_print_time(window, '!'); + win_print_time(window, '!'); wattron(window->win, COLOUR_THEM); wprintw(window->win, "** %s is now known as %s\n", old_nick, nick); wattroff(window->win, COLOUR_THEM); @@ -895,7 +895,7 @@ ui_room_nick_change(const char * const room, const char * const nick) int win_index = _find_prof_win_index(room); ProfWin *window = windows[win_index]; - window_print_time(window, '!'); + win_print_time(window, '!'); wattron(window->win, COLOUR_ME); wprintw(window->win, "** You are now known as %s\n", nick); wattroff(window->win, COLOUR_ME); @@ -937,7 +937,7 @@ ui_room_message(const char * const room_jid, const char * const nick, int win_index = _find_prof_win_index(room_jid); ProfWin *window = windows[win_index]; - window_print_time(window, '-'); + win_print_time(window, '-'); if (strcmp(nick, muc_get_room_nick(room_jid)) != 0) { if (strncmp(message, "/me ", 4) == 0) { wattron(window->win, COLOUR_THEM); @@ -1001,7 +1001,7 @@ ui_room_subject(const char * const room_jid, const char * const subject) int win_index = _find_prof_win_index(room_jid); ProfWin *window = windows[win_index]; - window_print_time(window, '!'); + win_print_time(window, '!'); wattron(window->win, COLOUR_ROOMINFO); wprintw(window->win, "Room subject: "); wattroff(window->win, COLOUR_ROOMINFO); @@ -1024,7 +1024,7 @@ ui_room_broadcast(const char * const room_jid, const char * const message) int win_index = _find_prof_win_index(room_jid); ProfWin *window = windows[win_index]; - window_print_time(window, '!'); + win_print_time(window, '!'); wattron(window->win, COLOUR_ROOMINFO); wprintw(window->win, "Room message: "); wattroff(window->win, COLOUR_ROOMINFO); @@ -1048,7 +1048,7 @@ ui_status(void) PContact pcontact = contact_list_get_contact(recipient); if (pcontact != NULL) { - window_show_contact(current, pcontact); + win_show_contact(current, pcontact); } else { ui_current_print_line("Error getting contact info."); } @@ -1062,7 +1062,7 @@ ui_status_private(void) PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart); if (pcontact != NULL) { - window_show_contact(current, pcontact); + win_show_contact(current, pcontact); } else { ui_current_print_line("Error getting contact info."); } @@ -1076,7 +1076,7 @@ ui_status_room(const char * const contact) PContact pcontact = muc_get_participant(ui_current_recipient(), contact); if (pcontact != NULL) { - window_show_contact(current, pcontact); + win_show_contact(current, pcontact); } else { ui_current_print_line("No such participant \"%s\" in room.", contact); } @@ -1242,7 +1242,7 @@ _new_prof_win(const char * const contact, win_type_t type) if (i != NUM_WINS) { int cols = getmaxx(stdscr); - windows[i] = window_create(contact, cols, type); + windows[i] = win_create(contact, cols, type); return i; } else { return 0; @@ -1318,7 +1318,7 @@ _show_status_string(ProfWin *window, const char * const from, if (!prefs_get_boolean(PREF_STATUSES)) return; - window_print_time(window, '-'); + win_print_time(window, '-'); if (show != NULL) { if (strcmp(show, "away") == 0) { diff --git a/src/ui/window.c b/src/ui/window.c index 7861cc01..5ef23b84 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -38,7 +38,7 @@ #define CONS_WIN_TITLE "_cons" ProfWin* -window_create(const char * const title, int cols, win_type_t type) +win_create(const char * const title, int cols, win_type_t type) { ProfWin *new_win = malloc(sizeof(struct prof_win_t)); new_win->from = strdup(title); @@ -55,7 +55,7 @@ window_create(const char * const title, int cols, win_type_t type) } void -window_free(ProfWin* window) +win_free(ProfWin* window) { delwin(window->win); free(window->from); @@ -66,7 +66,7 @@ window_free(ProfWin* window) } void -window_print_time(ProfWin* window, char show_char) +win_print_time(ProfWin* window, char show_char) { GDateTime *time = g_date_time_new_now_local(); gchar *date_fmt = g_date_time_format(time, "%H:%M:%S"); @@ -78,7 +78,7 @@ window_print_time(ProfWin* window, char show_char) } void -window_presence_colour_on(ProfWin *window, const char * const presence) +win_presence_colour_on(ProfWin *window, const char * const presence) { if (g_strcmp0(presence, "online") == 0) { wattron(window->win, COLOUR_ONLINE); @@ -96,7 +96,7 @@ window_presence_colour_on(ProfWin *window, const char * const presence) } void -window_presence_colour_off(ProfWin *window, const char * const presence) +win_presence_colour_off(ProfWin *window, const char * const presence) { if (g_strcmp0(presence, "online") == 0) { wattroff(window->win, COLOUR_ONLINE); @@ -114,7 +114,7 @@ window_presence_colour_off(ProfWin *window, const char * const presence) } void -window_show_contact(ProfWin *window, PContact contact) +win_show_contact(ProfWin *window, PContact contact) { const char *barejid = p_contact_barejid(contact); const char *name = p_contact_name(contact); @@ -122,8 +122,8 @@ window_show_contact(ProfWin *window, PContact contact) const char *status = p_contact_status(contact); GDateTime *last_activity = p_contact_last_activity(contact); - window_print_time(window, '-'); - window_presence_colour_on(window, presence); + win_print_time(window, '-'); + win_presence_colour_on(window, presence); wprintw(window->win, "%s", barejid); if (name != NULL) { @@ -157,5 +157,5 @@ window_show_contact(ProfWin *window, PContact contact) } wprintw(window->win, "\n"); - window_presence_colour_off(window, presence); + win_presence_colour_off(window, presence); } diff --git a/src/ui/window.h b/src/ui/window.h index 647b0fe3..933d4e66 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -45,12 +45,12 @@ typedef struct prof_win_t { int history_shown; } ProfWin; -ProfWin* window_create(const char * const title, int cols, win_type_t type); -void window_free(ProfWin *window); +ProfWin* win_create(const char * const title, int cols, win_type_t type); +void win_free(ProfWin *window); -void window_print_time(ProfWin *window, char show_char); -void window_presence_colour_on(ProfWin *window, const char * const presence); -void window_presence_colour_off(ProfWin *window, const char * const presence); -void window_show_contact(ProfWin *window, PContact contact); +void win_print_time(ProfWin *window, char show_char); +void win_presence_colour_on(ProfWin *window, const char * const presence); +void win_presence_colour_off(ProfWin *window, const char * const presence); +void win_show_contact(ProfWin *window, PContact contact); #endif From f63f68630b84d9b94f1238e8c2d8e9c2e6ca73ab Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 20:17:06 +0100 Subject: [PATCH 33/37] Added notifier module --- Makefile.am | 2 +- src/profanity.c | 1 + src/ui/core.c | 137 ++++++---------------------------------------- src/ui/notifier.c | 136 +++++++++++++++++++++++++++++++++++++++++++++ src/ui/notifier.h | 28 ++++++++++ src/ui/ui.h | 2 +- 6 files changed, 183 insertions(+), 123 deletions(-) create mode 100644 src/ui/notifier.c create mode 100644 src/ui/notifier.h diff --git a/Makefile.am b/Makefile.am index edcdbb83..61aace12 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ profanity_SOURCES = src/contact.c src/contact.h src/log.c src/common.c \ src/xmpp/capabilities.h src/xmpp/connection.h \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ - src/ui/console.c \ + src/ui/console.c src/ui/notifier.c src/ui/notifier.h \ src/command/command.h src/command/command.c src/command/history.c \ src/command/history.h src/command/parser.c \ src/command/parser.h \ diff --git a/src/profanity.c b/src/profanity.c index a0c917f6..052575a9 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -42,6 +42,7 @@ #include "log.h" #include "muc.h" #include "resource.h" +#include "ui/notifier.h" #include "ui/ui.h" #include "xmpp/xmpp.h" diff --git a/src/ui/core.c b/src/ui/core.c index 6bdc3fa0..777ce98a 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -28,9 +28,6 @@ #include #endif #include -#ifdef HAVE_LIBNOTIFY -#include -#endif #ifdef PLATFORM_CYGWIN #include #endif @@ -50,6 +47,7 @@ #include "jid.h" #include "log.h" #include "muc.h" +#include "ui/notifier.h" #include "ui/ui.h" #include "ui/window.h" @@ -86,17 +84,10 @@ static void _show_status_string(ProfWin *window, const char * const from, static void _win_handle_switch(const wint_t * const ch); static void _win_handle_page(const wint_t * const ch); static void _win_resize_all(void); -static gint _win_get_unread(void); static void _win_show_history(WINDOW *win, int win_index, const char * const contact); static void _ui_draw_win_title(void); -static void _notify(const char * const message, int timeout, - const char * const category); -static void _notify_remind(gint unread); -static void _notify_message(const char * const short_from); -static void _notify_typing(const char * const from); - void ui_init(void) { @@ -119,6 +110,7 @@ ui_init(void) console = windows[0]; current = console; cons_about(); + notifier_init(); #ifdef HAVE_LIBXSS display = XOpenDisplay(0); #endif @@ -171,11 +163,7 @@ ui_reset_idle_time(void) void ui_close(void) { -#ifdef HAVE_LIBNOTIFY - if (notify_is_initted()) { - notify_uninit(); - } -#endif + notifier_uninit(); endwin(); } @@ -239,7 +227,7 @@ ui_contact_typing(const char * const from) } if (prefs_get_boolean(PREF_NOTIFY_TYPING)) - _notify_typing(from); + notify_typing(from); } void @@ -392,7 +380,7 @@ ui_incoming_msg(const char * const from, const char * const message, if (prefs_get_boolean(PREF_BEEP)) beep(); if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) - _notify_message(display_from); + notify_message(display_from); g_free(display_from); } @@ -990,7 +978,7 @@ ui_room_message(const char * const room_jid, const char * const nick, beep(); } if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { - _notify_message(nick); + notify_message(nick); } } } @@ -1082,13 +1070,17 @@ ui_status_room(const char * const contact) } } -void -notify_remind(void) +gint +ui_unread(void) { - gint unread = _win_get_unread(); - if (unread > 0) { - _notify_remind(unread); + int i; + gint result = 0; + for (i = 0; i < NUM_WINS; i++) { + if (windows[i] != NULL) { + result += windows[i]->unread; + } } + return result; } static void @@ -1110,7 +1102,7 @@ _ui_draw_win_title(void) if (status == JABBER_CONNECTED) { const char * const jid = jabber_get_jid(); - gint unread = _win_get_unread(); + gint unread = ui_unread(); if (unread != 0) { snprintf(new_win_title, sizeof(new_win_title), "%c]0;%s%s (%d) - %s%c", '\033', "Profanity", version_str->str, unread, jid, '\007'); @@ -1133,90 +1125,6 @@ _ui_draw_win_title(void) } } -static void -_notify(const char * const message, int timeout, - const char * const category) -{ -#ifdef HAVE_LIBNOTIFY - gboolean notify_initted = notify_is_initted(); - - if (!notify_initted) { - notify_initted = notify_init("Profanity"); - } - - if (notify_initted) { - NotifyNotification *notification; - notification = notify_notification_new("Profanity", message, NULL); - notify_notification_set_timeout(notification, timeout); - notify_notification_set_category(notification, category); - notify_notification_set_urgency(notification, NOTIFY_URGENCY_NORMAL); - - GError *error = NULL; - gboolean notify_success = notify_notification_show(notification, &error); - - if (!notify_success) { - log_error("Error sending desktop notification:"); - log_error(" -> Message : %s", message); - log_error(" -> Error : %s", error->message); - } - } else { - log_error("Libnotify initialisation error."); - } -#endif -#ifdef PLATFORM_CYGWIN - NOTIFYICONDATA nid; - nid.cbSize = sizeof(NOTIFYICONDATA); - //nid.hWnd = hWnd; - nid.uID = 100; - nid.uVersion = NOTIFYICON_VERSION; - //nid.uCallbackMessage = WM_MYMESSAGE; - nid.hIcon = LoadIcon(NULL, IDI_APPLICATION); - strcpy(nid.szTip, "Tray Icon"); - nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; - Shell_NotifyIcon(NIM_ADD, &nid); - - // For a Ballon Tip - nid.uFlags = NIF_INFO; - strcpy(nid.szInfoTitle, "Profanity"); // Title - strcpy(nid.szInfo, message); // Copy Tip - nid.uTimeout = timeout; // 3 Seconds - nid.dwInfoFlags = NIIF_INFO; - - Shell_NotifyIcon(NIM_MODIFY, &nid); -#endif -} - -static void -_notify_remind(gint unread) -{ - char message[20]; - if (unread == 1) { - sprintf(message, "1 unread message"); - } else { - snprintf(message, sizeof(message), "%d unread messages", unread); - } - - _notify(message, 5000, "Incoming message"); -} - -static void -_notify_message(const char * const short_from) -{ - char message[strlen(short_from) + 1 + 10]; - sprintf(message, "%s: message.", short_from); - - _notify(message, 10000, "Incoming message"); -} - -static void -_notify_typing(const char * const from) -{ - char message[strlen(from) + 1 + 11]; - sprintf(message, "%s: typing...", from); - - _notify(message, 10000, "Incoming message"); -} - static int _find_prof_win_index(const char * const contact) { @@ -1493,19 +1401,6 @@ _win_handle_page(const wint_t * const ch) } } -static gint -_win_get_unread(void) -{ - int i; - gint result = 0; - for (i = 0; i < NUM_WINS; i++) { - if (windows[i] != NULL) { - result += windows[i]->unread; - } - } - return result; -} - static void _win_show_history(WINDOW *win, int win_index, const char * const contact) { diff --git a/src/ui/notifier.c b/src/ui/notifier.c new file mode 100644 index 00000000..2cd9ad73 --- /dev/null +++ b/src/ui/notifier.c @@ -0,0 +1,136 @@ +/* + * notifier.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 "config.h" + +#include +#include + +#include +#ifdef HAVE_LIBNOTIFY +#include +#endif + +#include "log.h" +#include "ui/ui.h" + +static void _notify(const char * const message, int timeout, + const char * const category); + +void +notifier_init(void) +{ +#ifdef HAVE_LIBNOTIFY + notify_init("Profanity"); +#endif +} + +void +notifier_uninit(void) +{ +#ifdef HAVE_LIBNOTIFY + if (notify_is_initted()) { + notify_uninit(); + } +#endif +} + +void +notify_typing(const char * const from) +{ + char message[strlen(from) + 1 + 11]; + sprintf(message, "%s: typing...", from); + + _notify(message, 10000, "Incoming message"); +} + +void +notify_message(const char * const short_from) +{ + char message[strlen(short_from) + 1 + 10]; + sprintf(message, "%s: message.", short_from); + + _notify(message, 10000, "Incoming message"); +} + +void +notify_remind(void) +{ + gint unread = ui_unread(); + if (unread > 0) { + char message[20]; + if (unread == 1) { + sprintf(message, "1 unread message"); + } else { + snprintf(message, sizeof(message), "%d unread messages", unread); + } + + _notify(message, 5000, "Incoming message"); + } +} + +static void +_notify(const char * const message, int timeout, + const char * const category) +{ +#ifdef HAVE_LIBNOTIFY + + if (notify_is_initted()) { + NotifyNotification *notification; + notification = notify_notification_new("Profanity", message, NULL); + notify_notification_set_timeout(notification, timeout); + notify_notification_set_category(notification, category); + notify_notification_set_urgency(notification, NOTIFY_URGENCY_NORMAL); + + GError *error = NULL; + gboolean notify_success = notify_notification_show(notification, &error); + + if (!notify_success) { + log_error("Error sending desktop notification:"); + log_error(" -> Message : %s", message); + log_error(" -> Error : %s", error->message); + } + } else { + log_error("Libnotify initialisation error."); + } +#endif +#ifdef PLATFORM_CYGWIN + NOTIFYICONDATA nid; + nid.cbSize = sizeof(NOTIFYICONDATA); + //nid.hWnd = hWnd; + nid.uID = 100; + nid.uVersion = NOTIFYICON_VERSION; + //nid.uCallbackMessage = WM_MYMESSAGE; + nid.hIcon = LoadIcon(NULL, IDI_APPLICATION); + strcpy(nid.szTip, "Tray Icon"); + nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; + Shell_NotifyIcon(NIM_ADD, &nid); + + // For a Ballon Tip + nid.uFlags = NIF_INFO; + strcpy(nid.szInfoTitle, "Profanity"); // Title + strcpy(nid.szInfo, message); // Copy Tip + nid.uTimeout = timeout; // 3 Seconds + nid.dwInfoFlags = NIIF_INFO; + + Shell_NotifyIcon(NIM_MODIFY, &nid); +#endif +} diff --git a/src/ui/notifier.h b/src/ui/notifier.h new file mode 100644 index 00000000..a12dfa54 --- /dev/null +++ b/src/ui/notifier.h @@ -0,0 +1,28 @@ +/* + * notifier.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 . + * + */ + +void notifier_init(void); +void notifier_uninit(void); + +void notify_typing(const char * const from); +void notify_message(const char * const short_from); +void notify_remind(void); diff --git a/src/ui/ui.h b/src/ui/ui.h index 47c6fe82..ab4eaa35 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -62,6 +62,7 @@ void ui_reset_idle_time(void); void ui_new_chat_win(const char * const to); void ui_print_error_from_recipient(const char * const from, const char *err_msg); void ui_print_system_msg_from_recipient(const char * const from, const char *message); +gint ui_unread(void); // current window actions void ui_close_current(void); @@ -188,5 +189,4 @@ void inp_block(void); void inp_get_password(char *passwd); void inp_replace_input(char *input, const char * const new_input, int *size); -void notify_remind(void); #endif From be41a376c51ee5a3266ecc791893bdc1ae45019e Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 23:39:16 +0100 Subject: [PATCH 34/37] Added windows include to notifier --- src/ui/core.c | 3 --- src/ui/notifier.c | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index 777ce98a..9d0bcdce 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -28,9 +28,6 @@ #include #endif #include -#ifdef PLATFORM_CYGWIN -#include -#endif #ifdef HAVE_NCURSESW_NCURSES_H #include #elif HAVE_NCURSES_H diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 2cd9ad73..3f2b9688 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -28,6 +28,9 @@ #ifdef HAVE_LIBNOTIFY #include #endif +#ifdef PLATFORM_CYGWIN +#include +#endif #include "log.h" #include "ui/ui.h" From 9a59631cbccc454da3990fa3768b3f7081498d9e Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Apr 2013 23:57:47 +0100 Subject: [PATCH 35/37] Use werase() rather than wclear() --- src/ui/core.c | 2 +- src/ui/inputwin.c | 2 +- src/ui/statusbar.c | 8 ++++---- src/ui/titlebar.c | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index 9d0bcdce..cb21c61e 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -500,7 +500,7 @@ ui_switch_win(const int i) void ui_clear_current(void) { - wclear(current->win); + werase(current->win); dirty = TRUE; } diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 9570a563..dfac289f 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -238,7 +238,7 @@ inp_win_reset(void) static void _clear_input(void) { - wclear(inp_win); + werase(inp_win); wmove(inp_win, 0, 0); } diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index a2b09470..3f0798d3 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -98,7 +98,7 @@ status_bar_resize(void) mvwin(status_bar, rows-2, 0); wresize(status_bar, 1, cols); wbkgd(status_bar, COLOUR_STATUS_TEXT); - wclear(status_bar); + werase(status_bar); wattron(status_bar, COLOUR_STATUS_BRACKET); mvwprintw(status_bar, 0, cols - 31, _active); wattroff(status_bar, COLOUR_STATUS_BRACKET); @@ -189,7 +189,7 @@ status_bar_print_message(const char * const msg) message = NULL; } - wclear(status_bar); + werase(status_bar); message = (char *) malloc((strlen(msg) + 1) * sizeof(char)); strcpy(message, msg); @@ -228,7 +228,7 @@ status_bar_clear(void) is_new[i] = FALSE; } - wclear(status_bar); + werase(status_bar); int cols = getmaxx(stdscr); @@ -247,7 +247,7 @@ status_bar_clear_message(void) message = NULL; } - wclear(status_bar); + werase(status_bar); int cols = getmaxx(stdscr); diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 5c8cee83..c786c774 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -52,7 +52,7 @@ create_title_bar(void) void title_bar_title(void) { - wclear(title_bar); + werase(title_bar); recipient = NULL; typing_elapsed = NULL; title_bar_show("Profanity. Type /help for help information."); @@ -67,7 +67,7 @@ title_bar_resize(void) wresize(title_bar, 1, cols); wbkgd(title_bar, COLOUR_TITLE_TEXT); - wclear(title_bar); + werase(title_bar); _title_bar_draw_title(); _title_bar_draw_status(); dirty = TRUE; @@ -173,7 +173,7 @@ title_bar_set_typing(gboolean is_typing) void title_bar_draw(void) { - wclear(title_bar); + werase(title_bar); _title_bar_draw_status(); _title_bar_draw_title(); } From 9373f41fa4a7ba97429f8daa78067601a17051bc Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 22 Apr 2013 21:11:08 +0100 Subject: [PATCH 36/37] Refactor marking windows as dirty and status bar new indicator --- src/ui/console.c | 209 ++++++++++++++++++----------------------------- src/ui/core.c | 85 ++++++++++--------- src/ui/ui.h | 2 +- 3 files changed, 128 insertions(+), 168 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 52731534..e2d561cd 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -40,46 +40,31 @@ #define CONS_WIN_TITLE "_cons" static ProfWin* console; -static int dirty; static void _cons_splash_logo(void); static void _cons_show_basic_help(void); +static void _cons_alert(void); ProfWin * cons_create(void) { int cols = getmaxx(stdscr); console = win_create(CONS_WIN_TITLE, cols, WIN_CONSOLE); - dirty = FALSE; return console; } -void -cons_refresh(void) -{ - int rows, cols; - if (dirty == TRUE) { - getmaxyx(stdscr, rows, cols); - prefresh(console->win, console->y_pos, 0, 1, 0, rows-3, cols-1); - dirty = FALSE; - } -} - void cons_show_time(void) { win_print_time(console, '-'); + ui_console_dirty(); } void cons_show_word(const char * const word) { wprintw(console->win, "%s", word); - - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); } void @@ -95,10 +80,8 @@ cons_debug(const char * const msg, ...) g_string_free(fmt_msg, TRUE); va_end(arg); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); ui_current_page_off(); ui_refresh(); @@ -116,8 +99,7 @@ cons_show(const char * const msg, ...) wprintw(console->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); - - dirty = TRUE; + ui_console_dirty(); } void @@ -134,10 +116,8 @@ cons_show_error(const char * const msg, ...) g_string_free(fmt_msg, TRUE); va_end(arg); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -147,6 +127,9 @@ cons_show_typing(const char * const short_from) wattron(console->win, COLOUR_TYPING); wprintw(console->win, "!! %s is typing a message...\n", short_from); wattroff(console->win, COLOUR_TYPING); + + ui_console_dirty(); + _cons_alert(); } void @@ -156,6 +139,9 @@ cons_show_incoming_message(const char * const short_from, const int win_index) wattron(console->win, COLOUR_INCOMING); wprintw(console->win, "<< incoming from %s (%d)\n", short_from, win_index + 1); wattroff(console->win, COLOUR_INCOMING); + + ui_console_dirty(); + _cons_alert(); } void @@ -199,10 +185,8 @@ cons_about(void) prefresh(console->win, 0, 0, 1, 0, rows-3, cols-1); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -229,10 +213,8 @@ cons_check_version(gboolean not_available_msg) } } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } } } @@ -252,6 +234,8 @@ cons_show_login_success(ProfAccount *account) wprintw(console->win, " (priority %d)", accounts_get_priority_for_presence_type(account->name, presence)); wprintw(console->win, ".\n"); + ui_console_dirty(); + _cons_alert(); } void @@ -324,10 +308,8 @@ cons_show_wins(void) } cons_show(""); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -458,10 +440,8 @@ cons_show_info(PContact pcontact) ordered_resources = g_list_next(ordered_resources); } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -534,10 +514,8 @@ cons_show_caps(const char * const contact, Resource *resource) } } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -562,10 +540,8 @@ cons_show_software_version(const char * const jid, const char * const presence, cons_show("OS : %s", os); } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -587,10 +563,8 @@ cons_show_room_list(GSList *rooms, const char * const conference_node) cons_show("No chat rooms at %s", conference_node); } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -631,10 +605,8 @@ cons_show_disco_info(const char *jid, GSList *identities, GSList *features) features = g_slist_next(features); } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } } @@ -658,10 +630,8 @@ cons_show_disco_items(GSList *items, const char * const jid) cons_show(""); cons_show("No service discovery items for %s", jid); } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -674,6 +644,8 @@ cons_show_status(const char * const contact) } else { cons_show("No such contact \"%s\" in roster.", contact); } + ui_console_dirty(); + _cons_alert(); } void @@ -706,10 +678,8 @@ cons_show_room_invite(const char * const invitor, const char * const room, jid_destroy(room_jid); g_string_free(default_service, TRUE); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -737,10 +707,8 @@ cons_show_account_list(gchar **accounts) cons_show(""); } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -852,10 +820,8 @@ cons_show_account(ProfAccount *account) } } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -911,10 +877,8 @@ cons_show_ui_prefs(void) else cons_show("Status (/statuses) : OFF"); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -941,6 +905,9 @@ cons_show_desktop_prefs(void) } else { cons_show("Reminder period (/notify remind) : %d seconds", remind_period); } + + ui_console_dirty(); + _cons_alert(); } void @@ -968,10 +935,8 @@ cons_show_chat_prefs(void) cons_show("Leave conversation (/gone) : %d minutes", gone_time); } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -987,10 +952,8 @@ cons_show_log_prefs(void) else cons_show("Chat logging (/chlog) : OFF"); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -1020,10 +983,8 @@ cons_show_presence_prefs(void) cons_show("Autoaway check (/autoaway check) : OFF"); } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -1050,10 +1011,8 @@ cons_show_connection_prefs(void) cons_show("Autoping interval (/autoping) : %d seconds", autoping_interval); } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -1071,10 +1030,8 @@ cons_show_themes(GSList *themes) } } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -1094,10 +1051,8 @@ cons_prefs(void) cons_show_connection_prefs(); cons_show(""); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -1114,10 +1069,8 @@ cons_help(void) cons_show("/help [command] - Detailed help on a specific command."); cons_show(""); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -1127,10 +1080,8 @@ cons_basic_help(void) cons_show("Basic Commands:"); _cons_show_basic_help(); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -1149,10 +1100,8 @@ cons_settings_help(void) cons_show(""); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -1171,10 +1120,8 @@ cons_presence_help(void) cons_show(""); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -1194,10 +1141,8 @@ cons_navigation_help(void) cons_show("PAGE UP, PAGE DOWN : Page the main window."); cons_show(""); - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } void @@ -1213,10 +1158,8 @@ cons_show_contacts(GSList *list) curr = g_slist_next(curr); } - dirty = TRUE; - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(0); - } + ui_console_dirty(); + _cons_alert(); } static void @@ -1283,5 +1226,15 @@ _cons_show_basic_help(void) } cons_show(""); + ui_console_dirty(); + _cons_alert(); +} + +static void +_cons_alert(void) +{ + if (ui_current_win_type() != WIN_CONSOLE) { + status_bar_new(0); + } } diff --git a/src/ui/core.c b/src/ui/core.c index cb21c61e..b936b59b 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -54,7 +54,7 @@ static ProfWin *current; static ProfWin *console; // current window state -static int dirty; +static gboolean current_win_dirty; // max columns for main windows, never resize below static int max_cols = 0; @@ -112,7 +112,7 @@ ui_init(void) display = XOpenDisplay(0); #endif ui_idle_time = g_timer_new(); - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -122,16 +122,23 @@ ui_refresh(void) title_bar_refresh(); status_bar_refresh(); - cons_refresh(); - if (dirty) { + if (current_win_dirty) { _current_window_refresh(); - dirty = FALSE; + current_win_dirty = FALSE; } inp_put_back(); } +void +ui_console_dirty(void) +{ + if (ui_current_win_type() == WIN_CONSOLE) { + current_win_dirty = TRUE; + } +} + unsigned long ui_get_idle_time(void) { @@ -172,7 +179,7 @@ ui_resize(const int ch, const char * const input, const int size) status_bar_resize(); _win_resize_all(); inp_win_resize(input, size); - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -211,7 +218,7 @@ ui_contact_typing(const char * const from) // have chat window but not currently in it } else if (win_index != current_index) { cons_show_typing(from); - dirty = TRUE; + current_win_dirty = TRUE; // in chat window with user } else { @@ -219,7 +226,7 @@ ui_contact_typing(const char * const from) title_bar_draw(); status_bar_active(win_index); - dirty = TRUE; + current_win_dirty = TRUE; } } @@ -299,7 +306,7 @@ ui_incoming_msg(const char * const from, const char * const message, cons_show("Windows all used, close a window to respond."); if (current_index == 0) { - dirty = TRUE; + current_win_dirty = TRUE; } else { status_bar_new(0); } @@ -335,7 +342,7 @@ ui_incoming_msg(const char * const from, const char * const message, title_bar_set_typing(FALSE); title_bar_draw(); status_bar_active(win_index); - dirty = TRUE; + current_win_dirty = TRUE; // not currently viewing chat window with sender } else { @@ -408,7 +415,7 @@ ui_contact_online(const char * const barejid, const char * const resource, jid_destroy(jid); if (win_index == current_index) - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -433,7 +440,7 @@ ui_contact_offline(const char * const from, const char * const show, } if (win_index == current_index) - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -449,9 +456,9 @@ ui_disconnected(void) wprintw(window->win, "%s\n", "Lost connection."); wattroff(window->win, COLOUR_ERROR); - // if current win, set dirty + // if current win, set current_win_dirty if (i == current_index) { - dirty = TRUE; + current_win_dirty = TRUE; } } } @@ -494,14 +501,14 @@ ui_switch_win(const int i) } } - dirty = TRUE; + current_win_dirty = TRUE; } void ui_clear_current(void) { werase(current->win); - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -518,7 +525,7 @@ ui_close_current(void) status_bar_active(0); title_bar_title(); - dirty = TRUE; + current_win_dirty = TRUE; } win_type_t @@ -545,7 +552,7 @@ ui_current_print_line(const char * const msg, ...) g_string_free(fmt_msg, TRUE); va_end(arg); - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -556,7 +563,7 @@ ui_current_error_line(const char * const msg) wprintw(current->win, "%s\n", msg); wattroff(current->win, COLOUR_ERROR); - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -575,7 +582,7 @@ ui_current_page_off(void) if (window->y_pos < 0) window->y_pos = 0; - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -594,7 +601,7 @@ ui_print_error_from_recipient(const char * const from, const char *err_msg) win_print_time(window, '-'); _win_show_error_msg(window->win, err_msg); if (win_index == current_index) { - dirty = TRUE; + current_win_dirty = TRUE; } } } @@ -617,7 +624,7 @@ ui_print_system_msg_from_recipient(const char * const from, const char *message) if (win_index == NUM_WINS) { win_index = _new_prof_win(bare_jid, WIN_CHAT); status_bar_active(win_index); - dirty = TRUE; + current_win_dirty = TRUE; } window = windows[win_index]; @@ -626,7 +633,7 @@ ui_print_system_msg_from_recipient(const char * const from, const char *message) // this is the current window if (win_index == current_index) { - dirty = TRUE; + current_win_dirty = TRUE; } } @@ -650,7 +657,7 @@ ui_recipient_gone(const char * const from) wprintw(window->win, "\n"); wattroff(window->win, COLOUR_GONE); if (win_index == current_index) { - dirty = TRUE; + current_win_dirty = TRUE; } } } @@ -810,7 +817,7 @@ ui_room_roster(const char * const room, GList *roster, const char * const presen } if (win_index == current_index) - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -825,7 +832,7 @@ ui_room_member_offline(const char * const room, const char * const nick) wattroff(window->win, COLOUR_OFFLINE); if (win_index == current_index) - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -841,7 +848,7 @@ ui_room_member_online(const char * const room, const char * const nick, wattroff(window->win, COLOUR_ONLINE); if (win_index == current_index) - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -855,7 +862,7 @@ ui_room_member_presence(const char * const room, const char * const nick, } if (win_index == current_index) - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -871,7 +878,7 @@ ui_room_member_nick_change(const char * const room, wattroff(window->win, COLOUR_THEM); if (win_index == current_index) - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -886,7 +893,7 @@ ui_room_nick_change(const char * const room, const char * const nick) wattroff(window->win, COLOUR_ME); if (win_index == current_index) - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -912,7 +919,7 @@ ui_room_history(const char * const room_jid, const char * const nick, } if (win_index == current_index) - dirty = TRUE; + current_win_dirty = TRUE; } void @@ -951,14 +958,14 @@ ui_room_message(const char * const room_jid, const char * const nick, // currently in groupchat window if (win_index == current_index) { status_bar_active(win_index); - dirty = TRUE; + current_win_dirty = TRUE; // not currenlty on groupchat window } else { status_bar_new(win_index); cons_show_incoming_message(nick, win_index); if (current_index == 0) { - dirty = TRUE; + current_win_dirty = TRUE; } if (strcmp(nick, muc_get_room_nick(room_jid)) != 0) { @@ -995,7 +1002,7 @@ ui_room_subject(const char * const room_jid, const char * const subject) // currently in groupchat window if (win_index == current_index) { status_bar_active(win_index); - dirty = TRUE; + current_win_dirty = TRUE; // not currenlty on groupchat window } else { @@ -1018,7 +1025,7 @@ ui_room_broadcast(const char * const room_jid, const char * const message) // currently in groupchat window if (win_index == current_index) { status_bar_active(win_index); - dirty = TRUE; + current_win_dirty = TRUE; // not currenlty on groupchat window } else { @@ -1355,7 +1362,7 @@ _win_handle_page(const wint_t * const ch) *page_start = y - page_space; current->paged = 1; - dirty = TRUE; + current_win_dirty = TRUE; } else if (mouse_event.bstate & BUTTON4_PRESSED) { // mouse wheel up *page_start -= 4; @@ -1364,7 +1371,7 @@ _win_handle_page(const wint_t * const ch) *page_start = 0; current->paged = 1; - dirty = TRUE; + current_win_dirty = TRUE; } } } @@ -1379,7 +1386,7 @@ _win_handle_page(const wint_t * const ch) *page_start = 0; current->paged = 1; - dirty = TRUE; + current_win_dirty = TRUE; // page down } else if (*ch == KEY_NPAGE) { @@ -1394,7 +1401,7 @@ _win_handle_page(const wint_t * const ch) *page_start = y - page_space; current->paged = 1; - dirty = TRUE; + current_win_dirty = TRUE; } } diff --git a/src/ui/ui.h b/src/ui/ui.h index ab4eaa35..4dbde5ee 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -63,6 +63,7 @@ void ui_new_chat_win(const char * const to); void ui_print_error_from_recipient(const char * const from, const char *err_msg); void ui_print_system_msg_from_recipient(const char * const from, const char *message); gint ui_unread(void); +void ui_console_dirty(void); // current window actions void ui_close_current(void); @@ -126,7 +127,6 @@ void title_bar_draw(void); // console window actions ProfWin* cons_create(void); -void cons_refresh(void); void cons_show(const char * const msg, ...); void cons_about(void); void cons_help(void); From f099bf9a7c25006c9cea89599b83a16461815ff4 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 22 Apr 2013 23:48:23 +0100 Subject: [PATCH 37/37] Added desktop notifications for chat room invites Use "/notify invite on|off" --- src/command/command.c | 18 +++++++++++++++++- src/config/preferences.c | 3 +++ src/config/preferences.h | 1 + src/ui/console.c | 10 ++++++++++ src/ui/notifier.c | 13 +++++++++++++ src/ui/notifier.h | 1 + 6 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/command/command.c b/src/command/command.c index adb831f4..6cbfdac9 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -499,11 +499,14 @@ static struct cmd_t setting_commands[] = " : use 0 to disable.", "typing : Notifications when contacts are typing.", " : on|off", + "invite : Notifications for chat room invites.", + " : on|off", "", "Example : /notify message on (enable message notifications)", "Example : /notify remind 10 (remind every 10 seconds)", "Example : /notify remind 0 (switch off reminders)", "Example : /notify typing on (enable typing notifications)", + "Example : /notify invite on (enable chat room invite notifications)", NULL } } }, { "/flash", @@ -783,6 +786,7 @@ cmd_init(void) autocomplete_add(notify_ac, strdup("message")); autocomplete_add(notify_ac, strdup("typing")); autocomplete_add(notify_ac, strdup("remind")); + autocomplete_add(notify_ac, strdup("invite")); autocomplete_add(notify_ac, strdup("status")); sub_ac = autocomplete_new(); @@ -2487,7 +2491,7 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help) // bad kind if ((strcmp(kind, "message") != 0) && (strcmp(kind, "typing") != 0) && - (strcmp(kind, "remind") != 0)) { + (strcmp(kind, "remind") != 0) && (strcmp(kind, "invite") != 0)) { cons_show("Usage: %s", help.usage); // set message setting @@ -2514,6 +2518,18 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help) cons_show("Usage: /notify typing on|off"); } + // set invite setting + } else if (strcmp(kind, "invite") == 0) { + if (strcmp(value, "on") == 0) { + cons_show("Chat room invite notifications enabled."); + prefs_set_boolean(PREF_NOTIFY_INVITE, TRUE); + } else if (strcmp(value, "off") == 0) { + cons_show("Chat room invite notifications disabled."); + prefs_set_boolean(PREF_NOTIFY_INVITE, FALSE); + } else { + cons_show("Usage: /notify invite on|off"); + } + // set remind setting } else if (strcmp(kind, "remind") == 0) { gint period = atoi(value); diff --git a/src/config/preferences.c b/src/config/preferences.c index 1abab5f6..d6d37234 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -299,6 +299,7 @@ _get_group(preference_t pref) return "chatstates"; case PREF_NOTIFY_TYPING: case PREF_NOTIFY_MESSAGE: + case PREF_NOTIFY_INVITE: return "notifications"; case PREF_CHLOG: return "logging"; @@ -344,6 +345,8 @@ _get_key(preference_t pref) return "typing"; case PREF_NOTIFY_MESSAGE: return "message"; + case PREF_NOTIFY_INVITE: + return "invite"; case PREF_CHLOG: return "chlog"; case PREF_AUTOAWAY_CHECK: diff --git a/src/config/preferences.h b/src/config/preferences.h index 70254e25..bdfe7a95 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -50,6 +50,7 @@ typedef enum { PREF_OUTTYPE, PREF_NOTIFY_TYPING, PREF_NOTIFY_MESSAGE, + PREF_NOTIFY_INVITE, PREF_CHLOG, PREF_AUTOAWAY_CHECK, PREF_AUTOAWAY_MODE, diff --git a/src/ui/console.c b/src/ui/console.c index e2d561cd..36358635 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -34,6 +34,7 @@ #include "config/preferences.h" #include "contact_list.h" #include "config/theme.h" +#include "ui/notifier.h" #include "ui/window.h" #include "ui/ui.h" @@ -675,6 +676,10 @@ cons_show_room_invite(const char * const invitor, const char * const room, cons_show("Type \"/join %s\" to accept the invitation", display_room); + if (prefs_get_boolean(PREF_NOTIFY_INVITE)) { + notify_invite(invitor, room); + } + jid_destroy(room_jid); g_string_free(default_service, TRUE); @@ -897,6 +902,11 @@ cons_show_desktop_prefs(void) else cons_show("Composing (/notify typing) : OFF"); + if (prefs_get_boolean(PREF_NOTIFY_INVITE)) + cons_show("Room invites (/notify invite) : ON"); + else + cons_show("Room invites (/notify invite) : OFF"); + gint remind_period = prefs_get_notify_remind(); if (remind_period == 0) { cons_show("Reminder period (/notify remind) : OFF"); diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 3f2b9688..5bf4defb 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -65,6 +65,19 @@ notify_typing(const char * const from) _notify(message, 10000, "Incoming message"); } +void +notify_invite(const char * const from, const char * const room) +{ + GString *message = g_string_new("Room invite\nfrom: "); + g_string_append(message, from); + g_string_append(message, "\nto: "); + g_string_append(message, room); + + _notify(message->str, 10000, "Incoming message"); + + g_string_free(message, FALSE); +} + void notify_message(const char * const short_from) { diff --git a/src/ui/notifier.h b/src/ui/notifier.h index a12dfa54..60b2e337 100644 --- a/src/ui/notifier.h +++ b/src/ui/notifier.h @@ -26,3 +26,4 @@ void notifier_uninit(void); void notify_typing(const char * const from); void notify_message(const char * const short_from); void notify_remind(void); +void notify_invite(const char * const from, const char * const room);