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/>.
22 #include "progressmanager.h"
24 #include <Akonadi/Collection>
25 #include <Akonadi/Item>
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
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 );
61 void setRootFolder( const Akonadi::Collection
&rootFolder
);
62 void setSaveLocation( const KUrl
& savePath
);
63 void setArchiveType( ArchiveType type
);
64 void setDeleteFoldersAfterCompletion( bool deleteThem
);
69 void itemFetchJobResult( KJob
*job
);
71 void archiveNextFolder();
72 void onArchiveNextFolderDone( KJob
*job
);
73 void archiveNextMessage();
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;
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
;
96 QWidget
*mParentWidget
;
97 int mArchivedMessages
;
99 QPointer
<KPIM::ProgressItem
> mProgressItem
;
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
;