changeset 31641:a47a82a009bf

propagate from branch 'im.pidgin.pidgin.mxit' (head 60960f69854c3b350f48451efaf9adbe770bd810) to branch 'im.pidgin.pidgin' (head 752daf02d2f9e9917b9b36fdecdb7719efe07391)
author Ethan Blanton <elb@pidgin.im>
date Mon, 06 Jun 2011 21:46:57 +0000
parents 5b51e5fb8d76 (diff) 8b434ffd4efc (current diff)
children 7db601938f95
files ChangeLog libpurple/protocols/mxit/protocol.c
diffstat 5 files changed, 149 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jun 06 20:13:30 2011 +0000
+++ b/ChangeLog	Mon Jun 06 21:46:57 2011 +0000
@@ -98,6 +98,10 @@
 	* The Change PIN option was moved into separate action.
 	* New profile attributes added and shown.
 	* Update to protocol v6.3.
+	* Added the ability to view and invite your Suggested Friends,
+	  and to search for contacts.
+	* Also display the Status Message of offline contacts in their
+	  profile information.
 
 	XMPP:
 	* Remember the previously entered user directory when searching.
--- a/libpurple/protocols/mxit/profile.c	Mon Jun 06 20:13:30 2011 +0000
+++ b/libpurple/protocols/mxit/profile.c	Mon Jun 06 21:46:57 2011 +0000
@@ -166,6 +166,7 @@
 	PurpleNotifyUserInfo*	info		= purple_notify_user_info_new();
 	struct contact*			contact		= NULL;
 	PurpleBuddy*			buddy;
+	gchar*					tmp			= NULL;
 
 	buddy = purple_find_buddy( session->acc, username );
 	if ( buddy ) {
@@ -175,7 +176,11 @@
 	}
 
 	purple_notify_user_info_add_pair( info, _( "Display Name" ), profile->nickname );
-	purple_notify_user_info_add_pair( info, _( "Birthday" ), profile->birthday );
+
+	tmp = g_strdup_printf("%s (%i)", profile->birthday, calculateAge( profile->birthday ) );
+	purple_notify_user_info_add_pair( info, _( "Birthday" ), tmp );
+	g_free( tmp );
+
 	purple_notify_user_info_add_pair( info, _( "Gender" ), profile->male ? _( "Male" ) : _( "Female" ) );
 
 	/* optional information */
@@ -282,6 +287,10 @@
 	purple_notify_searchresults_column_add( results, column );
 	column = purple_notify_searchresults_column_new( _( "Display Name" ) );
 	purple_notify_searchresults_column_add( results, column );
+	column = purple_notify_searchresults_column_new( _( "First Name" ) );
+	purple_notify_searchresults_column_add( results, column );
+	column = purple_notify_searchresults_column_new( _( "Last Name" ) );
+	purple_notify_searchresults_column_add( results, column );
 	column = purple_notify_searchresults_column_new( _( "Gender" ) );
 	purple_notify_searchresults_column_add( results, column );
 	column = purple_notify_searchresults_column_new( _( "Age" ) );
@@ -292,16 +301,21 @@
 	while (entries != NULL) {
 		struct MXitProfile* profile	= ( struct MXitProfile *) entries->data;
 		GList*	row;
+		gchar* tmp = purple_base64_encode( (unsigned char *) profile->userid, strlen( profile->userid ) );
 
 		/* column values */
-		row = g_list_append( NULL, g_strdup( profile->userid ) );
+		row = g_list_append( NULL, g_strdup_printf( "#%s", tmp ) );
 		row = g_list_append( row, g_strdup( profile->nickname ) );
+		row = g_list_append( row, g_strdup( profile->firstname ) );
+		row = g_list_append( row, g_strdup( profile->lastname ) );
 		row = g_list_append( row, g_strdup( profile->male ? "Male" : "Female" ) );
 		row = g_list_append( row, g_strdup_printf( "%i", calculateAge( profile->birthday ) ) );
 		row = g_list_append( row, g_strdup( profile->whereami ) );
 
 		purple_notify_searchresults_row_add( results, row );
 		entries = g_list_next( entries );
+
+		g_free( tmp );
 	}
 
 	/* button */
--- a/libpurple/protocols/mxit/protocol.c	Mon Jun 06 20:13:30 2011 +0000
+++ b/libpurple/protocols/mxit/protocol.c	Mon Jun 06 21:46:57 2011 +0000
@@ -1763,7 +1763,7 @@
 	int						count;
 	int						i;
 	const char*				avatarId	= NULL;
