changeset 9415:1c4092217e4a

[gaim-migrate @ 10230] " Adds support for status messages to Gadu Gadu. Please test Gaim support, as I have only been able to test it using a libgaim-style setting. May not apply cleanly to the plugin info section (callbacks) as I couldn't sync the latest commit there, it's not in anon-CVS yet. Should be easy to fix any conflict that occurs there." --Andrew Wellington please test committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 27 Jun 2004 18:19:09 +0000
parents f55fa0a2277e
children f63abdb00499
files ChangeLog src/protocols/gg/gg.c src/protocols/gg/libgg.c src/protocols/gg/libgg.h
diffstat 4 files changed, 130 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Jun 27 17:52:05 2004 +0000
+++ b/ChangeLog	Sun Jun 27 18:19:09 2004 +0000
@@ -3,6 +3,7 @@
 version 0.80cvs:
 	New Features:
 	* Support for the Epiphany web browser (Leonardo Serra)
+	* Status messages in Gadu-Gadu (Andrew (proton) Wellington)
 
 	Bug Fixes:
 	* The firefox browser option now works with firefox 0.9
--- a/src/protocols/gg/gg.c	Sun Jun 27 17:52:05 2004 +0000
+++ b/src/protocols/gg/gg.c	Sun Jun 27 18:19:09 2004 +0000
@@ -1,6 +1,6 @@
 /*
  * gaim - Gadu-Gadu Protocol Plugin
- * $Id: gg.c 10116 2004-06-19 04:57:43Z seanegan $
+ * $Id: gg.c 10230 2004-06-27 18:19:09Z lschiere $
  *
  * Copyright (C) 2001 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
  *
@@ -200,9 +200,47 @@
 		if (gd->own_status & GG_STATUS_FRIENDS_MASK)
 			status |= GG_STATUS_FRIENDS_MASK;
 	}
+	
+	if (msg) {
+	    switch (status) {
+		case GG_STATUS_AVAIL:
+		    status = GG_STATUS_AVAIL_DESCR;
+		    break;
+		case GG_STATUS_BUSY:
+		    status = GG_STATUS_BUSY_DESCR;
+		    break;
+		case GG_STATUS_INVISIBLE:
+		    status = GG_STATUS_INVISIBLE_DESCR;
+		    break;
+		case GG_STATUS_NOT_AVAIL:
+		    status = GG_STATUS_NOT_AVAIL_DESCR;
+		    break;
+	    }
+	}
 
 	gd->own_status = status;
-	gg_change_status(gd->sess, status);
+	if (msg)
+	    gg_change_status_descr(gd->sess, status, msg);
+	else
+	    gg_change_status(gd->sess, status);
+}
+
+static void agg_get_away(GaimConnection *gc, const char *who)
+{
+    GaimBuddy *buddy;
+    char *dialog_msg, **splitmsg;
+
+    if (invalid_uin(who))
+	return;
+    
+    buddy = gaim_find_buddy(gaim_connection_get_account(gc), who);
+    if (buddy->proto_data) {
+	/* Split at (carriage return/newline)'s, then rejoin later with BRs between. */
+	splitmsg = g_strsplit(buddy->proto_data, "\r\n", 0);
+    
+	dialog_msg = g_strdup_printf(_("<B>UIN:</B> %s<BR><B>Status:</B> %s<HR>%s"), who, (char *)buddy->proto_data, g_strjoinv("<BR>", splitmsg));
+	gaim_notify_formatted(gc, NULL, _("Buddy Information"), buddy->proto_data, dialog_msg, NULL, (char *)who);
+    }
 }
 
 static gchar *get_away_text(int uc)
@@ -476,28 +514,45 @@
 	case GG_EVENT_NOTIFY60:
 		{
 			gchar user[20];
-			struct gg_notify_reply60 *n = (void *)e->event.notify60;
 			guint status;
+			guint i = 0;
+
+			for (i = 0; e->event.notify60[i].uin; i++) {
+				GaimBuddy *buddy;
+				
+				g_snprintf(user, sizeof(user), "%lu", (long unsigned int)e->event.notify60[i].uin);
 
-			while (n->uin) {
-				switch (n->status) {
+				buddy = gaim_find_buddy(gaim_connection_get_account(gc), user);
+				if (buddy && buddy->proto_data != NULL) {
+					g_free(buddy->proto_data);
+					buddy->proto_data = NULL;
+				}
+			
+				switch (e->event.notify60[i].status) {
 				case GG_STATUS_NOT_AVAIL:
+				case GG_STATUS_NOT_AVAIL_DESCR:
 					status = UC_UNAVAILABLE;
 					break;
 				case GG_STATUS_AVAIL:
+				case GG_STATUS_AVAIL_DESCR:
 				case GG_STATUS_BUSY:
+				case GG_STATUS_BUSY_DESCR:
 				case GG_STATUS_INVISIBLE:
-					status = UC_NORMAL | (n->status << 5);
+				case GG_STATUS_INVISIBLE_DESCR:
+					status = UC_NORMAL | (e->event.notify60[i].status << 5);
 					break;
 				default:
 					status = UC_NORMAL;
 					break;
 				}
+				
+				if (buddy && e->event.notify60[i].descr != NULL) {
+					buddy->proto_data = g_strdup(e->event.notify60[i].descr);
+				}
 
-				g_snprintf(user, sizeof(user), "%lu", (long unsigned int)n->uin);
 				serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0,
 						status);
-				n++;
+				i++;
 			}
 		}
 		break;
@@ -530,21 +585,38 @@
 			gchar user[20];
 			guint status;
 
+			GaimBuddy *buddy;
+				
+			g_snprintf(user, sizeof(user), "%lu", e->event.status60.uin);
+
+			buddy = gaim_find_buddy(gaim_connection_get_account(gc), user);
+			if (buddy && buddy->proto_data != NULL) {
+				g_free(buddy->proto_data);
+				buddy->proto_data = NULL;
+			}
+
 			switch (e->event.status60.status) {
 			case GG_STATUS_NOT_AVAIL:
+			case GG_STATUS_NOT_AVAIL_DESCR:
 				status = UC_UNAVAILABLE;
 				break;
 			case GG_STATUS_AVAIL:
+			case GG_STATUS_AVAIL_DESCR:
 			case GG_STATUS_BUSY:
+			case GG_STATUS_BUSY_DESCR:
 			case GG_STATUS_INVISIBLE:
+			case GG_STATUS_INVISIBLE_DESCR:
 				status = UC_NORMAL | (e->event.status60.status << 5);
 				break;
 			default:
 				status = UC_NORMAL;
 				break;
 			}
-
-			g_snprintf(user, sizeof(user), "%lu", e->event.status60.uin);
+    
+			if (buddy && e->event.status60.descr != NULL) {
+				buddy->proto_data = g_strdup(e->event.status60.descr);
+			}
+			    
 			serv_got_update(gc, user, (status == UC_UNAVAILABLE) ? 0 : 1, 0, 0, 0,
 					status);
 		}
