[%General]
plugin_path=/usr/lib/mdictionary
-history_length=10
+history_size=10
search_limit=15
[dictionary_0]
error("Use the qmake include with Qt4.4 or greater, on Debian that is qmake-qt4");
}
-
+QT += sql
TEMPLATE = subdirs
SUBDIRS = trunk
--- /dev/null
+/*******************************************************************************
+
+ 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
--- /dev/null
+#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;
+}
--- /dev/null
+/*******************************************************************************
+
+ 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
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);
-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);
+ }
}
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();
}
}
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();
}
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);
}
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);
}
void Backbone::dictUpdated() {
if(dryRun)
return;
+ _history->setMaxSize(_historyLen);
QFileInfo file(QDir::toNativeSeparators(_configPath));
QDir confDir(file.dir());
if(!confDir.exists())
void Backbone::searchHtml(QList<Translation *> translations) {
_htmlResult.clear();
+
QList<TranslationPtr> dummy;
stopped = false;
- //_time.restart();
foreach(Translation* tr, translations)
dummy.append(TranslationPtr(tr));
}
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();
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;
+}
#include "../../includes/settings.h"
#include "../../includes/translation.h"
#include "../../includes/History.h"
+#include "Bookmarks.h"
/*! Inner part of dictionary - glues together GUI and plugins
/*! search for a word translation
\param word to be translated
+ \param dicts searching in dicionaries
+ \param bookmarks searching in bookmarks
*/
void search(QString word);
*/
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
//! 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;
-#-------------------------------------------------
-#
+# -------------------------------------------------
# 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 \
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 \
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
}
--- /dev/null
+#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/\">"
+ "<http://www.gnu.org/licenses/></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
+}
--- /dev/null
+#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
--- /dev/null
+/*******************************************************************************
+
+ 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()));
+}
--- /dev/null
+/*******************************************************************************
+
+ 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
refreshDictsList();
+ #ifndef Q_WS_MAEMO_5
+ setMinimumSize(500,300);
+ #endif
}
#include "MainWindow.h"
#include "ui_MainWindow.h"
+#include <QtGui>
#ifdef Q_WS_MAEMO_5
#include <QMaemo5InformationBox>
#endif
GUIInterface(parent),
ui(new Ui::MainWindow) {
+ #ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5StackedWindow);
+ #endif
+
this->backbone = backbone;
initializeUI();
connectTranslationWidget();
connectDictManager();
connectMenu();
+ connectBookmarksWidget();
+
setExactSearch(false);
setWindowTitle("mDictionary");
+
+ showMaximized();
}
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
}
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
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++) {
}
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());
}
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);
}
}
}
+void MainWindow::setSettings(Settings *s) {
+ backbone->setSettings(s);
+}
+
+Settings* MainWindow::settings() {
+ return backbone->settings();
+}
+
void MainWindow::connectBackbone() {
connect(this, SIGNAL(quit()),
backbone, SLOT(quit()));
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() {
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
+}
#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;
*/
void setExactSearch(bool);
+ Settings* settings();
+
+ void setSettings(Settings*);
+
public Q_SLOTS:
//! Search in exact mode for given word
void breakSearching();
+ void showAllBookmarks();
+
+
protected:
/*! When user wants to close application, we first sends signal to stop all
ongoing searches.
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;
void connectTranslationWidget();
void connectDictManager();
void connectMenu();
+ void connectBookmarksWidget();
};
#endif // MAINWINDOW_H
void MenuTabWidget::hideEvent(QHideEvent *e) {
//just set parent to null, and allow event to by handled by default handler
setParent(NULL);
+
+
+ QTabWidget::hideEvent(e);
}
#include "MenuWidget.h"
#include <QDebug>
+#include <QtGui>
MenuWidget::MenuWidget(QWidget *parent) :
QWidgetAction(parent) {
}
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);
}
it parent to NULL and prevent it from delete, so we can still use this
widget*/
return tabWidget;
+
+}
+
+void MenuWidget::hideMenu() {
+ tabWidget->parentWidget()->hide();
}
*/
void removeSubMenu(QString title);
+public Q_SLOTS:
+ void hideMenu();
+
protected:
MenuTabWidget* tabWidget;
QWidget* createWidget(QWidget *parent);
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(
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
horizontalLayout->addWidget(historyPrevToolButton);
horizontalLayout->addWidget(historyShowToolButton);
horizontalLayout->addWidget(historyNextToolButton);
+ horizontalLayout->addWidget(fullScreenToolButton);
//adding clear toolButton to textEdit with right alignment
lineEditLayout->addWidget(clearSearchWordToolButton, 0,
QToolButton* historyPrevToolButton;
QToolButton* historyNextToolButton;
QToolButton* historyShowToolButton;
+ QToolButton* fullScreenToolButton;
QHBoxLayout* horizontalLayout;
QProgressBar* searchingProgressBar;
--- /dev/null
+/*******************************************************************************
+
+ 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);
+}
--- /dev/null
+/*******************************************************************************
+
+ 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
}
void TranslationWidget::show(QStringList translations) {
+
show();
textEdit->clear();
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);
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*/
}
QTextEdit *textEdit;
QToolButton* zoomInToolButton;
QToolButton* zoomOutToolButton;
+ #ifdef Q_WS_MAEMO_5
+ QToolButton* fullScreenButton;
+ QToolButton* backButton;
+ #endif
QVBoxLayout *verticalLayout;
QHBoxLayout* horizontalLayout;
TranslationWidgetAutoResizer* resizer;
--- /dev/null
+/*******************************************************************************
+
+ 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
+}
--- /dev/null
+/*******************************************************************************
+
+ 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
--- /dev/null
+/*******************************************************************************
+
+ 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);
+ }
+}
+
+
--- /dev/null
+/*******************************************************************************
+
+ 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
+
/*******************************************************************************
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() {
/*!
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
/*!
//! 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
--- /dev/null
+<RCC>
+ <qresource prefix="/icons">
+ <file>staroff.png</file>
+ <file>staron.png</file>
+ <file>mdictionary.png</file>
+ </qresource>
+</RCC>
#include "translation.h"
#include "CommonDictInterface.h"
+class Settings;
+
//! Interface for different GUIs
/*!
Default base class for all GUIs is QMainWindow
/*! \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
/*! \param list of only active dictionaries
*/
void selectedDictionaries(QList<CommonDictInterface* >);
+
+ void addToBookmarks(QList<Translation*>);
};
#endif // GUIINTERFACE_H
as late as possible*/
class Translation {
public:
+ Translation () { _bookmark = 0; }
//! \return word to be translated
virtual QString key() const = 0;
//! \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*);
stopped = false;
if(word.indexOf("*")==-1 && word.indexOf("?")== 0)
word+="%";
+ word = word.toLower();
word = word.replace("*", "%");
word = word.replace("?", "_");
word = removeAccents(word);
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();
}
QSet<Translation*> translations;
QFile dictionaryFile(path);
+ word = word.toLower();
word = removeAccents(word);
stopped = false;
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;
QString result;
QString cacheFilePath = _settings->value("cache_path");
db.setDatabaseName(cacheFilePath);
+ key = key.toLower();
if(!db.open()) {
qDebug() << "Database error" << db.lastError().text() << endl;
QString XdxfPlugin::searchFile(QString key) {
+ key = key.toLower();
QFile dictionaryFile(path);
QString resultString("");
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
}
QString XdxfPlugin::removeAccents(QString string) {
-
string = string.replace(QString::fromUtf8("ł"), "l", Qt::CaseInsensitive);
QString normalized = string.normalized(QString::NormalizationForm_D);
normalized = normalized;
#
#-------------------------------------------------
-QT += testlib core
+QT += testlib core sql
TARGET = mDictionaryTests
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 += \
../../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
-
check.target = check
check.CONFIG = recursive
-check.recurse = tests src
+check.recurse = src
QMAKE_EXTRA_TARGETS += check