-	const char*				statusMsg	= NULL;
+	char*					statusMsg	= NULL;
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_parse_cmd_extprofile: profile for '%s'\n", mxitId );
 
@@ -1820,7 +1820,7 @@
 		}
 		else if ( strcmp( CP_PROFILE_STATUS, fname ) == 0 ) {
 			/* status message - just keep a reference to the value */
-			statusMsg = fvalue;
+			statusMsg = g_markup_escape_text( fvalue, -1 );
 		}
 		else if ( strcmp( CP_PROFILE_AVATAR, fname ) == 0 ) {
 			/* avatar id - just keep a reference to the value */
@@ -1907,10 +1907,29 @@
 			/* this is a contact */
 			if ( avatarId )
 				mxit_update_buddy_avatar( session, mxitId, avatarId );
+
+			if ( ( statusMsg ) && ( strlen( statusMsg ) > 0 ) ) {
+				/* update the status message */
+				PurpleBuddy*		buddy	= NULL;
+
+				buddy = purple_find_buddy( session->acc, mxitId );
+				if ( buddy ) {
+					contact = purple_buddy_get_protocol_data( buddy );
+					if ( contact ) {
+						if ( contact->statusMsg )
+							g_free( contact->statusMsg );
+						contact->statusMsg = strdup( statusMsg );
+					}
+				}
+			}
+
+			/* show the profile */
 			mxit_show_profile( session, mxitId, profile );
 			g_free( profile );
 		}
 	}
+
+	g_free( statusMsg );
 }
 
 
@@ -1967,6 +1986,14 @@
 				/* birthdate */
 				g_strlcpy( profile->birthday, fvalue, sizeof( profile->birthday ) );
 			}
+			else if ( strcmp( CP_PROFILE_FIRSTNAME, fname ) == 0 ) {
+				/* first name */
+				g_strlcpy( profile->firstname, fvalue, sizeof( profile->firstname ) );
+			}
+			else if ( strcmp( CP_PROFILE_LASTNAME, fname ) == 0 ) {
+				/* last name */
+				g_strlcpy( profile->lastname, fvalue, sizeof( profile->lastname ) );
+			}
 			else if ( strcmp( CP_PROFILE_GENDER, fname ) == 0 ) {
 				/* gender */
 				profile->male = ( fvalue[0] == '1' );
@@ -2099,6 +2126,7 @@
 					if ( contact ) {
 						/* this is an invite (add image to the internal image store) */
 						contact->imgid = purple_imgstore_add_with_id( chunk.data, chunk.length, NULL );
+						/* show the profile */
 						mxit_show_profile( session, chunk.mxitid, contact->profile );
 					}
 					else {
--- a/libpurple/protocols/mxit/roster.c	Mon Jun 06 20:13:30 2011 +0000
+++ b/libpurple/protocols/mxit/roster.c	Mon Jun 06 21:46:57 2011 +0000
@@ -474,7 +474,7 @@
 	contact->capabilities = flags;
 
 	/* validate mood */
-	if (( contact->mood < MXIT_MOOD_NONE ) || ( contact->mood > MXIT_MOOD_STRESSED ))
+	if ( ( contact->mood < MXIT_MOOD_NONE ) || ( contact->mood > MXIT_MOOD_STRESSED ) )
 		contact->mood = MXIT_MOOD_NONE;
 
 	g_strlcpy( contact->customMood, customMood, sizeof( contact->customMood ) );
@@ -485,7 +485,7 @@
 		g_free( contact->statusMsg );
 		contact->statusMsg = NULL;
 	}
-	if ( statusMsg[0] != '\0' )
+	if ( ( statusMsg ) && ( statusMsg[0] != '\0' ) )
 		contact->statusMsg = g_markup_escape_text( statusMsg, -1 );
 
 	/* update the buddy's status (reference: "libpurple/prpl.h") */
@@ -747,7 +747,14 @@
 		 * you accept an invite.  so in that case the user is already
 		 * in our blist and ready to be chatted to.
 		 */
-		mxit_send_invite( session, buddy_name, TRUE, buddy_alias, group_name, message );
+
+		if ( buddy_name[0] == '#' ) {
+			gchar *tmp = (gchar*) purple_base64_decode( buddy_name + 1, NULL );
+			mxit_send_invite( session, tmp, FALSE, buddy_alias, group_name, message );
+			g_free( tmp );
+		}
+		else
+			mxit_send_invite( session, buddy_name, TRUE, buddy_alias, group_name, message );
 	}
 	else {
 		purple_debug_info( MXIT_PLUGIN_ID, "mxit_add_buddy (scenario 2) (list:%i)\n", g_slist_length( list ) );
--- a/libpurple/protocols/mxit/voicevideo.c	Mon Jun 06 20:13:30 2011 +0000
+++ b/libpurple/protocols/mxit/voicevideo.c	Mon Jun 06 21:46:57 2011 +0000
@@ -109,6 +109,59 @@
 }
 
 
