changeset 1404:96e93119268d

[gaim-migrate @ 1414] argh committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sat, 13 Jan 2001 08:49:15 +0000
parents c0aa7fdc0a93
children cf36481bbc8f
files plugins/SIGNALS plugins/autorecon.c plugins/events.c plugins/iconaway.c plugins/icq/gaim_icq.c plugins/yay/yay.c src/away.c src/idle.c src/multi.h src/oscar.c src/plugins.c src/server.c src/toc.c
diffstat 13 files changed, 110 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/SIGNALS	Fri Jan 12 03:02:20 2001 +0000
+++ b/plugins/SIGNALS	Sat Jan 13 08:49:15 2001 +0000
@@ -64,15 +64,29 @@
 	serv_close is, so you still have a chance to get one last message out.
 
 event_away:
-	(none)
+	struct gaim_connection *gc, char *state, char *message
+
+	'gc' is the connection. Duh.
+	'state' is confusing. We'll save that for now.
+	'message' is the away message to be used.
 
-	This is fucked up for now. Currently all connections are told to use the
-	same away message when the user wants to be Away. The away message that
-	is used can be obtained from global variables.
+	Each protocol sets up what away states it can have. These are all char *,
+	and when the connection goes away it uses one of those. That's what state
+	is.
+
+	There's no way of telling from state and message whether you're actually
+	away; it only gives state information, and a possible message.
+
+	However, the protocols also are very nice (usually) and will set gc->away
+	if they're in an away-like state (e.g. Away or N/A for ICQ, etc). You can
+	use that for a more rigid (read "boolean") way of checking away-ness.
 
 event_back:
 	(none)
 
+	This is deprecated and will not be called again. It will probably be
+	removed eventually.
+
 event_im_recv:
 	struct gaim_connection *gc, char **who, char **text
 
--- a/plugins/autorecon.c	Fri Jan 12 03:02:20 2001 +0000
+++ b/plugins/autorecon.c	Sat Jan 13 08:49:15 2001 +0000
@@ -1,12 +1,13 @@
 #define GAIM_PLUGINS
 #include "gaim.h"
+#include "prpl.h"
 #include <gtk/gtk.h>
 
 extern GtkWidget *imaway;
 
 static int away_state;
 static int forced_off = 0;
-static struct away_message *last_away = NULL;
+static char *last_away = NULL;
 GSList *reconnects = NULL;
 GSList *recontim = NULL;
 
@@ -27,7 +28,7 @@
 	recon = (guint)g_slist_nth(recontim, place);
 	reconnects = g_slist_remove(reconnects, gc->user);
 	recontim = g_slist_remove(recontim, (void *)recon);
-	if (away_state) do_away_message(NULL, last_away);
+	if (away_state) serv_set_away(gc, GAIM_AWAY_CUSTOM, last_away);
 }
 
 static void do_signon(struct aim_user *u) {
@@ -50,25 +51,30 @@
 	forced_off = 1;
 }
 
