diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/console.c | 2 | ||||
-rw-r--r-- | src/ui/core.c | 14 | ||||
-rw-r--r-- | src/ui/inputwin.c | 6 | ||||
-rw-r--r-- | src/ui/notifier.c | 2 | ||||
-rw-r--r-- | src/ui/occupantswin.c | 4 | ||||
-rw-r--r-- | src/ui/rosterwin.c | 4 | ||||
-rw-r--r-- | src/ui/statusbar.h | 6 | ||||
-rw-r--r-- | src/ui/titlebar.c | 2 | ||||
-rw-r--r-- | src/ui/ui.h | 137 | ||||
-rw-r--r-- | src/ui/window.c | 71 | ||||
-rw-r--r-- | src/ui/window.h | 133 | ||||
-rw-r--r-- | src/ui/windows.c | 873 | ||||
-rw-r--r-- | src/ui/windows.h | 86 |
13 files changed, 232 insertions, 1108 deletions
diff --git a/src/ui/console.c b/src/ui/console.c index cb52619e..118656dd 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -50,7 +50,7 @@ #include "config/preferences.h" #include "config/theme.h" #include "ui/window.h" -#include "ui/windows.h" +#include "window_list.h" #include "ui/ui.h" #include "ui/statusbar.h" #include "xmpp/xmpp.h" diff --git a/src/ui/core.c b/src/ui/core.c index 3b29c094..127405f6 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -72,7 +72,7 @@ #include "ui/statusbar.h" #include "ui/inputwin.h" #include "ui/window.h" -#include "ui/windows.h" +#include "window_list.h" #include "xmpp/xmpp.h" #include "event/ui_events.h" @@ -1083,12 +1083,6 @@ ui_untrust(const char * const barejid) } void -ui_clear_current(void) -{ - wins_clear_current(); -} - -void ui_close_win(int index) { ProfWin *window = wins_get_by_num(index); @@ -2223,6 +2217,12 @@ ui_clear_win_title(void) } void +ui_clear_win(ProfWin *window) +{ + win_clear(window); +} + +void ui_goodbye_title(void) { int result = system("/bin/echo -ne \"\033]0;Thanks for using Profanity\007\""); diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index caea8ea9..57814414 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -62,7 +62,8 @@ #include "ui/ui.h" #include "ui/statusbar.h" #include "ui/inputwin.h" -#include "ui/windows.h" +#include "ui/window.h" +#include "window_list.h" #include "event/ui_events.h" #include "xmpp/xmpp.h" @@ -422,7 +423,8 @@ _inp_rl_getc(FILE *stream) static int _inp_rl_clear_handler(int count, int key) { - ui_clear_current(); + ProfWin *win = wins_get_current(); + win_clear(win); return 0; } diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 76290daf..12367190 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -48,7 +48,7 @@ #include "log.h" #include "muc.h" #include "ui/ui.h" -#include "ui/windows.h" +#include "window_list.h" #include "config/preferences.h" static void _notify(const char * const message, int timeout, const char * const category); diff --git a/src/ui/occupantswin.c b/src/ui/occupantswin.c index bba9d0b9..fe4a600c 100644 --- a/src/ui/occupantswin.c +++ b/src/ui/occupantswin.c @@ -36,7 +36,7 @@ #include "ui/ui.h" #include "ui/window.h" -#include "ui/windows.h" +#include "window_list.h" #include "config/preferences.h" static void @@ -124,4 +124,4 @@ occupantswin_occupants(const char * const roomjid) g_list_free(occupants); } -} \ No newline at end of file +} diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 763490c3..00bc28a4 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -38,7 +38,7 @@ #include "contact.h" #include "ui/ui.h" #include "ui/window.h" -#include "ui/windows.h" +#include "window_list.h" #include "config/preferences.h" #include "roster_list.h" @@ -192,4 +192,4 @@ rosterwin_roster(void) } free(by); } -} \ No newline at end of file +} diff --git a/src/ui/statusbar.h b/src/ui/statusbar.h index 7d2c5ea0..c37f43f3 100644 --- a/src/ui/statusbar.h +++ b/src/ui/statusbar.h @@ -42,10 +42,6 @@ void status_bar_clear(void); void status_bar_clear_message(void); void status_bar_get_password(void); void status_bar_print_message(const char * const msg); -void status_bar_inactive(const int win); -void status_bar_active(const int win); -void status_bar_new(const int win); -void status_bar_set_all_inactive(void); void status_bar_current(int i); -#endif \ No newline at end of file +#endif diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 55710c7a..746d2782 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -44,7 +44,7 @@ #include "ui/ui.h" #include "ui/titlebar.h" #include "ui/inputwin.h" -#include "ui/windows.h" +#include "window_list.h" #include "ui/window.h" #include "roster_list.h" #include "chat_session.h" diff --git a/src/ui/ui.h b/src/ui/ui.h index 29ee6bef..434fab24 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -38,7 +38,6 @@ #include "config.h" #include <wchar.h> - #include <glib.h> #ifdef HAVE_NCURSESW_NCURSES_H #include <ncursesw/ncurses.h> @@ -48,8 +47,109 @@ #include "contact.h" #include "jid.h" -#include "ui/window.h" #include "xmpp/xmpp.h" +#include "ui/buffer.h" +#include "chat_state.h" +#include "muc.h" + +#define LAYOUT_SPLIT_MEMCHECK 12345671 +#define PROFCHATWIN_MEMCHECK 22374522 +#define PROFMUCWIN_MEMCHECK 52345276 +#define PROFPRIVATEWIN_MEMCHECK 77437483 +#define PROFCONFWIN_MEMCHECK 64334685 +#define PROFXMLWIN_MEMCHECK 87333463 + +#define NO_ME 1 +#define NO_DATE 2 +#define NO_EOL 4 +#define NO_COLOUR_FROM 8 +#define NO_COLOUR_DATE 16 + +typedef enum { + LAYOUT_SIMPLE, + LAYOUT_SPLIT +} layout_type_t; + +typedef struct prof_layout_t { + layout_type_t type; + WINDOW *win; + ProfBuff buffer; + int y_pos; + int paged; +} ProfLayout; + +typedef struct prof_layout_simple_t { + ProfLayout base; +} ProfLayoutSimple; + +typedef struct prof_layout_split_t { + ProfLayout base; + WINDOW *subwin; + int sub_y_pos; + unsigned long memcheck; +} ProfLayoutSplit; + +typedef enum { + WIN_CONSOLE, + WIN_CHAT, + WIN_MUC, + WIN_MUC_CONFIG, + WIN_PRIVATE, + WIN_XML +} win_type_t; + +typedef enum { + PROF_ENC_NONE, + PROF_ENC_OTR +} prof_enc_t; + +typedef struct prof_win_t { + win_type_t type; + ProfLayout *layout; +} ProfWin; + +typedef struct prof_console_win_t { + ProfWin window; +} ProfConsoleWin; + +typedef struct prof_chat_win_t { + ProfWin window; + char *barejid; + int unread; + ChatState *state; + prof_enc_t enc_mode; + gboolean otr_is_trusted; + char *resource_override; + gboolean history_shown; + unsigned long memcheck; +} ProfChatWin; + +typedef struct prof_muc_win_t { + ProfWin window; + char *roomjid; + int unread; + gboolean showjid; + unsigned long memcheck; +} ProfMucWin; + +typedef struct prof_mucconf_win_t { + ProfWin window; + char *roomjid; + DataForm *form; + unsigned long memcheck; +} ProfMucConfWin; + +typedef struct prof_private_win_t { + ProfWin window; + char *fulljid; + int unread; + unsigned long memcheck; +} ProfPrivateWin; + +typedef struct prof_xml_win_t { + ProfWin window; + unsigned long memcheck; +} ProfXMLWin; // ui startup and control void ui_init(void); @@ -93,7 +193,6 @@ int ui_close_all_wins(void); int ui_close_read_wins(void); // current window actions -void ui_clear_current(void); win_type_t ui_current_win_type(void); gboolean ui_current_win_is_otr(void); @@ -224,6 +323,7 @@ void ui_page_up(void); void ui_page_down(void); void ui_subwin_page_up(void); void ui_subwin_page_down(void); +void ui_clear_win(ProfWin *window); void ui_auto_away(void); void ui_end_auto_away(void); @@ -332,12 +432,43 @@ void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *l void cons_show_contact_offline(PContact contact, char *resource, char *status); void cons_theme_colours(void); +// status bar +void status_bar_inactive(const int win); +void status_bar_active(const int win); +void status_bar_new(const int win); +void status_bar_set_all_inactive(void); + // roster window void rosterwin_roster(void); // occupants window void occupantswin_occupants(const char * const room); +// window interface +ProfWin* win_create_console(void); +ProfWin* win_create_xmlconsole(void); +ProfWin* win_create_chat(const char * const barejid); +ProfWin* win_create_muc(const char * const roomjid); +ProfWin* win_create_muc_config(const char * const title, DataForm *form); +ProfWin* win_create_private(const char * const fulljid); + +void win_update_virtual(ProfWin *window); +void win_free(ProfWin *window); +int win_unread(ProfWin *window); +void win_resize(ProfWin *window); +void win_hide_subwin(ProfWin *window); +void win_show_subwin(ProfWin *window); +void win_refresh_without_subwin(ProfWin *window); +void win_refresh_with_subwin(ProfWin *window); +void win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message); +void win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...); +char* win_get_title(ProfWin *window); +void win_show_occupant(ProfWin *window, Occupant *occupant); +void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant); +void win_show_contact(ProfWin *window, PContact contact); +void win_show_info(ProfWin *window, PContact contact); +void win_println(ProfWin *window, const char * const message); + // desktop notifier actions void notifier_initialise(void); void notifier_uninit(void); diff --git a/src/ui/window.c b/src/ui/window.c index 95b5e996..92db25fa 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -459,6 +459,46 @@ win_sub_page_up(ProfWin *window) } void +win_clear(ProfWin *window) +{ + werase(window->layout->win); + win_update_virtual(window); +} + +void +win_resize(ProfWin *window) +{ + int subwin_cols = 0; + int cols = getmaxx(stdscr); + + if (window->layout->type == LAYOUT_SPLIT) { + ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout; + if (layout->subwin) { + if (window->type == WIN_CONSOLE) { + subwin_cols = win_roster_cols(); + } else if (window->type == WIN_MUC) { + subwin_cols = win_occpuants_cols(); + } + wresize(layout->base.win, PAD_SIZE, cols - subwin_cols); + wresize(layout->subwin, PAD_SIZE, subwin_cols); + if (window->type == WIN_CONSOLE) { + rosterwin_roster(); + } else if (window->type == WIN_MUC) { + ProfMucWin *mucwin = (ProfMucWin *)window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + occupantswin_occupants(mucwin->roomjid); + } + } else { + wresize(layout->base.win, PAD_SIZE, cols); + } + } else { + wresize(window->layout->win, PAD_SIZE, cols); + } + + win_redraw(window); +} + +void win_mouse(ProfWin *window, const wint_t ch, const int result) { int rows = getmaxy(stdscr); @@ -531,6 +571,37 @@ win_update_virtual(ProfWin *window) } void +win_refresh_without_subwin(ProfWin *window) +{ + int rows, cols; + getmaxyx(stdscr, rows, cols); + + if ((window->type == WIN_MUC) || (window->type == WIN_CONSOLE)) { + pnoutrefresh(window->layout->win, window->layout->y_pos, 0, 1, 0, rows-3, cols-1); + } +} + +void +win_refresh_with_subwin(ProfWin *window) +{ + int rows, cols; + getmaxyx(stdscr, rows, cols); + int subwin_cols = 0; + + if (window->type == WIN_MUC) { + ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout; + subwin_cols = win_occpuants_cols(); + pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 1, 0, rows-3, (cols-subwin_cols)-1); + pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, 1, (cols-subwin_cols), rows-3, cols-1); + } else if (window->type == WIN_CONSOLE) { + ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout; + subwin_cols = win_roster_cols(); + pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 1, 0, rows-3, (cols-subwin_cols)-1); + pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, 1, (cols-subwin_cols), rows-3, cols-1); + } +} + +void win_move_to_end(ProfWin *window) { window->layout->paged = 0; diff --git a/src/ui/window.h b/src/ui/window.h index 06fbf7b5..4b11ade0 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -39,159 +39,42 @@ #include <wchar.h> -#ifdef HAVE_NCURSESW_NCURSES_H -#include <ncursesw/ncurses.h> -#elif HAVE_NCURSES_H -#include <ncurses.h> -#endif - #include "contact.h" #include "muc.h" +#include "ui/ui.h" #include "ui/buffer.h" #include "xmpp/xmpp.h" #include "chat_state.h" -#define NO_ME 1 -#define NO_DATE 2 -#define NO_EOL 4 -#define NO_COLOUR_FROM 8 -#define NO_COLOUR_DATE 16 +#ifdef HAVE_NCURSESW_NCURSES_H +#include <ncursesw/ncurses.h> +#elif HAVE_NCURSES_H +#include <ncurses.h> +#endif #define PAD_SIZE 1000 -#define LAYOUT_SPLIT_MEMCHECK 12345671 -#define PROFCHATWIN_MEMCHECK 22374522 -#define PROFMUCWIN_MEMCHECK 52345276 -#define PROFPRIVATEWIN_MEMCHECK 77437483 -#define PROFCONFWIN_MEMCHECK 64334685 -#define PROFXMLWIN_MEMCHECK 87333463 - -typedef enum { - LAYOUT_SIMPLE, - LAYOUT_SPLIT -} layout_type_t; - -typedef struct prof_layout_t { - layout_type_t type; - WINDOW *win; - ProfBuff buffer; - int y_pos; - int paged; -} ProfLayout; - -typedef struct prof_layout_simple_t { - ProfLayout base; -} ProfLayoutSimple; - -typedef struct prof_layout_split_t { - ProfLayout base; - WINDOW *subwin; - int sub_y_pos; - unsigned long memcheck; -} ProfLayoutSplit; - -typedef enum { - WIN_CONSOLE, - WIN_CHAT, - WIN_MUC, - WIN_MUC_CONFIG, - WIN_PRIVATE, - WIN_XML -} win_type_t; - -typedef enum { - PROF_ENC_NONE, - PROF_ENC_OTR -} prof_enc_t; - -typedef struct prof_win_t { - win_type_t type; - ProfLayout *layout; -} ProfWin; - -typedef struct prof_console_win_t { - ProfWin window; -} ProfConsoleWin; - -typedef struct prof_chat_win_t { - ProfWin window; - char *barejid; - int unread; - ChatState *state; - prof_enc_t enc_mode; - gboolean otr_is_trusted; - char *resource_override; - gboolean history_shown; - unsigned long memcheck; -} ProfChatWin; - -typedef struct prof_muc_win_t { - ProfWin window; - char *roomjid; - int unread; - gboolean showjid; - unsigned long memcheck; -} ProfMucWin; - -typedef struct prof_mucconf_win_t { - ProfWin window; - char *roomjid; - DataForm *form; - unsigned long memcheck; -} ProfMucConfWin; - -typedef struct prof_private_win_t { - ProfWin window; - char *fulljid; - int unread; - unsigned long memcheck; -} ProfPrivateWin; - -typedef struct prof_xml_win_t { - ProfWin window; - unsigned long memcheck; -} ProfXMLWin; - -ProfWin* win_create_console(void); -ProfWin* win_create_chat(const char * const barejid); -ProfWin* win_create_muc(const char * const roomjid); -ProfWin* win_create_muc_config(const char * const title, DataForm *form); -ProfWin* win_create_private(const char * const fulljid); -ProfWin* win_create_xmlconsole(void); - -char *win_get_title(ProfWin *window); - -void win_free(ProfWin *window); -void win_update_virtual(ProfWin *window); void win_move_to_end(ProfWin *window); -void win_show_contact(ProfWin *window, PContact contact); -void win_show_occupant(ProfWin *window, Occupant *occupant); void win_show_status_string(ProfWin *window, const char * const from, const char * const show, const char * const status, GDateTime *last_activity, const char * const pre, const char * const default_show); void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, const char * const from, const char * const message); -void win_show_info(ProfWin *window, PContact contact); -void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant); -void win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...); -void win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message); void win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, char *id); -void win_println(ProfWin *window, const char * const message); void win_newline(ProfWin *window); void win_redraw(ProfWin *window); -void win_hide_subwin(ProfWin *window); -void win_show_subwin(ProfWin *window); int win_roster_cols(void); int win_occpuants_cols(void); void win_printline_nowrap(WINDOW *win, char *msg); void win_mouse(ProfWin *current, const wint_t ch, const int result); void win_mark_received(ProfWin *window, const char * const id); -int win_unread(ProfWin *window); gboolean win_has_active_subwin(ProfWin *window); +void win_clear(ProfWin *window); + void win_page_up(ProfWin *window); void win_page_down(ProfWin *window); void win_sub_page_down(ProfWin *window); diff --git a/src/ui/windows.c b/src/ui/windows.c deleted file mode 100644 index 2334efc8..00000000 --- a/src/ui/windows.c +++ /dev/null @@ -1,873 +0,0 @@ -/* - * windows.c - * - * Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com> - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see <http://www.gnu.org/licenses/>. - * - * In addition, as a special exception, the copyright holders give permission to - * link the code of portions of this program with the OpenSSL library under - * certain conditions as described in each individual source file, and - * distribute linked combinations including the two. - * - * You must obey the GNU General Public License in all respects for all of the - * code used other than OpenSSL. If you modify file(s) with this exception, you - * may extend this exception to your version of the file(s), but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. If you delete this exception statement from all - * source files in the program, then also delete it here. - * - */ - -#include "config.h" - -#include <string.h> -#include <assert.h> -#include <stdlib.h> - -#include <glib.h> - -#ifdef HAVE_NCURSESW_NCURSES_H -#include <ncursesw/ncurses.h> -#elif HAVE_NCURSES_H -#include <ncurses.h> -#endif - -#include "common.h" -#include "roster_list.h" -#include "config/theme.h" -#include "ui/ui.h" -#include "ui/statusbar.h" -#include "ui/window.h" -#include "ui/windows.h" -#include "event/ui_events.h" - -static GHashTable *windows; -static int current; -static int max_cols; - -void -wins_init(void) -{ - windows = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, - (GDestroyNotify)win_free); - - max_cols = getmaxx(stdscr); - ProfWin *console = win_create_console(); - g_hash_table_insert(windows, GINT_TO_POINTER(1), console); - - current = 1; -} - -ProfWin * -wins_get_console(void) -{ - return g_hash_table_lookup(windows, GINT_TO_POINTER(1)); -} - -ProfChatWin * -wins_get_chat(const char * const barejid) -{ - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - - while (curr) { - ProfWin *window = curr->data; - if (window->type == WIN_CHAT) { - ProfChatWin *chatwin = (ProfChatWin*)window; - if (g_strcmp0(chatwin->barejid, barejid) == 0) { - g_list_free(values); - return chatwin; - } - } - curr = g_list_next(curr); - } - - g_list_free(values); - return NULL; -} - -ProfMucConfWin * -wins_get_muc_conf(const char * const roomjid) -{ - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - - while (curr) { - ProfWin *window = curr->data; - if (window->type == WIN_MUC_CONFIG) { - ProfMucConfWin *confwin = (ProfMucConfWin*)window; - if (g_strcmp0(confwin->roomjid, roomjid) == 0) { - g_list_free(values); - return confwin; - } - } - curr = g_list_next(curr); - } - - g_list_free(values); - return NULL; -} - -ProfMucWin * -wins_get_muc(const char * const roomjid) -{ - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - - while (curr) { - ProfWin *window = curr->data; - if (window->type == WIN_MUC) { - ProfMucWin *mucwin = (ProfMucWin*)window; - if (g_strcmp0(mucwin->roomjid, roomjid) == 0) { - g_list_free(values); - return mucwin; - } - } - curr = g_list_next(curr); - } - - g_list_free(values); - return NULL; -} - -ProfPrivateWin * -wins_get_private(const char * const fulljid) -{ - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - - while (curr) { - ProfWin *window = curr->data; - if (window->type == WIN_PRIVATE) { - ProfPrivateWin *privatewin = (ProfPrivateWin*)window; - if (g_strcmp0(privatewin->fulljid, fulljid) == 0) { - g_list_free(values); - return privatewin; - } - } - curr = g_list_next(curr); - } - - g_list_free(values); - return NULL; -} - -ProfWin * -wins_get_current(void) -{ - if (windows) { - return g_hash_table_lookup(windows, GINT_TO_POINTER(current)); - } else { - return NULL; - } -} - -ProfChatWin * -wins_get_current_chat(void) -{ - if (windows) { - ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current)); - if (window) { - ProfChatWin *chatwin = (ProfChatWin*)window; - assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - return chatwin; - } else { - return NULL; - } - } else { - return NULL; - } -} - -ProfMucWin * -wins_get_current_muc(void) -{ - if (windows) { - ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current)); - if (window) { - ProfMucWin *mucwin = (ProfMucWin*)window; - assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - return mucwin; - } else { - return NULL; - } - } else { - return NULL; - } -} - -ProfPrivateWin * -wins_get_current_private(void) -{ - if (windows) { - ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current)); - if (window) { - ProfPrivateWin *privatewin = (ProfPrivateWin*)window; - assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK); - return privatewin; - } else { - return NULL; - } - } else { - return NULL; - } -} - -ProfMucConfWin * -wins_get_current_muc_conf(void) -{ - if (windows) { - ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current)); - if (window) { - ProfMucConfWin *confwin = (ProfMucConfWin*)window; - assert(confwin->memcheck == PROFCONFWIN_MEMCHECK); - return confwin; - } else { - return NULL; - } - } else { - return NULL; - } -} - -GList * -wins_get_nums(void) -{ - return g_hash_table_get_keys(windows); -} - -void -wins_set_current_by_num(int i) -{ - ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(i)); - if (window) { - current = i; - if (window->type == WIN_CHAT) { - ProfChatWin *chatwin = (ProfChatWin*) window; - assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - chatwin->unread = 0; - } else if (window->type == WIN_MUC) { - ProfMucWin *mucwin = (ProfMucWin*) window; - assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - mucwin->unread = 0; - } else if (window->type == WIN_PRIVATE) { - ProfPrivateWin *privatewin = (ProfPrivateWin*) window; - privatewin->unread = 0; - } - } -} - -ProfWin * -wins_get_by_num(int i) -{ - return g_hash_table_lookup(windows, GINT_TO_POINTER(i)); -} - -ProfWin * -wins_get_next(void) -{ - // get and sort win nums - GList *keys = g_hash_table_get_keys(windows); - keys = g_list_sort(keys, cmp_win_num); - GList *curr = keys; - - // find our place in the list - while (curr) { - if (current == GPOINTER_TO_INT(curr->data)) { - break; - } - curr = g_list_next(curr); - } - - // if there is a next window return it - curr = g_list_next(curr); - if (curr) { - int next = GPOINTER_TO_INT(curr->data); - g_list_free(keys); - return wins_get_by_num(next); - // otherwise return the first window (console) - } else { - g_list_free(keys); - return wins_get_console(); - } -} - -ProfWin * -wins_get_previous(void) -{ - // get and sort win nums - GList *keys = g_hash_table_get_keys(windows); - keys = g_list_sort(keys, cmp_win_num); - GList *curr = keys; - - // find our place in the list - while (curr) { - if (current == GPOINTER_TO_INT(curr->data)) { - break; - } - curr = g_list_next(curr); - } - - // if there is a previous window return it - curr = g_list_previous(curr); - if (curr) { - int previous = GPOINTER_TO_INT(curr->data); - g_list_free(keys); - return wins_get_by_num(previous); - // otherwise return the last window - } else { - int new_num = GPOINTER_TO_INT(g_list_last(keys)->data); - g_list_free(keys); - return wins_get_by_num(new_num); - } -} - -int -wins_get_num(ProfWin *window) -{ - GList *keys = g_hash_table_get_keys(windows); - GList *curr = keys; - - while (curr) { - gconstpointer num_p = curr->data; - ProfWin *curr_win = g_hash_table_lookup(windows, num_p); - if (curr_win == window) { - g_list_free(keys); - return GPOINTER_TO_INT(num_p); - } - curr = g_list_next(curr); - } - - g_list_free(keys); - return -1; -} - -int -wins_get_current_num(void) -{ - return current; -} - -void -wins_close_current(void) -{ - wins_close_by_num(current); -} - -void -wins_close_by_num(int i) -{ - // console cannot be closed - if (i != 1) { - - // go to console if closing current window - if (i == current) { - current = 1; - ProfWin *window = wins_get_current(); - win_update_virtual(window); - } - - g_hash_table_remove(windows, GINT_TO_POINTER(i)); - status_bar_inactive(i); - } -} - -void -wins_clear_current(void) -{ - ProfWin *window = wins_get_current(); - werase(window->layout->win); - win_update_virtual(window); -} - -gboolean -wins_is_current(ProfWin *window) -{ - ProfWin *current_window = wins_get_current(); - - if (current_window == window) { - return TRUE; - } else { - return FALSE; - } -} - -ProfWin * -wins_new_xmlconsole(void) -{ - GList *keys = g_hash_table_get_keys(windows); - int result = get_next_available_win_num(keys); - g_list_free(keys); - ProfWin *newwin = win_create_xmlconsole(); - g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); - return newwin; -} - -ProfWin * -wins_new_chat(const char * const barejid) -{ - GList *keys = g_hash_table_get_keys(windows); - int result = get_next_available_win_num(keys); - g_list_free(keys); - ProfWin *newwin = win_create_chat(barejid); - g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); - return newwin; -} - -ProfWin * -wins_new_muc(const char * const roomjid) -{ - GList *keys = g_hash_table_get_keys(windows); - int result = get_next_available_win_num(keys); - g_list_free(keys); - ProfWin *newwin = win_create_muc(roomjid); - g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); - return newwin; -} - -ProfWin * -wins_new_muc_config(const char * const roomjid, DataForm *form) -{ - GList *keys = g_hash_table_get_keys(windows); - int result = get_next_available_win_num(keys); - g_list_free(keys); - ProfWin *newwin = win_create_muc_config(roomjid, form); - g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); - return newwin; -} - -ProfWin * -wins_new_private(const char * const fulljid) -{ - GList *keys = g_hash_table_get_keys(windows); - int result = get_next_available_win_num(keys); - g_list_free(keys); - ProfWin *newwin = win_create_private(fulljid); - g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); - return newwin; -} - -int -wins_get_total_unread(void) -{ - int result = 0; - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - - while (curr) { - ProfWin *window = curr->data; - result += win_unread(window); - curr = g_list_next(curr); - } - g_list_free(values); - return result; -} - -void -wins_resize_all(void) -{ - int cols = getmaxx(stdscr); - - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - while (curr) { - ProfWin *window = curr->data; - int subwin_cols = 0; - - if (window->layout->type == LAYOUT_SPLIT) { - ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout; - if (layout->subwin) { - if (window->type == WIN_CONSOLE) { - subwin_cols = win_roster_cols(); - } else if (window->type == WIN_MUC) { - subwin_cols = win_occpuants_cols(); - } - wresize(layout->base.win, PAD_SIZE, cols - subwin_cols); - wresize(layout->subwin, PAD_SIZE, subwin_cols); - if (window->type == WIN_CONSOLE) { - rosterwin_roster(); - } else if (window->type == WIN_MUC) { - ProfMucWin *mucwin = (ProfMucWin *)window; - assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - occupantswin_occupants(mucwin->roomjid); - } - } else { - wresize(layout->base.win, PAD_SIZE, cols); - } - } else { - wresize(window->layout->win, PAD_SIZE, cols); - } - - win_redraw(window); - curr = g_list_next(curr); - } - g_list_free(values); - - ProfWin *current_win = wins_get_current(); - win_update_virtual(current_win); -} - -void -wins_hide_subwin(ProfWin *window) -{ - int rows, cols; - getmaxyx(stdscr, rows, cols); - - win_hide_subwin(window); - - ProfWin *current_win = wins_get_current(); - if ((current_win->type == WIN_MUC) || (current_win->type == WIN_CONSOLE)) { - pnoutrefresh(current_win->layout->win, current_win->layout->y_pos, 0, 1, 0, rows-3, cols-1); - } -} - -void -wins_show_subwin(ProfWin *window) -{ - int rows, cols; - getmaxyx(stdscr, rows, cols); - int subwin_cols = 0; - - win_show_subwin(window); - - ProfWin *current_win = wins_get_current(); - if (current_win->type == WIN_MUC) { - ProfLayoutSplit *layout = (ProfLayoutSplit*)current_win->layout; - subwin_cols = win_occpuants_cols(); - pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 1, 0, rows-3, (cols-subwin_cols)-1); - pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, 1, (cols-subwin_cols), rows-3, cols-1); - } else if (current_win->type == WIN_CONSOLE) { - ProfLayoutSplit *layout = (ProfLayoutSplit*)current_win->layout; - subwin_cols = win_roster_cols(); - pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 1, 0, rows-3, (cols-subwin_cols)-1); - pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, 1, (cols-subwin_cols), rows-3, cols-1); - } -} - -ProfXMLWin * -wins_get_xmlconsole(void) -{ - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - - while (curr) { - ProfWin *window = curr->data; - if (window->type == WIN_XML) { - ProfXMLWin *xmlwin = (ProfXMLWin*)window; - assert(xmlwin->memcheck == PROFXMLWIN_MEMCHECK); - g_list_free(values); - return xmlwin; - } - curr = g_list_next(curr); - } - - g_list_free(values); - return NULL; -} - -GSList * -wins_get_chat_recipients(void) -{ - GSList *result = NULL; - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - - while (curr) { - ProfWin *window = curr->data; - if (window->type == WIN_CHAT) { - ProfChatWin *chatwin = (ProfChatWin*)window; - result = g_slist_append(result, chatwin->barejid); - } - curr = g_list_next(curr); - } - g_list_free(values); - return result; -} - -GSList * -wins_get_prune_wins(void) -{ - GSList *result = NULL; - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - - while (curr) { - ProfWin *window = curr->data; - if (win_unread(window) == 0 && - window->type != WIN_MUC && - window->type != WIN_MUC_CONFIG && - window->type != WIN_XML && - window->type != WIN_CONSOLE) { - result = g_slist_append(result, window); - } - curr = g_list_next(curr); - } - g_list_free(values); - return result; -} - -void -wins_lost_connection(void) -{ - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - - while (curr) { - ProfWin *window = curr->data; - if (window->type != WIN_CONSOLE) { - win_print(window, '-', NULL, 0, THEME_ERROR, "", "Lost connection."); - - // if current win, set current_win_dirty - if (wins_is_current(window)) { - win_update_virtual(window); - } - } - curr = g_list_next(curr); - } - g_list_free(values); -} - -gboolean -wins_swap(int source_win, int target_win) -{ - ProfWin *source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win)); - ProfWin *console = wins_get_console(); - - if (source) { - ProfWin *target = g_hash_table_lookup(windows, GINT_TO_POINTER(target_win)); - - // target window empty - if (!target) { - g_hash_table_steal(windows, GINT_TO_POINTER(source_win)); - g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source); - status_bar_inactive(source_win); - if (win_unread(source) > 0) { - status_bar_new(target_win); - } else { - status_bar_active(target_win); - } - if (wins_get_current_num() == source_win) { - wins_set_current_by_num(target_win); - ui_ev_focus_win(console); - } - return TRUE; - - // target window occupied - } else { - g_hash_table_steal(windows, GINT_TO_POINTER(source_win)); - g_hash_table_steal(windows, GINT_TO_POINTER(target_win)); - g_hash_table_insert(windows, GINT_TO_POINTER(source_win), target); - g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source); - if (win_unread(source) > 0) { - status_bar_new(target_win); - } else { - status_bar_active(target_win); - } - if (win_unread(target) > 0) { - status_bar_new(source_win); - } else { - status_bar_active(source_win); - } - if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { - ui_ev_focus_win(console); - } - return TRUE; - } - } else { - return FALSE; - } -} - -gboolean -wins_tidy(void) -{ - gboolean tidy_required = FALSE; - // check for gaps - GList *keys = g_hash_table_get_keys(windows); - keys = g_list_sort(keys, cmp_win_num); - - // get last used - GList *last = g_list_last(keys); - int last_num = GPOINTER_TO_INT(last->data); - - // find first free num TODO - Will sort again - int next_available = get_next_available_win_num(keys); - - // found gap (next available before last window) - if (cmp_win_num(GINT_TO_POINTER(next_available), GINT_TO_POINTER(last_num)) < 0) { - tidy_required = TRUE; - } - - if (tidy_required) { - status_bar_set_all_inactive(); - GHashTable *new_windows = g_hash_table_new_full(g_direct_hash, - g_direct_equal, NULL, (GDestroyNotify)win_free); - - int num = 1; - GList *curr = keys; - while (curr) { - ProfWin *window = g_hash_table_lookup(windows, curr->data); - if (num == 10) { - g_hash_table_insert(new_windows, GINT_TO_POINTER(0), window); - if (win_unread(window) > 0) { - status_bar_new(0); - } else { - status_bar_active(0); - } - } else { - g_hash_table_insert(new_windows, GINT_TO_POINTER(num), window); - if (win_unread(window) > 0) { - status_bar_new(num); - } else { - status_bar_active(num); - } - } - num++; - curr = g_list_next(curr); - } - - windows = new_windows; - current = 1; - ProfWin *console = wins_get_console(); - ui_ev_focus_win(console); - g_list_free(keys); - return TRUE; - } else { - g_list_free(keys); - return FALSE; - } -} - -GSList * -wins_create_summary(void) -{ - GSList *result = NULL; - - GList *keys = g_hash_table_get_keys(windows); - keys = g_list_sort(keys, cmp_win_num); - GList *curr = keys; - - while (curr) { - ProfWin *window = g_hash_table_lookup(windows, curr->data); - int ui_index = GPOINTER_TO_INT(curr->data); - - GString *chat_string; - GString *priv_string; - GString *muc_string; - GString *muc_config_string; - GString *xml_string; - - switch (window->type) - { - case WIN_CONSOLE: - result = g_slist_append(result, strdup("1: Console")); - break; - case WIN_CHAT: - chat_string = g_string_new(""); - - ProfChatWin *chatwin = (ProfChatWin*)window; - PContact contact = roster_get_contact(chatwin->barejid); - if (contact == NULL) { - g_string_printf(chat_string, "%d: Chat %s", ui_index, chatwin->barejid); - } else { - const char *display_name = p_contact_name_or_jid(contact); - g_string_printf(chat_string, "%d: Chat %s", ui_index, display_name); - GString *chat_presence = g_string_new(""); - g_string_printf(chat_presence, " - %s", p_contact_presence(contact)); - g_string_append(chat_string, chat_presence->str); - g_string_free(chat_presence, TRUE); - } - - if (chatwin->unread > 0) { - GString *chat_unread = g_string_new(""); - g_string_printf(chat_unread, ", %d unread", chatwin->unread); - g_string_append(chat_string, chat_unread->str); - g_string_free(chat_unread, TRUE); - } - - result = g_slist_append(result, strdup(chat_string->str)); - g_string_free(chat_string, TRUE); - - break; - - case WIN_PRIVATE: - priv_string = g_string_new(""); - ProfPrivateWin *privatewin = (ProfPrivateWin*)window; - g_string_printf(priv_string, "%d: Private %s", ui_index, privatewin->fulljid); - - if (privatewin->unread > 0) { - GString *priv_unread = g_string_new(""); - g_string_printf(priv_unread, ", %d unread", privatewin->unread); - g_string_append(priv_string, priv_unread->str); - g_string_free(priv_unread, TRUE); - } - - result = g_slist_append(result, strdup(priv_string->str)); - g_string_free(priv_string, TRUE); - - break; - - case WIN_MUC: - muc_string = g_string_new(""); - ProfMucWin *mucwin = (ProfMucWin*)window; - g_string_printf(muc_string, "%d: Room %s", ui_index, mucwin->roomjid); - - if (mucwin->unread > 0) { - GString *muc_unread = g_string_new(""); - g_string_printf(muc_unread, ", %d unread", mucwin->unread); - g_string_append(muc_string, muc_unread->str); - g_string_free(muc_unread, TRUE); - } - - result = g_slist_append(result, strdup(muc_string->str)); - g_string_free(muc_string, TRUE); - - break; - - case WIN_MUC_CONFIG: - muc_config_string = g_string_new(""); - char *title = win_get_title(window); - g_string_printf(muc_config_string, "%d: %s", ui_index, title); - result = g_slist_append(result, strdup(muc_config_string->str)); - g_string_free(muc_config_string, TRUE); - free(title); - - break; - - case WIN_XML: - xml_string = g_string_new(""); - g_string_printf(xml_string, "%d: XML console", ui_index); - result = g_slist_append(result, strdup(xml_string->str)); - g_string_free(xml_string, TRUE); - - break; - - default: - break; - } - curr = g_list_next(curr); - } - - g_list_free(keys); - return result; -} - -void -wins_destroy(void) -{ - g_hash_table_destroy(windows); -} diff --git a/src/ui/windows.h b/src/ui/windows.h deleted file mode 100644 index 4cc527ca..00000000 --- a/src/ui/windows.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * windows.h - * - * Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com> - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see <http://www.gnu.org/licenses/>. - * - * In addition, as a special exception, the copyright holders give permission to - * link the code of portions of this program with the OpenSSL library under - * certain conditions as described in each individual source file, and - * distribute linked combinations including the two. - * - * You must obey the GNU General Public License in all respects for all of the - * code used other than OpenSSL. If you modify file(s) with this exception, you - * may extend this exception to your version of the file(s), but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. If you delete this exception statement from all - * source files in the program, then also delete it here. - * - */ - -#ifndef UI_WINDOWS_H -#define UI_WINDOWS_H - -#include "ui/window.h" - -void wins_init(void); - -ProfWin * wins_new_xmlconsole(void); -ProfWin * wins_new_chat(const char * const barejid); -ProfWin * wins_new_muc(const char * const roomjid); -ProfWin * wins_new_muc_config(const char * const roomjid, DataForm *form); -ProfWin * wins_new_private(const char * const fulljid); - -ProfWin * wins_get_console(void); -ProfChatWin *wins_get_chat(const char * const barejid); -ProfMucWin * wins_get_muc(const char * const roomjid); -ProfMucConfWin * wins_get_muc_conf(const char * const roomjid); -ProfPrivateWin *wins_get_private(const char * const fulljid); -ProfXMLWin * wins_get_xmlconsole(void); - -ProfWin * wins_get_current(void); -ProfChatWin * wins_get_current_chat(void); -ProfMucWin * wins_get_current_muc(void); -ProfPrivateWin * wins_get_current_private(void); -ProfMucConfWin * wins_get_current_muc_conf(void); - -void wins_set_current_by_num(int i); - -ProfWin * wins_get_by_num(int i); - -ProfWin * wins_get_next(void); -ProfWin * wins_get_previous(void); -int wins_get_num(ProfWin *window); -int wins_get_current_num(void); -void wins_close_current(void); -void wins_close_by_num(int i); -void wins_clear_current(void); -gboolean wins_is_current(ProfWin *window); -int wins_get_total_unread(void); -void wins_resize_all(void); -GSList * wins_get_chat_recipients(void); -GSList * wins_get_prune_wins(void); -void wins_lost_connection(void); -gboolean wins_tidy(void); -GSList * wins_create_summary(void); -void wins_destroy(void); -GList * wins_get_nums(void); -gboolean wins_swap(int source_win, int target_win); -void wins_hide_subwin(ProfWin *window); -void wins_show_subwin(ProfWin *window); - -#endif |