Try to use FileProviderEditLocallyJob before attempting standard EditLocallyJob in EditLocallyManager

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-05-28 18:37:54 +08:00
parent 9642a03455
commit 5ce3cdc6ea
No known key found for this signature in database
GPG Key ID: C839200C384636B0
2 changed files with 53 additions and 4 deletions

View File

@ -23,6 +23,10 @@
#include "editlocallyverificationjob.h"
#include "systray.h"
#ifdef BUILD_FILE_PROVIDER_MODULE
#include "macOS/fileprovidereditlocallyjob.h"
#endif
namespace OCC {
Q_LOGGING_CATEGORY(lcEditLocallyManager, "nextcloud.gui.editlocallymanager", QtInfoMsg)
@ -121,7 +125,11 @@ void EditLocallyManager::verify(const AccountStatePtr &accountState,
};
const auto startEditLocally = [this, accountState, relPath, token, finishedHandler] {
finishedHandler();
editLocally(accountState, relPath, token);
#ifdef BUILD_FILE_PROVIDER_MODULE
editLocallyFileProvider(accountState, relPath, token);
#else
editLocally(accountState, relPath, token);
#endif
};
const auto verificationJob = EditLocallyVerificationJobPtr(
new EditLocallyVerificationJob(accountState, relPath, token)
@ -135,6 +143,32 @@ void EditLocallyManager::verify(const AccountStatePtr &accountState,
verificationJob->start();
}
#ifdef BUILD_FILE_PROVIDER_MODULE
void EditLocallyManager::editLocallyFileProvider(const AccountStatePtr &accountState,
const QString &relPath,
const QString &token)
{
if (_editLocallyFpJobs.contains(token)) {
return;
}
const auto removeJob = [this, token] { _editLocallyFpJobs.remove(token); };
const auto tryStandardJob = [this, accountState, relPath, token, removeJob] {
removeJob();
editLocally(accountState, relPath, token);
};
const Mac::FileProviderEditLocallyJobPtr job(
new Mac::FileProviderEditLocallyJob(accountState, relPath)
);
// We need to make sure the job sticks around until it is finished
_editLocallyFpJobs.insert(token, job);
connect(job.data(), &Mac::FileProviderEditLocallyJob::error, this, removeJob);
connect(job.data(), &Mac::FileProviderEditLocallyJob::notAvailable, this, tryStandardJob);
connect(job.data(), &Mac::FileProviderEditLocallyJob::finished, this, removeJob);
}
#endif
void EditLocallyManager::editLocally(const AccountStatePtr &accountState,
const QString &relPath,
const QString &token)
@ -143,12 +177,11 @@ void EditLocallyManager::editLocally(const AccountStatePtr &accountState,
return;
}
const auto removeJob = [this, token] { _editLocallyJobs.remove(token); };
const EditLocallyJobPtr job(new EditLocallyJob(accountState, relPath));
// We need to make sure the job sticks around until it is finished
_editLocallyJobs.insert(token, job);
const auto removeJob = [this, token] { _editLocallyJobs.remove(token); };
connect(job.data(), &EditLocallyJob::error, this, removeJob);
connect(job.data(), &EditLocallyJob::finished, this, removeJob);

View File

@ -17,9 +17,14 @@
#include <QObject>
#include <QHash>
#include "config.h"
#include "editlocallyjob.h"
#include "editlocallyverificationjob.h"
#ifdef BUILD_FILE_PROVIDER_MODULE
#include "macOS/fileprovidereditlocallyjob.h"
#endif
namespace OCC {
class EditLocallyManager : public QObject
@ -40,6 +45,13 @@ private slots:
void editLocally(const AccountStatePtr &accountState,
const QString &relPath,
const QString &token);
#ifdef BUILD_FILE_PROVIDER_MODULE
void editLocallyFileProvider(const AccountStatePtr &accountState,
const QString &relPath,
const QString &token);
#endif
private:
explicit EditLocallyManager(QObject *parent = nullptr);
@ -57,6 +69,10 @@ private:
QHash<QString, EditLocallyVerificationJobPtr> _verificationJobs;
QHash<QString, EditLocallyJobPtr> _editLocallyJobs;
#ifdef BUILD_FILE_PROVIDER_MODULE
QHash<QString, Mac::FileProviderEditLocallyJobPtr> _editLocallyFpJobs;
#endif
};
}