diff --git a/autotests/testattachment.h b/autotests/testattachment.h --- a/autotests/testattachment.h +++ b/autotests/testattachment.h @@ -30,7 +30,6 @@ void testValidity(); void testSerializer_data(); void testSerializer(); - void testWriteToTempFile(); }; #endif diff --git a/autotests/testattachment.cpp b/autotests/testattachment.cpp --- a/autotests/testattachment.cpp +++ b/autotests/testattachment.cpp @@ -95,19 +95,3 @@ stream2 >> attachment2; // deserialize QVERIFY(*attachment == *attachment2); } - -void AttachmentTest::testWriteToTempFile() -{ - QByteArray data("foo"); - Attachment::Ptr inlineAttachment = Attachment::Ptr(new Attachment(data.toBase64(), QStringLiteral("image/png"))); - Event *event = new Event(); - QString filePath = event->writeAttachmentToTempFile(inlineAttachment); - QVERIFY(filePath.endsWith(QLatin1String(".png"))); - QFile file(filePath); - QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); - QCOMPARE(file.readLine(), data); - file.close(); - - delete event; // file is deleted in DTOR - QVERIFY(!QFile::exists(filePath)); -} diff --git a/src/incidence.h b/src/incidence.h --- a/src/incidence.h +++ b/src/incidence.h @@ -539,22 +539,6 @@ */ void clearAttachments(); - /** - Writes the data in the attachment @p attachment to a temporary file - and returns the local name of the temporary file. - - @param attachment is a pointer to a valid Attachment instance. - @return a string containing the name of the temporary file containing the attachment. - @see clearTempFiles(). - */ - Q_REQUIRED_RESULT QString writeAttachmentToTempFile(const Attachment::Ptr &attachment) const; - - /** - Deletes all temporary files used by attachments and frees any memory in use by them. - @see writeAttachmentToTempFile(). - */ - void clearTempFiles(); - // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%% Secrecy and Status methods // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/incidence.cpp b/src/incidence.cpp --- a/src/incidence.cpp +++ b/src/incidence.cpp @@ -36,8 +36,6 @@ #include "calformat.h" #include "utils.h" -#include -#include #include // for .toHtmlEscaped() and Qt::mightBeRichText() #include #include @@ -161,7 +159,6 @@ QString mStatusString; // status string, for custom status QString mSchedulingID; // ID for scheduling mails QMap mRelatedToUid; // incidence uid this is related to, for each relType - QHash mTempFiles; // Temporary files for writing attachments to. QDateTime mRecurrenceId; // recurrenceId float mGeoLatitude; // Specifies latitude in decimal degrees @@ -204,7 +201,6 @@ for (const Alarm::Ptr &alarm : qAsConst(d->mAlarms)) { alarm->setParent(nullptr); } - clearTempFiles(); delete d->mRecurrence; delete d; } @@ -757,43 +753,6 @@ d->mAttachments.clear(); } -QString Incidence::writeAttachmentToTempFile(const Attachment::Ptr &attachment) const -{ - const QString attachementPath = d->mTempFiles.value(attachment); - if (!attachementPath.isEmpty()) { - return attachementPath; - } - QTemporaryFile file; - - QMimeDatabase mimeDb; - QStringList patterns = mimeDb.mimeTypeForName(attachment->mimeType()).globPatterns(); - - if (!patterns.empty()) { - file.setFileTemplate(file.fileTemplate() + QString(patterns.first()).remove(QLatin1Char('*'))); - } - file.setAutoRemove(false); - file.open(); - // read-only not to give the idea that it could be written to - file.setPermissions(QFile::ReadUser); - file.write(QByteArray::fromBase64(attachment->data())); - d->mTempFiles.insert(attachment, file.fileName()); - file.close(); - return d->mTempFiles.value(attachment); -} - -void Incidence::clearTempFiles() -{ - QHash::const_iterator it = d->mTempFiles.constBegin(); - const QHash::const_iterator end = d->mTempFiles.constEnd(); - for (; it != end; ++it) { - QFile f(it.value()); - // On Windows the file must be writeable before we can remove it - f.setPermissions(QFile::WriteUser); - f.remove(); - } - d->mTempFiles.clear(); -} - void Incidence::setResources(const QStringList &resources) { if (mReadOnly) {