Commit d16c7d2a authored by Sandro Knauß's avatar Sandro Knauß

Move temporaryfile to MimeTreeParser

parent 1e7e439c
......@@ -20,7 +20,7 @@ include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
include(ECMInstallIcons)
set(PIMCOMMON_LIB_VERSION "5.2.40")
set(PIMCOMMON_LIB_VERSION "5.2.41")
set(KF5_VERSION "5.19.0")
set(KDEPIMLIBS_LIB_VERSION "5.2.40")
set(LIBKDEPIM_LIB_VERSION "5.2.40")
......
......@@ -161,11 +161,6 @@ set(libpimcommon_util_SRCS
)
set(libpimcommon_temporary_SRCS
temporaryfile/attachmenttemporaryfilesdirs.cpp
)
set(libpimcommon_migrate_SRCS
migration/migrateapplicationfiles.cpp
migration/migratefileinfo.cpp
......@@ -208,7 +203,6 @@ set(libpimcommon_SRCS
${libpimcommon_acl_SRCS}
${libpimcommon_sieve_SRCS}
${libpimcommon_widgets_SRCS}
${libpimcommon_temporary_SRCS}
${libpimcommon_customtools_SRCS}
${libpimcommon_generericplugin_SRCS}
)
......@@ -301,7 +295,6 @@ if (BUILD_TESTING)
add_subdirectory(autocorrection/autotests)
add_subdirectory(widgets/autotests)
add_subdirectory(acl/autotests)
add_subdirectory(temporaryfile/autotests)
add_subdirectory(migration/autotests)
add_subdirectory(util/autotests)
add_subdirectory(shareserviceurl/autotests)
......@@ -470,14 +463,6 @@ ecm_generate_headers(PimCommon_Camelcasestorageserviceinterface_HEADERS
RELATIVE storageservice/interface
)
ecm_generate_headers(PimCommon_Camelcasetemporaryfile_HEADERS
HEADER_NAMES
AttachmentTemporaryFilesDirs
REQUIRED_HEADERS PimCommon_temporaryfile_HEADERS
PREFIX PimCommon
RELATIVE temporaryfile
)
ecm_generate_headers(PimCommon_Camelcasesievehighlighter_HEADERS
HEADER_NAMES
SieveSyntaxHighlighterUtil
......@@ -593,7 +578,6 @@ install(FILES
${PimCommon_Camelcasetranslator_HEADERS}
${PimCommon_Camelcasecustomtools_HEADERS}
${PimCommon_Camelcasestorageserviceinterface_HEADERS}
${PimCommon_Camelcasetemporaryfile_HEADERS}
${PimCommon_Camelcasesievehighlighter_HEADERS}
${PimCommon_Camelcaseacl_HEADERS}
${PimCommon_Camelcasemigrate_HEADERS}
......@@ -633,7 +617,6 @@ install(FILES
${PimCommon_translator_HEADERS}
${PimCommon_customtools_HEADERS}
${PimCommon_storageserviceinterface_HEADERS}
${PimCommon_temporaryfile_HEADERS}
${PimCommon_sievehighlighter_HEADERS}
${PimCommon_acl_HEADERS}
${PimCommon_migrate_HEADERS}
......
/*
Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "attachmenttemporaryfilesdirs.h"
#include <QDir>
#include <QFile>
#include <QTimer>
using namespace PimCommon;
class PimCommon::AttachmentTemporaryFilesDirsPrivate
{
public:
AttachmentTemporaryFilesDirsPrivate()
: mDelayRemoveAll(10000)
{
}
QStringList mTempFiles;
QStringList mTempDirs;
int mDelayRemoveAll;
};
AttachmentTemporaryFilesDirs::AttachmentTemporaryFilesDirs(QObject *parent)
: QObject(parent),
d(new PimCommon::AttachmentTemporaryFilesDirsPrivate)
{
}
AttachmentTemporaryFilesDirs::~AttachmentTemporaryFilesDirs()
{
delete d;
}
void AttachmentTemporaryFilesDirs::setDelayRemoveAllInMs(int ms)
{
d->mDelayRemoveAll = (ms < 0) ? 0 : ms;
}
void AttachmentTemporaryFilesDirs::removeTempFiles()
{
QTimer::singleShot(d->mDelayRemoveAll, this, &AttachmentTemporaryFilesDirs::slotRemoveTempFiles);
}
void AttachmentTemporaryFilesDirs::forceCleanTempFiles()
{
QStringList::ConstIterator end = d->mTempFiles.constEnd();
for (QStringList::ConstIterator it = d->mTempFiles.constBegin(); it != end; ++it) {
QFile::remove(*it);
}
d->mTempFiles.clear();
end = d->mTempDirs.constEnd();
for (QStringList::ConstIterator it = d->mTempDirs.constBegin(); it != end; ++it) {
QDir(*it).rmdir(*it);
}
d->mTempDirs.clear();
}
void AttachmentTemporaryFilesDirs::slotRemoveTempFiles()
{
forceCleanTempFiles();
//Delete it after cleaning
deleteLater();
}
void AttachmentTemporaryFilesDirs::addTempFile(const QString &file)
{
if (!d->mTempFiles.contains(file)) {
d->mTempFiles.append(file);
}
}
void AttachmentTemporaryFilesDirs::addTempDir(const QString &dir)
{
if (!d->mTempDirs.contains(dir)) {
d->mTempDirs.append(dir);
}
}
QStringList AttachmentTemporaryFilesDirs::temporaryFiles() const
{
return d->mTempFiles;
}
QStringList AttachmentTemporaryFilesDirs::temporaryDirs() const
{
return d->mTempDirs;
}
/*
Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef ATTACHMENTTEMPORARYFILESDIRS_H
#define ATTACHMENTTEMPORARYFILESDIRS_H
#include <QObject>
#include <QStringList>
#include "pimcommon_export.h"
namespace PimCommon
{
class AttachmentTemporaryFilesDirsPrivate;
class PIMCOMMON_EXPORT AttachmentTemporaryFilesDirs : public QObject
{
Q_OBJECT
public:
explicit AttachmentTemporaryFilesDirs(QObject *parent = Q_NULLPTR);
~AttachmentTemporaryFilesDirs();
void addTempFile(const QString &file);
void addTempDir(const QString &dir);
QStringList temporaryFiles() const;
void removeTempFiles();
void forceCleanTempFiles();
QStringList temporaryDirs() const;
void setDelayRemoveAllInMs(int ms);
private Q_SLOTS:
void slotRemoveTempFiles();
private:
AttachmentTemporaryFilesDirsPrivate *const d;
};
}
#endif // ATTACHMENTTEMPORARYFILESDIRS_H
ecm_add_test(attachmenttemporaryfilesdirstest.cpp
NAME_PREFIX "pimcommon-temporaryfile-"
LINK_LIBRARIES Qt5::Test KF5::PimCommon
)
/*
Copyright (c) 2014-2016 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "attachmenttemporaryfilesdirstest.h"
#include "../attachmenttemporaryfilesdirs.h"
#include <QTemporaryDir>
#include <qtest.h>
#include <QDebug>
using namespace PimCommon;
AttachmentTemporaryFilesDirsTest::AttachmentTemporaryFilesDirsTest(QObject *parent)
: QObject(parent)
{
}
AttachmentTemporaryFilesDirsTest::~AttachmentTemporaryFilesDirsTest()
{
}
void AttachmentTemporaryFilesDirsTest::shouldHaveDefaultValue()
{
AttachmentTemporaryFilesDirs attachmentDir;
QVERIFY(attachmentDir.temporaryFiles().isEmpty());
QVERIFY(attachmentDir.temporaryDirs().isEmpty());
}
void AttachmentTemporaryFilesDirsTest::shouldAddTemporaryFiles()
{
AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempFile(QStringLiteral("foo"));
QCOMPARE(attachmentDir.temporaryFiles().count(), 1);
attachmentDir.addTempFile(QStringLiteral("foo1"));
QCOMPARE(attachmentDir.temporaryFiles().count(), 2);
}
void AttachmentTemporaryFilesDirsTest::shouldAddTemporaryDirs()
{
AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempDir(QStringLiteral("foo"));
QCOMPARE(attachmentDir.temporaryDirs().count(), 1);
attachmentDir.addTempDir(QStringLiteral("foo1"));
QCOMPARE(attachmentDir.temporaryDirs().count(), 2);
}
void AttachmentTemporaryFilesDirsTest::shouldNotAddSameFiles()
{
AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempFile(QStringLiteral("foo"));
QCOMPARE(attachmentDir.temporaryFiles().count(), 1);
attachmentDir.addTempFile(QStringLiteral("foo"));
QCOMPARE(attachmentDir.temporaryFiles().count(), 1);
}
void AttachmentTemporaryFilesDirsTest::shouldNotAddSameDirs()
{
AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempDir(QStringLiteral("foo"));
QCOMPARE(attachmentDir.temporaryDirs().count(), 1);
attachmentDir.addTempDir(QStringLiteral("foo"));
QCOMPARE(attachmentDir.temporaryDirs().count(), 1);
}
void AttachmentTemporaryFilesDirsTest::shouldForceRemoveTemporaryDirs()
{
AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempDir(QStringLiteral("foo"));
attachmentDir.addTempDir(QStringLiteral("foo1"));
QCOMPARE(attachmentDir.temporaryDirs().count(), 2);
attachmentDir.forceCleanTempFiles();
QCOMPARE(attachmentDir.temporaryDirs().count(), 0);
QCOMPARE(attachmentDir.temporaryFiles().count(), 0);
}
void AttachmentTemporaryFilesDirsTest::shouldForceRemoveTemporaryFiles()
{
AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempFile(QStringLiteral("foo"));
attachmentDir.addTempFile(QStringLiteral("foo2"));
QCOMPARE(attachmentDir.temporaryFiles().count(), 2);
attachmentDir.forceCleanTempFiles();
QCOMPARE(attachmentDir.temporaryFiles().count(), 0);
QCOMPARE(attachmentDir.temporaryDirs().count(), 0);
}
void AttachmentTemporaryFilesDirsTest::shouldCreateDeleteTemporaryFiles()
{
QTemporaryDir tmpDir;
QVERIFY(tmpDir.isValid());
QFile file(tmpDir.path() + QStringLiteral("/foo"));
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Can open file";
return;
}
tmpDir.setAutoRemove(false);
file.close();
QVERIFY(file.exists());
AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempDir(tmpDir.path());
attachmentDir.addTempFile(file.fileName());
QVERIFY(!attachmentDir.temporaryFiles().isEmpty());
QCOMPARE(attachmentDir.temporaryFiles().first(), file.fileName());
const QString path = tmpDir.path();
attachmentDir.forceCleanTempFiles();
QCOMPARE(attachmentDir.temporaryFiles().count(), 0);
QCOMPARE(attachmentDir.temporaryDirs().count(), 0);
QVERIFY(!QDir(path).exists());
}
void AttachmentTemporaryFilesDirsTest::shouldRemoveTemporaryFilesAfterTime()
{
QTemporaryDir tmpDir;
QVERIFY(tmpDir.isValid());
QFile file(tmpDir.path() + QStringLiteral("/foo"));
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Can open file";
return;
}
tmpDir.setAutoRemove(false);
file.close();
QVERIFY(file.exists());
AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempDir(tmpDir.path());
attachmentDir.addTempFile(file.fileName());
QVERIFY(!attachmentDir.temporaryFiles().isEmpty());
QCOMPARE(attachmentDir.temporaryFiles().first(), file.fileName());
attachmentDir.setDelayRemoveAllInMs(500);
QTest::qSleep(1000);
attachmentDir.removeTempFiles();
const QString path = tmpDir.path();
attachmentDir.forceCleanTempFiles();
QCOMPARE(attachmentDir.temporaryFiles().count(), 0);
QCOMPARE(attachmentDir.temporaryDirs().count(), 0);
QVERIFY(!QDir(path).exists());
}
QTEST_MAIN(AttachmentTemporaryFilesDirsTest)
/*
Copyright (c) 2014-2016 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef ATTACHMENTTEMPORARYFILESDIRSTEST_H
#define ATTACHMENTTEMPORARYFILESDIRSTEST_H
#include <QObject>
class AttachmentTemporaryFilesDirsTest : public QObject
{
Q_OBJECT
public:
explicit AttachmentTemporaryFilesDirsTest(QObject *parent = Q_NULLPTR);
~AttachmentTemporaryFilesDirsTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAddTemporaryFiles();
void shouldAddTemporaryDirs();
void shouldNotAddSameFiles();
void shouldNotAddSameDirs();
void shouldForceRemoveTemporaryDirs();
void shouldForceRemoveTemporaryFiles();
void shouldCreateDeleteTemporaryFiles();
void shouldRemoveTemporaryFilesAfterTime();
};
#endif // ATTACHMENTTEMPORARYFILESDIRSTEST_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment