From 86f702e78da44d6d52d59b98ff67251ed15a002d Mon Sep 17 00:00:00 2001 From: Michael Haeckel Date: Fri, 21 Dec 2001 15:48:14 +0000 Subject: [PATCH] Save the index files on exit without being killed by the session management if it takes too long. svn path=/trunk/kdenetwork/kmail/; revision=128258 --- kmfolder.h | 9 +++++---- kmheaders.cpp | 3 +++ kmkernel.cpp | 14 +++++++++++++- kmkernel.h | 5 ++++- main.cpp | 3 ++- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/kmfolder.h b/kmfolder.h index 3cf2fbd43..4e47e25ed 100644 --- a/kmfolder.h +++ b/kmfolder.h @@ -386,6 +386,10 @@ public: void expireOldMessages(); + /** Write index to index-file. Returns 0 on success and errno error on + failure. */ + virtual int writeIndex(); + /** Inserts messages into the message dictionary. Might be called during kernel initialization. */ void fillMsgDict(KMMsgDict *dict); @@ -457,10 +461,7 @@ protected: failure. */ virtual int createIndexFromContents() = 0; - /** Write index to index-file. Returns 0 on success and errno error on - failure. */ - virtual int writeIndex(); - bool updateIndexStreamPtr(bool just_close=FALSE); + bool updateIndexStreamPtr(bool just_close=FALSE); /** Tests whether the contents (file) is newer than the index. Returns TRUE if the contents has changed (and the index should be recreated), diff --git a/kmheaders.cpp b/kmheaders.cpp index 09fbeba9f..e9e914f1d 100644 --- a/kmheaders.cpp +++ b/kmheaders.cpp @@ -743,6 +743,9 @@ void KMHeaders::setFolder (KMFolder *aFolder, bool jumpToFirst) mOwner, SLOT(statusMsg(const QString&))); writeSortOrder(); mFolder->close(); + // System folders remain open but we also should write the index from + // time to time + if (mFolder->dirty()) mFolder->writeIndex(); } mSortInfo.removed = 0; diff --git a/kmkernel.cpp b/kmkernel.cpp index 2e6d12a35..1aeb46627 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -46,6 +46,7 @@ KMKernel::KMKernel (QObject *parent, const char *name) : //kdDebug(5006) << "KMKernel::KMKernel" << endl; mySelf = this; closed_by_user = true; + the_firstInstance = true; the_msgDict = 0; new KMpgpWrap(); // register our own (libkdenetwork) utf-7 codec as long as Qt @@ -815,7 +816,18 @@ KabAPI* KMKernel::KABaddrBook() void KMKernel::notClosedByUser() { - closed_by_user = false; + closed_by_user = false; + + QStringList strList; + QValueList > folders; + KMFolder *folder; + the_folderMgr->createFolderList(&strList, &folders); + for (int i = 0; folders.at(i) != folders.end(); i++) + { + folder = *folders.at(i); + if (!folder || folder->isDir()) continue; + if (folder->isOpened() && folder->dirty()) folder->writeIndex(); + } } void KMKernel::emergencyExit( const QString& reason ) diff --git a/kmkernel.h b/kmkernel.h index 1c5acde91..0bab8a322 100644 --- a/kmkernel.h +++ b/kmkernel.h @@ -91,7 +91,9 @@ public: void ungrabPtrKb(void); void kmailMsgHandler(QtMsgType aType, const char* aMsg); void dumpDeadLetters(); - bool doSessionManagement (); + bool doSessionManagement(); + bool firstInstance() { return the_firstInstance; } + void setFirstInstance(bool value) { the_firstInstance = value; } void action (bool mailto, bool check, const QString &to, const QString &cc, const QString &bcc, const QString &subj, const QString &body, const KURL &messageFile, const KURL::List &attach); @@ -170,6 +172,7 @@ private: /** true unles kmail is closed by session management */ bool closed_by_user; bool allowedToExpire; + bool the_firstInstance; static KMKernel *mySelf; }; diff --git a/main.cpp b/main.cpp index 41cf0e31a..aa888239f 100644 --- a/main.cpp +++ b/main.cpp @@ -183,8 +183,9 @@ int KMailApplication::newInstance() args->clear(); - if (!kapp->isRestored()) + if (!kernel->firstInstance() || !kapp->isRestored()) kernel->action (mailto, checkMail, to, cc, bcc, subj, body, messageFile, attachURLs); + kernel->setFirstInstance(FALSE); return 0; }