1 /**
2 * UGENE - Integrated Bioinformatics Tools.
3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4 * http://ugene.net
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 #ifndef _U2_SAVE_DOCUMENT_TASK_H_
23 #define _U2_SAVE_DOCUMENT_TASK_H_
24
25 #include <QPointer>
26
27 #include <U2Core/GUrl.h>
28 #include <U2Core/Task.h>
29 #include <U2Core/UnloadedObject.h>
30
31 namespace U2 {
32
33 class Document;
34 class StateLock;
35 class IOAdapterFactory;
36 class DocumentFormat;
37
38 enum SaveDocFlag {
39 SaveDoc_Overwrite = 1 << 0,
40 SaveDoc_Append = 1 << 1,
41 SaveDoc_Roll = 1 << 2,
42 SaveDoc_DestroyAfter = 1 << 3,
43 SaveDoc_DestroyButDontUnload = 1 << 4,
44 SaveDoc_OpenAfter = 1 << 5,
45 SaveDoc_UnloadAfter = 1 << 6,
46 SaveDoc_ReduceLoggingLevel = 1 << 7
47 };
Q_DECLARE_FLAGS(SaveDocFlags,SaveDocFlag)48 Q_DECLARE_FLAGS(SaveDocFlags, SaveDocFlag)
49
50 class U2CORE_EXPORT SaveDocumentTask : public Task {
51 Q_OBJECT
52 public:
53 SaveDocumentTask(Document *doc, IOAdapterFactory *iof = nullptr, const GUrl &url = GUrl(), SaveDocFlags flags = SaveDoc_Overwrite);
54 SaveDocumentTask(Document *doc, SaveDocFlags flags, const QSet<QString> &excludeFileNames = QSet<QString>());
55
56 void prepare() override;
57
58 void run() override;
59
60 ReportResult report() override;
61
62 const GUrl &getURL() const {
63 return url;
64 }
65
66 IOAdapterFactory *getIOAdapterFactory() const {
67 return iof;
68 }
69
70 const QPointer<Document> &getDocument() const {
71 return doc;
72 }
73
74 // used in file-name rolling mode
75 void setExcludeFileNames(const QSet<QString> &_excludeFileNames) {
76 excludeFileNames = _excludeFileNames;
77 }
78
79 void addFlag(SaveDocFlag f);
80
81 /** Returns current set of 'openDocumentWithProjectHints'. See 'openDocumentWithProjectHints' for details. */
82 QVariantMap getOpenDocumentWithProjectHints() const;
83
84 /** Sets new 'openDocumentWithProjectHints'. See 'openDocumentWithProjectHints' for details. */
85 void setOpenDocumentWithProjectHints(const QVariantMap &hints);
86
87 private:
88 StateLock *lock;
89 QPointer<Document> doc;
90 IOAdapterFactory *iof;
91 GUrl url;
92 SaveDocFlags flags;
93 QSet<QString> excludeFileNames;
94
95 /** Set of hints passed to openWithProjectTask when SaveDoc_OpenAfter is present.*/
96 QVariantMap openDocumentWithProjectHints;
97 };
98
99 enum SavedNewDocFlag {
100 SavedNewDoc_Open = true,
101 SavedNewDoc_DoNotOpen = false
102 };
103
104 class U2CORE_EXPORT SaveMultipleDocuments : public Task {
105 Q_OBJECT
106 public:
107 SaveMultipleDocuments(const QList<Document *> &docs, bool askBeforeSave, SavedNewDocFlag openFlag = SavedNewDoc_DoNotOpen);
108
109 static QList<Document *> findModifiedDocuments(const QList<Document *> &docs);
110
111 private:
112 GUrl chooseAnotherUrl(Document *doc);
113 };
114
115 class U2CORE_EXPORT SaveCopyAndAddToProjectTask : public Task {
116 Q_OBJECT
117 public:
118 SaveCopyAndAddToProjectTask(Document *doc, IOAdapterFactory *iof, const GUrl &url);
119 ReportResult report();
120
121 private:
122 SaveDocumentTask *saveTask;
123 QList<UnloadedObjectInfo> info;
124 GUrl url;
125 GUrl origURL;
126 DocumentFormat *df;
127 QVariantMap hints;
128 };
129
130 class U2CORE_EXPORT RelocateDocumentTask : public Task {
131 Q_OBJECT
132 public:
133 RelocateDocumentTask(const GUrl &fromURL, const GUrl &toURL);
134 ReportResult report();
135
136 public:
137 GUrl fromURL;
138 GUrl toURL;
139 };
140
141 } // namespace U2
142
143 Q_DECLARE_OPERATORS_FOR_FLAGS(U2::SaveDocFlags)
144
145 #endif
146