Mailcommon

backupjob.h
1 /*
2  SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
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 
22 class KArchive;
23 class KJob;
24 
25 class QWidget;
26 
27 namespace Akonadi
28 {
29 class ItemFetchJob;
30 }
31 
32 namespace 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  */
41 class MAILCOMMON_EXPORT BackupJob : public QObject
42 {
43  Q_OBJECT
44 
45 public:
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();
61 Q_SIGNALS:
62  void backupDone(const QString &);
63  void error(const QString &);
64 
65 private:
66  void itemFetchJobResult(KJob *job);
67  void cancelJob();
68  void archiveNextFolder();
69  void onArchiveNextFolderDone(KJob *job);
70  void archiveNextMessage();
71  bool queueFolders(const Akonadi::Collection &root);
72  void processMessage(const Akonadi::Item &item);
73  Q_REQUIRED_RESULT QString pathForCollection(const Akonadi::Collection &collection) const;
74  Q_REQUIRED_RESULT QString subdirPathForCollection(const Akonadi::Collection &collection) const;
75  Q_REQUIRED_RESULT bool hasChildren(const Akonadi::Collection &collection) const;
76  void finish();
77  void abort(const QString &errorMessage);
78  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  Q_REQUIRED_RESULT 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 }
Q_SCRIPTABLE Q_NOREPLY void start()
KCALUTILS_EXPORT QString errorMessage(const KCalendarCore::Exception &exception)
Writes an entire folder structure to an archive file.
Definition: backupjob.h:41
Q_SCRIPTABLE Q_NOREPLY void abort()
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Oct 1 2022 04:00:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.