-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathmrupath.h
109 lines (82 loc) · 1.96 KB
/
mrupath.h
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
#pragma once
class MRUPath
{
private:
size_t size;
public:
QString mruType;
std::vector<fs::path> paths;
MRUPath(QString type = QString(), size_t sz = 10) :
size(sz)
{
if (type.isEmpty())
mruType = "FileLists";
else
mruType = type;
}
void setType(QString type)
{
mruType = type;
}
MRUPath(const MRUPath&) = delete; // No copying
~MRUPath() = default;
MRUPath& operator = (const MRUPath&) = delete; // No assignment
void readSettings()
{
QSettings settings;
uint count;
paths.clear();
QString keyName(mruType);
keyName += "/NrMRU";
count = settings.value(keyName, 0).toUInt();
for (size_t i = 0; i != count; i++)
{
keyName = QString("%1/MRU%2")
.arg(mruType).arg(i);
fs::path path(settings.value(keyName).toString().toStdU16String());
if (status(path).type() == fs::file_type::regular)
paths.push_back(path);
}
}
/* ------------------------------------------------------------------- */
void saveSettings()
{
QSettings settings;
QString keyName(mruType);
keyName += "/NrMRU";
// Clear all the entries first
settings.remove(mruType);
settings.setValue(keyName, (uint)paths.size());
for (size_t i = 0; i != paths.size(); i++)
{
keyName = QString("%1/MRU%2")
.arg(mruType).arg(i);
//
// Convert the path to a string and save in the settings.
//
settings.setValue(keyName, QString::fromStdU16String(paths[i].generic_u16string()));
}
}
/* ------------------------------------------------------------------- */
void Add(const fs::path & path)
{
//
// Is the supplied path already to be found in the mru
//
auto it = std::find(paths.begin(), paths.end(), path);
//
// If we found the path, delete it from the current location
//
if (it != paths.end())
{
paths.erase(it);
}
//
// Regardless of whether we already found it
// insert it at the front
//
paths.insert(paths.begin(), path);
if (paths.size() > size)
paths.resize(size);
}
};