kmail

backupjob.h

00001 /* Copyright 2009 Klarälvdalens Datakonsult AB
00002 
00003    This program is free software; you can redistribute it and/or
00004    modify it under the terms of the GNU General Public License as
00005    published by the Free Software Foundation; either version 2 of
00006    the License or (at your option) version 3 or any later version
00007    accepted by the membership of KDE e.V. (or its successor approved
00008    by the membership of KDE e.V.), which shall act as a proxy
00009    defined in Section 14 of version 3 of the license.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 #ifndef BACKUPJOB_H
00020 #define BACKUPJOB_H
00021 
00022 #include <kurl.h>
00023 #include <qptrlist.h>
00024 
00025 #include <qobject.h>
00026 
00027 class KMFolder;
00028 class KMMessage;
00029 class KArchive;
00030 class KProcess;
00031 class QWidget;
00032 
00033 namespace KPIM {
00034   class ProgressItem;
00035 }
00036 
00037 namespace KMail
00038 {
00039   class FolderJob;
00040 
00048 class BackupJob : public QObject
00049 {
00050   Q_OBJECT
00051 
00052   public:
00053 
00054     // These enum values have to stay in sync with the format combobox of ArchiveFolderDialog!
00055     enum ArchiveType { Zip = 0, Tar = 1, TarBz2 = 2, TarGz = 3 };
00056 
00057     explicit BackupJob( QWidget *parent = 0 );
00058     ~BackupJob();
00059     void setRootFolder( KMFolder *rootFolder );
00060     void setSaveLocation( const KURL &savePath );
00061     void setArchiveType( ArchiveType type );
00062     void setDeleteFoldersAfterCompletion( bool deleteThem );
00063     void start();
00064 
00065   private slots:
00066 
00067     void messageRetrieved( KMMessage *message );
00068     void folderJobFinished( KMail::FolderJob *job );
00069     void processCurrentMessage();
00070     void cancelJob();
00071 
00072   private:
00073 
00074     void queueFolders( KMFolder *root );
00075     void archiveNextFolder();
00076     void archiveNextMessage();
00077     QString stripRootPath( const QString &path ) const;
00078     bool hasChildren( KMFolder *folder ) const;
00079     void finish();
00080     void abort( const QString &errorMessage );
00081     bool writeDirHelper( const QString &directoryPath, const QString &permissionPath );
00082 
00083     KURL mMailArchivePath;
00084     ArchiveType mArchiveType;
00085     KMFolder *mRootFolder;
00086     KArchive *mArchive;
00087     QWidget *mParentWidget;
00088     bool mCurrentFolderOpen;
00089     int mArchivedMessages;
00090     uint mArchivedSize;
00091     KPIM::ProgressItem *mProgressItem;
00092     bool mAborted;
00093     bool mDeleteFoldersAfterCompletion;
00094 
00095     // True if we obtained ownership of the kMMessage after calling getMsg(), since we need
00096     // to call ungetMsg() then. For that, we also remember the original index.
00097     bool mUnget;
00098     int mMessageIndex;
00099 
00100     QPtrList<KMFolder> mPendingFolders;
00101     KMFolder *mCurrentFolder;
00102     QValueList<unsigned long> mPendingMessages;
00103     KMMessage *mCurrentMessage;
00104     FolderJob *mCurrentJob;
00105 };
00106 
00107 }
00108 
00109 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys