4 Bookmarks::Bookmarks() {
5 dbName = QDir::homePath() + "/.mdictionary/"
7 db = QSqlDatabase::addDatabase("QSQLITE", "history");
8 db.setDatabaseName(dbName);
13 bool Bookmarks::checkAndCreateDb() {
17 qDebug() << "Database error: " << db.lastError().text() << endl;
21 cur.exec("create table bookmarks(word text ,translation text)");
28 void Bookmarks::clear() {
30 cur.exec("drop table bookmarks");
31 cur.exec("create table bookmarks(word text ,translation text)");
36 void Bookmarks::add(Translation* translation) {
38 cur.prepare("insert into bookmarks values (?,?)");
39 cur.addBindValue(translation->key(), translation->key());
45 void Bookmarks::remove(Translation* translation) {
47 cur.prepare("delete from bookmarks where key=? and translation=?");
48 cur.addBindValue(translation->key(), translation->key());
54 QList<Translation*> Bookmarks::list() {
56 cur.exec("select key from bookmarks");
57 QList<Translation*> res;
59 res.append(new HistoryTranslation(cur.value(0).toString(), this));
65 QList<Translation*> Bookmarks::searchWordList(QString word) {
66 if(word.indexOf("*")==-1 && word.indexOf("?")== 0)
68 word = word.replace("*", "%");
69 word = word.replace("?", "_");
70 word = removeAccents(word);
73 cur.prepare("select key from bookmarks where key=?");
74 cur.addBindValue(word);
76 QList<Translation*> res;
78 res.append(new HistoryTranslation(cur.value(0).toString(), this));
84 QList<Translation*> Bookmarks::search(QString word) {
86 cur.prepare("select translation from bookmarks where word=? limit 1");
87 cur.addBindValue(word);
90 result = cur.value(0).toString();
96 void Bookmarks::clear() {
98 cur.exec("drop table bookmarks");
99 cur.exec("create table bookmarks(word text ,translation text)");
103 QString Bookmarks::removeAccents(QString string) {
104 string = string.replace(QString::fromUtf8("ł"), "l", Qt::CaseInsensitive);
105 QString normalized = string.normalized(QString::NormalizationForm_D);
106 normalized = normalized;
107 for(int i=0; i<normalized.size(); i++) {
108 if( !normalized[i].isLetterOrNumber() &&
109 !normalized[i].isSpace() &&
110 !normalized[i].isDigit() &&
111 normalized[i] != '*' &&
112 normalized[i] != '%') {
113 normalized.remove(i,1);