mirror of
https://github.com/chylex/Nextcloud-Desktop.git
synced 2025-05-11 02:34:10 +02:00
Vfs: Remove VfsDefaults
That just complicated things. It's ok if Vfs is not a fully abstract interface class. The pinstate-in-db methods are instead provided directly on Vfs and VfsSuffix and VfsOff use them to implement pin states. The start() method is simply non-virtual and calls into startImpl() for the plugin-specific startup code.
This commit is contained in:
parent
e9cbe13598
commit
6a977edeee
src
@ -60,17 +60,13 @@ Optional<Vfs::Mode> Vfs::modeFromString(const QString &str)
|
||||
return {};
|
||||
}
|
||||
|
||||
VfsDefaults::VfsDefaults(QObject *parent)
|
||||
: Vfs(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void VfsDefaults::start(const VfsSetupParams ¶ms)
|
||||
void Vfs::start(const VfsSetupParams ¶ms)
|
||||
{
|
||||
_setupParams = params;
|
||||
startImpl(params);
|
||||
}
|
||||
|
||||
bool VfsDefaults::setPinState(const QString &folderPath, PinState state)
|
||||
bool Vfs::setPinStateInDb(const QString &folderPath, PinState state)
|
||||
{
|
||||
auto path = folderPath.toUtf8();
|
||||
_setupParams.journal->internalPinStates().wipeForPathAndBelow(path);
|
||||
@ -78,13 +74,13 @@ bool VfsDefaults::setPinState(const QString &folderPath, PinState state)
|
||||
return true;
|
||||
}
|
||||
|
||||
Optional<PinState> VfsDefaults::pinState(const QString &folderPath)
|
||||
Optional<PinState> Vfs::pinStateInDb(const QString &folderPath)
|
||||
{
|
||||
return _setupParams.journal->internalPinStates().effectiveForPath(folderPath.toUtf8());
|
||||
}
|
||||
|
||||
VfsOff::VfsOff(QObject *parent)
|
||||
: VfsDefaults(parent)
|
||||
: Vfs(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -108,17 +108,15 @@ public:
|
||||
/// For WithSuffix modes: the suffix (including the dot)
|
||||
virtual QString fileSuffix() const = 0;
|
||||
|
||||
/// Access to the parameters the instance was start()ed with.
|
||||
const VfsSetupParams ¶ms() const { return _setupParams; }
|
||||
|
||||
|
||||
/** Initializes interaction with the VFS provider.
|
||||
*
|
||||
* For example, the VFS provider might monitor files to be able to start a file
|
||||
* hydration (download of a file's remote contents) when the user wants to open
|
||||
* it.
|
||||
*
|
||||
* Usually some registration needs to be done with the backend. This function
|
||||
* should take care of it if necessary.
|
||||
* The plugin-specific work is done in startImpl().
|
||||
*/
|
||||
virtual void start(const VfsSetupParams ¶ms) = 0;
|
||||
void start(const VfsSetupParams ¶ms);
|
||||
|
||||
/// Stop interaction with VFS provider. Like when the client application quits.
|
||||
virtual void stop() = 0;
|
||||
@ -221,29 +219,29 @@ signals:
|
||||
void beginHydrating();
|
||||
/// Emitted when the hydration ends
|
||||
void doneHydrating();
|
||||
};
|
||||
|
||||
class OCSYNC_EXPORT VfsDefaults : public Vfs
|
||||
{
|
||||
public:
|
||||
explicit VfsDefaults(QObject* parent = nullptr);
|
||||
|
||||
// stores the params
|
||||
void start(const VfsSetupParams ¶ms) override;
|
||||
|
||||
// use the journal to back the pinstates
|
||||
bool setPinState(const QString &folderPath, PinState state) override;
|
||||
Optional<PinState> pinState(const QString &folderPath) override;
|
||||
|
||||
// access initial setup data
|
||||
const VfsSetupParams ¶ms() const { return _setupParams; }
|
||||
|
||||
protected:
|
||||
/** Setup the plugin for the folder.
|
||||
*
|
||||
* For example, the VFS provider might monitor files to be able to start a file
|
||||
* hydration (download of a file's remote contents) when the user wants to open
|
||||
* it.
|
||||
*
|
||||
* Usually some registration needs to be done with the backend. This function
|
||||
* should take care of it if necessary.
|
||||
*/
|
||||
virtual void startImpl(const VfsSetupParams ¶ms) = 0;
|
||||
|
||||
// Db-backed pin state handling. Derived classes may use it to implement pin states.
|
||||
bool setPinStateInDb(const QString &folderPath, PinState state);
|
||||
Optional<PinState> pinStateInDb(const QString &folderPath);
|
||||
|
||||
// the parameters passed to start()
|
||||
VfsSetupParams _setupParams;
|
||||
};
|
||||
|
||||
/// Implementation of Vfs for Vfs::Off mode - does nothing
|
||||
class OCSYNC_EXPORT VfsOff : public VfsDefaults
|
||||
class OCSYNC_EXPORT VfsOff : public Vfs
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -269,8 +267,16 @@ public:
|
||||
bool isDehydratedPlaceholder(const QString &) override { return false; }
|
||||
bool statTypeVirtualFile(csync_file_stat_t *, void *) override { return false; }
|
||||
|
||||
bool setPinState(const QString &folderPath, PinState state) override
|
||||
{ return setPinStateInDb(folderPath, state); }
|
||||
Optional<PinState> pinState(const QString &folderPath) override
|
||||
{ return pinStateInDb(folderPath); }
|
||||
|
||||
public slots:
|
||||
void fileStatusChanged(const QString &, SyncFileStatus) override {}
|
||||
|
||||
protected:
|
||||
void startImpl(const VfsSetupParams &) override {}
|
||||
};
|
||||
|
||||
/// Check whether the plugin for the mode is available.
|
||||
|
@ -22,7 +22,7 @@
|
||||
namespace OCC {
|
||||
|
||||
VfsSuffix::VfsSuffix(QObject *parent)
|
||||
: VfsDefaults(parent)
|
||||
: Vfs(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
namespace OCC {
|
||||
|
||||
class VfsSuffix : public VfsDefaults
|
||||
class VfsSuffix : public Vfs
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -47,8 +47,16 @@ public:
|
||||
bool isDehydratedPlaceholder(const QString &filePath) override;
|
||||
bool statTypeVirtualFile(csync_file_stat_t *stat, void *stat_data) override;
|
||||
|
||||
bool setPinState(const QString &folderPath, PinState state) override
|
||||
{ return setPinStateInDb(folderPath, state); }
|
||||
Optional<PinState> pinState(const QString &folderPath) override
|
||||
{ return pinStateInDb(folderPath); }
|
||||
|
||||
public slots:
|
||||
void fileStatusChanged(const QString &, SyncFileStatus) override {}
|
||||
|
||||
protected:
|
||||
void startImpl(const VfsSetupParams &) override {}
|
||||
};
|
||||
|
||||
class SuffixVfsPluginFactory : public QObject, public DefaultPluginFactory<VfsSuffix>
|
||||
|
Loading…
Reference in New Issue
Block a user