[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepim-runtime/KDE/4.12] resources/maildir: Use QDirIterator for listing the maildir folders. This:
From: Andras Mantia <amantia () kde ! org>
Date: 2013-11-23 14:58:41
Message-ID: E1VkEfR-0008ON-ND () scm ! kde ! org
[Download RAW message or body]
Git commit d161e37622f8acb550d54cacd48f4886354fc1e5 by Andras Mantia.
Committed on 18/11/2013 at 16:18.
Pushed by amantia into branch 'KDE/4.12'.
Use QDirIterator for listing the maildir folders. This:
- avoids some extra stats
- avoids calling into Maildir::findRealKey that caches the keys and uses a lot of \
memory for no real reason (in this case)
REVIEW: 113918
BUG: 321944
(cherry picked from commit 6100bbf86a5ddf5ae009fb6724d4d2ac53593c7f)
M +16 -0 resources/maildir/libmaildir/maildir.cpp
M +6 -0 resources/maildir/libmaildir/maildir.h
M +32 -23 resources/maildir/retrieveitemsjob.cpp
M +3 -3 resources/maildir/retrieveitemsjob.h
http://commits.kde.org/kdepim-runtime/d161e37622f8acb550d54cacd48f4886354fc1e5
diff --git a/resources/maildir/libmaildir/maildir.cpp \
b/resources/maildir/libmaildir/maildir.cpp index 4a932db..a2d4305 100644
--- a/resources/maildir/libmaildir/maildir.cpp
+++ b/resources/maildir/libmaildir/maildir.cpp
@@ -422,6 +422,22 @@ QStringList Maildir::listNew() const
return result;
}
+QString Maildir::pathToNew() const
+{
+ if ( isValid() ) {
+ return d->path + QString::fromLatin1( "/new" );
+ }
+ return QString();
+}
+
+QString Maildir::pathToCurrent() const
+{
+ if ( isValid() ) {
+ return d->path + QString::fromLatin1( "/cur" );
+ }
+ return QString();
+}
+
QString Maildir::subDirPath() const
{
QDir dir( d->path );
diff --git a/resources/maildir/libmaildir/maildir.h \
b/resources/maildir/libmaildir/maildir.h index 506e4c7..64192d2 100644
--- a/resources/maildir/libmaildir/maildir.h
+++ b/resources/maildir/libmaildir/maildir.h
@@ -110,6 +110,12 @@ public:
*/
QStringList listCurrent() const;
+ /** Return the path to the "new" directory */
+ QString pathToNew() const;
+
+ /** Return the path to the "cur" directory */
+ QString pathToCurrent() const;
+
/**
* Returns the full path to the subdir (the NAME.directory folder ).
**/
diff --git a/resources/maildir/retrieveitemsjob.cpp \
b/resources/maildir/retrieveitemsjob.cpp index d7b0ff2..7c0756e 100644
--- a/resources/maildir/retrieveitemsjob.cpp
+++ b/resources/maildir/retrieveitemsjob.cpp
@@ -26,6 +26,7 @@
#include <akonadi/transactionsequence.h>
#include <QDateTime>
+#include <QDirIterator>
#include <KMime/Message>
RetrieveItemsJob::RetrieveItemsJob ( const Akonadi::Collection& collection, const \
KPIM::Maildir& md, QObject* parent ) : @@ -34,9 +35,9 @@ \
RetrieveItemsJob::RetrieveItemsJob ( const Akonadi::Collection& collection, cons \
m_maildir( md ), m_mimeType( KMime::Message::mimeType() ),
m_transaction( 0 ),
+ m_entryIterator(0),
m_previousMtime( 0 ),
- m_highestMtime( 0 ),
- m_nextIndex( 0 )
+ m_highestMtime( 0 )
{
Q_ASSERT( m_collection.isValid() );
Q_ASSERT( m_maildir.isValid() );
@@ -66,63 +67,69 @@ void RetrieveItemsJob::localListDone ( KJob* job )
}
m_listingPath = m_maildir.path() + QLatin1String( "/new/" );
- m_entryList = m_maildir.listNew();
+ delete m_entryIterator;
+ m_entryIterator = new QDirIterator( m_maildir.pathToNew(), QDir::Files );
m_previousMtime = m_collection.remoteRevision().toLongLong();
m_highestMtime = 0;
- processEntry(0);
+ processEntry();
}
-void RetrieveItemsJob::processEntry(qint64 index)
+void RetrieveItemsJob::processEntry()
{
- QString entry;
+ QFileInfo entryInfo;
+
+ QString filePath = m_entryIterator->next();
+
+ QString fileName = m_entryIterator->fileName();
bool newItemFound = false;
while ( !newItemFound ) {
- if ( index >= m_entryList.size() ) {
+ if ( filePath.isEmpty() ) {
if ( m_listingPath.endsWith( QLatin1String( "/new/" ) ) ) {
m_listingPath = m_maildir.path() + QLatin1String( "/cur/" );
- m_entryList = m_maildir.listCurrent();
- processEntry( 0 );
+ delete m_entryIterator;
+ m_entryIterator = new QDirIterator( m_maildir.pathToCurrent(), QDir::Files \
); + processEntry();
} else {
entriesProcessed();
}
return;
}
- entry = m_entryList[index];
- const qint64 currentMtime = m_maildir.lastModified( entry ).toMSecsSinceEpoch();
+ entryInfo = m_entryIterator->fileInfo();
+ const qint64 currentMtime = entryInfo.lastModified().toMSecsSinceEpoch();
m_highestMtime = qMax( m_highestMtime, currentMtime );
- if ( currentMtime <= m_previousMtime && m_localItems.contains( entry ) ) { // \
old, we got this one already
- m_localItems.remove( entry );
- index++;
+ if ( currentMtime <= m_previousMtime && m_localItems.contains( fileName ) ) { // \
old, we got this one already + m_localItems.remove( fileName );
+ filePath = m_entryIterator->next();
+ fileName = m_entryIterator->fileName();
} else {
newItemFound = true;
}
}
Akonadi::Item item;
- item.setRemoteId( entry );
+ item.setRemoteId( fileName );
item.setMimeType( m_mimeType );
- const qint64 entrySize = m_maildir.size( entry );
+ const qint64 entrySize = entryInfo.size();
if ( entrySize >= 0 )
item.setSize( entrySize );
KMime::Message *msg = new KMime::Message;
- msg->setHead( KMime::CRLFtoLF( m_maildir.readEntryHeadersFromFile( m_listingPath + \
entry ) ) ); + msg->setHead( KMime::CRLFtoLF( m_maildir.readEntryHeadersFromFile( \
m_listingPath + fileName ) ) ); msg->parse();
- Akonadi::Item::Flags flags = m_maildir.readEntryFlags( entry );
+ Akonadi::Item::Flags flags = m_maildir.readEntryFlags( fileName );
Q_FOREACH ( const Akonadi::Item::Flag &flag, flags ) {
item.setFlag( flag );
}
item.setPayload( KMime::Message::Ptr( msg ) );
- m_nextIndex = index + 1;
KJob *job = 0;
- if ( m_localItems.contains( entry ) ) { // modification
- item.setId( m_localItems.value( entry ).id() );
+ if ( m_localItems.contains( fileName ) ) { // modification
+ item.setId( m_localItems.value( fileName ).id() );
job = new Akonadi::ItemModifyJob( item, transaction() );
- m_localItems.remove( entry );
+ m_localItems.remove( fileName );
} else { // new item
job = new Akonadi::ItemCreateJob( item, m_collection, transaction() );
}
@@ -131,11 +138,13 @@ void RetrieveItemsJob::processEntry(qint64 index)
void RetrieveItemsJob::processEntryDone( KJob* )
{
- processEntry( m_nextIndex );
+ processEntry();
}
void RetrieveItemsJob::entriesProcessed()
{
+ delete m_entryIterator;
+ m_entryIterator = 0;
if ( !m_localItems.isEmpty() ) {
Akonadi::ItemDeleteJob *job = new Akonadi::ItemDeleteJob( m_localItems.values(), \
transaction() ); m_maildir.removeCachedKeys( m_localItems.keys() );
diff --git a/resources/maildir/retrieveitemsjob.h \
b/resources/maildir/retrieveitemsjob.h index 60f3602..538d5ad 100644
--- a/resources/maildir/retrieveitemsjob.h
+++ b/resources/maildir/retrieveitemsjob.h
@@ -26,6 +26,7 @@
#include "maildir.h"
+class QDirIterator;
namespace Akonadi
{
class TransactionSequence;
@@ -52,7 +53,7 @@ class RetrieveItemsJob : public Akonadi::Job
private slots:
void localListDone( KJob *job );
void transactionDone( KJob *job );
- void processEntry( qint64 index );
+ void processEntry();
void processEntryDone( KJob * );
private:
@@ -61,10 +62,9 @@ class RetrieveItemsJob : public Akonadi::Job
QHash<QString, Akonadi::Item> m_localItems;
QString m_mimeType;
Akonadi::TransactionSequence *m_transaction;
- QStringList m_entryList;
+ QDirIterator *m_entryIterator;
qint64 m_previousMtime;
qint64 m_highestMtime;
- qint64 m_nextIndex;
QString m_listingPath;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic