From 39630c3d588a052196c372ba8101b19e2914c2f2 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 17 Nov 2000 16:27:14 +0000 Subject: windows.h conflicted with microsoft's windows.h :) renamed windows.[ch] to fe-windows.[ch] git-svn-id: http://svn.irssi.org/repos/irssi/trunk@846 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-common/core/Makefile.am | 4 +- src/fe-common/core/autorun.c | 2 +- src/fe-common/core/command-history.c | 2 +- src/fe-common/core/command-history.h | 2 +- src/fe-common/core/fe-channels.c | 2 +- src/fe-common/core/fe-common-core.c | 2 +- src/fe-common/core/fe-core-commands.c | 2 +- src/fe-common/core/fe-log.c | 2 +- src/fe-common/core/fe-queries.c | 2 +- src/fe-common/core/fe-windows.c | 483 ++++++++++++++++++++++++++++++++++ src/fe-common/core/fe-windows.h | 74 ++++++ src/fe-common/core/formats.c | 2 +- src/fe-common/core/formats.h | 2 +- src/fe-common/core/keyboard.c | 2 +- src/fe-common/core/printtext.c | 2 +- src/fe-common/core/printtext.h | 2 +- src/fe-common/core/window-activity.c | 2 +- src/fe-common/core/window-commands.c | 2 +- src/fe-common/core/window-items.c | 2 +- src/fe-common/core/window-items.h | 2 +- src/fe-common/core/window-save.c | 2 +- src/fe-common/core/windows.c | 483 ---------------------------------- src/fe-common/core/windows.h | 74 ------ src/fe-common/irc/dcc/fe-dcc.c | 2 +- src/fe-common/irc/fe-ctcp.c | 2 +- src/fe-common/irc/fe-events.c | 2 +- src/fe-common/irc/fe-irc-commands.c | 2 +- src/fe-common/irc/fe-irc-server.c | 2 +- src/fe-text/gui-printtext.c | 2 +- src/fe-text/gui-readline.c | 2 +- src/fe-text/gui-textwidget.c | 2 +- src/fe-text/gui-windows.c | 2 +- src/fe-text/mainwindow-activity.c | 2 +- src/fe-text/mainwindows.h | 2 +- src/fe-text/statusbar-items.c | 2 +- src/fe-text/statusbar.c | 2 +- 36 files changed, 590 insertions(+), 590 deletions(-) create mode 100644 src/fe-common/core/fe-windows.c create mode 100644 src/fe-common/core/fe-windows.h delete mode 100644 src/fe-common/core/windows.c delete mode 100644 src/fe-common/core/windows.h diff --git a/src/fe-common/core/Makefile.am b/src/fe-common/core/Makefile.am index cea60d81..f54f5958 100644 --- a/src/fe-common/core/Makefile.am +++ b/src/fe-common/core/Makefile.am @@ -33,7 +33,7 @@ libfe_common_core_a_SOURCES = \ window-commands.c \ window-items.c \ window-save.c \ - windows.c + fe-windows.c noinst_HEADERS = \ command-history.h \ @@ -50,4 +50,4 @@ noinst_HEADERS = \ translation.h \ window-items.h \ window-save.h \ - windows.h + fe-windows.h diff --git a/src/fe-common/core/autorun.c b/src/fe-common/core/autorun.c index 506e45ff..b305b82e 100644 --- a/src/fe-common/core/autorun.c +++ b/src/fe-common/core/autorun.c @@ -23,7 +23,7 @@ #include "line-split.h" #include "special-vars.h" -#include "windows.h" +#include "fe-windows.h" static void sig_autorun(void) { diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c index 2a5e755f..7f1d771d 100644 --- a/src/fe-common/core/command-history.c +++ b/src/fe-common/core/command-history.c @@ -24,7 +24,7 @@ #include "special-vars.h" #include "settings.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" /* command history */ diff --git a/src/fe-common/core/command-history.h b/src/fe-common/core/command-history.h index 8ed26757..9f37f069 100644 --- a/src/fe-common/core/command-history.h +++ b/src/fe-common/core/command-history.h @@ -1,7 +1,7 @@ #ifndef __COMMAND_HISTORY_H #define __COMMAND_HISTORY_H -#include "windows.h" +#include "fe-windows.h" void command_history_init(void); void command_history_deinit(void); diff --git a/src/fe-common/core/fe-channels.c b/src/fe-common/core/fe-channels.c index 7f220752..bbe281f1 100644 --- a/src/fe-common/core/fe-channels.c +++ b/src/fe-common/core/fe-channels.c @@ -30,7 +30,7 @@ #include "channels-setup.h" #include "nicklist.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" #include "printtext.h" diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 2b04053f..c934954b 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -32,7 +32,7 @@ #include "formats.h" #include "themes.h" #include "translation.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" #include "window-save.h" diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index 50617981..b3c607ed 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -28,7 +28,7 @@ #include "settings.h" #include "irssi-version.h" -#include "windows.h" +#include "fe-windows.h" #include "printtext.h" #define PASTE_CHECK_SPEED 200 /* 0.2 sec */ diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c index 06841a6b..33b20f43 100644 --- a/src/fe-common/core/fe-log.c +++ b/src/fe-common/core/fe-log.c @@ -29,7 +29,7 @@ #include "special-vars.h" #include "settings.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" #include "formats.h" #include "themes.h" diff --git a/src/fe-common/core/fe-queries.c b/src/fe-common/core/fe-queries.c index dd15091c..81caf2c6 100644 --- a/src/fe-common/core/fe-queries.c +++ b/src/fe-common/core/fe-queries.c @@ -28,7 +28,7 @@ #include "levels.h" #include "queries.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" #include "printtext.h" diff --git a/src/fe-common/core/fe-windows.c b/src/fe-common/core/fe-windows.c new file mode 100644 index 00000000..7678c983 --- /dev/null +++ b/src/fe-common/core/fe-windows.c @@ -0,0 +1,483 @@ +/* + windows.c : irssi + + Copyright (C) 1999-2000 Timo Sirainen + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "module.h" +#include "module-formats.h" +#include "modules.h" +#include "signals.h" +#include "commands.h" +#include "servers.h" +#include "misc.h" +#include "settings.h" + +#include "levels.h" + +#include "printtext.h" +#include "fe-windows.h" +#include "window-items.h" + +GSList *windows; /* first in the list is the active window, + next is the last active, etc. */ +WINDOW_REC *active_win; + +static int daytag; +static int daycheck; /* 0 = don't check, 1 = time is 00:00, check, + 2 = time is 00:00, already checked */ + +static int window_get_new_refnum(void) +{ + WINDOW_REC *win; + GSList *tmp; + int refnum; + + refnum = 1; + tmp = windows; + while (tmp != NULL) { + win = tmp->data; + + if (refnum != win->refnum) { + tmp = tmp->next; + continue; + } + + refnum++; + tmp = windows; + } + + return refnum; +} + +WINDOW_REC *window_create(WI_ITEM_REC *item, int automatic) +{ + WINDOW_REC *rec; + + rec = g_new0(WINDOW_REC, 1); + rec->refnum = window_get_new_refnum(); + + windows = g_slist_prepend(windows, rec); + signal_emit("window created", 2, rec, GINT_TO_POINTER(automatic)); + + if (item != NULL) window_add_item(rec, item, automatic); + if (windows->next == NULL || !automatic || settings_get_bool("window_auto_change")) { + if (automatic && windows->next != NULL) + signal_emit("window changed automatic", 1, rec); + window_set_active(rec); + } + return rec; +} + +/* removed_refnum was removed from the windows list, pack the windows so + there won't be any holes. If there is any holes after removed_refnum, + leave the windows behind it alone. */ +static void windows_pack(int removed_refnum) +{ + WINDOW_REC *window; + int refnum; + + for (refnum = removed_refnum+1;; refnum++) { + window = window_find_refnum(refnum); + if (window == NULL) break; + + window_set_refnum(window, refnum-1); + } +} + +void window_destroy(WINDOW_REC *window) +{ + g_return_if_fail(window != NULL); + + if (window->destroying) return; + window->destroying = TRUE; + windows = g_slist_remove(windows, window); + + if (active_win == window && windows != NULL) { + active_win = NULL; /* it's corrupted */ + window_set_active(windows->data); + } + + while (window->items != NULL) + window_remove_item(window, window->items->data); + + windows_pack(window->refnum); + + signal_emit("window destroyed", 1, window); + + g_slist_foreach(window->waiting_channels, (GFunc) g_free, NULL); + g_slist_free(window->waiting_channels); + + g_free_not_null(window->theme_name); + g_free_not_null(window->name); + g_free(window); +} + +void window_set_active(WINDOW_REC *window) +{ + WINDOW_REC *old_window; + + if (window == active_win) + return; + + old_window = active_win; + active_win = window; + if (active_win != NULL) { + windows = g_slist_remove(windows, active_win); + windows = g_slist_prepend(windows, active_win); + } + + signal_emit("window changed", 2, active_win, old_window); +} + +void window_change_server(WINDOW_REC *window, void *server) +{ + window->active_server = server; + signal_emit("window server changed", 2, window, server); +} + +void window_set_refnum(WINDOW_REC *window, int refnum) +{ + GSList *tmp; + int old_refnum; + + g_return_if_fail(window != NULL); + g_return_if_fail(refnum >= 1); + if (window->refnum == refnum) return; + + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + WINDOW_REC *rec = tmp->data; + + if (rec->refnum == refnum) { + rec->refnum = window->refnum; + signal_emit("window refnum changed", 2, rec, GINT_TO_POINTER(refnum)); + break; + } + } + + old_refnum = window->refnum; + window->refnum = refnum; + signal_emit("window refnum changed", 2, window, GINT_TO_POINTER(old_refnum)); +} + +void window_set_name(WINDOW_REC *window, const char *name) +{ + g_free_not_null(window->name); + window->name = g_strdup(name); + + signal_emit("window name changed", 1, window); +} + +void window_set_level(WINDOW_REC *window, int level) +{ + g_return_if_fail(window != NULL); + + window->level = level; + signal_emit("window level changed", 1, window); +} + +/* return active item's name, or if none is active, window's name */ +char *window_get_active_name(WINDOW_REC *window) +{ + g_return_val_if_fail(window != NULL, NULL); + + if (window->active != NULL) + return window->active->name; + + return window->name; +} + +WINDOW_REC *window_find_level(void *server, int level) +{ + WINDOW_REC *match; + GSList *tmp; + + match = NULL; + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + WINDOW_REC *rec = tmp->data; + + if ((server == NULL || rec->active_server == server) && + (rec->level & level)) { + if (server == NULL || rec->active_server == server) + return rec; + match = rec; + } + } + + return match; +} + +WINDOW_REC *window_find_closest(void *server, const char *name, int level) +{ + WINDOW_REC *window; + WI_ITEM_REC *item; + + /* match by name */ + item = name == NULL ? NULL : + window_item_find(server, name); + if (item != NULL) + return window_item_window(item); + + /* match by level */ + if (level != MSGLEVEL_HILIGHT) + level &= ~(MSGLEVEL_HILIGHT | MSGLEVEL_NOHILIGHT); + window = window_find_level(server, level); + if (window != NULL) return window; + + /* match by level - ignore server */ + window = window_find_level(NULL, level); + if (window != NULL) return window; + + /* fallback to active */ + return active_win; +} + +WINDOW_REC *window_find_refnum(int refnum) +{ + GSList *tmp; + + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + WINDOW_REC *rec = tmp->data; + + if (rec->refnum == refnum) + return rec; + } + + return NULL; +} + +WINDOW_REC *window_find_name(const char *name) +{ + GSList *tmp; + + g_return_val_if_fail(name != NULL, NULL); + + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + WINDOW_REC *rec = tmp->data; + + if (rec->name != NULL && g_strcasecmp(rec->name, name) == 0) + return rec; + } + + return NULL; +} + +WINDOW_REC *window_find_item(WINDOW_REC *window, const char *name) +{ + WINDOW_REC *rec; + WI_ITEM_REC *item; + + g_return_val_if_fail(name != NULL, NULL); + + rec = window_find_name(name); + if (rec != NULL) return rec; + + item = window == NULL ? NULL : + window_item_find(window->active_server, name); + if (item == NULL && window->active_server != NULL) { + /* not found from the active server - any server? */ + item = window_item_find(NULL, name); + } + + if (item == NULL) { + char *chan; + + /* still nothing? maybe user just left the # in front of + channel, try again with it.. */ + chan = g_strdup_printf("#%s", name); + item = window == NULL ? NULL : + window_item_find(window->active_server, chan); + if (item == NULL) item = window_item_find(NULL, chan); + g_free(chan); + } + + if (item == NULL) + return 0; + + return MODULE_DATA(item); +} + +int window_refnum_prev(int refnum, int wrap) +{ + GSList *tmp; + int prev, max; + + max = prev = -1; + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + WINDOW_REC *rec = tmp->data; + + if (rec->refnum < refnum && (prev == -1 || rec->refnum > prev)) + prev = rec->refnum; + if (wrap && (max == -1 || rec->refnum > max)) + max = rec->refnum; + } + + return prev != -1 ? prev : max; +} + +int window_refnum_next(int refnum, int wrap) +{ + GSList *tmp; + int min, next; + + min = next = -1; + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + WINDOW_REC *rec = tmp->data; + + if (rec->refnum > refnum && (next == -1 || rec->refnum < next)) + next = rec->refnum; + if (wrap && (min == -1 || rec->refnum < min)) + min = rec->refnum; + } + + return next != -1 ? next : min; +} + +int windows_refnum_last(void) +{ + GSList *tmp; + int max; + + max = -1; + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + WINDOW_REC *rec = tmp->data; + + if (rec->refnum > max) + max = rec->refnum; + } + + return max; +} + +static void sig_server_looking(SERVER_REC *server) +{ + GSList *tmp; + + g_return_if_fail(server != NULL); + + /* Try to keep some server assigned to windows.. + Also change active window's server if the window is empty */ + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + WINDOW_REC *rec = tmp->data; + + if (rec->active_server == NULL || + (rec == active_win && rec->items == NULL)) + window_change_server(rec, server); + } +} + +static void sig_server_disconnected(SERVER_REC *server) +{ + GSList *tmp; + SERVER_REC *new_server; + + g_return_if_fail(server != NULL); + + new_server = servers == NULL ? NULL : servers->data; + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + WINDOW_REC *rec = tmp->data; + + if (rec->active_server == server) + window_change_server(rec, new_server); + } +} + +static void sig_print_text(void) +{ + GSList *tmp; + char month[10]; + time_t t; + struct tm *tm; + + t = time(NULL); + tm = localtime(&t); + strftime(month, sizeof(month)-1, "%b", tm); + + if (tm->tm_hour != 0 || tm->tm_min != 0) + return; + + daycheck = 2; + signal_remove("print text", (SIGNAL_FUNC) sig_print_text); + + /* day changed, print notice about it to every window */ + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + printformat_window(tmp->data, MSGLEVEL_NEVER, IRCTXT_DAYCHANGE, + tm->tm_mday, tm->tm_mon+1, + 1900+tm->tm_year, month); + } +} + +static int sig_check_daychange(void) +{ + time_t t; + struct tm *tm; + + t = time(NULL); + tm = localtime(&t); + + if (daycheck == 1 && tm->tm_hour == 0 && tm->tm_min == 0) { + sig_print_text(); + return TRUE; + } + + if (tm->tm_hour != 23 || tm->tm_min != 59) { + daycheck = 0; + return TRUE; + } + + /* time is 23:59 */ + if (daycheck == 0) { + daycheck = 1; + signal_add("print text", (SIGNAL_FUNC) sig_print_text); + } + return TRUE; +} + +static void read_settings(void) +{ + if (daytag != -1) { + g_source_remove(daytag); + daytag = -1; + } + + if (settings_get_bool("timestamps")) + daytag = g_timeout_add(30000, (GSourceFunc) sig_check_daychange, NULL); +} + +void windows_init(void) +{ + active_win = NULL; + daycheck = 0; daytag = -1; + settings_add_bool("lookandfeel", "window_auto_change", FALSE); + + read_settings(); + signal_add("server looking", (SIGNAL_FUNC) sig_server_looking); + signal_add("server disconnected", (SIGNAL_FUNC) sig_server_disconnected); + signal_add("server connect failed", (SIGNAL_FUNC) sig_server_disconnected); + signal_add("setup changed", (SIGNAL_FUNC) read_settings); +} + +void windows_deinit(void) +{ + if (daytag != -1) g_source_remove(daytag); + if (daycheck == 1) signal_remove("print text", (SIGNAL_FUNC) sig_print_text); + + signal_remove("server looking", (SIGNAL_FUNC) sig_server_looking); + signal_remove("server disconnected", (SIGNAL_FUNC) sig_server_disconnected); + signal_remove("server connect failed", (SIGNAL_FUNC) sig_server_disconnected); + signal_remove("setup changed", (SIGNAL_FUNC) read_settings); +} diff --git a/src/fe-common/core/fe-windows.h b/src/fe-common/core/fe-windows.h new file mode 100644 index 00000000..16fff673 --- /dev/null +++ b/src/fe-common/core/fe-windows.h @@ -0,0 +1,74 @@ +#ifndef __WINDOWS_H +#define __WINDOWS_H + +#include "servers.h" + +#define STRUCT_SERVER_REC SERVER_REC +#include "window-item-def.h" + +enum { + NEWDATA_TEXT = 1, + NEWDATA_MSG, + NEWDATA_HILIGHT, + NEWDATA_CUSTOM +}; + +typedef struct { + int refnum; + char *name; + + GSList *items; + WI_ITEM_REC *active; + SERVER_REC *active_server; + + GSList *waiting_channels; /* list of " " */ + + int lines; + int destroying:1; + + /* window-specific command line history */ + GList *cmdhist, *histpos; + int histlines; + + int level; + int new_data; + int last_color; + time_t last_timestamp; /* When was last timestamp printed */ + time_t last_line; /* When was last line printed */ + + char *theme_name; /* active theme in window, NULL = default */ + void *theme; /* THEME_REC */ + + void *gui_data; +} WINDOW_REC; + +extern GSList *windows; +extern WINDOW_REC *active_win; + +WINDOW_REC *window_create(WI_ITEM_REC *item, int automatic); +void window_destroy(WINDOW_REC *window); + +void window_set_active(WINDOW_REC *window); +void window_change_server(WINDOW_REC *window, void *server); + +void window_set_refnum(WINDOW_REC *window, int refnum); +void window_set_name(WINDOW_REC *window, const char *name); +void window_set_level(WINDOW_REC *window, int level); + +/* return active item's name, or if none is active, window's name */ +char *window_get_active_name(WINDOW_REC *window); + +WINDOW_REC *window_find_level(void *server, int level); +WINDOW_REC *window_find_closest(void *server, const char *name, int level); +WINDOW_REC *window_find_refnum(int refnum); +WINDOW_REC *window_find_name(const char *name); +WINDOW_REC *window_find_item(WINDOW_REC *window, const char *name); + +int window_refnum_prev(int refnum, int wrap); +int window_refnum_next(int refnum, int wrap); +int windows_refnum_last(void); + +void windows_init(void); +void windows_deinit(void); + +#endif diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c index 4b0df726..e6cedd1b 100644 --- a/src/fe-common/core/formats.c +++ b/src/fe-common/core/formats.c @@ -26,7 +26,7 @@ #include "levels.h" -#include "windows.h" +#include "fe-windows.h" #include "formats.h" #include "themes.h" #include "translation.h" diff --git a/src/fe-common/core/formats.h b/src/fe-common/core/formats.h index 5819353e..6a042156 100644 --- a/src/fe-common/core/formats.h +++ b/src/fe-common/core/formats.h @@ -2,7 +2,7 @@ #define __FORMATS_H #include "themes.h" -#include "windows.h" +#include "fe-windows.h" #define PRINTFLAG_BOLD 0x01 #define PRINTFLAG_REVERSE 0x02 diff --git a/src/fe-common/core/keyboard.c b/src/fe-common/core/keyboard.c index a21c11c1..5c47edb9 100644 --- a/src/fe-common/core/keyboard.c +++ b/src/fe-common/core/keyboard.c @@ -28,7 +28,7 @@ #include "settings.h" #include "keyboard.h" -#include "windows.h" +#include "fe-windows.h" #include "printtext.h" GSList *keyinfos; diff --git a/src/fe-common/core/printtext.c b/src/fe-common/core/printtext.c index 6019ba88..fe05298c 100644 --- a/src/fe-common/core/printtext.c +++ b/src/fe-common/core/printtext.c @@ -29,7 +29,7 @@ #include "servers.h" #include "themes.h" -#include "windows.h" +#include "fe-windows.h" #include "printtext.h" static int beep_msg_level, beep_when_away; diff --git a/src/fe-common/core/printtext.h b/src/fe-common/core/printtext.h index cc2ad2fb..d9e3ce79 100644 --- a/src/fe-common/core/printtext.h +++ b/src/fe-common/core/printtext.h @@ -1,7 +1,7 @@ #ifndef __PRINTTEXT_H #define __PRINTTEXT_H -#include "windows.h" +#include "fe-windows.h" void printformat_module(const char *module, void *server, const char *target, int level, int formatnum, ...); void printformat_module_window(const char *module, WINDOW_REC *window, int level, int formatnum, ...); diff --git a/src/fe-common/core/window-activity.c b/src/fe-common/core/window-activity.c index 96237e6a..7c90ec52 100644 --- a/src/fe-common/core/window-activity.c +++ b/src/fe-common/core/window-activity.c @@ -25,7 +25,7 @@ #include "misc.h" #include "settings.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" #include "nicklist.h" #include "hilight-text.h" diff --git a/src/fe-common/core/window-commands.c b/src/fe-common/core/window-commands.c index b9ef8450..217f5166 100644 --- a/src/fe-common/core/window-commands.c +++ b/src/fe-common/core/window-commands.c @@ -28,7 +28,7 @@ #include "levels.h" #include "themes.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" #include "window-save.h" #include "printtext.h" diff --git a/src/fe-common/core/window-items.c b/src/fe-common/core/window-items.c index f94bcc8c..8e36931d 100644 --- a/src/fe-common/core/window-items.c +++ b/src/fe-common/core/window-items.c @@ -27,7 +27,7 @@ #include "levels.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" #include "printtext.h" diff --git a/src/fe-common/core/window-items.h b/src/fe-common/core/window-items.h index 8e22c449..0ed052ea 100644 --- a/src/fe-common/core/window-items.h +++ b/src/fe-common/core/window-items.h @@ -1,7 +1,7 @@ #ifndef __WINDOW_ITEMS_H #define __WINDOW_ITEMS_H -#include "windows.h" +#include "fe-windows.h" /* Add/remove window item from `window' */ void window_add_item(WINDOW_REC *window, WI_ITEM_REC *item, int automatic); diff --git a/src/fe-common/core/window-save.c b/src/fe-common/core/window-save.c index 61d2bb5e..d9540c89 100644 --- a/src/fe-common/core/window-save.c +++ b/src/fe-common/core/window-save.c @@ -30,7 +30,7 @@ #include "queries.h" #include "themes.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" static void sig_window_restore_item(WINDOW_REC *window, const char *type, diff --git a/src/fe-common/core/windows.c b/src/fe-common/core/windows.c deleted file mode 100644 index 88127452..00000000 --- a/src/fe-common/core/windows.c +++ /dev/null @@ -1,483 +0,0 @@ -/* - windows.c : irssi - - Copyright (C) 1999-2000 Timo Sirainen - - This program 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 2 of the License, or - (at your option) any later version. - - This program 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 this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#include "module.h" -#include "module-formats.h" -#include "modules.h" -#include "signals.h" -#include "commands.h" -#include "servers.h" -#include "misc.h" -#include "settings.h" - -#include "levels.h" - -#include "printtext.h" -#include "windows.h" -#include "window-items.h" - -GSList *windows; /* first in the list is the active window, - next is the last active, etc. */ -WINDOW_REC *active_win; - -static int daytag; -static int daycheck; /* 0 = don't check, 1 = time is 00:00, check, - 2 = time is 00:00, already checked */ - -static int window_get_new_refnum(void) -{ - WINDOW_REC *win; - GSList *tmp; - int refnum; - - refnum = 1; - tmp = windows; - while (tmp != NULL) { - win = tmp->data; - - if (refnum != win->refnum) { - tmp = tmp->next; - continue; - } - - refnum++; - tmp = windows; - } - - return refnum; -} - -WINDOW_REC *window_create(WI_ITEM_REC *item, int automatic) -{ - WINDOW_REC *rec; - - rec = g_new0(WINDOW_REC, 1); - rec->refnum = window_get_new_refnum(); - - windows = g_slist_prepend(windows, rec); - signal_emit("window created", 2, rec, GINT_TO_POINTER(automatic)); - - if (item != NULL) window_add_item(rec, item, automatic); - if (windows->next == NULL || !automatic || settings_get_bool("window_auto_change")) { - if (automatic && windows->next != NULL) - signal_emit("window changed automatic", 1, rec); - window_set_active(rec); - } - return rec; -} - -/* removed_refnum was removed from the windows list, pack the windows so - there won't be any holes. If there is any holes after removed_refnum, - leave the windows behind it alone. */ -static void windows_pack(int removed_refnum) -{ - WINDOW_REC *window; - int refnum; - - for (refnum = removed_refnum+1;; refnum++) { - window = window_find_refnum(refnum); - if (window == NULL) break; - - window_set_refnum(window, refnum-1); - } -} - -void window_destroy(WINDOW_REC *window) -{ - g_return_if_fail(window != NULL); - - if (window->destroying) return; - window->destroying = TRUE; - windows = g_slist_remove(windows, window); - - if (active_win == window && windows != NULL) { - active_win = NULL; /* it's corrupted */ - window_set_active(windows->data); - } - - while (window->items != NULL) - window_remove_item(window, window->items->data); - - windows_pack(window->refnum); - - signal_emit("window destroyed", 1, window); - - g_slist_foreach(window->waiting_channels, (GFunc) g_free, NULL); - g_slist_free(window->waiting_channels); - - g_free_not_null(window->theme_name); - g_free_not_null(window->name); - g_free(window); -} - -void window_set_active(WINDOW_REC *window) -{ - WINDOW_REC *old_window; - - if (window == active_win) - return; - - old_window = active_win; - active_win = window; - if (active_win != NULL) { - windows = g_slist_remove(windows, active_win); - windows = g_slist_prepend(windows, active_win); - } - - signal_emit("window changed", 2, active_win, old_window); -} - -void window_change_server(WINDOW_REC *window, void *server) -{ - window->active_server = server; - signal_emit("window server changed", 2, window, server); -} - -void window_set_refnum(WINDOW_REC *window, int refnum) -{ - GSList *tmp; - int old_refnum; - - g_return_if_fail(window != NULL); - g_return_if_fail(refnum >= 1); - if (window->refnum == refnum) return; - - for (tmp = windows; tmp != NULL; tmp = tmp->next) { - WINDOW_REC *rec = tmp->data; - - if (rec->refnum == refnum) { - rec->refnum = window->refnum; - signal_emit("window refnum changed", 2, rec, GINT_TO_POINTER(refnum)); - break; - } - } - - old_refnum = window->refnum; - window->refnum = refnum; - signal_emit("window refnum changed", 2, window, GINT_TO_POINTER(old_refnum)); -} - -void window_set_name(WINDOW_REC *window, const char *name) -{ - g_free_not_null(window->name); - window->name = g_strdup(name); - - signal_emit("window name changed", 1, window); -} - -void window_set_level(WINDOW_REC *window, int level) -{ - g_return_if_fail(window != NULL); - - window->level = level; - signal_emit("window level changed", 1, window); -} - -/* return active item's name, or if none is active, window's name */ -char *window_get_active_name(WINDOW_REC *window) -{ - g_return_val_if_fail(window != NULL, NULL); - - if (window->active != NULL) - return window->active->name; - - return window->name; -} - -WINDOW_REC *window_find_level(void *server, int level) -{ - WINDOW_REC *match; - GSList *tmp; - - match = NULL; - for (tmp = windows; tmp != NULL; tmp = tmp->next) { - WINDOW_REC *rec = tmp->data; - - if ((server == NULL || rec->active_server == server) && - (rec->level & level)) { - if (server == NULL || rec->active_server == server) - return rec; - match = rec; - } - } - - return match; -} - -WINDOW_REC *window_find_closest(void *server, const char *name, int level) -{ - WINDOW_REC *window; - WI_ITEM_REC *item; - - /* match by name */ - item = name == NULL ? NULL : - window_item_find(server, name); - if (item != NULL) - return window_item_window(item); - - /* match by level */ - if (level != MSGLEVEL_HILIGHT) - level &= ~(MSGLEVEL_HILIGHT | MSGLEVEL_NOHILIGHT); - window = window_find_level(server, level); - if (window != NULL) return window; - - /* match by level - ignore server */ - window = window_find_level(NULL, level); - if (window != NULL) return window; - - /* fallback to active */ - return active_win; -} - -WINDOW_REC *window_find_refnum(int refnum) -{ - GSList *tmp; - - for (tmp = windows; tmp != NULL; tmp = tmp->next) { - WINDOW_REC *rec = tmp->data; - - if (rec->refnum == refnum) - return rec; - } - - return NULL; -} - -WINDOW_REC *window_find_name(const char *name) -{ - GSList *tmp; - - g_return_val_if_fail(name != NULL, NULL); - - for (tmp = windows; tmp != NULL; tmp = tmp->next) { - WINDOW_REC *rec = tmp->data; - - if (rec->name != NULL && g_strcasecmp(rec->name, name) == 0) - return rec; - } - - return NULL; -} - -WINDOW_REC *window_find_item(WINDOW_REC *window, const char *name) -{ - WINDOW_REC *rec; - WI_ITEM_REC *item; - - g_return_val_if_fail(name != NULL, NULL); - - rec = window_find_name(name); - if (rec != NULL) return rec; - - item = window == NULL ? NULL : - window_item_find(window->active_server, name); - if (item == NULL && window->active_server != NULL) { - /* not found from the active server - any server? */ - item = window_item_find(NULL, name); - } - - if (item == NULL) { - char *chan; - - /* still nothing? maybe user just left the # in front of - channel, try again with it.. */ - chan = g_strdup_printf("#%s", name); - item = window == NULL ? NULL : - window_item_find(window->active_server, chan); - if (item == NULL) item = window_item_find(NULL, chan); - g_free(chan); - } - - if (item == NULL) - return 0; - - return MODULE_DATA(item); -} - -int window_refnum_prev(int refnum, int wrap) -{ - GSList *tmp; - int prev, max; - - max = prev = -1; - for (tmp = windows; tmp != NULL; tmp = tmp->next) { - WINDOW_REC *rec = tmp->data; - - if (rec->refnum < refnum && (prev == -1 || rec->refnum > prev)) - prev = rec->refnum; - if (wrap && (max == -1 || rec->refnum > max)) - max = rec->refnum; - } - - return prev != -1 ? prev : max; -} - -int window_refnum_next(int refnum, int wrap) -{ - GSList *tmp; - int min, next; - - min = next = -1; - for (tmp = windows; tmp != NULL; tmp = tmp->next) { - WINDOW_REC *rec = tmp->data; - - if (rec->refnum > refnum && (next == -1 || rec->refnum < next)) - next = rec->refnum; - if (wrap && (min == -1 || rec->refnum < min)) - min = rec->refnum; - } - - return next != -1 ? next : min; -} - -int windows_refnum_last(void) -{ - GSList *tmp; - int max; - - max = -1; - for (tmp = windows; tmp != NULL; tmp = tmp->next) { - WINDOW_REC *rec = tmp->data; - - if (rec->refnum > max) - max = rec->refnum; - } - - return max; -} - -static void sig_server_looking(SERVER_REC *server) -{ - GSList *tmp; - - g_return_if_fail(server != NULL); - - /* Try to keep some server assigned to windows.. - Also change active window's server if the window is empty */ - for (tmp = windows; tmp != NULL; tmp = tmp->next) { - WINDOW_REC *rec = tmp->data; - - if (rec->active_server == NULL || - (rec == active_win && rec->items == NULL)) - window_change_server(rec, server); - } -} - -static void sig_server_disconnected(SERVER_REC *server) -{ - GSList *tmp; - SERVER_REC *new_server; - - g_return_if_fail(server != NULL); - - new_server = servers == NULL ? NULL : servers->data; - for (tmp = windows; tmp != NULL; tmp = tmp->next) { - WINDOW_REC *rec = tmp->data; - - if (rec->active_server == server) - window_change_server(rec, new_server); - } -} - -static void sig_print_text(void) -{ - GSList *tmp; - char month[10]; - time_t t; - struct tm *tm; - - t = time(NULL); - tm = localtime(&t); - strftime(month, sizeof(month)-1, "%b", tm); - - if (tm->tm_hour != 0 || tm->tm_min != 0) - return; - - daycheck = 2; - signal_remove("print text", (SIGNAL_FUNC) sig_print_text); - - /* day changed, print notice about it to every window */ - for (tmp = windows; tmp != NULL; tmp = tmp->next) { - printformat_window(tmp->data, MSGLEVEL_NEVER, IRCTXT_DAYCHANGE, - tm->tm_mday, tm->tm_mon+1, - 1900+tm->tm_year, month); - } -} - -static int sig_check_daychange(void) -{ - time_t t; - struct tm *tm; - - t = time(NULL); - tm = localtime(&t); - - if (daycheck == 1 && tm->tm_hour == 0 && tm->tm_min == 0) { - sig_print_text(); - return TRUE; - } - - if (tm->tm_hour != 23 || tm->tm_min != 59) { - daycheck = 0; - return TRUE; - } - - /* time is 23:59 */ - if (daycheck == 0) { - daycheck = 1; - signal_add("print text", (SIGNAL_FUNC) sig_print_text); - } - return TRUE; -} - -static void read_settings(void) -{ - if (daytag != -1) { - g_source_remove(daytag); - daytag = -1; - } - - if (settings_get_bool("timestamps")) - daytag = g_timeout_add(30000, (GSourceFunc) sig_check_daychange, NULL); -} - -void windows_init(void) -{ - active_win = NULL; - daycheck = 0; daytag = -1; - settings_add_bool("lookandfeel", "window_auto_change", FALSE); - - read_settings(); - signal_add("server looking", (SIGNAL_FUNC) sig_server_looking); - signal_add("server disconnected", (SIGNAL_FUNC) sig_server_disconnected); - signal_add("server connect failed", (SIGNAL_FUNC) sig_server_disconnected); - signal_add("setup changed", (SIGNAL_FUNC) read_settings); -} - -void windows_deinit(void) -{ - if (daytag != -1) g_source_remove(daytag); - if (daycheck == 1) signal_remove("print text", (SIGNAL_FUNC) sig_print_text); - - signal_remove("server looking", (SIGNAL_FUNC) sig_server_looking); - signal_remove("server disconnected", (SIGNAL_FUNC) sig_server_disconnected); - signal_remove("server connect failed", (SIGNAL_FUNC) sig_server_disconnected); - signal_remove("setup changed", (SIGNAL_FUNC) read_settings); -} diff --git a/src/fe-common/core/windows.h b/src/fe-common/core/windows.h deleted file mode 100644 index 16fff673..00000000 --- a/src/fe-common/core/windows.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef __WINDOWS_H -#define __WINDOWS_H - -#include "servers.h" - -#define STRUCT_SERVER_REC SERVER_REC -#include "window-item-def.h" - -enum { - NEWDATA_TEXT = 1, - NEWDATA_MSG, - NEWDATA_HILIGHT, - NEWDATA_CUSTOM -}; - -typedef struct { - int refnum; - char *name; - - GSList *items; - WI_ITEM_REC *active; - SERVER_REC *active_server; - - GSList *waiting_channels; /* list of " " */ - - int lines; - int destroying:1; - - /* window-specific command line history */ - GList *cmdhist, *histpos; - int histlines; - - int level; - int new_data; - int last_color; - time_t last_timestamp; /* When was last timestamp printed */ - time_t last_line; /* When was last line printed */ - - char *theme_name; /* active theme in window, NULL = default */ - void *theme; /* THEME_REC */ - - void *gui_data; -} WINDOW_REC; - -extern GSList *windows; -extern WINDOW_REC *active_win; - -WINDOW_REC *window_create(WI_ITEM_REC *item, int automatic); -void window_destroy(WINDOW_REC *window); - -void window_set_active(WINDOW_REC *window); -void window_change_server(WINDOW_REC *window, void *server); - -void window_set_refnum(WINDOW_REC *window, int refnum); -void window_set_name(WINDOW_REC *window, const char *name); -void window_set_level(WINDOW_REC *window, int level); - -/* return active item's name, or if none is active, window's name */ -char *window_get_active_name(WINDOW_REC *window); - -WINDOW_REC *window_find_level(void *server, int level); -WINDOW_REC *window_find_closest(void *server, const char *name, int level); -WINDOW_REC *window_find_refnum(int refnum); -WINDOW_REC *window_find_name(const char *name); -WINDOW_REC *window_find_item(WINDOW_REC *window, const char *name); - -int window_refnum_prev(int refnum, int wrap); -int window_refnum_next(int refnum, int wrap); -int windows_refnum_last(void); - -void windows_init(void); -void windows_deinit(void); - -#endif diff --git a/src/fe-common/irc/dcc/fe-dcc.c b/src/fe-common/irc/dcc/fe-dcc.c index 9a06973d..8f685514 100644 --- a/src/fe-common/irc/dcc/fe-dcc.c +++ b/src/fe-common/irc/dcc/fe-dcc.c @@ -33,7 +33,7 @@ #include "completion.h" #include "themes.h" -#include "windows.h" +#include "fe-windows.h" #include "module-formats.h" #include "printtext.h" diff --git a/src/fe-common/irc/fe-ctcp.c b/src/fe-common/irc/fe-ctcp.c index 02703883..2ed0feb4 100644 --- a/src/fe-common/irc/fe-ctcp.c +++ b/src/fe-common/irc/fe-ctcp.c @@ -30,7 +30,7 @@ #include "queries.h" #include "ignore.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" #include "printtext.h" diff --git a/src/fe-common/irc/fe-events.c b/src/fe-common/irc/fe-events.c index 4e1c70f7..19086b40 100644 --- a/src/fe-common/irc/fe-events.c +++ b/src/fe-common/irc/fe-events.c @@ -35,7 +35,7 @@ #include "fe-queries.h" #include "irc-channels.h" #include "irc-nicklist.h" -#include "windows.h" +#include "fe-windows.h" #include "printtext.h" #include "completion.h" diff --git a/src/fe-common/irc/fe-irc-commands.c b/src/fe-common/irc/fe-irc-commands.c index fe361ef9..c6fae677 100644 --- a/src/fe-common/irc/fe-irc-commands.c +++ b/src/fe-common/irc/fe-irc-commands.c @@ -34,7 +34,7 @@ #include "irc-queries.h" #include "fe-queries.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" #include "printtext.h" diff --git a/src/fe-common/irc/fe-irc-server.c b/src/fe-common/irc/fe-irc-server.c index 635391c4..cef890ff 100644 --- a/src/fe-common/irc/fe-irc-server.c +++ b/src/fe-common/irc/fe-irc-server.c @@ -31,7 +31,7 @@ #include "servers-reconnect.h" #include "irc-servers-setup.h" -#include "windows.h" +#include "fe-windows.h" #include "printtext.h" static void sig_server_add_create(IRC_SERVER_SETUP_REC **rec, diff --git a/src/fe-text/gui-printtext.c b/src/fe-text/gui-printtext.c index f7ca62bd..afc960c0 100644 --- a/src/fe-text/gui-printtext.c +++ b/src/fe-text/gui-printtext.c @@ -23,7 +23,7 @@ #include "commands.h" #include "settings.h" -#include "windows.h" +#include "fe-windows.h" #include "formats.h" #include "printtext.h" #include "themes.h" diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 7f4fd6f2..1e04c16b 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -27,7 +27,7 @@ #include "command-history.h" #include "keyboard.h" #include "translation.h" -#include "windows.h" +#include "fe-windows.h" #include "screen.h" #include "gui-entry.h" diff --git a/src/fe-text/gui-textwidget.c b/src/fe-text/gui-textwidget.c index c691f63b..67f35882 100644 --- a/src/fe-text/gui-textwidget.c +++ b/src/fe-text/gui-textwidget.c @@ -27,7 +27,7 @@ #include "settings.h" #include "irc-servers.h" -#include "windows.h" +#include "fe-windows.h" #include "printtext.h" #include "screen.h" diff --git a/src/fe-text/gui-windows.c b/src/fe-text/gui-windows.c index fefb9ae7..f17dec81 100644 --- a/src/fe-text/gui-windows.c +++ b/src/fe-text/gui-windows.c @@ -27,7 +27,7 @@ #include "irc.h" #include "channels.h" -#include "windows.h" +#include "fe-windows.h" #include "screen.h" #include "gui-entry.h" diff --git a/src/fe-text/mainwindow-activity.c b/src/fe-text/mainwindow-activity.c index 537bb6dd..e0a7d6ae 100644 --- a/src/fe-text/mainwindow-activity.c +++ b/src/fe-text/mainwindow-activity.c @@ -21,7 +21,7 @@ #include "module.h" #include "signals.h" -#include "windows.h" +#include "fe-windows.h" #include "gui-windows.h" static void sig_activity(WINDOW_REC *window) diff --git a/src/fe-text/mainwindows.h b/src/fe-text/mainwindows.h index f23aa8b7..fd56bd2b 100644 --- a/src/fe-text/mainwindows.h +++ b/src/fe-text/mainwindows.h @@ -1,7 +1,7 @@ #ifndef __MAINWINDOWS_H #define __MAINWINDOWS_H -#include "windows.h" +#include "fe-windows.h" #include "screen.h" typedef struct { diff --git a/src/fe-text/statusbar-items.c b/src/fe-text/statusbar-items.c index 0d316880..78a3b5f6 100644 --- a/src/fe-text/statusbar-items.c +++ b/src/fe-text/statusbar-items.c @@ -30,7 +30,7 @@ #include "irc-servers.h" #include "nicklist.h" -#include "windows.h" +#include "fe-windows.h" #include "window-items.h" #include "printtext.h" #include "formats.h" diff --git a/src/fe-text/statusbar.c b/src/fe-text/statusbar.c index 53501067..30f18efe 100644 --- a/src/fe-text/statusbar.c +++ b/src/fe-text/statusbar.c @@ -23,7 +23,7 @@ #include "servers.h" #include "settings.h" -#include "windows.h" +#include "fe-windows.h" #include "screen.h" #include "statusbar.h" -- cgit v1.2.3