-
Notifications
You must be signed in to change notification settings - Fork 1
/
SmartDirSettings.cpp
124 lines (100 loc) · 3.7 KB
/
SmartDirSettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// Created by septemberhx on 2020/6/4.
//
#include "SmartDirSettings.h"
#include <QSettings>
#include <QDebug>
SmartDirSettings *SmartDirSettings::instance() {
static auto *inst = new SmartDirSettings();
return inst;
}
SmartDirSettings::SmartDirSettings() {
this->_watchedDirPaths << "/home/septemberhx/Downloads" << "/home/septemberhx/Pictures";
this->setDefaultItemSize();
this->setDefaultCountPerPage();
this->setDefaultDirCountPerRow();
this->setDefaultEnableDirList();
this->readSettings();
connect(this, &SmartDirSettings::settingsChanged, this, &SmartDirSettings::saveSettings);
}
const QStringList &SmartDirSettings::watchedDirPaths() const {
return _watchedDirPaths;
}
int SmartDirSettings::getItemSize() const {
return itemSize;
}
void SmartDirSettings::setItemSize(int itemSize) {
SmartDirSettings::itemSize = itemSize;
emit settingsChanged();
}
void SmartDirSettings::setDefaultItemSize() {
this->itemSize = 20;
}
void SmartDirSettings::saveSettings() {
QSettings settings("dde-smart-dir", "smart-dir");
settings.setValue("main/dirs", this->_watchedDirPaths);
settings.setValue("main/size", this->itemSize);
settings.setValue("main/countPerPage", this->countPerPage);
settings.setValue("main/dirCountPerRow", this->dirCountPerRow);
settings.setValue("main/enableDirList", this->enableDirList);
settings.beginGroup("subDirMap");
for (const QString& path : this->enableDirFlagMap.keys()) {
settings.setValue(path, this->enableDirFlagMap[path]);
}
settings.endGroup();
}
void SmartDirSettings::readSettings() {
QSettings settings("dde-smart-dir", "smart-dir");
this->_watchedDirPaths = settings.value("main/dirs", this->watchedDirPaths()).value<QStringList>();
this->itemSize = settings.value("main/size", this->itemSize).toUInt();
this->countPerPage = settings.value("main/countPerPage", this->countPerPage).toUInt();
this->dirCountPerRow = settings.value("main/dirCountPerRow", this->dirCountPerRow).toUInt();
this->enableDirList = settings.value("main/enableDirList", this->enableDirList).toBool();
settings.beginGroup("subDirMap");
for (const QString& path : settings.allKeys()) {
qDebug() << path << settings.value(path).toBool();
this->enableDirFlagMap.insert(QString("/") + path, settings.value(path).toBool());
}
settings.endGroup();
}
void SmartDirSettings::setWatchedDirPaths(const QStringList &watchedDirPaths) {
_watchedDirPaths = watchedDirPaths;
emit settingsChanged();
}
int SmartDirSettings::getCountPerPage() const {
return countPerPage;
}
void SmartDirSettings::setCountPerPage(int countPerPage) {
SmartDirSettings::countPerPage = countPerPage;
emit settingsChanged();
}
void SmartDirSettings::setDefaultCountPerPage() {
this->countPerPage = 5;
}
void SmartDirSettings::setDefaultDirCountPerRow() {
this->dirCountPerRow = 3;
}
int SmartDirSettings::getDirCountPerRow() const {
return dirCountPerRow;
}
void SmartDirSettings::setDirCountPerRow(int dirCountPerRow) {
SmartDirSettings::dirCountPerRow = dirCountPerRow;
emit settingsChanged();
}
void SmartDirSettings::setDefaultEnableDirList() {
this->enableDirList = true;
}
bool SmartDirSettings::isEnableDirList() const {
return enableDirList;
}
void SmartDirSettings::setEnableDirList(bool enableDirList) {
SmartDirSettings::enableDirList = enableDirList;
emit settingsChanged();
}
const QMap<QString, bool> &SmartDirSettings::getEnableDirFlagMap() const {
return enableDirFlagMap;
}
void SmartDirSettings::setEnableDirFlagMap(const QMap<QString, bool> &enableDirFlagMap) {
SmartDirSettings::enableDirFlagMap = enableDirFlagMap;
emit settingsChanged();
}