changeset 1575:427e1409917c

[gaim-migrate @ 1585] more stuff committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 15 Mar 2001 15:03:08 +0000
parents 7ad82fa9e6ce
children 992871bf2649
files ChangeLog src/away.c src/buddy.c src/conversation.c src/gaim.h src/idle.c src/multi.c src/prefs.c src/server.c src/util.c
diffstat 10 files changed, 226 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Mar 15 13:44:16 2001 +0000
+++ b/ChangeLog	Thu Mar 15 15:03:08 2001 +0000
@@ -3,9 +3,11 @@
 version 0.11.0-pre7:
 	* Can build RPMs as non-root
 	* New yahoo library (can use HTTP proxy)
-	* Command-line arg to specify config file
+	* Command-line arg to specify config file (thanks Jason Boerner)
 	* Can view all conversations in one tabbed window
 	* Tooltips on links work again
+	* Can log system notices: signons/signoffs, awayness and idleness
+	  (thanks Andrew Echols)
 
 version 0.11.0-pre6 (03/06/2001):
 	* Fixed bug with NAS support
--- a/src/away.c	Thu Mar 15 13:44:16 2001 +0000
+++ b/src/away.c	Thu Mar 15 15:03:08 2001 +0000
@@ -57,6 +57,7 @@
 		GtkWidget *tmp = imaway;
 		imaway = NULL;
 		gtk_widget_destroy(tmp);
+		return;
 	}
 
 	serv_set_away_all(NULL);
--- a/src/buddy.c	Thu Mar 15 13:44:16 2001 +0000
+++ b/src/buddy.c	Thu Mar 15 15:03:08 2001 +0000
@@ -284,6 +284,7 @@
 void signoff(struct gaim_connection *gc)
 {
 	plugin_event(event_signoff, gc, 0, 0, 0);
+	system_log(log_signoff, gc, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON);
 	update_keepalive(gc, FALSE);
 	serv_close(gc);
 	redo_buddy_list();
@@ -1135,6 +1136,7 @@
 		c = c->next;
 	}
 #endif
+	system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON);
 #ifdef USE_PERL
 	perl_end();
 #endif
--- a/src/conversation.c	Thu Mar 15 13:44:16 2001 +0000
+++ b/src/conversation.c	Thu Mar 15 15:03:08 2001 +0000
@@ -1815,9 +1815,6 @@
 	style = gtk_style_new();
 	gdk_font_unref(style->font);
 	style->font = label->style->font;
-	style->fg[0].red = 0x0000;
-	style->fg[0].green = 0x0000;
-	style->fg[0].blue = 0x0000;
 	gtk_widget_set_style(label, style);
 	gtk_style_unref(style);
 }
--- a/src/gaim.h	Thu Mar 15 13:44:16 2001 +0000
+++ b/src/gaim.h	Thu Mar 15 15:03:08 2001 +0000
@@ -192,6 +192,16 @@
 	/* any others? it's easy to add... */
 };
 
+enum log_event {
+	log_signon = 0,
+	log_signoff,
+	log_away,
+	log_back,
+	log_idle,
+	log_unidle,
+	log_quit
+};
+
 #ifdef GAIM_PLUGINS
 #include <gmodule.h>
 
@@ -580,6 +590,7 @@
 extern void strncpy_nohtml(gchar *, const gchar *, size_t);
 extern void strncpy_withhtml(gchar *, const gchar *, size_t);
 extern void away_on_login(char *);
+extern void system_log(enum log_event, struct gaim_connection *, struct buddy *, int);
 
 /* Functions in server.c */
 /* input to serv */
--- a/src/idle.c	Thu Mar 15 13:44:16 2001 +0000
+++ b/src/idle.c	Thu Mar 15 15:03:08 2001 +0000
@@ -110,9 +110,11 @@
 		debug_printf("setting %s idle %d seconds\n", gc->username, idle_time);
 		serv_set_idle(gc, idle_time);
 		gc->is_idle = 1;
+		system_log(log_idle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON);
 	} else if (idle_time < 600 && gc->is_idle) {
 		debug_printf("setting %s unidle\n", gc->username);
 		serv_touch_idle(gc);
+		system_log(log_unidle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON);
 	}
 
 	return TRUE;
--- a/src/multi.c	Thu Mar 15 13:44:16 2001 +0000
+++ b/src/multi.c	Thu Mar 15 15:03:08 2001 +0000
@@ -714,6 +714,7 @@
 	gaim_setup(gc);
 
 	plugin_event(event_signon, gc, 0, 0, 0);
