changeset 11972:73777ad45562

[gaim-migrate @ 14265] Get rid of gc->is_idle, and get rid of some duplicate Yahoo! code committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 04 Nov 2005 17:33:32 +0000
parents cc7146eee26f
children 0fab529c01fc
files plugins/idle.c src/blist.h src/connection.h src/gtkidle.c src/protocols/irc/parse.c src/protocols/novell/novell.c src/protocols/yahoo/yahoo.c
diffstat 7 files changed, 84 insertions(+), 98 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/idle.c	Fri Nov 04 07:37:10 2005 +0000
+++ b/plugins/idle.c	Fri Nov 04 17:33:32 2005 +0000
@@ -49,7 +49,7 @@
 static void
 set_idle_time(GaimAccount *acct, int mins_idle)
 {
-	time_t t = time(NULL); /* grab the current time */
+	time_t t;
 	GaimConnection *gc = gaim_account_get_connection(acct);
 	GaimPresence *presence = gaim_account_get_presence(acct);
 
@@ -60,9 +60,8 @@
 			"setting idle time for %s to %d\n",
 			gaim_account_get_username(acct), mins_idle);
 
-	t -= 60 * mins_idle; /* subtract seconds idle from current time */
+	t -= time(NULL) - (60 * mins_idle); /* subtract seconds idle from current time */
 	gc->last_sent_time = t;
-	gc->is_idle = 0;
 
 	gaim_presence_set_idle(presence, mins_idle ? TRUE : FALSE, t);
 }
--- a/src/blist.h	Fri Nov 04 07:37:10 2005 +0000
+++ b/src/blist.h	Fri Nov 04 17:33:32 2005 +0000
@@ -104,7 +104,7 @@
 	char *server_alias;                     /**< The server-specified alias of the buddy.  (i.e. MSN "Friendly Names") */
 	void *proto_data;                       /**< This allows the prpl to associate whatever data it wants with a buddy */
 	GaimBuddyIcon *icon;                    /**< The buddy icon. */
-	GaimAccount *account;           	/**< the account this buddy belongs to */
+	GaimAccount *account;					/**< the account this buddy belongs to */
 	GaimPresence *presence;
 };
 
--- a/src/connection.h	Fri Nov 04 07:37:10 2005 +0000
+++ b/src/connection.h	Fri Nov 04 17:33:32 2005 +0000
@@ -91,7 +91,6 @@
 	guint idle_timer;            /**< The idle timer.                    */
 	time_t login_time;           /**< Time of login.                     */
 	time_t last_sent_time;       /**< The time something was last sent.  */
-	int is_idle;                 /**< Idle state of the connection.      */
 
 	gboolean is_auto_away;       /**< Whether or not it's auto-away.     */
 
--- a/src/gtkidle.c	Fri Nov 04 07:37:10 2005 +0000
+++ b/src/gtkidle.c	Fri Nov 04 17:33:32 2005 +0000
@@ -118,11 +118,14 @@
 	GaimConnection *gc = (GaimConnection *)data;
 	gboolean report_idle;
 	GaimAccount *account;
+	GaimPresence *presence;
 	time_t t;
 	int idle_time;
 
 	account = gaim_connection_get_account(gc);
 
+	presence = gaim_account_get_presence(account);
+
 	gaim_signal_emit(gaim_blist_get_handle(), "update-idle");
 
 	time(&t);
@@ -130,14 +133,14 @@
 	report_idle = gaim_prefs_get_bool("/gaim/gtk/idle/report");
 
 #ifdef USE_SCREENSAVER
-		idle_time = get_idle_time_from_system();
+	idle_time = get_idle_time_from_system();
 #else
-		/*
-		 * If Gaim wasn't built with xscreensaver support, then
-		 * fallback to calculating our idle time based on when
-		 * we last sent a message.
-		 */
-		idle_time = t - gc->last_sent_time;
+	/*
+	 * If Gaim wasn't built with xscreensaver support, then
+	 * fallback to calculating our idle time based on when
+	 * we last sent a message.
+	 */
+	idle_time = t - gc->last_sent_time;
 #endif /* USE_SCREENSAVER */
 
 	/* Should we become auto-away? */
@@ -145,10 +148,6 @@
 		(idle_time > (60 * gaim_prefs_get_int("/core/away/mins_before_away")))
 		&& (!gc->is_auto_away))
 	{
-		GaimPresence *presence;
-
-		presence = gaim_account_get_presence(account);
-
 		if (gaim_presence_is_available(presence))
 		{
 			const char *idleaway_name;
@@ -182,16 +181,16 @@
 	}
 
 	/* Deal with reporting idleness to the server, if appropriate */
-	if (report_idle && idle_time >= IDLEMARK && !gc->is_idle) {
+	if (report_idle && idle_time >= IDLEMARK && !gaim_presence_is_idle(presence)) {
 		gaim_debug_info("idle", "Setting %s idle %d seconds\n",
 				   gaim_account_get_username(account), idle_time);
 		serv_set_idle(gc, idle_time);
-		gc->is_idle = 1;
+		gaim_presence_set_idle(presence, TRUE, time(NULL));
 		/* LOG	system_log(log_idle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON); */
-	} else if ((!report_idle || idle_time < IDLEMARK) && gc->is_idle) {
+	} else if ((!report_idle || idle_time < IDLEMARK) && gaim_presence_is_idle(presence)) {
 		gaim_debug_info("idle", "Setting %s unidle\n",
 				   gaim_account_get_username(account));
-		gc->is_idle = 0;
+		gaim_presence_set_idle(presence, FALSE, time(NULL));
 		serv_set_idle(gc, 0);
 		/* LOG	system_log(log_unidle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON); */
 	}
--- a/src/protocols/irc/parse.c	Fri Nov 04 07:37:10 2005 +0000
+++ b/src/protocols/irc/parse.c	Fri Nov 04 17:33:32 2005 +0000
@@ -415,6 +415,7 @@
 		return buf;
 	} else if (!strncmp(cur, "PING ", 5)) {
 		if (notice) { /* reply */
+			/* TODO: Should this read in the timestamp as a double? */
 			sscanf(cur, "PING %lu", &timestamp);
 			gc = gaim_account_get_connection(irc->account);
 			if (!gc)
--- a/src/protocols/novell/novell.c	Fri Nov 04 07:37:10 2005 +0000
+++ b/src/protocols/novell/novell.c	Fri Nov 04 17:33:32 2005 +0000
@@ -2980,6 +2980,7 @@
 {
 	GaimConnection *gc;
 	gboolean connected;
+	GaimPresence *presence;
 	GaimStatusType *type;
 	GaimStatusPrimitive primitive;
 	NMUser *user;
@@ -2989,6 +2990,7 @@
 	char *text = NULL;
 
 	connected = gaim_account_is_connected(account);
+	presence = gaim_status_get_presence(status);
 	type = gaim_status_get_type(status);
 	primitive = gaim_status_type_get_primitive(type);
 
@@ -3036,7 +3038,7 @@
 		novellstatus = NM_STATUS_BUSY;
 	} else if (primitive == GAIM_STATUS_HIDDEN) {
 		novellstatus = NM_STATUS_OFFLINE;
-	} else if (gc->is_idle) {
+	} else if (gaim_presence_is_idle(presence)) {
 		novellstatus = NM_STATUS_AWAY_IDLE;
 	} else {
 		novellstatus = NM_STATUS_AVAILABLE;
--- a/src/protocols/yahoo/yahoo.c	Fri Nov 04 07:37:10 2005 +0000
+++ b/src/protocols/yahoo/yahoo.c	Fri Nov 04 17:33:32 2005 +0000
@@ -2444,12 +2444,55 @@
 	g_free(buddyicon);
 }
 
+static int get_yahoo_status_from_gaim_status(GaimStatus *status)
+{
+	GaimPresence *presence;
+	const char *status_id;
+	const char *msg;
+
+	presence = gaim_status_get_presence(status);
+	status_id = gaim_status_get_id(status);
+	msg = gaim_status_get_attr_string(status, "message");
+
+	if (!strcmp(status_id, YAHOO_STATUS_TYPE_AVAILABLE)) {
+		if ((msg != NULL) && (*msg != '\0'))
+			return YAHOO_STATUS_CUSTOM;
+		else
+			return YAHOO_STATUS_AVAILABLE;
+	} else if (!strcmp(status_id, YAHOO_STATUS_TYPE_BRB)) {
+		return YAHOO_STATUS_BRB;
+	} else if (!strcmp(status_id, YAHOO_STATUS_TYPE_BUSY)) {
+		return YAHOO_STATUS_BUSY;
+	} else if (!strcmp(status_id, YAHOO_STATUS_TYPE_NOTATHOME)) {
+		return YAHOO_STATUS_NOTATHOME;
+	} else if (!strcmp(status_id, YAHOO_STATUS_TYPE_NOTATDESK)) {
+		return YAHOO_STATUS_NOTATDESK;
+	} else if (!strcmp(status_id, YAHOO_STATUS_TYPE_NOTINOFFICE)) {
+		return YAHOO_STATUS_NOTINOFFICE;
+	} else if (!strcmp(status_id, YAHOO_STATUS_TYPE_ONPHONE)) {
+		return YAHOO_STATUS_ONPHONE;
+	} else if (!strcmp(status_id, YAHOO_STATUS_TYPE_ONVACATION)) {
+		return YAHOO_STATUS_ONVACATION;
+	} else if (!strcmp(status_id, YAHOO_STATUS_TYPE_OUTTOLUNCH)) {
+		return YAHOO_STATUS_OUTTOLUNCH;
+	} else if (!strcmp(status_id, YAHOO_STATUS_TYPE_STEPPEDOUT)) {
+		return YAHOO_STATUS_STEPPEDOUT;
+	} else if (!strcmp(status_id, YAHOO_STATUS_TYPE_INVISIBLE)) {
+		return YAHOO_STATUS_INVISIBLE;
+	} else if (!strcmp(status_id, YAHOO_STATUS_TYPE_AWAY)) {
+		return YAHOO_STATUS_CUSTOM;
+	} else if (gaim_presence_is_idle(presence)) {
+		return YAHOO_STATUS_IDLE;
+	} else {
+		gaim_debug_error("yahoo", "Unexpected GaimStatus!\n");
+		return YAHOO_STATUS_AVAILABLE;
+	}
+}
 
 static void yahoo_login(GaimAccount *account) {
 	GaimConnection *gc = gaim_account_get_connection(account);
 	struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1);
 	GaimStatus *status = gaim_account_get_active_status(account);
-	const char *id = gaim_status_get_id(status);
 	gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_NO_URLDESC;
 
 	gaim_connection_update_progress(gc, _("Connecting"), 1, 2);
@@ -2461,39 +2504,8 @@
 	yd->confs = NULL;
 	yd->conf_id = 2;
 
-	if (!strcmp(id, YAHOO_STATUS_TYPE_AVAILABLE)) {
-		if (gaim_status_get_attr_string(status, "message") != NULL)
-			yd->current_status = YAHOO_STATUS_CUSTOM;
-		else
-			yd->current_status = YAHOO_STATUS_AVAILABLE;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_BRB)) {
-		yd->current_status = YAHOO_STATUS_BRB;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_BUSY)) {
-		yd->current_status = YAHOO_STATUS_BUSY;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_NOTATHOME)) {
-		yd->current_status = YAHOO_STATUS_NOTATHOME;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_NOTATDESK)) {
-		yd->current_status = YAHOO_STATUS_NOTATDESK;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_NOTINOFFICE)) {
-		yd->current_status = YAHOO_STATUS_NOTINOFFICE;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_ONPHONE)) {
-		yd->current_status = YAHOO_STATUS_ONPHONE;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_ONVACATION)) {
-		yd->current_status = YAHOO_STATUS_ONVACATION;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_OUTTOLUNCH)) {
-		yd->current_status = YAHOO_STATUS_OUTTOLUNCH;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_STEPPEDOUT)) {
-		yd->current_status = YAHOO_STATUS_STEPPEDOUT;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_INVISIBLE)) {
-		yd->current_status = YAHOO_STATUS_INVISIBLE;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_AWAY)) {
-		yd->current_status = YAHOO_STATUS_CUSTOM;
-	} else if (gc->is_idle) { /* i think this is broken */
-		yd->current_status = YAHOO_STATUS_IDLE;
-	} else {
-		gaim_debug_error("yahoo", "Unexpected GaimStatus passed to yahoo_set_status!\n");
-		yd->current_status = YAHOO_STATUS_AVAILABLE;
-	}
+	yd->current_status = get_yahoo_status_from_gaim_status(status);
+
 	yahoo_server_check(account);
 	yahoo_picture_check(account);
 