@@ -823,6 +895,14 @@
 	agg_save_buddy_list(gc, NULL);
 }
 
+static void agg_buddy_free (GaimBuddy *buddy)
+{
+    if (buddy->proto_data) {
+	g_free(buddy->proto_data);
+	buddy->proto_data = NULL;
+    }
+}
+
 static void search_results(GaimConnection *gc, gchar *webdata)
 {
 	gchar **webdata_tbl;
@@ -1573,7 +1653,7 @@
 	NULL,
 	agg_group_buddy,
 	agg_rename_group,
-	NULL,
+	agg_buddy_free,
 	NULL,
 	NULL,
 	NULL,
--- a/src/protocols/gg/libgg.c	Sun Jun 27 17:52:05 2004 +0000
+++ b/src/protocols/gg/libgg.c	Sun Jun 27 18:19:09 2004 +0000
@@ -1,4 +1,4 @@
-/* $Id: libgg.c 10064 2004-06-11 03:58:48Z eblanton $ */
+/* $Id: libgg.c 10230 2004-06-27 18:19:09Z lschiere $ */
 
 /*
  *  (C) Copyright 2001 Wojtek Kaniewski <wojtekka@irc.pl>,
@@ -73,7 +73,7 @@
 #ifdef __GNUC__
 __attribute__ ((unused))
 #endif
-= "$Id: libgg.c 10064 2004-06-11 03:58:48Z eblanton $";
+= "$Id: libgg.c 10230 2004-06-27 18:19:09Z lschiere $";
 
 #endif 
 
@@ -592,6 +592,38 @@
 }
 
 /*
+ * gg_change_status_descr()
+ *
+ * zmienia status uøytkownika na opisowy.
+ *
+ *  - sess - opis sesji
+ *  - status - nowy status uøytkownika
+ *  - descr - opis statusu
+ *
+ * 0, -1.
+ */
+int gg_change_status_descr(struct gg_session *sess, int status, const char *descr)
+{
+	struct gg_new_status p;
+
+	gg_debug(GG_DEBUG_FUNCTION, "** gg_change_status_descr(%p, %d, \"%s\");\n", sess, status, descr);
+
+	if (!sess || !descr) {
+		errno = EFAULT;
+		return -1;
+	}
+
+	if (sess->state != GG_STATE_CONNECTED) {
+		errno = ENOTCONN;
+		return -1;
+	}
+
+	p.status = fix32(status);
+
+	return gg_send_packet(sess, GG_NEW_STATUS, &p, sizeof(p), descr, (strlen(descr) > GG_STATUS_DESCR_MAXSIZE) ? GG_STATUS_DESCR_MAXSIZE : strlen(descr), NULL);
+}
+
+/*
  * gg_logoff()
  *
  * wylogowuje użytkownika i zamyka poł±czenie.
--- a/src/protocols/gg/libgg.h	Sun Jun 27 17:52:05 2004 +0000
+++ b/src/protocols/gg/libgg.h	Sun Jun 27 18:19:09 2004 +0000
@@ -1,4 +1,4 @@
-/* $Id: libgg.h 10064 2004-06-11 03:58:48Z eblanton $ */
+/* $Id: libgg.h 10230 2004-06-27 18:19:09Z lschiere $ */
 
 /*
  *  (C) Copyright 2001 Wojtek Kaniewski <wojtekka@irc.pl>,
@@ -162,6 +162,7 @@
 void gg_logoff(struct gg_session *sess);
 int gg_write(struct gg_session *sess, const char *buf, int length);
 int gg_change_status(struct gg_session *sess, int status);
+int gg_change_status_descr(struct gg_session *sess, int status, const char *descr);
 int gg_send_message(struct gg_session *sess, int msgclass, uin_t recipient, const unsigned char *message);
 int gg_send_message_richtext(struct gg_session *sess, int msgclass, uin_t recipient, const unsigned char *message, const unsigned char *format, int formatlen);
 int gg_ping(struct gg_session *sess);
@@ -531,6 +532,8 @@
 
 #define GG_STATUS_FRIENDS_MASK 0x8000		/* tylko dla znajomych (4.6) */
 
+#define GG_STATUS_DESCR_MAXSIZE 70
+
 /* GG_S() stan bez uwzględnienia trybu tylko dla znajomych */
 #define GG_S(x) ((x) & ~GG_STATUS_FRIENDS_MASK)