+	system_log(log_signon, gc, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON);
 
 	/* away option given? */
 	if (opt_away) {
--- a/src/prefs.c	Thu Mar 15 13:44:16 2001 +0000
+++ b/src/prefs.c	Thu Mar 15 15:03:08 2001 +0000
@@ -305,10 +305,6 @@
 	gtk_box_pack_start(GTK_BOX(box), sep, FALSE, FALSE, 5);
 	gtk_widget_show(sep);
 
-	label = gtk_label_new(_("Nothing below is implemented yet"));
-	gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5);
-	gtk_widget_show(label);
-
 	gaim_button(_("Log when buddies sign on/sign off"), &logging_options, OPT_LOG_BUDDY_SIGNON, box);
 	gaim_button(_("Log when buddies become idle/un-idle"), &logging_options, OPT_LOG_BUDDY_IDLE, box);
 	gaim_button(_("Log when buddies go away/come back"), &logging_options, OPT_LOG_BUDDY_AWAY, box);
--- a/src/server.c	Thu Mar 15 13:44:16 2001 +0000
+++ b/src/server.c	Thu Mar 15 15:03:08 2001 +0000
@@ -162,6 +162,7 @@
 		(*gc->prpl->set_away)(gc, state, message);
 		plugin_event(event_away, gc, state, message, 0);
 	}
+	system_log(log_away, gc, NULL, OPT_LOG_BUDDY_AWAY | OPT_LOG_MY_SIGNON);
 }
 
 void serv_set_away_all(char *message)
@@ -171,10 +172,7 @@
 
 	while (c) {
 		g = (struct gaim_connection *)c->data;
-		if (g->prpl && g->prpl->set_away) {
-			(*g->prpl->set_away)(g, GAIM_AWAY_CUSTOM, message);
-			plugin_event(event_away, g, GAIM_AWAY_CUSTOM, message, 0);
-		}
+		serv_set_away(g, GAIM_AWAY_CUSTOM, message);
 		c = c->next;
 	}
 }
@@ -467,11 +465,14 @@
 
 	}
 
-	if (!b->idle && idle)
+	if (!b->idle && idle) {
 		plugin_event(event_buddy_idle, gc, b->name, 0, 0);
+		system_log(log_idle, gc, b, OPT_LOG_BUDDY_IDLE);
+	}
 	if (b->idle && !idle) {
 		do_pounce(b->name, OPT_POUNCE_UNIDLE);
 		plugin_event(event_buddy_unidle, gc, b->name, 0, 0);
+		system_log(log_unidle, gc, b, OPT_LOG_BUDDY_IDLE);
 	}
 
 	b->idle = idle;
@@ -480,8 +481,10 @@
 	if ((b->uc & UC_UNAVAILABLE) && !(type & UC_UNAVAILABLE)) {
 		do_pounce(b->name, OPT_POUNCE_UNAWAY);
 		plugin_event(event_buddy_back, gc, b->name, 0, 0);
+		system_log(log_back, gc, b, OPT_LOG_BUDDY_AWAY);
 	} else if (!(b->uc & UC_UNAVAILABLE) && (type & UC_UNAVAILABLE)) {
 		plugin_event(event_buddy_away, gc, b->name, 0, 0);
+		system_log(log_away, gc, b, OPT_LOG_BUDDY_AWAY);
 	}
 
 	b->uc = type;
@@ -495,10 +498,13 @@
 			b->present = 1;
 			do_pounce(b->name, OPT_POUNCE_SIGNON);
 			plugin_event(event_buddy_signon, gc, b->name, 0, 0);
+			system_log(log_signon, gc, b, OPT_LOG_BUDDY_SIGNON);
 		}
 	} else {
-		if (b->present)
+		if (b->present) {
 			plugin_event(event_buddy_signoff, gc, b->name, 0, 0);
+			system_log(log_signoff, gc, b, OPT_LOG_BUDDY_SIGNON);
+		}
 		b->present = 0;
 	}
 
--- a/src/util.c	Thu Mar 15 13:44:16 2001 +0000
+++ b/src/util.c	Thu Mar 15 15:03:08 2001 +0000
@@ -36,6 +36,7 @@
 #include <math.h>
 #include <pixmaps/aimicon.xpm>
 #include "gaim.h"
+#include "prpl.h"
 
 static GdkPixmap *icon_pm = NULL;
 static GdkBitmap *icon_bm = NULL;
