Skip to content

Commit 564a522

Browse files
committed
Move FolderDefinition to its own class
1 parent 1f15adb commit 564a522

File tree

6 files changed

+268
-216
lines changed

6 files changed

+268
-216
lines changed

src/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ target_sources(OpenCloudGui PRIVATE
3232
commonstrings.cpp
3333
connectionvalidator.cpp
3434
folder.cpp
35+
folderdefinition.cpp
3536
folderman.cpp
3637
folderstatusmodel.cpp
3738
folderwatcher.cpp

src/gui/folder.cpp

Lines changed: 1 addition & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "folderman.h"
3232
#include "folderwatcher.h"
3333
#include "gui/accountsettings.h"
34+
#include "gui/folderdefinition.h"
3435
#include "libsync/graphapi/spacesmanager.h"
3536
#include "localdiscoverytracker.h"
3637
#include "scheduling/syncscheduler.h"
@@ -60,32 +61,6 @@ namespace {
6061
* Either due to _engine->isAnotherSyncNeeded or a sync error
6162
*/
6263
constexpr int retrySyncLimitC = 3;
63-
64-
65-
auto davUrlC()
66-
{
67-
return QStringLiteral("davUrl");
68-
}
69-
70-
auto spaceIdC()
71-
{
72-
return QStringLiteral("spaceId");
73-
}
74-
75-
auto displayNameC()
76-
{
77-
return QLatin1String("displayString");
78-
}
79-
80-
auto deployedC()
81-
{
82-
return QStringLiteral("deployed");
83-
}
84-
85-
auto priorityC()
86-
{
87-
return QStringLiteral("priority");
88-
}
8964
}
9065

9166
namespace OCC {
@@ -1136,89 +1111,6 @@ bool Folder::virtualFilesEnabled() const
11361111
return _definition.virtualFilesMode != Vfs::Off;
11371112
}
11381113

1139-
FolderDefinition::FolderDefinition(const QUrl &davUrl, const QString &spaceId, const QString &displayName)
1140-
: _webDavUrl(davUrl)
1141-
, _spaceId(spaceId)
1142-
, _displayName(displayName)
1143-
{
1144-
}
1145-
1146-
void FolderDefinition::setPriority(uint32_t newPriority)
1147-
{
1148-
_priority = newPriority;
1149-
}
1150-
1151-
QUuid FolderDefinition::accountUUID() const
1152-
{
1153-
return _accountUUID;
1154-
}
1155-
1156-
uint32_t FolderDefinition::priority() const
1157-
{
1158-
return _priority;
1159-
}
1160-
1161-
void FolderDefinition::save(QSettings &settings, const FolderDefinition &folder)
1162-
{
1163-
settings.setValue("accountUUID", folder.accountUUID());
1164-
settings.setValue(QStringLiteral("localPath"), folder.localPath());
1165-
settings.setValue(QStringLiteral("journalPath"), folder.journalPath);
1166-
settings.setValue(spaceIdC(), folder.spaceId());
1167-
settings.setValue(davUrlC(), folder.webDavUrl());
1168-
settings.setValue(displayNameC(), folder.displayName());
1169-
settings.setValue(QStringLiteral("paused"), folder.paused);
1170-
settings.setValue(QStringLiteral("ignoreHiddenFiles"), folder.ignoreHiddenFiles);
1171-
settings.setValue(deployedC(), folder.isDeployed());
1172-
settings.setValue(priorityC(), folder.priority());
1173-
1174-
settings.setValue(QStringLiteral("virtualFilesMode"), Utility::enumToString(folder.virtualFilesMode));
1175-
}
1176-
1177-
FolderDefinition FolderDefinition::load(QSettings &settings)
1178-
{
1179-
FolderDefinition folder{settings.value(davUrlC()).toUrl(), settings.value(spaceIdC()).toString(), settings.value(displayNameC()).toString()};
1180-
1181-
folder._accountUUID = settings.value("accountUUID").toUuid();
1182-
folder.setLocalPath(settings.value(QStringLiteral("localPath")).toString());
1183-
folder.journalPath = settings.value(QStringLiteral("journalPath")).toString();
1184-
folder.paused = settings.value(QStringLiteral("paused")).toBool();
1185-
folder.ignoreHiddenFiles = settings.value(QStringLiteral("ignoreHiddenFiles"), QVariant(true)).toBool();
1186-
folder._deployed = settings.value(deployedC(), false).toBool();
1187-
folder._priority = settings.value(priorityC(), 0).toUInt();
1188-
1189-
folder.virtualFilesMode = Vfs::Off;
1190-
QString vfsModeString = settings.value(QStringLiteral("virtualFilesMode")).toString();
1191-
if (!vfsModeString.isEmpty()) {
1192-
if (auto mode = Vfs::modeFromString(vfsModeString)) {
1193-
folder.virtualFilesMode = *mode;
1194-
} else {
1195-
qCWarning(lcFolder) << "Unknown virtualFilesMode:" << vfsModeString << "assuming 'off'";
1196-
}
1197-
}
1198-
return folder;
1199-
}
1200-
1201-
void FolderDefinition::setLocalPath(const QString &path)
1202-
{
1203-
_localPath = QDir::fromNativeSeparators(path);
1204-
if (!_localPath.endsWith(QLatin1Char('/'))) {
1205-
_localPath.append(QLatin1Char('/'));
1206-
}
1207-
}
1208-
1209-
QString FolderDefinition::absoluteJournalPath() const
1210-
{
1211-
return QDir(localPath()).filePath(journalPath);
1212-
}
1213-
1214-
QString FolderDefinition::displayName() const
1215-
{
1216-
if (_displayName.isEmpty()) {
1217-
return Theme::instance()->appNameGUI();
1218-
}
1219-
return _displayName;
1220-
}
1221-
12221114
bool Folder::groupInSidebar() const
12231115
{
12241116
if (_accountState->account()->hasDefaultSyncRoot()) {
@@ -1231,27 +1123,4 @@ bool Folder::groupInSidebar() const
12311123
return false;
12321124
}
12331125

1234-
bool FolderDefinition::isDeployed() const
1235-
{
1236-
return _deployed;
1237-
}
1238-
1239-
QUrl FolderDefinition::webDavUrl() const
1240-
{
1241-
Q_ASSERT(_webDavUrl.isValid());
1242-
return _webDavUrl;
1243-
}
1244-
1245-
QString FolderDefinition::localPath() const
1246-
{
1247-
return _localPath;
1248-
}
1249-
1250-
QString FolderDefinition::spaceId() const
1251-
{
1252-
// we might call the function to check for the id
1253-
// anyhow one of the conditions needs to be true
1254-
Q_ASSERT(_webDavUrl.isValid() || !_spaceId.isEmpty());
1255-
return _spaceId;
1256-
}
12571126
} // namespace OCC

src/gui/folder.h

Lines changed: 6 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "accountstate.h"
2222
#include "common/syncjournaldb.h"
23+
#include "gui/folderdefinition.h"
2324
#include "libsync/graphapi/space.h"
2425
#include "networkjobs.h"
2526
#include "progressdispatcher.h"
@@ -28,11 +29,9 @@
2829

2930
#include <QDateTime>
3031
#include <QObject>
31-
#include <QUuid>
3232
#include <QtQml/QQmlEngine>
3333

3434
#include <chrono>
35-
#include <memory>
3635
#include <set>
3736

3837
class QThread;
@@ -46,83 +45,6 @@ class SyncRunFileLog;
4645
class FolderWatcher;
4746
class LocalDiscoveryTracker;
4847

49-
/**
50-
* @brief The FolderDefinition class
51-
* @ingroup gui
52-
*/
53-
class OPENCLOUD_GUI_EXPORT FolderDefinition
54-
{
55-
public:
56-
FolderDefinition(const QUrl &davUrl, const QString &spaceId, const QString &displayName = {});
57-
/// path to the journal, usually relative to localPath
58-
QString journalPath;
59-
60-
/// whether the folder is paused
61-
bool paused = false;
62-
/// whether the folder syncs hidden files
63-
bool ignoreHiddenFiles = true;
64-
/// Which virtual files setting the folder uses
65-
Vfs::Mode virtualFilesMode = Vfs::Off;
66-
67-
/// Saves the folder definition into the current settings.
68-
static void save(QSettings &settings, const FolderDefinition &folder);
69-
70-
/// Reads a folder definition from the current settings.
71-
static FolderDefinition load(QSettings &settings);
72-
73-
/// Ensure / as separator and trailing /.
74-
void setLocalPath(const QString &path);
75-
76-
/// journalPath relative to localPath.
77-
QString absoluteJournalPath() const;
78-
79-
QString localPath() const;
80-
81-
QUrl webDavUrl() const;
82-
83-
// could change in the case of spaces
84-
void setWebDavUrl(const QUrl &url) { _webDavUrl = url; }
85-
86-
// when using spaces we don't store the dav URL but the space id
87-
// this id is then used to look up the dav URL
88-
QString spaceId() const;
89-
90-
void setSpaceId(const QString &spaceId) { _spaceId = spaceId; }
91-
92-
QString displayName() const;
93-
94-
/**
95-
* The folder is deployed by an admin
96-
* We will hide the remove option and the disable/enable vfs option.
97-
*/
98-
bool isDeployed() const;
99-
100-
/**
101-
* Higher values mean more imortant
102-
* Used for sorting
103-
*/
104-
uint32_t priority() const;
105-
106-
void setPriority(uint32_t newPriority);
107-
108-
QUuid accountUUID() const;
109-
110-
private:
111-
QUrl _webDavUrl;
112-
113-
QString _spaceId;
114-
QString _displayName;
115-
/// path on local machine (always trailing /)
116-
QString _localPath;
117-
bool _deployed = false;
118-
119-
uint32_t _priority = 0;
120-
121-
QUuid _accountUUID;
122-
123-
friend class FolderMan;
124-
};
125-
12648
/**
12749
* @brief The Folder class
12850
* @ingroup gui
@@ -149,10 +71,6 @@ class OPENCLOUD_GUI_EXPORT Folder : public QObject
14971

15072
static void prepareFolder(const QString &path);
15173

152-
/** Create a new Folder
153-
*/
154-
Folder(const FolderDefinition &definition, const AccountStatePtr &accountState, std::unique_ptr<Vfs> &&vfs, QObject *parent = nullptr);
155-
15674
~Folder() override;
15775
/**
15876
* The account the folder is configured on.
@@ -410,6 +328,11 @@ private Q_SLOTS:
410328
void slotWatcherUnreliable(const QString &message);
411329

412330
private:
331+
/** Create a new Folder
332+
*/
333+
Folder(const FolderDefinition &definition, const AccountStatePtr &accountState, std::unique_ptr<Vfs> &&vfs, QObject *parent = nullptr);
334+
335+
413336
void showSyncResultPopup();
414337

415338
bool checkLocalPath();

0 commit comments

Comments
 (0)