mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Initialise file provider socket controller by requesting file provder domain data over socket from FileProviderExtension
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
9f2fff3782
commit
969ee489e5
@ -41,7 +41,7 @@ class FileProviderDomainManager::Private {
|
||||
void addFileProviderDomain(const AccountState *accountState)
|
||||
{
|
||||
const QString accountDisplayName = accountState->account()->displayName();
|
||||
const QString accountId = accountState->account()->id();
|
||||
const QString accountId = accountState->account()->userIdAtHostWithPort();
|
||||
|
||||
qCDebug(lcMacFileProviderDomainManager) << "Adding new file provider domain for account with id: " << accountId;
|
||||
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
#include "accountmanager.h"
|
||||
|
||||
namespace OCC {
|
||||
|
||||
namespace Mac {
|
||||
@ -53,10 +55,53 @@ void FileProviderSocketController::slotReadyRead()
|
||||
Q_ASSERT(_socket);
|
||||
while(_socket->canReadLine()) {
|
||||
const QString line = QString::fromUtf8(_socket->readLine().trimmed()).normalized(QString::NormalizationForm_C);
|
||||
Q_UNUSED(line);
|
||||
qCDebug(lcFileProviderSocketController) << "Received message in file provider socket:" << line;
|
||||
|
||||
parseReceivedLine(line);
|
||||
}
|
||||
}
|
||||
|
||||
void FileProviderSocketController::parseReceivedLine(const QString &receivedLine)
|
||||
{
|
||||
if (receivedLine.isEmpty()) {
|
||||
qCWarning(lcFileProviderSocketController) << "Received empty line, can't parse.";
|
||||
return;
|
||||
}
|
||||
|
||||
const auto argPos = receivedLine.indexOf(QLatin1Char(':'));
|
||||
if (argPos == -1) {
|
||||
qCWarning(lcFileProviderSocketController) << "Received line:"
|
||||
<< receivedLine
|
||||
<< "is incorrectly structured. Can't parse.";
|
||||
return;
|
||||
}
|
||||
|
||||
const auto command = receivedLine.mid(0, argPos);
|
||||
const auto argument = receivedLine.mid(argPos + 1);
|
||||
|
||||
if (command == QStringLiteral("FILE_PROVIDER_DOMAIN_IDENTIFIER_REQUEST_REPLY")) {
|
||||
_accountState = accountStateFromFileProviderDomainIdentifier(argument);
|
||||
return;
|
||||
}
|
||||
|
||||
qCWarning(lcFileProviderSocketController) << "Unknown command or reply:" << receivedLine;
|
||||
}
|
||||
|
||||
AccountStatePtr FileProviderSocketController::accountStateFromFileProviderDomainIdentifier(const QString &domainIdentifier)
|
||||
{
|
||||
Q_ASSERT(!domainIdentifier.isEmpty());
|
||||
|
||||
// We use Account's userIdAtHostWithPort() as the file provider domain's identifier in FileProviderDomainManager.
|
||||
// We can use this string to get a matching account here.
|
||||
const auto accountForReceivedDomainIdentifier = AccountManager::instance()->accountFromUserId(domainIdentifier);
|
||||
if (!accountForReceivedDomainIdentifier) {
|
||||
qCWarning(lcFileProviderSocketController) << "Could not find account matching user id matching file provider domain identifier:"
|
||||
<< domainIdentifier;
|
||||
}
|
||||
|
||||
return accountForReceivedDomainIdentifier;
|
||||
}
|
||||
|
||||
void FileProviderSocketController::sendMessage(const QString &message) const
|
||||
{
|
||||
if (!_socket) {
|
||||
@ -75,6 +120,20 @@ void FileProviderSocketController::sendMessage(const QString &message) const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FileProviderSocketController::start()
|
||||
{
|
||||
Q_ASSERT(_socket);
|
||||
requestFileProviderDomainInfo();
|
||||
}
|
||||
|
||||
void FileProviderSocketController::requestFileProviderDomainInfo() const
|
||||
{
|
||||
Q_ASSERT(_socket);
|
||||
const auto requestMessage = QStringLiteral("SEND_FILE_PROVIDER_DOMAIN_IDENTIFIER");
|
||||
sendMessage(requestMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
#include <QPointer>
|
||||
#include <QLocalSocket>
|
||||
|
||||
#include "accountstate.h"
|
||||
|
||||
namespace OCC {
|
||||
|
||||
namespace Mac {
|
||||
@ -34,14 +36,21 @@ signals:
|
||||
|
||||
public slots:
|
||||
void sendMessage(const QString &message) const;
|
||||
void start();
|
||||
|
||||
private slots:
|
||||
void slotOnDisconnected();
|
||||
void slotSocketDestroyed(QObject *object);
|
||||
void slotReadyRead();
|
||||
|
||||
void parseReceivedLine(const QString &receivedLine);
|
||||
void requestFileProviderDomainInfo() const;
|
||||
|
||||
private:
|
||||
static AccountStatePtr accountStateFromFileProviderDomainIdentifier(const QString &domainIdentifier);
|
||||
|
||||
QPointer<QLocalSocket> _socket;
|
||||
AccountStatePtr _accountState;
|
||||
};
|
||||
|
||||
} // namespace Mac
|
||||
|
||||
@ -66,6 +66,8 @@ void FileProviderSocketServer::slotNewConnection()
|
||||
connect(socketController.data(), &FileProviderSocketController::socketDestroyed,
|
||||
this, &FileProviderSocketServer::slotSocketDestroyed);
|
||||
_socketControllers.insert(socket, socketController);
|
||||
|
||||
socketController->start();
|
||||
}
|
||||
|
||||
void FileProviderSocketServer::slotSocketDestroyed(const QLocalSocket * const socket)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user