google translation can be added to bookmark
[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 /*! \file Bookmarks.h
23 \brief Bookmarks functionality - marking words as favorite, managing marked
24     words, searching in marked words (with cached translations)
25
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 /*! Bookmarks are a way to store words that You think You will need to search
50   for often.
51
52   When You add a bookmark (by clicking on "star" in words list) You add it to
53   a special list with cached translations from all available dictionaries so
54   You can search for them quickly even when You delete corresponding dict.
55   */
56 class Bookmarks : public AccentsNormalizer {
57 public:
58     Bookmarks();
59     ~Bookmarks();
60
61     /*! Adds new word and translation to bookmarks
62       \param translation new translation to be saved and cached as a bookmark
63     */
64     void add(Translation* translation);
65
66     void add(QString key,QString removeAccentKey,QString value);
67
68     /*! Removes word and corresponding translation cache from bookmarks list
69         \param translation translation to be removed
70     */
71     void remove(Translation* translation);
72
73     /*! \return all bookmarks (word and translation as a translation object
74      as a list)
75      */
76     QList<Translation*> list();
77
78     /*! Searches in bookmarks for a given word (wildcards may apply '*' and '?')
79       \param word word to search for
80       \return list of matching Translation objects
81       */
82     QList<Translation*> searchWordList(QString word);
83
84     /*! Searches for final translation of a given word
85       \return word translation list in text format xml to be formatted
86         and displayed
87       \param word word to search for
88       */
89     QStringList search(QString word, QString dbname);
90
91
92     /*! Clears bookmarks database */
93     void clear();
94
95
96     /*! \return true if a given word is already in bookmarks
97       \param word word to check
98       */
99     bool inBookmarks(QString word);
100
101 private:
102     bool checkAndCreateDb(QString dbName = "");
103
104     
105     QString dbName;
106     QSqlDatabase getDbCnx();
107     QMap<QChar, QRegExp> letters;
108     QRegExp noLetter;
109     QSqlDatabase mdb;
110
111 };
112
113 #endif // BOOKMARKS_H