-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbcmgr.cpp
402 lines (344 loc) · 10.9 KB
/
bcmgr.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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#include "bcmgr.h"
#include "QDebug"
BCMgr *bcMgr = NULL;
BCMgr::BCMgr(QObject *parent, const QString &userName) :
QObject(parent)
{
bcMgr = this;
PathManage::createRelExeDir("/userdata/" + userName);
PathManage::createRelExeDir("/userdata/" + userName + "/book");
PathManage::createRelExeDir("/userdata/" + userName + "/GoogleTTSVoice");
PathManage::createRelExeDir("/userdata/" + userName + "/RealSpeak");
QString udatadbPath = PathManage::makePathStr("/userdata/" + userName + "/userdata.db");
userConf = new MyConfig(PathManage::makePathStr("/userdata/" + userName + "/%1Config.ini")
.arg(userName));
qDebug() << "udatadbPath: " << udatadbPath;
userdatadb = new UserDataDB(udatadbPath,"UDATADB");
/////////////////////////////////////////////////////////////////////////////
//我的生词本
PathManage::createRelExeDir("/userdata/" + userName + "/我的生词本/");
QString myBookDB = PathManage::makePathStr("/userdata/" + userName + "/我的生词本/我的生词本.db");
qDebug() << "myBookDB: " << myBookDB;
myBook = new CreatWordListDB(myBookDB,"MYBOOk");
//将我的生词本添加到词库列表
bool badd = addNewBook(tr("生词本"),tr("我的生词本"),myBookDB,0);
if(badd == 1)
{
qDebug()<< QString("成功添加我的生词本到词库列表");
}
else
{
qDebug()<< QString("添加我的生词本到词库列表失败");
}
//////////////////////////////////////////////////////////////////////
//AnsleDict
PathManage::createRelExeDir("/AnsleDict/MyDict/");
PathManage::createRelExeDir("/AnsleDict/MyDict/Dict/");
}
BCMgr::~BCMgr()
{
qDebug() << QString("删除用户配置指针userConf");
delete userConf;
userConf = NULL;
qDebug() << QString("删除数据库UDATADB");
delete userdatadb;
userdatadb = NULL;
qDebug() << QString("删除数据库MYBOOk");
delete myBook;
myBook = NULL;
}
QSqlDatabase *BCMgr::getUserBookdb()
{
return userdatadb->getUserDatadb();
}
QString BCMgr::getUserName()
{
return userdatadb->getUserName();
}
QStringList BCMgr::getBookClasses()
{
return userdatadb->getBookClasses();
}
QString BCMgr::getBookClasse(const QString &bookpath)
{
return userdatadb->getBookClasse(bookpath);
}
QStringList BCMgr::getBookNames()
{
return userdatadb->getBookNames();
}
QStringList BCMgr::getBookNames(const QString &bookclass)
{
return userdatadb->getBookNames(bookclass);
}
QString BCMgr::getBookName(const QString &bookpath)
{
return userdatadb->getBookName(bookpath);
}
QStringList BCMgr::getBookPaths()
{
return userdatadb->getBookPaths();
}
QString BCMgr::getBookPaths(const QString &bookclass, const QString &bookname)
{
return userdatadb->getBookPaths(bookclass,bookname);
}
int BCMgr::getTotalNumb(const QString &bookclass, const QString &bookname)
{
return userdatadb->getTotalNumb(bookclass,bookname);
}
int BCMgr::getCount()
{
return userdatadb->getCount();
}
int BCMgr::getHaveLearnedNum(const QString &bookclass, const QString &bookname)
{
return userdatadb->getHaveLearnedNum(bookclass,bookname);
}
int BCMgr::getHaveLearnedNum(const QString &bookpath)
{
return userdatadb->getHaveLearnedNum(bookpath);
}
int BCMgr::getLearnState(const QString &bookclass, const QString &bookname)
{
return userdatadb->getLearnState(bookclass,bookname);
}
int BCMgr::getLearnState(const QString &bookpath)
{
return userdatadb->getLearnState(bookpath);
}
bool BCMgr::addNewBook(const QString &bookclass, const QString &bookname,
const QString &bookpath, int totalnum)
{
QString userName = Global::Conf->getCurrentUser();
return userdatadb->addNewBook(userName,bookclass,bookname,bookpath,totalnum);
}
void BCMgr::deleteBook(const QString &bookclass, const QString &bookname)
{
userdatadb->deleteBook(bookclass,bookname);
}
void BCMgr::addRootItem(QTreeWidget *parent, const QString &strings)
{
QList<QTreeWidgetItem *>index = parent->findItems(strings,0,0);
bool i = index.isEmpty();
if(i == true)
{
QTreeWidgetItem *root = new QTreeWidgetItem(QStringList(strings));
root->setIcon(0,QIcon("./rc/document_open.png"));
parent->addTopLevelItem(root);
}
else
{
index.at(0)->setSelected(true);
index.at(0)->setExpanded(true);
}
}
void BCMgr::addChildItem(QTreeWidget *parent, const QString &strings)
{
QTreeWidgetItem *item = parent->currentItem();
if(item->parent() == NULL)
{
QTreeWidgetItem *child = new QTreeWidgetItem(QStringList(strings));
child->setIcon(0,QIcon("./rc/book2.png"));
item->addChild(child);
item->setExpanded(true);
}
else
{
QTreeWidgetItem *rootItem = item->parent();
QTreeWidgetItem *child = new QTreeWidgetItem(QStringList(strings));
child->setIcon(0,QIcon("./rc/book2.png"));
rootItem->addChild(child);
rootItem->setExpanded(true);
}
}
void BCMgr::addChildItem(QTreeWidget *parent, const QString &string, const QString &strings)
{
QList<QTreeWidgetItem *>index = parent->findItems(string,0,0);
bool i = index.isEmpty();
if(i == true)
{
QTreeWidgetItem *root = new QTreeWidgetItem(parent,QStringList(string));
root->setIcon(0,QIcon("./rc/document_open.png"));
QTreeWidgetItem *child = new QTreeWidgetItem(QStringList(strings));
child->setIcon(0,QIcon("./rc/book2.png"));
root->addChild(child);
root->setExpanded(true);
}
else
{
QTreeWidgetItem* childItem = new QTreeWidgetItem(QStringList(strings));
childItem->setIcon(0,QIcon("./rc/book2.png"));
int childCount = index.at(0)->childCount();
int isEqual = 0;
for(int i=0; i<childCount; i++)
{
QString childText = index.at(0)->child(i)->text(0);
if(childText != strings)
{
isEqual++;
}
}
if(isEqual == childCount)
{
index.at(0)->addChild(childItem);
index.at(0)->setExpanded(true);
}
}
}
void BCMgr::removeRootItem(QTreeWidget *parent, const QString &strings, int column)
{
QList<QTreeWidgetItem *>index = parent->findItems(strings,0,column);
bool i = index.isEmpty();
if(i == false)
{
int inx = parent->indexOfTopLevelItem(index.at(0));
parent->takeTopLevelItem(inx);
int childCount = index.at(0)->childCount();//子节点数
for (int i=0;i<childCount;i++)
{
QTreeWidgetItem* item = parent ->currentItem();
item = index.at(0)->child(0);
delete item;
item=NULL;
}
}
index.clear();
}
void BCMgr::removeRootItem(QTreeWidget *parent)
{
QTreeWidgetItem* item = parent->currentItem();
if(item->parent() == NULL)
{
int inx = parent->indexOfTopLevelItem(item);
int childCount = item->childCount();//子节点数
for (int i=0; i<childCount; i++)
{
QTreeWidgetItem* newItem = parent ->currentItem();
newItem = item->child(0);
delete newItem;
newItem=NULL;
}
parent->takeTopLevelItem(inx);
}
delete item;
}
void BCMgr::removeChildItem(QTreeWidget *parent)
{
QTreeWidgetItem* item = parent->currentItem();
if(item->parent() != NULL)
{
item->removeChild(item);
}
delete item;
}
void BCMgr::removeChildItemByRow(QTreeWidget *parent, int row)
{
QTreeWidgetItem* item = parent->currentItem();
if(item->parent() == NULL)
{
item->removeChild(item->child(row));
}
}
void BCMgr::editItem(QTreeWidget *parent, const QString &strings)
{
QTreeWidgetItem* item = parent->currentItem();
item->setText(0,strings);
}
bool BCMgr::updateBookName(QTreeWidget *parent,const QString &bookclass, const QString &bookname,
const QString &newbookname)
{
if(userdatadb->setBookName(bookclass,bookname,newbookname))
{
editItem(parent,newbookname);
return true;
}
else
{
return false;
}
}
bool BCMgr::updateBookClass(QTreeWidget *parent,const QString &bookclass, const QString &newbookclass)
{
if(userdatadb->setBookClass(bookclass,newbookclass))
{
editItem(parent,newbookclass);
return true;
}
else
{
return false;
}
}
bool BCMgr::updateTotalNumb(const QString &bookclass, const QString &bookname, int totalNumb)
{
return userdatadb->setTotalNumb(bookclass,bookname,totalNumb);
}
bool BCMgr::updateTotalNumb(const QString &bookpath, const int totalnumb)
{
return userdatadb->setTotalNumb(bookpath,totalnumb);
}
bool BCMgr::updateHaveLearnedNum(const QString &bookclass,
const QString &bookname,
const int havelearned)
{
return userdatadb->setHaveLearnedNum(bookclass,bookname,havelearned);
}
bool BCMgr::updateHaveLearnedNum(const QString &bookpath, const int havelearned)
{
return userdatadb->setHaveLearnedNum(bookpath,havelearned);
}
bool BCMgr::updateLearnState(const QString &bookclass, const QString &bookname, bool learnstate)
{
return userdatadb->setLearnState(bookclass,bookname,learnstate);
}
bool BCMgr::updateLearnState(const QString &bookpath, bool learnstate)
{
return userdatadb->setLearnState(bookpath,learnstate);
}
bool BCMgr::existsDayRecord(const QString &bookpath, const QString &daytime)
{
return userdatadb->existsDayRecord(bookpath,daytime);
}
bool BCMgr::addNewBookStudyRecord(const QString &bookpath, const QString &daytime,
const int &learncount, const int &reviewcount)
{
return userdatadb->addNewBookStudyRecord(bookpath,daytime,
learncount,reviewcount);
}
int BCMgr::getDayLearnRecord(const QString &bookpath, const QString &daytime)
{
return userdatadb->getDayLearnRecord(bookpath,daytime);
}
int BCMgr::getDayReviewRecord(const QString &bookpath, const QString &daytime)
{
return userdatadb->getDayReviewRecord(bookpath,daytime);
}
bool BCMgr::updateLearnRecord(const QString &bookpath, const QString &daytime,
const int &learncount)
{
return userdatadb->updateLearnRecord(bookpath,daytime,
learncount);
}
bool BCMgr::updateReviewRecord(const QString &bookpath, const QString &daytime,
const int &reviewcount)
{
return userdatadb->updateReviewRecord(bookpath,daytime,
reviewcount);
}
void BCMgr::showBookList(QTreeWidget *parent)
{
parent->clear();
QStringList bookClassList;
QStringList bookNameList;
bookClassList = getBookClasses();
bookNameList = getBookNames();
for(int i = 0; i<bookClassList.size(); i++)
{
addChildItem(parent,bookClassList.at(i),bookNameList.at(i));
}
}
QSqlTableModel *BCMgr::userDataDBModel(QWidget *parent)
{
return userdatadb->userDataDBModel(parent);
}