Hi, The attached patch converts the meta contact id to use a QUuid instead of the hacked up string we use now. The kabc id (which is also the metacontact id in some cases) is exposed through a new kabcId function. The bulk of the patch is porting. I'm also changing the contactlist xml, but will write a kconf_update script so that previous versions of kopete keep working with the same contact list.
This is part of the contact list makeover from the break-the-contaclist branch, which will finally live up to its name. ;) Comments and suggestions welcome. Flames to /dev/null please. :) Thanks -- Matt
diff --git a/kopete/chatwindow/chatmemberslistwidget.cpp b/kopete/chatwindow/chatmemberslistwidget.cpp
index edd0bed..a7bd040 100644
--- a/kopete/chatwindow/chatmemberslistwidget.cpp
+++ b/kopete/chatwindow/chatmemberslistwidget.cpp
@@ -221,7 +221,7 @@ Q3DragObject *ChatMembersListWidget::dragObject()
d->setEncodedData( QString( c->protocol()->pluginId()+QChar( 0xE000 )+c->account()->accountId()+QChar( 0xE000 )+ c->contactId() ).toUtf8() );
drag->addDragObject( d );
- KABC::Addressee address = KABC::StdAddressBook::self()->findByUid(c->metaContact()->metaContactId());
+ KABC::Addressee address = KABC::StdAddressBook::self()->findByUid(c->metaContact()->kabcId());
if( !address.isEmpty() )
{
diff --git a/kopete/chatwindow/sidebarwidget.cpp b/kopete/chatwindow/sidebarwidget.cpp
index 5301843..7a3fdfd 100644
--- a/kopete/chatwindow/sidebarwidget.cpp
+++ b/kopete/chatwindow/sidebarwidget.cpp
@@ -75,7 +75,7 @@ void SidebarWidget::generateContactDetails()
if ( ! metaContact->picture().image().isNull() )
{
- QString photoName = QString(QLatin1String("kopete-metacontact-photo:%1")).arg( QLatin1String(QUrl::toPercentEncoding( metaContact->metaContactId()) ));
+ QString photoName = QString(QLatin1String("kopete-metacontact-photo:%1")).arg( QLatin1String(QUrl::toPercentEncoding( metaContact->kabcId()) ));
content += QString(QLatin1String("<img src=\"%1\" style=\"margin-bottom:10px;\"><br>")).arg( photoName );
w = ( metaContact->picture().image().width() > 100 ) ? metaContact->picture().image().width() + 20 : 120;
}
diff --git a/kopete/contactlist/kabcexport.cpp b/kopete/contactlist/kabcexport.cpp
index a9658f0..8801cde 100644
--- a/kopete/contactlist/kabcexport.cpp
+++ b/kopete/contactlist/kabcexport.cpp
@@ -107,7 +107,7 @@ KabcExportWizard::KabcExportWizard( QWidget *parent )
Q3CheckListItem * lvi = new ContactLVI( mc, m_contactList,
mc->displayName(), Q3CheckListItem::CheckBox );
lvi->setOn( false );
- if ( mc->metaContactId().contains(':') )
+ if ( !mc->kabcId().isEmpty() )
{
lvi->setOn( true );
lvi->setEnabled( true );
@@ -168,7 +168,7 @@ void KabcExportWizard::accept()
if ( item->isEnabled() && item->isOn() )
{
KABC::Addressee addr;
- addr = m_addressBook->findByUid( item->mc->metaContactId() );
+ addr = m_addressBook->findByUid( item->mc->kabcId() );
if ( addr.isEmpty() ) // unassociated contact
{
kDebug( 14000 ) << "creating addressee " << item->mc->displayName() << " in address book " << selectedResource->resourceName();
@@ -195,7 +195,7 @@ void KabcExportWizard::accept()
m_addressBook->insertAddressee( addr );
// set the metacontact's id to that of the new addressee
// - this causes the addressbook to be written by libkopete
- item->mc->setMetaContactId( addr.uid() );
+ item->mc->setKabcId( addr.uid() );
}
else
{
diff --git a/kopete/contactlist/kopeteaddrbookexport.cpp b/kopete/contactlist/kopeteaddrbookexport.cpp
index 9dd4800..bc8d575 100644
--- a/kopete/contactlist/kopeteaddrbookexport.cpp
+++ b/kopete/contactlist/kopeteaddrbookexport.cpp
@@ -168,7 +168,7 @@ void KopeteAddressBookExport::populateIM( const Kopete::Contact *contact, const
int KopeteAddressBookExport::showDialog()
{
- mAddressee = mAddressBook->findByUid( mMetaContact->metaContactId() );
+ mAddressee = mAddressBook->findByUid( mMetaContact->kabcId() );
if ( !mAddressee.isEmpty() )
{
numEmails = 0;
diff --git a/kopete/contactlist/kopetemetacontactitem.cpp b/kopete/contactlist/kopetemetacontactitem.cpp
diff --git a/libkopete/contactlist/xmlcontactstorage.cpp b/libkopete/contactlist/xmlcontactstorage.cpp
index 164ea3f..ec6cce6 100644
--- a/libkopete/contactlist/xmlcontactstorage.cpp
+++ b/libkopete/contactlist/xmlcontactstorage.cpp
@@ -21,6 +21,7 @@
// Qt includes
#include <QtCore/QFile>
+#include <QtCore/QUuid>
#include <QtCore/QRegExp>
#include <QtCore/QLatin1String>
#include <QtCore/QTextStream>
@@ -290,11 +291,15 @@ bool XmlContactStorage::parseMetaContact( Kopete::MetaContact *metaContact, cons
QString strContactId = element.attribute( QString::fromUtf8("contactId") );
if( !strContactId.isEmpty() )
{
- metaContact->setMetaContactId( strContactId );
+ metaContact->setMetaContactId( QUuid( strContactId ) );
// Set the KABC Picture
//metaContact->slotUpdateAddressBookPicture(); moved to MetaContact::setMetaContactId
}
+ QString strKabcId = element.attribute( QString::fromUtf8( "kabcId" ) );
+ if ( !strKabcId.isEmpty() )
+ metaContact->setKabcId( strKabcId );
+
QDomElement contactElement = element.firstChild().toElement();
while( !contactElement.isNull() )
{
@@ -436,7 +441,7 @@ bool XmlContactStorage::parseMetaContact( Kopete::MetaContact *metaContact, cons
{
// lets do the best conversion for the old name tracking
// if the custom display name is the same as kabc name, set the source to kabc
- if ( !metaContact->metaContactId().isEmpty() && ( metaContact->customDisplayName() == nameFromKABC( metaContact->metaContactId() )) )
+ if ( !metaContact->kabcId().isEmpty() && ( metaContact->customDisplayName() == nameFromKABC( metaContact->kabcId() )) )
metaContact->setDisplayNameSource( Kopete::MetaContact::SourceKABC );
else
metaContact->setDisplayNameSource( Kopete::MetaContact::SourceCustom );
@@ -452,7 +457,7 @@ bool XmlContactStorage::parseMetaContact( Kopete::MetaContact *metaContact, cons
}
else
{
- if ( !metaContact->metaContactId().isEmpty() && !photoFromKABC( metaContact->metaContactId() ).isNull() )
+ if ( !metaContact->kabcId().isEmpty() && !photoFromKABC( metaContact->kabcId() ).isNull() )
metaContact->setPhotoSource( Kopete::MetaContact::SourceKABC );
else
metaContact->setPhotoSource( Kopete::MetaContact::SourceCustom );
@@ -641,6 +646,7 @@ const QDomElement XmlContactStorage::storeMetaContact( Kopete::MetaContact *meta
QDomDocument metaContactDoc;
metaContactDoc.appendChild( metaContactDoc.createElement( QString::fromUtf8( "meta-contact" ) ) );
metaContactDoc.documentElement().setAttribute( QString::fromUtf8( "contactId" ), metaContact->metaContactId() );
+ metaContactDoc.documentElement().setAttribute( QString::fromUtf8( "kabcId" ), metaContact->kabcId() );
// the custom display name, used for the custom name source
QDomElement displayName = metaContactDoc.createElement( QString::fromUtf8("display-name" ) );
@@ -672,7 +678,7 @@ const QDomElement XmlContactStorage::storeMetaContact( Kopete::MetaContact *meta
// set the contact source for photo
_photoSource.setAttribute( QString::fromUtf8("source"), sourceToString( metaContact->photoSource() ) );
- if( !metaContact->metaContactId().isEmpty() )
+ if( !metaContact->kabcId().isEmpty() )
photo.setAttribute( QString::fromUtf8("syncWithKABC") , QString::fromUtf8( metaContact->isPhotoSyncedWithKABC() ? "true" : "false" ) );
if( metaContact->photoSourceContact() )
diff --git a/libkopete/kabcpersistence.cpp b/libkopete/kabcpersistence.cpp
index 8007943..febb315 100644
--- a/libkopete/kabcpersistence.cpp
+++ b/libkopete/kabcpersistence.cpp
@@ -106,7 +106,7 @@ void KABCPersistence::write( MetaContact * mc )
kDebug( 14010 ) << "looking up Addressee for " << mc->displayName() << "...";
// Look up the address book entry
- KABC::Addressee theAddressee = ab->findByUid( mc->metaContactId() );
+ KABC::Addressee theAddressee = ab->findByUid( mc->kabcId() );
// Check that if addressee is not deleted or if the link is spurious
// (inherited from Kopete < 0.8, where all metacontacts had random ids)
if ( theAddressee.isEmpty() )
@@ -222,17 +222,17 @@ void KABCPersistence::removeKABC( MetaContact *)
emit aboutToSave(this);
// If the metacontact is linked to a kabc entry
- if ( !d->metaContactId.isEmpty() )
+ if ( !d->kabcId().isEmpty() )
{
//kDebug( 14010 ) << "looking up Addressee for " << displayName() << "...";
// Look up the address book entry
- KABC::Addressee theAddressee = ab->findByUid( metaContactId() );
+ KABC::Addressee theAddressee = ab->findByUid( d->kabcId() );
if ( theAddressee.isEmpty() )
{
// remove the link
//kDebug( 14010 ) << "...not found.";
- d->metaContactId.clear();
+ d->kabcId.clear();
}
else
{
@@ -263,7 +263,7 @@ bool KABCPersistence::syncWithKABC( MetaContact * mc )
bool contactAdded = false;
// check whether the dontShowAgain was checked
KABC::AddressBook* ab = addressBook();
- KABC::Addressee addr = ab->findByUid( mc->metaContactId() );
+ KABC::Addressee addr = ab->findByUid( mc->kabcId() );
if ( !addr.isEmpty() ) // if we are associated with KABC
{
diff --git a/libkopete/kopetemetacontact.cpp b/libkopete/kopetemetacontact.cpp
index a44f6bc..25dbf28 100644
--- a/libkopete/kopetemetacontact.cpp
+++ b/libkopete/kopetemetacontact.cpp
@@ -72,6 +72,16 @@ MetaContact::~MetaContact()
delete d;
}
+QUuid MetaContact::metaContactId() const
+{
+ return d->metaContactId;
+}
+
+void MetaContact::setMetaContactId( const QUuid& newUuid)
+{
+ d->metaContactId = newUuid;
+}
+
void MetaContact::addContact( Contact *c )
{
if( d->contacts.contains( c ) )
@@ -591,8 +601,8 @@ QString MetaContact::displayName() const
{
// kabc source, try to get from addressbook
// if the metacontact has a kabc association
- if ( !metaContactId().isEmpty() )
- return nameFromKABC(metaContactId());
+ if ( !kabcId().isEmpty() )
+ return nameFromKABC(kabcId());
}
else if ( source == SourceContact )
{
@@ -960,7 +970,7 @@ void MetaContact::slotAllPluginsLoaded()
void MetaContact::slotUpdateAddressBookPicture()
{
KABC::AddressBook* ab = KABCPersistence::self()->addressBook();
- QString id = metaContactId();
+ QString id = kabcId();
if ( !id.isEmpty() && !id.contains(':') )
{
KABC::Addressee theAddressee = ab->findByUid(id);
@@ -1003,9 +1013,9 @@ void MetaContact::setTemporary( bool isTemporary, Group *group )
moveToGroup(temporaryGroup, group ? group : Group::topLevel());
}
-QString MetaContact::metaContactId() const
+QString MetaContact::kabcId() const
{
- if(d->metaContactId.isEmpty())
+ if(d->kabcId.isEmpty())
{
if(d->contacts.isEmpty())
return QString();
@@ -1014,12 +1024,12 @@ QString MetaContact::metaContactId() const
return QString();
return c->protocol()->pluginId()+QString::fromUtf8(":")+c->account()->accountId()+QString::fromUtf8(":") + c->contactId() ;
}
- return d->metaContactId;
+ return d->kabcId;
}
-void MetaContact::setMetaContactId( const QString& newMetaContactId )
+void MetaContact::setKabcId( const QString& newMetaContactId )
{
- if(newMetaContactId == d->metaContactId)
+ if(newMetaContactId == d->kabcId)
return;
// 1) Check the Id is not already used by another contact
@@ -1031,7 +1041,7 @@ void MetaContact::setMetaContactId( const QString& newMetaContactId )
// Don't remove IM addresses from kabc if we are changing contacts;
// other programs may have written that data and depend on it
- d->metaContactId = newMetaContactId;
+ d->kabcId = newMetaContactId;
if ( loading() )
{
slotUpdateAddressBookPicture();
@@ -1076,9 +1086,9 @@ void MetaContact::setPhotoSyncedWithKABC(bool b)
return;
}
- if ( !d->metaContactId.isEmpty() && !newValue.isNull())
+ if ( !d->kabcId.isEmpty() && !newValue.isNull())
{
- KABC::Addressee theAddressee = KABCPersistence::self()->addressBook()->findByUid( metaContactId() );
+ KABC::Addressee theAddressee = KABCPersistence::self()->addressBook()->findByUid( kabcId() );
if ( !theAddressee.isEmpty() )
{
diff --git a/libkopete/kopetemetacontact.h b/libkopete/kopetemetacontact.h
index f6182a0..490e7c2 100644
--- a/libkopete/kopetemetacontact.h
+++ b/libkopete/kopetemetacontact.h
@@ -24,6 +24,7 @@
#include "kopetecontactlistelement.h"
#include <QtCore/QList>
+#include <QtCore/QUuid>
#include <kdemacros.h>
#include <kurl.h>
@@ -61,7 +62,7 @@ class KOPETE_EXPORT MetaContact : public ContactListElement
Q_PROPERTY( bool isTemporary READ isTemporary )
Q_PROPERTY( bool canAcceptFiles READ canAcceptFiles )
//Q_PROPERTY( ulong idleTime READ idleTime )
- Q_PROPERTY( QString metaContactId READ metaContactId WRITE setMetaContactId )
+ Q_PROPERTY( QUuid metaContactId READ metaContactId WRITE setMetaContactId )
Q_PROPERTY( bool photoSyncedWithKABC READ isPhotoSyncedWithKABC WRITE setPhotoSyncedWithKABC )
public:
@@ -88,16 +89,28 @@ public:
/**
* @brief Returns this metacontact's ID.
*
- * Every metacontact has a unique id, set by when creating the contact, or reading the contactlist
- * TODO: make it real
+ * Every metacontact has a unique id, set when creating the contact,
+ * or reading the contactlist
*/
- QString metaContactId() const;
+ QUuid metaContactId() const;
/**
- * @brief Add or change the link to a KDE addressbook (KABC) Addressee.
- * FIXME: Use with care. You could create 1 to many relationships with the current implementation
+ * @internal
+ * Set the meta contact id for this meta contact to use. It should only
+ * be used by the contact list loading mechanism
*/
- void setMetaContactId( const QString& newMetaContactId );
+ void setMetaContactId( const QUuid& newMetaContactId );
+
+ /**
+ * @brief Get the KABC id for this metacontact
+ */
+ QString kabcId() const;
+
+ /**
+ * @brief Set the KABC id for this metacontact
+ * Use with care! You could create a one to many relationship
+ */
+ void setKabcId( const QString& newKabcId );
/**
* @brief Retrieve the list of contacts that are part of the meta contact
diff --git a/libkopete/kopetemetacontact_p.h b/libkopete/kopetemetacontact_p.h
index d37a243..aff3ecb 100644
--- a/libkopete/kopetemetacontact_p.h
+++ b/libkopete/kopetemetacontact_p.h
@@ -39,7 +39,7 @@ class MetaContact::Private
~Private()
{}
-
+ QUuid metaContactId;
// property sources
PropertySource photoSource;
PropertySource displayNameSource;
@@ -49,7 +49,7 @@ class MetaContact::Private
Contact *photoSourceContact;
// used when source is kabc
- QString metaContactId;
+ QString kabcId;
// used when source is custom
QString displayName;
diff --git a/libkopete/private/kopeteviewmanager.cpp b/libkopete/private/kopeteviewmanager.cpp
index c6a0466..b059bbc 100644
--- a/libkopete/private/kopeteviewmanager.cpp
+++ b/libkopete/private/kopeteviewmanager.cpp
@@ -311,7 +311,7 @@ void KopeteViewManager::messageAppended( Kopete::Message &msg, Kopete::ChatSessi
Kopete::MetaContact *mc= msg.from()->metaContact();
if(mc)
{
- notify->addContext( qMakePair( QString::fromLatin1("metacontact") , mc->metaContactId()) );
+ notify->addContext( qMakePair( QString::fromLatin1("metacontact") , mc->metaContactId().toString()) );
foreach( Kopete::Group *g , mc->groups() )
{
notify->addContext( qMakePair( QString::fromLatin1("group") , QString::number(g->groupId())) );
diff --git a/libkopete/ui/addressbooklinkwidget.cpp b/libkopete/ui/addressbooklinkwidget.cpp
index 3c970b2..f6512ab 100644
--- a/libkopete/ui/addressbooklinkwidget.cpp
+++ b/libkopete/ui/addressbooklinkwidget.cpp
@@ -81,7 +81,13 @@ void AddressBookLinkWidget::slotSelectAddressee()
else
message = i18n("Choose the corresponding entry in the address book" );
- Kopete::UI::AddressBookSelectorDialog dialog( i18n("Addressbook Association"), message, ( mMetaContact ? mMetaContact->metaContactId() : QString::null ), this ); //krazy:exclude=nullstrassign for old broken gcc
+ QString assocDisplayText;
+ if ( mMetaContact )
+ {
+ assocDisplayText = mMetaContact->kabcId();
+ }
+ Kopete::UI::AddressBookSelectorDialog dialog( i18n("Addressbook Association"), message,
+ assocDisplayText, this );
int result = dialog.exec();
KABC::Addressee addr;
@@ -91,7 +97,7 @@ void AddressBookLinkWidget::slotSelectAddressee()
edtAddressee->setText( addr.realName() );
btnClear->setEnabled( !addr.isEmpty() );
- mSelectedUid = ( addr.isEmpty() ? QString::null : addr.uid() ); //krazy:exclude=nullstrassign for old broken gcc
+ mSelectedUid = ( addr.isEmpty() ? QString() : addr.uid() );
emit addresseeChanged( addr );
}
}
diff --git a/plugins/cryptography/cryptographyguiclient.cpp b/plugins/cryptography/cryptographyguiclient.cpp
index 7aa46e8..7e9886c 100644
--- a/plugins/cryptography/cryptographyguiclient.cpp
+++ b/plugins/cryptography/cryptographyguiclient.cpp
@@ -120,12 +120,12 @@ void CryptographyGUIClient::slotEncryptToggled()
if ( mc->pluginData ( CryptographyPlugin::plugin(), "gpgKey" ).isEmpty() && m_encAction->isChecked() )
{
// to grab the public key from KABC (this same code is in crytographyselectuserkey.cpp)
- KABC::Addressee addressee = Kopete::KABCPersistence::self()->addressBook()->findByUid ( mc->metaContactId() );
+ KABC::Addressee addressee = Kopete::KABCPersistence::self()->addressBook()->findByUid ( mc->kabcId() );
if ( ! addressee.isEmpty() )
{
QStringList keys;
- keys = CryptographyPlugin::getKabcKeys( mc->metaContactId() );
+ keys = CryptographyPlugin::getKabcKeys( mc->kabcId() );
// ask user if they want to use key found in address book
if ( keys.count() == 1 ) {
diff --git a/plugins/cryptography/cryptographyplugin.cpp b/plugins/cryptography/cryptographyplugin.cpp
index 122cdbe..2f856e1 100644
--- a/plugins/cryptography/cryptographyplugin.cpp
+++ b/plugins/cryptography/cryptographyplugin.cpp
@@ -268,7 +268,7 @@ void CryptographyPlugin::slotExportOneKey()
return;
}
- addressee = Kopete::KABCPersistence::addressBook()->findByUid ( mc->metaContactId() );
+ addressee = Kopete::KABCPersistence::addressBook()->findByUid ( mc->kabcId() );
if ( addressee.isEmpty() )
addressee.setName ( mc->displayName() );
addressee.insertCustom ( "KADDRESSBOOK", "OPENPGPFP", key );
diff --git a/plugins/cryptography/cryptographyselectuserkey.cpp b/plugins/cryptography/cryptographyselectuserkey.cpp
index a335c5e..14614fd 100644
--- a/plugins/cryptography/cryptographyselectuserkey.cpp
+++ b/plugins/cryptography/cryptographyselectuserkey.cpp
@@ -64,7 +64,7 @@ CryptographySelectUserKey::CryptographySelectUserKey ( const QString& key ,Kopet
{
// find keys in address book and possibly use them (this same code is in cryptographyguiclient.cpp)
QStringList keys;
- keys = CryptographyPlugin::getKabcKeys ( m_metaContact->metaContactId() );
+ keys = CryptographyPlugin::getKabcKeys ( m_metaContact->kabcId() );
// if there is one key found, use it automatically
if ( keys.count() == 1 )
@@ -76,7 +76,7 @@ CryptographySelectUserKey::CryptographySelectUserKey ( const QString& key ,Kopet
// if more than one if found, let the user choose which one
if ( keys.count() > 1 )
{
- KABC::Addressee addressee = Kopete::KABCPersistence::self()->addressBook()->findByUid ( mc->metaContactId() );
+ KABC::Addressee addressee = Kopete::KABCPersistence::self()->addressBook()->findByUid ( mc->kabcId() );
KDialog dialog ( this );
QWidget w ( &dialog );
Ui::KabcKeySelectorUI ui;
diff --git a/plugins/cryptography/exportkeys.cpp b/plugins/cryptography/exportkeys.cpp
index ed6b237..60876d7 100644
--- a/plugins/cryptography/exportkeys.cpp
+++ b/plugins/cryptography/exportkeys.cpp
@@ -54,7 +54,7 @@ ExportKeys::ExportKeys ( Kopete::ChatSession * cs, QWidget *parent )
key = mc->pluginData( CryptographyPlugin::plugin(), "gpgKey" );
if (key.isEmpty())
continue;
- addressee = Kopete::KABCPersistence::addressBook()->findByUid (mc->metaContactId());
+ addressee = Kopete::KABCPersistence::addressBook()->findByUid (mc->kabcId());
if (addressee.isEmpty())
addressee.setName ( mc->displayName() );
addressee.insertCustom ("KADDRESSBOOK", "OPENPGPFP", key);
pgpJb7xaphd0w.pgp
Description: PGP signature
_______________________________________________ kopete-devel mailing list [email protected] https://mail.kde.org/mailman/listinfo/kopete-devel
