Merge branch 'bookmarks' of ssh://drop.maemo.org/git/mdictionary into bookmarks
[mdictionary] / trunk / src / base / backbone / Bookmarks.cpp
index 788d60c..8d68911 100644 (file)
@@ -17,7 +17,7 @@ bool Bookmarks::checkAndCreateDb() {
         return false;
     }
     QSqlQuery cur(db);
-    cur.exec("create table bookmarks(word text ,translation text)");
+    cur.exec("create table bookmarks(key text ,translation text)");
 
     return true;
 }
@@ -65,32 +65,40 @@ QList<Translation*> Bookmarks::list() {
 
 
 QList<Translation*> Bookmarks::searchWordList(QString word) {
-    if(word.indexOf("*")==-1 && word.indexOf("?")== 0)
+
+    if(word.indexOf("*")==-1 && word.indexOf("?")== -1)
         word+="%";
     word = word.replace("*", "%");
     word = word.replace("?", "_");
     word = removeAccents(word);
 
     QSqlQuery cur(db);
-    cur.prepare("select key from bookmarks where key=?");
+    cur.prepare("select key from bookmarks where key like ?");
     cur.addBindValue(word);
     cur.exec();
-    QList<Translation*> res;
+    QSet<QString> res;
     while(cur.next())
-        res.append(new BookmarkTranslation(cur.value(0).toString(), this));
-    return res;
+        res.insert(cur.value(0).toString());
+    qDebug() << "searchWordList " << res.size();
+    QList<Translation*> tr;
+    foreach(QString str, res.toList())
+        tr.append(new BookmarkTranslation(str, this));
+    return tr;
 }
 
 
 
 QStringList Bookmarks::search(QString word) {
+    qDebug() << "bookmarks::search";
     QSqlQuery cur(db);
     QStringList result;
-    cur.prepare("select translation from bookmarks where word=?");
+    cur.prepare("select translation from bookmarks where key=?");
     cur.addBindValue(word);
     cur.exec();
     while(cur.next())
         result << cur.value(0).toString();
+
+    qDebug() << result.size() << " " << result;
     return result;
 }
 
@@ -116,7 +124,7 @@ QString Bookmarks::removeAccents(QString string) {
 
 bool Bookmarks::inBookmarks(QString word) {
     QSqlQuery cur(db);
-    cur.prepare("select translation from bookmarks where word=? limit 1");
+    cur.prepare("select translation from bookmarks where key like ? limit 1");
     cur.addBindValue(word);
     cur.exec();
     if(cur.next())