summaryrefslogtreecommitdiff
path: root/src/fe-text/irssi.c
blob: 55bed47238e8489143c7e50f92ba963e5817d2ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 irssi.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 "args.h"
#include "signals.h"
#include "core.h"

#include "fe-common-core.h"
#include "fe-common-irc.h"
#include "themes.h"

#include "screen.h"
#include "gui-entry.h"
#include "mainwindows.h"
#include "gui-printtext.h"
#include "gui-readline.h"
#include "gui-special-vars.h"
#include "statusbar.h"
#include "gui-textwidget.h"
#include "gui-windows.h"

#include <signal.h>

void irc_init(void);
void irc_deinit(void);

#ifdef HAVE_PERL
void irssi_perl_init(void);
void irssi_perl_deinit(void);
#endif

static GMainLoop *main_loop;
int quitting;

static void sig_exit(void)
{
	g_main_quit(main_loop);
}

/* redraw irssi's screen.. */
void irssi_redraw(void)
{
	clear();
	refresh();

	/* windows */
        mainwindows_redraw();
	/* statusbar */
	statusbar_redraw(NULL);
	/* entry line */
	gui_entry_redraw();
}

static void textui_init(void)
{
	static struct poptOption options[] = {
		POPT_AUTOHELP
		{ NULL, '\0', 0, NULL }
	};

	args_register(options);

	irssi_gui = IRSSI_GUI_TEXT;
	core_init();
	irc_init();
	fe_common_core_init();
	fe_common_irc_init();

        theme_register(gui_text_formats);
	signal_add("gui exit", (SIGNAL_FUNC) sig_exit);
}

static void textui_finish_init(void)
{
	quitting = FALSE;

	screen_refresh_freeze();
	gui_entry_init();
	gui_printtext_init();
	gui_readline_init();
	gui_special_vars_init();
	gui_textwidget_init();
	mainwindows_init();
	gui_windows_init();
	statusbar_init();

	fe_common_core_finish_init();
	fe_common_irc_finish_init();

	signal_emit("irssi init finished", 0);
#ifdef HAVE_PERL
	irssi_perl_init();
#endif
	screen_refresh_thaw();
}

static void textui_deinit(void)
{
	quitting = TRUE;
	signal(SIGINT, SIG_DFL);

	signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
#ifdef HAVE_PERL
	irssi_perl_deinit();
#endif
	gui_textwidget_deinit();
	gui_special_vars_deinit();
	statusbar_deinit();
	gui_printtext_deinit();
	gui_readline_deinit();
	gui_windows_deinit();
	mainwindows_deinit();
	gui_entry_deinit();
	deinit_screen();

	theme_unregister();

	fe_common_irc_deinit();
	fe_common_core_deinit();
	irc_deinit();
	core_deinit();
}

int main(int argc, char **argv)
{
#ifdef HAVE_SOCKS
	SOCKSinit(argv[0]);
#endif

	textui_init();
	args_execute(argc, argv);

	if (!init_screen())
		g_error(_("Can't initialize screen handling, quitting.\n"));

	textui_finish_init();
	main_loop = g_main_new(TRUE);
	g_main_run(main_loop);
	g_main_destroy(main_loop);
	textui_deinit();

#ifdef MEM_DEBUG
	ig_mem_profile();
#endif

	return 0;
}