Index: ../kdenetwork/kopete/kopete/contactlist/contactlistproxymodel.cpp =================================================================== --- ../kdenetwork/kopete/kopete/contactlist/contactlistproxymodel.cpp (revision 1046954) +++ ../kdenetwork/kopete/kopete/contactlist/contactlistproxymodel.cpp (working copy) @@ -23,8 +23,10 @@ #include "kopetegroup.h" #include "kopetemetacontact.h" #include "kopetecontactlist.h" +#include "kopetecontact.h" #include "kopeteappearancesettings.h" #include "kopeteitembase.h" +#include namespace Kopete { @@ -116,10 +118,33 @@ int connectedContactsCount = model->data( current, Kopete::Items::ConnectedCountRole ).toInt(); int totalContactsCount = model->data( current, Kopete::Items::TotalCountRole ).toInt(); - // TODO: Find out how to check if we should hide the group if no metaContact was found. if ( !filterRegExp().isEmpty() ) - return true; + { + // This shows or hides the contacts group folder if something was found. + // Walk through the group's metacontacts and see it the search result was found + // If it is found then we can show this group folder. + // This is fairly slow with > group 10000 contacts. Reasonable? + for ( int i = 0; i < model->rowCount( current ); i++ ) + { + QModelIndex qmi = model->index( i, 0, current ); + QObject* mcObject = qVariantValue( model->data( qmi, Kopete::Items::ObjectRole ) ); + Kopete::MetaContact *mc = qobject_cast(mcObject); + if ( model->data( qmi, Kopete::Items::TypeRole ) != Kopete::Items::MetaContact ) + continue; + + // Do a better search. + if ( searchContactInfo( mc, filterRegExp() ) ) + { + qobject_cast(groupObject)->setExpanded(true); + return true; + } + } + + return false; + } + + if ( !showEmpty && totalContactsCount == 0 ) return false; @@ -133,8 +158,11 @@ { if ( !filterRegExp().isEmpty() ) { - QString mcName = model->data( current, Qt::DisplayRole ).toString(); - return mcName.contains( filterRegExp() ); + QObject* contactObject = qVariantValue( model->data( current, Kopete::Items::ObjectRole ) ); + Kopete::MetaContact *mc = qobject_cast(contactObject); + + // Do a better search + return searchContactInfo( mc, filterRegExp() ); } int mcStatus = model->data( current, Kopete::Items::OnlineStatusRole ).toInt(); @@ -147,8 +175,36 @@ return false; } +// Better search. Now a search will look in the metacontact display name, the invidual account contact names and any email addresses. +bool ContactListProxyModel::searchContactInfo(Kopete::MetaContact *mc, QRegExp searchPattern) const +{ + // Check the display name + if ( mc->displayName().contains( searchPattern ) ) + return true; + + // Check the address book + KABC::Addressee addressee = KABC::StdAddressBook::self()->findByUid( mc->kabcId() ); + if ( !addressee.isEmpty() ) + { + QString emailAddr = addressee.fullEmail(); + + if ( emailAddr.contains( searchPattern ) ) + return true; + } + + // Check alternative names + foreach( Kopete::Contact* c , mc->contacts() ) + { + // Search each metacontacts' contacts + if ( c->contactId().contains( searchPattern ) ) + return true; + } + + return false; } } +} + #include "contactlistproxymodel.moc" Index: ../kdenetwork/kopete/kopete/contactlist/contactlistproxymodel.h =================================================================== --- ../kdenetwork/kopete/kopete/contactlist/contactlistproxymodel.h (revision 1046954) +++ ../kdenetwork/kopete/kopete/contactlist/contactlistproxymodel.h (working copy) @@ -47,6 +47,9 @@ bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const; bool showOffline; bool showEmptyFolders; + + private: + bool searchContactInfo( Kopete::MetaContact *mc, QRegExp searchPattern ) const; }; }