Connect the backupjob to the progress manager

svn path=/branches/kdepim/enterprise/kdepim/; revision=1048166
wilder-work
Thomas McGuire 17 years ago
parent 0da8730708
commit affdec3ec3
  1. 2
      archivefolderdialog.cpp
  2. 35
      backupjob.cpp
  3. 7
      backupjob.h

@ -117,6 +117,8 @@ void ArchiveFolderDialog::slotOk()
KGuiItem( i18n( "Cancel" ) ) ) != KMessageBox::Yes ) {
return;
}
// TODO: Check if overwriting actually works!
}
if ( !mFolderRequester->folder() ) {

@ -23,6 +23,8 @@
#include "kmfoldercachedimap.h"
#include "kmfolderdir.h"
#include "progressmanager.h"
#include "kzip.h"
#include "ktar.h"
#include "kmessagebox.h"
@ -42,6 +44,8 @@ BackupJob::BackupJob( QWidget *parent )
mCurrentFolderOpen( false ),
mArchivedMessages( 0 ),
mArchivedSize( 0 ),
mProgressItem( 0 ),
mAborted( false ),
mCurrentFolder( 0 ),
mCurrentMessage( 0 ),
mCurrentJob( 0 )
@ -107,9 +111,19 @@ bool BackupJob::hasChildren( KMFolder *folder ) const
return false;
}
void BackupJob::cancelJob()
{
abort( i18n( "The operation was cancelled by the user." ) );
}
void BackupJob::abort( const QString &errorMessage )
{
// We could be called this twice, since killing the current job below will cause the job to fail,
// and that will call abort()
if ( mAborted )
return;
mAborted = true;
if ( mCurrentFolderOpen && mCurrentFolder ) {
mCurrentFolder->close( "BackupJob" );
mCurrentFolder = 0;
@ -121,6 +135,11 @@ void BackupJob::abort( const QString &errorMessage )
mCurrentJob->kill();
mCurrentJob = 0;
}
if ( mProgressItem ) {
mProgressItem->setComplete();
mProgressItem = 0;
// The progressmanager will delete it
}
QString text = i18n( "Failed to archive the folder '%1'." ).arg( mRootFolder->name() );
text += "\n" + errorMessage;
@ -139,6 +158,10 @@ void BackupJob::finish()
}
}
mProgressItem->setStatus( i18n( "Archiving finished" ) );
mProgressItem->setComplete();
mProgressItem = 0;
QFileInfo archiveFileInfo( mMailArchivePath.path() );
QString text = i18n( "Archiving folder '%1' successfully completed. "
"The archive was written to the file '%2'." )
@ -206,6 +229,8 @@ void BackupJob::archiveNextMessage()
abort( i18n( "Internal error while trying to retrieve a message from folder '%1'." )
.arg( mCurrentFolder->name() ) );
}
mProgressItem->setProgress( ( mProgressItem->progress() + 5 ) );
}
static int fileInfoToUnixPermissions( const QFileInfo &fileInfo )
@ -327,6 +352,7 @@ void BackupJob::archiveNextFolder()
mCurrentFolder = mPendingFolders.take( 0 );
kdDebug(5006) << "===> Archiving next folder: " << mCurrentFolder->name() << endl;
mProgressItem->setStatus( i18n( "Archiving folder %1" ).arg( mCurrentFolder->name() ) );
if ( mCurrentFolder->open( "BackupJob" ) != 0 ) {
abort( i18n( "Unable to open folder '%1'.").arg( mCurrentFolder->name() ) );
return;
@ -418,6 +444,15 @@ void BackupJob::start()
return;
}
mProgressItem = KPIM::ProgressManager::createProgressItem(
"BackupJob",
i18n( "Archiving" ),
QString(),
true );
mProgressItem->setUsesBusyIndicator( true );
connect( mProgressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
this, SLOT(cancelJob()) );
archiveNextFolder();
}

@ -30,6 +30,10 @@ class KArchive;
class KProcess;
class QWidget;
namespace KPIM {
class ProgressItem;
}
namespace KMail
{
class FolderJob;
@ -62,6 +66,7 @@ class BackupJob : public QObject
void messageRetrieved( KMMessage *message );
void folderJobFinished( KMail::FolderJob *job );
void processCurrentMessage();
void cancelJob();
private:
@ -82,6 +87,8 @@ class BackupJob : public QObject
bool mCurrentFolderOpen;
int mArchivedMessages;
uint mArchivedSize;
KPIM::ProgressItem *mProgressItem;
bool mAborted;
QPtrList<KMFolder> mPendingFolders;
KMFolder *mCurrentFolder;

Loading…
Cancel
Save