-static void away_toggle(void *m) {
-	if ((int)m == 1) {
-		last_away = awaymessage;
+static void away_toggle(struct gaim_connection *gc, char *state, char *message, gpointer data) {
+	if (gc->away) {
+		if (last_away)
+			g_free(last_away);
+		last_away = g_strdup(gc->away);
 		away_state = 1;
 	} else if (!forced_off)
 		away_state = 0;
 }
 
 char *gaim_plugin_init(GModule *handle) {
-	if (imaway) {
+	if (awaymessage) {
 		away_state = 1;
-		last_away = awaymessage;
+		last_away = g_strdup(awaymessage->message);
 	} else
 		away_state = 0;
 
-	gaim_signal_connect(handle, event_away, away_toggle, (void *)1);
-	gaim_signal_connect(handle, event_back, away_toggle, (void *)0);
+	gaim_signal_connect(handle, event_away, away_toggle, NULL);
 	gaim_signal_connect(handle, event_signoff, reconnect, NULL);
 	gaim_signal_connect(handle, event_signon, now_online, NULL);
 
 	return NULL;
 }
+
+void gaim_plugin_remove() {
+	g_free(last_away);
+}
--- a/plugins/events.c	Fri Jan 12 03:02:20 2001 +0000
+++ b/plugins/events.c	Sat Jan 13 08:49:15 2001 +0000
@@ -21,9 +21,9 @@
 	printf("event_signoff\n");
 }
 
-static void evt_away(void *data)
+static void evt_away(struct gaim_connection *gc, char *state, char *message, void *data)
 {
-	printf("event_away\n");
+	printf("event_away: %s %s %s\n", gc->username, state, message);
 }
 
 static void evt_back(void *data)
--- a/plugins/iconaway.c	Fri Jan 12 03:02:20 2001 +0000
+++ b/plugins/iconaway.c	Sat Jan 13 08:49:15 2001 +0000
@@ -13,10 +13,11 @@
 extern void applet_destroy_buddy();
 #endif
 
-void iconify_windows(void *data) {
-	XIconifyWindow(GDK_DISPLAY(),
-			GDK_WINDOW_XWINDOW(imaway->window),
-			((_XPrivDisplay)GDK_DISPLAY())->default_screen);
+void iconify_windows(struct gaim_connection *gc, char *state, char *message, void *data) {
+	if (imaway)
+		XIconifyWindow(GDK_DISPLAY(),
+				GDK_WINDOW_XWINDOW(imaway->window),
+				((_XPrivDisplay)GDK_DISPLAY())->default_screen);
 #ifdef USE_APPLET
 	applet_destroy_buddy();
 #else
--- a/plugins/icq/gaim_icq.c	Fri Jan 12 03:02:20 2001 +0000
+++ b/plugins/icq/gaim_icq.c	Sat Jan 13 08:49:15 2001 +0000
@@ -284,7 +284,8 @@
 
 static void icq_send_msg(struct gaim_connection *gc, char *who, char *msg, int away) {
 	struct icq_data *id = (struct icq_data *)gc->proto_data;
-	icq_SendMessage(id->link, atol(who), msg, ICQ_SEND_BESTWAY);
+	if (!away && (strlen(msg) > 0))
+		icq_SendMessage(id->link, atol(who), msg, ICQ_SEND_BESTWAY);
 }
 
 static void icq_keepalive(struct gaim_connection *gc) {
@@ -317,25 +318,36 @@
 static void icq_set_away(struct gaim_connection *gc, char *state, char *msg) {
 	struct icq_data *id = (struct icq_data *)gc->proto_data;
 
+	if (gc->away)
+		gc->away = NULL;
+
 	if (!strcmp(state, "Online"))
 		icq_ChangeStatus(id->link, STATUS_ONLINE);
-	else if (!strcmp(state, "Away"))
+	else if (!strcmp(state, "Away")) {
 		icq_ChangeStatus(id->link, STATUS_AWAY);
-	else if (!strcmp(state, "Do Not Disturb"))
+		gc->away = "";
+	} else if (!strcmp(state, "Do Not Disturb")) {
 		icq_ChangeStatus(id->link, STATUS_DND);
-	else if (!strcmp(state, "Not Available"))
+		gc->away = "";
+	} else if (!strcmp(state, "Not Available")) {
 		icq_ChangeStatus(id->link, STATUS_NA);
-	else if (!strcmp(state, "Occupied"))
+		gc->away = "";
+	} else if (!strcmp(state, "Occupied")) {
 		icq_ChangeStatus(id->link, STATUS_OCCUPIED);
-	else if (!strcmp(state, "Free For Chat"))
+		gc->away = "";
+	} else if (!strcmp(state, "Free For Chat")) {
 		icq_ChangeStatus(id->link, STATUS_FREE_CHAT);
-	else if (!strcmp(state, "Invisible"))
+		gc->away = "";
+	} else if (!strcmp(state, "Invisible")) {
 		icq_ChangeStatus(id->link, STATUS_INVISIBLE);
-	else if (!strcmp(state, GAIM_AWAY_CUSTOM)) {
-		if (msg)
+		gc->away = "";
+	} else if (!strcmp(state, GAIM_AWAY_CUSTOM)) {
+		if (msg) {
 			icq_ChangeStatus(id->link, STATUS_NA);
-		else
+			gc->away = "";
+		} else {
 			icq_ChangeStatus(id->link, STATUS_ONLINE);
+		}
 	}
 }
 
--- a/plugins/yay/yay.c	Fri Jan 12 03:02:20 2001 +0000
+++ b/plugins/yay/yay.c	Sat Jan 13 08:49:15 2001 +0000
@@ -302,9 +302,14 @@
 static void yahoo_set_away(struct gaim_connection *gc, char *state, char *msg) {
 	struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
 
+	if (gc->away)
+		g_free(gc->away);
+	gc->away = NULL;
+
 	if (msg) {
 		yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_CUSTOM, msg);
 		yd->current_status = YAHOO_STATUS_CUSTOM;
+		gc->away = g_strdup(msg);
 	} else if (state) {
 		if (!strcmp(state, "Available")) {
 			yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_AVAILABLE, msg);
@@ -312,33 +317,43 @@
 		} else if (!strcmp(state, "Be Right Back")) {
 			yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_BRB, msg);
 			yd->current_status = YAHOO_STATUS_BRB;
+			gc->away = g_strdup(yahoo_get_status_string(YAHOO_STATUS_BRB));
 		} else if (!strcmp(state, "Busy")) {
 			yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_BUSY, msg);
 			yd->current_status = YAHOO_STATUS_BUSY;
+			gc->away = g_strdup(yahoo_get_status_string(YAHOO_STATUS_BUSY));
 		} else if (!strcmp(state, "Not At Home")) {
 			yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_NOTATHOME, msg);
 			yd->current_status = YAHOO_STATUS_NOTATHOME;
+			gc->away = g_strdup(yahoo_get_status_string(YAHOO_STATUS_NOTATHOME));
 		} else if (!strcmp(state, "Not At Desk")) {
 			yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_NOTATDESK, msg);
 			yd->current_status = YAHOO_STATUS_NOTATDESK;
+			gc->away = g_strdup(yahoo_get_status_string(YAHOO_STATUS_NOTATDESK));
 		} else if (!strcmp(state, "Not In Office")) {
 			yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_NOTINOFFICE, msg);
 			yd->current_status = YAHOO_STATUS_NOTINOFFICE;
+			gc->away = g_strdup(yahoo_get_status_string(YAHOO_STATUS_NOTINOFFICE));
 		} else if (!strcmp(state, "On Phone")) {
 			yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_ONPHONE, msg);
 			yd->current_status = YAHOO_STATUS_ONPHONE;
+			gc->away = g_strdup(yahoo_get_status_string(YAHOO_STATUS_ONPHONE));
 		} else if (!strcmp(state, "On Vacation")) {
 			yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_ONVACATION, msg);
 			yd->current_status = YAHOO_STATUS_ONVACATION;
