Messagelib

attachmenttemporaryfilesdirs.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2020 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 
6 */
7 
8 #include "attachmenttemporaryfilesdirs.h"
9 
10 #include <QDir>
11 #include <QFile>
12 #include <QTimer>
13 
14 using namespace MimeTreeParser;
15 
16 class MimeTreeParser::AttachmentTemporaryFilesDirsPrivate
17 {
18 public:
19  AttachmentTemporaryFilesDirsPrivate()
20  {
21  }
22 
23  QStringList mTempFiles;
24  QStringList mTempDirs;
25  int mDelayRemoveAll = 10000;
26 };
27 
28 AttachmentTemporaryFilesDirs::AttachmentTemporaryFilesDirs(QObject *parent)
29  : QObject(parent)
30  , d(new AttachmentTemporaryFilesDirsPrivate)
31 {
32 }
33 
34 AttachmentTemporaryFilesDirs::~AttachmentTemporaryFilesDirs()
35 {
36  delete d;
37 }
38 
39 void AttachmentTemporaryFilesDirs::setDelayRemoveAllInMs(int ms)
40 {
41  d->mDelayRemoveAll = (ms < 0) ? 0 : ms;
42 }
43 
44 void AttachmentTemporaryFilesDirs::removeTempFiles()
45 {
46  QTimer::singleShot(d->mDelayRemoveAll, this, &AttachmentTemporaryFilesDirs::slotRemoveTempFiles);
47 }
48 
49 void AttachmentTemporaryFilesDirs::forceCleanTempFiles()
50 {
51  QStringList::ConstIterator end = d->mTempFiles.constEnd();
52  for (QStringList::ConstIterator it = d->mTempFiles.constBegin(); it != end; ++it) {
53  QFile::remove(*it);
54  }
55  d->mTempFiles.clear();
56  end = d->mTempDirs.constEnd();
57  for (QStringList::ConstIterator it = d->mTempDirs.constBegin(); it != end; ++it) {
58  QDir(*it).rmdir(*it);
59  }
60  d->mTempDirs.clear();
61 }
62 
63 void AttachmentTemporaryFilesDirs::slotRemoveTempFiles()
64 {
65  forceCleanTempFiles();
66  //Delete it after cleaning
67  deleteLater();
68 }
69 
70 void AttachmentTemporaryFilesDirs::addTempFile(const QString &file)
71 {
72  if (!d->mTempFiles.contains(file)) {
73  d->mTempFiles.append(file);
74  }
75 }
76 
77 void AttachmentTemporaryFilesDirs::addTempDir(const QString &dir)
78 {
79  if (!d->mTempDirs.contains(dir)) {
80  d->mTempDirs.append(dir);
81  }
82 }
83 
84 QStringList AttachmentTemporaryFilesDirs::temporaryFiles() const
85 {
86  return d->mTempFiles;
87 }
88 
89 QStringList AttachmentTemporaryFilesDirs::temporaryDirs() const
90 {
91  return d->mTempDirs;
92 }
bool remove()
bool rmdir(const QString &dirName) const const
const QList< QKeySequence > & end()
typedef ConstIterator
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Sep 22 2020 23:13:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.