--- /dev/null
+[D-BUS Service]
+Name=com.comarch.mdictionary
+Exec=/usr/bin/mdictionary
Icon=mdictionary
Exec=/usr/bin/mdictionary
X-Maemo-Category=Main
+X-Osso-Service=com.comarch.mdictionary
--- /dev/null
+[Desktop Entry]
+Name=mDictionary
+Type=qt
+X-Path=/usr/lib/hildon-desktop/mdictionarywidget
+X-Multiple-Instances=false
bool Bookmarks::checkAndCreateDb() {
QSqlDatabase db = getDbCnx(dbName);
- if(!db.isOpen() && !db.open()) {
- qDebug() << "Database error: " << db.lastError().text() << endl;
- return false;
- }
+ db.open();
QSqlQuery cur(db);
cur.exec("create table bookmarks(key text, normalized text, translation text)");
db.close();
-
return true;
}
void Bookmarks::clear() {
+ checkAndCreateDb();
QSqlDatabase db = getDbCnx(dbName);
if(!db.isOpen() && !db.open()) {
qDebug() << "Database error: " << db.lastError().text() << endl;
void Bookmarks::add(Translation* translation) {
+ checkAndCreateDb();
QSqlDatabase db = getDbCnx(dbName);
if(!db.isOpen() && !db.open()) {
qDebug() << "Database error: " << db.lastError().text() << endl;
void Bookmarks::remove(Translation* translation) {
+ checkAndCreateDb();
QSqlDatabase db = getDbCnx(dbName);
if(!db.isOpen() && !db.open()) {
qDebug() << "Database error: " << db.lastError().text() << endl;
QList<Translation*> Bookmarks::list() {
+ checkAndCreateDb();
QList<Translation*> res;
QSqlDatabase db = getDbCnx(dbName);
if(!db.isOpen() && !db.open()) {
QList<Translation*> Bookmarks::searchWordList(QString word) {
-
+ checkAndCreateDb();
if(word.indexOf("*")==-1 && word.indexOf("?")== -1)
word+="%";
word = word.replace("*", "%");
QStringList Bookmarks::search(QString word, QString dbName) {
+ checkAndCreateDb();
QStringList result;
QSqlDatabase db = getDbCnx(dbName);
if(!db.isOpen() && !db.open()) {
bool Bookmarks::inBookmarks(QString word) {
+ checkAndCreateDb();
QSqlDatabase db = getDbCnx(dbName);
if(!db.isOpen() && !db.open()) {
qDebug() << "Database error: " << db.lastError().text() << endl;
_dictNum = 0;
_dir = QDir::homePath() + "/.mdictionary/";
+ if(!QDir(_dir).exists())
+ QDir().mkdir(_dir);
+
if(!_configPath.size())
_configPath = _dir + "mdictionary.config";
if(!_pluginPath.size())
dictFin = !_searchDicts;
bookmarkFin = !_searchBookmarks;
+ if(!_searchDicts && !_searchBookmarks) {
+ Q_EMIT notify(Notify::Warning, tr("You have to specify where You want "
+ "to look for translations"));
+ Q_EMIT ready();
+ }
+
if (_searchDicts) {
_innerResult = QtConcurrent::mapped(activeDicts(), mapSearch);
_resultWatcher.setFuture(_innerResult);
while(it.hasNext()) {
QList<Translation* > list = it.next();
- foreach(Translation* trans, list)
+ foreach(Translation* trans, list) {
+ if(!trans)
+ continue;
+ if(!_searchBookmarks)
+ trans->setBookmark(_bookmarks.
+ inBookmarks(trans->key()));
_result.insert(trans->key().toLower(), trans);
+ }
}
}
_searchLimit = set.value("general/search_limit", 15).toInt();
_searchBookmarks = set.value("general/search_bookmarks",1).toBool();
_searchDicts = set.value("general/search_dictionaries",1).toBool();
+ _zoom = set.value("general/zoom", 1.0).toReal();
}
set->setValue("general/search_limit", _searchLimit);
set->setValue("general/search_bookmarks", _searchBookmarks);
set->setValue("general/search_dictionaries", _searchDicts);
+ set->setValue("general/zoom", _zoom);
}
_searchBookmarks = 1;
else
_searchBookmarks = 0;
+ _zoom = settings->value("zoom").toFloat();
+ if(!_zoom)
+ _zoom ++;
+
dictUpdated();
if(settings)
delete settings;
Settings * settings = new Settings();
settings->setValue("history_size", QString("%1").arg(_historyLen));
settings->setValue("search_limit", QString("%1").arg(_searchLimit));
+ settings->setValue("zoom", QString("%1").arg(_zoom));
if(_searchBookmarks)
settings->setValue("search_bookmarks", "true");
else
QString _configPath;
QString _dir;
int _historyLen;
+ qreal _zoom;
bool dryRun; // mainly for testing - when true then doesn't bother configs etc
bool stopped; // true when user stops searching/fetching
gui \
sql \
xml \
- xmlpatterns
-
+ xmlpatterns \
+ webkit \
+ dbus
maemo5:QT += maemo5
TARGET = mdictionary
TEMPLATE = app
gui/BookmarksWidget.cpp \
gui/WelcomeScreenWidget.cpp \
gui/AboutWidget.cpp \
- gui/TranslationTextEdit.cpp
+ gui/TranslationTextEdit.cpp \
+ gui/DBusAdapter.cpp \
+ gui/NotifyManager.cpp
HEADERS += gui/MainWindow.h \
backbone/ConfigGenerator.h \
gui/AboutWidget.h \
gui/MenuTabWidget.h \
gui/DictManagerWidget.h \
gui/DictTypeSelectDialog.h \
- gui/TranslationWidgetAutoResizer.h \
../includes/History.h \
gui/HistoryListDialog.h \
../includes/GUIInterface.h \
gui/TranslationTextEdit.h \
../includes/AccentsNormalizer.h \
../includes/DictDialog.h
-RESOURCES += \
- translations.qrc \
- ../../../data/gui.qrc
+ ../includes/DictDialog.h \
+ gui/DBusAdapter.h \
+ gui/NotifyManager.h
+
+RESOURCES += ../../../data/gui.qrc
unix {
# VARIABLES
isEmpty(PREFIX):PREFIX = /usr
BINDIR = $$PREFIX/bin
DATADIR = $$PREFIX/share
+ LIBDIR = $$PREFIX/lib/mdictionary
DEFINES += DATADIR=\\\"$$DATADIR\\\" \
- PKGDATADIR=\\\"$$PKGDATADIR\\\"
+ PKGDATADIR=\\\"$$PKGDATADIR\\\" \
+ LIBDIR=\\\"$$LIBDIR\\\"
# MAKE INSTALL
INSTALLS += target \
desktop \
- icon64
+ icon64 \
+ bookmarks \
+ service
target.path = $$BINDIR
maemo5 {
desktop.path = $$DATADIR/applications/hildon
}
desktop.files += ../../../data/other/$${TARGET}.desktop
icon64.files += ../../../data/icons/64x64/$${TARGET}.png
+ bookmarks.path = $$LIBDIR
+ bookmarks.files += ../../../data/icons/16x16/staron.png
+ service.path = $$DATADIR/dbus-1/services
+ service.files += ../../../data/other/com.comarch.mdictionary.service
}
RESOURCES += xslt2.qrc
--- /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 "DBusAdapter.h"
+#include <QDebug>
+
+DBusAdapter::DBusAdapter(MainWindow *w):
+ QDBusAbstractAdaptor(w)
+{
+ mainWindow = w;
+}
+
+void DBusAdapter::search(QString word) {
+ showApplication();
+ mainWindow->search(word);
+}
+
+void DBusAdapter::showApplication() {
+ if(!mainWindow->isActiveWindow())
+ mainWindow->activateWindow();
+}
--- /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 DBUSADAPTER_H
+#define DBUSADAPTER_H
+
+#include <QDBusAbstractAdaptor>
+#include "MainWindow.h"
+
+class DBusAdapter : public QDBusAbstractAdaptor
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "com.comarch.mdictionary")
+public:
+ explicit DBusAdapter(MainWindow* w);
+
+public slots:
+ void search(QString);
+ void showApplication();
+
+private:
+ MainWindow* mainWindow;
+
+};
+
+#endif // DBUSADAPTER_H
*******************************************************************************/
-//Created by Mateusz Półrola
+//! \file MainWindow.cpp
+//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
#include "MainWindow.h"
#include <QtGui>
setExactSearch(false);
- setWindowTitle("mDictionary");
-
showMaximized();
}
setAttribute(Qt::WA_Maemo5StackedWindow);
#endif
- //translationWidget is another stacked window, so we don't add it to layout
- //only create it with this widget as parent
- translationWidget = new TranslationWidget(this);
+ setWindowIcon(QIcon(":/icons/64x64/mdictionary.png"));
+ setWindowTitle("mDictionary");
+
+ /*translationWidget is another stacked window, so we don't add it to
+ layout only create it with this widget as parent
+ it must be created as first object in main window, otherwise sometimes
+ when app starts in maemo, when trying to set stacked window attribure
+ it segfaults*/
+ translationWidget = new TranslationWidget(this);
mainLayout = new QVBoxLayout();
QWidget* w = new QWidget();
w->setLayout(mainLayout);
setCentralWidget(w);
+
menuBar = new QMenuBar();
setMenuBar(menuBar);
+ initializeSearchWidgets();
+
+ initializeMenu();
+
+ notifyManager = new NotifyManager(this);
+}
+
+void MainWindow::initializeSearchWidgets() {
searchBarWidget = new SearchBarWidget();
wordListWidget = new WordListWidget();
welcomeScreenWidget = new WelcomeScreenWidget();
-
#ifdef Q_WS_MAEMO_5
- //At start we set widget as welcome screen widget
+ //At start we set widget as welcome screen widget
mainLayout->addWidget(welcomeScreenWidget);
mainLayout->addWidget(searchBarWidget, 0, Qt::AlignBottom);
#else
splitter->addWidget(wordListWidget);
splitter->addWidget(welcomeScreenWidget);
splitter->setStretchFactor(1, 150);
+
mainLayout->addWidget(splitter);
mainLayout->addWidget(searchBarWidget);
#endif
+}
+void MainWindow::initializeMenu() {
+ initializeMenuWidgets();
+#ifdef Q_WS_MAEMO_5
+ menuWidget = new MenuWidget(this);
+
+ menuWidget->addSubMenu(tr("Settings"), settingsWidget);
+ menuWidget->addSubMenu(tr("Dictionaries"), dictManagerWidget);
+ menuWidget->addSubMenu(tr("Bookmarks"), bookmarksWidget);
+ menuWidget->addSubMenu(tr("About"), aboutWidget);
+
+ menuBar->addAction(menuWidget);
+#else
+ dictionariesAction = menuBar->addAction(tr("Dictionaries"));
+ connect(dictionariesAction, SIGNAL(triggered()),
+ dictManagerWidget, SLOT(show()));
+
+ settingsAction = menuBar->addAction(tr("Settings"));
+ connect(settingsAction, SIGNAL(triggered()),
+ settingsWidget, SLOT(show()));
+
+ QMenu* m = 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 = menuBar->addAction(tr("About"));
+ connect(aboutAction, SIGNAL(triggered()),
+ aboutWidget, SLOT(show()));
+#endif
+}
+
+void MainWindow::initializeMenuWidgets() {
dictManagerWidget = new DictManagerWidget(this);
dictManagerWidget->hide();
aboutWidget = new AboutWidget(this);
aboutWidget->hide();
-
- //creating menus
-
- #ifdef Q_WS_MAEMO_5
- menuWidget = new MenuWidget(this);
- menuWidget->addSubMenu(tr("Settings"), settingsWidget);
- menuWidget->addSubMenu(tr("Dictionaries"), dictManagerWidget);
- menuWidget->addSubMenu(tr("Bookmarks"), bookmarksWidget);
- menuWidget->addSubMenu(tr("About"), aboutWidget);
- menuBar->addAction(menuWidget);
- #else
- dictionariesAction = menuBar->addAction(tr("Dictionaries"));
- connect(dictionariesAction, SIGNAL(triggered()),
- dictManagerWidget, SLOT(show()));
-
- settingsAction = menuBar->addAction(tr("Settings"));
- connect(settingsAction, SIGNAL(triggered()),
- settingsWidget, SLOT(show()));
-
- QMenu* m = 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 = menuBar->addAction(tr("About"));
- connect(aboutAction, SIGNAL(triggered()),
- aboutWidget, SLOT(show()));
- #endif
}
void MainWindow::closeEvent(QCloseEvent *event) {
//request to stop all searches and close app
- Q_EMIT quit();
- event->accept();
+ Q_EMIT quit();
+ event->accept();
}
-bool MainWindow::exactSearch() {
+bool MainWindow::isInExactSearch() {
return _exactSearch;
}
_exactSearch = exact;
}
-void MainWindow::setSearchString(QString word) {
+void MainWindow::setExactSearchString(QString word) {
searchString = word;
}
void MainWindow::wordListReady() {
//gets results from backbone
- QMultiHash<QString, Translation*> res = backbone->result();
+ QMultiHash<QString, Translation*> backboneResult = backbone->result();
QHash<QString, QList<Translation*> > searchResult;
#ifdef Q_WS_MAEMO_5
- //switch welcome screen with word list
- if(!wordListWidget->isVisible()) {
- int i = mainLayout->indexOf(welcomeScreenWidget);
- QBoxLayout* l = (QBoxLayout*)(mainLayout);
- l->removeWidget(welcomeScreenWidget);
- welcomeScreenWidget->deleteLater();
- l->insertWidget(0, wordListWidget);
- }
+ hideWelcomeScreen();
#endif
//if nothing was found
- if(res.count() == 0) {
+ if(backboneResult.count() == 0) {
showNotify(Notify::Info, tr("Can't find any matching words"));
//show empty list to remove results of old search
else {
//find translations of the same key word
QMultiHash<QString, Translation*>::iterator i;
- for(i = res.begin(); i != res.end(); i++) {
+ for(i = backboneResult.begin(); i != backboneResult.end(); i++) {
searchResult[i.key()].push_back(i.value());
}
+ //show search results
+ Q_EMIT showWordList(searchResult);
- if(!exactSearch()) {
- Q_EMIT showWordList(searchResult);
- }
- else {
- #ifndef Q_WS_MAEMO_5
- //on desktop we show word list in exact search
- Q_EMIT showWordList(searchResult);
- #endif
- bool foundExactMatch = false;
- QHash<QString, QList<Translation*> >::iterator j;
- for(j = searchResult.begin(); j != searchResult.end(); j++) {
- if(j.key() == searchString && !foundExactMatch) {
- foundExactMatch = true;
- Q_EMIT searchTranslations(j.value());
- break;
- }
- }
- if(!foundExactMatch) {
+ if(isInExactSearch()) {
+ QList<Translation*> exactTranslation;
+ if(checkExactSearch(searchResult, exactTranslation)) {
+ qDebug()<<exactTranslation.count();
+ Q_EMIT searchTranslations(exactTranslation);
+ }
+ else {
showNotify(Notify::Info,
tr("Can't find exactly matching word"));
-
- Q_EMIT showWordList(searchResult);
}
+ setExactSearch(false);
}
}
- setExactSearch(false);
+}
+
+bool MainWindow::checkExactSearch(
+ QHash<QString, QList<Translation *> > searchResult,
+ QList<Translation *> &found) {
+
+ bool foundExactMatch = false;
+ QHash<QString, QList<Translation*> >::iterator j;
+ for(j = searchResult.begin(); j != searchResult.end(); j++) {
+ if(j.key().toLower() == searchString.toLower()
+ && !foundExactMatch) {
+ found = j.value();
+ return true;
+ }
+ }
+ return false;
}
void MainWindow::translationsReady() {
#ifndef Q_WS_MAEMO_5
+ hideWelcomeScreen();
+ #endif
+
+ Q_EMIT showTranslation(backbone->htmls());
+ notifyManager->screenChanged();
+}
+
+
+void MainWindow::hideWelcomeScreen() {
+#ifdef Q_WS_MAEMO_5
+ //switch welcome screen with word list
+ if(!wordListWidget->isVisible()) {
+ mainLayout->removeWidget(welcomeScreenWidget);
+ welcomeScreenWidget->deleteLater();
+
+ mainLayout->insertWidget(0, wordListWidget);
+ }
+#else
//switch welcome screen with translation widget
if(!translationWidget->isVisible()) {
- QBoxLayout* l = (QBoxLayout*)(mainLayout);
- QSplitter* s = (QSplitter*)((QWidgetItem*)(l->itemAt(0))->widget());
- s->insertWidget(1,translationWidget);
- s->setStretchFactor(1, 150);
+ splitter->insertWidget(1,translationWidget);
+ splitter->setStretchFactor(1, 150);
welcomeScreenWidget->deleteLater();
}
- #endif
-
- Q_EMIT showTranslation(backbone->htmls());
+#endif
}
QList<CommonDictInterface*> MainWindow::getPlugins() {
void MainWindow::searchExact(QString word) {
setExactSearch(true);
- //searching with searchBar, not directly by emitting searchWordList(),
- //because it will set search word in searchBar's edit line
- //this function is only used by history and when searching from attributes
searchBarWidget->search(word);
}
+void MainWindow::searchDelay(QString word) {
+ searchBarWidget->searchDelay(word);
+}
+
-void MainWindow::breakSearching() {
+
+
+void MainWindow::searchingInterrupted() {
//make sure to unset exact search mode
setExactSearch(false);
}
#ifndef Q_WS_MAEMO_5
setExactSearch(true);
#endif
- searchBarWidget->searchDelay(next);
+ searchDelay(next);
}
}
setExactSearch(true);
#endif
QString prev = backbone->history()->previous();
- searchBarWidget->searchDelay(prev);
+ searchDelay(prev);
}
}
}
void MainWindow::showHistory(QPoint p) {
+
HistoryListDialog historyDialog(backbone->history()->list(), searchBarWidget);
#ifndef Q_WS_MAEMO_5
void MainWindow::showNotify(Notify::NotifyType type, QString text) {
+ notifyManager->showNotify(type, text);
+}
- switch(type) {
- case Notify::Info:
- #ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(0,
- text,
- QMaemo5InformationBox::DefaultTimeout);
- #else
- QMessageBox::information(this, tr("Information"), text);
- #endif
- break;
+void MainWindow::connectBackbone() {
+
+ connect(this, SIGNAL(searchWordList(QString)),
+ this, SIGNAL(setBusy()));
+
+ connect(this, SIGNAL(searchTranslations(QList<Translation*>)),
+ this, SIGNAL(setBusy()));
+
+ connect(this, SIGNAL(stopSearching()),
+ this, SIGNAL(setIdle()));
+
+ connect(this, SIGNAL(searchWordList(QString)),
+ this, SLOT(setExactSearchString(QString)));
+
+ connect(this, SIGNAL(searchTranslations(QList<Translation*>)),
+ this, SLOT(addToHistory(QList<Translation*>)));
- case Notify::Warning:
- #ifndef Q_WS_MAEMO_5
- QMessageBox::warning(this, tr("Warning"), text);
- break;
- #endif
- case Notify::Error:
- #ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(0,
- text,
- QMaemo5InformationBox::NoTimeout);
- #else
- QMessageBox::critical(this, tr("Error"), text);
- #endif
- break;
- }
-}
-void MainWindow::connectBackbone() {
connect(this, SIGNAL(quit()),
backbone, SLOT(quit()));
backbone, SLOT(stopSearching()));
connect(this, SIGNAL(stopSearching()),
- this, SLOT(breakSearching()));
+ this, SLOT(searchingInterrupted()));
connect(this, SIGNAL(addNewDictionary(CommonDictInterface*)),
backbone, SLOT(addDictionary(CommonDictInterface*)));
connect(backbone, SIGNAL(notify(Notify::NotifyType,QString)),
this, SLOT(showNotify(Notify::NotifyType,QString)));
-
-
-
-
- connect(this, SIGNAL(searchWordList(QString)),
- this, SIGNAL(setBusy()));
-
- connect(this, SIGNAL(searchTranslations(QList<Translation*>)),
- this, SIGNAL(setBusy()));
-
- connect(this, SIGNAL(stopSearching()),
- this, SIGNAL(setIdle()));
-
- connect(this, SIGNAL(searchWordList(QString)),
- this, SLOT(setSearchString(QString)));
-
- connect(this, SIGNAL(searchTranslations(QList<Translation*>)),
- this, SLOT(addToHistory(QList<Translation*>)));
-
-
}
void MainWindow::connectSearchBar() {
*******************************************************************************/
//! \file MainWindow.h
-//! \brief Implements interface for GUI
//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
#ifndef MAINWINDOW_H
#include "BookmarksWidget.h"
#include "WelcomeScreenWidget.h"
#include "AboutWidget.h"
+#include "NotifyManager.h"
//! Implements interface for GUI
/*!
- Creates all of GUI subcomponents, and connects all GUI interface signals with
- suitable backbone signals and slots. Only this class has direct access to
- backbone object. It manages all requests of subcomponents e. g. searching of
- given word, displaying history, removing dictionary.
+ Creates all of GUI subcomponents, and connects all GUI interface signals
+ with suitable backbone signals and slots.
+ Only this class has direct access to backbone object.
+ It manages all requests of subcomponents e. g. searching of given word,
+ displaying history, removing dictionary.
It also provide data from backbone to subcomponents e. g. result of search.
*/
class MainWindow : public GUIInterface
/*!
\param backbone object which will be doing all searches and returning data
\param parent parent widget of this window
- */
-
- explicit MainWindow(Backbone* backbone, QWidget *parent = 0);
+ */
+ MainWindow(Backbone* backbone, QWidget *parent = 0);
~MainWindow();
//! Returns all loaded dictionaries with infromation about that they are
/*!
\return Hash of pointers to dictionary and boolean flag indicating if
dictionary is active
- */
+ */
QHash<CommonDictInterface*, bool> getDictionaries();
//! Returns all loaded plugins
/*!
\return List of pointers to plugins
- */
+ */
QList<CommonDictInterface*> getPlugins();
//! Indicates if GUI is in exact search mode.
- /*! When GUI is in exact search mode it searches for word, and
- if it finds exactly matching translation it directly displays it, without
- displaying matching word list. This mode is used for browsing search
- history and searching words from application arguments.
+ /*! When GUI is in exact search mode it searches for word, and if it
+ finds exactly matching translation it displaying matching words list
+ and then directly displays translation of first exactly matched word.
+ This mode is used for browsing search history and searching words
+ from application arguments.
\returns flag indicating if GUI is in exact search mode
+ \sa setExactSearch()
+ \sa setExactSearchString()
*/
- bool exactSearch();
-
- //! Sets GUI exact search mode.
- /*! When GUI is in exact search mode it searches for word, and
- if it finds exactly matching translation it directly displays it, without
- displaying matching word list. This mode is used for browsing search
- history and searching words from application arguments.
- \param exactSearch flag indicating if GUI will be in exact search mode
- \sa exactSearch()
- */
- void setExactSearch(bool);
+ bool isInExactSearch();
- //! Returns current settings.
+ //! Returns current application settings.
/*!
\returns Settings object containing current application settings
- */
+ */
Settings* settings();
//! Sets new settings.
/*!
\param Settings object containing new application settings
- */
+ */
void setSettings(Settings*);
//! Searches in exact mode for given word
/*!
GUI will be automatically set into exact search mode, and after search or
- break will be unset from exact search mode.
+ when user break the search it will be unset from exact search mode.
\param word which will be searched in dictionaries
- */
+ \sa search()
+ */
void searchExact(QString);
//! Search for given word
/*!
+ It sets passed word in line edit of search bar and search for given word.
\param word which will be searched in dictionaries
- */
+ \sa SearchBarWidget
+ \sa searchExact()
+ */
void search(QString);
+ //! Start searching for given word after 500 ms delay
+ /*!
+ After times up it sets passed word in line edit of search bar and search
+ for given word.
+ \param word which will be searched in dictionaries
+ \sa SearchBarWidget
+ \sa searchExact()
+ \sa search()
+ */
+ void searchDelay(QString);
+
+ //! Sets string for exact search
+ /*!
+ Sets string for which current search is ongoing, is used to find exact
+ word when GUI is in search exact mode.
+ */
+ void setExactSearchString(QString);
+
+ //! Sets GUI exact search mode.
+ /*! When GUI is in exact search mode it searches for word, and if it
+ finds exactly matching translation it displaying matching words list
+ and then directly displays translation of first exactly matched word.
+ This mode is used for browsing search history and searching words
+ from application arguments.
+ \param exactSearch flag indicating if GUI will be in exact search mode
+ \sa isInExactSearch()
+ \sa setExactSearchString()
+ */
+ void setExactSearch(bool);
//! Gets word list from backbone and prepares received list to display
/*!
Checks if received list is empty, in that case displays suitable
- information. If GUI is in exact search mode it will search for exact
- word in received list, and if word is found it will emit signal to
- display its translation. Otherwise it will display list of matching
- words and show suitable information.
- \sa exactSearch()
+ information. Otherwise it merge results of the same key word and emit
+ signal to display word list.
+ If GUI is in exact search mode it will search for exact word in received
+ list and if any of found words match exacly the word passed to
+ searchExact() method.
+ \sa isInExactSearch()
+ \sa searchExact()
\sa showTranslation()
+ \sa setExactSearchString()
*/
void wordListReady();
void addToHistory(QList<Translation*>);
//! Shows history dialog
+ /*!
+ In meamo shows dialog with history.
+ In desktop shows popup containing history, which bottom edge is on the
+ same height as passed point.
+ \param point on screen when popup has to show
+ */
void showHistory(QPoint);
//! Shows translation of next word in history
/*!
It will work only if there is available next word in history.
- Translation of word is searched with searchExact() function
+ Translation of word is searched with searchDelay() function.
+ On maemo search is in normal mode, on desktop in exact search mode.
+ \sa searchDelay()
\sa searchExact()
*/
void historyNext();
//! Shows translation of previous word in history
/*!
It will work only if there is available previous word in history.
- Translation of word is searched with searchExact() function
+ Translation of word is searched with searchDelay() function.
+ On maemo search is in normal mode, on desktop in exact search mode.
+ \sa searchDelay()
\sa searchExact()
*/
void historyPrev();
- void showNotify(Notify::NotifyType, QString);
+ //! Shows notify to user
+ /*!
+ It shows different type of notyfies as informations, warnings and errors.
+ In maemo they are represented as notes, on desktop as message boxes.
+ \param type type of notify
+ \param message notify message
+ */
+ void showNotify(Notify::NotifyType type, QString message);
private Q_SLOTS:
- //! Sets string for which current search is ongoing, is used to find exact
- //! word when GUI is in search exact mode.
- void setSearchString(QString);
-
- //! Disables menu when search is ongoing
+ //! Disables menu
void disableMenu();
//! Enables menu
//! When user breaks searching it makes sure that exact search mode will be
//! disabled
- void breakSearching();
+ void searchingInterrupted();
//! Asks for confirmation when user click on "delete all bookmarks"
void removeBookmarks();
-
protected:
- /*! When user wants to close application, we first send signal to stop all
+ /*!
+ When user wants to close application, we first send signal to stop all
ongoing searches.
*/
void closeEvent(QCloseEvent *);
Backbone* backbone;
void initializeUI();
+ void initializeSearchWidgets();
+ void initializeMenu();
+ void initializeMenuWidgets();
+
+ void hideWelcomeScreen();
+
+ bool checkExactSearch(QHash<QString, QList<Translation*> > searchResult,
+ QList<Translation*> &found);
SearchBarWidget* searchBarWidget;
QWidget* translationWidget;
BookmarksWidget* bookmarksWidget;
QWidget* welcomeScreenWidget;
AboutWidget* aboutWidget;
- QVBoxLayout* mainLayout;
QMenuBar* menuBar;
+ QVBoxLayout* mainLayout;
+ NotifyManager* notifyManager;
#ifndef Q_WS_MAEMO_5
QSplitter* splitter;
--- /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 "NotifyManager.h"
+#include <QMessageBox>
+#ifdef Q_WS_MAEMO_5
+ #include <QMaemo5InformationBox>
+#endif
+#include <QDebug>
+#include <QLabel>
+
+NotifyManager::NotifyManager(QObject *parent) :
+ QObject(parent)
+{
+}
+
+void NotifyManager::notifyClosed() {
+ QObject* dialog = QObject::sender();
+
+ QHash<QString, QDialog*>::Iterator it;
+
+ for(it = activeNotifies.begin(); it != activeNotifies.end(); it++) {
+ if(it.value() == dialog) {
+ activeNotifies.remove(it.key());
+ return;
+ }
+ }
+}
+
+void NotifyManager::screenChanged() {
+ QHash<QString, QDialog*>::Iterator it;
+
+ for(it = activeNotifies.begin(); it != activeNotifies.end(); it++) {
+ it.value()->hide();
+ it.value()->show();
+ }
+}
+
+void NotifyManager::showNotify(Notify::NotifyType type, QString text) {
+
+ if(activeNotifies.contains(text)) {
+ return;
+ }
+
+ #ifdef Q_WS_MAEMO_5
+ QMaemo5InformationBox* mbox =
+ new QMaemo5InformationBox(0);
+
+ QLabel* infoLabel = new QLabel(text);
+ infoLabel->setAlignment(Qt::AlignCenter);
+ infoLabel->setWordWrap(true);
+
+ mbox->setWidget(infoLabel);
+ #else
+ QMessageBox* mbox =
+ new QMessageBox(qobject_cast<QWidget*>(this->parent()));
+
+ #endif
+
+
+ switch(type) {
+
+ case Notify::Info:
+ #ifdef Q_WS_MAEMO_5
+ mbox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
+ #else
+ mbox->setText(text);
+ mbox->setWindowTitle(tr("Information"));
+ mbox->setIcon(QMessageBox::Information);
+
+ #endif
+ break;
+
+ case Notify::Warning:
+ #ifndef Q_WS_MAEMO_5
+ mbox->setText(text);
+ mbox->setWindowTitle(tr("Warning"));
+ mbox->setIcon(QMessageBox::Warning);
+ break;
+ #endif
+
+ case Notify::Error:
+ #ifdef Q_WS_MAEMO_5
+ mbox->setTimeout(QMaemo5InformationBox::NoTimeout);
+ #else
+ mbox->setText(text);
+ mbox->setWindowTitle(tr("Error"));
+ mbox->setIcon(QMessageBox::Critical);
+ #endif
+ break;
+ }
+
+ activeNotifies.insert(text, mbox);
+ connect(mbox, SIGNAL(finished(int)), this, SLOT(notifyClosed()));
+ mbox->exec();
+}
--- /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 NOTIFYMANAGER_H
+#define NOTIFYMANAGER_H
+
+#include <QObject>
+#include <QHash>
+#include <QString>
+#include <QDialog>
+#include "../../includes/Notify.h"
+
+class NotifyManager : public QObject
+{
+ Q_OBJECT
+public:
+ NotifyManager(QObject *parent = 0);
+
+public slots:
+ void showNotify(Notify::NotifyType type, QString text);
+ void screenChanged();
+
+private slots:
+ void notifyClosed();
+
+private:
+ QHash<QString, QDialog*> activeNotifies;
+};
+
+#endif // NOTIFYMANAGER_H
#include <QtGui>
#include "TranslationTextEdit.h"
+#include "TranslationWidget.h"
TranslationTextEdit::TranslationTextEdit(QWidget *parent) :
- QTextEdit(parent)
+ QWebView(parent)
{
+ realParent = qobject_cast<TranslationWidget*>(parent);
searchSelectedAction = new QAction(tr("Search"), this);
+ copySelectedAction = new QAction(tr("Copy"), this);
+ selectAllAction = new QAction(tr("Select All"), this);
+ setAcceptDrops(false);
+
+ #ifdef Q_WS_MAEMO_5
+ installEventFilter(this);
+ property("kineticScroller").value<QAbstractKineticScroller*>()->
+ setEnabled(true);
+ #endif
+
connect(searchSelectedAction, SIGNAL(triggered()),
this, SIGNAL(search()));
+ connect(page(), SIGNAL(selectionChanged()), this, SLOT(selection()));
}
+
+bool TranslationTextEdit::eventFilter(QObject *, QEvent *e)
+{
+ switch (e->type()) {
+ case QEvent::MouseButtonPress:
+ if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
+ mousePressed = true;
+ break;
+ case QEvent::MouseButtonRelease:
+ if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
+ mousePressed = false;
+ break;
+ case QEvent::MouseMove:
+ if (mousePressed)
+ return true;
+ break;
+ default:
+ break;
+ }
+ return false;
+}
+
+
void TranslationTextEdit::contextMenuEvent(QContextMenuEvent *e) {
- QMenu *menu = createStandardContextMenu(e->pos());
- if(textCursor().selectedText().isEmpty())
+ QMenu *menu = new QMenu;
+ if(selectedText().isEmpty())
searchSelectedAction->setEnabled(false);
else
searchSelectedAction->setEnabled(true);
- menu->addSeparator();
menu->addAction(searchSelectedAction);
+ menu->addSeparator();
+ menu->addAction(pageAction(QWebPage::Copy));
+ menu->addAction(pageAction(QWebPage::SelectAll));
menu->exec(e->globalPos());
delete menu;
e->ignore();
}
+
+
+void TranslationTextEdit::zoomIn() {
+ setZoomFactor(zoomFactor()*1.05);
+ realParent->updateZoom(zoomFactor());
+
+}
+
+void TranslationTextEdit::zoomOut() {
+ setZoomFactor(zoomFactor()*0.95);
+ realParent->updateZoom(zoomFactor());
+}
+
+void TranslationTextEdit::copy() {
+ pageAction(QWebPage::Copy)->trigger();
+}
+
+void TranslationTextEdit::selection() {
+ if(selectedText().size())
+ Q_EMIT copyAvailable(true);
+ else
+ Q_EMIT copyAvailable(false);
+}
+
+
+void TranslationTextEdit::selectAll() {
+ pageAction(QWebPage::SelectAll)->trigger();
+}
+
+
+
#include <QTextEdit>
#include <QAction>
+#include <QWebView>
+#include <QEvent>
-class TranslationTextEdit : public QTextEdit
+class TranslationWidget;
+
+class TranslationTextEdit : public QWebView
{
Q_OBJECT
public:
explicit TranslationTextEdit(QWidget *parent = 0);
+public Q_SLOTS:
+ void zoomIn();
+ void zoomOut();
+ void copy();
+ void selection();
+ void selectAll();
+
Q_SIGNALS:
void search();
+ void copyAvailable(bool);
protected:
void contextMenuEvent(QContextMenuEvent *);
private:
QAction* searchSelectedAction;
+ QAction* copySelectedAction;
+ QAction* selectAllAction;
+ TranslationWidget* realParent;
+ bool mousePressed;
+ bool eventFilter(QObject *, QEvent *);
+
};
#endif // TRANSLATIONTEXTEDIT_H
//Created by Mateusz Półrola
#include "TranslationWidget.h"
-#include "TranslationWidgetAutoResizer.h"
#include <QDebug>
#ifdef Q_WS_MAEMO_5
#include <QtGui/QX11Info>
#endif
TranslationWidget::TranslationWidget(QWidget *parent):
- QScrollArea(parent) {
+ QScrollArea(parent){
+
+ guiinterface = qobject_cast<GUIInterface*>(parent);
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow);
setWindowTitle("mDictionary");
- connect(textEdit, SIGNAL(search()),
+ connect(webkit, SIGNAL(search()),
this, SLOT(searchSelected()));
QFile file(":/xsl/xsl.xsl");
void TranslationWidget::show(QStringList translations) {
- textEdit->clear();
-
showMaximized();
#ifdef Q_WS_MAEMO_5
if(!buttonsInitialized)
initButtons();
#endif
- textEdit->repaint(this->rect());
+ webkit->repaint(this->rect());
update(this->rect());
QString trans;
QString t;
+
foreach(t, translations) {
trans += t + "\n";
}
- QImage image(":icons/16x16/staron.png");
- QTextDocument *document = textEdit->document();
- document->addResource(QTextDocument::ImageResource,
- QUrl("mydata://image.png"), QVariant(image));
+ trans=tr("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + tr("\n <ar>")
+ + trans + tr("\n </ar>");
+ trans=XslConversion(trans);
- QFile cssFile(QDir::homePath() + "/.mdictionary/style.css");
- cssFile.open(QFile::ReadOnly);
- document->addResource(QTextDocument::StyleSheetResource,
- QUrl("mydata://style.css"),
- QVariant(cssFile.readAll()));
+ QString head = "<html><head>";
+ head += "<link rel=\"stylesheet\" type=\"text/css\" " ;
+ head += "href=\"" + QDir::homePath() + "/.mdictionary/style.css";
+ head += "\" /></head><body ondragstart=\"return false\">";
+ trans = head + trans;
+ trans+= "</body></html>";
+ trans.replace("$STAR$", "/usr/lib/mdictionary/staron.png");
- trans=tr("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + tr("\n <ar>") + trans + tr("\n </ar>");
- trans=XslConversion(trans);
- textEdit->insertHtml(trans);
+ webkit->setHtml(trans, QUrl().fromLocalFile("/"));
+
- textEdit->repaint(this->rect());
+ webkit->repaint(this->rect());
update(this->rect());
Q_EMIT updateSize();
void TranslationWidget::initializeUI() {
- textEdit = new TranslationTextEdit(this);
- textEdit->setReadOnly(true);
-
- resizer = new TranslationWidgetAutoResizer(textEdit);
- connect(this, SIGNAL(updateSize()),
- resizer, SLOT(textEditChanged()));
+ webkit = new TranslationTextEdit(this);
+ Settings* set = guiinterface->settings();
+ qreal fac = set->value("zoom").toFloat();
+ if(!fac)
+ fac++;
+ webkit->setZoomFactor(fac);
QWidget*w = new QWidget(this);
verticalLayout = new QVBoxLayout(w);
- verticalLayout->addWidget(textEdit);
-
- textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ verticalLayout->addWidget(webkit);
this->setWidget(w);
this->setWidgetResizable(true);
showButtonsButton->setMinimumSize(searchButton->sizeHint());
connect(zoomInButton, SIGNAL(clicked()),
- textEdit, SLOT(zoomIn()));
+ webkit, SLOT(zoomIn()));
connect(zoomOutButton, SIGNAL(clicked()),
- textEdit, SLOT(zoomOut()));
+ webkit, SLOT(zoomOut()));
connect(searchButton, SIGNAL(clicked()),
this, SLOT(searchSelected()));
connect(copyButton, SIGNAL(clicked()),
- textEdit, SLOT(copy()));
+ webkit, SLOT(copy()));
- connect(textEdit, SIGNAL(copyAvailable(bool)),
+ connect(webkit, SIGNAL(copyAvailable(bool)),
searchButton, SLOT(setEnabled(bool)));
- connect(textEdit, SIGNAL(copyAvailable(bool)),
+ connect(webkit, SIGNAL(copyAvailable(bool)),
copyButton, SLOT(setEnabled(bool)));
connect(selectAllButton, SIGNAL(clicked()),
- textEdit, SLOT(selectAll()));
+ webkit, SLOT(selectAll()));
buttonsInitialized = false;
#ifdef Q_WS_MAEMO_5
hide();
#endif
- Q_EMIT search(textEdit->textCursor().selectedText());
+ Q_EMIT search(webkit->selectedText().toLower());
}
#ifdef Q_WS_MAEMO_5
void TranslationWidget::keyPressEvent(QKeyEvent* event) {
switch (event->key()) {
case Qt::Key_F7:
- textEdit->zoomIn();
+ webkit->zoomIn();
event->accept();
break;
case Qt::Key_F8:
- textEdit->zoomOut();
+ webkit->zoomOut();
event->accept();
break;
}
#endif
+void TranslationWidget::updateZoom(qreal factor) {
+ Settings* set = guiinterface->settings();
+ set->setValue("zoom", QString("%1").arg(factor));
+ guiinterface->setSettings(set);
+}
+
+
#include <QModelIndex>
#include <QtGui>
#include "../backbone/backbone.h"
-#include "TranslationWidgetAutoResizer.h"
#include <QtXml>
#include <QXmlQuery>
#include "TranslationTextEdit.h"
#include <QPropertyAnimation>
+#include "../../includes/GUIInterface.h"
//! Displays translation of word found in dictionaries
/*!
//! Requests to show translation of word list passed as parameter.
void show(QStringList);
+ //! Updates users zoom preferences and sends its to backbone to be saved
+ void updateZoom(qreal);
+
protected:
#ifdef Q_WS_MAEMO_5
void keyPressEvent(QKeyEvent *);
QString XslConversion(QString translation);
QToolButton* zoomInToolButton;
QToolButton* zoomOutToolButton;
- TranslationTextEdit *textEdit;
+ TranslationTextEdit *webkit;
QString xslt;
#ifdef Q_WS_MAEMO_5
QToolButton* zoomInButton;
#endif
QVBoxLayout *verticalLayout;
QHBoxLayout* horizontalLayout;
- TranslationWidgetAutoResizer* resizer;
+ GUIInterface* guiinterface;
void initializeUI();
};
+++ /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 TranslationWidgetAutoResizer.h
-//! \brief Implements translation widget auto resizer
-//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>a
-
-#ifndef TRANSLATIONWIDGETAUTORESIZER_H
-#define TRANSLATIONWIDGETAUTORESIZER_H
-
-#include <QtGui/qtextedit.h>
-class TranslationWidgetAutoResizer : public QObject
-{
- Q_OBJECT
-
-public:
- TranslationWidgetAutoResizer(QWidget *parent) :QObject(parent),
- textEdit(qobject_cast<QTextEdit* >((parent))),
- edit(qobject_cast<QFrame* >((parent))) {
-
- connect(parent, SIGNAL(textChanged()), this,
- SLOT(textEditChanged()));
- connect(parent, SIGNAL(cursorPositionChanged()),
- this, SLOT(textEditChanged()));
- }
-
-public Q_SLOTS:
- inline void textEditChanged();
-
-private:
- QTextEdit *textEdit;
- QFrame *edit;
-};
-
-void TranslationWidgetAutoResizer::textEditChanged() {
- QTextDocument *doc = textEdit->document();
-
- QSize s = doc->size().toSize();
-
- const QRect fr = edit->frameRect();
- const QRect cr = edit->contentsRect();
-
- edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height()) -
- 1));
-
- edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height()) -
- 1));
-}
-
-#endif // TRANSLATIONWIDGETAUTORESIZER_H
#include "../backbone/backbone.h"
#include "../../includes/translation.h"
#include "../../includes/Notify.h"
+#include "DBusAdapter.h"
#include <QDebug>
+#include <QDBusConnection>
+
QStringList parseParameters(int argc, char *argv[]) {
Backbone backbone;
MainWindow w(&backbone);
+
+ DBusAdapter* adapter = new DBusAdapter(&w);
+
+ QDBusConnection::sessionBus().registerObject("/mainWindow",
+ &w);
+ QDBusConnection::sessionBus().registerService("com.comarch.mdictionary");
+
+
w.show();
+
if(search.count() > 0) {
w.setExactSearch(true);
w.searchExact(search[0]);
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="mydata://style.css" />
- </head>
- <body>
<table border="1" width="100%">
<xsl:for-each select="ar/dict">
<xsl:apply-templates/>
</xsl:for-each>
</table>
- </body>
- </html>
</xsl:template>
<xsl:template match="info">
<tr>
<th class="info">
<xsl:if test="@bookmark = 'true'">
- <img src="mydata://image.png"/>
+ <img src="$STAR$" width="16" height="16"/>
</xsl:if>
<xsl:value-of select="."/> <!-- <img src="{$path}"/> -->
</th>
<RCC>
<qresource prefix="/xsl">
- <file>xsl.xsl</file>
<file>style.css</file>
+ <file>xsl.xsl</file>
</qresource>
<qresource prefix="/config">
<file>mdictionary.config</file>
--- /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 "MainWidget.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <QtGui/QX11Info>
+#include <QtDBus/QDBusMessage>
+#include <QtDBus/QDBusPendingCall>
+#include <QList>
+#include <QDebug>
+
+
+HomeWidget::HomeWidget(QWidget *parent):
+ QWidget(parent)
+{
+ //setting application name, it will use it later to set home applet id
+ QCoreApplication::instance()->setApplicationName(
+ "mDictionary desktop widget");
+
+ //setting this attribute to get transparent backgorund
+ setAttribute(Qt::WA_TranslucentBackground);
+
+ initializeX11();
+
+ initializeUI();
+}
+
+
+void HomeWidget::initializeUI() {
+
+
+ horizontalLayout = new QHBoxLayout;
+ setLayout(horizontalLayout);
+
+
+ searchStringLineEdit = new QLineEdit;
+
+ searchButton = new QPushButton(tr("Search"));
+ searchButton->setMaximumHeight(60);
+
+ logo = new QToolButton();
+ logo->setIcon(QIcon(":/icons/64x64/mdictionary.png"));
+
+ horizontalLayout->addWidget(logo);
+ horizontalLayout->addWidget(searchStringLineEdit);
+ horizontalLayout->addWidget(searchButton);
+ horizontalLayout->setContentsMargins(10,10,10,10);
+
+ connect(searchStringLineEdit, SIGNAL(returnPressed()),
+ this, SLOT(search()));
+
+ connect(searchButton, SIGNAL(clicked()),
+ this, SLOT(search()));
+
+ connect(logo, SIGNAL(clicked()),
+ this, SLOT(logoClicked()));
+
+
+ setMinimumHeight(100);
+ setMaximumHeight(100);
+}
+
+void HomeWidget::initializeX11() {
+
+ Atom winTypeAtom = XInternAtom(QX11Info::display(),
+ "_NET_WM_WINDOW_TYPE",
+ false);
+
+ Atom homeAppletAtom = XInternAtom(QX11Info::display(),
+ "_HILDON_WM_WINDOW_TYPE_HOME_APPLET",
+ false);
+
+ Atom appletIDAtom = XInternAtom(QX11Info::display(),
+ "_HILDON_APPLET_ID",
+ false);
+
+ Atom utf8Atom = XInternAtom(QX11Info::display(),
+ "UTF8_STRING",
+ false);
+
+
+ // Set window type to home applet
+ XChangeProperty(QX11Info::display(), winId(), winTypeAtom,
+ XA_ATOM, 32, PropModeReplace,
+ (unsigned char *) &homeAppletAtom, 1);
+
+ // Applet id will be the same as application name
+ QByteArray id (
+ QCoreApplication::instance()->applicationName().remove(' ').toUtf8());
+
+
+ XChangeProperty(QX11Info::display(), winId(), appletIDAtom, utf8Atom, 8,
+ PropModeReplace, (unsigned char *)id.constData(),
+ id.length());
+}
+
+void HomeWidget::search() {
+ if(searchStringLineEdit->text().isEmpty()) return;
+
+ QDBusMessage message =
+ QDBusMessage::createMethodCall("com.comarch.mdictionary",
+ "/mainWindow",
+ "com.comarch.mdictionary",
+ "search");
+
+ QList<QVariant> args;
+ args.append(searchStringLineEdit->text());
+ message.setArguments(args);
+
+ QDBusConnection::sessionBus().send(message);
+}
+
+void HomeWidget::logoClicked() {
+ QDBusMessage message =
+ QDBusMessage::createMethodCall("com.comarch.mdictionary",
+ "/mainWindow",
+ "com.comarch.mdictionary",
+ "showApplication");
+ QDBusConnection::sessionBus().send(message);
+}
+
+
+
+void HomeWidget::paintEvent(QPaintEvent *event) {
+ //custom painting of rounded corners
+ QPainter p(this);
+ p.setBrush(QColor(0, 0, 0, 255));
+
+ p.setPen(Qt::NoPen);
+
+ p.drawRoundedRect(rect(), 25, 25);
+
+ p.end();
+
+ QWidget::paintEvent(event);
+}
--- /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 MainWidget.cpp
+//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
+
+#ifndef MAINWIDGET_H
+#define MAINWIDGET_H
+
+#include <QWidget>
+#include <QtGui>
+#include <QtDBus/QDBusConnection>
+#include <QPushButton>
+
+//! Implements widget for maemo that allows user to quick search using mdictionary right of home screen.
+/*!
+ Shows tool button with logo of mDictionary which can start application.
+ In line edit user inputs word, and using button next to it or by pressing enter, widget start mDictionary already witch started search for given word.
+ If mDictionary is already running in background it will show the program.
+ */
+class HomeWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ HomeWidget(QWidget *parent = 0);
+
+private slots:
+ void search();
+ void logoClicked();
+
+protected:
+ /*! Reimplemented paintEvent to display rounded corners with transparency */
+ void paintEvent(QPaintEvent *);
+
+private:
+ /*! Initializes ui of widget*/
+ void initializeUI();
+
+ /*! Initializes X11 to set application type as home widget*/
+ void initializeX11();
+
+
+ QLineEdit* searchStringLineEdit;
+ QPushButton* searchButton;
+ QToolButton* logo;
+ QHBoxLayout* horizontalLayout;
+};
+
+#endif // MAINWIDGET_H
--- /dev/null
+# -------------------------------------------------
+# Project created by QtCreator 2010-08-03T08:54:27
+# -------------------------------------------------
+QT += core gui dbus
+
+TARGET = mdictionarywidget
+
+TEMPLATE = app
+
+MDICT_BINDIR = $$[MDICT_BINDIR]
+
+isEmpty(MDICT_BINDIR):MDICT_BINDIR = .
+
+DESTDIR = $${MDICT_BINDIR}
+
+
+unix {
+ # VARIABLES
+ isEmpty(PREFIX):PREFIX = /usr
+ BINDIR = $$PREFIX/bin
+ DATADIR = $$PREFIX/share
+ DEFINES += DATADIR=\\\"$$DATADIR\\\" \
+ PKGDATADIR=\\\"$$PKGDATADIR\\\"
+
+ # MAKE INSTALL
+ INSTALLS += target \
+ desktop
+
+ target.path = /usr/lib/hildon-desktop
+
+ desktop.path = $$DATADIR/applications/hildon-home
+ desktop.files += ../../../data/other/$${TARGET}.desktop
+}
+
+SOURCES += \
+ main.cpp \
+ MainWidget.cpp
+
+HEADERS += \
+ MainWidget.h
+
+RESOURCES += \
+ ../../../data/icons/gui.qrc
--- /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 "MainWidget.h"
+#include <QtGui/QApplication>
+#include <X11/extensions/Xrender.h>
+
+
+int main(int argc, char *argv[]) {
+
+ Display *dpy = XOpenDisplay(0); // open default display
+ if (!dpy) {
+ qWarning("Cannot connect to the X server");
+ exit(1);
+ }
+
+ QApplication a(dpy, argc, argv);
+ QApplication::setOrganizationName("Comarch S.A.");
+ QApplication::setOrganizationDomain("comarch.com");
+ QApplication::setApplicationName("mDictionaryWidget");
+
+ HomeWidget w;
+
+ w.show();
+
+ return a.exec();
+}
_langFrom=languages.key(pluginSettings->value("lang_from"));
}
+ setMinimumHeight(370);
#ifdef Q_WS_MAEMO_5
changeLangButton=new QPushButton(
tr("To: ") + _langTo);
verticalLayout->addWidget(infoLabel);
+
langFromComboBox = new QComboBox;
langToComboBox = new QComboBox;
langToComboBox->setCurrentIndex(actualLangTo);
langFromComboBox->setCurrentIndex(actualLangFrom);
+
+
setWindowTitle(tr("Google Settings"));
verticalLayout->addWidget(connectInfoLabel);
+
langFromLayout->addWidget(langFromLabel);
langFromLayout->addWidget(langFromComboBox);
langToLayout->addWidget(langToLabel);
langToLayout->addWidget(langToComboBox);
+
+
langLayout->addLayout(langFromLayout);
langLayout->addLayout(langToLayout);
changelangLayout->addLayout(langLayout);
connect(saveButton, SIGNAL(clicked()),
this, SLOT(accept()));
+
+
connect(langFromComboBox, SIGNAL(activated(int)),
this, SLOT(activatedFrom(int)));
connect(langToComboBox, SIGNAL(activated(int)),
this, SLOT(activatedTo(int)));
+
+
connect(changeLangButton, SIGNAL(clicked()),
this, SLOT(changeLangButtonClicked()));
}
+
void GoogleSettingsDialog::activatedFrom(int index) {
- _langFrom=langFromComboBox->itemText(index);
+ _langFrom=langFromComboBox->itemText(index);
}
void GoogleSettingsDialog::activatedTo(int index) {
_langTo=langToComboBox->itemText(index);
}
+
void GoogleSettingsDialog::changeLangButtonClicked() {
+
int tempIndexTo=langToComboBox->currentIndex();
QString tempLangTo=_langTo;
langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
langFromComboBox->setCurrentIndex(tempIndexTo);
_langTo=_langFrom;
_langFrom=tempLangTo;
+
}
QString GoogleSettingsDialog::langFrom() {
//! \return destination language code iso 639-2
QString langTo();
-public slots:
+private slots:
void activatedFrom(int);
void activatedTo(int);
void changeLangButtonClicked();
+
private:
QLabel* infoLabel;
QLabel* langFromLabel;
QLabel* connectInfoLabel;
QPushButton* saveButton;
QPushButton* changeLangButton;
+
+
QComboBox *langFromComboBox;
QComboBox *langToComboBox;
#-------------------------------------------------
QT += core xml gui network
-
+maemo5:QT += maemo5
TARGET = GooglePlugin
TEMPLATE = lib
XdxfLoadDialog::XdxfLoadDialog(QWidget *parent) :
QDialog(parent) {
- verticalLayout = new QVBoxLayout(this);
+ verticalLayout = new QVBoxLayout;
setLayout(verticalLayout);
setWindowTitle(tr("Add new XDXF dictionary"));
- browseLayout = new QHBoxLayout(this);
- verticalLayout->addLayout(browseLayout);
+ browseLayout = new QVBoxLayout;
- browseButton = new QPushButton(tr("Browse"),this);
- browseLabel = new QLabel(tr("Dictionary file: not selected"),this);
+ browseButton = new QPushButton(tr("Browse"));
+ browseLabel = new QLabel(tr("Dictionary file: not selected"));
+ //browseLabel->setWordWrap(true);
+ browseLabel->setMargin(5);
- browseLayout->addWidget(browseLabel);
- browseLayout->addWidget(browseButton,0, Qt::AlignRight);
+ browseLayout->addWidget(browseLabel, 0, Qt::AlignLeft);
+ browseLayout->addWidget(browseButton);
+ verticalLayout->addLayout(browseLayout);
- cacheLayout = new QHBoxLayout(this);
+ cacheLayout = new QHBoxLayout;
verticalLayout->addLayout(cacheLayout);
accentsCheckBox = new QCheckBox(tr("Strip accents \n(searching takes more time, "
"but spelling don't have to be exact)"));
cacheCheckBox->setChecked(true);
cacheLayout->addWidget(cacheCheckBox);
- addButton = new QPushButton(tr("Add"),this);
+ addButton = new QPushButton(tr("Add"));
verticalLayout->addWidget(addButton);
tr("XDXF Files (*.xdxf)"),
NULL,
NULL);
+
if (!fileName.isEmpty()) {
- browseLabel->setText(tr("Dictionary file: ") + fileName);
+ qDebug()<<fileName;
+ browseLabel->setText(tr("Dictionary file: %1").arg(fileName));
_dicitonaryFilePath = fileName;
- }
+ }repaint(rect());
+ resize(size());
}
void XdxfLoadDialog::addDictionary() {
QCheckBox* cacheCheckBox;
QCheckBox* accentsCheckBox;
QVBoxLayout* verticalLayout;
- QHBoxLayout* browseLayout;
+ QVBoxLayout* browseLayout;
QHBoxLayout* cacheLayout;
QString _dicitonaryFilePath;
bool _generateCache;
TEMPLATE=subdirs
-SUBDIRS = plugins base
+SUBDIRS = plugins base desktopWidget
check.target = check
check.CONFIG = recursive