changeset 14318:437ce90442cf

[gaim-migrate @ 17011] Use GaimPresence to keep track of our status instead of qd->status. Also allow invisible logins. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Thu, 24 Aug 2006 07:00:34 +0000
parents c8ddda5d8ec8
children 69f594f56de5
files libgaim/protocols/qq/buddy_status.c libgaim/protocols/qq/buddy_status.h libgaim/protocols/qq/keep_alive.c libgaim/protocols/qq/login_logout.c libgaim/protocols/qq/login_logout.h libgaim/protocols/qq/qq.c libgaim/protocols/qq/qq.h
diffstat 7 files changed, 59 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/libgaim/protocols/qq/buddy_status.c	Thu Aug 24 02:35:15 2006 +0000
+++ b/libgaim/protocols/qq/buddy_status.c	Thu Aug 24 07:00:34 2006 +0000
@@ -35,16 +35,8 @@
 #include "qq_proxy.h"
 
 #define QQ_MISC_STATUS_HAVING_VIIDEO      0x00000001
-
-#define QQ_ICON_SUFFIX_DEFAULT            QQ_ICON_SUFFIX_OFFLINE
 #define QQ_CHANGE_ONLINE_STATUS_REPLY_OK 	0x30	/* ASCII value of "0" */
 
-enum {
-	QQ_ICON_SUFFIX_NORMAL = 1,
-	QQ_ICON_SUFFIX_OFFLINE = 2,
-	QQ_ICON_SUFFIX_AWAY = 3,
-};
-
 void qq_buddy_status_dump_unclear(qq_buddy_status *s)
 {
 	GString *dump;
@@ -120,22 +112,25 @@
 	return FALSE;
 }
 
-/* The QQ client seems to use a separate icon for each
- * face/status combo, but we only use one and let Gaim
- * handle the rest. We need to use this function to report 
- * the correct icon file back to the server. */
-gint get_icon_offset_from_self_status(guint8 status)
-{
-	switch (status) {
-	case QQ_SELF_STATUS_AVAILABLE:
+ /* Help calculate the correct icon index to tell the server. */
+gint get_icon_offset(GaimConnection *gc)
+{ 
+	GaimAccount *account;
+	GaimPresence *presence; 
+
+	g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, 2);
+
+	account = gaim_connection_get_account(gc);
+	presence = gaim_account_get_presence(account);
+
+	if (gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_INVISIBLE)) {
+		return 2;
+	} else if (gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_AWAY)
+			|| gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_EXTENDED_AWAY)
+			|| gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_UNAVAILABLE)) {
+		return 1;
+        } else {
 		return 0;
-	case QQ_SELF_STATUS_AWAY:
-	case QQ_SELF_STATUS_CUSTOM:
-		return 1;
-	case QQ_SELF_STATUS_INVISIBLE:
-		return 2;
-	default:
-		return 2;
 	}
 }
 
@@ -146,26 +141,25 @@
 	guint8 *raw_data, *cursor, away_cmd;
 	guint32 misc_status;
 	gboolean fake_video;
+	GaimAccount *account;
+	GaimPresence *presence; 
 
 	g_return_if_fail(gc != NULL && gc->proto_data != NULL);
 
+	account = gaim_connection_get_account(gc);
+	presence = gaim_account_get_presence(account);
+
 	qd = (qq_data *) gc->proto_data;
 	if (!qd->logged_in)
 		return;
 
-	switch (qd->status) {
-	case QQ_SELF_STATUS_AVAILABLE:
-		away_cmd = QQ_BUDDY_ONLINE_NORMAL;
-		break;
-	case QQ_SELF_STATUS_INVISIBLE:
+	if (gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_INVISIBLE)) {
 		away_cmd = QQ_BUDDY_ONLINE_INVISIBLE;
-		break;
-	case QQ_SELF_STATUS_AWAY:
-	case QQ_SELF_STATUS_IDLE:
-	case QQ_SELF_STATUS_CUSTOM:
+	} else if (gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_AWAY)
+			|| gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_EXTENDED_AWAY)
+			|| gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_UNAVAILABLE)) {
 		away_cmd = QQ_BUDDY_ONLINE_AWAY;
-		break;
-	default:
+	} else {
 		away_cmd = QQ_BUDDY_ONLINE_NORMAL;
 	}
 
@@ -191,6 +185,9 @@
 	qq_data *qd;
 	gint len;
 	guint8 *data, *cursor, reply;
+	GaimBuddy *b;
+	qq_buddy *q_bud;
+	gchar *name;
 
 	g_return_if_fail(gc != NULL && gc->proto_data != NULL);
 	g_return_if_fail(buf != NULL && buf_len != 0);
