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

List:       kopete-devel
Subject:    [kopete-devel] [PATCH] Identity and property update
From:       "Roman Jarosz" <kedgedev () centrum ! cz>
Date:       2007-11-24 14:24:55
Message-ID: op.t2avntyqyuholc () localhost
[Download RAW message or body]

Hi, 

I discovered that ICQ/AIM doesn't refresh buddy icons, this is regression and was \
introduced by identity merge.

The problem is that to fix it I have to add identityChanged signal to \
Kopete::Account, because there's no way (or no easy way) to detect identity change \
for a specific account. And I need that so I can update the icon when account is \
moved to other identity and also to catch propertyChanged singal from current \
identity.

The patch is attached, any objections?

Regards,
Roman


["buddyupdate.diff" (buddyupdate.diff)]

Index: protocols/oscar/oscaraccount.h
===================================================================
--- protocols/oscar/oscaraccount.h	(revision 740626)
+++ protocols/oscar/oscaraccount.h	(working copy)
@@ -92,6 +92,11 @@
 	QTextCodec* contactCodec( const QString& contactName ) const;
 
 	/**
+	 * Updates buddy icon
+	 */
+	void updateBuddyIcon( const QString &path );
+
+	/**
 	 * Add a contact to the server site list
 	 * \param contactName the screen name of the new contact to add
 	 * \param groupName the group of the new contact
@@ -190,6 +195,13 @@
 	/** Sends buddy icon to server */
 	void slotSendBuddyIcon();
 
+	/** Identity changed */
+	void slotIdentityChanged();
+	
+	/** Identity's property changed */
+	void slotIdentityPropertyChanged( Kopete::PropertyContainer *container, const \
QString &key, +	                                  const QVariant &oldValue, const \
QVariant &newValue ); +
 private:
 	OscarAccountPrivate *d;
 
Index: protocols/oscar/oscaraccount.cpp
===================================================================
--- protocols/oscar/oscaraccount.cpp	(revision 740626)
+++ protocols/oscar/oscaraccount.cpp	(working copy)
@@ -145,6 +145,9 @@
 	                  this, SLOT( askIncoming( QString, QString, Oscar::DWORD, QString, \
QString ) ) );  QObject::connect( d->engine, SIGNAL( getTransferManager( \
                Kopete::TransferManager ** ) ),
 	                  this, SLOT( getTransferManager( Kopete::TransferManager ** ) ) );
+
+	QObject::connect( this, SIGNAL(identityChanged()),
+	                  this, SLOT(slotIdentityChanged()) );
 }
 
 OscarAccount::~OscarAccount()
@@ -490,6 +493,40 @@
 	return contactCodec( contact );
 }
 
+void OscarAccount::updateBuddyIcon( const QString &path )
+{
+	if ( path.isEmpty() )
+	{
+		myself()->removeProperty( Kopete::Global::Properties::self()->photo() );
+	}
+	else
+	{
+		QImage image( path );
+		if ( image.isNull() )
+			return;
+		
+		const QSize size = ( d->engine->isIcq() ) ? QSize( 52, 64 ) : QSize( 48, 48 );
+		
+		image = image.scaled( size, Qt::KeepAspectRatioByExpanding, \
Qt::SmoothTransformation ); +		if( image.width() > size.width())
+			image = image.copy( ( image.width() - size.width() ) / 2, 0, size.width(), \
image.height() ); +		
+		if( image.height() > size.height())
+			image = image.copy( 0, ( image.height() - size.height() ) / 2, image.width(), \
size.height() ); +		
+		QString newlocation( KStandardDirs::locateLocal( "appdata", "oscarpictures/" + \
accountId() + ".jpg" ) ); +		
+		kDebug(OSCAR_RAW_DEBUG) << "Saving buddy icon: " << newlocation;
+		if ( !image.save( newlocation, "JPEG" ) )
+			return;
+		
+		myself()->setProperty( Kopete::Global::Properties::self()->photo() , newlocation \
); +	}
+	
+	d->buddyIconDirty = true;
+	updateBuddyIconInSSI();
+}
+
 bool OscarAccount::addContactToSSI( const QString& contactName, const QString& \
groupName, bool autoAddGroup )  {
 	ContactManager* listManager = d->engine->ssiManager();
@@ -775,12 +812,11 @@
 	if ( !engine()->isActive() )
 		return;
 	
-	QString photoPath = identity()->property( \
                Kopete::Global::Properties::self()->photo() ).value().toString();
-	
+	QString photoPath = myself()->property( Kopete::Global::Properties::self()->photo() \
).value().toString(); +
 	ContactManager* ssi = engine()->ssiManager();
 	OContact item = ssi->findItemForIconByRef( 1 );
 	
-	// FIXME: we need to resize the photo before sending it
 	if ( photoPath.isEmpty() )
 	{
 		if ( item )
@@ -861,7 +897,7 @@
 {
 	//need to disconnect because we could end up with many connections
 	QObject::disconnect( engine(), SIGNAL( iconServerConnected() ), this, SLOT( \
                slotSendBuddyIcon() ) );
-	QString photoPath = identity()->property( \
Kopete::Global::Properties::self()->photo() ).value().toString(); +	QString photoPath \
= myself()->property( Kopete::Global::Properties::self()->photo() \
).value().toString();  if ( photoPath.isEmpty() )
 		return;
 	
@@ -884,6 +920,25 @@
 	}
 }
 
+void OscarAccount::slotIdentityChanged()
+{
+	QObject::connect( identity(), SIGNAL(propertyChanged(Kopete::PropertyContainer*, \
const QString&, const QVariant&, const QVariant&)), +	                  this, \
SLOT(slotIdentityPropertyChanged(Kopete::PropertyContainer*, const QString&, const \
QVariant&, const QVariant&)) ); +
+	QString photoPath = identity()->property( \
Kopete::Global::Properties::self()->photo() ).value().toString(); +	updateBuddyIcon( \
photoPath ); +}
+
+void OscarAccount::slotIdentityPropertyChanged( Kopete::PropertyContainer*, const \
QString &key, +                                                const QVariant&, const \
QVariant &newValue ) +{
+	kDebug(OSCAR_GEN_DEBUG) << "Identity property changed";
+	if ( key == Kopete::Global::Properties::self()->photo().key() )
+	{
+		updateBuddyIcon( newValue.toString() );
+	}
+}
+
 void OscarAccount::slotGoOffline()
 {
 }
Index: libkopete/kopeteaccount.cpp
===================================================================
--- libkopete/kopeteaccount.cpp	(revision 740626)
+++ libkopete/kopeteaccount.cpp	(working copy)
@@ -426,6 +426,8 @@
 	ident->addAccount( this );
 	d->identity = ident;
 	d->configGroup->writeEntry("Identity", ident->id());
+
+	emit identityChanged();
 }
 
 Contact * Account::myself() const
Index: libkopete/kopeteaccount.h
===================================================================
--- libkopete/kopeteaccount.h	(revision 740626)
+++ libkopete/kopeteaccount.h	(working copy)
@@ -454,6 +454,11 @@
 	 */
 	void isConnectedChanged();
 
+	/**
+	 * Emitted whenever new identity is assigned to this @p account.
+	 */
+	void identityChanged();
+	
 private:
 	/**
 	 * @internal



_______________________________________________
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