Hi folks. I started looking at implementing (subclassing) an QAbstractItemModel to use for the contact list, and what i started with was to look at the contact list itself (Kopete::ContactList, that is, not UI). Here are my thoughts:
currently, the list does no sorting and is basically just a central lookup point for contacts and stuff. i think that's cool. sorting should go into a data model, so different views (a feature i hope we might end up with) can use differently sorted models (grouped vs. plain, etc). So it's basically a lookup point, and i thought a QHash would be a better way to look up in many metacontacts. For groups it probably doesn't _really_ matter, but i just went ahead and did it anyway. My main reasoning btw: most functions just iterate over all contacts anyways (data structure shouldnt make a difference), but the few lookup ones can gain performance when using a hash. Also, i would like to suggest this: The only other thing happening in there is a bunch of (mostly rather unelegant) functions that are only used for the dcop interface, and i think they should not be in there. Since the dcop interface has to be ported to dbus anyways, i figured it could go into a seperate place. my suggestion would even be: put in a plugin. that way, whenever it is decided that some external app needs a new function, it would suffice to release a new version of the plugin. but i don't really care about that, it should just be seperated from the core contact list. Also, i think all the stuff related to selection should not be in there, that should be view/gui specific.I think ContactList shoud be a pure backend. Anyways, attached is a patch for trunk to use QHash instead of QMap for storing the metacontacts and the groups. Let me know what you think about all that, i am ready to give it some loving... regards, conrausch -- [EMAIL PROTECTED] http://conrausch.doesntexist.org JabberID: [EMAIL PROTECTED] # support cryptography! public key: http://elise.no-ip.com/ch.gmx.asc Modified files: cad/libgeda Makefile Log: Ve vill make you obey ze new autoconf rulez! Orr elz you vill listen to Mariah Carey recordingz until ze brainz come out ze noze.
Index: libkopete/kopetecontactlist.cpp
===================================================================
--- libkopete/kopetecontactlist.cpp (revision 563449)
+++ libkopete/kopetecontactlist.cpp (working copy)
@@ -25,6 +25,7 @@
#include <qtimer.h>
//Added by qt3to4:
#include <QTextStream>
+#include <QHash>
#include <kapplication.h>
#include <kabc/stdaddressbook.h>
@@ -52,8 +53,8 @@
/** Flag: do not save the contactlist until she is completely loaded */
bool loaded ;
- QList<MetaContact *> contacts;
- QList<Group *> groups;
+ QHash<QString, MetaContact *> contacts;
+ QHash<uint, Group *> groups;
QList<MetaContact *> selectedMetaContacts;
QList<Group *> selectedGroups;
@@ -114,42 +115,25 @@
QList<MetaContact *> ContactList::metaContacts() const
{
- return d->contacts;
+ return d->contacts.values();
}
QList<Group *> ContactList::groups() const
{
- return d->groups;
+ return d->groups.values();
}
MetaContact *ContactList::metaContact( const QString &metaContactId ) const
{
- QListIterator<MetaContact *> it( d->contacts );
-
- while ( it.hasNext() )
- {
- MetaContact *mc = it.next();
- if( mc->metaContactId() == metaContactId )
- return mc;
- }
-
- return 0L;
+ return d->contacts.value(metaContactId, 0L);
}
Group * ContactList::group(unsigned int groupId) const
{
- QListIterator<Group *> it(d->groups);
-
- while ( it.hasNext() )
- {
- Group *curr = it.next();
- if( curr->groupId()==groupId )
- return curr;
- }
- return 0L;
+ return d->groups.value(groupId, 0L);
}
@@ -169,10 +153,11 @@
MetaContact *ContactList::findMetaContactByDisplayName( const QString &displayName ) const
{
- QListIterator<MetaContact *> it( d->contacts );
+ QMutableHashIterator<QString, MetaContact *> it( d->contacts );
while ( it.hasNext() )
{
- MetaContact *mc = it.next();
+ it.next();
+ MetaContact *mc = it.value();
// kDebug(14010) << "Display Name: " << it.current()->displayName() << "\n";
if( mc->displayName() == displayName ) {
return mc;
@@ -201,10 +186,11 @@
if( type == Group::Temporary )
return Group::temporary();
- QListIterator<Group *> it(d->groups);
+ QMutableHashIterator<uint, Group *> it(d->groups);
while ( it.hasNext() )
{
- Group *curr = it.next();
+ it.next();
+ Group *curr = it.value();
if( curr->type() == type && curr->displayName() == displayName )
return curr;
}
@@ -226,12 +212,12 @@
}
-void ContactList::addMetaContact( MetaContact *mc )
+void ContactList::addMetaContact(MetaContact *mc)
{
- if ( d->contacts.contains( mc ) )
+ if ( d->contacts.contains( mc->metaContactId() ) )
return;
- d->contacts.append( mc );
+ d->contacts.insert( mc->metaContactId(), mc );
emit metaContactAdded( mc );
connect( mc, SIGNAL( persistentDataChanged( ) ), SLOT( slotSaveLater() ) );
@@ -240,39 +226,39 @@
}
-void ContactList::removeMetaContact(MetaContact *m)
+void ContactList::removeMetaContact(MetaContact *mc)
{
- if ( !d->contacts.contains(m) )
+ if ( ! d->contacts.contains(mc->metaContactId()) )
{
kDebug(14010) << k_funcinfo << "Trying to remove a not listed MetaContact." << endl;
return;
}
- if ( d->selectedMetaContacts.contains( m ) )
+ if ( d->selectedMetaContacts.contains( mc ) )
{
- d->selectedMetaContacts.removeAll( m );
+ d->selectedMetaContacts.removeAll( mc );
setSelectedItems( d->selectedMetaContacts, d->selectedGroups );
}
//removes subcontact from server here and now.
- QList<Contact *> cts = m->contacts();
+ QList<Contact *> cts = mc->contacts();
QListIterator<Contact *> it(cts);
while( it.hasNext() )
{
it.next()->deleteContact();
}
- d->contacts.removeAll( m );
- emit metaContactRemoved( m );
- m->deleteLater();
+ d->contacts.remove( mc->metaContactId() );
+ emit metaContactRemoved( mc );
+ mc->deleteLater();
}
void ContactList::addGroup( Group * g )
{
- if(!d->groups.contains(g) )
+ if( ! d->groups.contains(g->groupId()) )
{
- d->groups.append( g );
+ d->groups.insert( g->groupId(), g );
emit groupAdded( g );
connect( g , SIGNAL ( displayNameChanged(Kopete::Group* , const QString & )) , this , SIGNAL ( groupRenamed(Kopete::Group* , const QString & )) ) ;
}
@@ -286,7 +272,7 @@
setSelectedItems( d->selectedMetaContacts, d->selectedGroups );
}
- d->groups.removeAll( g );
+ d->groups.remove( g->groupId() );
emit groupRemoved( g );
g->deleteLater();
}
@@ -911,15 +897,19 @@
doc.documentElement().setAttribute( QLatin1String("version"), QLatin1String("1.0"));
// Save group information. ie: Open/Closed, pehaps later icons? Who knows.
- QListIterator<Group *> it(d->groups);
+ QMutableHashIterator<uint, Group *> it(d->groups);
while ( it.hasNext() )
- doc.documentElement().appendChild( doc.importNode( (it.next())->toXML(), true ) );
+ {
+ it.next();
+ doc.documentElement().appendChild( doc.importNode(it.value()->toXML(), true ) );
+ }
// Save metacontact information.
- QListIterator<MetaContact *> mcit(d->contacts);
+ QMutableHashIterator<QString, MetaContact *> mcit(d->contacts);
while ( mcit.hasNext() )
{
- MetaContact *mc = mcit.next();
+ mcit.next();
+ MetaContact *mc = mcit.value();
if( !mc->isTemporary() )
doc.documentElement().appendChild( doc.importNode( mc->toXML(), true ) );
}
@@ -937,10 +927,11 @@
QStringList ContactList::contacts() const
{
QStringList contacts;
- QListIterator<Kopete::MetaContact *> it( d->contacts );
+ QHashIterator<QString, Kopete::MetaContact *> it( d->contacts );
while ( it.hasNext() )
{
- contacts.append( it.next()->displayName() );
+ it.next();
+ contacts.append( it.value()->displayName() );
}
return contacts;
}
@@ -948,10 +939,11 @@
QStringList ContactList::contactStatuses() const
{
QStringList meta_contacts;
- QListIterator<Kopete::MetaContact *> it( d->contacts );
+ QHashIterator<QString, Kopete::MetaContact *> it( d->contacts );
while ( it.hasNext() )
{
- Kopete::MetaContact * mc = it.next();
+ it.next();
+ const Kopete::MetaContact * mc = it.value();
meta_contacts.append( QString::fromLatin1( "%1 (%2)" ).
arg( mc->displayName(), mc->statusString() ));
}
@@ -961,10 +953,11 @@
QStringList ContactList::reachableContacts() const
{
QStringList contacts;
- QListIterator<Kopete::MetaContact *> it( d->contacts );
+ QHashIterator<QString, Kopete::MetaContact *> it( d->contacts );
while ( it.hasNext() )
{
- Kopete::MetaContact * mc = it.next();
+ it.next();
+ const Kopete::MetaContact * mc = it.value();
if ( mc->isReachable() )
contacts.append( mc->displayName() );
}
@@ -974,10 +967,11 @@
QList<Contact *> ContactList::onlineContacts() const
{
QList<Kopete::Contact *> result;
- QListIterator<Kopete::MetaContact *> it( d->contacts );
+ QHashIterator<QString, Kopete::MetaContact *> it( d->contacts );
while ( it.hasNext() )
{
- Kopete::MetaContact *mc = it.next();
+ it.next();
+ const Kopete::MetaContact *mc = it.value();
if ( mc->isOnline() )
{
QList<Kopete::Contact *> contacts = mc->contacts();
@@ -996,10 +990,11 @@
QList<Kopete::MetaContact *> Kopete::ContactList::onlineMetaContacts() const
{
QList<Kopete::MetaContact *> result;
- QListIterator<Kopete::MetaContact *> it( d->contacts );
+ QMutableHashIterator<QString, Kopete::MetaContact *> it( d->contacts );
while ( it.hasNext() )
{
- Kopete::MetaContact * mc = it.next();
+ it.next();
+ Kopete::MetaContact * mc = it.value();
if ( mc->isOnline() )
result.append( mc );
}
@@ -1009,10 +1004,11 @@
QList<Kopete::MetaContact *> Kopete::ContactList::onlineMetaContacts( const QString &protocolId ) const
{
QList<Kopete::MetaContact *> result;
- QListIterator<Kopete::MetaContact *> it( d->contacts );
+ QMutableHashIterator<QString, Kopete::MetaContact *> it( d->contacts );
while ( it.hasNext() )
{
- Kopete::MetaContact * mc = it.next();
+ it.next();
+ Kopete::MetaContact * mc = it.value();
// FIXME: This loop is not very efficient :(
if ( mc->isOnline() )
{
@@ -1032,10 +1028,11 @@
QList<Kopete::Contact *> Kopete::ContactList::onlineContacts( const QString &protocolId ) const
{
QList<Kopete::Contact *> result;
- QListIterator<Kopete::MetaContact *> it( d->contacts );
+ QHashIterator<QString, Kopete::MetaContact *> it( d->contacts );
while ( it.hasNext() )
{
- Kopete::MetaContact * mc = it.next();
+ it.next();
+ const Kopete::MetaContact * mc = it.value();
// FIXME: This loop is not very efficient :(
if ( mc->isOnline() )
{
@@ -1056,10 +1053,11 @@
{
QStringList contacts;
QList<Kopete::MetaContact *> result;
- QListIterator<Kopete::MetaContact *> it( d->contacts );
+ QHashIterator<QString, Kopete::MetaContact *> it( d->contacts );
while ( it.hasNext() )
{
- Kopete::MetaContact * mc = it.next();
+ it.next();
+ const Kopete::MetaContact * mc = it.value();
if ( mc->canAcceptFiles() )
contacts.append( mc->displayName() );
}
@@ -1095,15 +1093,15 @@
// kDebug(14010) << "Get contacts for: " << displayName << "\n";
QStringList protocols;
- Kopete::MetaContact *c = findMetaContactByDisplayName( displayName );
- if( c )
+ Kopete::MetaContact *mc = findMetaContactByDisplayName( displayName );
+ if( mc )
{
- QList<Kopete::Contact *> mContacts = c->contacts();
- kDebug(14010) << mContacts.count() << endl;
- QListIterator<Kopete::Contact *> jt( mContacts );
- while ( jt.hasNext() )
+ QList<Kopete::Contact *> contacts = mc->contacts();
+ kDebug(14010) << contacts.count() << endl;
+ QListIterator<Kopete::Contact *> it( contacts );
+ while ( it.hasNext() )
{
- Kopete::Contact *c = jt.next();
+ Kopete::Contact *c = it.next();
kDebug(14010) << "1" << c->protocol()->pluginId() << endl;
if( c->canAcceptFiles() ) {
kDebug(14010) << c->protocol()->pluginId() << endl;
pgpiSKFhifBn6.pgp
Description: PGP signature
_______________________________________________ kopete-devel mailing list [email protected] https://mail.kde.org/mailman/listinfo/kopete-devel
