From b5756b7457b82a198814a7da92f69365727eb02f Mon Sep 17 00:00:00 2001 From: Carsten Burghardt Date: Wed, 27 Oct 2004 20:15:44 +0000 Subject: [PATCH] Several fixes: - the search folder should of course also check added messages correctly - finish the progressitem when the move to an imap folder fails svn path=/trunk/kdepim/; revision=358300 --- folderstorage.cpp | 10 ++++++ folderstorage.h | 12 ++++++-- imapaccountbase.cpp | 6 ++++ imapjob.cpp | 11 +++++-- kmcommands.cpp | 2 +- kmfolderimap.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++- kmfolderimap.h | 6 ++++ kmfoldersearch.cpp | 48 +++++++++++++++++------------ kmfoldersearch.h | 3 ++ 9 files changed, 145 insertions(+), 28 deletions(-) diff --git a/folderstorage.cpp b/folderstorage.cpp index 76bc499f5..39bcbb4f3 100644 --- a/folderstorage.cpp +++ b/folderstorage.cpp @@ -1015,4 +1015,14 @@ void FolderStorage::search( KMSearchPattern* pattern ) emit searchDone( folder(), serNums ); } +//----------------------------------------------------------------------------- +void FolderStorage::search( KMSearchPattern* pattern, Q_UINT32 serNum ) +{ + QValueList serNums; + if ( pattern->matches( serNum ) ) + serNums.append( serNum ); + + emit searchDone( folder(), serNums ); +} + #include "folderstorage.moc" diff --git a/folderstorage.h b/folderstorage.h index 9a92e89a8..7f867e474 100644 --- a/folderstorage.h +++ b/folderstorage.h @@ -407,11 +407,17 @@ public: KMail::FolderContentsType contentsType() const { return mContentsType; } /** - * Search for messages - * The end is signaled with searchDone() - */ + * Search for messages + * The end is signaled with searchDone() + */ virtual void search( KMSearchPattern* ); + /** + * Check if the message matches the search criteria + * The end is signaled with searchDone() + */ + virtual void search( KMSearchPattern*, Q_UINT32 serNum ); + signals: /** Emitted when the status, name, or associated accounts of this folder changed. */ diff --git a/imapaccountbase.cpp b/imapaccountbase.cpp index bd3d7adc7..a29c528b6 100644 --- a/imapaccountbase.cpp +++ b/imapaccountbase.cpp @@ -285,6 +285,12 @@ namespace KMail { bool ImapAccountBase::handleJobError( KIO::Job *job, const QString& context, bool abortSync ) { + JobIterator it = findJob( job ); + if ( it != jobsEnd() && (*it).progressItem ) + { + (*it).progressItem->setComplete(); + (*it).progressItem = 0; + } return handleError( job->error(), job->errorText(), job, context, abortSync ); } diff --git a/imapjob.cpp b/imapjob.cpp index 8423fa14e..dce8bfdb9 100644 --- a/imapjob.cpp +++ b/imapjob.cpp @@ -144,8 +144,8 @@ void ImapJob::init( JobType jt, QString sets, KMFolderImap* folder, true, account->useSSL() || account->useTLS() ); jd.progressItem->setTotalItems( jd.total ); - connect ( jd.progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), -account, SLOT( slotAbortRequested( KPIM:ProgressItem* ) ) ); + connect ( jd.progressItem, SIGNAL( progressItemCanceled( KPIM::ProgressItem*)), + account, SLOT( slotAbortRequested( KPIM::ProgressItem* ) ) ); KIO::SimpleJob *simpleJob = KIO::put( url, 0, FALSE, FALSE, FALSE ); KIO::Scheduler::assignJobToSlave( account->slave(), simpleJob ); mJob = simpleJob; @@ -595,7 +595,12 @@ void ImapJob::slotCopyMessageResult( KIO::Job *job ) if (job->error()) { - account->handleJobError( job, i18n("Error while copying messages.") ); + mErrorCode = job->error(); + QString errStr = i18n("Error while copying messages."); + if ( (*it).progressItem ) + (*it).progressItem->setStatus( errStr ); + account->handleJobError( job, errStr ); + deleteLater(); return; } else { if ( !(*it).msgList.isEmpty() ) diff --git a/kmcommands.cpp b/kmcommands.cpp index 96c480d09..13cf9bbd4 100644 --- a/kmcommands.cpp +++ b/kmcommands.cpp @@ -1832,7 +1832,7 @@ KMCommand::Result KMMoveCommand::execute() } } if (!list.isEmpty() && mDestFolder) { - mDestFolder->moveMsg(list, &index); + mDestFolder->moveMsg(list, &index); } else { FolderToMessageListMap::Iterator it; for ( it = folderDeleteList.begin(); it != folderDeleteList.end(); ++it ) { diff --git a/kmfolderimap.cpp b/kmfolderimap.cpp index c42327b7c..5931ac9c4 100644 --- a/kmfolderimap.cpp +++ b/kmfolderimap.cpp @@ -419,6 +419,8 @@ int KMFolderImap::addMsg(QPtrList& msgList, int* aIndex_ret) imapJob = new ImapJob(temp_msgs, *it, ImapJob::tMoveMessage, this); connect(imapJob, SIGNAL(messageCopied(QPtrList)), SLOT(addMsgQuiet(QPtrList))); + connect(imapJob, SIGNAL(result(KMail::FolderJob*)), + SLOT(slotCopyMsgResult(KMail::FolderJob*))); imapJob->start(); } } @@ -465,6 +467,13 @@ int KMFolderImap::addMsg(QPtrList& msgList, int* aIndex_ret) return 0; } +//----------------------------------------------------------------------------- +void KMFolderImap::slotCopyMsgResult( FolderJob* job ) +{ + if ( job->error() ) // getFolder() will not be called in this case + emit folderComplete( this, false ); +} + //----------------------------------------------------------------------------- void KMFolderImap::copyMsg(QPtrList& msgList) { @@ -1916,6 +1925,61 @@ void KMFolderImap::search( KMSearchPattern* pattern ) getFolder(); } +//----------------------------------------------------------------------------- +void KMFolderImap::search( KMSearchPattern* pattern, Q_UINT32 serNum ) +{ + if ( !pattern ) + { + // not much to do here + QValueList serNums; + emit searchDone( folder(), serNums ); + return; + } + QString searchString = searchStringFromPattern( pattern ); + if ( searchString.isEmpty() ) + { + // download the message and search local + int idx = -1; + KMFolder *aFolder = 0; + 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 = ""; + job->start(); + } else + { + // imap search + // remember the serNum + mSearchSerNums.clear(); + mSearchSerNums.append( serNum ); + int idx = -1; + KMFolder *aFolder = 0; + kmkernel->msgDict()->getLocation(serNum, &aFolder, &idx); + assert(aFolder && (idx != -1)); + KMMsgBase *mb = getMsgBase( idx ); + + // only search for that UID + searchString += " UID " + QString::number( mb->UID() ); + KURL url = mAccount->getUrl(); + url.setPath( imapPath() + ";SECTION=" + searchString ); + QByteArray packedArgs; + QDataStream stream( packedArgs, IO_WriteOnly ); + stream << (int) 'E' << url; + 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&)) ); + connect( job, SIGNAL(result(KIO::Job *)), + SLOT(slotSearchResult(KIO::Job *)) ); + } +} + //----------------------------------------------------------------------------- void KMFolderImap::slotSearch() { @@ -2007,6 +2071,12 @@ 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; @@ -2024,7 +2094,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 - mImapSearchData = data; mSearchSerNums.clear(); mRemainingMsgs = 0; QString question = i18n("To execute your search all messages of the folder %1 " @@ -2038,6 +2107,7 @@ void KMFolderImap::slotSearchData( KIO::Job* job, const QString& data ) emit searchDone( folder(), serNums ); return; } + mImapSearchData = data; for ( int i = 0; i < count(); ++i ) { KMMessage * msg = getMsg( i ); @@ -2082,7 +2152,10 @@ void KMFolderImap::slotSearchMessageArrived( KMMessage* msg ) if ( idx != -1 ) unGetMsg( idx ); if ( mRemainingMsgs == 0 ) + { emit searchDone( folder(), mSearchSerNums ); + mImapSearchData = ""; + } } //----------------------------------------------------------------------------- diff --git a/kmfolderimap.h b/kmfolderimap.h index 99b3cad32..c40eecb3b 100644 --- a/kmfolderimap.h +++ b/kmfolderimap.h @@ -294,6 +294,7 @@ public: * is signaled with searchDone() */ virtual void search( KMSearchPattern* ); + virtual void search( KMSearchPattern*, Q_UINT32 serNum ); signals: void folderComplete(KMFolderImap *folder, bool success); @@ -342,6 +343,11 @@ public slots: */ static void flagsToStatus(KMMsgBase *msg, int flags, bool newMsg = TRUE); + /** + * Connected to the result signal of the copy/move job + */ + void slotCopyMsgResult( FolderJob* job ); + protected: virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder, QString partSpecifier, diff --git a/kmfoldersearch.cpp b/kmfoldersearch.cpp index de571bd52..b829783ed 100644 --- a/kmfoldersearch.cpp +++ b/kmfoldersearch.cpp @@ -243,11 +243,11 @@ void KMSearch::slotProcessNextBatch() void KMSearch::slotSearchFolderDone( KMFolder* folder, QValueList serNums ) { + kdDebug(5006) << k_funcinfo << folder->label() << " found " << serNums.count() << endl; disconnect( folder->storage(), SIGNAL( searchDone( KMFolder*, QValueList ) ), this, SLOT( slotSearchFolderDone( KMFolder*, QValueList ) ) ); - kdDebug(5006) << k_funcinfo << folder->label() << " found " << serNums.count() << endl; --mRemainingFolders; mLastFolder = folder->label(); mSearchedCount += folder->count(); @@ -261,6 +261,7 @@ void KMSearch::slotSearchFolderDone( KMFolder* folder, QValueList serN } if ( mRemainingFolders <= 0 ) { + mRemainingFolders = 0; mRunning = false; mLastFolder = QString::null; mRemainingFolders = -1; @@ -915,26 +916,33 @@ void KMFolderSearch::examineAddedMessage(KMFolder *aFolder, Q_UINT32 serNum) if (!folder->isOpened()) return; - if (folder->folderType() == KMFolderTypeImap) { - // Unless there is a search currently running, add the message to - // the list of ones to check on folderCompleted and hook up the signal. - KMFolderImap *imapFolder = - dynamic_cast ( folder->storage() ); - if (!mSearch->running()) { - mUnexaminedMessages.push(serNum); - disconnect(imapFolder, SIGNAL(folderComplete(KMFolderImap*, bool)), - this, SLOT (examineCompletedFolder(KMFolderImap*, bool))); - connect(imapFolder, SIGNAL(folderComplete(KMFolderImap*, bool)), - this, SLOT (examineCompletedFolder(KMFolderImap*, bool))); - } + connect( folder->storage(), + SIGNAL( searchDone( KMFolder*, QValueList ) ), + this, + SLOT( slotSearchExamineMsgDone( KMFolder*, QValueList ) ) ); + folder->storage()->search( search()->searchPattern(), serNum ); +} + +void KMFolderSearch::slotSearchExamineMsgDone( KMFolder* folder, QValueList serNums ) +{ + kdDebug(5006) << k_funcinfo << folder->label() << " found " << serNums.count() << endl; + disconnect( folder->storage(), + SIGNAL( searchDone( KMFolder*, QValueList ) ), + this, + SLOT( slotSearchExamineMsgDone( KMFolder*, QValueList ) ) ); + + if ( serNums.empty() ) + return; + + if (mSearch->running()) { + mSearch->stop(); + mExecuteSearchTimer->start( 0, true ); } else { - if (search()->searchPattern()->matches(serNum)) - if (mSearch->running()) { - mSearch->stop(); - mExecuteSearchTimer->start(0, true); - } else { - addSerNum(serNum); - } + QValueListIterator it; + for ( it = serNums.begin(); it != serNums.end(); ++it ) + { + addSerNum( *it ); + } } } diff --git a/kmfoldersearch.h b/kmfoldersearch.h index 62f1bf9ca..16d0596f1 100644 --- a/kmfoldersearch.h +++ b/kmfoldersearch.h @@ -141,6 +141,9 @@ public slots: /** Incrementally update the index if possible else call writeIndex */ virtual int updateIndex(); + // Examine the added message + void slotSearchExamineMsgDone( KMFolder*, QValueList ); + public: //See base class for documentation virtual QCString& getMsgString(int idx, QCString& mDest);