diff options
Diffstat (limited to 'framework/src/domain/mime/mimetreeparser/attachmenttemporaryfilesdirs.cpp')
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/attachmenttemporaryfilesdirs.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/attachmenttemporaryfilesdirs.cpp b/framework/src/domain/mime/mimetreeparser/attachmenttemporaryfilesdirs.cpp new file mode 100644 index 00000000..364bc422 --- /dev/null +++ b/framework/src/domain/mime/mimetreeparser/attachmenttemporaryfilesdirs.cpp | |||
@@ -0,0 +1,108 @@ | |||
1 | /* | ||
2 | Copyright (c) 2013-2017 Montel Laurent <montel@kde.org> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | |||
19 | */ | ||
20 | |||
21 | #include "attachmenttemporaryfilesdirs.h" | ||
22 | |||
23 | #include <QDir> | ||
24 | #include <QFile> | ||
25 | #include <QTimer> | ||
26 | |||
27 | using namespace MimeTreeParser; | ||
28 | |||
29 | class MimeTreeParser::AttachmentTemporaryFilesDirsPrivate | ||
30 | { | ||
31 | public: | ||
32 | AttachmentTemporaryFilesDirsPrivate() | ||
33 | : mDelayRemoveAll(10000) | ||
34 | { | ||
35 | |||
36 | } | ||
37 | QStringList mTempFiles; | ||
38 | QStringList mTempDirs; | ||
39 | int mDelayRemoveAll; | ||
40 | }; | ||
41 | |||
42 | AttachmentTemporaryFilesDirs::AttachmentTemporaryFilesDirs(QObject *parent) | ||
43 | : QObject(parent), | ||
44 | d(new AttachmentTemporaryFilesDirsPrivate) | ||
45 | { | ||
46 | |||
47 | } | ||
48 | |||
49 | AttachmentTemporaryFilesDirs::~AttachmentTemporaryFilesDirs() | ||
50 | { | ||
51 | delete d; | ||
52 | } | ||
53 | |||
54 | void AttachmentTemporaryFilesDirs::setDelayRemoveAllInMs(int ms) | ||
55 | { | ||
56 | d->mDelayRemoveAll = (ms < 0) ? 0 : ms; | ||
57 | } | ||
58 | |||
59 | void AttachmentTemporaryFilesDirs::removeTempFiles() | ||
60 | { | ||
61 | QTimer::singleShot(d->mDelayRemoveAll, this, &AttachmentTemporaryFilesDirs::slotRemoveTempFiles); | ||
62 | } | ||
63 | |||
64 | void AttachmentTemporaryFilesDirs::forceCleanTempFiles() | ||
65 | { | ||
66 | QStringList::ConstIterator end = d->mTempFiles.constEnd(); | ||
67 | for (QStringList::ConstIterator it = d->mTempFiles.constBegin(); it != end; ++it) { | ||
68 | QFile::remove(*it); | ||
69 | } | ||
70 | d->mTempFiles.clear(); | ||
71 | end = d->mTempDirs.constEnd(); | ||
72 | for (QStringList::ConstIterator it = d->mTempDirs.constBegin(); it != end; ++it) { | ||
73 | QDir(*it).rmdir(*it); | ||
74 | } | ||
75 | d->mTempDirs.clear(); | ||
76 | } | ||
77 | |||
78 | void AttachmentTemporaryFilesDirs::slotRemoveTempFiles() | ||
79 | { | ||
80 | forceCleanTempFiles(); | ||
81 | //Delete it after cleaning | ||
82 | deleteLater(); | ||
83 | } | ||
84 | |||
85 | void AttachmentTemporaryFilesDirs::addTempFile(const QString &file) | ||
86 | { | ||
87 | if (!d->mTempFiles.contains(file)) { | ||
88 | d->mTempFiles.append(file); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | void AttachmentTemporaryFilesDirs::addTempDir(const QString &dir) | ||
93 | { | ||
94 | if (!d->mTempDirs.contains(dir)) { | ||
95 | d->mTempDirs.append(dir); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | QStringList AttachmentTemporaryFilesDirs::temporaryFiles() const | ||
100 | { | ||
101 | return d->mTempFiles; | ||
102 | } | ||
103 | |||
104 | QStringList AttachmentTemporaryFilesDirs::temporaryDirs() const | ||
105 | { | ||
106 | return d->mTempDirs; | ||
107 | } | ||
108 | |||