soc.2009.transport: 72aae753: VCard handling moved from vcardhandler t...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Thu Jun 4 09:06:11 EDT 2009


-----------------------------------------------------------------
Revision: 72aae753d4a87754326c8b4683e549e8cba01171
Ancestor: cc6f4260630e2c685ba168c7c05a5f02805db4b4
Author: hanzz at soc.pidgin.im
Date: 2009-06-04T13:03:09
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/72aae753d4a87754326c8b4683e549e8cba01171

Modified files:
        protocols/abstractprotocol.h protocols/facebook.cpp
        protocols/facebook.h protocols/gg.h protocols/icq.cpp
        protocols/icq.h vcardhandler.cpp

ChangeLog: 

VCard handling moved from vcardhandler to protocols class. Added simple support for VCard for Facebook (mainly to test trananslation class).

-------------- next part --------------
============================================================
--- protocols/abstractprotocol.h	1f040c126cc65db67ecbb0f8c0a70b8be915f908
+++ protocols/abstractprotocol.h	a465917ba088118515e655568c2df0af6d0a820a
@@ -23,7 +23,12 @@
 
 #include <string>
 #include <list>
+#include "glib.h"
+#include "gloox/tag.h"
+#include "../user.h"
 
+using namespace gloox;
+
 class AbstractProtocol
 {
 	public:
@@ -56,6 +61,10 @@ class AbstractProtocol
 		 * Returns pregenerated text according to key
 		 */
 		virtual std::string text(const std::string &key) = 0;
+		/*
+		 * Returns VCard Tag*
+		 */
+		virtual Tag *getVCardTag(User *user, GList *vcardEntries) = 0;
 };
 
 #endif
============================================================
--- protocols/facebook.cpp	3eb4d18a879356cdbf7d8946c6e5e4e86f0ee884
+++ protocols/facebook.cpp	920d502b4fe0a4e5395baaf6f2d2485ac0b5ffd6
@@ -98,3 +98,73 @@ std::string FacebookProtocol::text(const
 		return "Enter your Facebook email and password:";
 	return "not defined";
 }
+
+Tag *FacebookProtocol::getVCardTag(User *user, GList *vcardEntries) {
+	PurpleNotifyUserInfoEntry *vcardEntry;
+	std::string firstName;
+	std::string lastName;
+	std::string header;
+	std::string label;
+	std::string description("");
+
+	Tag *vcard = new Tag( "vCard" );
+	vcard->addAttribute( "xmlns", "vcard-temp" );
+
+	while (vcardEntries) {
+		vcardEntry = (PurpleNotifyUserInfoEntry *)(vcardEntries->data);
+		if (purple_notify_user_info_entry_get_label(vcardEntry) && purple_notify_user_info_entry_get_value(vcardEntry)){
+			label = (std::string) purple_notify_user_info_entry_get_label(vcardEntry);
+			Log().Get("vcard label") << label << " => " << (std::string)purple_notify_user_info_entry_get_value(vcardEntry);
+			if (label==tr(user->getLang(),"Gender")){
+				vcard->addChild( new Tag("GENDER", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label==tr(user->getLang(),"Name")){
+				vcard->addChild( new Tag("FN", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label==tr(user->getLang(),"Birthday")){
+				vcard->addChild( new Tag("BDAY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label==tr(user->getLang(),"Mobile")) {
+				Tag *tel = new Tag("TEL");
+				tel->addChild ( new Tag("CELL") );
+				tel->addChild ( new Tag("NUMBER", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)) );
+				vcard->addChild(tel);
+			}
+			else {
+				std::string k(purple_notify_user_info_entry_get_value(vcardEntry));
+				if (!k.empty()) {
+					description+= label + ": " + k + "\n\n";
+				}
+			}
+		}
+		else if (purple_notify_user_info_entry_get_type(vcardEntry)==PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER){
+			header = (std::string)purple_notify_user_info_entry_get_label(vcardEntry);
+			Log().Get("vcard header") << header;
+// 			if (head)
+// 				if (!head->children().empty())
+// 					vcard->addChild(head);
+// 			if (header=="Home Address"){
+// 				head = new Tag("ADR");
+// 				head->addChild(new Tag("HOME"));
+// 			}
+// 			if (header=="Work Address"){
+// 				head = new Tag("ADR");
+// 				head->addChild(new Tag("WORK"));
+// 			}
+// 			if (header=="Work Information"){
+// 				head = new Tag("ORG");
+// 			}
+		}
+		vcardEntries = vcardEntries->next;
+	}
+	
+	// add last head if any
+// 	if (head)
+// 		if (!head->children().empty())
+// 			vcard->addChild(head);
+	vcard->addChild( new Tag("DESC", description));
+	
+
+	return vcard;
+}
+
============================================================
--- protocols/facebook.h	db5d0a4da098fb78fff4dbde2d1db2ebc90f597c
+++ protocols/facebook.h	033c22b317a94dacfd7b649680cb1208e7b62a23
@@ -24,6 +24,7 @@ class GlooxMessageHandler;
 #include "abstractprotocol.h"
 
 class GlooxMessageHandler;
+extern Localization localization;
 
 class FacebookProtocol : AbstractProtocol
 {
@@ -37,6 +38,7 @@ class FacebookProtocol : AbstractProtoco
 		std::list<std::string> transportFeatures();
 		std::list<std::string> buddyFeatures();
 		std::string text(const std::string &key);
+		Tag *getVCardTag(User *user, GList *vcardEntries);
 		
 		std::string replace(std::string &str, const char *string_to_replace, const char *new_string);
 	
============================================================
--- protocols/gg.h	e56ab9d7aeafcccd89411a28358120a9bb80ffc3
+++ protocols/gg.h	e291b5a76382c26cb6a086e2192c64a129f68eb6
@@ -37,6 +37,7 @@ class GGProtocol : AbstractProtocol
 		std::list<std::string> transportFeatures();
 		std::list<std::string> buddyFeatures();
 		std::string text(const std::string &key);
+		Tag *getVCardTag(User *user, GList *vcardEntries) { return NULL; }
 		
 		std::string replace(std::string &str, const char *string_to_replace, const char *new_string);
 	
============================================================
--- protocols/icq.cpp	715dac537bfc443a8774411e0312dc427c4a5e27
+++ protocols/icq.cpp	0146781a3b964a055d8f2a91672f68facdd81532
@@ -80,3 +80,95 @@ std::string ICQProtocol::text(const std:
 	return "not defined";
 }
 
+Tag *ICQProtocol::getVCardTag(User *user, GList *vcardEntries) {
+	Tag *N = new Tag("N");
+	Tag *head = new Tag("ADR");
+	PurpleNotifyUserInfoEntry *vcardEntry;
+	std::string firstName;
+	std::string lastName;
+	std::string header;
+	std::string label;
+
+	Tag *vcard = new Tag( "vCard" );
+	vcard->addAttribute( "xmlns", "vcard-temp" );
+
+	while (vcardEntries) {
+		vcardEntry = (PurpleNotifyUserInfoEntry *)(vcardEntries->data);
+		if (purple_notify_user_info_entry_get_label(vcardEntry) && purple_notify_user_info_entry_get_value(vcardEntry)){
+			label=(std::string)purple_notify_user_info_entry_get_label(vcardEntry);
+			Log().Get("vcard label") << label << " => " << (std::string)purple_notify_user_info_entry_get_value(vcardEntry);
+			if (label=="First Name"){
+				N->addChild( new Tag("GIVEN", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+				firstName = (std::string)purple_notify_user_info_entry_get_value(vcardEntry);
+			}
+			else if (label=="Last Name"){
+				N->addChild( new Tag("FAMILY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+				lastName = (std::string)purple_notify_user_info_entry_get_value(vcardEntry);
+			}
+			else if (label=="Gender"){
+				vcard->addChild( new Tag("GENDER", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label=="Nick"){
+				vcard->addChild( new Tag("NICKNAME", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label=="Birthday"){
+				vcard->addChild( new Tag("BDAY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label=="UIN"){
+				vcard->addChild( new Tag("UID", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label=="City"){
+				head->addChild( new Tag("LOCALITY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label=="State"){
+				head->addChild( new Tag("CTRY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label=="Company"){
+				head->addChild( new Tag("ORGNAME", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label=="Division"){
+				head->addChild( new Tag("ORGUNIT", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label=="Position"){
+				vcard->addChild( new Tag("TITLE", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
+			}
+			else if (label=="Personal Web Page"){
+				std::string page = (std::string)purple_notify_user_info_entry_get_value(vcardEntry);
+				
+				//vcard->addChild( new Tag("URL", stripHTMLTags(page)));
+				//vcard->addChild( new Tag("URL", page));
+			}
+		}
+		else if (purple_notify_user_info_entry_get_type(vcardEntry)==PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER){
+			header = (std::string)purple_notify_user_info_entry_get_label(vcardEntry);
+			if (head)
+				if (!head->children().empty())
+					vcard->addChild(head);
+			if (header=="Home Address"){
+				head = new Tag("ADR");
+				head->addChild(new Tag("HOME"));
+			}
+			if (header=="Work Address"){
+				head = new Tag("ADR");
+				head->addChild(new Tag("WORK"));
+			}
+			if (header=="Work Information"){
+				head = new Tag("ORG");
+			}
+		}
+		vcardEntries = vcardEntries->next;
+	}
+	// add last head if any
+	if (head)
+		if (!head->children().empty())
+			vcard->addChild(head);
+	// combine first name and last name to full name
+	if (!firstName.empty() || !lastName.empty())
+		vcard->addChild( new Tag("FN", firstName + " " + lastName));
+	// add photo ant N if any
+	if(!N->children().empty())
+		vcard->addChild(N);
+
+	return vcard;
+}
+
============================================================
--- protocols/icq.h	d6039d86545350beddf0bea3a6f561b7e46eeb53
+++ protocols/icq.h	f0a24f0e9b3480870d210c503a356b6613410f38
@@ -37,6 +37,7 @@ class ICQProtocol : AbstractProtocol
 		std::list<std::string> transportFeatures();
 		std::list<std::string> buddyFeatures();
 		std::string text(const std::string &key);
+		Tag *getVCardTag(User *user, GList *vcardEntries);
 		
 		std::string replace(std::string &str, const char *string_to_replace, const char *new_string);
 	
============================================================
--- vcardhandler.cpp	f0b141a97d9598e6e0f18d5a1db74a110d85ec40
+++ vcardhandler.cpp	2f8abaade2d7eba3cc615b7e23953bec3f18441f
@@ -22,6 +22,7 @@
 #include "usermanager.h"
 #include "log.h"
 #include "gloox/vcard.h"
+#include "protocols/abstractprotocol.h"
 
 void base64encode(const unsigned char * input, int len, std::string & out)
 {
@@ -125,9 +126,7 @@ void GlooxVCardHandler::userInfoArrived(
 
 void GlooxVCardHandler::userInfoArrived(PurpleConnection *gc,std::string who, PurpleNotifyUserInfo *user_info){
 	GList *vcardEntries = purple_notify_user_info_get_entries(user_info);
-	std::string label;
 	User *user = p->userManager()->getUserByAccount(purple_connection_get_account(gc));
-	PurpleNotifyUserInfoEntry *vcardEntry;
 
 	if (user!=NULL){
 		if (!user->isConnected())
@@ -140,14 +139,14 @@ void GlooxVCardHandler::userInfoArrived(
 		reply->addAttribute( "type", "result" );
 		reply->addAttribute( "to", vcardRequests[who].back() );
 		reply->addAttribute( "from", who+"@"+p->jid() );
-		Tag *vcard = new Tag( "vCard" );
-		vcard->addAttribute( "xmlns", "vcard-temp" );
-		Tag *N = new Tag("N");
-		Tag *head = new Tag("ADR");
+
+		Tag *vcard = p->protocol()->getVCardTag(user, vcardEntries);
+		if (!vcard) {
+			Tag *vcard = new Tag( "vCard" );
+			vcard->addAttribute( "xmlns", "vcard-temp" );
+		}
+
 		Tag *photo = new Tag("PHOTO");
-		std::string firstName;
-		std::string lastName;
-		std::string header;
 
 		PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(gc), who.c_str());
 		if (buddy){
@@ -169,83 +168,6 @@ void GlooxVCardHandler::userInfoArrived(
 			}
 		}
 
-
-		while (vcardEntries) {
-			vcardEntry = (PurpleNotifyUserInfoEntry *)(vcardEntries->data);
-			if (purple_notify_user_info_entry_get_label(vcardEntry) && purple_notify_user_info_entry_get_value(vcardEntry)){
-				label=(std::string)purple_notify_user_info_entry_get_label(vcardEntry);
-				Log().Get("vcard label") << label << " => " << (std::string)purple_notify_user_info_entry_get_value(vcardEntry);
-				if (label=="First Name"){
-					N->addChild( new Tag("GIVEN", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
-					firstName = (std::string)purple_notify_user_info_entry_get_value(vcardEntry);
-				}
-				else if (label=="Last Name"){
-					N->addChild( new Tag("FAMILY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
-					lastName = (std::string)purple_notify_user_info_entry_get_value(vcardEntry);
-				}
-				else if (label=="Gender"){
-					vcard->addChild( new Tag("GENDER", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
-				}
-				else if (label=="Nick"){
-					vcard->addChild( new Tag("NICKNAME", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
-				}
-				else if (label=="Birthday"){
-					vcard->addChild( new Tag("BDAY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
-				}
-				else if (label=="UIN"){
-					vcard->addChild( new Tag("UID", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
-				}
-				else if (label=="City"){
-					head->addChild( new Tag("LOCALITY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
-				}
-				else if (label=="State"){
-					head->addChild( new Tag("CTRY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
-				}
-				else if (label=="Company"){
-					head->addChild( new Tag("ORGNAME", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
-				}
-				else if (label=="Division"){
-					head->addChild( new Tag("ORGUNIT", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
-				}
-				else if (label=="Position"){
-					vcard->addChild( new Tag("TITLE", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
-				}
-				else if (label=="Personal Web Page"){
-					std::string page = (std::string)purple_notify_user_info_entry_get_value(vcardEntry);
-					
-// 					vcard->addChild( new Tag("URL", stripHTMLTags(page)));
-// 					vcard->addChild( new Tag("URL", page));
-				}
-			}
-			else if (purple_notify_user_info_entry_get_type(vcardEntry)==PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER){
-				header = (std::string)purple_notify_user_info_entry_get_label(vcardEntry);
-				if (head)
-					if (!head->children().empty())
-						vcard->addChild(head);
-				if (header=="Home Address"){
-					head = new Tag("ADR");
-					head->addChild(new Tag("HOME"));
-				}
-				if (header=="Work Address"){
-					head = new Tag("ADR");
-					head->addChild(new Tag("WORK"));
-				}
-				if (header=="Work Information"){
-					head = new Tag("ORG");
-				}
-			}
-			vcardEntries = vcardEntries->next;
-		}
-		// add last head if any
-		if (head)
-			if (!head->children().empty())
-				vcard->addChild(head);
-		// combine first name and last name to full name
-		if (!firstName.empty() || !lastName.empty())
-			vcard->addChild( new Tag("FN", firstName + " " + lastName));
-		// add photo ant N if any
-		if(!N->children().empty())
-			vcard->addChild(N);
 		if(!photo->children().empty())
 			vcard->addChild(photo);
 


More information about the Commits mailing list