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

List:       kopete-devel
Subject:    [kopete-devel] Patch to allow showing metacontact's picture
From:       "Michal Vaner \(Vorner\)" <michal.vaner () kdemail ! net>
Date:       2005-12-04 19:42:49
Message-ID: 200512042043.01210.michal.vaner () kdemail ! net
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hello,
I did not like the new way how there is contact's picture showed instead of 
metacontact's. So I added a config option and managed to change the code so 
it shows the one user wants.

I put a patch here and ask you for a review. I did not dare to commit it right 
away, as it adds config option to the GUI and changes the core of Kopete.

I get a patch to the image if it is possible. Otherwise, I use the 
base64-encoding trick for now. I would like to ask, do you think a temp file 
would be better or is there any better way to do it, when the picture is from 
address book? (I guess it is not in a separated file anyway).

Thank you for any comments.

-- 

Windows are like..
windows. Shiny but fragile and expensive.

Michal Vaner (Vorner)

["kopete-photo.diff" (text/x-diff)]

Index: kopete/config/appearance/appearanceconfig.cpp
===================================================================
--- kopete/config/appearance/appearanceconfig.cpp	(revision 485483)
+++ kopete/config/appearance/appearanceconfig.cpp	(working copy)
@@ -389,6 +389,8 @@
 		this, SLOT(slotGetStyles()));
 	connect(d->mPrfsChatWindow->metaContactDisplayEnabled, SIGNAL(toggled(bool)),
 		this, SLOT(emitChanged()));
+	connect(d->mPrfsChatWindow->metaContactPictureEnabled, SIGNAL(toggled(bool)),
+		this, SLOT(emitChanged()));
 	connect(d->mPrfsChatWindow->groupConsecutiveMessages, SIGNAL(toggled(bool)),
 		this, SLOT(emitChanged()));
 	// Show the available styles when the Manager has finish to load the styles.
@@ -525,6 +527,7 @@
 	p->setTransparencyEnabled( d->mPrfsChatWindow->mTransparencyEnabled->isChecked() );
 	p->setTransparencyValue( d->mPrfsChatWindow->mTransparencyValue->value() );
 	p->setMetaContactDisplay( \
d->mPrfsChatWindow->metaContactDisplayEnabled->isChecked() ); \
+	p->setMetaContactPicture( \
d->mPrfsChatWindow->metaContactPictureEnabled->isChecked() );  \
p->setGroupConsecutiveMessages( \
d->mPrfsChatWindow->groupConsecutiveMessages->isChecked() );  
 	// Get the stylePath
@@ -595,6 +598,7 @@
 	d->mPrfsChatWindow->mTransparencyTintColor->setColor( p->transparencyColor() );
 	d->mPrfsChatWindow->mTransparencyValue->setValue( p->transparencyValue() );
 	d->mPrfsChatWindow->metaContactDisplayEnabled->setChecked( p->metaContactDisplay() \
); +	d->mPrfsChatWindow->metaContactPictureEnabled->setChecked( \
p->metaContactPicture() );  d->mPrfsChatWindow->groupConsecutiveMessages->setChecked( \
p->groupConsecutiveMessages() );  // Look for avaiable chat window styles.
 	ChatWindowStyleManager::self()->loadStyles();
Index: kopete/config/appearance/appearanceconfig_chatwindow.ui
===================================================================
--- kopete/config/appearance/appearanceconfig_chatwindow.ui	(revision 485483)
+++ kopete/config/appearance/appearanceconfig_chatwindow.ui	(working copy)
@@ -8,8 +8,8 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>462</width>
-            <height>457</height>
+            <width>484</width>
+            <height>481</height>
         </rect>
     </property>
     <property name="sizePolicy">
@@ -172,27 +172,41 @@
             <property name="title">
                 <string>Display</string>
             </property>
-            <grid>
+            <vbox>
                 <property name="name">
                     <cstring>unnamed</cstring>
                 </property>
-                <widget class="QCheckBox" row="0" column="0">
+                <widget class="QCheckBox">
                     <property name="name">
                         <cstring>metaContactDisplayEnabled</cstring>
                     </property>
                     <property name="text">
                         <string>Use meta contact &amp;name for display in chat \
window</string>  </property>
+                    <property name="accel">
+                        <string>Alt+N</string>
+                    </property>
                 </widget>
-                <widget class="QCheckBox" row="1" column="0">
+                <widget class="QCheckBox">
                     <property name="name">
+                        <cstring>metaContactPictureEnabled</cstring>
+                    </property>
+                    <property name="text">
+                        <string>Use meta contact picture for display in chat \
window</string> +                    </property>
+                </widget>
+                <widget class="QCheckBox">
+                    <property name="name">
                         <cstring>groupConsecutiveMessages</cstring>
                     </property>
                     <property name="text">
                         <string>Group consecuti&amp;ve messages</string>
                     </property>
+                    <property name="accel">
+                        <string>Alt+V</string>
+                    </property>
                 </widget>
-            </grid>
+            </vbox>
         </widget>
         <widget class="QButtonGroup">
             <property name="name">
Index: kopete/chatwindow/chatmessagepart.cpp
===================================================================
--- kopete/chatwindow/chatmessagepart.cpp	(revision 485483)
+++ kopete/chatwindow/chatmessagepart.cpp	(working copy)
@@ -994,16 +994,53 @@
 	if( message.from() )
 	{
 
-		QString photoPath = \
message.from()->property(Kopete::Global::Properties::self()->photo().key()).value().toString();
 +		bool needFallback = true;
+		QString photoPath;
+
+		// Metacontact's picture or contact's picture?
+		if( KopetePrefs::prefs()->metaContactPicture() )
+		{
+			// Do we have an url for it or we need to put it there directly?
+			switch( message.from()->metaContact()->photoSource() ) {
+				case Kopete::MetaContact::SourceCustom:
+					photoPath = message.from()->metaContact()->customPhoto().url();
+					break;
+				case Kopete::MetaContact::SourceContact:
+					photoPath = message.from()->metaContact()->photoSourceContact()->property(Kopete::Global::Properties::self()->photo().key()).value().toString();
 +					break;
+				default:
+					// TODO: Maybe this is not too good, maybe a temp file would be better?
+					QImage photo = message.from()->metaContact()->photo();
+					if( !photo.isNull() )
+					{
+						QByteArray ba;
+						QBuffer buffer( ba );
+						buffer.open( IO_WriteOnly );
+						photo.save ( &buffer, "PNG" );
+						QString photo64=KCodecs::base64Encode(ba);
+						resultHTML = resultHTML.replace( QString::fromUtf8("%userIconPath%"), \
QString("data:image/png;base64,%1").arg(photo64) ); +						needFallback = false;
+					}
+					break;
+			}
+		}
+		else
+		{
+			photoPath = message.from()->property(Kopete::Global::Properties::self()->photo().key()).value().toString();
 +		}
 		// If the photo path is empty, set the default buddy icon for the theme
-		if( photoPath.isEmpty() )
+		if( photoPath.isEmpty() && needFallback )
 		{
 			if(message.direction() == Kopete::Message::Inbound)
 				photoPath = QString::fromUtf8("Incoming/buddy_icon.png");
 			else if(message.direction() == Kopete::Message::Outbound)
 				photoPath = QString::fromUtf8("Outgoing/buddy_icon.png");
 		}
-		resultHTML = resultHTML.replace(QString::fromUtf8("%userIconPath%"), photoPath);
+		// Is it URL?
+		if( !photoPath.isEmpty() )
+		{
+			resultHTML = resultHTML.replace(QString::fromUtf8("%userIconPath%"), photoPath);
+		}
 #if 0
 		QImage photo = message.from()->metaContact()->photo();
 		if( !photo.isNull() )
Index: libkopete/kopetemetacontact.h
===================================================================
--- libkopete/kopetemetacontact.h	(revision 485483)
+++ libkopete/kopetemetacontact.h	(working copy)
@@ -207,10 +207,10 @@
 	QString customDisplayName() const;
 
 	/**
-	 * @brief Returns the custom display name
+	 * @brief Returns the custom photo
 	 *
-	 * @see displayName()
-	 * @see displayNameSource()
+	 * @see photo()
+	 * @see photoSource()
 	 */
 	KURL customPhoto() const;
 
Index: libkopete/kopeteprefs.h
===================================================================
--- libkopete/kopeteprefs.h	(revision 485483)
+++ libkopete/kopeteprefs.h	(working copy)
@@ -141,6 +141,7 @@
 	int maxConactNameLength() const { return mMaxContactNameLength; }
 	bool emoticonsRequireSpaces() const { return mEmoticonsRequireSpaces; }
 	bool metaContactDisplay() const { return mMetaContactDisplay; }
+	bool metaContactPicture() const { return mMetaContactPicture; }
 	bool groupConsecutiveMessages() const { return mGroupConsecutiveMessages; }
 
 	void setIconTheme(const QString &value);
@@ -213,6 +214,7 @@
 	void setBalloonClose( bool );
 	void setBalloonDelay( int );
 	void setMetaContactDisplay( bool );
+	void setMetaContactPicture( bool );
 	void setGroupConsecutiveMessages( bool );
 
 signals:
@@ -341,6 +343,7 @@
 	bool mReconnectOnDisconnect;
 	bool mEmoticonsRequireSpaces;
 	bool mMetaContactDisplay;
+	bool mMetaContactPicture;
 	bool mGroupConsecutiveMessages;
 
 	QString fileContents(const QString &path);
Index: libkopete/kopeteprefs.cpp
===================================================================
--- libkopete/kopeteprefs.cpp	(revision 485483)
+++ libkopete/kopeteprefs.cpp	(working copy)
@@ -117,6 +117,7 @@
 	mStyleVariant = config->readEntry("StyleVariant");
 	// Read Chat Window Style display
 	mMetaContactDisplay = config->readBoolEntry("MetaContactDisplay", false);
+	mMetaContactPicture = config->readBoolEntry("MetaContactPicture", false);
 	mGroupConsecutiveMessages = config->readBoolEntry("GroupConsecutiveMessages", \
true);  
 	mToolTipContents = config->readListEntry("ToolTipContents");
@@ -242,6 +243,7 @@
 	config->writeEntry("StyleVariant", mStyleVariant);
 	// Chat Window Display
 	config->writeEntry("MetaContactDisplay", mMetaContactDisplay);
+	config->writeEntry("MetaContactPicture", mMetaContactPicture);
 	config->writeEntry("GroupConsecutiveMessages", mGroupConsecutiveMessages);
 
 	config->writeEntry("ToolTipContents", mToolTipContents);
@@ -765,6 +767,11 @@
 	mMetaContactDisplay = value;
 }
 
+void KopetePrefs::setMetaContactPicture( bool value) 
+{
+	mMetaContactPicture = value;
+}
+
 void KopetePrefs::setGroupConsecutiveMessages( bool value )
 {
 	mGroupConsecutiveMessages = value;


[Attachment #8 (application/pgp-signature)]

_______________________________________________
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