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

Draft: Rename stop and unregisterFolder methods #9252

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/common/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ class OCSYNC_EXPORT Vfs : public QObject
*/
void start(const VfsSetupParams &params);

/// Stop interaction with VFS provider. Like when the client application quits.
virtual void stop() = 0;
/// Stop interaction with VFS provider, because the client is going to quit.
virtual void stopForExit() = 0;

/// Deregister the folder with the sync provider, like when a folder is removed.
virtual void unregisterFolder() = 0;
/// Stop and deregister the folder with the sync provider, like when a folder is removed.
virtual void stopAndUnregisterFolder() = 0;


/** Whether the socket api should show pin state options
Expand Down Expand Up @@ -285,8 +285,8 @@ class OCSYNC_EXPORT VfsOff : public Vfs

QString fileSuffix() const override { return QString(); }

void stop() override {}
void unregisterFolder() override {}
void stopForExit() override { }
void stopAndUnregisterFolder() override { }

bool socketApiPinStateActionsShown() const override { return false; }
bool isHydrating() const override { return false; }
Expand Down
2 changes: 1 addition & 1 deletion src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ void AccountSettings::slotFolderWizardAccepted()

#ifdef Q_OS_WIN
if (folderMan->navigationPaneHelper().showInExplorerNavigationPane())
definition.navigationPaneClsid = QUuid::createUuid();
definition.isInNavigationPane = true;
#endif

auto selectiveSyncBlackList = folderWizard->property("selectiveSyncBlackList").toStringList();
Expand Down
121 changes: 73 additions & 48 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ namespace {
* 1\Folders\4\version=2
* 1\FoldersWithPlaceholders\3\version=3
*/
auto versionC()
{
return QStringLiteral("version");
}

constexpr int WinVfsSettingsVersion = 4;
constexpr int SettingsVersion = 2;
}
const QLatin1String versionC("version");

constexpr int SettingsVersion = 5;

// Settings keys:
const QLatin1String localPathC("localPath");
const QLatin1String journalPathC("journalPath");
const QLatin1String targetPathC("targetPath");
const QLatin1String pausedC("paused");
const QLatin1String ignoreHiddenFilesC("ignoreHiddenFiles");
const QLatin1String virtualFilesModeC("virtualFilesMode");
const QLatin1String navigationPaneClsidC("navigationPaneClsid");
const QLatin1String uuidC("uuid");
const QLatin1String isInNavigationPaneC("isInNavigationPane");
const QLatin1String usePlaceholdersC("usePlaceholders");
} // anonymous namespace

namespace OCC {

Expand Down Expand Up @@ -167,8 +175,9 @@ Folder::Folder(const FolderDefinition &definition,
Folder::~Folder()
{
// If wipeForRemoval() was called the vfs has already shut down.
if (_vfs)
_vfs->stop();
if (_vfs) {
_vfs->stopForExit();
}

// Reset then engine first as it will abort and try to access members of the Folder
_engine.reset();
Expand Down Expand Up @@ -701,8 +710,7 @@ void Folder::setVirtualFilesEnabled(bool enabled)
// TODO: Must wait for current sync to finish!
SyncEngine::wipeVirtualFiles(path(), _journal, *_vfs);

_vfs->stop();
_vfs->unregisterFolder();
_vfs->stopAndUnregisterFolder();

disconnect(_vfs.data(), nullptr, this, nullptr);
disconnect(&_engine->syncFileStatusTracker(), nullptr, _vfs.data(), nullptr);
Expand Down Expand Up @@ -844,8 +852,7 @@ void Folder::wipeForRemoval()
QFile::remove(stateDbFile + "-wal");
QFile::remove(stateDbFile + "-journal");

_vfs->stop();
_vfs->unregisterFolder();
_vfs->stopAndUnregisterFolder();
_vfs.reset(nullptr); // warning: folder now in an invalid state
}

Expand Down Expand Up @@ -1306,60 +1313,78 @@ void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction dir, std::functio

void FolderDefinition::save(QSettings &settings, const FolderDefinition &folder)
{
settings.setValue(QLatin1String("localPath"), folder.localPath);
settings.setValue(QLatin1String("journalPath"), folder.journalPath);
settings.setValue(QLatin1String("targetPath"), folder.targetPath);
settings.setValue(QLatin1String("paused"), folder.paused);
settings.setValue(QLatin1String("ignoreHiddenFiles"), folder.ignoreHiddenFiles);
settings.setValue(localPathC, folder.localPath);
settings.setValue(journalPathC, folder.journalPath);
settings.setValue(targetPathC, folder.targetPath);
settings.setValue(pausedC, folder.paused);
settings.setValue(ignoreHiddenFilesC, folder.ignoreHiddenFiles);
settings.setValue(uuidC, folder.uuid);
settings.setValue(virtualFilesModeC, Vfs::modeToString(folder.virtualFilesMode));

settings.setValue(QStringLiteral("virtualFilesMode"), Vfs::modeToString(folder.virtualFilesMode));
Q_ASSERT(SettingsVersion <= maxSettingsVersion());
settings.setValue(versionC, SettingsVersion);

// Ensure new vfs modes won't be attempted by older clients
const int version = folder.virtualFilesMode == Vfs::WindowsCfApi ? WinVfsSettingsVersion : SettingsVersion;
Q_ASSERT(version <= maxSettingsVersion());
settings.setValue(versionC(), version);
if (settings.contains(navigationPaneClsidC)) {
// Migrate old navigationPaneClsid to new uuid
settings.remove(navigationPaneClsidC);
}

// Happens only on Windows when the explorer integration is enabled.
if (!folder.navigationPaneClsid.isNull())
settings.setValue(QLatin1String("navigationPaneClsid"), folder.navigationPaneClsid);
else
settings.remove(QLatin1String("navigationPaneClsid"));
if (folder.isInNavigationPane) {
settings.setValue(isInNavigationPaneC, true);
} else {
settings.remove(isInNavigationPaneC);
}
}

bool FolderDefinition::load(QSettings &settings, const QString &alias,
FolderDefinition *folder)
{
folder->alias = FolderMan::unescapeAlias(alias);
folder->localPath = settings.value(QLatin1String("localPath")).toString();
folder->journalPath = settings.value(QLatin1String("journalPath")).toString();
folder->targetPath = settings.value(QLatin1String("targetPath")).toString();
folder->paused = settings.value(QLatin1String("paused")).toBool();
folder->ignoreHiddenFiles = settings.value(QLatin1String("ignoreHiddenFiles"), QVariant(true)).toBool();
folder->navigationPaneClsid = settings.value(QLatin1String("navigationPaneClsid")).toUuid();
FolderDefinition FolderDefinition::load(const QSettings &settings, const QString &alias)
{
FolderDefinition folder;
folder.alias = FolderMan::unescapeAlias(alias);
folder.localPath = settings.value(localPathC).toString();
folder.journalPath = settings.value(journalPathC).toString();
folder.targetPath = settings.value(targetPathC).toString();
folder.paused = settings.value(pausedC).toBool();
folder.ignoreHiddenFiles = settings.value(ignoreHiddenFilesC, QVariant(true)).toBool();
folder.isInNavigationPane = settings.value(isInNavigationPaneC, QVariant(true)).toBool();

if (settings.contains(uuidC)) {
folder.uuid = settings.value(uuidC).toUuid();
} else if (settings.contains(navigationPaneClsidC)) {
// For backwards compatibility, will be changed when saved:
folder.uuid = settings.value(navigationPaneClsidC).toUuid();
if (!folder.isInNavigationPane) {
folder.isInNavigationPane = true;
}
}

folder->virtualFilesMode = Vfs::Off;
QString vfsModeString = settings.value(QStringLiteral("virtualFilesMode")).toString();
// Sanity check:
if (folder.uuid.isNull()) {
folder.uuid = QUuid::createUuid();
}

folder.virtualFilesMode = Vfs::Off;
QString vfsModeString = settings.value(virtualFilesModeC).toString();
if (!vfsModeString.isEmpty()) {
if (auto mode = Vfs::modeFromString(vfsModeString)) {
folder->virtualFilesMode = *mode;
folder.virtualFilesMode = *mode;
} else {
qCWarning(lcFolder) << "Unknown virtualFilesMode:" << vfsModeString << "assuming 'off'";
}
} else {
if (settings.value(QLatin1String("usePlaceholders")).toBool()) {
folder->virtualFilesMode = Vfs::WithSuffix;
folder->upgradeVfsMode = true; // maybe winvfs is available?
if (settings.value(usePlaceholdersC).toBool()) {
folder.virtualFilesMode = Vfs::WithSuffix;
folder.upgradeVfsMode = true; // maybe winvfs is available?
}
}

// Old settings can contain paths with native separators. In the rest of the
// code we assume /, so clean it up now.
folder->localPath = prepareLocalPath(folder->localPath);
folder.localPath = prepareLocalPath(folder.localPath);

// Target paths also have a convention
folder->targetPath = prepareTargetPath(folder->targetPath);
folder.targetPath = prepareTargetPath(folder.targetPath);

return true;
return folder;
}

QString FolderDefinition::prepareLocalPath(const QString &path)
Expand Down
34 changes: 27 additions & 7 deletions src/gui/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ class FolderDefinition
bool ignoreHiddenFiles;
/// Which virtual files setting the folder uses
Vfs::Mode virtualFilesMode = Vfs::Off;
/// The CLSID where this folder appears in registry for the Explorer navigation pane entry.
QUuid navigationPaneClsid;

/// The (always valid) UUID for the folder. This can be overwritten when read from the settings.
QUuid uuid = QUuid::createUuid();

/// Is shown in Windows Explorer navigation pane
bool isInNavigationPane = false;

/// Whether the vfs mode shall silently be updated if possible
bool upgradeVfsMode = false;
Expand All @@ -81,8 +85,7 @@ class FolderDefinition
static void save(QSettings &settings, const FolderDefinition &folder);

/// Reads a folder definition from the current settings group.
static bool load(QSettings &settings, const QString &alias,
FolderDefinition *folder);
static FolderDefinition load(const QSettings &settings, const QString &alias);

/** The highest version in the settings that load() can read
*
Expand All @@ -91,8 +94,9 @@ class FolderDefinition
* (version remains readable by 2.5.1)
* Version 3: introduction of new windows vfs mode in 2.6.0
* Version 4: until 2.9.1 windows vfs tried to unregister folders with a different id from windows.
* Version 5: renamed navigationPaneClsid to uuid in the settings for FolderDefinition
*/
static int maxSettingsVersion() { return 4; }
static int maxSettingsVersion() { return 5; }

/// Ensure / as separator and trailing /.
static QString prepareLocalPath(const QString &path);
Expand Down Expand Up @@ -163,8 +167,24 @@ class Folder : public QObject
*/
QString remotePathTrailingSlash() const;

void setNavigationPaneClsid(const QUuid &clsid) { _definition.navigationPaneClsid = clsid; }
QUuid navigationPaneClsid() const { return _definition.navigationPaneClsid; }
/**
* UUID for the folder
*/
QUuid uuid() const { return _definition.uuid; }

/**
* Currently only used on Windows.
*
* @return true is the folder is shown in the Windows Explorer navigation pane, false otherwise
*/
bool isInNavigationPane() const { return _definition.isInNavigationPane; }

/**
* Currently only used on Windows.
*
* @param yesno true is the folder shold be shown in the Windows Explorer navigation pane, false otherwise
*/
void setIsInNavigationPane(bool yesno) { _definition.isInNavigationPane = yesno; }

/**
* remote folder path with server url
Expand Down
Loading