Q_LOGGING_CATEGORY(lcEditLocallyJob, "nextcloud.gui.editlocallyjob", QtInfoMsg)
-EditLocallyJob::EditLocallyJob(const QString &userId,
- const QString &relPath,
- const QString &token,
- QObject *parent)
+EditLocallyJob::EditLocallyJob(const AccountStatePtr &accountState,
+ const QString &relPath,
+ const QString &token,
+ QObject *parent)
: QObject{parent}
- , _userId(userId)
+ , _accountState(accountState)
, _relPath(relPath)
, _token(token)
{
void EditLocallyJob::startSetup()
{
- if (_token.isEmpty() || _relPath.isEmpty() || _userId.isEmpty()) {
+ if (_token.isEmpty() || _relPath.isEmpty() || !_accountState) {
qCWarning(lcEditLocallyJob) << "Could not start setup."
<< "token:" << _token
<< "relPath:" << _relPath
- << "userId" << _userId;
+ << "accountState:" << _accountState;
showError(tr("Could not start editing locally."), tr("An error occurred during setup."));
return;
}
// verified the token
Systray::instance()->createEditFileLocallyLoadingDialog({});
- _accountState = AccountManager::instance()->accountFromUserId(_userId);
-
// We now ask the server to verify the token, before we again modify any
// state or look at local files
startCheck();
}
_fileName = relPathSplit.last();
- _folderForFile = findFolderForFile(_relPath, _userId);
+ _folderForFile = findFolderForFile(_relPath, _accountState->account()->userIdAtHostWithPort());
if (!_folderForFile) {
showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath);
void EditLocallyJob::findAfolderAndConstructPaths()
{
- _folderForFile = findFolderForFile(_relPath, _userId);
+ _folderForFile = findFolderForFile(_relPath, _accountState->account()->userIdAtHostWithPort());
if (!_folderForFile) {
showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath);
}
const auto folderMap = FolderMan::instance()->map();
-
const auto relPathSplit = relPath.split(QLatin1Char('/'));
// a file is on the first level of remote root, so, we just need a proper folder that points to a remote root
if (relPathSplit.size() == 1) {
- const auto foundIt = std::find_if(std::begin(folderMap), std::end(folderMap), [&userId](const OCC::Folder *folder) {
- return folder->remotePath() == QStringLiteral("/") && folder->accountState()->account()->userIdAtHostWithPort() == userId;
+ const auto foundIt = std::find_if(std::begin(folderMap),
+ std::end(folderMap),
+ [&userId](const OCC::Folder *folder) {
+ const auto folderUserId = folder->accountState()->account()->userIdAtHostWithPort();
+ return folder->remotePath() == QStringLiteral("/") && folderUserId == userId;
});
return foundIt != std::end(folderMap) ? foundIt.value() : nullptr;
}
- const auto relPathWithSlash = relPath.startsWith(QStringLiteral("/")) ? relPath : QStringLiteral("/") + relPath;
+ const auto relPathWithSlash =
+ relPath.startsWith(QStringLiteral("/")) ? relPath : QStringLiteral("/") + relPath;
for (const auto &folder : folderMap) {
// make sure we properly handle folders with non-root(nested) remote paths
#include <QUrlQuery>
#include <QLoggingCategory>
+#include "accountmanager.h"
+
namespace OCC {
Q_LOGGING_CATEGORY(lcEditLocallyManager, "nextcloud.gui.editlocallymanager", QtInfoMsg)
void EditLocallyManager::editLocally(const QUrl &url)
{
const auto inputs = parseEditLocallyUrl(url);
- createJob(inputs.userId, inputs.relPath, inputs.token);
+ const auto accountState = AccountManager::instance()->accountFromUserId(inputs.userId);
+ createJob(accountState, inputs.relPath, inputs.token);
}
EditLocallyManager::EditLocallyInputData EditLocallyManager::parseEditLocallyUrl(const QUrl &url)
return {userId, fileRemotePath, token};
}
-void EditLocallyManager::createJob(const QString &userId,
const QString &relPath,
const QString &token)
+void EditLocallyManager::createJob(const AccountStatePtr &accountState,
{
if (_jobs.contains(token)) {
return;
}
- const EditLocallyJobPtr job(new EditLocallyJob(userId, relPath, token));
+ const EditLocallyJobPtr job(new EditLocallyJob(accountState, relPath, token));
// We need to make sure the job sticks around until it is finished
_jobs.insert(token, job);