From a17a4d395eef06ce14653cff9b2caef577ea8dde Mon Sep 17 00:00:00 2001 From: Ingo Klcker Date: Sun, 30 May 2004 11:39:11 +0000 Subject: [PATCH] more detailed completed status for KMCommands svn path=/trunk/kdepim/; revision=316069 --- actionscheduler.cpp | 10 +++++----- actionscheduler.h | 7 +++++-- kmcommands.cpp | 21 ++++++++++++--------- kmcommands.h | 6 ++++-- kmheaders.cpp | 21 ++++++++++++--------- kmheaders.h | 5 ++++- 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/actionscheduler.cpp b/actionscheduler.cpp index 39ad3fe34..7d5157af7 100644 --- a/actionscheduler.cpp +++ b/actionscheduler.cpp @@ -1,5 +1,5 @@ /* Action Scheduler - + This file is part of KMail, the KDE mail client. Copyright (c) Don Sanders @@ -566,14 +566,14 @@ void ActionScheduler::moveMessage() KMFilterAction::sendMDN( msg, KMime::MDN::Deleted ); KMCommand *cmd = new KMMoveCommand( folder, msg ); - connect ( cmd, SIGNAL( completed(bool) ), - this, SLOT( moveMessageFinished(bool) ) ); + connect( cmd, SIGNAL( completed( KMCommand::Result ) ), + this, SLOT( moveMessageFinished( KMCommand::Result ) ) ); cmd->start(); } -void ActionScheduler::moveMessageFinished(bool success) +void ActionScheduler::moveMessageFinished( KMCommand::Result result ) { - if ( !success ) + if ( result != KMCommand::OK ) mResult = ResultError; if (!mSrcFolder->count()) diff --git a/actionscheduler.h b/actionscheduler.h index d3321b4ed..faf598a80 100644 --- a/actionscheduler.h +++ b/actionscheduler.h @@ -1,4 +1,5 @@ -/* Action Scheduler +/* -*- mode: C++ -*- + Action Scheduler This file is part of KMail, the KDE mail client. Copyright (c) Don Sanders @@ -37,6 +38,8 @@ #include "kmfilteraction.h" // for KMFilterAction::ReturnCode #include "kmfilter.h" #include "kmfiltermgr.h" // KMFilterMgr::FilterSet +#include "kmcommands.h" + class KMHeaders; /* A class for asynchronous filtering of messages */ @@ -107,7 +110,7 @@ private slots: void messageRetrieved(KMMessage*); void filterMessage(); void moveMessage(); - void moveMessageFinished(bool); + void moveMessageFinished( KMCommand::Result result ); private: static KMFolderMgr *tempFolderMgr; diff --git a/kmcommands.cpp b/kmcommands.cpp index d64d7e213..abe39bbc9 100644 --- a/kmcommands.cpp +++ b/kmcommands.cpp @@ -1589,8 +1589,10 @@ void KMMoveCommand::execute() typedef QMap< KMFolder*, QPtrList* > FolderToMessageListMap; FolderToMessageListMap folderDeleteList; - if (mDestFolder && mDestFolder->open() != 0) + if (mDestFolder && mDestFolder->open() != 0) { + completeMove( Failed ); return; + } KCursorSaver busy(KBusyPtr::busy()); // TODO set SSL state according to source and destfolder connection? @@ -1665,7 +1667,7 @@ void KMMoveCommand::execute() } else if (rc != 0) { // Something went wrong. Stop processing here, it is likely that the // other moves would fail as well. - completeMove( false); + completeMove( Failed ); return; } } @@ -1697,11 +1699,11 @@ void KMMoveCommand::execute() if ( mMsgList.first() ) { srcFolder = mMsgList.first()->parent(); if ( mDestFolder && mDestFolder == srcFolder ) { - completeMove( true ); + completeMove( OK ); } } if ( !mDestFolder ) { - emit completeMove( true ); + completeMove( OK ); } } } @@ -1719,10 +1721,11 @@ void KMMoveCommand::slotImapFolderCompleted(KMFolderImap *, bool success) kdDebug(5006) << "### Not all moved messages reported back that they were " << endl << "### added to the target folder. Did uidValidity change? " << endl; } + completeMove( OK ); } else { // Should we inform the user here or leave that to the caller? + completeMove( Failed ); } - completeMove( success ); } void KMMoveCommand::slotMsgAddedToDestFolder(KMFolder *folder, Q_UINT32 serNum) @@ -1738,24 +1741,24 @@ void KMMoveCommand::slotMsgAddedToDestFolder(KMFolder *folder, Q_UINT32 serNum) if (mDestFolder && mDestFolder->folderType() != KMFolderTypeImap) { mDestFolder->sync(); } - completeMove( true ); + completeMove( OK ); } else { mProgressItem->incCompletedItems(); mProgressItem->updateProgress(); } } -void KMMoveCommand::completeMove( bool success ) +void KMMoveCommand::completeMove( Result result ) { if ( mProgressItem ) mProgressItem->setComplete(); - emit completed( success ); + emit completed( result ); deleteLater(); } void KMMoveCommand::slotMoveCanceled() { - completeMove( false ); + completeMove( Canceled ); } // srcFolder doesn't make much sense for searchFolders diff --git a/kmcommands.h b/kmcommands.h index 450dc6490..030c601d7 100644 --- a/kmcommands.h +++ b/kmcommands.h @@ -34,6 +34,8 @@ class KMCommand : public QObject Q_OBJECT public: + enum Result { OK, Canceled, Failed }; + // Trival constructor, don't retrieve any messages KMCommand( QWidget *parent = 0 ); // Retrieve all messages in msgList when start is called. @@ -83,7 +85,7 @@ signals: void messagesTransfered(bool); /** Emitted when the command has completed. * @success Success or error. */ - void completed( bool success ); + void completed( KMCommand::Result result ); private: // ProgressDialog for transferring messages @@ -596,7 +598,7 @@ public slots: private: virtual void execute(); - void completeMove( bool success ); + void completeMove( Result result ); KMFolder *mDestFolder; QPtrList mMsgList; diff --git a/kmheaders.cpp b/kmheaders.cpp index 2e884f12c..b3ac38ce0 100644 --- a/kmheaders.cpp +++ b/kmheaders.cpp @@ -1640,8 +1640,8 @@ void KMHeaders::deleteMsg () finalizeMove( nextItem, contentX, contentY ); KMCommand *command = new KMDeleteMsgCommand( mFolder, msgList ); - connect (command, SIGNAL(completed( bool)), - this, SLOT(slotMoveCompleted( bool))); + connect( command, SIGNAL( completed( KMCommand::Result ) ), + this, SLOT( slotMoveCompleted( KMCommand::Result ) ) ); command->start(); KMBroadcastStatus::instance()->setStatusMsg(""); @@ -1724,19 +1724,19 @@ void KMHeaders::moveMsgToFolder ( KMFolder* destFolder, bool askForConfirmation finalizeMove( nextItem, contentX, contentY ); KMCommand *command = new KMMoveCommand( destFolder, msgList ); - connect (command, SIGNAL(completed( bool)), - this, SLOT(slotMoveCompleted( bool))); + connect( command, SIGNAL( completed( KMCommand::Result ) ), + this, SLOT( slotMoveCompleted( KMCommand::Result ) ) ); command->start(); } -void KMHeaders::slotMoveCompleted( bool success ) +void KMHeaders::slotMoveCompleted( KMCommand::Result result ) { - kdDebug(5006) << "KMHeaders::slotMoveCompleted: " << success << endl; - if (success) { + kdDebug(5006) << "KMHeaders::slotMoveCompleted: " << result << endl; + if ( result == KMCommand::OK ) { KMBroadcastStatus::instance()->setStatusMsg(i18n("Messages moved successfully.")); } else { - /* The move failed or the user canceled it reset the state of all + /* The move failed or the user canceled it; reset the state of all * messages involved and repaint. * * Note: This potentially resets too many items if there is more than one @@ -1755,7 +1755,10 @@ void KMHeaders::slotMoveCompleted( bool success ) } } triggerUpdate(); - KMBroadcastStatus::instance()->setStatusMsg(i18n("Moving messages failed.")); + if ( result == KMCommand::Failed ) + KMBroadcastStatus::instance()->setStatusMsg(i18n("Moving messages failed.")); + else + KMBroadcastStatus::instance()->setStatusMsg(i18n("Moving messages canceled.")); } } diff --git a/kmheaders.h b/kmheaders.h index 475476dec..1efd6bd7d 100644 --- a/kmheaders.h +++ b/kmheaders.h @@ -1,3 +1,5 @@ +// -*- mode: C++ -*- + #ifndef __KMHEADERS #define __KMHEADERS @@ -12,6 +14,7 @@ #include "kmmessage.h" #include "kmime_util.h" #include +#include "kmcommands.h" class KMFolder; class KMMessage; @@ -291,7 +294,7 @@ protected slots: void rightButtonPressed( QListViewItem *, const QPoint &, int ); private slots: - void slotMoveCompleted( bool success ); + void slotMoveCompleted( KMCommand::Result result ); private: /** Is equivalent to clearing the list and inserting an item for