2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
fe-common-core.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
|
|
|
|
*/
|
2000-07-02 18:04:00 -04:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "module.h"
|
2000-05-15 04:25:45 -04:00
|
|
|
#include "module-formats.h"
|
2001-02-18 21:50:08 -05:00
|
|
|
#include "args.h"
|
|
|
|
#include "misc.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "levels.h"
|
|
|
|
#include "settings.h"
|
2001-02-18 21:50:08 -05:00
|
|
|
|
2001-01-01 02:45:54 -05:00
|
|
|
#include "channels.h"
|
2001-02-18 21:50:08 -05:00
|
|
|
#include "servers-setup.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
#include "fe-queries.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "hilight-text.h"
|
|
|
|
#include "command-history.h"
|
2000-06-17 07:53:45 -04:00
|
|
|
#include "completion.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "keyboard.h"
|
|
|
|
#include "printtext.h"
|
2000-11-12 20:52:41 -05:00
|
|
|
#include "formats.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "themes.h"
|
|
|
|
#include "translation.h"
|
2001-01-28 10:46:00 -05:00
|
|
|
#include "fe-channels.h"
|
2000-11-17 11:27:14 -05:00
|
|
|
#include "fe-windows.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "window-items.h"
|
2001-02-21 14:19:24 -05:00
|
|
|
#include "windows-layout.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-11-17 11:55:46 -05:00
|
|
|
#include <signal.h>
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-02-18 21:50:08 -05:00
|
|
|
static char *autocon_server;
|
|
|
|
static char *autocon_password;
|
|
|
|
static int autocon_port;
|
|
|
|
static int no_autoconnect;
|
|
|
|
static char *cmdline_nick;
|
|
|
|
static char *cmdline_hostname;
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
void autorun_init(void);
|
|
|
|
void autorun_deinit(void);
|
|
|
|
|
|
|
|
void fe_core_log_init(void);
|
|
|
|
void fe_core_log_deinit(void);
|
|
|
|
|
2000-12-29 19:42:47 -05:00
|
|
|
void fe_exec_init(void);
|
|
|
|
void fe_exec_deinit(void);
|
|
|
|
|
2000-12-10 00:51:52 -05:00
|
|
|
void fe_expandos_init(void);
|
|
|
|
void fe_expandos_deinit(void);
|
|
|
|
|
2001-02-18 23:44:15 -05:00
|
|
|
void fe_help_init(void);
|
|
|
|
void fe_help_deinit(void);
|
|
|
|
|
2000-10-13 18:26:33 -04:00
|
|
|
void fe_ignore_init(void);
|
|
|
|
void fe_ignore_deinit(void);
|
|
|
|
|
2000-10-14 10:07:31 -04:00
|
|
|
void fe_ignore_messages_init(void);
|
|
|
|
void fe_ignore_messages_deinit(void);
|
|
|
|
|
2000-04-28 04:07:42 -04:00
|
|
|
void fe_log_init(void);
|
|
|
|
void fe_log_deinit(void);
|
|
|
|
|
2000-09-30 18:49:48 -04:00
|
|
|
void fe_messages_init(void);
|
|
|
|
void fe_messages_deinit(void);
|
|
|
|
|
2000-07-02 18:04:00 -04:00
|
|
|
void fe_modules_init(void);
|
|
|
|
void fe_modules_deinit(void);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
void fe_server_init(void);
|
|
|
|
void fe_server_deinit(void);
|
|
|
|
|
|
|
|
void fe_settings_init(void);
|
|
|
|
void fe_settings_deinit(void);
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
void window_activity_init(void);
|
|
|
|
void window_activity_deinit(void);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
void window_commands_init(void);
|
|
|
|
void window_commands_deinit(void);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
void fe_core_commands_init(void);
|
|
|
|
void fe_core_commands_deinit(void);
|
|
|
|
|
2001-01-01 02:45:54 -05:00
|
|
|
static void sig_connected(SERVER_REC *server)
|
|
|
|
{
|
|
|
|
MODULE_DATA_SET(server, g_new0(MODULE_SERVER_REC, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_disconnected(SERVER_REC *server)
|
|
|
|
{
|
|
|
|
g_free(MODULE_DATA(server));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_channel_created(CHANNEL_REC *channel)
|
|
|
|
{
|
|
|
|
MODULE_DATA_SET(channel, g_new0(MODULE_CHANNEL_REC, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_channel_destroyed(CHANNEL_REC *channel)
|
|
|
|
{
|
|
|
|
g_free(MODULE_DATA(channel));
|
|
|
|
}
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
void fe_common_core_init(void)
|
|
|
|
{
|
2001-02-18 21:50:08 -05:00
|
|
|
static struct poptOption options[] = {
|
2001-05-17 16:13:59 -04:00
|
|
|
{ "connect", 'c', POPT_ARG_STRING, &autocon_server, 0, "Automatically connect to server/ircnet", "SERVER" },
|
|
|
|
{ "password", 'w', POPT_ARG_STRING, &autocon_password, 0, "Autoconnect password", "SERVER" },
|
|
|
|
{ "port", 'p', POPT_ARG_INT, &autocon_port, 0, "Autoconnect port", "PORT" },
|
|
|
|
{ "noconnect", '!', POPT_ARG_NONE, &no_autoconnect, 0, "Disable autoconnecting", NULL },
|
|
|
|
{ "nick", 'n', POPT_ARG_STRING, &cmdline_nick, 0, "Specify nick to use", NULL },
|
|
|
|
{ "hostname", 'h', POPT_ARG_STRING, &cmdline_hostname, 0, "Specify host name to use", NULL },
|
2001-02-18 21:50:08 -05:00
|
|
|
{ NULL, '\0', 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
autocon_server = NULL;
|
|
|
|
autocon_password = NULL;
|
|
|
|
autocon_port = 6667;
|
|
|
|
no_autoconnect = FALSE;
|
|
|
|
cmdline_nick = NULL;
|
|
|
|
cmdline_hostname = NULL;
|
|
|
|
args_register(options);
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
settings_add_bool("lookandfeel", "timestamps", TRUE);
|
|
|
|
settings_add_bool("lookandfeel", "msgs_timestamps", FALSE);
|
2001-03-03 13:30:21 -05:00
|
|
|
settings_add_int("lookandfeel", "timestamp_timeout", 0);
|
|
|
|
|
2000-07-30 14:37:49 -04:00
|
|
|
settings_add_bool("lookandfeel", "bell_beeps", FALSE);
|
2001-03-03 13:30:21 -05:00
|
|
|
settings_add_str("lookandfeel", "beep_msg_level", "");
|
|
|
|
settings_add_bool("lookandfeel", "beep_when_window_active", TRUE);
|
2000-07-30 14:37:49 -04:00
|
|
|
settings_add_bool("lookandfeel", "beep_when_away", TRUE);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-03-03 13:30:21 -05:00
|
|
|
settings_add_bool("lookandfeel", "hide_text_style", FALSE);
|
2001-05-10 15:54:48 -04:00
|
|
|
settings_add_bool("lookandfeel", "hide_server_tags", FALSE);
|
2001-03-03 13:30:21 -05:00
|
|
|
|
2000-07-16 11:55:36 -04:00
|
|
|
settings_add_bool("lookandfeel", "use_status_window", TRUE);
|
2000-06-10 14:12:28 -04:00
|
|
|
settings_add_bool("lookandfeel", "use_msgs_window", FALSE);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
themes_init();
|
|
|
|
theme_register(fecommon_core_formats);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
autorun_init();
|
|
|
|
command_history_init();
|
2000-06-17 07:53:45 -04:00
|
|
|
completion_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
keyboard_init();
|
|
|
|
printtext_init();
|
2000-11-12 20:52:41 -05:00
|
|
|
formats_init();
|
2001-01-11 05:15:34 -05:00
|
|
|
#ifndef WIN32
|
2000-12-29 19:42:47 -05:00
|
|
|
fe_exec_init();
|
2001-01-11 05:15:34 -05:00
|
|
|
#endif
|
2000-12-10 00:51:52 -05:00
|
|
|
fe_expandos_init();
|
2001-02-18 23:44:15 -05:00
|
|
|
fe_help_init();
|
2000-10-13 18:26:33 -04:00
|
|
|
fe_ignore_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
fe_log_init();
|
2000-07-02 18:04:00 -04:00
|
|
|
fe_modules_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
fe_server_init();
|
|
|
|
fe_settings_init();
|
|
|
|
translation_init();
|
|
|
|
windows_init();
|
2000-05-15 04:25:45 -04:00
|
|
|
window_activity_init();
|
|
|
|
window_commands_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
window_items_init();
|
2001-02-21 14:19:24 -05:00
|
|
|
windows_layout_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
fe_core_commands_init();
|
2000-10-14 10:07:31 -04:00
|
|
|
|
2000-12-01 23:43:30 -05:00
|
|
|
fe_channels_init();
|
|
|
|
fe_queries_init();
|
|
|
|
|
2000-10-15 14:04:06 -04:00
|
|
|
fe_messages_init();
|
2001-03-03 13:40:25 -05:00
|
|
|
hilight_text_init();
|
2000-10-14 10:07:31 -04:00
|
|
|
fe_ignore_messages_init();
|
2000-12-17 00:44:45 -05:00
|
|
|
|
2001-01-01 02:45:54 -05:00
|
|
|
settings_check();
|
|
|
|
|
|
|
|
signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
|
|
|
|
signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected);
|
|
|
|
signal_add_first("channel created", (SIGNAL_FUNC) sig_channel_created);
|
|
|
|
signal_add_last("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void fe_common_core_deinit(void)
|
|
|
|
{
|
|
|
|
autorun_deinit();
|
|
|
|
hilight_text_deinit();
|
|
|
|
command_history_deinit();
|
2000-06-17 07:53:45 -04:00
|
|
|
completion_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
keyboard_deinit();
|
|
|
|
printtext_deinit();
|
2000-11-12 20:52:41 -05:00
|
|
|
formats_deinit();
|
2001-01-11 05:15:34 -05:00
|
|
|
#ifndef WIN32
|
2000-12-29 19:42:47 -05:00
|
|
|
fe_exec_deinit();
|
2001-01-11 05:15:34 -05:00
|
|
|
#endif
|
2000-12-10 00:51:52 -05:00
|
|
|
fe_expandos_deinit();
|
2001-02-18 23:44:15 -05:00
|
|
|
fe_help_deinit();
|
2000-10-13 18:26:33 -04:00
|
|
|
fe_ignore_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
fe_log_deinit();
|
2000-07-02 18:04:00 -04:00
|
|
|
fe_modules_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
fe_server_deinit();
|
|
|
|
fe_settings_deinit();
|
|
|
|
translation_deinit();
|
|
|
|
windows_deinit();
|
2000-05-15 04:25:45 -04:00
|
|
|
window_activity_deinit();
|
|
|
|
window_commands_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
window_items_deinit();
|
2001-02-21 14:19:24 -05:00
|
|
|
windows_layout_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
fe_core_commands_deinit();
|
2000-05-15 04:25:45 -04:00
|
|
|
|
2000-12-01 23:43:30 -05:00
|
|
|
fe_channels_deinit();
|
|
|
|
fe_queries_deinit();
|
|
|
|
|
2000-10-15 14:04:06 -04:00
|
|
|
fe_messages_deinit();
|
2000-10-14 10:07:31 -04:00
|
|
|
fe_ignore_messages_init();
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
theme_unregister();
|
|
|
|
themes_deinit();
|
2001-01-01 02:45:54 -05:00
|
|
|
|
|
|
|
signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
|
|
|
|
signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
|
|
|
|
signal_remove("channel created", (SIGNAL_FUNC) sig_channel_created);
|
|
|
|
signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-09 12:25:21 -05:00
|
|
|
void glog_func(const char *log_domain, GLogLevelFlags log_level,
|
|
|
|
const char *message)
|
|
|
|
{
|
|
|
|
const char *reason;
|
|
|
|
|
|
|
|
switch (log_level) {
|
|
|
|
case G_LOG_LEVEL_WARNING:
|
|
|
|
reason = "warning";
|
|
|
|
break;
|
|
|
|
case G_LOG_LEVEL_CRITICAL:
|
|
|
|
reason = "critical";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
reason = "error";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-02-17 14:44:22 -05:00
|
|
|
if (windows == NULL)
|
|
|
|
fprintf(stderr, "GLib %s: %s", reason, message);
|
|
|
|
else {
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
|
|
|
|
TXT_GLIB_ERROR, reason, message);
|
|
|
|
}
|
2001-01-09 12:25:21 -05:00
|
|
|
}
|
|
|
|
|
2001-02-18 21:50:08 -05:00
|
|
|
static void create_windows(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
|
2001-02-21 14:19:24 -05:00
|
|
|
windows_layout_restore();
|
2000-07-31 21:02:46 -04:00
|
|
|
if (windows != NULL)
|
|
|
|
return;
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
if (settings_get_bool("use_status_window")) {
|
2000-04-26 04:03:38 -04:00
|
|
|
window = window_create(NULL, TRUE);
|
|
|
|
window_set_name(window, "(status)");
|
2000-05-04 06:32:42 -04:00
|
|
|
window_set_level(window, MSGLEVEL_ALL ^
|
|
|
|
(settings_get_bool("use_msgs_window") ?
|
2000-11-27 06:53:07 -05:00
|
|
|
(MSGLEVEL_MSGS|MSGLEVEL_DCCMSGS) : 0));
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
if (settings_get_bool("use_msgs_window")) {
|
2000-04-26 04:03:38 -04:00
|
|
|
window = window_create(NULL, TRUE);
|
|
|
|
window_set_name(window, "(msgs)");
|
2000-11-27 06:53:07 -05:00
|
|
|
window_set_level(window, MSGLEVEL_MSGS|MSGLEVEL_DCCMSGS);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (windows == NULL) {
|
|
|
|
/* we have to have at least one window.. */
|
|
|
|
window = window_create(NULL, TRUE);
|
|
|
|
}
|
|
|
|
}
|
2001-02-18 21:50:08 -05:00
|
|
|
|
|
|
|
static void autoconnect_servers(void)
|
|
|
|
{
|
|
|
|
GSList *tmp, *chatnets;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (autocon_server != NULL) {
|
|
|
|
/* connect to specified server */
|
|
|
|
str = g_strdup_printf(autocon_password == NULL ? "%s %d" : "%s %d %s",
|
|
|
|
autocon_server, autocon_port, autocon_password);
|
|
|
|
signal_emit("command connect", 1, str);
|
|
|
|
g_free(str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (no_autoconnect) {
|
|
|
|
/* don't autoconnect */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* connect to autoconnect servers */
|
|
|
|
chatnets = NULL;
|
|
|
|
for (tmp = setupservers; tmp != NULL; tmp = tmp->next) {
|
|
|
|
SERVER_SETUP_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
if (rec->autoconnect &&
|
|
|
|
(rec->chatnet == NULL ||
|
|
|
|
gslist_find_icase_string(chatnets, rec->chatnet) == NULL)) {
|
|
|
|
if (rec->chatnet != NULL)
|
|
|
|
chatnets = g_slist_append(chatnets, rec->chatnet);
|
|
|
|
|
|
|
|
str = g_strdup_printf("%s %d", rec->address, rec->port);
|
|
|
|
signal_emit("command connect", 1, str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(chatnets);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fe_common_core_finish_init(void)
|
|
|
|
{
|
|
|
|
signal_emit("irssi init read settings", 0);
|
|
|
|
|
|
|
|
#ifdef SIGPIPE
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (cmdline_nick != NULL) {
|
|
|
|
/* override nick found from setup */
|
|
|
|
settings_set_str("nick", cmdline_nick);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmdline_hostname != NULL) {
|
|
|
|
/* override host name found from setup */
|
|
|
|
settings_set_str("hostname", cmdline_hostname);
|
|
|
|
}
|
|
|
|
|
|
|
|
create_windows();
|
2001-02-21 14:19:24 -05:00
|
|
|
|
|
|
|
/* _after_ windows are created.. */
|
|
|
|
g_log_set_handler(G_LOG_DOMAIN,
|
|
|
|
(GLogLevelFlags) (G_LOG_LEVEL_CRITICAL |
|
|
|
|
G_LOG_LEVEL_WARNING),
|
|
|
|
(GLogFunc) glog_func, NULL);
|
|
|
|
|
|
|
|
autoconnect_servers();
|
2001-02-18 21:50:08 -05:00
|
|
|
}
|