@@ -204,11 +201,17 @@
 		read_packet_b(data, &cursor, len, &reply);
 		if (reply != QQ_CHANGE_ONLINE_STATUS_REPLY_OK) {
 			gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Change status fail\n");
-		} else
+		} else {
 			gaim_debug(GAIM_DEBUG_INFO, "QQ", "Change status OK\n");
-	} else
+			name = uid_to_gaim_name(qd->uid);
+			b = gaim_find_buddy(gc->account, name);
+			g_free(name);
+			q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
+			qq_update_buddy_contact(gc, q_bud);
+		}
+	} else {
 		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt chg status reply\n");
-
+	}
 }
 
 /* it is a server message indicating that one of my buddies has changed its status */
@@ -236,11 +239,13 @@
 		bytes = 0;
 		/* 000-030: qq_buddy_status */
 		bytes += qq_buddy_status_read(data, &cursor, len, s);
-		/* 031-034: my uid */
+		/* 031-034: my uid */ 
+		/* This has a value of 0 when we've changed our status to 
+		 * QQ_BUDDY_ONLINE_INVISIBLE */
 		bytes += read_packet_dw(data, &cursor, len, &my_uid);
 
-		if (my_uid == 0 || bytes != 35) {
-			gaim_debug(GAIM_DEBUG_ERROR, "QQ", "my_uid == 0 || bytes(%d) != 35\n", bytes);
+		if (bytes != 35) {
+			gaim_debug(GAIM_DEBUG_ERROR, "QQ", "bytes(%d) != 35\n", bytes);
 			g_free(s->ip);
 			g_free(s->unknown_key);
 			g_free(s);
@@ -263,7 +268,7 @@
 			qq_update_buddy_contact(gc, q_bud);
 		} else {
 			gaim_debug(GAIM_DEBUG_ERROR, "QQ", 
-					"got information of unknown buddy by gfhuang %d\n", s->uid);
+					"got information of unknown buddy %d\n", s->uid);
 		}
 
 		g_free(s->ip);
--- a/libgaim/protocols/qq/buddy_status.h	Thu Aug 24 02:35:15 2006 +0000
+++ b/libgaim/protocols/qq/buddy_status.h	Thu Aug 24 07:00:34 2006 +0000
@@ -47,19 +47,11 @@
 	QQ_BUDDY_ONLINE_INVISIBLE = 0x28
 };
 
-enum {
-	QQ_SELF_STATUS_AVAILABLE = 0x11,
-	QQ_SELF_STATUS_AWAY = 0x12,
-	QQ_SELF_STATUS_INVISIBLE = 0x13,
-	QQ_SELF_STATUS_CUSTOM = 0x14,
-	QQ_SELF_STATUS_IDLE = 0x15
-};
- 
 void qq_buddy_status_dump_unclear(qq_buddy_status *s);
 gboolean is_online(guint8 status);
 
 gint qq_buddy_status_read(guint8 *data, guint8 **cursor, gint len, qq_buddy_status *s);
-gint get_icon_offset_from_self_status(guint8 status);
+gint get_icon_offset(GaimConnection *gc);
 
 void qq_send_packet_change_status(GaimConnection *gc);
 
--- a/libgaim/protocols/qq/keep_alive.c	Thu Aug 24 02:35:15 2006 +0000
+++ b/libgaim/protocols/qq/keep_alive.c	Thu Aug 24 07:00:34 2006 +0000
@@ -160,13 +160,13 @@
 			break;
 		default:
 			status_id = "invisible";
-			gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown status by gfhuang: %x\n", q_bud->status);
+			gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown status: %x\n", q_bud->status);
 			break;
 		}
 		gaim_debug(GAIM_DEBUG_INFO, "QQ", "set buddy %d to %s\n", q_bud->uid, status_id);
 		gaim_prpl_got_user_status(gc->account, name, status_id, NULL);
 	} else {
-		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown buddy by gfhuang: %d\n", q_bud->uid);
+		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown buddy: %d\n", q_bud->uid);
 	}
 
 	gaim_debug(GAIM_DEBUG_INFO, "QQ", "qq_update_buddy_contact, client=%04x\n", q_bud->client_version);
--- a/libgaim/protocols/qq/login_logout.c	Thu Aug 24 02:35:15 2006 +0000
+++ b/libgaim/protocols/qq/login_logout.c	Thu Aug 24 07:00:34 2006 +0000
@@ -231,11 +231,10 @@
 	/* Now goes on updating my icon/nickname, not showing info_window */
 	qd->modifying_face = FALSE;
 	qq_send_packet_get_info(gc, qd->uid, FALSE);
-	/* change my status manually, even server may broadcast my online */
-	qd->status = (qd->login_mode == QQ_LOGIN_MODE_HIDDEN) ? QQ_SELF_STATUS_INVISIBLE : QQ_SELF_STATUS_AVAILABLE;
+
 	qq_send_packet_change_status(gc);
