Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.6] Refactor FolderMan's "Edit Locally" capabilities as separate class #5111

Merged
merged 9 commits into from
Oct 31, 2022
4 changes: 4 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ set(client_SRCS
conflictsolver.cpp
connectionvalidator.h
connectionvalidator.cpp
editlocallyjob.h
editlocallyjob.cpp
editlocallymanager.h
editlocallymanager.cpp
folder.h
folder.cpp
foldercreationdialog.h
Expand Down
15 changes: 15 additions & 0 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,21 @@ AccountStatePtr AccountManager::account(const QString &name)
return it != _accounts.cend() ? *it : AccountStatePtr();
}

AccountStatePtr AccountManager::accountFromUserId(const QString &id) const
{
for (const auto &account : accounts()) {
const auto isUserIdWithPort = id.split(QLatin1Char(':')).size() > 1;
const auto port = isUserIdWithPort ? account->account()->url().port() : -1;
const auto portString = (port > 0 && port != 80 && port != 443) ? QStringLiteral(":%1").arg(port) : QStringLiteral("");
const QString davUserId = QStringLiteral("%1@%2").arg(account->account()->davUser(), account->account()->url().host()) + portString;

if (davUserId == id) {
return account;
}
}
return {};
}

AccountState *AccountManager::addAccount(const AccountPtr &newAccount)
{
auto id = newAccount->id();
Expand Down
6 changes: 6 additions & 0 deletions src/gui/accountmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class AccountManager : public QObject
*/
AccountStatePtr account(const QString &name);

/**
* Return the account state pointer for an account from its id
*/

[[nodiscard]] AccountStatePtr accountFromUserId(const QString &id) const;

/**
* Delete the AccountState
*/
Expand Down
29 changes: 3 additions & 26 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "config.h"
#include "account.h"
#include "accountstate.h"
#include "editlocallymanager.h"
#include "connectionvalidator.h"
#include "folder.h"
#include "folderman.h"
Expand Down Expand Up @@ -749,34 +750,10 @@ void Application::handleEditLocallyFromOptions()
return;
}

handleEditLocally(_editFileLocallyUrl);
EditLocallyManager::instance()->editLocally(_editFileLocallyUrl);
_editFileLocallyUrl.clear();
}

void Application::handleEditLocally(const QUrl &url) const
{
auto pathSplit = url.path().split('/', Qt::SkipEmptyParts);

if (pathSplit.size() < 2) {
qCWarning(lcApplication) << "Invalid URL for file local editing: " + pathSplit.join('/');
return;
}

// for a sample URL "nc://open/admin@nextcloud.lan:8080/Photos/lovely.jpg", QUrl::path would return "admin@nextcloud.lan:8080/Photos/lovely.jpg"
const auto userId = pathSplit.takeFirst();
const auto fileRemotePath = pathSplit.join('/');
const auto urlQuery = QUrlQuery{url};

auto token = QString{};
if (urlQuery.hasQueryItem(QStringLiteral("token"))) {
token = urlQuery.queryItemValue(QStringLiteral("token"));
} else {
qCWarning(lcApplication) << "Invalid URL for file local editing: missing token";
}

FolderMan::instance()->editFileLocally(userId, fileRemotePath, token);
}

QString substLang(const QString &lang)
{
// Map the more appropriate script codes
Expand Down Expand Up @@ -917,7 +894,7 @@ bool Application::event(QEvent *event)
// On macOS, Qt does not handle receiving a custom URI as it does on other systems (as an application argument).
// Instead, it sends out a QFileOpenEvent. We therefore need custom handling for our URI handling on macOS.
qCInfo(lcApplication) << "macOS: Opening local file for editing: " << openEvent->url();
handleEditLocally(openEvent->url());
EditLocallyManager::instance()->editLocally(openEvent->url());
} else {
const auto errorParsingLocalFileEditingUrl = QStringLiteral("The supplied url for local file editing '%1' is invalid!").arg(openEvent->url().toString());
qCInfo(lcApplication) << errorParsingLocalFileEditingUrl;
Expand Down
2 changes: 0 additions & 2 deletions src/gui/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public slots:
/// Attempt to show() the tray icon again. Used if no systray was available initially.
void tryTrayAgain();

void handleEditLocally(const QUrl &url) const;

protected:
void parseOptions(const QStringList &);
void setupTranslations();
Expand Down
Loading