From 5b706099c9b17590b91f99e3e632b68b1788064d Mon Sep 17 00:00:00 2001 From: Carsten Burghardt Date: Mon, 1 Nov 2004 10:07:50 +0000 Subject: [PATCH] Seems like it was no good idea to use the same signal for new searches and for the update from added messages. But as Till kept annoying me this should be fixed now ;-) svn path=/trunk/kdepim/; revision=359518 --- folderstorage.cpp | 6 +++--- folderstorage.h | 1 + kmfolderimap.cpp | 53 +++++++++++++++++++++++++++++----------------- kmfolderimap.h | 2 ++ kmfoldersearch.cpp | 20 +++++++---------- kmfoldersearch.h | 2 +- 6 files changed, 49 insertions(+), 35 deletions(-) diff --git a/folderstorage.cpp b/folderstorage.cpp index 39bcbb4f3..52d8817f6 100644 --- a/folderstorage.cpp +++ b/folderstorage.cpp @@ -1018,11 +1018,11 @@ void FolderStorage::search( KMSearchPattern* pattern ) //----------------------------------------------------------------------------- void FolderStorage::search( KMSearchPattern* pattern, Q_UINT32 serNum ) { - QValueList serNums; + Q_UINT32 mySerNum = 0; if ( pattern->matches( serNum ) ) - serNums.append( serNum ); + mySerNum = serNum; - emit searchDone( folder(), serNums ); + emit searchDone( folder(), mySerNum ); } #include "folderstorage.moc" diff --git a/folderstorage.h b/folderstorage.h index 7f867e474..15a470993 100644 --- a/folderstorage.h +++ b/folderstorage.h @@ -465,6 +465,7 @@ signals: * The matching serial numbers are included */ void searchDone( KMFolder*, QValueList serNums ); + void searchDone( KMFolder*, Q_UINT32 serNum ); public slots: /** Incrementally update the index if possible else call writeIndex */ diff --git a/kmfolderimap.cpp b/kmfolderimap.cpp index 68fe2821a..151edcd4b 100644 --- a/kmfolderimap.cpp +++ b/kmfolderimap.cpp @@ -1931,8 +1931,7 @@ void KMFolderImap::search( KMSearchPattern* pattern, Q_UINT32 serNum ) if ( !pattern ) { // not much to do here - QValueList serNums; - emit searchDone( folder(), serNums ); + emit searchDone( folder(), 0 ); return; } QString searchString = searchStringFromPattern( pattern ); @@ -1941,26 +1940,23 @@ void KMFolderImap::search( KMSearchPattern* pattern, Q_UINT32 serNum ) // download the message and search local int idx = -1; KMFolder *aFolder = 0; - kmkernel->msgDict()->getLocation(serNum, &aFolder, &idx); + kmkernel->msgDict()->getLocation( serNum, &aFolder, &idx ); - mSearchSerNums.clear(); KMMessage * msg = getMsg( idx ); ImapJob *job = new ImapJob( msg ); job->setParentFolder( this ); connect( job, SIGNAL(messageRetrieved(KMMessage*)), - this, SLOT(slotSearchMessageArrived(KMMessage*)) ); - mRemainingMsgs = 1; - mImapSearchData = ""; + this, SLOT(slotSearchSingleMessage(KMMessage*)) ); job->start(); } else { // imap search - // remember the serNum + // remember the serNum so that we don't have to reconstruct it later mSearchSerNums.clear(); mSearchSerNums.append( serNum ); int idx = -1; KMFolder *aFolder = 0; - kmkernel->msgDict()->getLocation(serNum, &aFolder, &idx); + kmkernel->msgDict()->getLocation( serNum, &aFolder, &idx ); assert(aFolder && (idx != -1)); KMMsgBase *mb = getMsgBase( idx ); @@ -1974,7 +1970,7 @@ void KMFolderImap::search( KMSearchPattern* pattern, Q_UINT32 serNum ) KIO::SimpleJob *job = KIO::special( url, packedArgs, false ); KIO::Scheduler::assignJobToSlave(mAccount->slave(), job); connect( job, SIGNAL(infoMessage(KIO::Job*,const QString&)), - SLOT(slotSearchData(KIO::Job*,const QString&)) ); + SLOT(slotSearchDataSingleMessage(KIO::Job*,const QString&)) ); connect( job, SIGNAL(result(KIO::Job *)), SLOT(slotSearchResult(KIO::Job *)) ); } @@ -1990,6 +1986,7 @@ void KMFolderImap::slotSearch() return slotSearchData( 0, QString::null ); // do the IMAP search + mSearchSerNums.clear(); KURL url = mAccount->getUrl(); url.setPath( imapPath() + ";SECTION=" + searchString ); QByteArray packedArgs; @@ -2071,12 +2068,6 @@ void KMFolderImap::slotSearchData( KIO::Job* job, const QString& data ) if ( mLocalSearchPattern->isEmpty() ) { - if ( !mSearchSerNums.empty() && !data.isEmpty() ) - { - // we directly searched for these sernums - emit searchDone( folder(), mSearchSerNums ); - return; - } // search for the serial number of the UIDs // data contains all found uids separated by blank QValueList serNums; @@ -2094,7 +2085,6 @@ void KMFolderImap::slotSearchData( KIO::Job* job, const QString& data ) { // we have search patterns that can not be handled by the server // so we need to download all messages and check - mSearchSerNums.clear(); mRemainingMsgs = 0; QString question = i18n("To execute your search all messages of the folder %1 " "have to be downloaded from the server. This may take some time. " @@ -2122,6 +2112,27 @@ void KMFolderImap::slotSearchData( KIO::Job* job, const QString& data ) } +//----------------------------------------------------------------------------- +void KMFolderImap::slotSearchDataSingleMessage( KIO::Job* job, const QString& data ) +{ + if ( job && job->error() ) + return; + + if ( !data.isEmpty() ) + emit searchDone( folder(), mSearchSerNums.first() ); + else + emit searchDone( folder(), 0 ); +} + +//----------------------------------------------------------------------------- +void KMFolderImap::slotSearchSingleMessage( KMMessage* msg ) +{ + if ( mLocalSearchPattern->matches( msg ) ) + emit searchDone( folder(), msg->getMsgSerNum() ); + else + emit searchDone( folder(), 0 ); +} + //----------------------------------------------------------------------------- void KMFolderImap::slotSearchMessageArrived( KMMessage* msg ) { @@ -2163,9 +2174,13 @@ void KMFolderImap::slotSearchResult( KIO::Job *job ) { if ( job->error() ) { - QValueList serNums; mAccount->handleJobError( job, i18n("Error while searching.") ); - emit searchDone( folder(), serNums ); + if ( mSearchSerNums.empty() ) + { + QValueList serNums; + emit searchDone( folder(), serNums ); + } else + emit searchDone( folder(), 0 ); } } diff --git a/kmfolderimap.h b/kmfolderimap.h index 221138c03..8404e416f 100644 --- a/kmfolderimap.h +++ b/kmfolderimap.h @@ -446,12 +446,14 @@ protected slots: * Is called when the search is done */ void slotSearchData( KIO::Job * job, const QString& data ); + void slotSearchDataSingleMessage( KIO::Job * job, const QString& data ); void slotSearchResult( KIO::Job * job ); /** * Called when a msg was downloaded for local search */ void slotSearchMessageArrived( KMMessage* msg ); + void slotSearchSingleMessage( KMMessage* msg ); protected: QString mImapPath; diff --git a/kmfoldersearch.cpp b/kmfoldersearch.cpp index 9820d3c01..b270d020d 100644 --- a/kmfoldersearch.cpp +++ b/kmfoldersearch.cpp @@ -916,33 +916,29 @@ void KMFolderSearch::examineAddedMessage(KMFolder *aFolder, Q_UINT32 serNum) folder->open(); connect( folder->storage(), - SIGNAL( searchDone( KMFolder*, QValueList ) ), + SIGNAL( searchDone( KMFolder*, Q_UINT32 ) ), this, - SLOT( slotSearchExamineMsgDone( KMFolder*, QValueList ) ) ); + SLOT( slotSearchExamineMsgDone( KMFolder*, Q_UINT32 ) ) ); folder->storage()->search( search()->searchPattern(), serNum ); } -void KMFolderSearch::slotSearchExamineMsgDone( KMFolder* folder, QValueList serNums ) +void KMFolderSearch::slotSearchExamineMsgDone( KMFolder* folder, Q_UINT32 serNum ) { - kdDebug(5006) << k_funcinfo << folder->label() << " found " << serNums.count() << endl; + kdDebug(5006) << k_funcinfo << folder->label() << " found " << serNum << endl; disconnect( folder->storage(), - SIGNAL( searchDone( KMFolder*, QValueList ) ), + SIGNAL( searchDone( KMFolder*, Q_UINT32 ) ), this, - SLOT( slotSearchExamineMsgDone( KMFolder*, QValueList ) ) ); + SLOT( slotSearchExamineMsgDone( KMFolder*, Q_UINT32 ) ) ); folder->close(); - if ( serNums.empty() ) + if ( serNum == 0 ) return; if (mSearch->running()) { mSearch->stop(); mExecuteSearchTimer->start( 0, true ); } else { - QValueListIterator it; - for ( it = serNums.begin(); it != serNums.end(); ++it ) - { - addSerNum( *it ); - } + addSerNum( serNum ); } } diff --git a/kmfoldersearch.h b/kmfoldersearch.h index 239b60c6b..27d1c96db 100644 --- a/kmfoldersearch.h +++ b/kmfoldersearch.h @@ -140,7 +140,7 @@ public slots: virtual int updateIndex(); // Examine the added message - void slotSearchExamineMsgDone( KMFolder*, QValueList ); + void slotSearchExamineMsgDone( KMFolder*, Q_UINT32 serNum ); public: //See base class for documentation