code clean
[mdictionary] / src / mdictionary / backbone / Bookmarks.h
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     mDictionary is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 /*!
23     \file Bookmarks.h
24     \brief Bookmarks functionality - marking words as favorite, managing marked
25     words, searching in marked words (with cached translations)
26
27     \author Bartosz Szatkowski <bulislaw@linux.com>
28 */
29
30 #ifndef BOOKMARKS_H
31 #define BOOKMARKS_H
32
33 #include <QtSql>
34 #include <QString>
35 #include <QVariant>
36 #include <QStringList>
37 #include <QList>
38 #include <QSqlQuery>
39 #include <QSqlDatabase>
40 #include <QSqlError>
41 #include <QDir>
42 #include <QDebug>
43 #include "../../include/settings.h"
44 #include "../../include/translation.h"
45 #include "../../include/AccentsNormalizer.h"
46 class BookmarkTranslation;
47
48
49 /*!
50     Bookmarks are a way to store words that You think You will need to search
51     for often.
52
53     When You add a bookmark (by clicking on "star" in words list) You add it to
54     a special list with cached translations from all available dictionaries so
55     You can search for them quickly even when You delete corresponding dict.
56 */
57 class Bookmarks : public AccentsNormalizer {
58 public:
59     Bookmarks();
60     ~Bookmarks();
61
62     /*!
63         Adds new word and translation to bookmarks
64         \param translation new translation to be saved and cached as a bookmark
65     */
66     void add(Translation* translation);
67
68     void add(QString key,QString removeAccentKey,QString value);
69
70     /*!
71         Removes word and corresponding translation cache from bookmarks list
72         \param translation translation to be removed
73     */
74     void remove(Translation* translation);
75
76     /*!
77         \return all bookmarks (word and translation as a translation object
78         as a list)
79     */
80     QList<Translation*> list();
81
82     /*!
83         Searches in bookmarks for a given word (wildcards may apply '*' and '?')
84         \param word word to search for
85         \return list of matching Translation objects
86     */
87     QList<Translation*> searchWordList(QString word);
88
89     /*!
90         Searches for final translation of a given word
91         \return word translation list in text format xml to be formatted
92         and displayed
93         \param word word to search for
94     */
95     QStringList search(QString word, QString dbname);
96
97     /*!
98         Clears bookmarks database
99     */
100     void clear();
101
102     /*!
103         \return true if a given word is already in bookmarks
104         \param word word to check
105     */
106     bool inBookmarks(QString word);
107
108 private:
109     bool checkAndCreateDb(QString dbName = "");
110
111     
112     QString dbName;
113     QSqlDatabase getDbCnx();
114     QMap<QChar, QRegExp> letters;
115     QRegExp noLetter;
116     QSqlDatabase mdb;
117
118 };
119
120 #endif // BOOKMARKS_H