Mailcommon

backupjob.h
1/*
2 SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3
4 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5*/
6
7#pragma once
8
9#include "mailcommon_export.h"
10
11#include <Libkdepim/ProgressManager>
12
13#include <Akonadi/Collection>
14#include <Akonadi/Item>
15
16#include <QUrl>
17
18#include <QDateTime>
19#include <QObject>
20#include <QPointer>
21
22class KArchive;
23class KJob;
24
25class QWidget;
26
27namespace Akonadi
28{
29class ItemFetchJob;
30}
31
32namespace MailCommon
33{
34/**
35 * Writes an entire folder structure to an archive file. The archive is
36 * structured like a hierarchy of maildir folders. However, every type of
37 * folder works as the source, i.e. also online IMAP folders.
38 *
39 * The job deletes itself after it finished.
40 */
41class MAILCOMMON_EXPORT BackupJob : public QObject
42{
43 Q_OBJECT
44
45public:
46 // These enum values have to stay in sync with the format combobox of ArchiveFolderDialog!
47 enum ArchiveType {
48 Zip = 0,
49 Tar = 1,
50 TarBz2 = 2,
51 TarGz = 3
52 };
53
54 explicit BackupJob(QWidget *parent = nullptr);
55 ~BackupJob() override;
56
57 void setRootFolder(const Akonadi::Collection &rootFolder);
58 void setSaveLocation(const QUrl &savePath);
59 void setArchiveType(ArchiveType type);
60 void setDeleteFoldersAfterCompletion(bool deleteThem);
61 void setRecursive(bool recursive);
62 void setDisplayMessageBox(bool display);
63 void setRealPath(const QString &path);
64
65 void start();
66Q_SIGNALS:
67 void backupDone(const QString &);
68 void error(const QString &);
69
70private:
71 MAILCOMMON_NO_EXPORT void itemFetchJobResult(KJob *job);
72 MAILCOMMON_NO_EXPORT void cancelJob();
73 MAILCOMMON_NO_EXPORT void archiveNextFolder();
74 MAILCOMMON_NO_EXPORT void onArchiveNextFolderDone(KJob *job);
75 MAILCOMMON_NO_EXPORT void archiveNextMessage();
76 [[nodiscard]] MAILCOMMON_NO_EXPORT bool queueFolders(const Akonadi::Collection &root);
77 MAILCOMMON_NO_EXPORT void processMessage(const Akonadi::Item &item);
78 [[nodiscard]] MAILCOMMON_NO_EXPORT QString pathForCollection(const Akonadi::Collection &collection) const;
79 [[nodiscard]] MAILCOMMON_NO_EXPORT QString subdirPathForCollection(const Akonadi::Collection &collection) const;
80 [[nodiscard]] MAILCOMMON_NO_EXPORT bool hasChildren(const Akonadi::Collection &collection) const;
81 MAILCOMMON_NO_EXPORT void finish();
82 MAILCOMMON_NO_EXPORT void abort(const QString &errorMessage);
83 [[nodiscard]] MAILCOMMON_NO_EXPORT bool writeDirHelper(const QString &directoryPath);
84
85 // Helper function to return the name of the given collection.
86 // Some Collection's don't have the name fetched. However, in mAllFolders,
87 // we have a list of Collection's that have that information in them, so
88 // we can just look it up there.
89 [[nodiscard]] MAILCOMMON_NO_EXPORT QString collectionName(const Akonadi::Collection &collection) const;
90
91 QString mRealPath;
92 QUrl mMailArchivePath;
93 QDateTime mArchiveTime;
94 ArchiveType mArchiveType = Zip;
95 Akonadi::Collection mRootFolder;
96 KArchive *mArchive = nullptr;
97 QWidget *const mParentWidget;
98 int mArchivedMessages = 0;
99 uint mArchivedSize = 0;
100 QPointer<KPIM::ProgressItem> mProgressItem;
101 bool mAborted = false;
102 bool mDeleteFoldersAfterCompletion = false;
103 bool mRecursive = true;
104
105 Akonadi::Collection::List mPendingFolders;
106 Akonadi::Collection::List mAllFolders;
107 Akonadi::Collection mCurrentFolder;
108 Akonadi::Item::List mPendingMessages;
109 Akonadi::ItemFetchJob *mCurrentJob = nullptr;
110 bool mDisplayMessageBox = true;
111};
112}
Writes an entire folder structure to an archive file.
Definition backupjob.h:42
Q_SCRIPTABLE Q_NOREPLY void abort()
Q_SCRIPTABLE Q_NOREPLY void start()
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.