2 log-away.c : Awaylog handling
4 Copyright (C) 1999-2001 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
28 static LOG_REC *awaylog;
29 static int away_filepos;
32 static void sig_log_written(LOG_REC *log)
34 if (log != awaylog) return;
39 static void awaylog_open(void)
45 fname = settings_get_str("awaylog_file");
46 level = settings_get_level("awaylog_level");
47 if (*fname == '\0' || level == 0) return;
49 log = log_find(fname);
50 if (log != NULL && log->handle != -1)
51 return; /* already open */
54 log = log_create_rec(fname, level);
59 if (!log_start_logging(log)) {
60 /* creating log file failed? close it. */
66 away_filepos = lseek(log->handle, 0, SEEK_CUR);
70 static void awaylog_close(void)
75 fname = settings_get_str("awaylog_file");
76 if (*fname == '\0') return;
78 log = log_find(fname);
79 if (log == NULL || log->handle == -1) {
80 /* awaylog not open */
84 if (awaylog == log) awaylog = NULL;
86 signal_emit("awaylog show", 3, log, GINT_TO_POINTER(away_msgs),
87 GINT_TO_POINTER(away_filepos));
91 static void sig_away_changed(SERVER_REC *server)
93 if (server->usermode_away)
99 void log_away_init(void)
107 awaylog_file = g_strconcat(get_irssi_dir(), "/away.log", NULL);
108 settings_add_str("log", "awaylog_file", awaylog_file);
109 g_free(awaylog_file);
110 settings_add_level("log", "awaylog_level", "msgs hilight");
112 signal_add("log written", (SIGNAL_FUNC) sig_log_written);
113 signal_add("away mode changed", (SIGNAL_FUNC) sig_away_changed);
116 void log_away_deinit(void)
118 signal_remove("log written", (SIGNAL_FUNC) sig_log_written);
119 signal_remove("away mode changed", (SIGNAL_FUNC) sig_away_changed);