+static void mxit_candidates_prepared_cb(PurpleMedia* media, gchar* sessionid, gchar* who, void* session)
+{
+	purple_debug_info(MXIT_PLUGIN_ID, "mxit_candidates_prepared_cb: buddy '%s', session '%s'\n", who, sessionid);
+
+	if (purple_media_is_initiator(media, sessionid, who)) {
+		// TODO: Send INVITE via SIP.
+	}
+	else {
+		// TODO: ??
+	}
+}
+
+static void mxit_stream_info_cb(PurpleMedia* media, PurpleMediaInfoType type, char* sessionid, gchar* who, gboolean local, void* session)
+{
+	purple_debug_info(MXIT_PLUGIN_ID, "mxit_stream_info_cb: buddy '%s', session '%s', info %d \n", who, sessionid, type);
+
+	switch (type) {
+		case PURPLE_MEDIA_INFO_HANGUP:
+			break;
+		case PURPLE_MEDIA_INFO_ACCEPT:
+			break;
+		case PURPLE_MEDIA_INFO_REJECT:
+			break;
+		case PURPLE_MEDIA_INFO_MUTE:
+			break;
+		case PURPLE_MEDIA_INFO_UNMUTE:
+			break;
+		case PURPLE_MEDIA_INFO_PAUSE:
+			break;
+		case PURPLE_MEDIA_INFO_UNPAUSE:
+			break;
+		case PURPLE_MEDIA_INFO_HOLD:
+			break;
+		case PURPLE_MEDIA_INFO_UNHOLD:
+			break;
+	}
+}
+
+static void mxit_state_changed_cb(PurpleMedia* media, PurpleMediaState state, gchar* sessionid, char* who, void* session)
+{
+	purple_debug_info(MXIT_PLUGIN_ID, "mxit_state_changed_cb: buddy '%s', session '%s', state %d\n", who, sessionid, state);
+
+	switch (state) {
+		case PURPLE_MEDIA_STATE_NEW:
+			break;
+		case PURPLE_MEDIA_STATE_CONNECTED:
+			break;
+		case PURPLE_MEDIA_STATE_END:
+			break;
+	}
+}
+
+
 /*------------------------------------------------------------------------
  * Initiate a voice/video session with a contact.
  *
@@ -119,9 +172,44 @@
  */
 gboolean mxit_media_initiate(PurpleAccount *account, const char *who, PurpleMediaSessionType type)
 {
+	gchar* transmitter = "rawudp";
+	PurpleMedia* media = NULL;
+
 	purple_debug_info(MXIT_PLUGIN_ID, "mxit_media_initiate: buddy '%s'\n", who);
 
-	return FALSE;
+	media = purple_media_manager_create_media(
+		purple_media_manager_get(),
+		account,
+		"fsrtpconference",
+		who,
+		TRUE
+	);
+
+	if (!media) {
+		purple_debug_info(MXIT_PLUGIN_ID, "mxit_media_initiate: could not create media session\n");
+		return FALSE;
+	}
+
+	/* attach callbacks */
+	g_signal_connect(G_OBJECT(media), "candidates-prepared", G_CALLBACK(mxit_candidates_prepared_cb), NULL);
+	g_signal_connect(G_OBJECT(media), "stream-info", G_CALLBACK(mxit_stream_info_cb), NULL);
+	g_signal_connect(G_OBJECT(media), "state-changed", G_CALLBACK(mxit_state_changed_cb), NULL);
+
+	/* initiate audio session */
+	if ((type & PURPLE_MEDIA_AUDIO) && 
+			(!purple_media_add_stream(media, "audio", who, PURPLE_MEDIA_AUDIO, TRUE, transmitter, 0, NULL))) {
+		purple_media_end(media, NULL, NULL);
+		return FALSE;
+	}
+
+	/* initiate video session */
+	if ((type & PURPLE_MEDIA_VIDEO) &&
+			(!purple_media_add_stream(media, "video", who, PURPLE_MEDIA_VIDEO, TRUE, transmitter, 0, NULL))) {
+		purple_media_end(media, NULL, NULL);
+		return FALSE;
+	}
+
+	return TRUE;
 }
 
 #else