diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -135,7 +135,6 @@ notificationoptions.cpp syntaxhighlightingmanager.cpp - copyfilejob.cpp receivetypingnotificationmanager.cpp diff --git a/src/core/copyfilejob.h b/src/core/copyfilejob.h deleted file mode 100644 --- a/src/core/copyfilejob.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - Copyright (c) 2018-2020 Laurent Montel - - 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 ) version 3 or, at the discretion of KDE e.V. - ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 COPYFILEJOB_H -#define COPYFILEJOB_H - -#include - -class CopyFileJob : public KJob -{ - Q_OBJECT -public: - explicit CopyFileJob(QObject *parent = nullptr); - ~CopyFileJob() override = default; - - void start() override; - - void setLocalFile(const QString &localFile); - - void setCachedFile(const QString &cachedFile); - -private: - Q_DISABLE_COPY(CopyFileJob) - QString mLocalFile; - QString mCachedFile; -}; - -#endif // COPYFILEJOB_H diff --git a/src/core/copyfilejob.cpp b/src/core/copyfilejob.cpp deleted file mode 100644 --- a/src/core/copyfilejob.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright (c) 2018-2020 Laurent Montel - - 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 ) version 3 or, at the discretion of KDE e.V. - ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "copyfilejob.h" -#include "ruqola_debug.h" -#include - -CopyFileJob::CopyFileJob(QObject *parent) - : KJob(parent) -{ -} - -void CopyFileJob::start() -{ - if (mLocalFile.isEmpty() || mCachedFile.isEmpty()) { - qCWarning(RUQOLA_LOG) << " localfile or cachedfile not defined"; - } else { - QFile f(mCachedFile); - if (!f.copy(mLocalFile)) { - qCWarning(RUQOLA_LOG) << "Impossible to copy " << mCachedFile << " to " << mLocalFile; - } - } -} - -void CopyFileJob::setLocalFile(const QString &localFile) -{ - mLocalFile = localFile; -} - -void CopyFileJob::setCachedFile(const QString &cachedFile) -{ - mCachedFile = cachedFile; -} diff --git a/src/core/rocketchatcache.cpp b/src/core/rocketchatcache.cpp --- a/src/core/rocketchatcache.cpp +++ b/src/core/rocketchatcache.cpp @@ -24,7 +24,6 @@ #include "managerdatapaths.h" #include "restapirequest.h" #include "avatarmanager.h" -#include "copyfilejob.h" #include #include #include @@ -94,16 +93,16 @@ void RocketChatCache::downloadFile(const QString &url, const QUrl &localFile, bool storeInCache) { - if (fileInCache(QUrl(url))) { - auto *job = new CopyFileJob(this); - job->setCachedFile(fileCachePath(QUrl(url))); - job->setLocalFile(localFile.toString()); - job->start(); + QFile f(fileCachePath(QUrl(url))); + if (f.exists()) { + if (!f.copy(localFile.toLocalFile())) { + qCWarning(RUQOLA_LOG) << "Impossible to copy" << f.fileName() << "to" << localFile; + } } else { - //Redownload it. TODO inform user ? - //FIXME we don't use localfile! + // Not in cache. We need to download it (e.g. file attachment). const QUrl clickedUrl = generateDownloadFile(url); mAccount->restApi()->downloadFile(clickedUrl, QStringLiteral("text/plain"), storeInCache, localFile); + // this will call slotDataDownloaded } }