Fixed sigsev after searching in bookmarks
[mdictionary] / trunk / src / base / 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 (witch 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 "../../includes/settings.h"
44 #include "../../includes/translation.h"
45 class BookmarkTranslation;
46
47
48 /*! Bookmarks are way to store words that You think You will need to search
49   for often.
50
51   When You add bookmark (by clickin on "star" in words list) You adds it to
52   special list with cached translations from all available dictionaries so
53   You can search for them quickly even when You delete coresponding dict.
54   */
55 class Bookmarks
56 {
57 public:
58     Bookmarks();
59
60     /*! Adds new word and translation to bookmarks
61       \param translation new translation to be saved and cached as a bookmark
62     */
63     void add(Translation* translation);
64
65     /*! Removes word and coresponding translation cache from bookmark list
66         \param translation translation to be removed
67     */
68     void remove(Translation* translation);
69
70     /*! \return all bookmarks (word and translation as a translation object
71      as a list
72      */
73     QList<Translation*> list();
74
75     /*! search in bookmarks for given word (wildcards may apply '*' and '?')
76       \param word to search for
77       \return list of matching Translation objects
78       */
79     QList<Translation*> searchWordList(QString word);
80
81     /*! Search for final translation of given word
82       \return word translation list in text format xml or html to be formated
83         and displayed
84       \param word word to search for
85       */
86     QStringList search(QString word, QString dbname);
87
88
89     /*! clars bookmarks database */
90     void clear();
91
92
93     /*! \return true if given word is already in bookmarks
94       \param word to check
95       */
96     bool inBookmarks(QString word);
97
98 private:
99     QString dbName;
100
101     bool checkAndCreateDb();
102     QString removeAccents(QString);
103
104 };
105
106 #endif // BOOKMARKS_H