The last part of typo fixes (I really hope)
[kdepim.git] / kmail / backupjob.h
blobc20444f8e166ea97b3d2e906ec96129952efcacb
1 /* Copyright 2009 Klarälvdalens Datakonsult AB
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License as
5 published by the Free Software Foundation; either version 2 of
6 the License or (at your option) version 3 or any later version
7 accepted by the membership of KDE e.V. (or its successor approved
8 by the membership of KDE e.V.), which shall act as a proxy
9 defined in Section 14 of version 3 of the license.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef BACKUPJOB_H
20 #define BACKUPJOB_H
22 #include "progressmanager.h"
24 #include <Akonadi/Collection>
25 #include <Akonadi/Item>
26 #include <kurl.h>
27 #include <qlist.h>
29 #include <qobject.h>
30 #include <qpointer.h>
32 class KArchive;
33 class KJob;
34 class QWidget;
36 namespace Akonadi {
37 class ItemFetchJob;
40 namespace KMail
43 /**
44 * Writes an entire folder structure to an archive file.
45 * The archive is structured like a hierarchy of maildir folders. However, every type of folder
46 * works as the source, i.e. also online IMAP folders.
48 * The job deletes itself after it finished.
50 class BackupJob : public QObject
52 Q_OBJECT
54 public:
56 // These enum values have to stay in sync with the format combobox of ArchiveFolderDialog!
57 enum ArchiveType { Zip = 0, Tar = 1, TarBz2 = 2, TarGz = 3 };
59 explicit BackupJob( QWidget *parent = 0 );
60 ~BackupJob();
61 void setRootFolder( const Akonadi::Collection &rootFolder );
62 void setSaveLocation( const KUrl& savePath );
63 void setArchiveType( ArchiveType type );
64 void setDeleteFoldersAfterCompletion( bool deleteThem );
65 void start();
67 private slots:
69 void itemFetchJobResult( KJob *job );
70 void cancelJob();
71 void archiveNextFolder();
72 void onArchiveNextFolderDone( KJob *job );
73 void archiveNextMessage();
75 private:
77 bool queueFolders( const Akonadi::Collection &root );
78 void processMessage( const Akonadi::Item &item );
79 QString pathForCollection( const Akonadi::Collection &collection ) const;
80 QString subdirPathForCollection( const Akonadi::Collection &collection ) const;
81 bool hasChildren( const Akonadi::Collection &collection ) const;
82 void finish();
83 void abort( const QString &errorMessage );
84 bool writeDirHelper( const QString &directoryPath );
86 // Helper function to return the name of the given collection.
87 // Some Collection's don't have the name fetched. However, in mAllFolders,
88 // we have a list of Collection's that have that information in them, so
89 // we can just look it up there.
90 QString collectionName( const Akonadi::Collection &collection ) const;
92 KUrl mMailArchivePath;
93 ArchiveType mArchiveType;
94 Akonadi::Collection mRootFolder;
95 KArchive *mArchive;
96 QWidget *mParentWidget;
97 int mArchivedMessages;
98 uint mArchivedSize;
99 QPointer<KPIM::ProgressItem> mProgressItem;
100 bool mAborted;
101 bool mDeleteFoldersAfterCompletion;
103 Akonadi::Collection::List mPendingFolders;
104 Akonadi::Collection::List mAllFolders;
105 Akonadi::Collection mCurrentFolder;
106 Akonadi::Item::List mPendingMessages;
107 Akonadi::ItemFetchJob *mCurrentJob;
112 #endif