+			gc->away = g_strdup(yahoo_get_status_string(YAHOO_STATUS_ONVACATION));
 		} else if (!strcmp(state, "Out To Lunch")) {
 			yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_OUTTOLUNCH, msg);
 			yd->current_status = YAHOO_STATUS_OUTTOLUNCH;
+			gc->away = g_strdup(yahoo_get_status_string(YAHOO_STATUS_OUTTOLUNCH));
 		} else if (!strcmp(state, "Stepped Out")) {
 			yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_STEPPEDOUT, msg);
 			yd->current_status = YAHOO_STATUS_STEPPEDOUT;
+			gc->away = g_strdup(yahoo_get_status_string(YAHOO_STATUS_STEPPEDOUT));
 		} else if (!strcmp(state, "Invisible")) {
 			yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_INVISIBLE, msg);
 			yd->current_status = YAHOO_STATUS_INVISIBLE;
+			gc->away = g_strdup(yahoo_get_status_string(YAHOO_STATUS_INVISIBLE));
 		} else if (!strcmp(state, GAIM_AWAY_CUSTOM)) {
 			if (gc->is_idle) {
 				yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_IDLE, NULL);
--- a/src/away.c	Fri Jan 12 03:02:20 2001 +0000
+++ b/src/away.c	Sat Jan 13 08:49:15 2001 +0000
@@ -57,7 +57,6 @@
 		GtkWidget *tmp = imaway;
 		imaway = NULL;
 		gtk_widget_destroy(tmp);
-		plugin_event(event_back, 0, 0, 0, 0);
 	}
 
 	serv_set_away_all(NULL);
