4 Copyright (C) 1999-2000 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "module-formats.h"
23 #include "modules-load.h"
31 #include "printtext.h"
32 #include "fe-common-core.h"
33 #include "fe-common-silc.h"
37 #include "gui-entry.h"
38 #include "mainwindows.h"
39 #include "gui-printtext.h"
40 #include "gui-readline.h"
41 #include "statusbar.h"
42 #include "gui-windows.h"
43 #include "textbuffer-reformat.h"
47 #ifdef HAVE_STATIC_PERL
48 void perl_core_init(void);
49 void perl_core_deinit(void);
51 void fe_perl_init(void);
52 void fe_perl_deinit(void);
56 void silc_deinit(void);
58 void gui_expandos_init(void);
59 void gui_expandos_deinit(void);
61 void textbuffer_commands_init(void);
62 void textbuffer_commands_deinit(void);
64 void lastlog_init(void);
65 void lastlog_deinit(void);
67 void mainwindow_activity_init(void);
68 void mainwindow_activity_deinit(void);
70 void mainwindows_layout_init(void);
71 void mainwindows_layout_deinit(void);
73 void term_dummy_init(void);
74 void term_dummy_deinit(void);
76 static int dirty, full_redraw, dummy;
78 static GMainLoop *main_loop;
81 static const char *firsttimer_text =
82 "Looks like this is the first time you run irssi.\n"
83 "This is just a reminder that you really should go read\n"
84 "startup-HOWTO if you haven't already. Irssi's default\n"
85 "settings aren't probably what you've used to, and you\n"
86 "shouldn't judge the whole client as crap based on them.\n\n"
87 "You can find startup-HOWTO and more irssi beginner info at\n"
88 "http://irssi.org/beginner/";
89 static int display_firsttimer = FALSE;
92 static void sig_exit(void)
97 /* redraw irssi's screen.. */
98 void irssi_redraw(void)
104 void irssi_set_dirty(void)
109 static void dirty_check(void)
119 /* first clear the screen so curses will be
120 forced to redraw the screen */
124 mainwindows_redraw();
125 statusbar_redraw(NULL, TRUE);
128 mainwindows_redraw_dirty();
129 statusbar_redraw_dirty();
135 static void textui_init(void)
138 struct sigaction act;
140 sigemptyset(&act.sa_mask);
142 act.sa_handler = SIG_IGN;
143 sigaction(SIGTRAP, &act, NULL);
146 irssi_gui = IRSSI_GUI_TEXT;
149 fe_common_core_init();
150 fe_common_silc_init();
152 theme_register(gui_text_formats);
153 signal_add_last("gui exit", (SIGNAL_FUNC) sig_exit);
156 static void textui_finish_init(void)
163 term_refresh_freeze();
165 textbuffer_view_init();
166 textbuffer_commands_init();
167 textbuffer_reformat_init();
169 gui_printtext_init();
173 mainwindow_activity_init();
174 mainwindows_layout_init();
181 module_register("core", "fe-text");
183 #ifdef HAVE_STATIC_PERL
190 fe_common_core_finish_init();
191 signal_emit("irssi init finished", 0);
194 if (display_firsttimer) {
195 printtext_window(active_win, MSGLEVEL_CLIENTNOTICE,
196 "%s", firsttimer_text);
201 static void textui_deinit(void)
203 signal(SIGINT, SIG_DFL);
205 term_refresh_freeze();
206 while (modules != NULL)
207 module_unload(modules->data);
209 #ifdef HAVE_STATIC_PERL
214 dirty_check(); /* one last time to print any quit messages */
215 signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
222 gui_printtext_deinit();
223 gui_readline_deinit();
224 gui_windows_deinit();
225 mainwindows_layout_deinit();
226 mainwindow_activity_deinit();
227 mainwindows_deinit();
228 gui_expandos_deinit();
229 textbuffer_reformat_deinit();
230 textbuffer_commands_deinit();
231 textbuffer_view_deinit();
240 fe_common_silc_deinit();
241 fe_common_core_deinit();
246 static void check_oldcrap(void)
249 char *path, str[256];
252 /* check that default.theme is up-to-date */
253 path = g_strdup_printf("%s/default.theme", get_irssi_dir());
254 f = fopen(path, "r+");
260 while (!found && fgets(str, sizeof(str), f) != NULL)
261 found = strstr(str, "abstracts = ") != NULL;
269 printf("\nYou seem to have old default.theme in "IRSSI_DIR_SHORT"/ directory.\n");
270 printf("Themeing system has changed a bit since last irssi release,\n");
271 printf("you should either delete your old default.theme or manually\n");
272 printf("merge it with the new default.theme.\n\n");
273 printf("Do you want to delete the old theme now? (Y/n)\n");
276 fgets(str, sizeof(str), stdin);
277 if (i_toupper(str[0]) == 'Y' || str[0] == '\n' || str[0] == '\0')
282 static void check_files(void)
286 if (stat(get_irssi_dir(), &statbuf) != 0) {
287 /* ~/.irssi doesn't exist, first time running irssi */
288 display_firsttimer = TRUE;
295 static void winsock_init(void)
297 WORD wVersionRequested;
300 wVersionRequested = MAKEWORD(2, 2);
302 if (WSAStartup(wVersionRequested, &wsaData) != 0) {
303 printf("Error initializing winsock\n");
309 int main(int argc, char **argv)
311 static struct poptOption options[] = {
312 { "dummy", 'd', POPT_ARG_NONE, &dummy, 0, "Use the dummy terminal mode", NULL },
313 { NULL, '\0', 0, NULL }
318 core_init_paths(argc, argv);
329 /* initialize the i18n stuff */
330 bindtextdomain(PACKAGE, LOCALEDIR);
335 args_register(options);
336 args_execute(argc, argv);
342 if (!dummy && !term_init()) {
343 fprintf(stderr, "Can't initialize screen handling, quitting.\n");
344 fprintf(stderr, "You can still use the dummy mode with -d parameter\n");
348 textui_finish_init();
349 main_loop = g_main_new(TRUE);
351 /* Does the same as g_main_run(main_loop), except we
352 can call our dirty-checker after each iteration */
354 g_main_iteration(TRUE);
358 g_main_destroy(main_loop);
361 session_upgrade(); /* if we /UPGRADEd, start the new process */