-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.cpp
More file actions
74 lines (66 loc) · 1.73 KB
/
data.cpp
File metadata and controls
74 lines (66 loc) · 1.73 KB
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
#include "data.h"
Data::Data(string settingsFileName) {
ifstream in(settingsFileName);
if(in.is_open()) {
string themesListFName;
in >> password >> themesListFName;
in.close();
readThemesList(themesListFName);
for(auto& themeName : themesFileNames) {
readTheme(themeName);
}
} else {
cerr << "Settings file not found." << endl;
exit(0);
}
}
void Data::addTheme(Theme theme) {
themes.push_back(theme);
}
void Data::removeTheme(string themeName) {
for(auto e = themes.begin(); e != themes.end(); e++) {
if((*e).getName("") == themeName) {
themes.erase(e);
return;
}
}
}
bool Data::isValid(string password) const {
if(password == this->password) {
return true;
}
return false;
}
void Data::readThemesList(const string& themesListFName) {
ifstream in(themesListFName);
if(in.is_open()) {
string themeFileName;
while(in >> themeFileName) {
themesFileNames.push_back(themeFileName);
}
}
}
void Data::readTheme(const string &themeName) {
themes.push_back(Theme(themeName));
}
vector<string> Data::getThemesList(string password) const {
if(isValid(password)) {
vector<string> answer;
for(auto theme : themes) {
answer.push_back(theme.getName(""));
}
return answer;
} else {
cout << "Incorrect password" << endl;
return {};
}
}
Theme& Data::getTheme(const string &name) {
for(size_t c = 0; c < themes.size(); c++) {
if(themes[c].getName("") == name) {
return themes[c];
}
}
cerr << "Theme not found: " << name << endl;
return defaultTheme;
}