Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 18 Aug 2010 13:37:07 +0000 (15:37 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 18 Aug 2010 13:37:07 +0000 (15:37 +0200)
39 files changed:
data/mdictionary.defaults
mdictionary.pro
trunk/src/base/backbone/BookmarkTranslations.h [new file with mode: 0644]
trunk/src/base/backbone/Bookmarks.cpp [new file with mode: 0644]
trunk/src/base/backbone/Bookmarks.h [new file with mode: 0644]
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/src/base/base.pro
trunk/src/base/gui/AboutWidget.cpp [new file with mode: 0644]
trunk/src/base/gui/AboutWidget.h [new file with mode: 0644]
trunk/src/base/gui/BookmarksWidget.cpp [new file with mode: 0644]
trunk/src/base/gui/BookmarksWidget.h [new file with mode: 0644]
trunk/src/base/gui/DictManagerWidget.cpp
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/MainWindow.h
trunk/src/base/gui/MenuTabWidget.cpp
trunk/src/base/gui/MenuWidget.cpp
trunk/src/base/gui/MenuWidget.h
trunk/src/base/gui/SearchBarWidget.cpp
trunk/src/base/gui/SearchBarWidget.h
trunk/src/base/gui/SettingsWidget.cpp [new file with mode: 0644]
trunk/src/base/gui/SettingsWidget.h [new file with mode: 0644]
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/gui/TranslationWidget.h
trunk/src/base/gui/WelcomeScreenWidget.cpp [new file with mode: 0644]
trunk/src/base/gui/WelcomeScreenWidget.h [new file with mode: 0644]
trunk/src/base/gui/WordListProxyStyle.cpp [new file with mode: 0644]
trunk/src/base/gui/WordListProxyStyle.h [new file with mode: 0644]
trunk/src/base/gui/WordListWidget.cpp
trunk/src/base/gui/WordListWidget.h
trunk/src/base/gui/gui.qrc [new file with mode: 0644]
trunk/src/base/gui/mdictionary.png [new file with mode: 0755]
trunk/src/base/gui/staroff.png [new file with mode: 0644]
trunk/src/base/gui/staron.png [new file with mode: 0644]
trunk/src/includes/GUIInterface.h
trunk/src/includes/translation.h
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/tests/mDictionaryTests/mDictionaryTests.pro
trunk/trunk.pro

index 83f046e..ca7c907 100644 (file)
@@ -1,6 +1,6 @@
 [%General]
 plugin_path=/usr/lib/mdictionary
-history_length=10
+history_size=10
 search_limit=15
 
 [dictionary_0]
index c54e852..912067e 100644 (file)
@@ -4,7 +4,7 @@ isEmpty( ISQT4 ) {
 error("Use the qmake include with Qt4.4 or greater, on Debian that is qmake-qt4");
 }
 
-
+QT += sql
 TEMPLATE = subdirs
 SUBDIRS  = trunk
 
diff --git a/trunk/src/base/backbone/BookmarkTranslations.h b/trunk/src/base/backbone/BookmarkTranslations.h
new file mode 100644 (file)
index 0000000..29ff21e
--- /dev/null
@@ -0,0 +1,93 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! /file BookmarkTranslation.h
+\brief Bookmarks functionality needs its own translation  object - becouse
+    Translation object should use slighty different api of Bookmarks objects
+
+\author Bartosz Szatkowski <bulislaw@linux.com>
+*/
+#ifndef BOOKMARKTRANSLATIONS_H
+#define BOOKMARKTRANSLATIONS_H
+
+#include "../../includes/settings.h"
+#include "../../includes/translation.h"
+#include "Bookmarks.h"
+
+
+
+class BookmarkTranslation : public Translation
+{
+public:
+    BookmarkTranslation(QString key, Bookmarks* bookmarks, QString dbName) {
+        _key = key;
+        _dictionaryInfo = dbName;
+        _bookmarks = bookmarks;
+        _bookmark = 1;
+    }
+
+    //! \return word to be translated
+    QString key() const {
+        return _key;
+    }
+
+    /*! \returns dictionary information (plugin name, languages, <logo> etc)\
+        to be displayed in translation table header*/
+    QString dictionaryInfo() const {
+        return _dictionaryInfo;
+    }
+
+    //! \return parsed raw format into html
+    QString toHtml() const {
+        if(!_key.size() || !_bookmarks)
+            return "";
+        qDebug() << ">toHtml";
+
+        QStringList list = _bookmarks->search(_key, _dictionaryInfo);
+        qDebug() << "toHtml" << list.size();
+        QString result;
+        foreach(QString translation, list)
+            result += translation + "\n";
+        qDebug() << "<toHtml";
+        return result;
+
+    }
+
+    /*! sets the word for which we want to find a translation
+        \param word for which we want to find a translation */
+    void setKey(QString key) {
+        _key = key;
+    };
+
+    //! sets information about dictionary
+    void setDictionaryInfo(QString dictionaryInfo) {
+        _dictionaryInfo = dictionaryInfo;
+    }
+
+
+private:
+    QString _key;
+    QString _dictionaryInfo;
+    Bookmarks* _bookmarks;
+
+};
+
+#endif // HISTORYTRANSLATION_H
diff --git a/trunk/src/base/backbone/Bookmarks.cpp b/trunk/src/base/backbone/Bookmarks.cpp
new file mode 100644 (file)
index 0000000..2f20ea9
--- /dev/null
@@ -0,0 +1,177 @@
+#include "Bookmarks.h"
+#include "BookmarkTranslations.h"
+#include <QThread>
+
+Bookmarks::Bookmarks() {
+    this->dbName = QDir::homePath() + "/.mdictionary/"
+                 + "bookmarks.db";
+    checkAndCreateDb();
+}
+
+
+QSqlDatabase Bookmarks::getDbCnx(QString dbName) {
+    QSqlDatabase db =QSqlDatabase::addDatabase("QSQLITE",
+            QString("%2").arg((int)QThread::currentThreadId()));
+    db.setDatabaseName(dbName);
+    return db;
+}
+
+bool Bookmarks::checkAndCreateDb() {
+    QSqlDatabase db = getDbCnx(dbName);
+    if(!db.isOpen() && !db.open()) {
+        qDebug() << "Database error: " << db.lastError().text() << endl;
+        return false;
+    }
+    QSqlQuery cur(db);
+    cur.exec("create table bookmarks(key text ,translation text)");
+    db.close();
+
+    return true;
+}
+
+
+
+void Bookmarks::clear() {
+    QSqlDatabase db = getDbCnx(dbName);
+    if(!db.isOpen() && !db.open()) {
+        qDebug() << "Database error: " << db.lastError().text() << endl;
+        return ;
+    }
+    QSqlQuery cur(db);
+    cur.exec("drop table bookmarks");
+    cur.exec("create table bookmarks(key text ,translation text)");
+    db.close();
+}
+
+
+
+void Bookmarks::add(Translation* translation) {
+    QSqlDatabase db = getDbCnx(dbName);
+    if(!db.isOpen() && !db.open()) {
+        qDebug() << "Database error: " << db.lastError().text() << endl;
+        return ;
+    }
+    QSqlQuery cur(db);
+    cur.prepare("insert into bookmarks values (?,?)");
+    cur.addBindValue(translation->key());
+    cur.addBindValue(translation->toHtml());
+    cur.exec();
+    db.close();
+}
+
+
+
+void Bookmarks::remove(Translation* translation) {
+    QSqlDatabase db = getDbCnx(dbName);
+    if(!db.isOpen() && !db.open()) {
+        qDebug() << "Database error: " << db.lastError().text() << endl;
+        return ;
+    }
+    QSqlQuery cur(db);
+    cur.prepare("delete from bookmarks where key=?");
+    cur.addBindValue(translation->key());
+    cur.exec();
+    db.close();
+}
+
+
+
+QList<Translation*> Bookmarks::list() {
+    QList<Translation*> res;
+    QSqlDatabase db = getDbCnx(dbName);
+    if(!db.isOpen() && !db.open()) {
+        qDebug() << "Database error: " << db.lastError().text() << endl;
+        return res;
+    }
+    QSqlQuery cur(db);
+    cur.exec("select distinct key from bookmarks");
+    while(cur.next())
+        res.append(new BookmarkTranslation(cur.value(0).toString(), this, dbName));
+    db.close();
+    return res;
+}
+
+
+
+QList<Translation*> Bookmarks::searchWordList(QString word) {
+
+    if(word.indexOf("*")==-1 && word.indexOf("?")== -1)
+        word+="%";
+    word = word.replace("*", "%");
+    word = word.replace("?", "_");
+    word = removeAccents(word);
+
+    QList<Translation*> tr;
+    QSqlDatabase db = getDbCnx(dbName);
+    if(!db.isOpen() && !db.open()) {
+        qDebug() << "Database error: " << db.lastError().text() << endl;
+        return tr;
+    }
+    QSqlQuery cur(db);
+    cur.prepare("select key from bookmarks where key like ?");
+    cur.addBindValue(word);
+    cur.exec();
+    QSet<QString> res;
+    while(cur.next())
+        res.insert(cur.value(0).toString());
+    foreach(QString str, res.toList())
+        tr.append(new BookmarkTranslation(str, this, dbName));
+    db.close();
+    return tr;
+}
+
+
+
+QStringList Bookmarks::search(QString word, QString dbName) {
+    QStringList result;
+    QSqlDatabase db = getDbCnx(dbName);
+    if(!db.isOpen() && !db.open()) {
+        qDebug() << "Database error: " << db.lastError().text() << endl;
+        return result;
+    }
+    QSqlQuery cur(db);
+    cur.prepare("select translation from bookmarks where key=?");
+    cur.addBindValue(word);
+    cur.exec();
+    while(cur.next())
+        result << cur.value(0).toString();
+
+    db.close();
+    return result;
+}
+
+
+
+QString Bookmarks::removeAccents(QString string) {
+    string = string.replace(QString::fromUtf8("ł"), "l", Qt::CaseInsensitive);
+    QString normalized = string.normalized(QString::NormalizationForm_D);
+    normalized = normalized;
+    for(int i=0; i<normalized.size(); i++) {
+        if( !normalized[i].isLetterOrNumber() &&
+            !normalized[i].isSpace() &&
+            !normalized[i].isDigit() &&
+            normalized[i] != '*' &&
+            normalized[i] != '%') {
+            normalized.remove(i,1);
+        }
+    }
+    return normalized;
+}
+
+
+
+bool Bookmarks::inBookmarks(QString word) {
+    QSqlDatabase db = getDbCnx(dbName);
+    if(!db.isOpen() && !db.open()) {
+        qDebug() << "Database error: " << db.lastError().text() << endl;
+        return false;
+    }
+    QSqlQuery cur(db);
+    cur.prepare("select translation from bookmarks where key like ? limit 1");
+    cur.addBindValue(word);
+    cur.exec();
+    if(cur.next())
+        return true;
+    db.close();
+    return false;
+}
diff --git a/trunk/src/base/backbone/Bookmarks.h b/trunk/src/base/backbone/Bookmarks.h
new file mode 100644 (file)
index 0000000..3726415
--- /dev/null
@@ -0,0 +1,107 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! /file Bookmarks.h
+\brief Bookmarks functionality - marking words as favorite, managing marked
+    words, searching in marked words (witch cached translations)
+
+
+\author Bartosz Szatkowski <bulislaw@linux.com>
+*/
+
+#ifndef BOOKMARKS_H
+#define BOOKMARKS_H
+
+#include <QtSql>
+#include <QString>
+#include <QVariant>
+#include <QStringList>
+#include <QList>
+#include <QSqlQuery>
+#include <QSqlDatabase>
+#include <QSqlError>
+#include <QDir>
+#include <QDebug>
+#include "../../includes/settings.h"
+#include "../../includes/translation.h"
+class BookmarkTranslation;
+
+
+/*! Bookmarks are way to store words that You think You will need to search
+  for often.
+
+  When You add bookmark (by clickin on "star" in words list) You adds it to
+  special list with cached translations from all available dictionaries so
+  You can search for them quickly even when You delete coresponding dict.
+  */
+class Bookmarks
+{
+public:
+    Bookmarks();
+
+    /*! Adds new word and translation to bookmarks
+      \param translation new translation to be saved and cached as a bookmark
+    */
+    void add(Translation* translation);
+
+    /*! Removes word and coresponding translation cache from bookmark list
+        \param translation translation to be removed
+    */
+    void remove(Translation* translation);
+
+    /*! \return all bookmarks (word and translation as a translation object
+     as a list
+     */
+    QList<Translation*> list();
+
+    /*! search in bookmarks for given word (wildcards may apply '*' and '?')
+      \param word to search for
+      \return list of matching Translation objects
+      */
+    QList<Translation*> searchWordList(QString word);
+
+    /*! Search for final translation of given word
+      \return word translation list in text format xml or html to be formated
+        and displayed
+      \param word word to search for
+      */
+    QStringList search(QString word, QString dbname);
+
+
+    /*! clars bookmarks database */
+    void clear();
+
+
+    /*! \return true if given word is already in bookmarks
+      \param word to check
+      */
+    bool inBookmarks(QString word);
+
+private:
+    QString dbName;
+
+    bool checkAndCreateDb();
+    QString removeAccents(QString);
+    QSqlDatabase getDbCnx(QString dbName);
+
+};
+
+#endif // BOOKMARKS_H
index 6270791..b353e2c 100644 (file)
@@ -72,6 +72,10 @@ void Backbone::init() {
    connect(&_resultWatcher, SIGNAL(finished()), this, SLOT(translationReady()));
    connect(&_htmlResultWatcher, SIGNAL(finished()), this,
            SLOT(htmlTranslationReady()));
+   connect(&_bookmarkWatcher, SIGNAL(finished()), this,
+           SLOT(bookmarksListReady()));
+   connect(&_bookmarkSearchWatcher, SIGNAL(finished()), this,
+           SLOT(translationReady()));
 
    QThreadPool::globalInstance()->setMaxThreadCount(
            QThreadPool::globalInstance()->maxThreadCount()+1);
@@ -170,14 +174,24 @@ void Backbone::stopSearching() {
 
 
 
-void Backbone::search(QString word) {
+void Backbone::search(QString word){
     _result.clear();
     mappedSearch = word.toLower();
-    //_time.restart();
+
     stopped = false;
+    dictFin = !_searchDicts;
+    bookmarkFin = !_searchBookmarks;
+
+    if (_searchDicts) {
+        _innerResult = QtConcurrent::mapped(activeDicts(), mapSearch);
+        _resultWatcher.setFuture(_innerResult);
+    }
 
-    _innerResult = QtConcurrent::mapped(activeDicts(), mapSearch);
-    _resultWatcher.setFuture(_innerResult);
+    if(_searchBookmarks) {
+        _innerBookmarks = QtConcurrent::run(_bookmarks,
+                &Bookmarks::searchWordList, word);
+        _bookmarkSearchWatcher.setFuture(_innerBookmarks);
+    }
 }
 
 
@@ -222,18 +236,26 @@ void Backbone::addDictionary(CommonDictInterface *dict, bool active) {
 
 
 void Backbone::translationReady() {
-    //if(!_innerResult.isFinished())
-     //   return;
-    QFutureIterator<QList<Translation*> > it(_innerResult);
+    if(!dictFin && _innerResult.isFinished()) {
+        dictFin = 1;
+        QFutureIterator<QList<Translation*> > it(_innerResult);
+
+        while(it.hasNext()) {
+            QList<Translation* > list = it.next();
+            foreach(Translation* trans, list)
+                _result.insert(trans->key().toLower(), trans);
+        }
+    }
+
+    if(!bookmarkFin && _innerBookmarks.isFinished()) {
+        bookmarkFin = 1;
+        QList<Translation*> list = _innerBookmarks.result();
 
-    while(it.hasNext()) {
-        QList<Translation* > list = it.next();
         foreach(Translation* trans, list)
-            _result.insert(trans->key().toLower(), trans);
+                _result.insert(trans->key().toLower(), trans);
     }
 
-    //qDebug () << "time " << _time.elapsed();
-    if(!stopped)
+    if(!stopped && bookmarkFin && dictFin)
         Q_EMIT ready();
 }
 
@@ -295,8 +317,10 @@ void Backbone::loadPrefs(QString fileName) {
     }
     QSettings set(file.filePath(), QSettings::IniFormat);
     _pluginPath = set.value("general/plugin_path", _pluginPath).toString();
-    _historyLen = set.value("general/history_length", 10).toInt();
+    _historyLen = set.value("general/history_size", 10).toInt();
     _searchLimit = set.value("general/search_limit", 15).toInt();
+    _searchBookmarks = set.value("general/search_bookmarks",1).toBool();
+    _searchDicts = set.value("general/search_dictionaries",1).toBool();
 }
 
 
@@ -305,8 +329,10 @@ void Backbone::savePrefs(QSettings *set) {
     if(dryRun)
         return;
     set->setValue("general/plugin_path", _pluginPath);
-    set->setValue("general/history_length", _historyLen);
+    set->setValue("general/history_size", _historyLen);
     set->setValue("general/search_limit", _searchLimit);
+    set->setValue("general/search_bookmarks", _searchBookmarks);
+    set->setValue("general/search_dictionaries", _searchDicts);
 }
 
 
@@ -315,7 +341,7 @@ void Backbone::saveDefaultPrefs(QSettings *set) {
     if(dryRun)
         return;
     set->setValue("general/plugin_path", _defaultPluginPath);
-    set->setValue("general/history_length", _defaultHistoryLen);
+    set->setValue("general/history_size", _defaultHistoryLen);
     set->setValue("general/search_limit", _defaultSearchLimit);
 }
 
@@ -366,6 +392,7 @@ void Backbone::loadDicts(QString fileName, bool _default) {
 void Backbone::dictUpdated() {
     if(dryRun)
         return;
+    _history->setMaxSize(_historyLen);
     QFileInfo file(QDir::toNativeSeparators(_configPath));
     QDir confDir(file.dir());
     if(!confDir.exists())
@@ -418,9 +445,9 @@ QStringList Backbone::htmls() {
 
 void Backbone::searchHtml(QList<Translation *> translations) {
     _htmlResult.clear();
+
     QList<TranslationPtr> dummy;
     stopped = false;
-    //_time.restart();
     foreach(Translation* tr, translations)
         dummy.append(TranslationPtr(tr));
 
@@ -430,14 +457,11 @@ void Backbone::searchHtml(QList<Translation *> translations) {
 }
 
 void Backbone::htmlTranslationReady() {
-    //if(!_innerHtmlResult.isFinished())
-        //return;
 
     QFutureIterator<QString> it(_innerHtmlResult);
     while(it.hasNext())
        _htmlResult.append(it.next());
 
-    //qDebug() << "time " << _time.elapsed();
     if(!stopped)
         Q_EMIT htmlReady();
 
@@ -452,3 +476,46 @@ QList<CommonDictInterface*> Backbone::activeDicts() {
     return res;
 
 }
+
+
+
+void Backbone::bookmarksListReady() {
+   _bookmarksResult = _innerBookmarks.result();
+   Q_EMIT bookmarksReady();
+}
+
+
+
+
+void Backbone::setSettings(Settings *settings) {
+    _historyLen = settings->value("history_size").toInt();
+    _searchLimit = settings->value("search_limit").toInt();
+    if(settings->value("search_dictionaries") == "true")
+        _searchDicts = 1;
+    else
+        _searchDicts = 0;
+    if(settings->value("search_bookmarks") == "true")
+        _searchBookmarks = 1;
+    else
+        _searchBookmarks = 0;
+    dictUpdated();
+}
+
+
+
+
+Settings* Backbone::settings() {
+    Settings * settings = new Settings();
+    settings->setValue("history_size", QString("%1").arg(_historyLen));
+    settings->setValue("search_limit", QString("%1").arg(_searchLimit));
+    if(_searchBookmarks)
+        settings->setValue("search_bookmarks", "true");
+    else
+        settings->setValue("search_bookmarks", "false");
+
+    if(_searchDicts)
+        settings->setValue("search_dictionaries", "true");
+    else
+        settings->setValue("search_dictionaries", "false");
+    return settings;
+}
index 142d729..21cb3df 100644 (file)
@@ -47,6 +47,7 @@
 #include "../../includes/settings.h"
 #include "../../includes/translation.h"
 #include "../../includes/History.h"
+#include "Bookmarks.h"
 
 
 /*! Inner part of dictionary - glues together GUI and plugins
@@ -96,6 +97,8 @@ public Q_SLOTS:
 
     /*! search for a word translation
        \param word to be translated
+       \param dicts searching in dicionaries
+       \param bookmarks searching in bookmarks
       */
     void search(QString word);
 
@@ -138,8 +141,74 @@ public Q_SLOTS:
       */
     void searchHtml(QList<Translation*>);
 
-    // TODO addToBookmark(Translation*);
-    // TODO removeFromBookmark(Translation*);
+
+    /*! add bookmarks to given translations (translation object is fetched and
+      added to bookmarks data base (key and translation stored in db)
+      \param translation translation object  to be stored in db
+      */
+    void addBookmark(QList<Translation*> translations) {
+        foreach(Translation* translation, translations)
+            //_bookmarks.add(translation);
+            QtConcurrent::run(_bookmarks, &Bookmarks::add, translation);
+    }
+
+
+    /*! Remove bookmarks to given translatios
+      \param translation remove bookmark to this translation
+      */
+    void removeBookmark(QList<Translation*> translations) {
+        foreach(Translation* translation, translations)
+            _bookmarks.remove(translation);
+    }
+
+
+
+    /*! Remove all bookmarks
+      */
+    void removeAllBookmark(){
+        _bookmarks.clear();
+    }
+
+
+   /*! Searching for list of bookmarks may take some time, so i moved it to
+       new thread (to avoid gui blocking), when ready bookmarksReady is emited
+       and result is returned after calling getBookmarks()
+       */
+   void fetchBookmarks() {
+        _result.clear();
+
+        stopped = false;
+        dictFin = 1;
+        bookmarkFin = 0;
+
+        if(_searchBookmarks) {
+           _innerBookmarks = QtConcurrent::run(_bookmarks,
+                   &Bookmarks::searchWordList, QString("*"));
+           _bookmarkSearchWatcher.setFuture(_innerBookmarks);
+        }
+   }
+
+   /*! \return list of all bookmarks
+     */
+   QList<Translation*> bookmarks() {
+       return _bookmarksResult;
+   }
+
+
+   /*! Sets settings for backbone: history_size, search_limit,
+       searching backends (search_bookmarks, search_dictionaries)
+       \param settings settings object with opitons set
+       */
+    void setSettings(Settings* settings);
+
+
+    /*! \return coresponding settings object with history_size, search_limit,
+       searching backends (search_bookmarks, search_dictionaries)
+       */
+    Settings* settings();
+
+
+
 
 Q_SIGNALS:
     /*! emmited when backbone is ready to close - after getting stop signal it
@@ -155,41 +224,64 @@ Q_SIGNALS:
     //! throwed when searches are stopped
     void searchCanceled();
 
+    //! emmited when bookmark list is ready to fetch
+    void bookmarksReady();
+
+private Q_SLOTS:
+    void bookmarksListReady();
 
 
 private:
-    QHash<CommonDictInterface*, bool> _dicts;
-    QList<CommonDictInterface*> _plugins;
-    QFuture<QList<Translation*> > _innerResult;
-    QFuture<QString> _innerHtmlResult;
-    QMultiHash<QString, Translation*> _result;
-    QStringList _htmlResult;
-    //QTime _time;
+    QHash<CommonDictInterface*, bool> _dicts; // List of dictionaries
+    QList<CommonDictInterface*> _plugins;  // List of plugins
+
+
+    QFuture<QList<Translation*> > _innerResult; //Res of concurent word search
+    QFuture<QString> _innerHtmlResult;  // Result of html search
+    QFuture<QList<Translation*> > _innerBookmarks; //Res of search in bookmarks
+    QFuture<QList<Translation*> > _innerListBookmarks; //Res of search in bookmarks
+    QFuture<QStringList> _innerHtmlBookmarks; //Html result of bookmarks search
+
+    QMultiHash<QString, Translation*> _result; //Final result of word search
+    QStringList _htmlResult; // Final result of html search
+    QList<Translation*> _bookmarksResult; // Final result of search in bookmarks
+
+
+    // Keeps track of concurent computations
+    QFutureWatcher<QList<Translation*> > _resultWatcher;
+    QFutureWatcher<QList<Translation*> > _bookmarkWatcher;
+    QFutureWatcher<QList<Translation*> > _bookmarkSearchWatcher;
+    QFutureWatcher<QString> _htmlResultWatcher;
+
+
     QString _pluginPath, _defaultPluginPath;
     QString _configPath;
     QString _defaultConfigPath;
-    QFutureWatcher<QList<Translation*> > _resultWatcher;
-    QFutureWatcher<QString> _htmlResultWatcher;
     int _searchLimit, _defaultSearchLimit;
     int _activeSearchNum;
     int _historyLen, _defaultHistoryLen;
     bool dryRun;
     bool stopped;
+    bool bookmarkFin, dictFin; // inform whether givent search type is ready
+    bool _searchDicts, _searchBookmarks;
+    Bookmarks _bookmarks;
 
 
     void init();
+
     QStringList getFilesFromDir(QString dir, QStringList nameFilter);
     void loadPlugins(); //< locate and load plugins
     void loadPrefs(QString fileName);
     void loadDicts(QString fileName, bool _default=false);
+
     void saveState(QSettings*, Settings*, bool, uint);
     void addInternalDictionary(CommonDictInterface*, bool);
     void savePrefs(QSettings*);
     void saveDefaultPrefs(QSettings*);
+
     CommonDictInterface* plugin(QString type); //< search for given type plugin
     QList<CommonDictInterface*> activeDicts();
 
-    //QList<Translation*> mapSearch(CommonDictInterface*) const;
 
     History* _history;
 
index 03bfb66..8d29e8a 100644 (file)
@@ -1,28 +1,17 @@
-#-------------------------------------------------
-#
+# -------------------------------------------------
 # Project created by QtCreator 2010-08-03T08:54:27
-#
-#-------------------------------------------------
-
-QT       += core gui
-
-maemo5 {
-    QT += maemo5
-}
-
+# -------------------------------------------------
+QT += core \
+    gui \
+    sql
+maemo5:QT += maemo5
 TARGET = mdictionary
 TEMPLATE = app
-
 MDICT_BINDIR = $$[MDICT_BINDIR]
-
-isEmpty(MDICT_BINDIR) {
-  MDICT_BINDIR = .
-}
-
+isEmpty(MDICT_BINDIR):MDICT_BINDIR = .
 DESTDIR = $${MDICT_BINDIR}
-
-SOURCES += gui/main.cpp\
-        gui/MainWindow.cpp \
+SOURCES += gui/main.cpp \
+    gui/MainWindow.cpp \
     gui/SearchBarWidget.cpp \
     gui/WordListWidget.cpp \
     gui/TranslationWidget.cpp \
@@ -32,9 +21,16 @@ SOURCES += gui/main.cpp\
     gui/DictManagerWidget.cpp \
     gui/DictTypeSelectDialog.cpp \
     backbone/History.cpp \
-    gui/HistoryListDialog.cpp
+    gui/HistoryListDialog.cpp \
+    gui/WordListProxyStyle.cpp \
+    backbone/Bookmarks.cpp \
+    gui/SettingsWidget.cpp \
+    gui/BookmarksWidget.cpp \
+    gui/WelcomeScreenWidget.cpp \ 
+    gui/AboutWidget.cpp
 
 HEADERS  += gui/MainWindow.h \
+    gui/AboutWidget.h \
     gui/SearchBarWidget.h \
     gui/WordListWidget.h \
     gui/TranslationWidget.h \
@@ -49,38 +45,41 @@ HEADERS  += gui/MainWindow.h \
     gui/TranslationWidgetAutoResizer.h \
     ../includes/History.h \
     gui/HistoryListDialog.h \
-    ../includes/GUIInterface.h
+    ../includes/GUIInterface.h \
+    gui/WordListProxyStyle.h \
+    backbone/Bookmarks.h \
+    backbone/BookmarkTranslations.h \
+    gui/SettingsWidget.h \
+    gui/BookmarksWidget.h \
+    gui/WelcomeScreenWidget.h
 
 FORMS    += gui/MainWindow.ui
-
-unix {
-  #VARIABLES
-  isEmpty(PREFIX) {
-    PREFIX = /usr
-  }
-  BINDIR = $$PREFIX/bin
-  DATADIR =$$PREFIX/share
-
-  DEFINES += DATADIR=\\\"$$DATADIR\\\" PKGDATADIR=\\\"$$PKGDATADIR\\\"
-
-  #MAKE INSTALL
-
-  INSTALLS += target desktop icon64 configs
-
-  configs.path = ~/.mdictionary
-  configs.files += ../../../data/mdictionary.defaults
-
-  target.path =$$BINDIR
-
-maemo5 {
-  desktop.path = $$DATADIR/applications/hildon
-  icon64.path = $$DATADIR/icons/hicolor/64x64/hildon
-}
-
-unix {
-  desktop.path = $$DATADIR/applications
-  icon64.path = $$DATADIR/icons
-}
-  desktop.files += ../../../data/other/$${TARGET}.desktop
-  icon64.files += ../../../data/icons/64x64/$${TARGET}.png
+RESOURCES += gui/gui.qrc
+
+unix { 
+    # VARIABLES
+    isEmpty(PREFIX):PREFIX = /usr
+    BINDIR = $$PREFIX/bin
+    DATADIR = $$PREFIX/share
+    DEFINES += DATADIR=\\\"$$DATADIR\\\" \
+        PKGDATADIR=\\\"$$PKGDATADIR\\\"
+    
+    # MAKE INSTALL
+    INSTALLS += target \
+        desktop \
+        icon64 \
+        configs
+    configs.path = ~/.mdictionary
+    configs.files += ../../../data/mdictionary.defaults
+    target.path = $$BINDIR
+    maemo5 { 
+        desktop.path = $$DATADIR/applications/hildon
+        icon64.path = $$DATADIR/icons/hicolor/64x64/hildon
+    }
+    !maemo5 { 
+        desktop.path = $$DATADIR/applications
+        icon64.path = $$DATADIR/icons
+    }
+    desktop.files += ../../../data/other/$${TARGET}.desktop
+    icon64.files += ../../../data/icons/64x64/$${TARGET}.png
 }
diff --git a/trunk/src/base/gui/AboutWidget.cpp b/trunk/src/base/gui/AboutWidget.cpp
new file mode 100644 (file)
index 0000000..369fda9
--- /dev/null
@@ -0,0 +1,52 @@
+#include "AboutWidget.h"
+
+AboutWidget::AboutWidget(GUIInterface *parent): QDialog(parent)
+{
+    QString infoNote, licenseNote, comarchNote;
+    infoNote = "<center><h2><u>mDictionary</u></h2></center>";
+    comarchNote = "<center>Meamo/Meego Mulitlingual Dictionary</center>";
+    comarchNote += "<center>Copyright 2006-2010, Comarch S.A. <br />";
+    comarchNote += "<a href=\"http://mdictionary.garage.maemo.org\">http://mdictionary.garage.maemo.org</a></center>";
+    licenseNote = "<br /><p><font size=\"small\">This program is free software: you can redistribute it and/or modify\n"
+                  "it under the terms of the GNU General Public License as published by\n"
+                  "the Free Software Foundation, either version 3 of the License, or\n"
+                  "(at your option) any later version.<br />"
+                  "This program is distributed in the hope that it will be useful,\n"
+                  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+                  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
+                  "GNU General Public License for more details.<br />"
+                  "You should have received a copy of the GNU General Public License\n"
+                  "along with this program.  If not, see"
+                  "<a href=\"http://www.gnu.org/licenses/\">"
+                  "&lt;http://www.gnu.org/licenses/&gt;</a>."
+                  "</p></font>";
+
+    setWindowTitle(tr("About"));
+    mainLayout = new QVBoxLayout(this);
+    setLayout(mainLayout);
+
+    imageLabel = new QLabel(this);
+    mainLabel = new QLabel(this);
+    licenseLabel = new QLabel(this);
+    mainLayout->addWidget(imageLabel, 0, Qt::AlignCenter);
+    mainLayout->addWidget(mainLabel);
+    mainLayout->addWidget(licenseLabel);
+    mainLabel->setOpenExternalLinks(true);
+
+    QImage img(":/icons/mdictionary.png");
+    imageLabel->setPixmap(QPixmap::fromImage(img));
+    imageLabel->resize(imageLabel->pixmap()->size());
+    imageLabel->setMinimumSize(imageLabel->pixmap()->size());
+
+    mainLabel->setText(infoNote + comarchNote);
+
+    licenseLabel->setText(licenseNote);
+    licenseLabel->setWordWrap(true);
+    licenseLabel->setOpenExternalLinks(true);
+    this->repaint();
+    this->update();
+
+    #ifdef Q_WS_MAEMO_5
+        mainLayout->addSpacing(20);
+    #endif
+}
diff --git a/trunk/src/base/gui/AboutWidget.h b/trunk/src/base/gui/AboutWidget.h
new file mode 100644 (file)
index 0000000..6bfa069
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef ABOUTWIDGET_H
+#define ABOUTWIDGET_H
+
+#include <QDialog>
+#include <QWidget>
+#include <QtGui>
+#include "../../includes/GUIInterface.h"
+
+class AboutWidget : public QDialog
+{
+    Q_OBJECT
+public:
+    AboutWidget(GUIInterface *parent = 0);
+private:
+    QVBoxLayout* mainLayout;
+    QLabel* mainLabel, * licenseLabel, *imageLabel;
+
+
+};
+
+#endif // ABOUTWIDGET_H
diff --git a/trunk/src/base/gui/BookmarksWidget.cpp b/trunk/src/base/gui/BookmarksWidget.cpp
new file mode 100644 (file)
index 0000000..7bbe036
--- /dev/null
@@ -0,0 +1,46 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "BookmarksWidget.h"
+
+BookmarksWidget::BookmarksWidget(GUIInterface *parent) :
+    QDialog(parent)
+{
+    setWindowTitle(tr("Bookmarks"));
+
+    verticalLayout = new QVBoxLayout;
+    setLayout(verticalLayout);
+
+    showAllBookmarksPushButton = new QPushButton(tr("Show all bookmarks"));
+    removeAllBookmarksPushButton =
+            new QPushButton(tr("Remove all bookmarks"));
+
+    verticalLayout->addWidget(showAllBookmarksPushButton);
+    verticalLayout->addWidget(removeAllBookmarksPushButton);
+
+    connect(showAllBookmarksPushButton, SIGNAL(clicked()),
+            this, SIGNAL(showAllBookmarks()));
+
+    connect(removeAllBookmarksPushButton, SIGNAL(clicked()),
+            this, SIGNAL(removeAllBookmarks()));
+}
diff --git a/trunk/src/base/gui/BookmarksWidget.h b/trunk/src/base/gui/BookmarksWidget.h
new file mode 100644 (file)
index 0000000..87b909c
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef BOOKMARKSWIDGET_H
+#define BOOKMARKSWIDGET_H
+
+#include <QDialog>
+#include <QtGui>
+#include "../../includes/GUIInterface.h"
+
+class BookmarksWidget : public QDialog
+{
+    Q_OBJECT
+public:
+    explicit BookmarksWidget(GUIInterface *parent = 0);
+
+Q_SIGNALS:
+    void showAllBookmarks();
+    void removeAllBookmarks();
+
+private:
+    QPushButton* showAllBookmarksPushButton;
+    QPushButton* removeAllBookmarksPushButton;
+    QVBoxLayout* verticalLayout;
+
+};
+
+#endif // BOOKMARKSWIDGET_H
index 7e793ad..236aa35 100644 (file)
@@ -73,6 +73,9 @@ DictManagerWidget::DictManagerWidget(GUIInterface *parent) :
 
     refreshDictsList();
 
+    #ifndef Q_WS_MAEMO_5
+        setMinimumSize(500,300);
+    #endif
 }
 
 
index 943cc78..8dc1f47 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "MainWindow.h"
 #include "ui_MainWindow.h"
+#include <QtGui>
 #ifdef Q_WS_MAEMO_5
     #include <QMaemo5InformationBox>
 #endif
@@ -32,6 +33,10 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
     GUIInterface(parent),
     ui(new Ui::MainWindow) {
 
+    #ifdef Q_WS_MAEMO_5
+        setAttribute(Qt::WA_Maemo5StackedWindow);
+    #endif
+
     this->backbone = backbone;
 
     initializeUI();
@@ -42,10 +47,14 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
     connectTranslationWidget();
     connectDictManager();
     connectMenu();
+    connectBookmarksWidget();
+
 
     setExactSearch(false);
 
     setWindowTitle("mDictionary");
+
+    showMaximized();
 }
 
 MainWindow::~MainWindow() {
@@ -56,44 +65,78 @@ MainWindow::~MainWindow() {
 void MainWindow::initializeUI() {
     ui->setupUi(this);
 
+    //showFullScreen();
     //sets attribute to maemo's stacked window
-    #ifdef Q_WS_MAEMO_5
-        setAttribute(Qt::WA_Maemo5StackedWindow);
-    #endif
+
 
 
     searchBarWidget = new SearchBarWidget;
+
     wordListWidget = new WordListWidget;
 
     //translationWidget is antoher stacked window, so we don't add it to layout
     //only create it with this widget as parent
     translationWidget = new TranslationWidget(this);
 
+    welcomeScreenWidget = new WelcomeScreenWidget;
+
     #ifdef Q_WS_MAEMO_5
-        ui->centralWidget->layout()->addWidget(wordListWidget);
+        ui->centralWidget->layout()->addWidget(welcomeScreenWidget);
+        QVBoxLayout* vl = (QVBoxLayout*)(ui->centralWidget->layout());
+        vl->addWidget(searchBarWidget, 0, Qt::AlignBottom);
     #else
+        translationWidget->hide();
         splitter = new QSplitter(Qt::Horizontal);
         splitter->addWidget(wordListWidget);
-        splitter->addWidget(translationWidget);
+        splitter->addWidget(welcomeScreenWidget);
         splitter->setStretchFactor(1, 150);
         ui->centralWidget->layout()->addWidget(splitter);
+        ui->centralWidget->layout()->addWidget(searchBarWidget);
     #endif
-    ui->centralWidget->layout()->addWidget(searchBarWidget);
 
 
 
     dictManagerWidget = new DictManagerWidget(this);
     dictManagerWidget->hide();
+
+    settingsWidget = new SettingsWidget(this);
+    settingsWidget->hide();
+
+    bookmarksWidget = new BookmarksWidget(this);
+    bookmarksWidget->hide();
+
+    aboutWidget = new AboutWidget(this);
+    aboutWidget->hide();
+
+
+
     #ifdef Q_WS_MAEMO_5
         menuWidget = new MenuWidget(this);
+        menuWidget->addSubMenu(tr("Settings"), settingsWidget);
         menuWidget->addSubMenu(tr("Dictionaries"), dictManagerWidget);
-        menuWidget->addSubMenu(tr("Settings"), new QPushButton("Settings"));
-        menuWidget->addSubMenu(tr("About"), new QPushButton("About"));
+        menuWidget->addSubMenu(tr("Bookmarks"), bookmarksWidget);
+        menuWidget->addSubMenu(tr("About"), aboutWidget);
         ui->menuBar->addAction(menuWidget);
     #else
         dictionariesAction = ui->menuBar->addAction(tr("Dictionaries"));
         connect(dictionariesAction, SIGNAL(triggered()),
                 dictManagerWidget, SLOT(show()));
+
+        settingsAction = ui->menuBar->addAction(tr("Settings"));
+        connect(settingsAction, SIGNAL(triggered()),
+                settingsWidget, SLOT(show()));
+
+        QMenu* m = ui->menuBar->addMenu(tr("Bookmarks"));
+        bookmarksShowAllAction = new QAction(tr("Show all"), m);
+
+        bookmarksRemoveAllAction = new QAction(tr("Remove all"), m);
+
+        m->addAction(bookmarksShowAllAction);
+        m->addAction(bookmarksRemoveAllAction);
+
+        aboutAction = ui->menuBar->addAction(tr("About"));
+        connect(aboutAction, SIGNAL(triggered()),
+                aboutWidget, SLOT(show()));
     #endif
 
 }
@@ -121,6 +164,17 @@ void MainWindow::wordListReady() {
     QMultiHash<QString, Translation*> res = backbone->result();
     QHash<QString, QList<Translation*> > searchResult;
 
+    #ifdef Q_WS_MAEMO_5
+    if(!wordListWidget->isVisible()) {
+        int i = ui->centralWidget->layout()->indexOf(welcomeScreenWidget);
+        QBoxLayout* l = (QBoxLayout*)(ui->centralWidget->layout());
+        l->removeWidget(welcomeScreenWidget);
+        welcomeScreenWidget->deleteLater();
+        l->insertWidget(0, wordListWidget);
+        qDebug()<<"changed";
+    }
+    #endif
+
     //if nothing was found
     if(res.count() == 0) {
         #ifdef Q_WS_MAEMO_5
@@ -143,7 +197,9 @@ void MainWindow::wordListReady() {
             emit showWordList(searchResult);
         }
         else {
-
+            #ifndef Q_WS_MAEMO_5
+                emit showWordList(searchResult);
+            #endif
             bool foundExactMatch = false;
             QHash<QString, QList<Translation*> >::iterator j;
             for(j = searchResult.begin(); j != searchResult.end(); j++) {
@@ -170,6 +226,18 @@ void MainWindow::wordListReady() {
 }
 
 void MainWindow::translationsReady() {
+    #ifndef Q_WS_MAEMO_5
+    if(!translationWidget->isVisible()) {
+        int i = ui->centralWidget->layout()->indexOf(welcomeScreenWidget);
+        QBoxLayout* l = (QBoxLayout*)(ui->centralWidget->layout());
+        QSplitter* s = (QSplitter*)((QWidgetItem*)(l->itemAt(0))->widget());
+        s->insertWidget(1,translationWidget);
+        s->setStretchFactor(1, 150);
+        welcomeScreenWidget->deleteLater();
+        qDebug()<<"changed";
+    }
+    #endif
+
     emit showTranslation(backbone->htmls());
 }
 
@@ -206,12 +274,18 @@ void MainWindow::addToHistory(QList<Translation *> trans) {
 void MainWindow::historyNext() {
     if(backbone->history()->nextAvailable()) {
         QString next = backbone->history()->next();
+        #ifndef Q_WS_MAEMO_5
+            setExactSearch(true);
+        #endif
         searchBarWidget->searchDelay(next);
     }
 }
 
 void MainWindow::historyPrev() {
     if(backbone->history()->prevAvailable()) {
+        #ifndef Q_WS_MAEMO_5
+            setExactSearch(true);
+        #endif
         QString prev = backbone->history()->previous();
         searchBarWidget->searchDelay(prev);
     }
@@ -245,6 +319,14 @@ void MainWindow::showHistory() {
     }
 }
 
+void MainWindow::setSettings(Settings *s) {
+    backbone->setSettings(s);
+}
+
+Settings* MainWindow::settings() {
+    return backbone->settings();
+}
+
 void MainWindow::connectBackbone() {
     connect(this, SIGNAL(quit()),
             backbone, SLOT(quit()));
@@ -347,11 +429,19 @@ void MainWindow::connectWordList() {
             this, SIGNAL(searchTranslations(QList<Translation*>)));
 
 
+
+
     connect(this, SIGNAL(setBusy()),
             wordListWidget, SLOT(lockList()));
 
     connect(this, SIGNAL(setIdle()),
             wordListWidget, SLOT(unlockList()));
+
+    connect(wordListWidget, SIGNAL(addBookmark(QList<Translation*>)),
+            backbone, SLOT(addBookmark(QList<Translation*>)));
+
+    connect(wordListWidget, SIGNAL(removeBookmark(QList<Translation*>)),
+            backbone, SLOT(removeBookmark(QList<Translation*>)));
 }
 
 void MainWindow::connectTranslationWidget() {
@@ -379,3 +469,33 @@ void MainWindow::connectMenu() {
     connect(this, SIGNAL(setIdle()),
             this, SLOT(enableMenu()));
 }
+
+
+void MainWindow::showAllBookmarks() {
+    #ifdef Q_WS_MAEMO_5
+        menuWidget->hideMenu();
+    #endif
+    backbone->fetchBookmarks();
+}
+
+void MainWindow::connectBookmarksWidget() {
+    #ifdef Q_WS_MAEMO_5
+        connect(bookmarksWidget, SIGNAL(removeAllBookmarks()),
+                backbone, SLOT(removeAllBookmark()));
+
+        connect(bookmarksWidget, SIGNAL(showAllBookmarks()),
+                this, SLOT(showAllBookmarks()));
+
+        connect(bookmarksWidget, SIGNAL(removeAllBookmarks()),
+                backbone, SLOT(fetchBookmarks()));
+    #else
+        connect(bookmarksShowAllAction, SIGNAL(triggered()),
+                backbone, SLOT(fetchBookmarks()));
+
+        connect(bookmarksRemoveAllAction, SIGNAL(triggered()),
+                backbone, SLOT(removeAllBookmark()));
+
+        connect(bookmarksRemoveAllAction, SIGNAL(triggered()),
+                backbone, SLOT(fetchBookmarks()));
+    #endif
+}
index 7ee6614..6032269 100644 (file)
 
 #include <QMainWindow>
 #include "../../includes/GUIInterface.h"
+#include "../../includes/settings.h"
 #include "../backbone/backbone.h"
 #include "TranslationWidget.h"
 #include "WordListWidget.h"
 #include "SearchBarWidget.h"
 #include "MenuWidget.h"
 #include "DictManagerWidget.h"
+#include "SettingsWidget.h"
 #include "HistoryListDialog.h"
+#include "BookmarksWidget.h"
+#include "WelcomeScreenWidget.h"
+#include "AboutWidget.h"
 
 namespace Ui {
     class MainWindow;
@@ -94,6 +99,10 @@ public:
     */
     void setExactSearch(bool);
 
+    Settings* settings();
+
+    void setSettings(Settings*);
+
 
  public Q_SLOTS:
     //! Search in exact mode for given word
@@ -165,6 +174,9 @@ private Q_SLOTS:
     void breakSearching();
 
 
+    void showAllBookmarks();
+
+
 protected:
     /*! When user wants to close application, we first sends signal to stop all
         ongoing searches.
@@ -180,17 +192,22 @@ private:
 
 
     SearchBarWidget* searchBarWidget;
-    TranslationWidget* translationWidget;
-    WordListWidget* wordListWidget;
+    QWidget* translationWidget;
+    QWidget* wordListWidget;
     MenuWidget* menuWidget;
     DictManagerWidget* dictManagerWidget;
+    SettingsWidget* settingsWidget;
+    BookmarksWidget* bookmarksWidget;
+    QWidget* welcomeScreenWidget;
+    AboutWidget* aboutWidget;
 
     #ifndef Q_WS_MAEMO_5
         QSplitter* splitter;
         QAction* dictionariesAction;
-        //QAction* edit;
-       // QAction* settingsAction;
-        //QAction* aboutAction;
+        QAction* bookmarksShowAllAction;
+        QAction* bookmarksRemoveAllAction;
+        QAction* settingsAction;
+        QAction* aboutAction;
     #endif
 
     bool _exactSearch;
@@ -203,6 +220,7 @@ private:
     void connectTranslationWidget();
     void connectDictManager();
     void connectMenu();
+    void connectBookmarksWidget();
 };
 
 #endif // MAINWINDOW_H
index 3f90967..0b52973 100644 (file)
@@ -33,4 +33,7 @@ MenuTabWidget::MenuTabWidget(QWidget *parent) :
 void MenuTabWidget::hideEvent(QHideEvent *e) {
     //just set parent to null, and allow event to by handled by default handler
     setParent(NULL);
+
+
+    QTabWidget::hideEvent(e);
 }
index e516b71..fa6210b 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "MenuWidget.h"
 #include <QDebug>
+#include <QtGui>
 
 MenuWidget::MenuWidget(QWidget *parent) :
     QWidgetAction(parent) {
@@ -39,7 +40,11 @@ MenuWidget::~MenuWidget() {
 }
 
 void MenuWidget::addSubMenu(QString title, QWidget *widget) {
-    tabWidget->addTab(widget, title);
+    QScrollArea* sa = new QScrollArea(tabWidget);
+    sa->setWidget(widget);
+    sa->setWidgetResizable(true);
+    sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    tabWidget->addTab(sa, title);
 }
 
 
@@ -58,4 +63,9 @@ QWidget* MenuWidget::createWidget(QWidget *) {
     it parent to NULL and prevent it from delete, so we can still use this
     widget*/
     return tabWidget;
+
+}
+
+void MenuWidget::hideMenu() {
+    tabWidget->parentWidget()->hide();
 }
index 58f4b96..fafc63b 100644 (file)
@@ -51,6 +51,9 @@ public:
     */
     void removeSubMenu(QString title);
 
+public Q_SLOTS:
+    void hideMenu();
+
 protected:
     MenuTabWidget* tabWidget;
     QWidget* createWidget(QWidget *parent);
index ee9fca7..4731d6e 100644 (file)
@@ -110,14 +110,14 @@ void SearchBarWidget::initializeUI() {
 
 
     searchPushButton = new QPushButton(tr("Search"));
-    searchPushButton->setMinimumWidth(150);
+    searchPushButton->setMinimumWidth(125);
     #ifndef Q_WS_MAEMO_5
         searchPushButton->setMinimumHeight(
                 searchPushButton->sizeHint().height()*2);
     #endif
 
     searchWordLineEdit = new QLineEdit();
-    searchWordLineEdit->setMinimumWidth(300);
+    searchWordLineEdit->setMinimumWidth(250);
 
     #ifndef Q_WS_MAEMO_5
         searchWordLineEdit->setMinimumHeight(
@@ -185,6 +185,18 @@ void SearchBarWidget::initializeUI() {
                 clearSearchWordToolButton->sizeHint().height()*2);
     #endif
 
+    fullScreenToolButton = new QToolButton();
+    #ifdef Q_WS_MAEMO_5
+        fullScreenToolButton->setIcon(
+                generateIcon(QIcon::fromTheme("general_fullsize")));
+    #else
+        fullScreenToolButton->setIcon(
+                generateIcon(QIcon::fromTheme("view-fullscreen")));
+        fullScreenToolButton->setMinimumSize(
+                fullScreenToolButton->sizeHint().height()*2,
+                fullScreenToolButton->sizeHint().height()*2);
+    #endif
+
 
     searchingProgressBar = new QProgressBar();
     //progress bar have minimum and maximum values set to 0, which will effect
@@ -207,6 +219,7 @@ void SearchBarWidget::initializeUI() {
     horizontalLayout->addWidget(historyPrevToolButton);
     horizontalLayout->addWidget(historyShowToolButton);
     horizontalLayout->addWidget(historyNextToolButton);
+    horizontalLayout->addWidget(fullScreenToolButton);
 
     //adding clear toolButton to textEdit with right alignment
     lineEditLayout->addWidget(clearSearchWordToolButton, 0,
index 2bf1ee0..1172d7b 100644 (file)
@@ -117,6 +117,7 @@ private:
     QToolButton* historyPrevToolButton;
     QToolButton* historyNextToolButton;
     QToolButton* historyShowToolButton;
+    QToolButton* fullScreenToolButton;
     QHBoxLayout* horizontalLayout;
     QProgressBar* searchingProgressBar;
 
diff --git a/trunk/src/base/gui/SettingsWidget.cpp b/trunk/src/base/gui/SettingsWidget.cpp
new file mode 100644 (file)
index 0000000..5b34ee5
--- /dev/null
@@ -0,0 +1,124 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "SettingsWidget.h"
+#include <QDebug>
+
+SettingsWidget::SettingsWidget(GUIInterface *parent) :
+    QDialog(parent)
+{
+    guiInterface = parent;
+
+    setWindowTitle(tr("Settings"));
+
+    verticalLayout = new QVBoxLayout;
+    setLayout(verticalLayout);
+
+    historySizeSpinBox = new QSpinBox;
+    searchResultSizeSpinBox = new QSpinBox;
+
+    spinBoxesFormLayout = new QFormLayout;
+
+    spinBoxesFormLayout->addRow(tr("Search result size"),
+                                searchResultSizeSpinBox);
+
+    spinBoxesFormLayout->addRow(tr("History size"),
+                                historySizeSpinBox);
+
+    searchResultSizeSpinBox->setMinimum(1);
+    historySizeSpinBox->setMinimum(1);
+
+    #ifdef Q_WS_MAEMO_5
+        verticalLayout->addSpacing(20);
+    #endif
+    verticalLayout->addLayout(spinBoxesFormLayout);
+
+
+    checkBoxesLabel = new QLabel(tr("Search in:"));
+
+    searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"));
+    searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"));
+
+    verticalLayout->addSpacing(20);
+    verticalLayout->addWidget(checkBoxesLabel);
+    verticalLayout->addWidget(searchInDictionariesCheckBox);
+    verticalLayout->addWidget(searchInBookmarksCheckBox);
+
+
+
+    #ifndef Q_WS_MAEMO_5
+        setMinimumWidth(250);
+        setMaximumWidth(250);
+    #endif
+}
+
+void SettingsWidget::showEvent(QShowEvent *e) {
+
+    settings = guiInterface->settings();
+
+    historySizeSpinBox->setValue(
+            settings->value("history_size").toInt());
+
+    searchResultSizeSpinBox->setValue(
+            settings->value("search_limit").toInt());
+
+    if(settings->value("search_bookmarks") == "true")
+        searchInBookmarksCheckBox->setChecked(true);
+    else
+        searchInBookmarksCheckBox->setChecked(false);
+
+    if(settings->value("search_dictionaries") == "true")
+        searchInDictionariesCheckBox->setChecked(true);
+    else
+        searchInDictionariesCheckBox->setChecked(false);
+
+    QDialog::showEvent(e);
+}
+
+void SettingsWidget::hideEvent(QHideEvent *e) {
+    Settings* newSettings = new Settings;
+    newSettings->setValue("history_size",
+                          QString::number(historySizeSpinBox->value()));
+    newSettings->setValue("search_limit",
+                          QString::number(searchResultSizeSpinBox->value()));
+
+    if(searchInDictionariesCheckBox->isChecked())
+        newSettings->setValue("search_dictionaries", "true");
+    else
+        newSettings->setValue("search_dictionaries", "false");
+
+    if(searchInBookmarksCheckBox->isChecked())
+        newSettings->setValue("search_bookmarks", "true");
+    else
+        newSettings->setValue("search_bookmarks", "false");
+
+    QString key;
+    foreach(key, newSettings->keys()) {
+        if(settings->value(key) != newSettings->value(key)) {
+            guiInterface->setSettings(newSettings);
+            break;
+        }
+    }
+
+    QDialog::hideEvent(e);
+}
diff --git a/trunk/src/base/gui/SettingsWidget.h b/trunk/src/base/gui/SettingsWidget.h
new file mode 100644 (file)
index 0000000..defb521
--- /dev/null
@@ -0,0 +1,56 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef SETTINGSWIDGET_H
+#define SETTINGSWIDGET_H
+
+#include <QWidget>
+#include <QtGui>
+#include "../../includes/GUIInterface.h"
+#include "../../includes/settings.h"
+
+class SettingsWidget : public QDialog
+{
+    Q_OBJECT
+public:
+    explicit SettingsWidget(GUIInterface *parent = 0);
+
+protected:
+    void showEvent(QShowEvent *);
+    void hideEvent(QHideEvent *);
+
+private:
+    QSpinBox* historySizeSpinBox;
+    QSpinBox* searchResultSizeSpinBox;
+    QVBoxLayout* verticalLayout;
+    QFormLayout* spinBoxesFormLayout;
+
+    QLabel* checkBoxesLabel;
+    QCheckBox* searchInDictionariesCheckBox;
+    QCheckBox* searchInBookmarksCheckBox;
+
+    GUIInterface* guiInterface;
+    Settings* settings;
+};
+
+#endif // SETTINGSWIDGET_H
index 22c55c0..04c7565 100644 (file)
@@ -44,6 +44,7 @@ void TranslationWidget::show() {
 }
 
 void TranslationWidget::show(QStringList translations) {
+
     show();
 
     textEdit->clear();
@@ -84,9 +85,12 @@ void TranslationWidget::initializeUI() {
 
     QWidget*w = new QWidget;
     verticalLayout = new QVBoxLayout(w);
-    //verticalLayout->addLayout(horizontalLayout);
     verticalLayout->addWidget(textEdit);
 
+    textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+
     this->setWidget(w);
     this->setWidgetResizable(true);
 
@@ -102,5 +106,31 @@ void TranslationWidget::initializeUI() {
     connect(zoomInToolButton, SIGNAL(clicked()),
             this, SIGNAL(updateSize()));
 
+   /* #ifdef Q_WS_MAEMO_5
+        fullScreenButton = new QToolButton(this);
+        fullScreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
+        fullScreenButton->setMinimumSize(fullScreenButton->sizeHint());
+        int x = QApplication::desktop()->screenGeometry(this).width()  -
+                fullScreenButton->sizeHint().width();
+        int y = QApplication::desktop()->screenGeometry(this).height() -
+                fullScreenButton->sizeHint().height();
+        fullScreenButton->move(QPoint(x,y));
+        fullScreenButton->show();
+        fullScreenButton->setWindowOpacity(0.5);
+
+
+        backButton = new QToolButton(this);
+        backButton->setIcon(QIcon::fromTheme("general_overlay_back"));
+        backButton->setMinimumSize(fullScreenButton->sizeHint());
+        x = QApplication::desktop()->screenGeometry(this).width()  -
+                backButton->sizeHint().width();
+        y = 0;
+        backButton->move(QPoint(x,y));
+        backButton->show();
+        backButton->setWindowOpacity(0.5);
+
+        connect(backButton, SIGNAL(clicked()),
+                this, SLOT(hide()));
+    #endif*/
 }
 
index 0b8f058..957f243 100644 (file)
@@ -55,6 +55,10 @@ private:
     QTextEdit *textEdit;
     QToolButton* zoomInToolButton;
     QToolButton* zoomOutToolButton;
+    #ifdef Q_WS_MAEMO_5
+        QToolButton* fullScreenButton;
+        QToolButton* backButton;
+    #endif
     QVBoxLayout *verticalLayout;
     QHBoxLayout* horizontalLayout;
     TranslationWidgetAutoResizer* resizer;
diff --git a/trunk/src/base/gui/WelcomeScreenWidget.cpp b/trunk/src/base/gui/WelcomeScreenWidget.cpp
new file mode 100644 (file)
index 0000000..e72c88c
--- /dev/null
@@ -0,0 +1,54 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "WelcomeScreenWidget.h"
+
+WelcomeScreenWidget::WelcomeScreenWidget(QWidget *parent) :
+    QScrollArea(parent)
+{
+    QString infoNote, licenseNote, comarchNote;
+    infoNote = "<center><h1>Welcome in mDictionary!</h1></center>";
+
+
+    mainLayout = new QVBoxLayout(this);
+    setLayout(mainLayout);
+
+    imageLabel = new QLabel(this);
+    mainLabel = new QLabel(infoNote, this);
+
+    mainLayout->addStretch(0);
+    mainLayout->addWidget(imageLabel, 0, Qt::AlignCenter);
+    mainLayout->addWidget(mainLabel, 0, Qt::AlignCenter);
+    mainLayout->addStretch(0);
+
+    QImage img(":/icons/mdictionary.png");
+    imageLabel->setPixmap(QPixmap::fromImage(img));
+    imageLabel->resize(imageLabel->pixmap()->size());
+
+
+    //mainLabel->setWordWrap(true);
+
+    #ifdef Q_WS_MAEMO_5
+        mainLayout->addSpacing(20);
+    #endif
+}
diff --git a/trunk/src/base/gui/WelcomeScreenWidget.h b/trunk/src/base/gui/WelcomeScreenWidget.h
new file mode 100644 (file)
index 0000000..8a06634
--- /dev/null
@@ -0,0 +1,42 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef WELCOMESCREENWIDGET_H
+#define WELCOMESCREENWIDGET_H
+
+#include <QWidget>
+#include <QScrollArea>
+#include <QtGui>
+
+class WelcomeScreenWidget : public QScrollArea
+{
+    Q_OBJECT
+public:
+    explicit WelcomeScreenWidget(QWidget *parent = 0);
+
+private:
+    QVBoxLayout* mainLayout;
+    QLabel* mainLabel, * licenseLabel, *imageLabel;
+};
+
+#endif // WELCOMESCREENWIDGET_H
diff --git a/trunk/src/base/gui/WordListProxyStyle.cpp b/trunk/src/base/gui/WordListProxyStyle.cpp
new file mode 100644 (file)
index 0000000..57d03c4
--- /dev/null
@@ -0,0 +1,50 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "WordListProxyStyle.h"
+
+
+WordListProxyStyle::WordListProxyStyle() :
+    QProxyStyle()
+{
+    starPixmapOn = QPixmap(":/icons/staron.png");
+    starPixmapOff = QPixmap(":/icons/staroff.png");
+}
+
+
+void WordListProxyStyle::drawPrimitive(PrimitiveElement element,
+                                       const QStyleOption *option,
+                                       QPainter *painter,
+                                       const QWidget *widget) const {
+    if(element == PE_IndicatorCheckBox) {
+        if(option->state & QStyle::State_On)
+            painter->drawPixmap(option->rect, starPixmapOn);
+        else
+            painter->drawPixmap(option->rect, starPixmapOff);
+    }
+    else {
+        QProxyStyle::drawPrimitive(element, option, painter, widget);
+    }
+}
+
+
diff --git a/trunk/src/base/gui/WordListProxyStyle.h b/trunk/src/base/gui/WordListProxyStyle.h
new file mode 100644 (file)
index 0000000..dd76e73
--- /dev/null
@@ -0,0 +1,44 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef WORDLISTPROXYSTYLE_H
+#define WORDLISTPROXYSTYLE_H
+
+#include <QProxyStyle>
+#include <QtGui>
+
+class WordListProxyStyle : public QProxyStyle
+{
+public:
+    WordListProxyStyle();
+    void drawPrimitive(PrimitiveElement element,
+                       const QStyleOption *option,
+                       QPainter *painter,
+                       const QWidget *widget) const;
+
+private:
+    QPixmap starPixmapOn;
+    QPixmap starPixmapOff;
+};
+
+#endif // WORDLISTPROXYSTYLE_H
index bd3cf02..60cf791 100644 (file)
@@ -1,3 +1,4 @@
+
 /*******************************************************************************
 
     This file is part of mDictionary.
 #include <QDebug>
 #include "../../includes/translation.h"
 #include <QMultiHash>
+#include "WordListProxyStyle.h"
+
 
 #ifdef Q_WS_MAEMO_5
     #include <QMaemo5InformationBox>
 #endif
 
 WordListWidget::WordListWidget(QWidget *parent):
-    QListView(parent) {
+    QTreeView(parent) {
 
-    wordListModel = new QStringListModel();
+    model = new QStandardItemModel(this);
+    setModel(model);
+    setHeaderHidden(true);
+    setRootIsDecorated(false);
+    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
-    connect(this, SIGNAL(clicked(QModelIndex)),
-            this, SLOT(itemClicked(QModelIndex)));
+    setStyle(new WordListProxyStyle);
 
-
-    setModel(wordListModel);
+    #ifdef Q_WS_MAEMO_5
+        checkBoxWidth = 70;
+    #else
+        checkBoxWidth = 25;
+    #endif
 }
 
-void WordListWidget::addWord(QString word) {
-    int wordsCount = wordListModel->rowCount();
-
-    wordListModel->insertRow(wordsCount);
-
-    QModelIndex newWordIndex = wordListModel->index(wordsCount);
+void WordListWidget::addWord(QString word, int row) {
+    QStandardItem* item = new QStandardItem(word);
+    item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+    QStandardItem* itemCheckBox = new QStandardItem();
+    itemCheckBox->setFlags(itemCheckBox->flags() ^ Qt::ItemIsEditable |
+                           Qt::ItemIsUserCheckable);
+
+    bool bookmark = false;
+    Translation* t;
+    foreach(t, searchResult[word]) {
+        if(t->isBookmark()) {
+            bookmark = true;
+            break;
+        }
+    }
 
-    wordListModel->setData(newWordIndex, word);
+    if(bookmark)
+        itemCheckBox->setCheckState(Qt::Checked);
+    else
+        itemCheckBox->setCheckState(Qt::Unchecked);
 
+    model->setItem(row,0, item);
+    model->setItem(row,1, itemCheckBox);
 }
 
-void WordListWidget::clear() {
-    int wordsCount = wordListModel->rowCount();
-
-    for(int i = 0; i < wordsCount; i++) {
-        wordListModel->removeRow(0);
-    }
-}
 
 void WordListWidget::showSearchResults(
-       QHash<QString, QList<Translation *> > result) {
-    clear();
+        QHash<QString, QList<Translation *> > result) {
+    model->clear();
     searchResult.clear();
 
+    model->setColumnCount(2);
+    model->setRowCount(result.count());
+
     searchResult = result;
+    int row=0;
     QHash<QString, QList<Translation*> >::iterator i;
     for(i = result.begin(); i != result.end(); i++) {
-           addWord(i.key());
+           addWord(i.key(), row++);
+    }
+
+    resizeColumns();
+    model->sort(0);
+}
+
+void WordListWidget::wordClicked(QModelIndex index) {
+    emit showTranslation(
+            searchResult[index.data().toString()]);
+}
+
+void WordListWidget::wordChecked(QModelIndex index) {
+    Qt::CheckState state =
+            Qt::CheckState(index.data(Qt::CheckStateRole).toInt());
+
+    if(selectedIndexes().count()==0) return;
+    QModelIndex item = selectedIndexes().at(0);
+    if(!item.isValid()) return;
+
+    repaint();
+
+    if(state == Qt::Checked) {
+        emit addBookmark(searchResult[item.data().toString()]);
+    }
+    else {
+        emit removeBookmark(searchResult[item.data().toString()]);
     }
+}
+
+
+void WordListWidget::mouseReleaseEvent(QMouseEvent *event) {
+    QTreeView::mouseReleaseEvent(event);
 
-    wordListModel->sort(0, Qt::AscendingOrder);
 
-    scrollTo(model()->index(0,0));
+    QModelIndex index = indexAt(event->pos());
+    if(!index.isValid()) return;
+    if(selectedIndexes().count() == 0) return;
+
+    if(selectedIndexes().at(0) != index && selectedIndexes().at(1) != index)
+        return;
+
+    int c = index.column();
+    if(c==0)
+        wordClicked(index);
+    else
+        wordChecked(index);
+}
 
+void WordListWidget::resizeEvent(QResizeEvent *event) {
+    resizeColumns();
+    QTreeView::resizeEvent(event);
 }
 
-void WordListWidget::itemClicked(QModelIndex index) {
-    emit showTranslation(searchResult[index.model()->data(index).toString()]);
+void WordListWidget::resizeColumns() {
+    setColumnWidth(0, viewport()->width() -checkBoxWidth - 20);
+    setColumnWidth(1, checkBoxWidth);
 }
 
 void WordListWidget::lockList() {
index d2cff2c..7ad634d 100644 (file)
 /*!
     It allow user to select word to see it's translation or to mark it as "star"
   */
-class WordListWidget : public QListView {
+class WordListWidget : public QTreeView {
     Q_OBJECT
 public:
     explicit WordListWidget(QWidget *parent = 0);
 
+
 Q_SIGNALS:
     //! Request to show translation which is described by passed translations
     //! objects
     void showTranslation(QList<Translation*>);
 
 
+    //! Request to add selected word to bookmarks
+    void addBookmark(QList<Translation*>);
+
+    //! Request to remove selected word from bookmarks
+    void removeBookmark(QList<Translation*>);
+
+
 public Q_SLOTS:
     //! Shows search results
     /*!
@@ -59,19 +67,21 @@ public Q_SLOTS:
     //! Unlocks words list
     void unlockList();
 
+protected:
+    void mouseReleaseEvent(QMouseEvent *event);
+    void resizeEvent(QResizeEvent *event);
 
 private Q_SLOTS:
-    void itemClicked(QModelIndex index);
+    void wordClicked(QModelIndex index);
+    void wordChecked(QModelIndex index);
 
 private:
-    //Backbone *backbone;
-    //words are keeping as QStringListModel which allow to sort them
-    QStringListModel *wordListModel;
-    void addWord(QString word);
-    //clears all list of words
-    void clear();
+    void addWord(QString word, int row);
+    QStandardItemModel* model;
+    int checkBoxWidth;
+    void resizeColumns();
+
     QHash<QString, QList<Translation*> > searchResult;
-    //QString _exactMatchString;
 };
 
 #endif // WORDLISTWIDGET_H
diff --git a/trunk/src/base/gui/gui.qrc b/trunk/src/base/gui/gui.qrc
new file mode 100644 (file)
index 0000000..dc740a5
--- /dev/null
@@ -0,0 +1,7 @@
+<RCC>
+    <qresource prefix="/icons">
+        <file>staroff.png</file>
+        <file>staron.png</file>
+        <file>mdictionary.png</file>
+    </qresource>
+</RCC>
diff --git a/trunk/src/base/gui/mdictionary.png b/trunk/src/base/gui/mdictionary.png
new file mode 100755 (executable)
index 0000000..3768425
Binary files /dev/null and b/trunk/src/base/gui/mdictionary.png differ
diff --git a/trunk/src/base/gui/staroff.png b/trunk/src/base/gui/staroff.png
new file mode 100644 (file)
index 0000000..7b0c1bc
Binary files /dev/null and b/trunk/src/base/gui/staroff.png differ
diff --git a/trunk/src/base/gui/staron.png b/trunk/src/base/gui/staron.png
new file mode 100644 (file)
index 0000000..2291707
Binary files /dev/null and b/trunk/src/base/gui/staron.png differ
index 7914ce1..17aa8ee 100644 (file)
@@ -32,6 +32,8 @@
 #include "translation.h"
 #include "CommonDictInterface.h"
 
+class Settings;
+
 //! Interface for different GUIs
 /*!
   Default base class for all GUIs is QMainWindow
@@ -73,6 +75,10 @@ public:
     /*! \sa exactSearch() */
     void setExactSearch(bool exactSearch);
 
+    virtual Settings* settings() = 0;
+
+    virtual void setSettings(Settings*) = 0;
+
 
 public Q_SLOTS:
     //! Search in exact mode for given word
@@ -182,6 +188,8 @@ Q_SIGNALS:
     /*! \param list of only active dictionaries
       */
     void selectedDictionaries(QList<CommonDictInterface* >);
+
+    void addToBookmarks(QList<Translation*>);
 };
 
 #endif // GUIINTERFACE_H
index 8d4332b..c32e75d 100644 (file)
@@ -37,6 +37,7 @@
   as late as possible*/
 class Translation {
   public:
+    Translation  () { _bookmark = 0; }
     //! \return word to be translated
     virtual QString key() const = 0;
  
@@ -51,6 +52,19 @@ class Translation {
     //! \return parsed raw format into html
     virtual QString toHtml() const = 0;
 
+    //! \retrun whether given translation is taken from bookmarks
+    bool isBookmark() const {
+        return _bookmark;
+   }
+
+   //! \param b if true then translation is from bookmarks
+   void setBookmark(bool b) {
+       _bookmark = b;
+   }
+
+   protected:
+       bool _bookmark;
+
 };
 
 Q_DECLARE_METATYPE(Translation*);
index b544870..807937e 100644 (file)
@@ -89,6 +89,7 @@ QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
         stopped = false;
         if(word.indexOf("*")==-1 && word.indexOf("?")== 0)
             word+="%";
+        word = word.toLower();
         word = word.replace("*", "%");
         word = word.replace("?", "_");
         word = removeAccents(word);
@@ -100,8 +101,9 @@ QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
         cur.addBindValue(limit);
         cur.exec();
         while(cur.next())
-            translations.insert(new TranslationXdxf(cur.value(0).toString(),
-                                                    _infoNote, this));
+            translations.insert(new TranslationXdxf(
+                        cur.value(0).toString().toLower(),
+                        _infoNote, this));
         return translations.toList();
 }
 
@@ -111,6 +113,7 @@ QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
     QSet<Translation*> translations;
     QFile dictionaryFile(path);
 
+    word = word.toLower();
     word = removeAccents(word);
 
     stopped = false;
@@ -141,7 +144,8 @@ QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
                         ok=false;  /*if key word is in the dictionary more that one */
                 }
                 if(ok)  /*add key word to list*/
-                    translations<<(new TranslationXdxf(a,_infoNote,this));
+                    translations<<(new TranslationXdxf(a.toLower(),
+                                _infoNote,this));
                 i++;
                 if(i>=limit && limit!=0)
                     break;
@@ -167,6 +171,7 @@ QString XdxfPlugin::searchCache(QString key) {
     QString result;
     QString cacheFilePath = _settings->value("cache_path");
     db.setDatabaseName(cacheFilePath);
+    key = key.toLower();
 
     if(!db.open()) {
         qDebug() << "Database error" << db.lastError().text() << endl;
@@ -187,6 +192,7 @@ QString XdxfPlugin::searchCache(QString key) {
 
 
 QString XdxfPlugin::searchFile(QString key) {
+    key = key.toLower();
     QFile dictionaryFile(path);
     QString resultString("");
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
@@ -366,7 +372,6 @@ void XdxfPlugin::getDictionaryInfo() {
 }
 
 QString XdxfPlugin::removeAccents(QString string) {
-
     string = string.replace(QString::fromUtf8("ł"), "l", Qt::CaseInsensitive);
     QString normalized = string.normalized(QString::NormalizationForm_D);
     normalized = normalized;
index ed2c910..656bb4b 100644 (file)
@@ -4,7 +4,7 @@
 #
 #-------------------------------------------------
 
-QT       += testlib core
+QT       += testlib core sql
 
 
 TARGET = mDictionaryTests
@@ -16,7 +16,8 @@ TEMPLATE = app
 
 SOURCES += tst_Backbone.cpp \
     ../../src/base/backbone/backbone.cpp \
-    ../../src/base/backbone/History.cpp
+    ../../src/base/backbone/History.cpp \
+    ../../src/base/backbone/Bookmarks.cpp
 DEFINES += SRCDIR=\\\"$$PWD/\\\"
 
 HEADERS += \
@@ -26,9 +27,10 @@ HEADERS += \
     ../../src/includes/settings.h \
     ../../src/includes/CommonDictInterface.h \
     ../../src/includes/History.h \
-    TranslationMock.h
+    TranslationMock.h \
+    ../../src/base/backbone/BookmarkTranslations.h \
+    ../../src/base/backbone/Bookmarks.h
 
 check.target = check
 check.commands += ./mDictionaryTests
 QMAKE_EXTRA_TARGETS += check
-
index 0739438..7235070 100644 (file)
@@ -3,5 +3,5 @@ SUBDIRS = tests src
 
 check.target = check
 check.CONFIG = recursive
-check.recurse = tests src
+check.recurse = src
 QMAKE_EXTRA_TARGETS += check