From 76c4e0634987056c026c9d66ae7e9656f662a5a0 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Sat, 29 Oct 2022 13:21:56 +0200 Subject: [PATCH] Rename EditLocallyHandler to EditLocallyJob Signed-off-by: Claudio Cambra --- src/gui/CMakeLists.txt | 4 +- ...tlocallyhandler.cpp => editlocallyjob.cpp} | 58 +++++++++---------- ...{editlocallyhandler.h => editlocallyjob.h} | 14 ++--- src/gui/editlocallymanager.cpp | 30 +++++----- src/gui/editlocallymanager.h | 10 ++-- 5 files changed, 57 insertions(+), 59 deletions(-) rename src/gui/{editlocallyhandler.cpp => editlocallyjob.cpp} (81%) rename src/gui/{editlocallyhandler.h => editlocallyjob.h} (84%) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 4995dafcb1805..3a845531e5db0 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -81,8 +81,8 @@ set(client_SRCS conflictsolver.cpp connectionvalidator.h connectionvalidator.cpp - editlocallyhandler.h - editlocallyhandler.cpp + editlocallyjob.h + editlocallyjob.cpp editlocallymanager.h editlocallymanager.cpp folder.h diff --git a/src/gui/editlocallyhandler.cpp b/src/gui/editlocallyjob.cpp similarity index 81% rename from src/gui/editlocallyhandler.cpp rename to src/gui/editlocallyjob.cpp index 50e22698a823d..63f9515f8e471 100644 --- a/src/gui/editlocallyhandler.cpp +++ b/src/gui/editlocallyjob.cpp @@ -12,7 +12,7 @@ * for more details. */ -#include "editlocallyhandler.h" +#include "editlocallyjob.h" #include #include @@ -26,9 +26,9 @@ namespace OCC { -Q_LOGGING_CATEGORY(lcEditLocallyHandler, "nextcloud.gui.editlocallyhandler", QtInfoMsg) +Q_LOGGING_CATEGORY(lcEditLocallyJob, "nextcloud.gui.editlocallyjob", QtInfoMsg) -EditLocallyHandler::EditLocallyHandler(const QString &userId, +EditLocallyJob::EditLocallyJob(const QString &userId, const QString &relPath, const QString &token, QObject *parent) @@ -39,10 +39,10 @@ EditLocallyHandler::EditLocallyHandler(const QString &userId, { } -void EditLocallyHandler::startSetup() +void EditLocallyJob::startSetup() { if (_token.isEmpty() || _relPath.isEmpty() || _userId.isEmpty()) { - qCWarning(lcEditLocallyHandler) << "Could not start setup." + qCWarning(lcEditLocallyJob) << "Could not start setup." << "token:" << _token << "relPath:" << _relPath << "userId" << _userId; @@ -56,14 +56,14 @@ void EditLocallyHandler::startSetup() // We check the input data locally first, without modifying any state or // showing any potentially misleading data to the user if (!isTokenValid(_token)) { - qCWarning(lcEditLocallyHandler) << "Edit locally request is missing a valid token, will not open file. " + qCWarning(lcEditLocallyJob) << "Edit locally request is missing a valid token, will not open file. " << "Token received was:" << _token; showError(tr("Invalid token received."), tr("Please try again.")); return; } if (!isRelPathValid(_relPath)) { - qCWarning(lcEditLocallyHandler) << "Provided relPath was:" << _relPath << "which is not canonical."; + qCWarning(lcEditLocallyJob) << "Provided relPath was:" << _relPath << "which is not canonical."; showError(tr("Invalid file path was provided."), tr("Please try again.")); return; } @@ -71,7 +71,7 @@ void EditLocallyHandler::startSetup() _accountState = AccountManager::instance()->accountFromUserId(_userId); if (!_accountState) { - qCWarning(lcEditLocallyHandler) << "Could not find an account " << _userId << " to edit file " << _relPath << " locally."; + qCWarning(lcEditLocallyJob) << "Could not find an account " << _userId << " to edit file " << _relPath << " locally."; showError(tr("Could not find an account for local editing."), tr("Please try again.")); return; } @@ -81,10 +81,10 @@ void EditLocallyHandler::startSetup() startTokenRemoteCheck(); } -void EditLocallyHandler::startTokenRemoteCheck() +void EditLocallyJob::startTokenRemoteCheck() { if (!_accountState || _relPath.isEmpty() || _token.isEmpty()) { - qCWarning(lcEditLocallyHandler) << "Could not start token check." + qCWarning(lcEditLocallyJob) << "Could not start token check." << "accountState:" << _accountState << "relPath:" << _relPath << "token:" << _token; @@ -101,14 +101,14 @@ void EditLocallyHandler::startTokenRemoteCheck() params.addQueryItem(QStringLiteral("path"), prefixSlashToPath(encodedRelPath)); _checkTokenJob->addQueryParams(params); _checkTokenJob->setVerb(SimpleApiJob::Verb::Post); - connect(_checkTokenJob.get(), &SimpleApiJob::resultReceived, this, &EditLocallyHandler::remoteTokenCheckResultReceived); + connect(_checkTokenJob.get(), &SimpleApiJob::resultReceived, this, &EditLocallyJob::remoteTokenCheckResultReceived); _checkTokenJob->start(); } -void EditLocallyHandler::remoteTokenCheckResultReceived(const int statusCode) +void EditLocallyJob::remoteTokenCheckResultReceived(const int statusCode) { - qCInfo(lcEditLocallyHandler) << "token check result" << statusCode; + qCInfo(lcEditLocallyJob) << "token check result" << statusCode; constexpr auto HTTP_OK_CODE = 200; _tokenVerified = statusCode == HTTP_OK_CODE; @@ -121,10 +121,10 @@ void EditLocallyHandler::remoteTokenCheckResultReceived(const int statusCode) proceedWithSetup(); } -void EditLocallyHandler::proceedWithSetup() +void EditLocallyJob::proceedWithSetup() { if (!_tokenVerified) { - qCWarning(lcEditLocallyHandler) << "Could not proceed with setup as token is not verified."; + qCWarning(lcEditLocallyJob) << "Could not proceed with setup as token is not verified."; return; } @@ -159,12 +159,12 @@ void EditLocallyHandler::proceedWithSetup() Q_EMIT setupFinished(); } -QString EditLocallyHandler::prefixSlashToPath(const QString &path) +QString EditLocallyJob::prefixSlashToPath(const QString &path) { return path.startsWith('/') ? path : QChar::fromLatin1('/') + path; } -bool EditLocallyHandler::isTokenValid(const QString &token) +bool EditLocallyJob::isTokenValid(const QString &token) { if (token.isEmpty()) { return false; @@ -178,7 +178,7 @@ bool EditLocallyHandler::isTokenValid(const QString &token) return regexMatch.hasMatch(); } -bool EditLocallyHandler::isRelPathValid(const QString &relPath) +bool EditLocallyJob::isRelPathValid(const QString &relPath) { if (relPath.isEmpty()) { return false; @@ -201,7 +201,7 @@ bool EditLocallyHandler::isRelPathValid(const QString &relPath) return true; } -bool EditLocallyHandler::isRelPathExcluded(const QString &relPath) +bool EditLocallyJob::isRelPathExcluded(const QString &relPath) { if (relPath.isEmpty()) { return false; @@ -221,7 +221,7 @@ bool EditLocallyHandler::isRelPathExcluded(const QString &relPath) return false; } -void EditLocallyHandler::showError(const QString &message, const QString &informativeText) +void EditLocallyJob::showError(const QString &message, const QString &informativeText) { Systray::instance()->destroyEditFileLocallyLoadingDialog(); showErrorNotification(message, informativeText); @@ -230,7 +230,7 @@ void EditLocallyHandler::showError(const QString &message, const QString &inform Q_EMIT error(message, informativeText); } -void EditLocallyHandler::showErrorNotification(const QString &message, const QString &informativeText) const +void EditLocallyJob::showErrorNotification(const QString &message, const QString &informativeText) const { if (!_accountState || !_accountState->account()) { return; @@ -246,7 +246,7 @@ void EditLocallyHandler::showErrorNotification(const QString &message, const QSt } } -void EditLocallyHandler::showErrorMessageBox(const QString &message, const QString &informativeText) const +void EditLocallyJob::showErrorMessageBox(const QString &message, const QString &informativeText) const { const auto messageBox = new QMessageBox; messageBox->setAttribute(Qt::WA_DeleteOnClose); @@ -259,10 +259,10 @@ void EditLocallyHandler::showErrorMessageBox(const QString &message, const QStri messageBox->raise(); } -void EditLocallyHandler::startEditLocally() +void EditLocallyJob::startEditLocally() { if (_fileName.isEmpty() || _localFilePath.isEmpty() || !_folderForFile) { - qCWarning(lcEditLocallyHandler) << "Could not start to edit locally." + qCWarning(lcEditLocallyJob) << "Could not start to edit locally." << "fileName:" << _fileName << "localFilePath:" << _localFilePath << "folderForFile:" << _folderForFile; @@ -273,20 +273,20 @@ void EditLocallyHandler::startEditLocally() _folderForFile->startSync(); const auto syncFinishedConnection = connect(_folderForFile, &Folder::syncFinished, - this, &EditLocallyHandler::folderSyncFinished); + this, &EditLocallyJob::folderSyncFinished); EditLocallyManager::instance()->folderSyncFinishedConnections.insert(_localFilePath, syncFinishedConnection); } -void EditLocallyHandler::folderSyncFinished(const OCC::SyncResult &result) +void EditLocallyJob::folderSyncFinished(const OCC::SyncResult &result) { Q_UNUSED(result) disconnectSyncFinished(); openFile(); } -void EditLocallyHandler::disconnectSyncFinished() const +void EditLocallyJob::disconnectSyncFinished() const { if(_localFilePath.isEmpty()) { return; @@ -300,10 +300,10 @@ void EditLocallyHandler::disconnectSyncFinished() const } } -void EditLocallyHandler::openFile() +void EditLocallyJob::openFile() { if(_localFilePath.isEmpty()) { - qCWarning(lcEditLocallyHandler) << "Could not edit locally. Invalid local file path."; + qCWarning(lcEditLocallyJob) << "Could not edit locally. Invalid local file path."; return; } diff --git a/src/gui/editlocallyhandler.h b/src/gui/editlocallyjob.h similarity index 84% rename from src/gui/editlocallyhandler.h rename to src/gui/editlocallyjob.h index 0093191b80849..258382a80a2bf 100644 --- a/src/gui/editlocallyhandler.h +++ b/src/gui/editlocallyjob.h @@ -20,21 +20,21 @@ namespace OCC { -class EditLocallyHandler; -using EditLocallyHandlerPtr = QSharedPointer; +class EditLocallyJob; +using EditLocallyJobPtr = QSharedPointer; class Folder; class SyncResult; -class EditLocallyHandler : public QObject +class EditLocallyJob : public QObject { Q_OBJECT public: - explicit EditLocallyHandler(const QString &userId, - const QString &relPath, - const QString &token, - QObject *parent = nullptr); + explicit EditLocallyJob(const QString &userId, + const QString &relPath, + const QString &token, + QObject *parent = nullptr); [[nodiscard]] static bool isTokenValid(const QString &token); [[nodiscard]] static bool isRelPathValid(const QString &relPath); diff --git a/src/gui/editlocallymanager.cpp b/src/gui/editlocallymanager.cpp index 1d8bea8c9c0fa..567a4abbd80a0 100644 --- a/src/gui/editlocallymanager.cpp +++ b/src/gui/editlocallymanager.cpp @@ -17,8 +17,6 @@ #include #include -#include "editlocallyhandler.h" - namespace OCC { Q_LOGGING_CATEGORY(lcEditLocallyManager, "nextcloud.gui.editlocallymanager", QtInfoMsg) @@ -41,7 +39,7 @@ EditLocallyManager *EditLocallyManager::instance() void EditLocallyManager::editLocally(const QUrl &url) { const auto inputs = parseEditLocallyUrl(url); - createHandler(inputs.userId, inputs.relPath, inputs.token); + createJob(inputs.userId, inputs.relPath, inputs.token); } EditLocallyManager::EditLocallyInputData EditLocallyManager::parseEditLocallyUrl(const QUrl &url) @@ -69,25 +67,25 @@ EditLocallyManager::EditLocallyInputData EditLocallyManager::parseEditLocallyUrl return {userId, fileRemotePath, token}; } -void EditLocallyManager::createHandler(const QString &userId, +void EditLocallyManager::createJob(const QString &userId, const QString &relPath, const QString &token) { - const EditLocallyHandlerPtr handler(new EditLocallyHandler(userId, relPath, token)); - // We need to make sure the handler sticks around until it is finished - _handlers.insert(token, handler); + const EditLocallyJobPtr job(new EditLocallyJob(userId, relPath, token)); + // We need to make sure the job sticks around until it is finished + _jobs.insert(token, job); - const auto removeHandler = [this, token] { _handlers.remove(token); }; - const auto setupHandler = [handler] { handler->startEditLocally(); }; + const auto removeJob = [this, token] { _jobs.remove(token); }; + const auto setupJob = [job] { job->startEditLocally(); }; - connect(handler.data(), &EditLocallyHandler::error, - this, removeHandler); - connect(handler.data(), &EditLocallyHandler::fileOpened, - this, removeHandler); - connect(handler.data(), &EditLocallyHandler::setupFinished, - handler.data(), setupHandler); + connect(job.data(), &EditLocallyJob::error, + this, removeJob); + connect(job.data(), &EditLocallyJob::fileOpened, + this, removeJob); + connect(job.data(), &EditLocallyJob::setupFinished, + job.data(), setupJob); - handler->startSetup(); + job->startSetup(); } } diff --git a/src/gui/editlocallymanager.h b/src/gui/editlocallymanager.h index 3ba414fca77b3..cf42f1ed76fb8 100644 --- a/src/gui/editlocallymanager.h +++ b/src/gui/editlocallymanager.h @@ -17,7 +17,7 @@ #include #include -#include "editlocallyhandler.h" +#include "editlocallyjob.h" namespace OCC { @@ -34,9 +34,9 @@ public slots: void editLocally(const QUrl &url); private slots: - void createHandler(const QString &userId, - const QString &relPath, - const QString &token); + void createJob(const QString &userId, + const QString &relPath, + const QString &token); private: explicit EditLocallyManager(QObject *parent = nullptr); @@ -50,7 +50,7 @@ private slots: [[nodiscard]] static EditLocallyInputData parseEditLocallyUrl(const QUrl &url); - QHash _handlers; + QHash _jobs; }; }