soc.2009.transport: e96221a7: Enable avatars setting

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Thu Jun 18 01:25:34 EDT 2009


-----------------------------------------------------------------
Revision: e96221a7f8006e942c520f9d236ad79c3152f99b
Ancestor: 346bc59b5b65740cd014788fd6ef1f797ca0458e
Author: hanzz at soc.pidgin.im
Date: 2009-06-16T10:20:51
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/e96221a7f8006e942c520f9d236ad79c3152f99b

Modified files:
        adhocsettings.cpp user.cpp vcardhandler.cpp

ChangeLog: 

Enable avatars setting

-------------- next part --------------
============================================================
--- adhocsettings.cpp	e180005b2d84171f013e03e2368eda311019f5c4
+++ adhocsettings.cpp	ee7f59a0e4c2b19dda4452c4f84b202bfd58855a
@@ -72,6 +72,17 @@ AdhocSettings::AdhocSettings(GlooxMessag
 		field->addChild(new Tag("value","0"));
 	xdata->addChild(field);
 
+	field = new Tag("field");
+	field->addAttribute("type","boolean");
+	field->addAttribute("label","Enable avatars");
+	field->addAttribute("var","enable_avatars");
+	value = m_user->getSetting("enable_avatars");
+	if (purple_value_get_boolean(value))
+		field->addChild(new Tag("value","1"));
+	else
+		field->addChild(new Tag("value","0"));
+	xdata->addChild(field);
+
 	c->addChild(xdata);
 	response->addChild(c);
 	main->j->send(response);
============================================================
--- user.cpp	edb4c76e12644bc91ba8ceef42c7aa5a63937a7d
+++ user.cpp	79434030301d6c8a4693c118336cdc22f68ef2cb
@@ -71,6 +71,12 @@ User::User(GlooxMessageHandler *parent, 
 		purple_value_set_boolean(value, true);
 		g_hash_table_replace(m_settings, g_strdup("enable_transport"), value);
 	}
+	if ( (value = getSetting("enable_avatars")) == NULL ) {
+		p->sql()->addSetting(m_jid, "enable_avatars", "1", PURPLE_TYPE_BOOLEAN);
+		value = purple_value_new(PURPLE_TYPE_BOOLEAN);
+		purple_value_set_boolean(value, true);
+		g_hash_table_replace(m_settings, g_strdup("enable_avatars"), value);
+	}
 }
 
 bool User::syncCallback() {
@@ -310,29 +316,31 @@ Tag *User::generatePresenceStanza(Purple
 		Log().Get(m_jid) << "avatarHash";
 	}
 
-	Tag *x = new Tag("x");
-	x->addAttribute("xmlns","vcard-temp:x:update");
-	if (avatarHash != NULL) {
-		Log().Get(m_jid) << "Got avatar hash";
-		// Check if it's patched libpurple which saved icons to directories
-		char *hash = rindex(avatarHash,'/');
-		std::string h;
-		if (hash) {
-			char *dot;
-			hash++;
-			dot = strchr(hash, '.');
-			if (dot)
-				*dot = '\0';
-			x->addChild(new Tag("photo",(std::string) hash));
+	if (purple_value_get_boolean(getSetting("enable_avatars"))){
+		Tag *x = new Tag("x");
+		x->addAttribute("xmlns","vcard-temp:x:update");
+		if (avatarHash != NULL) {
+			Log().Get(m_jid) << "Got avatar hash";
+			// Check if it's patched libpurple which saved icons to directories
+			char *hash = rindex(avatarHash,'/');
+			std::string h;
+			if (hash) {
+				char *dot;
+				hash++;
+				dot = strchr(hash, '.');
+				if (dot)
+					*dot = '\0';
+				x->addChild(new Tag("photo",(std::string) hash));
+			}
+			else
+				x->addChild(new Tag("photo",(std::string) avatarHash));
 		}
-		else
-			x->addChild(new Tag("photo",(std::string) avatarHash));
+		else{
+			Log().Get(m_jid) << "no avatar hash";
+			x->addChild(new Tag("photo"));
+		}
+		tag->addChild(x);
 	}
-	else{
-		Log().Get(m_jid) << "no avatar hash";
-		x->addChild(new Tag("photo"));
-	}
-	tag->addChild(x);
 
 	// update stats...
 	if (s==PURPLE_STATUS_OFFLINE){
============================================================
--- vcardhandler.cpp	6d40be6b1f704a00ee09f936ee7ebdbb00784a58
+++ vcardhandler.cpp	2231b8a1af82c0273dffec4ccee3021c92853fda
@@ -146,30 +146,34 @@ void GlooxVCardHandler::userInfoArrived(
 			vcard->addAttribute( "xmlns", "vcard-temp" );
 		}
 
-		Tag *photo = new Tag("PHOTO");
+		if (purple_value_get_boolean(user->getSetting("enable_avatars"))) {
+			Tag *photo = new Tag("PHOTO");
 
-		PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(gc), who.c_str());
-		if (buddy){
-			std::cout << "found buddy " << who << "\n";
-			gsize len;
-			PurpleBuddyIcon *icon = NULL;
-			icon = purple_buddy_icons_find(purple_connection_get_account(gc), who.c_str());
-			if(icon!=NULL) {
-				std::cout << "found icon\n";
-				const gchar * data = (gchar*)purple_buddy_icon_get_data(icon, &len);
-				if (data!=NULL){
-					std::cout << "making avatar " << len <<"\n";
-					std::string avatarData((char *)data,len);
-                    base64encode((unsigned char *)data, len, avatarData);
-					photo->addChild( new Tag("BINVAL", avatarData));
-					std::cout << "avatar made\n";
-// 					std::cout << photo->xml() << "\n";
+			PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(gc), who.c_str());
+			if (buddy){
+				std::cout << "found buddy " << who << "\n";
+				gsize len;
+				PurpleBuddyIcon *icon = NULL;
+				icon = purple_buddy_icons_find(purple_connection_get_account(gc), who.c_str());
+				if(icon!=NULL) {
+					std::cout << "found icon\n";
+					const gchar * data = (gchar*)purple_buddy_icon_get_data(icon, &len);
+					if (data!=NULL){
+						std::cout << "making avatar " << len <<"\n";
+						std::string avatarData((char *)data,len);
+						base64encode((unsigned char *)data, len, avatarData);
+						photo->addChild( new Tag("BINVAL", avatarData));
+						std::cout << "avatar made\n";
+	// 					std::cout << photo->xml() << "\n";
+					}
 				}
 			}
-		}
 
-		if(!photo->children().empty())
-			vcard->addChild(photo);
+			if(!photo->children().empty())
+				vcard->addChild(photo);
+			else 
+				delete photo;
+		}
 
 		reply->addChild(vcard);
 		std::cout << reply->xml() << "\n";


More information about the Commits mailing list