+
 	/* now refresh buddy list */
-
 	/* changed by gfhuang, using With Qun version, error, not working still */
 	qq_send_packet_get_buddies_list(gc, QQ_FRIENDS_LIST_POSITION_START);
 	/* qq_send_packet_get_all_list_with_group(gc, QQ_FRIENDS_LIST_POSITION_START); */
--- a/libgaim/protocols/qq/login_logout.h	Thu Aug 24 02:35:15 2006 +0000
+++ b/libgaim/protocols/qq/login_logout.h	Thu Aug 24 07:00:34 2006 +0000
@@ -27,6 +27,7 @@
 #include "connection.h"
 
 #define QQ_LOGIN_MODE_NORMAL        0x0a
+#define QQ_LOGIN_MODE_AWAY	    0x1e
 #define QQ_LOGIN_MODE_HIDDEN        0x28
 
 void qq_send_packet_request_login_token(GaimConnection *gc);
--- a/libgaim/protocols/qq/qq.c	Thu Aug 24 02:35:15 2006 +0000
+++ b/libgaim/protocols/qq/qq.c	Thu Aug 24 07:00:34 2006 +0000
@@ -94,7 +94,7 @@
 	qq_data *qd;
 	GaimConnection *gc;
 	GaimPresence *presence;	
-	gboolean login_hidden, use_tcp;
+	gboolean use_tcp;
 
 	g_return_if_fail(account != NULL);
 
@@ -111,16 +111,16 @@
 	qq_port = gaim_account_get_string(account, "port", NULL);
 	use_tcp = gaim_account_get_bool(account, "use_tcp", FALSE);
         presence = gaim_account_get_presence(account);
-        login_hidden = gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_INVISIBLE);
 
 	qd->use_tcp = use_tcp;
 
-	if (login_hidden) {
+	if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_INVISIBLE)) {
 		qd->login_mode = QQ_LOGIN_MODE_HIDDEN;
-		gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login in hidden mode\n");
+	} else if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_AWAY)
+				|| gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_EXTENDED_AWAY)) {
+		qd->login_mode = QQ_LOGIN_MODE_AWAY;
 	} else {
 		qd->login_mode = QQ_LOGIN_MODE_NORMAL;
-		gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login in normal mode\n");
 	}
 
 	if (qq_server == NULL || strlen(qq_server) == 0)
@@ -258,7 +258,7 @@
                 emblems[0] = "offline";
 	} else {
 		/* TODO the wireless icon is a bit too big to look good with QQ faces */
-		if (q_bud->status == QQ_BUDDY_ONLINE_AWAY || q_bud->status == QQ_SELF_STATUS_AWAY)
+		if (q_bud->status == QQ_BUDDY_ONLINE_AWAY)
 			emblems[i++] = "away";
 		if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER)
 			emblems[i++] = "qq_member";
@@ -306,23 +306,6 @@
 static void _qq_set_away(GaimAccount *account, GaimStatus *status)
 {
 	GaimConnection *gc = gaim_account_get_connection(account);
-	const char *state = gaim_status_get_id(status);
-
-	qq_data *qd;
-	
-
-	g_return_if_fail(gc != NULL && gc->proto_data != NULL);
-
-	qd = (qq_data *) gc->proto_data;
-
-	if(0 == strcmp(state, "available"))
-		qd->status = QQ_SELF_STATUS_AVAILABLE;
-	else if (0 == strcmp(state, "away"))
-		qd->status = QQ_SELF_STATUS_AWAY;
-	else if (0 == strcmp(state, "invisible"))
-		qd->status = QQ_SELF_STATUS_INVISIBLE;
-	else
-		qd->status = QQ_SELF_STATUS_AVAILABLE;
 
 	qq_send_packet_change_status(gc);
 }
@@ -420,7 +403,7 @@
 	qd = (qq_data *) gc->proto_data;
 
 	field = gaim_request_fields_get_field(fields, "face_num");
-	suffix = get_icon_offset_from_self_status(qd->status);
+	suffix = get_icon_offset(gc);
 	qd->my_icon = gaim_request_field_choice_get_value(field) * 3 + suffix;
 	qd->modifying_face = TRUE;
 	qq_send_packet_get_info(gc, qd->uid, FALSE);
--- a/libgaim/protocols/qq/qq.h	Thu Aug 24 02:35:15 2006 +0000
+++ b/libgaim/protocols/qq/qq.h	Thu Aug 24 07:00:34 2006 +0000
@@ -64,7 +64,6 @@
 
 	guint16 send_seq;		/* send sequence number */
 	guint8 login_mode;		/* online of invisible */
-	guint8 status;
 	gboolean logged_in;		/* used by qq-add_buddy */
 	gboolean use_tcp;		/* network in tcp or udp */