@@ -335,38 +336,16 @@
 }
 
 
-FILE *open_log_file(char *name)
+FILE *open_gaim_log_file(char *name, int *flag)
 {
 	char *buf;
 	char *buf2;
 	char log_all_file[256];
-	struct log_conversation *l;
 	struct stat st;
-	int flag = 0;
 	FILE *fd;
 	int res;
 	gchar *gaim_dir;
 
-	if (!(logging_options & OPT_LOG_ALL)) {
-
-		l = find_log_info(name);
-		if (!l)
-			return NULL;
-
-		if (stat(l->filename, &st) < 0)
-			flag = 1;
-
-		fd = fopen(l->filename, "a");
-
-		if (flag) {	/* is a new file */
-			fprintf(fd, "<HTML><HEAD><TITLE>");
-			fprintf(fd, "IM Sessions with %s", name);
-			fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n");
-		}
-
-		return fd;
-	}
-
 	buf = g_malloc(BUF_LONG);
 	buf2 = g_malloc(BUF_LONG);
 	gaim_dir = gaim_user_dir();
@@ -388,6 +367,7 @@
 			do_error_dialog(buf, "Error!");
 			g_free(buf);
 			g_free(buf2);
+			g_free(gaim_dir);
 			return NULL;
 		}
 	} else
@@ -396,7 +376,7 @@
 	g_snprintf(log_all_file, 256, "%s/logs", gaim_dir);
 
 	if (stat(log_all_file, &st) < 0)
-		flag = 1;
+		*flag = 1;
 	if (!S_ISDIR(st.st_mode))
 		unlink(log_all_file);
 
@@ -409,6 +389,7 @@
 			do_error_dialog(buf, "Error!");
 			g_free(buf);
 			g_free(buf2);
+			g_free(gaim_dir);
 			return NULL;
 		}
 	} else
@@ -416,26 +397,69 @@
 
 
 
-	g_snprintf(log_all_file, 256, "%s/logs/%s.log", gaim_dir, normalize(name));
+	g_snprintf(log_all_file, 256, "%s/logs/%s", gaim_dir, name);
 	if (stat(log_all_file, &st) < 0)
-		flag = 1;
+		*flag = 1;
 
 	debug_printf("Logging to: \"%s\"\n", log_all_file);
 
 	fd = fopen(log_all_file, "a");
 
+	g_free(buf);
+	g_free(buf2);
+	g_free(gaim_dir);
+	return fd;
+}
+
+FILE *open_log_file(char *name)
+{
+	struct stat st;
+	char realname[256];
+	struct log_conversation *l;
+	FILE *fd;
+	int flag = 0;
+
+	if (!(logging_options & OPT_LOG_ALL)) {
+
+		l = find_log_info(name);
+		if (!l)
+			return NULL;
+
+		if (stat(l->filename, &st) < 0)
+			flag = 1;
+
+		fd = fopen(l->filename, "a");
+
+		if (flag) {	/* is a new file */
+			fprintf(fd, "<HTML><HEAD><TITLE>");
+			fprintf(fd, "IM Sessions with %s", name);
+			fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n");
+		}
+
+		return fd;
+	}
+
+	g_snprintf(realname, sizeof(realname), "%s.log", normalize(name));
+	fd = open_gaim_log_file(realname, &flag);
+
 	if (fd && flag) {	/* is a new file */
 		fprintf(fd, "<HTML><HEAD><TITLE>");
 		fprintf(fd, "IM Sessions with %s", name);
 		fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n");
 	}
 
-	g_free(buf);
-	g_free(buf2);
-	g_free(gaim_dir);
 	return fd;
 }
 
+FILE *open_system_log_file(char *name)
+{
+	int x;
+
+	if (name)
+		return open_log_file(name);
+	else
+		return open_gaim_log_file("system", &x);
+}
 
 /* we only need this for TOC, because messages must be escaped */
 int escape_message(char *msg)
@@ -1326,3 +1350,144 @@
 	}
 	return;
 }
