diff --git a/cachedimapjob.cpp b/cachedimapjob.cpp index 1c85dea90..42715c937 100644 --- a/cachedimapjob.cpp +++ b/cachedimapjob.cpp @@ -290,9 +290,11 @@ void CachedImapJob::slotGetNextMessage(KIO::Job * job) mSentBytes += size; emit progress( mSentBytes, mTotalBytes ); mAccount->removeJob(it); - } + } else + mFolder->quiet( true ); if( mMsgsForDownload.isEmpty() ) { + mFolder->quiet( false ); delete this; return; } diff --git a/folderstorage.cpp b/folderstorage.cpp index 1c88ca3a4..3519c758d 100644 --- a/folderstorage.cpp +++ b/folderstorage.cpp @@ -61,7 +61,7 @@ using KMail::ListJob; //----------------------------------------------------------------------------- FolderStorage::FolderStorage( KMFolder* folder, const char* aName ) - : QObject( folder, aName ), mFolder( folder ) + : QObject( folder, aName ), mFolder( folder ), mEmitChangedTimer( 0L ) { mOpenCount = 0; mQuiet = 0; @@ -82,6 +82,7 @@ FolderStorage::FolderStorage( KMFolder* folder, const char* aName ) mDirtyTimer = new QTimer(this); connect(mDirtyTimer, SIGNAL(timeout()), this, SLOT(updateIndex())); + mHasChildren = HasNoChildren; mContentsType = KMail::ContentsTypeMail; } @@ -192,15 +193,32 @@ void FolderStorage::markUnreadAsRead() //----------------------------------------------------------------------------- void FolderStorage::quiet(bool beQuiet) { + if (beQuiet) + { + /* Allocate the timer here to don't have one timer for each folder. BTW, + * a timer is created when a folder is checked + */ + if ( !mEmitChangedTimer) { + mEmitChangedTimer= new QTimer( this ); + connect( mEmitChangedTimer, SIGNAL( timeout() ), + this, SLOT( slotEmitChangedTimer() ) ); + } mQuiet++; - else { + } else { mQuiet--; if (mQuiet <= 0) { + delete mEmitChangedTimer; + mEmitChangedTimer=0L; + mQuiet = 0; - if (mChanged) + if (mChanged) { emit changed(); + // Don't hurt emit this if the mUnreadMsg really don't change + // We emit it here, because this signal is delayed if mQuiet >0 + emit numUnreadMsgsChanged( folder() ); + } mChanged = FALSE; } } @@ -245,6 +263,12 @@ int FolderStorage::expungeOldMsg(int days) return msgnb; } +//------------------------------------------ +void FolderStorage::slotEmitChangedTimer() +{ + emit changed(); + mChanged=false; +} //----------------------------------------------------------------------------- void FolderStorage::emitMsgAddedSignals(int idx) { @@ -252,6 +276,11 @@ void FolderStorage::emitMsgAddedSignals(int idx) if (!mQuiet) { emit msgAdded(idx); } else { + /** Restart always the timer or not. BTW we get a kmheaders refresh + * each 3 seg.?*/ + if ( !mEmitChangedTimer->isActive() ) { + mEmitChangedTimer->start( 3000 ); + } mChanged=true; } emit msgAdded( folder(), serNum ); @@ -359,7 +388,16 @@ void FolderStorage::removeMsg(int idx, bool) if (mb->isUnread() || mb->isNew() || (folder() == kmkernel->outboxFolder())) { --mUnreadMsgs; - emit numUnreadMsgsChanged( folder() ); + if ( !mQuiet ) { +// kdDebug( 5006 ) << "FolderStorage::msgStatusChanged" << endl; + emit numUnreadMsgsChanged( folder() ); + }else{ + if ( !mEmitChangedTimer->isActive() ) { +// kdDebug( 5006 )<< "EmitChangedTimer started" << endl; + mEmitChangedTimer->start( 3000 ); + } + mChanged = true; + } } --mTotalMsgs; @@ -388,7 +426,14 @@ KMMessage* FolderStorage::take(int idx) if (msg->isUnread() || msg->isNew() || ( folder() == kmkernel->outboxFolder() )) { --mUnreadMsgs; - emit numUnreadMsgsChanged( folder() ); + if ( !mQuiet ) { + emit numUnreadMsgsChanged( folder() ); + }else{ + if ( !mEmitChangedTimer->isActive() ) { + mEmitChangedTimer->start( 3000 ); + } + mChanged = true; + } } --mTotalMsgs; msg->setParent(0); @@ -800,10 +845,14 @@ void FolderStorage::msgStatusChanged(const KMMsgStatus oldStatus, if (deltaUnread != 0) { if (mUnreadMsgs < 0) mUnreadMsgs = 0; mUnreadMsgs += deltaUnread; - if ( !mQuiet ) + if ( !mQuiet ) { emit numUnreadMsgsChanged( folder() ); - else + }else{ + if ( !mEmitChangedTimer->isActive() ) { + mEmitChangedTimer->start( 3000 ); + } mChanged = true; + } Q_UINT32 serNum = kmkernel->msgDict()->getMsgSerNum(folder(), idx); emit msgChanged( folder(), serNum, deltaUnread ); } @@ -814,9 +863,18 @@ void FolderStorage::headerOfMsgChanged(const KMMsgBase* aMsg, int idx) { if (idx < 0) idx = aMsg->parent()->find( aMsg ); - if (idx >= 0 && !mQuiet) - emit msgHeaderChanged(folder(), idx); - else + + if (idx >= 0 ) + { + if ( !mQuiet ) + emit msgHeaderChanged(folder(), idx); + else{ + if ( !mEmitChangedTimer->isActive() ) { + mEmitChangedTimer->start( 3000 ); + } + mChanged = true; + } + } else mChanged = true; } diff --git a/folderstorage.h b/folderstorage.h index 39c226e33..994045608 100644 --- a/folderstorage.h +++ b/folderstorage.h @@ -507,6 +507,8 @@ public slots: /** Add a copy of the message to the folder after it has been retrieved from an IMAP server */ virtual void reallyAddCopyOfMsg(KMMessage* aMsg); + /** Emit changed signal if mQuite <=0 */ + void slotEmitChangedTimer(); protected slots: virtual void removeJob( QObject* ); @@ -592,6 +594,8 @@ protected: KMFolder* mFolder; + QTimer * mEmitChangedTimer; + int mCurrentSearchedMsg; KMSearchPattern* mSearchPattern; }; diff --git a/kmfoldercachedimap.cpp b/kmfoldercachedimap.cpp index 21dead09c..48dd8b13d 100644 --- a/kmfoldercachedimap.cpp +++ b/kmfoldercachedimap.cpp @@ -313,7 +313,7 @@ void KMFolderCachedImap::reloadUidMap() KMMsgBase *msg = getMsgBase( i ); if( !msg ) continue; ulong uid = msg->UID(); - kdDebug(5006) << "Inserting: " << i << " with uid: " << uid << endl; + //kdDebug(5006) << "Inserting: " << i << " with uid: " << uid << endl; uidMap.insert( uid, i ); } close(); diff --git a/kmfoldermaildir.cpp b/kmfoldermaildir.cpp index d708cf8b3..d7f00be22 100644 --- a/kmfoldermaildir.cpp +++ b/kmfoldermaildir.cpp @@ -465,7 +465,16 @@ if( fileD0.open( IO_WriteOnly ) ) { mUnreadMsgs = 1; else ++mUnreadMsgs; - emit numUnreadMsgsChanged( folder() ); + if ( !mQuiet ) { + kdDebug( 5006 ) << "FolderStorage::msgStatusChanged" << endl; + emit numUnreadMsgsChanged( folder() ); + }else{ + if ( !mEmitChangedTimer->isActive() ) { +// kdDebug( 5006 )<< "QuietTimer started" << endl; + mEmitChangedTimer->start( 3000 ); + } + mChanged = true; + } } ++mTotalMsgs; diff --git a/kmfoldertree.cpp b/kmfoldertree.cpp index 15db53832..f7cf8c3e1 100644 --- a/kmfoldertree.cpp +++ b/kmfoldertree.cpp @@ -291,6 +291,8 @@ KMFolderTree::KMFolderTree( KMMainWidget *mainWidget, QWidget *parent, mMainWidget = mainWidget; mReloading = false; + mUpdateCountTimer= new QTimer( this ); + addAcceptableDropMimetype(MailListDrag::format(), false); int namecol = addColumn( i18n("Folder"), 250 ); @@ -313,6 +315,9 @@ KMFolderTree::KMFolderTree( KMMainWidget *mainWidget, QWidget *parent, // connects all needed signals to their slots void KMFolderTree::connectSignals() { + connect( mUpdateCountTimer, SIGNAL(timeout()), + this, SLOT(slotUpdateCountTimeout()) ); + connect(&mUpdateTimer, SIGNAL(timeout()), this, SLOT(delayedUpdate())); @@ -535,6 +540,9 @@ void KMFolderTree::reload(bool openFolders) connect(fti->folder(),SIGNAL(nameChanged()), fti,SLOT(slotNameChanged())); + // With the use of slotUpdateCountsDelayed is not necesary + // a specific processing for Imap +#if 0 if (fti->folder()->folderType() == KMFolderTypeImap) { // imap-only KMFolderImap *imapFolder = @@ -543,23 +551,24 @@ void KMFolderTree::reload(bool openFolders) this,SLOT(slotUpdateCounts(KMFolderImap*, bool))); connect( imapFolder, SIGNAL(folderComplete(KMFolderImap*, bool)), this,SLOT(slotUpdateCounts(KMFolderImap*, bool))); - } else { - // others-only, imap doesn't need this because of the folderComplete-signal - // we want to be noticed of changes to update the unread/total columns - disconnect(fti->folder(), SIGNAL(msgAdded(KMFolder*,Q_UINT32)), - this,SLOT(slotUpdateCounts(KMFolder*))); - connect(fti->folder(), SIGNAL(msgAdded(KMFolder*,Q_UINT32)), - this,SLOT(slotUpdateCounts(KMFolder*))); - } + } else {*/ +#endif + + // we want to be noticed of changes to update the unread/total columns + disconnect(fti->folder(), SIGNAL(msgAdded(KMFolder*,Q_UINT32)), + this,SLOT(slotUpdateCountsDelayed(KMFolder*))); + connect(fti->folder(), SIGNAL(msgAdded(KMFolder*,Q_UINT32)), + this,SLOT(slotUpdateCountsDelayed(KMFolder*))); + //} disconnect(fti->folder(), SIGNAL(numUnreadMsgsChanged(KMFolder*)), - this,SLOT(slotUpdateCounts(KMFolder*))); + this,SLOT(slotUpdateCountsDelayed(KMFolder*))); connect(fti->folder(), SIGNAL(numUnreadMsgsChanged(KMFolder*)), - this,SLOT(slotUpdateCounts(KMFolder*))); + this,SLOT(slotUpdateCountsDelayed(KMFolder*))); disconnect(fti->folder(), SIGNAL(msgRemoved(KMFolder*)), - this,SLOT(slotUpdateCounts(KMFolder*))); + this,SLOT(slotUpdateCountsDelayed(KMFolder*))); connect(fti->folder(), SIGNAL(msgRemoved(KMFolder*)), - this,SLOT(slotUpdateCounts(KMFolder*))); + this,SLOT(slotUpdateCountsDelayed(KMFolder*))); disconnect(fti->folder(), SIGNAL(shortcutChanged(KMFolder*)), mMainWidget, SLOT( slotShortcutChanged(KMFolder*))); @@ -1455,8 +1464,38 @@ void KMFolderTree::slotUpdateCounts(KMFolderImap * folder, bool success) } //----------------------------------------------------------------------------- +void KMFolderTree::slotUpdateCountsDelayed(KMFolder * folder) +{ +// kdDebug(5006) << "KMFolderTree::slotUpdateCountsDelayed()" << endl; + if ( !mFolderToUpdateCount.contains( folder->idString() ) ) + { +// kdDebug( 5006 )<< "adding " << folder->idString() << " to updateCountList " << endl; + mFolderToUpdateCount.insert( folder->idString(),folder ); + } + if ( !mUpdateCountTimer->isActive() ) + mUpdateCountTimer->start( 500 ); +} + + +void KMFolderTree::slotUpdateCountTimeout() +{ +// kdDebug(5006) << "KMFolderTree::slotUpdateCountTimeout()" << endl; + + QMap::iterator it; + for ( it= mFolderToUpdateCount.begin(); + it!=mFolderToUpdateCount.end(); + ++it ) + { + slotUpdateCounts( it.data() ); + } + mFolderToUpdateCount.clear(); + mUpdateCountTimer->stop(); + +} + void KMFolderTree::slotUpdateCounts(KMFolder * folder) { + // kdDebug(5006) << "KMFolderTree::slotUpdateCounts()" << endl; QListViewItem * current; if (folder) current = indexOfFolder(folder); diff --git a/kmfoldertree.h b/kmfoldertree.h index eddb71246..d0a9b6ed8 100644 --- a/kmfoldertree.h +++ b/kmfoldertree.h @@ -268,6 +268,9 @@ protected slots: /** Update the total and unread columns (if available) */ void slotUpdateCounts(KMFolder * folder); void slotUpdateCounts(KMFolderImap * folder, bool success = true); + /** Update the total and unread columns but delayed */ + void slotUpdateCountsDelayed(KMFolder * folder); + void slotUpdateCountTimeout(); void slotUpdateOneCount(); /** slots for the unread/total-popup */ @@ -340,6 +343,9 @@ private: bool mReloading; QMap mFolderToItem; + QTimer *mUpdateCountTimer; + QMap mFolderToUpdateCount; + /** Map menu id into a folder */ KMMenuToFolder mMenuToFolder; };