Skip to content

Commit

Permalink
Fix review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Dec 5, 2022
1 parent 28cde1b commit 82c7aee
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 41 deletions.
65 changes: 35 additions & 30 deletions src/gui/editlocallyjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ namespace OCC {
Q_LOGGING_CATEGORY(lcEditLocallyJob, "nextcloud.gui.editlocallyjob", QtInfoMsg)

EditLocallyJob::EditLocallyJob(const QString &userId,
const QString &fullRelPath,
const QString &relPath,
const QString &token,
QObject *parent)
: QObject{parent}
, _userId(userId)
, _relPath(fullRelPath)
, _relPath(relPath)
, _token(token)
{
}
Expand Down Expand Up @@ -118,34 +118,7 @@ void EditLocallyJob::remoteTokenCheckResultReceived(const int statusCode)
return;
}

_folderForFile = findFolderForFile(_relPath, _userId);

if (!_folderForFile) {
showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath);
return;
}

_relativePathToRemoteRoot = getRelativePathToRemoteRootForFile();

if (_relativePathToRemoteRoot.isEmpty()) {
qCWarning(lcEditLocallyJob) << "_relativePathToRemoteRoot is empty for" << _relPath;
showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath);
return;
}

_relPathParent = getRelativePathParent();

if (_relPathParent.isEmpty()) {
showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath);
return;
}

if (_relPathParent == QStringLiteral("/")) {
proceedWithSetup();
return;
}

fetchRemoteFileParentInfo();
findAfolderAndConstructPaths();
}

void EditLocallyJob::proceedWithSetup()
Expand Down Expand Up @@ -182,6 +155,38 @@ void EditLocallyJob::proceedWithSetup()
Q_EMIT setupFinished();
}

void EditLocallyJob::findAfolderAndConstructPaths()
{
_folderForFile = findFolderForFile(_relPath, _userId);

if (!_folderForFile) {
showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath);
return;
}

_relativePathToRemoteRoot = getRelativePathToRemoteRootForFile();

if (_relativePathToRemoteRoot.isEmpty()) {
qCWarning(lcEditLocallyJob) << "_relativePathToRemoteRoot is empty for" << _relPath;
showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath);
return;
}

_relPathParent = getRelativePathParent();

if (_relPathParent.isEmpty()) {
showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath);
return;
}

if (_relPathParent == QStringLiteral("/")) {
proceedWithSetup();
return;
}

fetchRemoteFileParentInfo();
}

QString EditLocallyJob::prefixSlashToPath(const QString &path)
{
return path.startsWith('/') ? path : QChar::fromLatin1('/') + path;
Expand Down
21 changes: 11 additions & 10 deletions src/gui/editlocallyjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <QObject>

#include "accountstate.h"
#include <syncfileitem.h>
#include "syncfileitem.h"

namespace OCC {

Expand All @@ -33,7 +33,7 @@ class EditLocallyJob : public QObject

public:
explicit EditLocallyJob(const QString &userId,
const QString &fullRelPath,
const QString &relPath,
const QString &token,
QObject *parent = nullptr);

Expand All @@ -51,17 +51,14 @@ public slots:
void startSetup();
void startEditLocally();

private:
private slots:
void fetchRemoteFileParentInfo();
bool checkIfFileParentSyncIsNeeded(); // returns true if sync will be needed, false otherwise
void startSyncBeforeOpening();
void eraseBlacklistRecordForItem();
[[nodiscard]] const QString getRelativePathToRemoteRootForFile() const;
[[nodiscard]] const QString getRelativePathParent() const;

private slots:
void startTokenRemoteCheck();
void proceedWithSetup();
void findAfolderAndConstructPaths();

void showError(const QString &message, const QString &informativeText);
void showErrorNotification(const QString &message, const QString &informativeText) const;
Expand All @@ -77,13 +74,17 @@ private slots:
void openFile();

private:
[[nodiscard]] bool checkIfFileParentSyncIsNeeded(); // returns true if sync will be needed, false otherwise
[[nodiscard]] const QString getRelativePathToRemoteRootForFile() const; // returns either '/' or a (relative path - Folder::remotePath()) for folders pointing to a non-root remote path e.g. '/subfolder' instead of '/'
[[nodiscard]] const QString getRelativePathParent() const;

bool _tokenVerified = false;

AccountStatePtr _accountState;
QString _userId;
QString _relPath;
QString _relativePathToRemoteRoot;
QString _relPathParent;
QString _relPath; // full remote path for a file (as on the server)
QString _relativePathToRemoteRoot; // (relative path - Folder::remotePath()) for folders pointing to a non-root remote path e.g. '/subfolder' instead of '/'
QString _relPathParent; // a folder where the file resides ('/' if it is in the first level of a remote root, or e.g. a '/subfolder/a/b/c if it resides in a nested folder)
QString _token;
SyncFileItemPtr _fileParentItem;

Expand Down
2 changes: 1 addition & 1 deletion src/libsync/syncfileitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

#include "syncfileitem.h"
#include <common/checksums.h>
#include "common/checksums.h"
#include "common/syncjournalfilerecord.h"
#include "common/utility.h"
#include "helpers.h"
Expand Down

0 comments on commit 82c7aee

Please sign in to comment.