Merge branch 'master' into google
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 26 Aug 2010 06:47:46 +0000 (08:47 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 26 Aug 2010 06:47:46 +0000 (08:47 +0200)
Conflicts:
trunk/src/base/backbone/backbone.cpp
trunk/src/base/gui/DictManagerWidget.cpp
trunk/src/base/gui/SearchBarWidget.cpp

22 files changed:
data/icons/16x16/staroff.png
data/icons/16x16/staron.png
trunk/src/base/backbone/Bookmarks.cpp
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/src/base/gui/AboutWidget.cpp
trunk/src/base/gui/AboutWidget.h
trunk/src/base/gui/BookmarksWidget.cpp
trunk/src/base/gui/BookmarksWidget.h
trunk/src/base/gui/DictManagerWidget.cpp
trunk/src/base/gui/DictManagerWidget.h
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/MainWindow.h
trunk/src/base/gui/SearchBarWidget.cpp
trunk/src/base/gui/SettingsWidget.cpp
trunk/src/base/gui/SettingsWidget.h
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/gui/main.cpp
trunk/src/includes/Notify.h
trunk/src/plugins/xdxf/src/XdxfCachingDialog.cpp
trunk/src/plugins/xdxf/src/XdxfSettingsDialog.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.cpp

index f5bcd45..23ce5dd 100644 (file)
Binary files a/data/icons/16x16/staroff.png and b/data/icons/16x16/staroff.png differ
index b335977..1cec111 100644 (file)
Binary files a/data/icons/16x16/staron.png and b/data/icons/16x16/staron.png differ
index 3770eb6..dfee9c8 100644 (file)
@@ -61,7 +61,6 @@ void Bookmarks::add(Translation* translation) {
 }
 
 
-
 void Bookmarks::remove(Translation* translation) {
     QSqlDatabase db = getDbCnx(dbName);
     if(!db.isOpen() && !db.open()) {
index c642969..fe99eec 100644 (file)
@@ -30,8 +30,9 @@
 
 int Backbone::_searchLimit;
 
-// Sadly QtConcurrent mapped doesn't let me use something like calling method of
-// some class with supplied argument
+// Sadly QtConcurent::mapped dosent let me use something like calling method of
+// some class with supplied argument; so i have to sin against art and put
+// global function and variable so i could supply function with some parametr
 QString mappedSearch;
 QList<Translation*> mapSearch(CommonDictInterface *dict) {
     if(dict)
@@ -39,10 +40,25 @@ QList<Translation*> mapSearch(CommonDictInterface *dict) {
     return QList<Translation*>();
 }
 
+
+
+/*! Smart pointer (kind of) for translation object
+
+    QtConcurent::mapped  use collection of data and one function, what i need is
+    to map signle data object to method calls for multiple objects. TranslationPtr
+    is try to store method call as a data -> moreover QtConcurent allow only for
+    methods without any parameters so TranslationPtr is created with Translation
+    object -> ready to call toHtml() for supplied Translation.
+
+    Another thing is that QtConcurent dont like pointers in data collection
+    so TranslationPtr is way to hide real translation object (pointer for object)
+    */
 class TranslationPtr {
     Translation* _tr;
 public:
     TranslationPtr(Translation* tr) :_tr(tr) {}
+
+    /*! \return translation text for corresponding Translation object */
     QString toHtml() const {
         QString trans;
         trans = _tr->toHtml();
@@ -63,6 +79,9 @@ void Backbone::init() {
    _searchLimit = 15;
 
    loadPrefs(_defaultConfigPath);
+
+   // Default configuration are stored in separate config file and we dont want
+   // to update it
    _defaultPluginPath = _pluginPath;
    _defaultHistoryLen = _historyLen;
    _defaultSearchLimit = _searchLimit;
@@ -81,6 +100,8 @@ void Backbone::init() {
    connect(&_bookmarkSearchWatcher, SIGNAL(finished()), this,
            SLOT(translationReady()));
 
+   // In common opinion perfect thread count is cores_number+1 (in qt perfect
+   // thread count is set to cores number
    QThreadPool::globalInstance()->setMaxThreadCount(
            QThreadPool::globalInstance()->maxThreadCount()+1);
 
@@ -96,6 +117,7 @@ Backbone::Backbone(QString pluginPath, QString configPath, bool dry,
 {
     _pluginPath = pluginPath;
     _configPath = configPath;
+
     _defaultConfigPath = configPath;
     dryRun = false;
     if(dry)
@@ -180,11 +202,15 @@ void Backbone::stopSearching() {
 
 
 void Backbone::search(QString word){
-    qDebug() << "SEEEEEEEEEARCH";
     _result.clear();
     mappedSearch = word.toLower();
 
     stopped = false;
+
+    // When dictFin and bookmarkFin is set to true then translationReady()
+    // signal is emited see translationReady(),
+    // so when searching only in one of them, coresponding *Fin is set to false
+    // and other to true so program is waiting only for one translation
     dictFin = !_searchDicts;
     bookmarkFin = !_searchBookmarks;
 
@@ -221,8 +247,9 @@ void Backbone::addDictionary(CommonDictInterface *dict, bool active) {
 
 
  void Backbone::addInternalDictionary(CommonDictInterface* dict, bool active) {
-     dict->setHash(++_dictNum);
+     dict->setHash(++_dictNum); // Hash must be uniqe in every session but not between
      _dicts[dict] = active;
+
      connect(dict, SIGNAL(settingsChanged()), this, SLOT(dictUpdated()));
      connect(dict, SIGNAL(notify(Notify::NotifyType,QString)), this,
              SIGNAL(notify(Notify::NotifyType,QString)));
@@ -245,9 +272,10 @@ void Backbone::addDictionary(CommonDictInterface *dict, bool active) {
 
 
 void Backbone::translationReady() {
-    bool changed = 0; // prevents from doubling ready() signal, when both are
+    bool changed = 0; // prevents doubling ready() signal, when both if's are
                       //  executed in one translationReady() call then second
-                      // call doubles ready*() emit without any new data
+                      // translationReady() call doubles ready*() emit
+
     if(!dictFin && _innerResult.isFinished()) {
         changed = 1;
         dictFin = 1;
@@ -270,9 +298,8 @@ void Backbone::translationReady() {
     }
 
     if(!stopped && bookmarkFin && dictFin && changed) {
-        qDebug() << "EMITTTTTT";
         Q_EMIT ready();
-        }
+    }
 }
 
 QStringList Backbone::getFilesFromDir(QString dir, QStringList nameFilter) {
@@ -374,6 +401,7 @@ void Backbone::saveDefaultPrefs(QSettings *set) {
 void Backbone::loadDicts(QString fileName, bool _default) {
     if(dryRun)
         return;
+
     QFileInfo file(QDir::toNativeSeparators(fileName));
     QDir confDir(file.dir());
     if(!confDir.exists()){
@@ -422,6 +450,12 @@ void Backbone::loadDicts(QString fileName, bool _default) {
 void Backbone::dictUpdated() {
     if(dryRun)
         return;
+
+    // For convienence this function is called for each change in dictionaries
+    // and each call dumps configuration for all dictionaries into file.
+    // Maybe better way would be to store new/changed configuration but
+    // parsing settings file and figuring out what was changed, in my opinion,
+    // would take more time
     _history->setMaxSize(_historyLen);
     QFileInfo file(QDir::toNativeSeparators(_configPath));
     QDir confDir(file.dir());
@@ -457,6 +491,7 @@ void Backbone::saveState(QSettings* set, Settings* plugSet, bool active
         return;
     if(!set || !plugSet)
         return;
+
     QString section;
     section.append(QString("dictionary_%1").arg(hash));
     QList<QString> keys = plugSet->keys();
@@ -531,6 +566,8 @@ void Backbone::setSettings(Settings *settings) {
     else
         _searchBookmarks = 0;
     dictUpdated();
+    if(settings)
+        delete settings;
 }
 
 
index 17f4a69..d19bc70 100644 (file)
@@ -210,7 +210,7 @@ public Q_SLOTS:
 
     /*! Removes all bookmarks
       */
-    void removeAllBookmark(){
+    void removeAllBookmarks(){
         _bookmarks.clear();
     }
 
index c77d58b..73df15f 100644 (file)
@@ -1,3 +1,30 @@
+/*******************************************************************************
+
+    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 AboutWidget.cpp
+\brief Simple "about" widget - product, company, license info
+
+
+\author Bartosz Szatkowski <bulislaw@linux.com>
+*/
+
 #include "AboutWidget.h"
 
 AboutWidget::AboutWidget(GUIInterface *parent): QDialog(parent)
@@ -60,9 +87,10 @@ AboutWidget::AboutWidget(GUIInterface *parent): QDialog(parent)
     #ifndef Q_WS_MAEMO_5
         w->setLayout(mainLayout);
         scroll->setWidget(w);
+        scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
         scrollLayout->addWidget(scroll, 0, Qt::AlignHCenter);
         this->setLayout(scrollLayout);
-        this->resize(img.width()*1.65, img.height()*2.60);
+        w->setMinimumSize(img.width()*1.6, img.height()*2.45);
     #else
         setLayout(mainLayout);
     #endif
index 567b663..a1cdda2 100644 (file)
@@ -1,3 +1,30 @@
+/*******************************************************************************
+
+    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 AboutWidget.h
+\brief Simple "about" widget - product, company, license info
+
+
+\author Bartosz Szatkowski <bulislaw@linux.com>
+*/
+
 #ifndef ABOUTWIDGET_H
 #define ABOUTWIDGET_H
 
index 438edac..1536265 100644 (file)
@@ -46,3 +46,5 @@ BookmarksWidget::BookmarksWidget(GUIInterface *parent) :
     connect(removeAllBookmarksPushButton, SIGNAL(clicked()),
             this, SIGNAL(removeAllBookmarks()));
 }
+
+
index 9c347fb..288b7e2 100644 (file)
@@ -40,10 +40,12 @@ class BookmarksWidget : public QDialog
 public:
     explicit BookmarksWidget(GUIInterface *parent = 0);
 
+
 Q_SIGNALS:
     void showAllBookmarks();
     void removeAllBookmarks();
 
+
 private:
     QPushButton* showAllBookmarksPushButton;
     QPushButton* removeAllBookmarksPushButton;
index 22fe241..157aa2f 100644 (file)
@@ -62,21 +62,33 @@ DictManagerWidget::DictManagerWidget(GUIInterface *parent) :
 
 
     connect(addNewDictButton, SIGNAL(clicked()),
+            this, SLOT(saveChanges()));
+    connect(addNewDictButton, SIGNAL(clicked()),
             this, SLOT(addNewDictButtonClicked()));
 
     connect(removeDictButton, SIGNAL(clicked()),
+            this, SLOT(saveChanges()));
+    connect(removeDictButton, SIGNAL(clicked()),
             this, SLOT(removeButtonClicked()));
 
     connect(settingsButton, SIGNAL(clicked()),
+            this, SLOT(saveChanges()));
+    connect(settingsButton, SIGNAL(clicked()),
             this, SLOT(settingsButtonClicked()));
 
     connect(dictListWidget, SIGNAL(itemClicked(QListWidgetItem*)),
             this, SLOT(itemSelected(QListWidgetItem*)));
 
+    connect(dictListWidget, SIGNAL(itemChanged(QListWidgetItem*)),
+            this, SLOT(changed()));
+
     refreshDictsList();
 
     #ifndef Q_WS_MAEMO_5
         setMinimumSize(500,300);
+        closeButton = new QPushButton(tr("Save"));
+        buttonGroup->addWidget(closeButton);
+        connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
     #endif
 }
 
@@ -113,22 +125,39 @@ void DictManagerWidget::refreshDictsList() {
 }
 
 void DictManagerWidget::showEvent(QShowEvent *e) {
+    _changed = false;
+    #ifndef Q_WS_MAEMO_5
+        _save = false;
+    #endif
     refreshDictsList();
     QWidget::showEvent(e);
 }
 
-void DictManagerWidget::hideEvent(QHideEvent *e)
-{
-    QList<CommonDictInterface*> checkedDicts;
+void DictManagerWidget::saveChanges() {
+
+    #ifndef Q_WS_MAEMO_5
+    if(_save) {
+    #else
+    if(_changed &&
+            QMessageBox::question(this, "Save", "Do you want to save changes?",
+            QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
+    #endif
+        QList<CommonDictInterface*> checkedDicts;
 
-    for(int i=0; i<dictListWidget->count(); i++) {
-        QListWidgetItem* item = dictListWidget->item(i);
-        if(item->checkState() == Qt::Checked) {
-            checkedDicts.push_back(dictsHash[item]);
+        for(int i=0; i<dictListWidget->count(); i++) {
+            QListWidgetItem* item = dictListWidget->item(i);
+            if(item->checkState() == Qt::Checked) {
+                checkedDicts.push_back(dictsHash[item]);
+            }
         }
+        emit selectedDictionaries(checkedDicts);
     }
-    Q_EMIT selectedDictionaries(checkedDicts);
+    _changed = false;
+}
 
+void DictManagerWidget::hideEvent(QHideEvent *e)
+{
+    saveChanges();
     QWidget::hideEvent(e);
 }
 
@@ -154,11 +183,15 @@ void DictManagerWidget::itemSelected(QListWidgetItem *) {
 }
 
 void DictManagerWidget::removeButtonClicked() {
-    QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
-    if(selected.count() > 0) {
-        Q_EMIT removeDictionary(dictsHash[selected[0]]);
-        refreshDictsList();
-    }
+    if(QMessageBox::question(this, "Remove dictionary",
+            "Do you want to remove selected dictionary?",
+            QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) {
+        QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
+        if(selected.count() > 0) {
+            emit removeDictionary(dictsHash[selected[0]]);
+            refreshDictsList();
+        }
+   }
 }
 
 void DictManagerWidget::settingsButtonClicked() {
@@ -168,3 +201,16 @@ void DictManagerWidget::settingsButtonClicked() {
         refreshDictsList();
     }
 }
+
+
+void DictManagerWidget::changed() {
+    _changed=true;
+}
+
+
+#ifndef Q_WS_MAEMO_5
+    void DictManagerWidget::save() {
+        _save = true;
+        hide();
+    }
+#endif
index 4d587a2..56abbd5 100644 (file)
@@ -85,6 +85,12 @@ private Q_SLOTS:
     /*! Shows plugin's settings dialog*/
     void settingsButtonClicked();
 
+    //! Each change of state (that needs to be saved) should call this to indicate state change
+    void changed();
+
+    //! saves changes
+    void saveChanges();
+
 private:
     QPushButton* addNewDictButton;
     QPushButton* removeDictButton;
@@ -97,8 +103,16 @@ private:
     //holds association between items on list and CommonDictInterface objects
     QHash<QListWidgetItem*, CommonDictInterface*> dictsHash;
     GUIInterface* guiInterface;
+    bool _changed;
 
     void refreshDictsList();
+    #ifndef Q_WS_MAEMO_5
+        QPushButton* closeButton;
+        bool _save;
+
+        public Q_SLOTS:
+            void save();
+    #endif
 };
 
 #endif // DICTMANAGERWIDGET_H
index 1f75d97..42b1b2f 100644 (file)
@@ -67,18 +67,18 @@ void MainWindow::initializeUI() {
     translationWidget = new TranslationWidget(this);
 
 
-    mainLayout = new QVBoxLayout(this);
-    QWidget* w = new QWidget(this);
+    mainLayout = new QVBoxLayout();
+    QWidget* w = new QWidget();
     w->setLayout(mainLayout);
     setCentralWidget(w);
-    menuBar = new QMenuBar(this);
+    menuBar = new QMenuBar();
     setMenuBar(menuBar);
 
-    searchBarWidget = new SearchBarWidget(this);
+    searchBarWidget = new SearchBarWidget();
 
-    wordListWidget = new WordListWidget(this);
+    wordListWidget = new WordListWidget();
 
-    welcomeScreenWidget = new WelcomeScreenWidget(this);
+    welcomeScreenWidget = new WelcomeScreenWidget();
 
 
     #ifdef Q_WS_MAEMO_5
@@ -328,6 +328,7 @@ Settings* MainWindow::settings() {
 
 
 void MainWindow::showNotify(Notify::NotifyType type, QString text) {
+
     switch(type) {
     case Notify::Info:
         #ifdef Q_WS_MAEMO_5
@@ -340,9 +341,12 @@ void MainWindow::showNotify(Notify::NotifyType type, QString text) {
         break;
 
     case Notify::Warning:
+        qDebug() << text;
         #ifndef Q_WS_MAEMO_5
                 QMessageBox::warning(this, "Warning", text);
                 break;
+        #else
+            QMessageBox::information(this, "Warning", text);
         #endif
 
     case Notify::Error:
@@ -399,6 +403,9 @@ void MainWindow::connectBackbone() {
     connect(backbone, SIGNAL(searchCanceled()),
             this, SIGNAL(setIdle()));
 
+    connect(backbone, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SLOT(showNotify(Notify::NotifyType,QString)));
+
 
 
 
@@ -514,10 +521,7 @@ void MainWindow::connectBookmarksWidget() {
     #ifdef Q_WS_MAEMO_5
         //after removing bookmarks we search for it once again to clear word list
         connect(bookmarksWidget, SIGNAL(removeAllBookmarks()),
-                backbone, SLOT(removeAllBookmark()));
-
-        connect(bookmarksWidget, SIGNAL(removeAllBookmarks()),
-                backbone, SLOT(fetchBookmarks()));
+                this, SLOT(removeBookmarks()));
 
 
         connect(bookmarksWidget, SIGNAL(showAllBookmarks()),
@@ -528,13 +532,28 @@ void MainWindow::connectBookmarksWidget() {
 
 
     #else
+        connect(bookmarksRemoveAllAction, SIGNAL(triggered()),
+                this, SLOT(removeBookmarks()));
         connect(bookmarksShowAllAction, SIGNAL(triggered()),
                 backbone, SLOT(fetchBookmarks()));
 
-        connect(bookmarksRemoveAllAction, SIGNAL(triggered()),
-                backbone, SLOT(removeAllBookmark()));
+    #endif
+}
 
-        connect(bookmarksRemoveAllAction, SIGNAL(triggered()),
-                backbone, SLOT(fetchBookmarks()));
+
+void MainWindow::removeBookmarks() {
+    QWidget* par;
+    #ifdef Q_WS_MAEMO_5
+        par = bookmarksWidget;
+    #else
+        par = this;
     #endif
+    if(QMessageBox::question(par, "Delete all bookmarks",
+             "Do you want to delete all bookmarks? (This action cannot be revoked)",
+             QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) {
+        backbone->removeAllBookmarks();
+        if(searchString.size())
+            backbone->search(searchString);
+
+    }
 }
index 66fb906..e65769b 100644 (file)
@@ -191,6 +191,9 @@ private Q_SLOTS:
     //! disabled
     void breakSearching();
 
+    //! 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
index 29368e3..6921e26 100644 (file)
@@ -105,15 +105,15 @@ void SearchBarWidget::initializeUI() {
     #endif
 
 
-    horizontalLayout = new QHBoxLayout(this);
-    verticalLayout = new QVBoxLayout(this);
+    horizontalLayout = new QHBoxLayout();
+    verticalLayout = new QVBoxLayout();
 
 
-    searchPushButton = new QPushButton(tr("Search"),this);
+    searchPushButton = new QPushButton(tr("Search"));
     searchPushButton->setMinimumWidth(125);
 
 
-    searchWordLineEdit = new QLineEdit(this);
+    searchWordLineEdit = new QLineEdit();
     searchWordLineEdit->setMinimumWidth(250);
 
     #ifndef Q_WS_MAEMO_5
@@ -123,26 +123,28 @@ void SearchBarWidget::initializeUI() {
 
 
     //create layout for lineEdit to have clear button on it
-    QHBoxLayout* lineEditLayout = new QHBoxLayout(this);
+    QHBoxLayout* lineEditLayout = new QHBoxLayout();
     searchWordLineEdit->setLayout(lineEditLayout);
 
 
-    clearSearchWordToolButton = new QToolButton(this);
+    clearSearchWordToolButton = new QToolButton();
     #ifdef Q_WS_MAEMO_5
         clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
         //tool buttons will have size 2 times smaller
         clearSearchWordToolButton->setMaximumSize(
                 clearSearchWordToolButton->sizeHint().height()/2,
                 clearSearchWordToolButton->sizeHint().height()/2);
+        lineEditLayout->setContentsMargins(0,0,10,0);
     #else
         clearSearchWordToolButton->setIcon(QIcon::fromTheme("edit-clear"));
         clearSearchWordToolButton->setMinimumSize(
-                clearSearchWordToolButton->sizeHint().height(),
-                clearSearchWordToolButton->sizeHint().height());
+                searchWordLineEdit->sizeHint().height()*1.2,
+                searchWordLineEdit->sizeHint().height()*1.2);
+        lineEditLayout->setContentsMargins(0,0,5,0);
     #endif
 
 
-    historyNextToolButton = new QToolButton(this);
+    historyNextToolButton = new QToolButton();
     #ifdef Q_WS_MAEMO_5
         historyNextToolButton->setIcon(
                 generateIcon(QIcon::fromTheme("general_forward")));
@@ -153,7 +155,7 @@ void SearchBarWidget::initializeUI() {
 
 
 
-    historyPrevToolButton = new QToolButton(this);
+    historyPrevToolButton = new QToolButton();
     #ifdef Q_WS_MAEMO_5
         historyPrevToolButton->setIcon(
                 generateIcon(QIcon::fromTheme("general_back")));
@@ -164,7 +166,7 @@ void SearchBarWidget::initializeUI() {
 
 
 
-    historyShowToolButton = new QToolButton(this);
+    historyShowToolButton = new QToolButton();
     #ifdef Q_WS_MAEMO_5
         historyShowToolButton->setIcon(
                 generateIcon(QIcon::fromTheme("general_back"), 90));
@@ -185,8 +187,8 @@ void SearchBarWidget::initializeUI() {
                 fullScreenToolButton->sizeHint().height()*2);
     #endif*/
 
-    searchingProgressBar = new QProgressBar(this);
-    //progress bar has minimum and maximum values set to 0, which will effect
+    searchingProgressBar = new QProgressBar();
+    //progress bar have minimum and maximum values set to 0, which will effect
     //with "I'm alive" bar
     searchingProgressBar->setMinimum(0);
     searchingProgressBar->setMaximum(0);
@@ -209,8 +211,8 @@ void SearchBarWidget::initializeUI() {
    // horizontalLayout->addWidget(fullScreenToolButton);
 
     //adding clear toolButton to textEdit with right alignment
-    lineEditLayout->addWidget(clearSearchWordToolButton, 0,
-                              Qt::AlignRight | Qt::AlignVCenter);
+    lineEditLayout->addWidget(clearSearchWordToolButton, 0, Qt::AlignRight);
+
 
     verticalLayout->addLayout(horizontalLayout);
 }
index 77a239b..156f271 100644 (file)
@@ -45,7 +45,7 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) :
     spinBoxesFormLayout->addRow(tr("History size"),
                                 historySizeSpinBox);
 
-    searchResultSizeSpinBox->setMinimum(1);
+    searchResultSizeSpinBox->setMinimum(0);
     historySizeSpinBox->setMinimum(1);
 
     #ifdef Q_WS_MAEMO_5
@@ -65,16 +65,35 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) :
     verticalLayout->addWidget(searchInBookmarksCheckBox);
 
 
+    connect(historySizeSpinBox, SIGNAL(valueChanged(int)), this,
+            SLOT(changed()));
+    connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)), this,
+            SLOT(changed()));
+    connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)), this,
+            SLOT(changed()));
+    connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)), this,
+            SLOT(changed()));
+
+
     settings = 0;
 
     #ifndef Q_WS_MAEMO_5
         setMinimumWidth(250);
         setMaximumWidth(250);
+        footerLayout = new QHBoxLayout(this);
+        closeButton = new QPushButton(tr("Save"));
+        footerLayout->addStretch(0);
+        footerLayout->addWidget(closeButton);
+        verticalLayout->addLayout(footerLayout);
+        connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
     #endif
 }
 
 void SettingsWidget::showEvent(QShowEvent *e) {
 
+   #ifndef Q_WS_MAEMO_5
+       _save = false;
+   #endif
    settings = guiInterface->settings();
 
    historySizeSpinBox->setValue(
@@ -93,13 +112,21 @@ void SettingsWidget::showEvent(QShowEvent *e) {
     else
         searchInDictionariesCheckBox->setChecked(false);
 
+    _changed = false;
     QDialog::showEvent(e);
 }
 
 void SettingsWidget::hideEvent(QHideEvent *e) {
     QDialog::hideEvent(e);
 
-    if(settings) {
+    #ifndef Q_WS_MAEMO_5
+    if(settings && _save) {
+    #else
+    if(settings && _changed &&
+            QMessageBox::question(this, "Save", "Do you want to save changes?",
+             QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
+
+    #endif
         Settings* newSettings = new Settings;
         newSettings->setValue("history_size",
                               QString::number(historySizeSpinBox->value()));
@@ -126,7 +153,22 @@ void SettingsWidget::hideEvent(QHideEvent *e) {
             }
         }
 
+    }
+    if(settings) {
         delete settings;
         settings = 0;
     }
+    _changed = false;
+}
+
+
+void SettingsWidget::changed() {
+    _changed = true;
 }
+
+#ifndef Q_WS_MAEMO_5
+    void SettingsWidget::save() {
+        _save = true;
+        hide();
+    }
+#endif
index 4889a91..5c248d0 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <QWidget>
 #include <QtGui>
+#include <QPushButton>
 #include "../../includes/GUIInterface.h"
 #include "../../includes/settings.h"
 
@@ -51,6 +52,7 @@ public:
       */
     explicit SettingsWidget(GUIInterface *parent = 0);
 
+
 protected:
     void showEvent(QShowEvent *);
     void hideEvent(QHideEvent *);
@@ -67,6 +69,19 @@ private:
 
     GUIInterface* guiInterface;
     Settings* settings;
+    bool _changed;
+    #ifndef Q_WS_MAEMO_5
+        QPushButton* closeButton;
+        QHBoxLayout* footerLayout;
+        bool _save;
+
+        private Q_SLOTS:
+            void save();
+    #endif
+
+private Q_SLOTS:
+    void changed();
+
 };
 
 #endif // SETTINGSWIDGET_H
index 5699587..91ba5b2 100644 (file)
@@ -60,6 +60,7 @@ void TranslationWidget::show() {
 
 
 void TranslationWidget::show(QStringList translations) {
+    textEdit->clear();
 
     showMaximized();
 
@@ -67,8 +68,8 @@ void TranslationWidget::show(QStringList translations) {
         if(!buttonsInitialized)
             initButtons();
     #endif
-
-    textEdit->clear();
+    textEdit->repaint(this->rect());
+    update(this->rect());
 
     QString trans;
     QString t;
@@ -80,6 +81,7 @@ void TranslationWidget::show(QStringList translations) {
     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);
 
index c5879c5..f047889 100644 (file)
@@ -25,6 +25,7 @@
 #include "MainWindow.h"
 #include "../backbone/backbone.h"
 #include "../../includes/translation.h"
+#include "../../includes/Notify.h"
 #include <QDebug>
 
 
@@ -60,6 +61,8 @@ int main(int argc, char *argv[]) {
 
     qRegisterMetaType<Translation*>("Translation*");
     qRegisterMetaType<QList<Translation*> >("QList<Translation*>");
+    qRegisterMetaType<Notify>("Notify");
+    qRegisterMetaType<Notify::NotifyType>("Notify::NotifyType");
     Backbone backbone;
     MainWindow w(&backbone);
     w.show();
index 7fe2995..a5266e9 100644 (file)
@@ -29,6 +29,7 @@
 #define NOTIFY_H
 
 #include <QObject>
+#include <QMetaClassInfo>
 
 /*! Notify wraps NotifyType which is interpreted by GUI and may change way in
     which GUI handles given notification
@@ -36,6 +37,8 @@
 class Notify : QObject {
     Q_OBJECT
 public:
+    Notify() : QObject(0) {}
+    Notify(const Notify&) : QObject(0) {}
     enum notifytype {Error, Warning, Info};
     Q_DECLARE_FLAGS(NotifyType, notifytype);
 };
index 604ee03..c3b2cfd 100644 (file)
@@ -70,6 +70,9 @@ void XdxfCachingDialog::updateCachingProgress(int progress, int time) {
 
     cachingLabel->setText(tr("Estimated time left: ") +
                       QString::number(seconds) + tr(" seconds"));
+    if(progress >= 100)
+        this->hide();
+        
 
 }
 
index 9b6d991..9102027 100644 (file)
@@ -125,7 +125,6 @@ Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
             settings->setValue(key, plugin->settings()->value(key));
         settings->setValue("path", settingsDialog.dicitonaryFilePath());
 
-        qDebug()<<settingsDialog.generateCache();
         if(settingsDialog.generateCache()) {
             settings->setValue("generateCache", "true");
         }
@@ -133,7 +132,6 @@ Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
             settings->setValue("generateCache", "false");
         }
         plugin->setSettings(settings);
-        delete settings;
         return 0;
     }
 
index 0cc32e7..eb111dc 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "xdxfplugin.h"
 #include <QDebug>
+#include "../../../includes/Notify.h"
 
 XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
                     _langFrom(tr("")), _langTo(tr("")),_name(tr("")),
@@ -75,7 +76,6 @@ QString XdxfPlugin::infoNote() const {
 }
 
 QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
-    //if(_settings->value("cached") == "true")
     if(word.indexOf("*")==-1 && word.indexOf("?")==-1 && word.indexOf("_")==-1
        && word.indexOf("%")==-1)
         word+="*";
@@ -91,6 +91,9 @@ QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
         db.setDatabaseName(cacheFilePath);
         if(!db.open()) {
             qDebug() << "Database error" << db.lastError().text() << endl;
+            Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+                    "opened for %1 dictionary. Searching in xdxf file. "
+                    "You may want to recache.").arg(name()));
             return searchWordListFile(word, limit);
         }
 
@@ -99,7 +102,6 @@ QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
         word = word.replace("*", "%");
         word = word.replace("?", "_");
         word = removeAccents(word);
-        //qDebug() << word;
 
         QSqlQuery cur(db);
         if(limit !=0)
@@ -139,6 +141,8 @@ QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
     regWord.setPatternSyntax(QRegExp::Wildcard);
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
         qDebug()<<"Error: could not open file";
+        Q_EMIT notify(Notify::Warning,
+                QString("Xdxf file cannot be read for %1").arg(name()));
         return translations.toList();
     }
 
@@ -190,6 +194,9 @@ QString XdxfPlugin::searchCache(QString key) {
 
     if(!db.open()) {
         qDebug() << "Database error" << db.lastError().text() << endl;
+        Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+                "opened for %1 dictionary. Searching in xdxf file. "
+                "You may want to recache.").arg(name()));
         return searchFile(key);
     }
 
@@ -211,7 +218,9 @@ QString XdxfPlugin::searchFile(QString key) {
     QFile dictionaryFile(path);
     QString resultString("");
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
-        qDebug()<<"Error: could not open file when search";
+        Q_EMIT notify(Notify::Warning,
+                QString("Xdxf file cannot be read for %1").arg(name()));
+        qDebug()<<"Error: could not open file";
         return "";
     }
     QXmlStreamReader reader(&dictionaryFile);
@@ -339,6 +348,8 @@ void XdxfPlugin::setSettings(Settings *settings) {
 void XdxfPlugin::getDictionaryInfo() {
     QFile dictionaryFile(path);
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+       Q_EMIT notify(Notify::Warning,
+               QString("Xdxf file cannot be read dictionary"));
         qDebug()<<"Error: could not open file";
         return;
     }
@@ -360,10 +371,6 @@ void XdxfPlugin::getDictionaryInfo() {
 
     QString format = "png";
     QString initialPath = QDir::currentPath() + tr("/xdxf.") + format;
-//  qDebug()<<initialPath;
-//  QPixmap test(":/icons/xdxf.png");
-//  qDebug()<<QPixmap(test).save(initialPath,format.toAscii());
-//  qDebug()<<QPixmap("/home/jakub/star.jpg").save(initialPath,format.toAscii());
 
     _infoNote="path=\""+initialPath+"\"> \n" + _name + " [" + _langFrom + "-" + _langTo + "] (" + _type + ")";
 
@@ -398,6 +405,9 @@ int XdxfPlugin::countWords() {
 
     QFile dictionaryFile(path);
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        Q_EMIT notify(Notify::Warning,
+                QString("Xdxf file cannot be read for %1 dictionary")
+                .arg(name()));
         qDebug()<<"Error: could not open file";
         return -1;
     }
@@ -431,6 +441,10 @@ bool XdxfPlugin::makeCache(QString dir) {
 
 
     if (!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        Q_EMIT updateCachingProgress(100, 0);
+        Q_EMIT notify(Notify::Warning,
+                QString("Xdxf file cannot be read for %1 dictionary")
+                .arg(name()));
         return 0;
     }
 
@@ -439,6 +453,10 @@ bool XdxfPlugin::makeCache(QString dir) {
     db.setDatabaseName(cachePathN);
     if(!db.open()) {
         qDebug() << "Database error" << db.lastError().text() << endl;
+        Q_EMIT updateCachingProgress(100, 0);
+        Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+                "opened for %1 dictionary. Searching in xdxf file. "
+                "You may want to recache.").arg(name()));
         return false;
     }
     QCoreApplication::processEvents();
@@ -513,6 +531,9 @@ bool XdxfPlugin::makeCache(QString dir) {
 
     if(!cur.next() || countWords() != cur.value(0).toInt())
     {
+        Q_EMIT updateCachingProgress(100, timer.restart());
+        Q_EMIT notify(Notify::Warning,
+                QString("Database caching error, please try againg."));
         db.close();
         return false;
     }