@@ -3063,69 +3075,43 @@
 
 static void yahoo_set_status(GaimAccount *account, GaimStatus *status)
 {
-	GaimConnection *gc = gaim_account_get_connection(account);
+	GaimConnection *gc;
+	GaimPresence *presence;
 	struct yahoo_data *yd;
 	struct yahoo_packet *pkt;
 	int old_status;
-	const char *id;
 	const char *msg = NULL;
 	char *tmp = NULL;
 	char *conv_msg = NULL;
 
-	id = gaim_status_get_id(status);
 	if (!gaim_status_is_active(status))
 		return;
 
 	if (!gaim_account_is_connected(account))
 		return;
 
+	gc = gaim_account_get_connection(account);
+	presence = gaim_status_get_presence(status);
 	yd = (struct yahoo_data *)gc->proto_data;
 	old_status = yd->current_status;
 
-	if (!strcmp(id, YAHOO_STATUS_TYPE_AVAILABLE)) {
+	yd->current_status = get_yahoo_status_from_gaim_status(status);
+
+	if (yd->current_status == YAHOO_STATUS_CUSTOM)
+	{
 		msg = gaim_status_get_attr_string(status, "message");
-		if ((msg == NULL) || (*msg == '\0')) {
-			yd->current_status = YAHOO_STATUS_AVAILABLE;
+
+		if (gaim_status_is_available(status)) {
+			tmp = yahoo_string_encode(gc, msg, NULL);
+			conv_msg = gaim_markup_strip_html(tmp);
+			g_free(tmp);
 		} else {
-			yd->current_status = YAHOO_STATUS_CUSTOM;
+			if ((msg == NULL) || (*msg == '\0'))
+				msg = _("Away");
 			tmp = yahoo_string_encode(gc, msg, NULL);
 			conv_msg = gaim_markup_strip_html(tmp);
 			g_free(tmp);
 		}
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_BRB)) {
-		yd->current_status = YAHOO_STATUS_BRB;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_BUSY)) {
-		yd->current_status = YAHOO_STATUS_BUSY;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_NOTATHOME)) {
-		yd->current_status = YAHOO_STATUS_NOTATHOME;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_NOTATDESK)) {
-		yd->current_status = YAHOO_STATUS_NOTATDESK;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_NOTINOFFICE)) {
-		yd->current_status = YAHOO_STATUS_NOTINOFFICE;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_ONPHONE)) {
-		yd->current_status = YAHOO_STATUS_ONPHONE;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_ONVACATION)) {
-		yd->current_status = YAHOO_STATUS_ONVACATION;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_OUTTOLUNCH)) {
-		yd->current_status = YAHOO_STATUS_OUTTOLUNCH;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_STEPPEDOUT)) {
-		yd->current_status = YAHOO_STATUS_STEPPEDOUT;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_INVISIBLE)) {
-		yd->current_status = YAHOO_STATUS_INVISIBLE;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_AWAY)) {
-		yd->current_status = YAHOO_STATUS_CUSTOM;
-
-		msg = gaim_status_get_attr_string(status, "message");
-		if ((msg == NULL) && (*msg == '\0'))
-			msg = _("Away");
-		tmp = yahoo_string_encode(gc, msg, NULL);
-		conv_msg = gaim_markup_strip_html(tmp);
-		g_free(tmp);
-	} else if (gc->is_idle) { /* i think this is broken */
-		yd->current_status = YAHOO_STATUS_IDLE;
-	} else {
-		gaim_debug_error("yahoo", "Unexpected GaimStatus passed to yahoo_login!\n");
-		yd->current_status = YAHOO_STATUS_AVAILABLE;
 	}
 
 	if (yd->current_status == YAHOO_STATUS_INVISIBLE) {
@@ -3147,9 +3133,9 @@
 
 	g_free(conv_msg);
 
-	if (gc->is_idle)
+	if (gaim_presence_is_idle(presence))
 		yahoo_packet_hash_str(pkt, 47, "2");
-	else if (!gaim_status_type_is_available(gaim_status_get_type(status)))
+	else if (!gaim_status_is_available(status))
 		yahoo_packet_hash_str(pkt, 47, "1");
 
 	yahoo_packet_send_and_free(pkt, yd);