[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kopete-devel
Subject:    [kopete-devel] [PATCH] Send Yahoo! Buddy Icon
From:       Andre Duffeck <andre () duffeck ! de>
Date:       2005-06-26 13:52:48
Message-ID: 42BEB330.7030202 () duffeck ! de
[Download RAW message or body]

Hi,

this patch adds sending of Yahoo! Buddy Icon.

Please review.

Thanks,
Andre

["yahoosendbuddyicon.patch" (text/x-patch)]

Index: kyahoo.h
===================================================================
--- kyahoo.h	(Revision 429081)
+++ kyahoo.h	(Arbeitskopie)
@@ -50,0 +51,8 @@
+struct YahooBuddyIconUploadData
+{
+	QString url;
+	int size;
+	int transmitted;
+	QFile file;
+};
+
@@ -171,0 +180,4 @@
+	void sendBuddyIconInfo( const QString &who, const QString &url, int checksum );
+	void sendBuddyIconUpdate( const QString &who, int type );
+	void sendBuddyIconChecksum( int checksum, const QString &who );
+	void uploadBuddyIcon( const QString &url, int size );
@@ -207,0 +220,3 @@
+	void _gotBuddyIconRequestReceiver( int id, char *who );
+	void _uploadBuddyIconProceed( int id, int fd, int error, void *data );
+	void _buddyIconUploaded( int id, const char *url);
@@ -296,0 +312,6 @@
+	
+	/** emitted when someone requests our buddy icon */
+	void gotBuddyIconRequest( const QString &who );
+	
+	/** emitted when our buddy icon was successfully uploaded*/
+	void buddyIconUploaded( const QString &url );
@@ -305,0 +327 @@
+	void slotTransmitBuddyIcon( int fd, YahooBuddyIconUploadData *uploadData );
Index: yahoocontact.h
===================================================================
--- yahoocontact.h	(Revision 429081)
+++ yahoocontact.h	(Arbeitskopie)
@@ -37,0 +38 @@
+struct KURL;
@@ -69,2 +69,0 @@
-	void setDisplayPicture(KTempFile *f, int checksum);
-	
@@ -73,0 +73,4 @@
+	void setDisplayPicture(KTempFile *f, int checksum);
+	void sendBuddyIconInfo( const QString &url, int checksum );
+	void sendBuddyIconUpdate( int type );
+	void sendBuddyIconChecksum( int checksum );
Index: yahooprotocol.cpp
===================================================================
--- yahooprotocol.cpp	(Revision 429081)
+++ yahooprotocol.cpp	(Arbeitskopie)
@@ -58 +58,4 @@
-	iconCheckSum("iconCheckSum", i18n("Buddy Icon Checksum"), QString::null, true, \
false, true) +	iconCheckSum("iconCheckSum", i18n("Buddy Icon Checksum"), \
QString::null, true), +	iconExpire("iconExpire", i18n("Buddy Icon Expire"), \
QString::null, true), +	iconLocalUrl("iconLocalUrl", i18n("Buddy Icon Local Url"), \
QString::null, true), +	iconRemoteUrl("iconRemoteUrl", i18n("Buddy Icon Remote Url"), \
                QString::null, true)
Index: yahooaccount.h
===================================================================
--- yahooaccount.h	(Revision 429081)
+++ yahooaccount.h	(Arbeitskopie)
@@ -104,0 +105,5 @@
+
+	/**
+	 * Set Buddy Icon
+	 */
+	void setBuddyIcon( KURL url );
@@ -124,0 +130,5 @@
+	/**
+	 * Emitted when our Buddy Icon has changed
+	 */
+	void signalBuddyIconChanged( int type );
+
@@ -175,0 +186,2 @@
+	void slotGotBuddyIconRequest(const QString &);
+	void slotBuddyIconChanged(const QString&);
Index: yahooeditaccount.cpp
===================================================================
--- yahooeditaccount.cpp	(Revision 429081)
+++ yahooeditaccount.cpp	(Arbeitskopie)
@@ -26,0 +27 @@
+#include <qimage.h>
@@ -32,0 +34,2 @@
+#include <kurl.h>
+#include <kfiledialog.h>
@@ -68,0 +72,6 @@
+
+		QString iconUrl = account()->configGroup()->readEntry("pictureUrl", "");
+		bool sendPicture = account()->configGroup()->readBoolEntry("sendPicture", false);
+		optionSendBuddyIcon->setChecked( sendPicture );
+		editPictureUrl->setText( iconUrl );
+		editPictureUrl->setEnabled( sendPicture );
@@ -71,0 +81,3 @@
+	QObject::connect(buttonSelectPicture, SIGNAL(clicked()), this, \
SLOT(slotSelectPicture())); +
+	optionSendBuddyIcon->setEnabled( account() );
@@ -111 +123,2 @@
-	if( optionOverrideServer->isChecked() )	{
+	if ( optionOverrideServer->isChecked() )
+	{
@@ -114 +127,3 @@
-	} else {
+	}
+	else
+	{
@@ -118,0 +134,11 @@
+	account()->configGroup()->writeEntry("pictureUrl", editPictureUrl->text() );
+	account()->configGroup()->writeEntry("sendPicture", \
optionSendBuddyIcon->isChecked() ); +	if ( optionSendBuddyIcon->isChecked() )
+	{
+		yahooAccount->setBuddyIcon( editPictureUrl->text() );
+	}
+	else
+	{
+		yahooAccount->setBuddyIcon( KURL( QString::null ) );
+	}
+	
@@ -126,0 +153,10 @@
+void YahooEditAccount::slotSelectPicture()
+{
+	KURL file = KFileDialog::getImageOpenURL( QString::null, this, i18n( "Yahoo Buddy \
Icon" ) ); +
+	if ( file.isEmpty() )
+		return;
+
+	editPictureUrl->setText( file.url() );
+}
+
Index: yahooprotocol.h
===================================================================
--- yahooprotocol.h	(Revision 429081)
+++ yahooprotocol.h	(Arbeitskopie)
@@ -73,0 +74,3 @@
+	const Kopete::ContactPropertyTmpl iconExpire;
+	const Kopete::ContactPropertyTmpl iconLocalUrl;
+	const Kopete::ContactPropertyTmpl iconRemoteUrl;
Index: yahooeditaccount.h
===================================================================
--- yahooeditaccount.h	(Revision 429081)
+++ yahooeditaccount.h	(Arbeitskopie)
@@ -52,0 +53 @@
+	void slotSelectPicture();
Index: libyahoo2/yahoo2_callbacks.h
===================================================================
--- libyahoo2/yahoo2_callbacks.h	(Revision 429081)
+++ libyahoo2/yahoo2_callbacks.h	(Arbeitskopie)
@@ -429,0 +430 @@
+void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddyiconrequest)(int id, const char *me, \
const char *who); @@ -434,0 +436,2 @@
+void YAHOO_CALLBACK_TYPE(ext_yahoo_buddicon_uploaded)(int id, const char *url);
+
Index: libyahoo2/yahoo2.h
===================================================================
--- libyahoo2/yahoo2.h	(Revision 429081)
+++ libyahoo2/yahoo2.h	(Arbeitskopie)
@@ -196 +196,5 @@
-
+void yahoo_send_picture_info(int id, const char *who, const char *url, int \
checksum); +void yahoo_send_picture_checksum(int id, const char *who, int checksum);
+void yahoo_send_picture_update(int id, const char *who, int type);
+void yahoo_send_picture(int id, const char *name, unsigned long size,
+							yahoo_get_fd_callback callback, void *data);
Index: libyahoo2/libyahoo2.c
===================================================================
--- libyahoo2/libyahoo2.c	(Revision 429081)
+++ libyahoo2/libyahoo2.c	(Arbeitskopie)
@@ -759,0 +760,3 @@
+	if( yid->type == YAHOO_CONNECTION_FT )
+		yahoo_send_data(yid->fd, data, len);
+	else
@@ -760,0 +764 @@
+	
@@ -1611,2 +1614,0 @@
-				to = pair->value;
-			case 5:
@@ -1613,0 +1616,2 @@
+			case 5:
+				to = pair->value;
@@ -1643,4 +1647 @@
-		case 4:		/* we */
-			to = pair->value;
-			break;
-		case 5:		/* sender */
+		case 4:		/* sender */
@@ -1648,0 +1650,3 @@
+		case 5:		/* we */
+			to = pair->value;
+			break;
@@ -1663,0 +1668 @@
+			YAHOO_CALLBACK(ext_yahoo_got_buddyiconrequest)(yd->client_id, to, from);
@@ -1670,0 +1676,30 @@
+static void yahoo_process_picture_upload(struct yahoo_input_data *yid, struct \
yahoo_packet *pkt) +{
+	struct yahoo_data *yd = yid->yd;
+	YList *l;
+	char *url;
+
+	if ( pkt->status != 1 )
+		return;		/* something went wrong */
+	
+	for(l = pkt->hash; l; l = l->next)
+	{
+		struct yahoo_pair *pair = l->data;
+
+		switch(pair->key)
+		{
+			case 5:		/* we */
+				break;
+			case 20:		/* url */
+				url = pair->value;
+				break;
+			case 27:		/* local filename */
+				break;
+			case 38:		/* time */
+				break;
+		}
+	}
+
+	YAHOO_CALLBACK(ext_yahoo_buddyicon_uploaded)(yd->client_id, url);
+}
+
@@ -2725,0 +2761,3 @@
+	case YAHOO_SERVICE_PICTURE_UPLOAD:
+		yahoo_process_picture_upload(yid, pkt);
+		break;	
@@ -4450,0 +4489,55 @@
+void yahoo_send_picture_info(int id, const char *who, const char *url, int checksum)
+{
+	struct yahoo_input_data *yid = find_input_by_id_and_type(id, \
YAHOO_CONNECTION_PAGER); +	struct yahoo_data *yd;
+	struct yahoo_packet *pkt;
+	char checksum_str[10];
+
+	if( !yid )
+		return;
+
+	yd = yid->yd;
+
+	snprintf(checksum_str, sizeof(checksum_str), "%d", checksum);
+
+	pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0);
+	yahoo_packet_hash(pkt, 1, yd->user);
+	yahoo_packet_hash(pkt, 4, yd->user);
+	yahoo_packet_hash(pkt, 5, who);
+	yahoo_packet_hash(pkt, 13, "2");
+	yahoo_packet_hash(pkt, 20, url);
+	yahoo_packet_hash(pkt, 192, checksum_str);
+	yahoo_send_packet(yid, pkt, 0);
+
+	yahoo_packet_free(pkt);
+}
+
+void yahoo_send_picture_update(int id, const char *who, int type)
+{
+	struct yahoo_input_data *yid = find_input_by_id_and_type(id, \
YAHOO_CONNECTION_PAGER); +	struct yahoo_data *yd;
+	struct yahoo_packet *pkt;
+	char type_str[10];
+
+	if( !yid )
+		return;
+
+	yd = yid->yd;
+
+	snprintf(type_str, sizeof(type_str), "%d", type);
+
+	pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0);
+	yahoo_packet_hash(pkt, 1, yd->user);
+	yahoo_packet_hash(pkt, 5, who);
+	yahoo_packet_hash(pkt, 206, type_str);
+	yahoo_send_packet(yid, pkt, 0);
+
+	yahoo_packet_free(pkt);
+}
+
+void yahoo_send_picture_checksum(int id, const char *who, int checksum)
+{
+	struct yahoo_input_data *yid = find_input_by_id_and_type(id, \
YAHOO_CONNECTION_PAGER); +	struct yahoo_data *yd;
+	struct yahoo_packet *pkt;
+	char checksum_str[10];
@@ -4451,0 +4545,17 @@
+	if( !yid )
+		return;
+
+	yd = yid->yd;
+	
+	snprintf(checksum_str, sizeof(checksum_str), "%d", checksum);
+
+	pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0);
+	yahoo_packet_hash(pkt, 1, yd->user);
+	if( who != 0 )
+		yahoo_packet_hash(pkt, 5, who);
+	yahoo_packet_hash(pkt, 192, checksum_str);
+	yahoo_packet_hash(pkt, 212, "1");
+	yahoo_send_packet(yid, pkt, 0);
+
+	yahoo_packet_free(pkt);
+}
@@ -4655,0 +4766,93 @@
+static void _yahoo_send_picture_connected(int id, int fd, int error, void *data)
+{
+	struct yahoo_input_data *yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_FT);
+	struct send_file_data *sfd = data;
+	struct yahoo_packet *pkt = sfd->pkt;
+	unsigned char buff[1024];
+
+	if(fd <= 0) {
+		sfd->callback(id, fd, error, sfd->user_data);
+		FREE(sfd);
+		yahoo_packet_free(pkt);
+		inputs = y_list_remove(inputs, yid);
+		FREE(yid);
+		return;
+	}
+
+	yid->fd = fd;
+	yahoo_send_packet(yid, pkt, 8);
+	yahoo_packet_free(pkt);
+
+	snprintf((char *)buff, sizeof(buff), "29");
+	buff[2] = 0xc0;
+	buff[3] = 0x80;
+	
+	write(yid->fd, buff, 4);
+
+	/*	YAHOO_CALLBACK(ext_yahoo_add_handler)(nyd->fd, YAHOO_INPUT_READ); */
+
+	sfd->callback(id, fd, error, sfd->user_data);
+	FREE(sfd);
+	inputs = y_list_remove(inputs, yid);
+	/*
+	while(yahoo_tcp_readline(buff, sizeof(buff), nyd->fd) > 0) {
+	if(!strcmp(buff, ""))
+	break;
+}
+
+	*/
+	yahoo_input_close(yid);
+}
+
+void yahoo_send_picture(int id, const char *name, unsigned long size,
+							yahoo_get_fd_callback callback, void *data)
+{
+	struct yahoo_data *yd = find_conn_by_id(id);
+	struct yahoo_input_data *yid;
+	struct yahoo_server_settings *yss;
+	struct yahoo_packet *pkt = NULL;
+	char size_str[10];
+	char expire_str[10];
+	long content_length=0;
+	unsigned char buff[1024];
+	char url[255];
+	struct send_file_data *sfd;
+
+	if(!yd)
+		return;
+
+	yss = yd->server_settings;
+
+	yid = y_new0(struct yahoo_input_data, 1);
+	yid->yd = yd;
+	yid->type = YAHOO_CONNECTION_FT;
+
+	pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPLOAD, YAHOO_STATUS_AVAILABLE, \
yd->session_id); +
+	snprintf(size_str, sizeof(size_str), "%ld", size);
+	snprintf(expire_str, sizeof(expire_str), "%ld", 604800);
+
+	yahoo_packet_hash(pkt, 0, yd->user);
+	yahoo_packet_hash(pkt, 1, yd->user);
+	yahoo_packet_hash(pkt, 14, "");
+	yahoo_packet_hash(pkt, 27, name);
+	yahoo_packet_hash(pkt, 28, size_str);
+	yahoo_packet_hash(pkt, 38, expire_str);
+	
+
+	content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt);
+
+	snprintf(url, sizeof(url), "http://%s:%d/notifyft",
+				yss->filetransfer_host, yss->filetransfer_port);
+	snprintf((char *)buff, sizeof(buff), "Y=%s; T=%s",
+				 yd->cookie_y, yd->cookie_t);
+	inputs = y_list_prepend(inputs, yid);
+
+	sfd = y_new0(struct send_file_data, 1);
+	sfd->pkt = pkt;
+	sfd->callback = callback;
+	sfd->user_data = data;
+	yahoo_http_post(yid->yd->client_id, url, (char *)buff, content_length+4+size,
+						_yahoo_send_picture_connected, sfd);
+}
+
Index: kyahoo.cpp
===================================================================
--- kyahoo.cpp	(Revision 429081)
+++ kyahoo.cpp	(Arbeitskopie)
@@ -71,0 +72 @@
+	void upload_buddyIcon_callback( int id, int fd, int error, void *data );
@@ -350,0 +352,34 @@
+void YahooSession::sendBuddyIconChecksum( int checksum, const QString &who )
+{
+	kdDebug(14181) << k_funcinfo << checksum << " sent to " << who << endl;
+	if ( who.isEmpty() )
+		yahoo_send_picture_checksum( m_connId, 0, checksum );
+	else
+		yahoo_send_picture_checksum( m_connId, who.local8Bit(), checksum );
+}
+
+void YahooSession::sendBuddyIconInfo( const QString &who, const QString &url, int \
checksum ) +{
+	kdDebug(14180) << k_funcinfo << "Url: " << url << " checksum: " << checksum << \
endl; +	yahoo_send_picture_info( m_connId, who.local8Bit(), url.local8Bit(), checksum \
); +}
+
+void YahooSession::sendBuddyIconUpdate( const QString &who, int type )
+{
+	kdDebug(14181) << k_funcinfo << endl;
+	yahoo_send_picture_update( m_connId, who.local8Bit(), type );
+}
+
+void YahooSession::uploadBuddyIcon( const QString &url, int size )
+{
+	kdDebug(14181) << k_funcinfo << endl;
+	YahooBuddyIconUploadData *uploadData = new YahooBuddyIconUploadData();
+	uploadData->url = url;
+	uploadData->size = size;
+	uploadData->transmitted = 0;
+	uploadData->file.setName( url );
+	
+	yahoo_send_picture( m_connId, url.local8Bit(), size, upload_buddyIcon_callback, \
reinterpret_cast< void*>( uploadData ) ); +
+}
+
@@ -942 +977 @@
-void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddyicon)(int id, const char *who, const \
char */*me*/, const char *url, int checksum) +void \
YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddyicon)(int id, const char */*me*/, const char \
*who, const char *url, int checksum) @@ -955,0 +991,14 @@
+void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddyiconrequest)(int id, const char */*me*/, \
const char *who) +{
+	YahooSession *session = YahooSessionManager::manager()->session( id );
+	if ( session )
+		session->_gotBuddyIconRequestReceiver( id, (char*)who );
+}
+	
+void YAHOO_CALLBACK_TYPE(ext_yahoo_buddyicon_uploaded)(int id, const char *url)
+{
+	YahooSession *session = YahooSessionManager::manager()->session( id );
+	if ( session )
+		session->_buddyIconUploaded( id, (char*)url );
+}
+	
@@ -962,0 +1012,7 @@
+
+void upload_buddyIcon_callback( int id, int fd, int error, void *data )
+{
+	YahooSession *session = YahooSessionManager::manager()->session( id );
+	if ( session )
+		session->_uploadBuddyIconProceed( id, fd, error, (char*)data );
+}
@@ -972,0 +1029,47 @@
+void YahooSession::_uploadBuddyIconProceed( int id, int fd, int error, void *data )
+{
+	YahooBuddyIconUploadData *uploadData = reinterpret_cast< YahooBuddyIconUploadData \
*>( data ); +	kdDebug(14181) << k_funcinfo << "Url: " << uploadData->url << " Size: " \
<< uploadData->size << endl; +
+	if( !uploadData->file.open(IO_ReadOnly) )
+		return;
+	
+	slotTransmitBuddyIcon( fd, uploadData );
+}
+
+void YahooSession::slotTransmitBuddyIcon( int fd, YahooBuddyIconUploadData \
*uploadData ) +{
+	KExtendedSocket* socket = m_connManager.connectionForFD( fd );
+	if( !socket )
+		return;
+	
+	if( uploadData->transmitted >= uploadData->size )      {
+		char buf[1024];
+		int r;
+		if( socket->readBlock( buf, r) <=0 )
+			kdDebug(14181) << k_funcinfo << "Icon " << uploadData->file.name() << " \
successfully uploaded" << endl; +		
+		uploadData->file.close();
+		delete uploadData;
+		return;
+	}
+	
+	char buf[1024];
+	int read;
+	
+	read = uploadData->file.readBlock( buf, 512 );
+
+	if ( read < 0 )
+		return;
+	
+	uploadData->transmitted += socket->writeBlock( buf, read );
+	
+	slotTransmitBuddyIcon(fd, uploadData);
+}
+
+void YahooSession::_buddyIconUploaded( int id, const char *url)
+{
+	kdDebug(14181) << k_funcinfo << endl;
+	emit buddyIconUploaded( QString( url ) );
+}
+
@@ -983 +1086 @@
-	kdDebug(14181) << k_funcinfo << endl;
+	kdDebug(14181) << k_funcinfo << "checksum: " << checksum << " received from: " << \
who << endl; @@ -988,0 +1092,7 @@
+void YahooSession::_gotBuddyIconRequestReceiver( int id, char *who )
+{
+	kdDebug(14181) << k_funcinfo << "Got Buddy Icon Request from: " << who << endl;
+
+	emit gotBuddyIconRequest ( QString( who ) );
+}
+
Index: yahoocontact.cpp
===================================================================
--- yahoocontact.cpp	(Revision 429081)
+++ yahoocontact.cpp	(Arbeitskopie)
@@ -37,0 +38 @@
+#include <qfile.h>
@@ -50,0 +52 @@
+#include <kurl.h>
@@ -314,0 +317,19 @@
+void YahooContact::sendBuddyIconChecksum( int checksum )
+{
+	kdDebug(14180) << k_funcinfo << endl;
+	m_account->yahooSession()->sendBuddyIconChecksum( checksum, m_userId );
+	
+}
+
+void YahooContact::sendBuddyIconInfo( const QString &url, int checksum )
+{
+	kdDebug(14180) << k_funcinfo << endl;
+	m_account->yahooSession()->sendBuddyIconInfo( m_userId, url, checksum );
+}
+
+void YahooContact::sendBuddyIconUpdate( int type )
+{
+	kdDebug(14180) << k_funcinfo << endl;
+	m_account->yahooSession()->sendBuddyIconUpdate( m_userId, type );
+}
+
Index: ui/yahooeditaccountbase.ui
===================================================================
--- ui/yahooeditaccountbase.ui	(Revision 429081)
+++ ui/yahooeditaccountbase.ui	(Arbeitskopie)
@@ -199,0 +200,25 @@
+                <spacer>
+                    <property name="name">
+                        <cstring>spacer4</cstring>
+                    </property>
+                    <property name="orientation">
+                        <enum>Vertical</enum>
+                    </property>
+                    <property name="sizeType">
+                        <enum>Expanding</enum>
+                    </property>
+                    <property name="sizeHint">
+                        <size>
+                            <width>20</width>
+                            <height>110</height>
+                        </size>
+                    </property>
+                    <property name="geometry">
+                        <rect>
+                            <x>187</x>
+                            <y>185</y>
+                            <width>20</width>
+                            <height>110</height>
+                        </rect>
+                    </property>
+                </spacer>
@@ -206,2 +231,2 @@
-                            <x>12</x>
-                            <y>11</y>
+                            <x>10</x>
+                            <y>10</y>
@@ -224 +249,4 @@
-                                <string>Override defau&amp;lt server \
information</string> +                                <string>O&amp;verride default \
server information</string> +                            </property>
+                            <property name="accel">
+                                <string>Alt+V</string>
@@ -322 +350 @@
-                <spacer>
+                <widget class="QGroupBox">
@@ -324,13 +352 @@
-                        <cstring>spacer4</cstring>
-                    </property>
-                    <property name="orientation">
-                        <enum>Vertical</enum>
-                    </property>
-                    <property name="sizeType">
-                        <enum>Expanding</enum>
-                    </property>
-                    <property name="sizeHint">
-                        <size>
-                            <width>20</width>
-                            <height>210</height>
-                        </size>
+                        <cstring>groupBox4</cstring>
@@ -340,4 +356,4 @@
-                            <x>187</x>
-                            <y>85</y>
-                            <width>20</width>
-                            <height>210</height>
+                            <x>10</x>
+                            <y>90</y>
+                            <width>400</width>
+                            <height>79</height>
@@ -346 +362,36 @@
-                </spacer>
+                    <property name="title">
+                        <string>Buddy Icon</string>
+                    </property>
+                    <grid>
+                        <property name="name">
+                            <cstring>unnamed</cstring>
+                        </property>
+                        <widget class="QCheckBox" row="0" column="0" rowspan="1" \
colspan="2"> +                            <property name="name">
+                                <cstring>optionSendBuddyIcon</cstring>
+                            </property>
+                            <property name="text">
+                                <string>Send Buddy Icon to other users</string>
+                            </property>
+                            <property name="accel">
+                                <string></string>
+                            </property>
+                        </widget>
+                        <widget class="QPushButton" row="1" column="1">
+                            <property name="name">
+                                <cstring>buttonSelectPicture</cstring>
+                            </property>
+                            <property name="text">
+                                <string>Select Picture</string>
+                            </property>
+                            <property name="accel">
+                                <string></string>
+                            </property>
+                        </widget>
+                        <widget class="QLineEdit" row="1" column="0">
+                            <property name="name">
+                                <cstring>editPictureUrl</cstring>
+                            </property>
+                        </widget>
+                    </grid>
+                </widget>
@@ -386,0 +438,6 @@
+    <connection>
+        <sender>optionSendBuddyIcon</sender>
+        <signal>toggled(bool)</signal>
+        <receiver>editPictureUrl</receiver>
+        <slot>setEnabled(bool)</slot>
+    </connection>
@@ -393,0 +451,3 @@
+<slots>
+    <slot access="private" specifier="nicht virtual">slotSelectPicture()</slot>
+</slots>
Index: yahooaccount.cpp
===================================================================
--- yahooaccount.cpp	(Revision 429081)
+++ yahooaccount.cpp	(Arbeitskopie)
@@ -25,0 +26 @@
+#include <qimage.h>
@@ -36,0 +38 @@
+#include <kstandarddirs.h>
@@ -81,0 +84,5 @@
+	myself()->setProperty( YahooProtocol::protocol()->iconRemoteUrl, \
configGroup()->readEntry( "iconRemoteUrl", "" ) ); +	myself()->setProperty( \
YahooProtocol::protocol()->iconLocalUrl, configGroup()->readEntry( "iconLocalUrl", "" \
) ); +	myself()->setProperty( YahooProtocol::protocol()->iconCheckSum, \
configGroup()->readNumEntry( "iconCheckSum", 0 ) ); +	myself()->setProperty( \
YahooProtocol::protocol()->iconExpire, configGroup()->readNumEntry( "iconExpire", 0 ) \
); +
@@ -269,0 +277,3 @@
+		QObject::connect(m_session, SIGNAL(gotBuddyIconRequest(const QString&)), this, \
SLOT(slotGotBuddyIconRequest(const QString&)) ); +
+		QObject::connect(m_session, SIGNAL(buddyIconUploaded( const QString &)), this, \
SLOT(slotBuddyIconChanged(const QString&))); @@ -354,0 +365,6 @@
+		
+		QObject::disconnect(m_session, SIGNAL(gotBuddyIconRequest(const QString&)), this, \
SLOT(slotGotBuddyIconRequest(const QString&)) ); +		
+		QObject::disconnect(m_session, SIGNAL(buddyIconUploaded( const QString & )), this, \
SLOT(slotBuddyIconChanged(const QString&))); +
+		
@@ -584,0 +601,2 @@
+		 
+		setBuddyIcon( myself()->property( YahooProtocol::protocol()->iconLocalUrl \
).value().toString() ); @@ -637 +655 @@
-	if ( true ) // TODO?: make this configurable 
+	if ( true && !(static_cast<YahooContact *>(contact( userid )) == myself() ) ) // \
TODO?: make this configurable @@ -639 +657,8 @@
-		m_session->requestBuddyIcon( userid );
+		m_session->requestBuddyIcon( userid );		// Try to get Buddy Icon
+
+		if ( !myself()->property( YahooProtocol::protocol()->iconLocalUrl ).isNull() )
+		{
+			static_cast< YahooContact* >( contact( userid ) )->sendBuddyIconUpdate( 2 );
+			static_cast< YahooContact* >( contact( userid ) )->sendBuddyIconChecksum(
+				myself()->property( YahooProtocol::protocol()->iconCheckSum ).value().toInt() );
+		}
@@ -669 +694,2 @@
-		if( newStatus == static_cast<YahooProtocol*>( m_protocol )->Online )
+		if( newStatus == static_cast<YahooProtocol*>( m_protocol )->Online &&
+		    contact(who) != myself() )
@@ -921,0 +948,90 @@
+void YahooAccount::slotGotBuddyIconRequest( const QString & who )
+{
+	kdDebug(14180) << k_funcinfo << endl;
+	YahooContact *kc = contact( who );
+	if ( kc == NULL ) {
+		kdDebug(14180) << k_funcinfo << "contact " << who << " doesn't exist." << endl;
+		return;
+	}
+	kc->sendBuddyIconInfo( myself()->property( YahooProtocol::protocol()->iconRemoteUrl \
).value().toString(), +							myself()->property( \
YahooProtocol::protocol()->iconCheckSum ).value().toInt() ); +}
+
+void YahooAccount::setBuddyIcon( KURL url )
+{
+	kdDebug(14180) << k_funcinfo << "Url: " << url.path() << endl;
+	QString s = url.path();
+	if ( url.path().isEmpty() )
+	{
+		myself()->removeProperty( YahooProtocol::protocol()->iconLocalUrl );
+		myself()->removeProperty( YahooProtocol::protocol()->iconRemoteUrl );
+		myself()->removeProperty( YahooProtocol::protocol()->iconExpire );
+	}
+	else
+	{
+		QImage image( url.path() );
+		QString newlocation( locateLocal( "appdata", "yahoopictures/"+ \
url.fileName().lower() ) ) ; +		QFile iconFile( newlocation );
+		QByteArray data;
+		uint expire = myself()->property( YahooProtocol::protocol()->iconExpire \
).value().toInt(); +		
+		if ( image.isNull() ) {
+			return;
+		}
+		image = image.smoothScale( 96, 96, QImage::ScaleMin );
+
+		if( !image.save( newlocation, "PNG" ) || !iconFile.open(IO_ReadOnly) )
+		{
+			KMessageBox::sorry( Kopete::UI::Global::mainWidget(), i18n( "An error occurred \
when trying to change the display picture." ), i18n( "Yahoo Plugin" ) ); +			return;
+		}
+		
+		data = iconFile.readAll();
+		iconFile.close();
+		
+		// create checksum - taken from qhash.cpp of qt4
+		const uchar *p = reinterpret_cast<const uchar *>(data.data());
+		int n = data.size();
+		uint checksum = 0;
+		uint g;
+		while (n--)
+		{
+			checksum = (checksum << 4) + *p++;
+			if ((g = (checksum & 0xf0000000)) != 0)
+				checksum ^= g >> 23;
+			checksum &= ~g;
+		}
+		
+		myself()->setProperty( YahooProtocol::protocol()->iconLocalUrl, newlocation );
+		configGroup()->writeEntry( "iconLocalUrl", newlocation );
+		if ( checksum != static_cast<uint>(myself()->property( \
YahooProtocol::protocol()->iconCheckSum ).value().toInt()) || +		     \
QDateTime::currentDateTime().toTime_t() > expire ) +		{
+			myself()->setProperty( YahooProtocol::protocol()->iconCheckSum, checksum );
+			myself()->setProperty( YahooProtocol::protocol()->iconExpire , \
QDateTime::currentDateTime().toTime_t() + 604800 ); +			configGroup()->writeEntry( \
"iconCheckSum", checksum ); +			configGroup()->writeEntry( "iconExpire", \
myself()->property( YahooProtocol::protocol()->iconExpire ).value().toInt() ); +			
+			m_session->uploadBuddyIcon( newlocation, data.size() );
+		}
+	}
+}
+
+void YahooAccount::slotBuddyIconChanged( const QString &url )
+{
+	kdDebug(14180) << k_funcinfo << endl;
+	QDictIterator<Kopete::Contact> it( contacts() );
+	int checksum = myself()->property( YahooProtocol::protocol()->iconCheckSum \
).value().toInt(); +
+	myself()->setProperty( YahooProtocol::protocol()->iconRemoteUrl, url );
+	configGroup()->writeEntry( "iconRemoteUrl", url );
+	
+	for ( ; it.current(); ++it )
+	{
+		if ( it.current() == myself() || !it.current()->isReachable())
+			continue;
+		static_cast< YahooContact* >( it.current() )->sendBuddyIconChecksum( checksum );
+		static_cast< YahooContact* >( it.current() )->sendBuddyIconUpdate( 2 );
+	}
+}
+



_______________________________________________
kopete-devel mailing list
kopete-devel@kde.org
https://mail.kde.org/mailman/listinfo/kopete-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic