Debian Codegraph @

src/Gui/DocumentRecovery.h

raw
1 /***************************************************************************
2 * Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library 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 Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef GUI_DIALOG_DOCUMENTRECOVERY_H
25 #define GUI_DIALOG_DOCUMENTRECOVERY_H
26
27 #include <QDialog>
28 #include <QFileInfo>
29 #include <QFileInfoList>
30 #include <QList>
31 #include <QScopedPointer>
32
33
34 namespace Gui
35 {
36 namespace Dialog
37 {
38
39 class DocumentRecoveryPrivate;
40
41 /*!
42 @author Werner Mayer
43 */
44 class DocumentRecovery: public QDialog
45 {
46 Q_OBJECT
47
48 public:
49 explicit DocumentRecovery(const QList<QFileInfo>&, QWidget* parent = nullptr);
50 ~DocumentRecovery() override;
51
52 void accept() override;
53 bool foundDocuments() const;
54
55 protected:
56 void closeEvent(QCloseEvent*) override;
57 void contextMenuEvent(QContextMenuEvent*) override;
58 QString createProjectFile(const QString&);
59 void cleanup(QDir&, const QList<QFileInfo>&, const QString&);
60
61 protected:
62 void onButtonCleanupClicked();
63 void onDeleteSection();
64
65 private:
66 static std::string doctools;
67 QScopedPointer<DocumentRecoveryPrivate> d_ptr;
68 Q_DISABLE_COPY(DocumentRecovery)
69 Q_DECLARE_PRIVATE(DocumentRecovery)
70 };
71
72 class DocumentRecoveryFinder
73 {
74 public:
75 bool checkForPreviousCrashes();
76
77 private:
78 void checkDocumentDirs(QDir&, const QList<QFileInfo>&, const QString&);
79 bool showRecoveryDialogIfNeeded();
80
81 private:
82 QList<QFileInfo> restoreDocFiles;
83 };
84
85 class DocumentRecoveryHandler
86 {
87 public:
88 void checkForPreviousCrashes(
89 const std::function<void(QDir&, const QList<QFileInfo>&, const QString&)>& callableFunc
90 ) const;
91 };
92
93 class DocumentRecoveryCleaner
94 {
95 public:
96 void clearDirectory(const QFileInfo& dir);
97 void setIgnoreFiles(const QStringList&);
98 void setIgnoreDirectories(const QFileInfoList&);
99
100 private:
101 void subtractFiles(QStringList&);
102 void subtractDirs(QFileInfoList&);
103
104 private:
105 QStringList ignoreFiles;
106 QFileInfoList ignoreDirs;
107 };
108
109 } // namespace Dialog
110
111 } // namespace Gui
112
113
114 #endif // GUI_DIALOG_DOCUMENTRECOVERY_H