@@ -160,7 +159,6 @@
 	serv_set_away_all(buf2);
 	g_free(buf2);
 	gtk_widget_show(imaway);
-	plugin_event(event_away, 0, 0, 0, 0);
 }
 
 void rem_away_mess(GtkWidget *w, struct away_message *a)
--- a/src/idle.c	Fri Jan 12 03:02:20 2001 +0000
+++ b/src/idle.c	Sat Jan 13 08:49:15 2001 +0000
@@ -37,9 +37,6 @@
 #include "prpl.h"
 
 
-int auto_is_away = 0;
-
-
 gint check_idle(struct gaim_connection *gc)
 {
 	time_t t;
@@ -70,15 +67,13 @@
 #endif /* USE_SCREENSAVER */
 		idle_time = t - gc->lastsent;
 
-	if ((general_options & OPT_GEN_AUTO_AWAY) &&
-	    (idle_time > (60 * auto_away)) && (awaymessage == NULL) && (auto_is_away == 0)) {
-		set_default_away((GtkWidget*)NULL, 
-				 (gpointer)g_slist_index(away_messages,
-							 default_away));
+	if ((general_options & OPT_GEN_AUTO_AWAY) && (idle_time > (60 * auto_away)) &&
+			(!gc->away) && (!gc->is_auto_away)) {
+		set_default_away((GtkWidget*)NULL, (gpointer)g_slist_index(away_messages, default_away));
 		serv_set_away(gc, GAIM_AWAY_CUSTOM, default_away->message);
-		auto_is_away = 1;
-	} else if (auto_is_away == 1 && idle_time < 60 * auto_away) {
-		auto_is_away = 0;
+		gc->is_auto_away = TRUE;
+	} else if (gc->is_auto_away && idle_time < 60 * auto_away) {
+		gc->is_auto_away = FALSE;
 		if (awaymessage != NULL)
 			serv_set_away(gc, GAIM_AWAY_CUSTOM, NULL);
 	}
--- a/src/multi.h	Fri Jan 12 03:02:20 2001 +0000
+++ b/src/multi.h	Sat Jan 13 08:49:15 2001 +0000
@@ -67,6 +67,9 @@
 	GtkWidget *meter;
 	GtkWidget *progress;
 	GtkWidget *status;
+
+	char *away;
+	gboolean is_auto_away;
 };
 
 /* now that we have our struct, we're going to need lots of them. Maybe even a list of them. */
--- a/src/oscar.c	Fri Jan 12 03:02:20 2001 +0000
+++ b/src/oscar.c	Sat Jan 13 08:49:15 2001 +0000
@@ -1742,6 +1742,11 @@
 static void oscar_set_away(struct gaim_connection *g, char *state, char *message) {
 	struct oscar_data *odata = (struct oscar_data *)g->proto_data;
 	aim_bos_setprofile(odata->sess, odata->conn, g->user->user_info, message, gaim_caps);
+	if (g->away)
+		g_free (g->away);
+	g->away = NULL;
+	if (message)
+		g->away = g_strdup (message);
 }
 
 static void oscar_warn(struct gaim_connection *g, char *name, int anon) {
--- a/src/plugins.c	Fri Jan 12 03:02:20 2001 +0000
+++ b/src/plugins.c	Sat Jan 13 08:49:15 2001 +0000
@@ -642,8 +642,6 @@
 				break;
 
 				/* no args */
-			case event_away:
-			case event_back:
 			case event_blist_update:
 			case event_quit:
 				{
@@ -708,6 +706,8 @@
 				/* struct gaim_connection *, char *, char * */
 			case event_chat_buddy_join:
 			case event_chat_buddy_leave:
+			case event_away:
+			case event_back:
 				{
 					void (*function)(struct gaim_connection *, char *, char *,
 							  void *) = g->function;
@@ -748,10 +748,10 @@
 		g_snprintf(buf, sizeof buf, "\"%s\"", ((struct gaim_connection *)arg1)->username);
 		break;
 	case event_away:
-		buf[0] = 0;
+		g_snprintf(buf, sizeof buf, "\"%s\"", ((struct gaim_connection *)arg1)->username);
 		break;
 	case event_back:
-		buf[0] = 0;
+		g_snprintf(buf, sizeof buf, "\"%s\"", ((struct gaim_connection *)arg1)->username);
 		break;
 	case event_im_recv:
 		g_snprintf(buf, sizeof buf, "\"%s\" \"%s\" %s",
--- a/src/server.c	Fri Jan 12 03:02:20 2001 +0000
+++ b/src/server.c	Sat Jan 13 08:49:15 2001 +0000
@@ -160,8 +160,10 @@
 
 void serv_set_away(struct gaim_connection *gc, char *state, char *message)
 {
-	if (gc && gc->prpl && gc->prpl->set_away)
+	if (gc && gc->prpl && gc->prpl->set_away) {
 		(*gc->prpl->set_away)(gc, state, message);
+		plugin_event(event_away, gc, state, message, 0);
+	}
 }
 
 void serv_set_away_all(char *message)
@@ -171,8 +173,10 @@
 
 	while (c) {
 		g = (struct gaim_connection *)c->data;
-		if (g->prpl && g->prpl->set_away)
+		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);
+		}
 		c = c->next;
 	}
 }
@@ -348,7 +352,7 @@
 	if (away)
 		away = WFLAG_AUTO;
 
-	if (awaymessage != NULL) {
+	if (gc->away) {
 		if (!(general_options & OPT_GEN_DISCARD_WHEN_AWAY)) {
 			if (cnv == NULL) {
 				new_conv = 1;
@@ -387,7 +391,7 @@
 
 
 
-	if (awaymessage != NULL) {
+	if (gc->away) {
 		time_t t;
 		char *tmpmsg;
 		struct buddy *b = find_buddy(gc, name);
@@ -402,7 +406,7 @@
 		cnv->sent_away = t;
 
 		/* apply default fonts and colors */
-		tmpmsg = stylize(awaymessage->message, MSG_LEN);
+		tmpmsg = stylize(gc->away, MSG_LEN);
 
 		serv_send_im(gc, name, away_subs(tmpmsg, alias), 1);
 
--- a/src/toc.c	Fri Jan 12 03:02:20 2001 +0000
+++ b/src/toc.c	Sat Jan 13 08:49:15 2001 +0000
@@ -46,7 +46,7 @@
 #include "pixmaps/dt_icon.xpm"
 #include "pixmaps/free_icon.xpm"
 
-#define REVISION "gaim:$Revision: 1411 $"
+#define REVISION "gaim:$Revision: 1414 $"
 
 #define TYPE_SIGNON    1
 #define TYPE_DATA      2
@@ -721,6 +721,11 @@
 	} else
 		g_snprintf(buf, MSG_LEN, "toc_set_away \"\"");
 	sflap_send(g, buf, -1, TYPE_DATA);
+	if (g->away)
+		g_free (g->away);
+	g->away = NULL;
+	if (message)
+		g->away = g_strdup (message);
 }
 
 static void toc_set_info(struct gaim_connection *g, char *info)