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 { Zip = 0, Tar = 1, TarBz2 = 2, TarGz = 3 };
48
49 explicit BackupJob(QWidget *parent = nullptr);
50 ~BackupJob() override;
51
52 void setRootFolder(const Akonadi::Collection &rootFolder);
53 void setSaveLocation(const QUrl &savePath);
54 void setArchiveType(ArchiveType type);
55 void setDeleteFoldersAfterCompletion(bool deleteThem);
56 void setRecursive(bool recursive);
57 void setDisplayMessageBox(bool display);
58 void setRealPath(const QString &path);
59
60 void start();
61Q_SIGNALS:
62 void backupDone(const QString &);
63 void error(const QString &);
64
65private:
66 MAILCOMMON_NO_EXPORT void itemFetchJobResult(KJob *job);
67 MAILCOMMON_NO_EXPORT void cancelJob();
68 MAILCOMMON_NO_EXPORT void archiveNextFolder();
69 MAILCOMMON_NO_EXPORT void onArchiveNextFolderDone(KJob *job);
70 MAILCOMMON_NO_EXPORT void archiveNextMessage();
71 MAILCOMMON_NO_EXPORT bool queueFolders(const Akonadi::Collection &root);
72 MAILCOMMON_NO_EXPORT void processMessage(const Akonadi::Item &item);
73 [[nodiscard]] MAILCOMMON_NO_EXPORT QString pathForCollection(const Akonadi::Collection &collection) const;
74 [[nodiscard]] MAILCOMMON_NO_EXPORT QString subdirPathForCollection(const Akonadi::Collection &collection) const;
75 [[nodiscard]] MAILCOMMON_NO_EXPORT bool hasChildren(const Akonadi::Collection &collection) const;
76 MAILCOMMON_NO_EXPORT void finish();
77 MAILCOMMON_NO_EXPORT void abort(const QString &errorMessage);
78 MAILCOMMON_NO_EXPORT bool writeDirHelper(const QString &directoryPath);
79
80 // Helper function to return the name of the given collection.
81 // Some Collection's don't have the name fetched. However, in mAllFolders,
82 // we have a list of Collection's that have that information in them, so
83 // we can just look it up there.
84 [[nodiscard]] MAILCOMMON_NO_EXPORT QString collectionName(const Akonadi::Collection &collection) const;
85
86 QString mRealPath;
87 QUrl mMailArchivePath;
88 QDateTime mArchiveTime;
89 ArchiveType mArchiveType = Zip;
90 Akonadi::Collection mRootFolder;
91 KArchive *mArchive = nullptr;
92 QWidget *const mParentWidget;
93 int mArchivedMessages = 0;
94 uint mArchivedSize = 0;
95 QPointer<KPIM::ProgressItem> mProgressItem;
96 bool mAborted = false;
97 bool mDeleteFoldersAfterCompletion = false;
98 bool mRecursive = true;
99
100 Akonadi::Collection::List mPendingFolders;
101 Akonadi::Collection::List mAllFolders;
102 Akonadi::Collection mCurrentFolder;
103 Akonadi::Item::List mPendingMessages;
104 Akonadi::ItemFetchJob *mCurrentJob = nullptr;
105 bool mDisplayMessageBox = true;
106};
107}
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 Tue Mar 26 2024 11:14:01 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.