+
+void system_log(enum log_event what, struct gaim_connection *gc, struct buddy *who, int why)
+{
+	FILE *fd;
+	char text[256], html[256];
+
+	if ((logging_options & why) != why)
+		return;
+
+	if (logging_options & OPT_LOG_INDIVIDUAL)
+		fd = open_system_log_file(who->name);
+	else
+		fd = open_system_log_file(NULL);
+
+	if (!fd)
+		return;
+
+	if (why & OPT_LOG_MY_SIGNON) {
+		switch (what) {
+		case log_signon:
+			g_snprintf(text, sizeof(text), "+++ %s (%s) signed on @ %s",
+					gc->username, (*gc->prpl->name)(), full_date());
+			g_snprintf(html, sizeof(html), "<B>%s</B>", text);
+			break;
+		case log_signoff:
+			g_snprintf(text, sizeof(text), "+++ %s (%s) signed off @ %s",
+					gc->username, (*gc->prpl->name)(), full_date());
+			g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text);
+			break;
+		case log_away:
+			g_snprintf(text, sizeof(text), "+++ %s (%s) changed away state @ %s",
+					gc->username, (*gc->prpl->name)(), full_date());
+			g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text);
+			break;
+		case log_back:
+			g_snprintf(text, sizeof(text), "+++ %s (%s) came back @ %s",
+					gc->username, (*gc->prpl->name)(), full_date());
+			g_snprintf(html, sizeof(html), "%s", text);
+			break;
+		case log_idle:
+			g_snprintf(text, sizeof(text), "+++ %s (%s) became idle @ %s",
+					gc->username, (*gc->prpl->name)(), full_date());
+			g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text);
+			break;
+		case log_unidle:
+			g_snprintf(text, sizeof(text), "+++ %s (%s) returned from idle @ %s",
+					gc->username, (*gc->prpl->name)(), full_date());
+			g_snprintf(html, sizeof(html), "%s", text);
+			break;
+		case log_quit:
+			g_snprintf(text, sizeof(text), "+++ Program exit @ %s", full_date());
+			g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text);
+			break;
+		}
+	} else if (strcmp(who->name, who->show)) {
+		switch (what) {
+		case log_signon:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed on @ %s",
+				gc->username, (*gc->prpl->name)(), who->show, who->name, full_date());
+			g_snprintf(html, sizeof(html), "<B>%s</B>", text);
+			break;
+		case log_signoff:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed off @ %s",
+				gc->username, (*gc->prpl->name)(), who->show, who->name, full_date());
+			g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text);
+			break;
+		case log_away:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) went away @ %s",
+				gc->username, (*gc->prpl->name)(), who->show, who->name, full_date());
+			g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text);
+			break;
+		case log_back:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) came back @ %s",
+				gc->username, (*gc->prpl->name)(), who->show, who->name, full_date());
+			g_snprintf(html, sizeof(html), "%s", text);
+			break;
+		case log_idle:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) became idle @ %s",
+				gc->username, (*gc->prpl->name)(), who->show, who->name, full_date());
+			g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text);
+			break;
+		case log_unidle:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) returned from idle @ %s",
+				gc->username, (*gc->prpl->name)(), who->show, who->name, full_date());
+			g_snprintf(html, sizeof(html), "%s", text);
+			break;
+		default:
+			fclose(fd);
+			return;
+			break;
+		}
+	} else {
+		switch (what) {
+		case log_signon:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed on @ %s",
+				gc->username, (*gc->prpl->name)(), who->name, full_date());
+			g_snprintf(html, sizeof(html), "<B>%s</B>", text);
+			break;
+		case log_signoff:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed off @ %s",
+				gc->username, (*gc->prpl->name)(), who->name, full_date());
+			g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text);
+			break;
+		case log_away:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s went away @ %s",
+				gc->username, (*gc->prpl->name)(), who->name, full_date());
+			g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text);
+			break;
+		case log_back:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s came back @ %s",
+				gc->username, (*gc->prpl->name)(), who->name, full_date());
+			g_snprintf(html, sizeof(html), "%s", text);
+			break;
+		case log_idle:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s became idle @ %s",
+				gc->username, (*gc->prpl->name)(), who->name, full_date());
+			g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text);
+			break;
+		case log_unidle:
+			g_snprintf(text, sizeof(text), "%s (%s) reported that %s returned from idle @ %s",
+				gc->username, (*gc->prpl->name)(), who->name, full_date());
+			g_snprintf(html, sizeof(html), "%s", text);
+			break;
+		default:
+			fclose(fd);
+			return;
+			break;
+		}
+	}
+
+	if (logging_options & OPT_LOG_STRIP_HTML) {
+		fprintf(fd, "---- %s ----\n", text);
+	} else {
+		if (logging_options & OPT_LOG_INDIVIDUAL)
+			fprintf(fd, "<HR>%s<BR><HR><BR>\n", html);
+		else
+			fprintf(fd, "%s<BR>\n", html);
+	}
+
+	fclose(fd);
+}