Rename EditLocallyHandler to EditLocallyJob

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2022-10-29 13:21:56 +02:00 committed by Claudio Cambra
parent ee8b12009a
commit 72e154def1
5 changed files with 57 additions and 59 deletions

View file

@ -81,8 +81,8 @@ set(client_SRCS
conflictsolver.cpp conflictsolver.cpp
connectionvalidator.h connectionvalidator.h
connectionvalidator.cpp connectionvalidator.cpp
editlocallyhandler.h editlocallyjob.h
editlocallyhandler.cpp editlocallyjob.cpp
editlocallymanager.h editlocallymanager.h
editlocallymanager.cpp editlocallymanager.cpp
folder.h folder.h

View file

@ -12,7 +12,7 @@
* for more details. * for more details.
*/ */
#include "editlocallyhandler.h" #include "editlocallyjob.h"
#include <QMessageBox> #include <QMessageBox>
#include <QDesktopServices> #include <QDesktopServices>
@ -26,9 +26,9 @@
namespace OCC { 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 &relPath,
const QString &token, const QString &token,
QObject *parent) QObject *parent)
@ -39,10 +39,10 @@ EditLocallyHandler::EditLocallyHandler(const QString &userId,
{ {
} }
void EditLocallyHandler::startSetup() void EditLocallyJob::startSetup()
{ {
if (_token.isEmpty() || _relPath.isEmpty() || _userId.isEmpty()) { if (_token.isEmpty() || _relPath.isEmpty() || _userId.isEmpty()) {
qCWarning(lcEditLocallyHandler) << "Could not start setup." qCWarning(lcEditLocallyJob) << "Could not start setup."
<< "token:" << _token << "token:" << _token
<< "relPath:" << _relPath << "relPath:" << _relPath
<< "userId" << _userId; << "userId" << _userId;
@ -56,14 +56,14 @@ void EditLocallyHandler::startSetup()
// We check the input data locally first, without modifying any state or // We check the input data locally first, without modifying any state or
// showing any potentially misleading data to the user // showing any potentially misleading data to the user
if (!isTokenValid(_token)) { 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; << "Token received was:" << _token;
showError(tr("Invalid token received."), tr("Please try again.")); showError(tr("Invalid token received."), tr("Please try again."));
return; return;
} }
if (!isRelPathValid(_relPath)) { 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.")); showError(tr("Invalid file path was provided."), tr("Please try again."));
return; return;
} }
@ -71,7 +71,7 @@ void EditLocallyHandler::startSetup()
_accountState = AccountManager::instance()->accountFromUserId(_userId); _accountState = AccountManager::instance()->accountFromUserId(_userId);
if (!_accountState) { 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.")); showError(tr("Could not find an account for local editing."), tr("Please try again."));
return; return;
} }
@ -81,10 +81,10 @@ void EditLocallyHandler::startSetup()
startTokenRemoteCheck(); startTokenRemoteCheck();
} }
void EditLocallyHandler::startTokenRemoteCheck() void EditLocallyJob::startTokenRemoteCheck()
{ {
if (!_accountState || _relPath.isEmpty() || _token.isEmpty()) { if (!_accountState || _relPath.isEmpty() || _token.isEmpty()) {
qCWarning(lcEditLocallyHandler) << "Could not start token check." qCWarning(lcEditLocallyJob) << "Could not start token check."
<< "accountState:" << _accountState << "accountState:" << _accountState
<< "relPath:" << _relPath << "relPath:" << _relPath
<< "token:" << _token; << "token:" << _token;
@ -101,14 +101,14 @@ void EditLocallyHandler::startTokenRemoteCheck()
params.addQueryItem(QStringLiteral("path"), prefixSlashToPath(encodedRelPath)); params.addQueryItem(QStringLiteral("path"), prefixSlashToPath(encodedRelPath));
_checkTokenJob->addQueryParams(params); _checkTokenJob->addQueryParams(params);
_checkTokenJob->setVerb(SimpleApiJob::Verb::Post); _checkTokenJob->setVerb(SimpleApiJob::Verb::Post);
connect(_checkTokenJob.get(), &SimpleApiJob::resultReceived, this, &EditLocallyHandler::remoteTokenCheckResultReceived); connect(_checkTokenJob.get(), &SimpleApiJob::resultReceived, this, &EditLocallyJob::remoteTokenCheckResultReceived);
_checkTokenJob->start(); _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; constexpr auto HTTP_OK_CODE = 200;
_tokenVerified = statusCode == HTTP_OK_CODE; _tokenVerified = statusCode == HTTP_OK_CODE;
@ -121,10 +121,10 @@ void EditLocallyHandler::remoteTokenCheckResultReceived(const int statusCode)
proceedWithSetup(); proceedWithSetup();
} }
void EditLocallyHandler::proceedWithSetup() void EditLocallyJob::proceedWithSetup()
{ {
if (!_tokenVerified) { 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; return;
} }
@ -159,12 +159,12 @@ void EditLocallyHandler::proceedWithSetup()
Q_EMIT setupFinished(); Q_EMIT setupFinished();
} }
QString EditLocallyHandler::prefixSlashToPath(const QString &path) QString EditLocallyJob::prefixSlashToPath(const QString &path)
{ {
return path.startsWith('/') ? path : QChar::fromLatin1('/') + path; return path.startsWith('/') ? path : QChar::fromLatin1('/') + path;
} }
bool EditLocallyHandler::isTokenValid(const QString &token) bool EditLocallyJob::isTokenValid(const QString &token)
{ {
if (token.isEmpty()) { if (token.isEmpty()) {
return false; return false;
@ -178,7 +178,7 @@ bool EditLocallyHandler::isTokenValid(const QString &token)
return regexMatch.hasMatch(); return regexMatch.hasMatch();
} }
bool EditLocallyHandler::isRelPathValid(const QString &relPath) bool EditLocallyJob::isRelPathValid(const QString &relPath)
{ {
if (relPath.isEmpty()) { if (relPath.isEmpty()) {
return false; return false;
@ -201,7 +201,7 @@ bool EditLocallyHandler::isRelPathValid(const QString &relPath)
return true; return true;
} }
bool EditLocallyHandler::isRelPathExcluded(const QString &relPath) bool EditLocallyJob::isRelPathExcluded(const QString &relPath)
{ {
if (relPath.isEmpty()) { if (relPath.isEmpty()) {
return false; return false;
@ -221,7 +221,7 @@ bool EditLocallyHandler::isRelPathExcluded(const QString &relPath)
return false; return false;
} }
void EditLocallyHandler::showError(const QString &message, const QString &informativeText) void EditLocallyJob::showError(const QString &message, const QString &informativeText)
{ {
Systray::instance()->destroyEditFileLocallyLoadingDialog(); Systray::instance()->destroyEditFileLocallyLoadingDialog();
showErrorNotification(message, informativeText); showErrorNotification(message, informativeText);
@ -230,7 +230,7 @@ void EditLocallyHandler::showError(const QString &message, const QString &inform
Q_EMIT error(message, informativeText); 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()) { if (!_accountState || !_accountState->account()) {
return; 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; const auto messageBox = new QMessageBox;
messageBox->setAttribute(Qt::WA_DeleteOnClose); messageBox->setAttribute(Qt::WA_DeleteOnClose);
@ -259,10 +259,10 @@ void EditLocallyHandler::showErrorMessageBox(const QString &message, const QStri
messageBox->raise(); messageBox->raise();
} }
void EditLocallyHandler::startEditLocally() void EditLocallyJob::startEditLocally()
{ {
if (_fileName.isEmpty() || _localFilePath.isEmpty() || !_folderForFile) { if (_fileName.isEmpty() || _localFilePath.isEmpty() || !_folderForFile) {
qCWarning(lcEditLocallyHandler) << "Could not start to edit locally." qCWarning(lcEditLocallyJob) << "Could not start to edit locally."
<< "fileName:" << _fileName << "fileName:" << _fileName
<< "localFilePath:" << _localFilePath << "localFilePath:" << _localFilePath
<< "folderForFile:" << _folderForFile; << "folderForFile:" << _folderForFile;
@ -273,20 +273,20 @@ void EditLocallyHandler::startEditLocally()
_folderForFile->startSync(); _folderForFile->startSync();
const auto syncFinishedConnection = connect(_folderForFile, &Folder::syncFinished, const auto syncFinishedConnection = connect(_folderForFile, &Folder::syncFinished,
this, &EditLocallyHandler::folderSyncFinished); this, &EditLocallyJob::folderSyncFinished);
EditLocallyManager::instance()->folderSyncFinishedConnections.insert(_localFilePath, EditLocallyManager::instance()->folderSyncFinishedConnections.insert(_localFilePath,
syncFinishedConnection); syncFinishedConnection);
} }
void EditLocallyHandler::folderSyncFinished(const OCC::SyncResult &result) void EditLocallyJob::folderSyncFinished(const OCC::SyncResult &result)
{ {
Q_UNUSED(result) Q_UNUSED(result)
disconnectSyncFinished(); disconnectSyncFinished();
openFile(); openFile();
} }
void EditLocallyHandler::disconnectSyncFinished() const void EditLocallyJob::disconnectSyncFinished() const
{ {
if(_localFilePath.isEmpty()) { if(_localFilePath.isEmpty()) {
return; return;
@ -300,10 +300,10 @@ void EditLocallyHandler::disconnectSyncFinished() const
} }
} }
void EditLocallyHandler::openFile() void EditLocallyJob::openFile()
{ {
if(_localFilePath.isEmpty()) { if(_localFilePath.isEmpty()) {
qCWarning(lcEditLocallyHandler) << "Could not edit locally. Invalid local file path."; qCWarning(lcEditLocallyJob) << "Could not edit locally. Invalid local file path.";
return; return;
} }

View file

@ -20,21 +20,21 @@
namespace OCC { namespace OCC {
class EditLocallyHandler; class EditLocallyJob;
using EditLocallyHandlerPtr = QSharedPointer<EditLocallyHandler>; using EditLocallyJobPtr = QSharedPointer<EditLocallyJob>;
class Folder; class Folder;
class SyncResult; class SyncResult;
class EditLocallyHandler : public QObject class EditLocallyJob : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit EditLocallyHandler(const QString &userId, explicit EditLocallyJob(const QString &userId,
const QString &relPath, const QString &relPath,
const QString &token, const QString &token,
QObject *parent = nullptr); QObject *parent = nullptr);
[[nodiscard]] static bool isTokenValid(const QString &token); [[nodiscard]] static bool isTokenValid(const QString &token);
[[nodiscard]] static bool isRelPathValid(const QString &relPath); [[nodiscard]] static bool isRelPathValid(const QString &relPath);

View file

@ -17,8 +17,6 @@
#include <QUrl> #include <QUrl>
#include <QLoggingCategory> #include <QLoggingCategory>
#include "editlocallyhandler.h"
namespace OCC { namespace OCC {
Q_LOGGING_CATEGORY(lcEditLocallyManager, "nextcloud.gui.editlocallymanager", QtInfoMsg) Q_LOGGING_CATEGORY(lcEditLocallyManager, "nextcloud.gui.editlocallymanager", QtInfoMsg)
@ -41,7 +39,7 @@ EditLocallyManager *EditLocallyManager::instance()
void EditLocallyManager::editLocally(const QUrl &url) void EditLocallyManager::editLocally(const QUrl &url)
{ {
const auto inputs = parseEditLocallyUrl(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) EditLocallyManager::EditLocallyInputData EditLocallyManager::parseEditLocallyUrl(const QUrl &url)
@ -69,25 +67,25 @@ EditLocallyManager::EditLocallyInputData EditLocallyManager::parseEditLocallyUrl
return {userId, fileRemotePath, token}; return {userId, fileRemotePath, token};
} }
void EditLocallyManager::createHandler(const QString &userId, void EditLocallyManager::createJob(const QString &userId,
const QString &relPath, const QString &relPath,
const QString &token) const QString &token)
{ {
const EditLocallyHandlerPtr handler(new EditLocallyHandler(userId, relPath, token)); const EditLocallyJobPtr job(new EditLocallyJob(userId, relPath, token));
// We need to make sure the handler sticks around until it is finished // We need to make sure the job sticks around until it is finished
_handlers.insert(token, handler); _jobs.insert(token, job);
const auto removeHandler = [this, token] { _handlers.remove(token); }; const auto removeJob = [this, token] { _jobs.remove(token); };
const auto setupHandler = [handler] { handler->startEditLocally(); }; const auto setupJob = [job] { job->startEditLocally(); };
connect(handler.data(), &EditLocallyHandler::error, connect(job.data(), &EditLocallyJob::error,
this, removeHandler); this, removeJob);
connect(handler.data(), &EditLocallyHandler::fileOpened, connect(job.data(), &EditLocallyJob::fileOpened,
this, removeHandler); this, removeJob);
connect(handler.data(), &EditLocallyHandler::setupFinished, connect(job.data(), &EditLocallyJob::setupFinished,
handler.data(), setupHandler); job.data(), setupJob);
handler->startSetup(); job->startSetup();
} }
} }

View file

@ -17,7 +17,7 @@
#include <QObject> #include <QObject>
#include <QHash> #include <QHash>
#include "editlocallyhandler.h" #include "editlocallyjob.h"
namespace OCC { namespace OCC {
@ -34,9 +34,9 @@ public slots:
void editLocally(const QUrl &url); void editLocally(const QUrl &url);
private slots: private slots:
void createHandler(const QString &userId, void createJob(const QString &userId,
const QString &relPath, const QString &relPath,
const QString &token); const QString &token);
private: private:
explicit EditLocallyManager(QObject *parent = nullptr); explicit EditLocallyManager(QObject *parent = nullptr);
@ -50,7 +50,7 @@ private:
[[nodiscard]] static EditLocallyInputData parseEditLocallyUrl(const QUrl &url); [[nodiscard]] static EditLocallyInputData parseEditLocallyUrl(const QUrl &url);
QHash<QString, EditLocallyHandlerPtr> _handlers; QHash<QString, EditLocallyJobPtr> _jobs;
}; };
} }