This repository was archived by the owner on Dec 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatConfig.cpp
More file actions
204 lines (189 loc) · 5 KB
/
Copy pathCatConfig.cpp
File metadata and controls
204 lines (189 loc) · 5 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "CatConfig.h"
//============================================================================
CategoryConfig::CategoryConfig()
{
CheckStorage();
BuildList();
}
//============================================================================
void CategoryConfig::CheckStorage()
{
QString dirHome("sMemo");
QString dirCat1("Personal");
QString dirCat2("Business");
QString dirCat3("Unfiled");
QString dirCat4("All");
QString fileCat(QDir::homeDirPath()+"/sMemo/categories");
QDir pd1 = QDir::home();
if (!pd1.exists(QString(dirHome), FALSE))
{
if (!pd1.mkdir(dirHome, FALSE))
{
QMessageBox::critical(0, "sMemo", QString("Can't create directory: \n"+dirHome));
exit(1);
}
if (!pd1.cd(dirHome, FALSE))
{
QMessageBox::critical(0, "sMemo", QString("Can't change directory: \n"+dirHome));
exit(1);
}
if (!pd1.mkdir(dirCat1, FALSE))
{
QMessageBox::critical(0, "sMemo", QString("Can't create category: \n"+dirCat1));
exit(1);
}
if (!pd1.mkdir(dirCat2, FALSE))
{
QMessageBox::critical(0, "sMemo", QString("Can't create category: \n"+dirCat2));
exit(1);
}
if (!pd1.mkdir(dirCat3, FALSE))
{
QMessageBox::critical(0, "sMemo", QString("Can't create category: \n"+dirCat3));
exit(1);
}
if (!pd1.mkdir(dirCat4, FALSE))
{
QMessageBox::critical(0, "sMemo", QString("Can't create category: \n"+dirCat4));
exit(1);
}
QFile file(fileCat);
if(!file.open(IO_WriteOnly))
{
QString message = "Could not write category file!";
QMessageBox::warning(0, "File i/o error", message);
}
else
{
QTextStream outStream(&file);
outStream << (dirCat1+"\n").utf8();
outStream << dirCat1+"\n";
outStream << (dirCat2+"\n").utf8();
outStream << dirCat2+"\n";
file.close();
}
}
}
//============================================================================
void CategoryConfig::BuildList()
{
QFile catFile(QDir::homeDirPath()+"/sMemo/categories");
QDir catDir = QDir::home();
categories.clear();
folders.clear();
categories << "All";
folders << "All";
if (catFile.open(IO_ReadOnly))
{
QTextStream txt(&catFile);
while (!txt.eof())
{
categories << QString::fromUtf8(txt.readLine());
folders << txt.readLine();
}
catFile.close();
}
else
{
QString message = "Could not read category file!";
QMessageBox::warning(0, "File i/o error", message);
}
categories << "Unfiled";
folders << "Unfiled";
}
//============================================================================
void CategoryConfig::BuildCategoryCombo(QComboBox *list, bool withAll)
{
unsigned int i;
list->clear();
if (withAll==TRUE)
{
for(i=0; i<categories.count(); i++)
{
list->insertItem(categories[i]);
}
}
else
{
for(i=1; i<categories.count(); i++)
{
list->insertItem(categories[i]);
}
}
}
//============================================================================
void CategoryConfig::BuildCategoryListBox(QListBox *list, bool withAllUnfiled)
{
unsigned int i;
list->clear();
if (withAllUnfiled==TRUE)
{
for(i=0; i<categories.count(); i++)
{
list->insertItem(categories[i]);
}
}
else
{
for(i=1; i<categories.count()-1; i++)
{
list->insertItem(categories[i]);
}
}
}
//============================================================================
void CategoryConfig::AddCategory(QString category, QString folder)
{
QString fileCat(QDir::homeDirPath()+"/sMemo/categories");
QFile file(fileCat);
if(!file.open(IO_WriteOnly | IO_Append))
{
QString message = "Could not write category file!";
QMessageBox::warning(0, "File i/o error", message);
}
else
{
QTextStream outStream(&file);
outStream << (category+"\n").utf8();
outStream << folder+"\n";
file.close();
}
}
//============================================================================
void CategoryConfig::RenameCategory(int index, QString newName, bool withAllUnfiled)
{
if (withAllUnfiled==FALSE)
index++;
categories[index] = newName;
WriteCategories();
}
//============================================================================
void CategoryConfig::DeleteCategory(unsigned int index)
{
//index++; // May be better to use withAllUnfiled!
categories.remove(categories.at(index));
folders.remove(folders.at(index));
WriteCategories();
}
//============================================================================
void CategoryConfig::WriteCategories()
{
unsigned int i;
QString fileCat(QDir::homeDirPath()+"/sMemo/categories");
QFile file(fileCat);
if(!file.open(IO_WriteOnly))
{
QString message = "Could not write category file!";
QMessageBox::warning(0, "File i/o error", message);
}
else
{
QTextStream outStream(&file);
for(i=1; i<categories.count()-1; i++)
{
outStream << (categories[i]+"\n").utf8();
outStream << folders[i]+"\n";
}
file.close();
}
}