diff options
Diffstat (limited to 'src/gui/curses/gui-curses-main.c')
-rw-r--r-- | src/gui/curses/gui-curses-main.c | 334 |
1 files changed, 123 insertions, 211 deletions
diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index db62058f4..c4870167b 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -29,22 +29,88 @@ #include <string.h> #include <signal.h> -#include "../../common/weechat.h" -#include "../gui.h" -#include "../../common/fifo.h" -#include "../../common/utf8.h" -#include "../../common/util.h" -#include "../../common/weeconfig.h" -#include "../../protocols/irc/irc.h" +#include "../../core/weechat.h" +#include "../../core/wee-config.h" +#include "../../core/wee-hook.h" +#include "../../core/wee-string.h" +#include "../../core/wee-utf8.h" +#include "../../core/wee-util.h" +#include "../../plugins/plugin.h" +#include "../gui-infobar.h" +#include "../gui-input.h" +#include "../gui-history.h" +#include "../gui-hotlist.h" +#include "../gui-keyboard.h" +#include "../gui-main.h" +#include "../gui-window.h" #include "gui-curses.h" -#ifdef PLUGINS -#include "../../plugins/plugins.h" -#endif +/* + * gui_main_pre_init: pre-initialize GUI (called before gui_init) + */ -int send_irc_quit = 0; +void +gui_main_pre_init (int *argc, char **argv[]) +{ + /* nothing for Curses interface */ + (void) argc; + (void) argv; +} + +/* + * gui_main_init: init GUI + */ +void +gui_main_init () +{ + struct t_gui_buffer *ptr_buffer; + + initscr (); + + curs_set (1); + noecho (); + nodelay (stdscr, TRUE); + raw (); + + gui_color_init (); + gui_chat_prefix_build (); + + gui_infobar = NULL; + + gui_ok = ((COLS > WINDOW_MIN_WIDTH) && (LINES > WINDOW_MIN_HEIGHT)); + + refresh (); + + /* init clipboard buffer */ + gui_input_clipboard = NULL; + + /* get time length */ + gui_chat_time_length = util_get_time_length (cfg_look_buffer_time_format); + + /* create new window/buffer */ + if (gui_window_new (NULL, 0, 0, COLS, LINES, 100, 100)) + { + gui_current_window = gui_windows; + ptr_buffer = gui_buffer_new (NULL, "weechat", "weechat"); + if (ptr_buffer) + { + gui_init_ok = 1; + gui_buffer_set_title (ptr_buffer, + PACKAGE_STRING " " WEECHAT_COPYRIGHT_DATE + " - " WEECHAT_WEBSITE); + gui_window_redraw_buffer (ptr_buffer); + } + else + gui_init_ok = 0; + + if (cfg_look_set_title) + gui_window_title_set (); + + signal (SIGWINCH, gui_window_refresh_screen_sigwinch); + } +} /* * gui_main_quit: quit weechat (signal received) @@ -54,7 +120,6 @@ void gui_main_quit () { quit_weechat = 1; - send_irc_quit = 1; } /* @@ -64,26 +129,23 @@ gui_main_quit () void gui_main_loop () { - fd_set read_fd; - static struct timeval timeout, tv; - t_irc_server *ptr_server; - t_gui_buffer *ptr_buffer; - int old_day, old_min, old_sec, diff; + fd_set read_fds, write_fds, except_fds; + static struct timeval timeout; + struct t_gui_buffer *ptr_buffer; + int old_day, old_min, old_sec; char text_time[1024], *text_time2; - time_t new_time; + struct timeval tv_time; struct tm *local_time; quit_weechat = 0; - send_irc_quit = 0; - - new_time = time (NULL); - gui_last_activity_time = new_time; - local_time = localtime (&new_time); + + gettimeofday (&tv_time, NULL); + gui_keyboard_last_activity_time = tv_time.tv_sec; + local_time = localtime (&tv_time.tv_sec); old_day = local_time->tm_mday; old_min = -1; old_sec = -1; - irc_check_away = 0; /* if SIGTERM or SIGHUP received => quit */ signal (SIGTERM, gui_main_quit); @@ -94,9 +156,22 @@ gui_main_loop () /* refresh needed ? */ if (gui_refresh_screen_needed) gui_window_refresh_screen (0); + + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->chat_refresh_needed) + { + gui_chat_draw (ptr_buffer, 0); + ptr_buffer->chat_refresh_needed = 0; + } + } - new_time = time (NULL); - local_time = localtime (&new_time); + gettimeofday (&tv_time, NULL); + local_time = localtime (&tv_time.tv_sec); + + /* execute hook timers */ + hook_timer_exec (&tv_time); /* minute has changed ? => redraw infobar */ if (local_time->tm_min != old_min) @@ -108,17 +183,17 @@ gui_main_loop () && (local_time->tm_mday != old_day)) { strftime (text_time, sizeof (text_time), - cfg_look_day_change_timestamp, local_time); - text_time2 = weechat_iconv_to_internal (NULL, text_time); + cfg_look_day_change_time_format, local_time); + text_time2 = string_iconv_to_internal (NULL, text_time); gui_add_hotlist = 0; for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { - if (ptr_buffer->type == GUI_BUFFER_TYPE_STANDARD) - gui_printf_nolog_notime (ptr_buffer, - _("Day changed to %s\n"), - (text_time2) ? - text_time2 : text_time); + if (ptr_buffer->type == GUI_BUFFER_TYPE_FORMATED) + gui_chat_printf (ptr_buffer, + _("\t\tDay changed to %s"), + (text_time2) ? + text_time2 : text_time); } if (text_time2) free (text_time2); @@ -131,16 +206,6 @@ gui_main_loop () if (local_time->tm_sec != old_sec) { old_sec = local_time->tm_sec; - - /* send queued messages */ - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if (ptr_server->is_connected) - { - irc_server_outqueue_send (ptr_server); - } - } /* display time in infobar (if seconds displayed) */ if (cfg_look_infobar_seconds) @@ -161,22 +226,6 @@ gui_main_loop () gui_infobar_draw (gui_current_window->buffer, 1); } } - - /* away check */ - if (cfg_irc_away_check != 0) - { - irc_check_away++; - if (irc_check_away >= (cfg_irc_away_check * 60)) - { - irc_check_away = 0; - irc_server_check_away (); - } - } - -#ifdef PLUGINS - /* call timer handlers */ - plugin_timer_handler_exec (); -#endif } /* read keyboard */ @@ -184,15 +233,15 @@ gui_main_loop () /* on GNU/Hurd 2 select() are causing troubles with keyboard */ /* waiting for a fix, we use only one select() */ #ifndef __GNU__ - FD_ZERO (&read_fd); + FD_ZERO (&read_fds); timeout.tv_sec = 0; timeout.tv_usec = 8000; - FD_SET (STDIN_FILENO, &read_fd); + FD_SET (STDIN_FILENO, &read_fds); - if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout) > 0) + if (select (FD_SETSIZE, &read_fds, NULL, NULL, &timeout) > 0) { - if (FD_ISSET (STDIN_FILENO, &read_fd)) + if (FD_ISSET (STDIN_FILENO, &read_fds)) { gui_keyboard_read (); } @@ -201,163 +250,30 @@ gui_main_loop () gui_keyboard_flush (); #endif - /* read sockets (servers, child process when connecting, FIFO pipe) */ - - FD_ZERO (&read_fd); + /* read sockets/files/pipes */ + hook_fd_set (&read_fds, &write_fds, &except_fds); #ifdef __GNU__ timeout.tv_sec = 0; timeout.tv_usec = 10000; - FD_SET (STDIN_FILENO, &read_fd); + FD_SET (STDIN_FILENO, &read_fds); #else timeout.tv_sec = 0; timeout.tv_usec = 2000; #endif - if (weechat_fifo != -1) - FD_SET (weechat_fifo, &read_fd); - - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - /* check if reconnection is pending */ - if ((!ptr_server->is_connected) - && (ptr_server->reconnect_start > 0) - && (new_time >= (ptr_server->reconnect_start + ptr_server->autoreconnect_delay))) - irc_server_reconnect (ptr_server); - else - { - if (ptr_server->is_connected) - { - /* check for lag */ - if ((ptr_server->lag_check_time.tv_sec == 0) - && (new_time >= ptr_server->lag_next_check)) - { - irc_server_sendf (ptr_server, "PING %s", ptr_server->address); - gettimeofday (&(ptr_server->lag_check_time), NULL); - } - - /* lag timeout => disconnect */ - if ((ptr_server->lag_check_time.tv_sec != 0) - && (cfg_irc_lag_disconnect > 0)) - { - gettimeofday (&tv, NULL); - diff = (int) get_timeval_diff (&(ptr_server->lag_check_time), &tv); - if (diff / 1000 > cfg_irc_lag_disconnect * 60) - { - irc_display_prefix (ptr_server, ptr_server->buffer, GUI_PREFIX_ERROR); - gui_printf (ptr_server->buffer, - _("%s lag is high, disconnecting from server...\n"), - WEECHAT_WARNING); - irc_server_disconnect (ptr_server, 1); - continue; - } - } - - /* check if it's time to autojoin channels (after command delay) */ - if ((ptr_server->command_time != 0) - && (new_time >= ptr_server->command_time + ptr_server->command_delay)) - { - irc_server_autojoin_channels (ptr_server); - ptr_server->command_time = 0; - } - } - - if (!ptr_server->is_connected && (ptr_server->child_pid > 0)) - FD_SET (ptr_server->child_read, &read_fd); - else - { - if (ptr_server->sock >= 0) - FD_SET (ptr_server->sock, &read_fd); - } - } - } - - if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout) > 0) + if (select (FD_SETSIZE, + &read_fds, &write_fds, &except_fds, + &timeout) > 0) { #ifdef __GNU__ - if (FD_ISSET (STDIN_FILENO, &read_fd)) + if (FD_ISSET (STDIN_FILENO, &read_fds)) { gui_keyboard_read (); } #endif - if ((weechat_fifo != -1) && (FD_ISSET (weechat_fifo, &read_fd))) - { - fifo_read (); - } - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if (!ptr_server->is_connected && (ptr_server->child_pid > 0)) - { - if (FD_ISSET (ptr_server->child_read, &read_fd)) - irc_server_child_read (ptr_server); - } - else - { - if ((ptr_server->sock >= 0) && - (FD_ISSET (ptr_server->sock, &read_fd))) - irc_server_recv (ptr_server); - } - } + hook_fd_exec (&read_fds, &write_fds, &except_fds); } - - /* manages active DCC */ - irc_dcc_handle (); - } - if (send_irc_quit) - irc_send_cmd_quit (NULL, NULL, NULL); -} - -/* - * gui_main_pre_init: pre-initialize GUI (called before gui_init) - */ - -void -gui_main_pre_init (int *argc, char **argv[]) -{ - /* nothing for Curses interface */ - (void) argc; - (void) argv; -} - -/* - * gui_main_init: init GUI - */ - -void -gui_main_init () -{ - initscr (); - - curs_set (1); - noecho (); - nodelay (stdscr, TRUE); - raw (); - - gui_color_init (); - - gui_infobar = NULL; - - gui_ok = ((COLS > WINDOW_MIN_WIDTH) && (LINES > WINDOW_MIN_HEIGHT)); - - refresh (); - - /* init clipboard buffer */ - gui_input_clipboard = NULL; - - /* create new window/buffer */ - if (gui_window_new (NULL, 0, 0, COLS, LINES, 100, 100)) - { - gui_current_window = gui_windows; - gui_buffer_new (gui_windows, NULL, NULL, GUI_BUFFER_TYPE_STANDARD, 1); - - if (cfg_look_set_title) - gui_window_set_title (); - - gui_init_ok = 1; - - signal (SIGWINCH, gui_window_refresh_screen_sigwinch); } } @@ -371,11 +287,7 @@ gui_main_end () /* free clipboard buffer */ if (gui_input_clipboard) free (gui_input_clipboard); - - /* delete all panels */ - while (gui_panels) - gui_panel_free (gui_panels); - + /* delete all windows */ while (gui_windows) gui_window_free (gui_windows); @@ -386,7 +298,7 @@ gui_main_end () gui_buffer_free (gui_buffers, 0); /* delete global history */ - history_global_free (); + gui_history_global_free (); /* delete infobar messages */ while (gui_infobar) @@ -394,7 +306,7 @@ gui_main_end () /* reset title */ if (cfg_look_set_title) - gui_window_reset_title (); + gui_window_title_reset (); /* end of Curses output */ refresh (); |