Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
authorBartosz Szatkowski <bulislaw@linux.com>
Wed, 11 Aug 2010 10:50:08 +0000 (12:50 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Wed, 11 Aug 2010 10:50:08 +0000 (12:50 +0200)
12 files changed:
trunk/src/base/backbone/History.cpp [new file with mode: 0644]
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/src/base/base.pro
trunk/src/base/gui/HistoryListDialog.cpp [new file with mode: 0644]
trunk/src/base/gui/HistoryListDialog.h [new file with mode: 0644]
trunk/src/base/gui/SearchBarWidget.cpp
trunk/src/base/gui/SearchBarWidget.h
trunk/src/includes/History.h [new file with mode: 0644]
trunk/tests/mDictionaryTests/mDictionaryTests.pro
trunk/tests/mDictionaryTests/mDictionaryTests.pro.user [deleted file]
trunk/tests/mDictionaryTests/tst_Backbone.cpp

diff --git a/trunk/src/base/backbone/History.cpp b/trunk/src/base/backbone/History.cpp
new file mode 100644 (file)
index 0000000..850a90d
--- /dev/null
@@ -0,0 +1,187 @@
+/*******************************************************************************
+
+    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 "../../includes/History.h"
+#include <QDebug>
+
+History::History(int maxSize, QObject *parent) :
+    QObject(parent)
+{
+    _maxSize = maxSize;
+    currentElement = -1;
+    _prevAvailable = false;
+    _nextAvailable = false;
+    _listAvailable = false;
+}
+
+
+void History::setMaxSize(int size) {
+    if(maxSize() <= 0) return;
+    if(size > _maxSize) {
+        _maxSize = size;
+    }
+    else {
+        _maxSize = size;
+        if(currentElement > 0) {
+            _history.remove(0, currentElement);
+        }
+
+        while(_history.size() > _maxSize) {
+            _history.pop_back();
+        }
+
+        setCurrentElement(0);
+    }
+}
+
+int History::maxSize() {
+    return _maxSize;
+}
+
+void History::add(QString word) {
+    if(currentElement != -1) {
+        //we search the same word so we don't add it again
+        if(_history[currentElement] == word)
+            return;
+    }
+
+    //if we are not in head, we deleted everything ahed us
+    if(currentElement > 0) {
+        _history.remove(0, currentElement);
+    }
+
+
+    if(_history.contains(word)) {
+        _history.remove(_history.indexOf(word));
+    }
+
+    //add new word to head
+    _history.push_front(word);
+
+    //fit to max size
+    while(_history.size() > _maxSize) {
+        _history.pop_back();
+    }
+
+    currentElement = 0;
+
+    if(_history.size() > 1) {
+        _prevAvailable = true;
+        _nextAvailable = false;
+        _listAvailable = true;
+    }
+    else {
+        _prevAvailable = false;
+        _nextAvailable = false;
+        _listAvailable = true;
+    }
+
+    emit historyChanged(_prevAvailable,
+                        _nextAvailable,
+                        _listAvailable);
+}
+
+QString History::previous() {
+    if(_prevAvailable) {
+        currentElement++;
+
+        _nextAvailable = true;
+
+        if(currentElement+1 == _history.size()) {
+            _prevAvailable = false;
+        }
+
+        emit historyChanged(_prevAvailable,
+                            _nextAvailable,
+                            _listAvailable);
+
+        return _history[currentElement];
+    }
+    return QString();
+}
+
+QString History::next() {
+    if(_nextAvailable) {
+        currentElement--;
+
+        _prevAvailable = true;
+
+        if(currentElement == 0) {
+           _nextAvailable = false;
+        }
+
+        emit historyChanged(_prevAvailable,
+                            _nextAvailable,
+                            _listAvailable);
+
+        return _history[currentElement];
+    }
+    return QString();
+}
+
+QStringList History::list() {
+    QStringList result;
+
+    if(_listAvailable) {
+        for(int i=0; i<_history.size(); i++) {
+            result << _history[i];
+        }
+    }
+    return result;
+}
+
+bool History::nextAvailable() {
+    return _nextAvailable;
+}
+
+bool History::prevAvailable() {
+    return _prevAvailable;
+}
+
+bool History::listAvailable() {
+    return _listAvailable;
+}
+
+void History::setCurrentElement(int element) {
+    if(element < 0 || element >= _history.size()) return;
+
+    currentElement = element;
+
+    if(currentElement > 0) {
+       _nextAvailable = true;
+    }
+    else {
+        _nextAvailable = false;
+    }
+
+    if(currentElement+1 < _history.size()) {
+        _prevAvailable = true;
+    }
+    else {
+        _prevAvailable = false;
+    }
+
+    emit historyChanged(_prevAvailable,
+                        _nextAvailable,
+                        _listAvailable);
+}
index 4d297f4..ce169e9 100644 (file)
@@ -51,6 +51,8 @@ void Backbone::init() {
    connect(&_timerSearch, SIGNAL(timeout()), this, SLOT(translationReady()));
    connect(&_timerHtmlSearch, SIGNAL(timeout()), this,
            SLOT(htmlTranslationReady()));
+
+   _history = new History(5, this);
 }
 
 Backbone::Backbone(QString pluginPath, QString configPath, QObject *parent)
@@ -117,8 +119,8 @@ QList<CommonDictInterface* > Backbone::getPlugins() {
 
 
 
-QList<QString> Backbone::getHistory() {
-    //TODO code needed
+History* Backbone::history() {
+    return _history;
 }
 
 
index fc79e4f..74a3737 100644 (file)
@@ -37,6 +37,7 @@
 #include "../../includes/CommonDictInterface.h"
 #include "../../includes/settings.h"
 #include "../../includes/translation.h"
+#include "../../includes/History.h"
 
 
 /*! Inner part of dictionary - glues together GUI and plugins
@@ -67,7 +68,7 @@ public:
     QList<CommonDictInterface*> getPlugins();
 
     //! \return history of performed searches
-    QList<QString> getHistory(); //TODO implementation needed (in future)
+    History* history();
 
     //! \return return search fesult
     QMultiHash<QString, Translation*> result();
@@ -175,6 +176,8 @@ private:
     void saveDefaultPrefs(QSettings*);
     CommonDictInterface* plugin(QString type); //< search for given type plugin
 
+    History* _history;
+
 };
 
 #endif // BACKBONE_H
index 07f99c8..a079b2f 100644 (file)
@@ -30,7 +30,9 @@ SOURCES += gui/main.cpp\
     gui/MenuWidget.cpp \
     gui/MenuTabWidget.cpp \
     gui/DictManagerWidget.cpp \
-    gui/DictTypeSelectDialog.cpp
+    gui/DictTypeSelectDialog.cpp \
+    backbone/History.cpp \
+    gui/HistoryListDialog.cpp
 
 HEADERS  += gui/MainWindow.h \
     gui/SearchBarWidget.h \
@@ -44,7 +46,9 @@ HEADERS  += gui/MainWindow.h \
     gui/MenuTabWidget.h \
     gui/DictManagerWidget.h \
     gui/DictTypeSelectDialog.h \
-    gui/TranslationWidgetAutoResizer.h
+    gui/TranslationWidgetAutoResizer.h \
+    ../includes/History.h \
+    gui/HistoryListDialog.h
 
 FORMS    += gui/MainWindow.ui
 
diff --git a/trunk/src/base/gui/HistoryListDialog.cpp b/trunk/src/base/gui/HistoryListDialog.cpp
new file mode 100644 (file)
index 0000000..62f5d3e
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************
+
+    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 "HistoryListDialog.h"
+
+HistoryListDialog::HistoryListDialog(History *history, SearchBarWidget *parent):
+        QDialog(parent)
+{
+    this->history = history;
+    searchBar = parent;
+
+    verticalLayout = new QVBoxLayout;
+    setLayout(verticalLayout);
+
+    historyListWidget = new QListWidget;
+    verticalLayout->addWidget(historyListWidget);
+
+
+    QStringList words = history->list();
+
+    for(int i=0; i<words.count(); i++) {
+        QListWidgetItem* item = new QListWidgetItem(
+                QString::number(i+1) + ". " + words[i]);
+        historyListWidget->addItem(item);
+    }
+
+     setModal(true);
+
+     setWindowTitle(tr("History"));
+
+     setMinimumHeight(300);
+
+     connect(historyListWidget, SIGNAL(clicked(QModelIndex)),
+             this, SLOT(itemClicked(QModelIndex)));
+}
+
+
+void HistoryListDialog::itemClicked(QModelIndex index) {
+    QString selectedWord = history->list()[index.row()];
+
+    history->setCurrentElement(index.row());
+
+    searchBar->search(selectedWord);
+
+    accept();
+}
+
diff --git a/trunk/src/base/gui/HistoryListDialog.h b/trunk/src/base/gui/HistoryListDialog.h
new file mode 100644 (file)
index 0000000..4a60faa
--- /dev/null
@@ -0,0 +1,49 @@
+/*******************************************************************************
+
+    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 HISTORYLISTDIALOG_H
+#define HISTORYLISTDIALOG_H
+
+#include <QDialog>
+#include "SearchBarWidget.h"
+#include "../../includes/History.h"
+#include <QtGui>
+
+class HistoryListDialog : public QDialog
+{
+    Q_OBJECT
+public:
+    explicit HistoryListDialog(History* history, SearchBarWidget*parent);
+
+private Q_SLOTS:
+    void itemClicked(QModelIndex);
+private:
+    History* history;
+    SearchBarWidget* searchBar;
+
+    QListWidget* historyListWidget;
+    QVBoxLayout* verticalLayout;
+
+};
+
+#endif // HISTORYLISTDIALOG_H
index 94b0045..476ec26 100644 (file)
@@ -25,6 +25,7 @@
 #include "SearchBarWidget.h"
 #include <QDebug>
 #include "../../includes/DictDialog.h"
+#include "HistoryListDialog.h"
 
 
 SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
@@ -32,6 +33,8 @@ SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
 
     this->backbone = backbone;
 
+    history = backbone->history();
+
     initializeUI();
 
     setMaximumHeight(150);
@@ -70,7 +73,13 @@ SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
     connect(backbone, SIGNAL(htmlReady()),
             this, SLOT(setIdle()));
 
+
+    connect(history, SIGNAL(historyChanged(bool,bool,bool)),
+            this, SLOT(updateHistoryButtons(bool,bool,bool)));
+
     searchWordLineEdit->setFocus();
+
+    setEnabled(true);
 }
 
 SearchBarWidget::~SearchBarWidget() {
@@ -162,7 +171,6 @@ void SearchBarWidget::initializeUI() {
                               Qt::AlignRight | Qt::AlignVCenter);
 
     verticalLayout->addLayout(horizontalLayout);
-
 }
 
 
@@ -181,15 +189,19 @@ void SearchBarWidget::search(QString word) {
     if(!_isSearching && !word.isEmpty()) {
         searchWordLineEdit->setText(word);
         setBusy();
+        history->add(word);
         emit searchForTranslations(word);
     }
 }
 
 void SearchBarWidget::setEnabled(bool enabled) {
     searchWordLineEdit->setEnabled(enabled);
-    historyNextToolButton->setEnabled(enabled);
-    historyPrevToolButton->setEnabled(enabled);
-    historyShowToolButton->setEnabled(enabled);
+
+    if(enabled) {
+        historyNextToolButton->setEnabled(history->nextAvailable());
+        historyPrevToolButton->setEnabled(history->prevAvailable());
+        historyShowToolButton->setEnabled(history->listAvailable());
+    }
 }
 
 void SearchBarWidget::setBusy() {
@@ -211,25 +223,37 @@ void SearchBarWidget::setIdle() {
 }
 
 void SearchBarWidget::historyNextToolButtonClicked() {
-
+    QString next = history->next();
+    if(!next.isEmpty()) {
+        searchWordLineEdit->setText(next);
+    }
 }
 
 void SearchBarWidget::historyPrevToolButtonClicked() {
-
+    QString prev = history->previous();
+    if(!prev.isEmpty()) {
+        searchWordLineEdit->setText(prev);
+    }
 }
 
 void SearchBarWidget::historyShowToolButtonClicked() {
-
+    HistoryListDialog listDialog(history, this);
+    listDialog.exec();
 }
 
 void SearchBarWidget::clearSearchWordToolButtonClicked() {
     searchWordLineEdit->clear();
 }
 
-void SearchBarWidget::showHistoryListDialog() {
-
-}
 
 bool SearchBarWidget::isSearching() const {
     return _isSearching;
 }
+
+void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) {
+    if(!isSearching()) {
+        historyPrevToolButton->setEnabled(prev);
+        historyNextToolButton->setEnabled(next);
+        historyShowToolButton->setEnabled(list);
+    }
+}
index fbceb03..ca8ebb4 100644 (file)
@@ -28,7 +28,7 @@
 #include <QWidget>
 #include <QtGui>
 #include "../backbone/backbone.h"
-
+#include "../../includes/History.h"
 
 //! Displays search bar
 /*!
@@ -87,10 +87,12 @@ private Q_SLOTS:
     void historyPrevToolButtonClicked();
     void historyNextToolButtonClicked();
     void historyShowToolButtonClicked();
+    void updateHistoryButtons(bool prev, bool next, bool list);
 
 
 private:
     Backbone* backbone;
+    History* history;
     QLineEdit* searchWordLineEdit;
     QToolButton* clearSearchWordToolButton;
     QPushButton* searchPushButton;
@@ -107,7 +109,6 @@ private:
     bool _isSearching;
 
     void initializeUI();
-    void showHistoryListDialog();
 };
 
 #endif // SEARCHBARWIDGET_H
diff --git a/trunk/src/includes/History.h b/trunk/src/includes/History.h
new file mode 100644 (file)
index 0000000..df56199
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************
+
+    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 HISTORY_H
+#define HISTORY_H
+
+#include <QObject>
+#include <QVector>
+#include <QStringList>
+
+class History : public QObject
+{
+    Q_OBJECT
+public:
+    explicit History(int maxSize = 5, QObject *parent = 0);
+
+Q_SIGNALS:
+    void historyChanged(bool prevAvailable,
+                        bool nextAvailable,
+                        bool listAvailable);
+
+public:
+    void add(QString);
+    QString previous();
+    QString next();
+    QStringList list();
+
+    bool prevAvailable();
+    bool nextAvailable();
+    bool listAvailable();
+
+    void setCurrentElement(int element);
+
+    int maxSize();
+
+    void setMaxSize(int size);
+
+private:
+    QVector<QString> _history;
+    int _maxSize;
+    int currentElement;
+    bool _prevAvailable;
+    bool _nextAvailable;
+    bool _listAvailable;
+};
+
+#endif // HISTORY_H
index 9c9ea98..ed2c910 100644 (file)
@@ -15,7 +15,8 @@ TEMPLATE = app
 
 
 SOURCES += tst_Backbone.cpp \
-    ../../src/base/backbone/backbone.cpp
+    ../../src/base/backbone/backbone.cpp \
+    ../../src/base/backbone/History.cpp
 DEFINES += SRCDIR=\\\"$$PWD/\\\"
 
 HEADERS += \
@@ -24,6 +25,7 @@ HEADERS += \
     ../../src/includes/translation.h \
     ../../src/includes/settings.h \
     ../../src/includes/CommonDictInterface.h \
+    ../../src/includes/History.h \
     TranslationMock.h
 
 check.target = check
diff --git a/trunk/tests/mDictionaryTests/mDictionaryTests.pro.user b/trunk/tests/mDictionaryTests/mDictionaryTests.pro.user
deleted file mode 100644 (file)
index bd14af5..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-<!DOCTYPE QtCreatorProject>
-<qtcreator>
- <data>
-  <variable>ProjectExplorer.Project.ActiveTarget</variable>
-  <value type="int">0</value>
- </data>
- <data>
-  <variable>ProjectExplorer.Project.EditorSettings</variable>
-  <valuemap type="QVariantMap">
-   <value key="EditorConfiguration.Codec" type="QByteArray">UTF-8</value>
-  </valuemap>
- </data>
- <data>
-  <variable>ProjectExplorer.Project.Target.0</variable>
-  <valuemap type="QVariantMap">
-   <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Desktop</value>
-   <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Target.DesktopTarget</value>
-   <value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">0</value>
-   <value key="ProjectExplorer.Target.ActiveRunConfiguration" type="int">0</value>
-   <valuemap key="ProjectExplorer.Target.BuildConfiguration.0" type="QVariantMap">
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">QMake</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
-     <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
-    </valuemap>
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
-    <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
-      <value type="QString">clean</value>
-     </valuelist>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
-    <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
-    <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
-    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt w PATH Debug</value>
-    <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mDictionaryTests-build</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">3</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
-   </valuemap>
-   <valuemap key="ProjectExplorer.Target.BuildConfiguration.1" type="QVariantMap">
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">QMake</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
-     <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
-    </valuemap>
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
-    <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
-      <value type="QString">clean</value>
-     </valuelist>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
-    <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
-    <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
-    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt w PATH Release</value>
-    <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">3</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
-   </valuemap>
-   <valuemap key="ProjectExplorer.Target.BuildConfiguration.2" type="QVariantMap">
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">QMake</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
-     <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
-    </valuemap>
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
-    <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
-      <value type="QString">clean</value>
-     </valuelist>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
-    <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
-    <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
-    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt 4.6.3 OpenSource Debug</value>
-    <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
-   </valuemap>
-   <valuemap key="ProjectExplorer.Target.BuildConfiguration.3" type="QVariantMap">
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">QMake</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
-     <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
-    </valuemap>
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
-    <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
-      <value type="QString">clean</value>
-     </valuelist>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
-    <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
-    <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
-    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt 4.6.3 OpenSource Release</value>
-    <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
-   </valuemap>
-   <value key="ProjectExplorer.Target.BuildConfigurationCount" type="int">4</value>
-   <valuemap key="ProjectExplorer.Target.RunConfiguration.0" type="QVariantMap">
-    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">mDictionaryTests</value>
-    <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4RunConfiguration</value>
-    <value key="Qt4ProjectManager.Qt4RunConfiguration.BaseEnvironmentBase" type="int">2</value>
-    <valuelist key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments" type="QVariantList"/>
-    <value key="Qt4ProjectManager.Qt4RunConfiguration.ProFile" type="QString">mDictionaryTests.pro</value>
-    <value key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix" type="bool">false</value>
-    <value key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal" type="bool">false</value>
-    <valuelist key="Qt4ProjectManager.Qt4RunConfiguration.UserEnvironmentChanges" type="QVariantList"/>
-    <value key="Qt4ProjectManager.Qt4RunConfiguration.UserSetName" type="bool">false</value>
-    <value key="Qt4ProjectManager.Qt4RunConfiguration.UserSetWorkingDirectory" type="bool">false</value>
-    <value key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory" type="QString"></value>
-   </valuemap>
-   <value key="ProjectExplorer.Target.RunConfigurationCount" type="int">1</value>
-  </valuemap>
- </data>
- <data>
-  <variable>ProjectExplorer.Project.TargetCount</variable>
-  <value type="int">1</value>
- </data>
- <data>
-  <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
-  <value type="int">4</value>
- </data>
-</qtcreator>
index 7aae8a6..9f615fe 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <QtCore/QString>
 #include <QtTest/QtTest>
+#include <QStringList>
 #include <QList>
 #include <QTime>
 #include "../../src/base/backbone/backbone.h"
@@ -52,7 +53,7 @@ private Q_SLOTS:
     void stopSearchingTest();
     void searchTest();
     void translationTest();
-    void multiTranslationTest();
+    void historyTest();
     void quitTest();
 };
 
@@ -171,8 +172,7 @@ void BackboneTest::searchTest() {
     }
 
     qDebug() << "main " << this->thread()->currentThreadId();
-    QStringList list;
-    list << "pigwa";
+    QString list("pigwa");
 
     back->search(list);
     usleep(2000);
@@ -193,8 +193,7 @@ void BackboneTest::translationTest() {
 
     QTime time;
     time.start();
-    QStringList list;
-    list << "nic";
+    QString list("nic");
     back->search(list);
     qDebug() << "Time for backbone.search: " << time.elapsed();
     usleep(1000);
@@ -206,29 +205,6 @@ void BackboneTest::translationTest() {
     QVERIFY2(back->result().size() == total*2, "Lost some of the translations");
 }
 
-void BackboneTest::multiTranslationTest() {
-    QSignalSpy translatS(back, SIGNAL(ready()));
-    QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
-
-
-    QTime time;
-    QStringList list;
-
-    list << "a" << "b" << "c";
-    back->search(list);
-    qDebug() << "Time for backbone.search: " << time.elapsed();
-    usleep(1000);
-    time.start();
-    back->translationReady();
-    qDebug() << "Time for backbone->translation: " << time.elapsed();
-
-    QVERIFY2(translatS.count() == 1, "Lost finall 'ready()' signal");
-    QVERIFY2(back->result().size() == total*2*3,
-             "Lost some of the translations");
-}
-
-
-
 void BackboneTest::quitTest() {
     QSignalSpy translatS(back, SIGNAL(closeOk()));
     for(int i = 0; i < total; i++) {
@@ -251,6 +227,58 @@ void BackboneTest::quitTest() {
     QVERIFY2(translatS.count() == 1, "Lost finall 'closeOk()' signal");
 }
 
+void BackboneTest::historyTest() {
+    History* history = back->history();
+
+    history->add("mleko");
+
+    QCOMPARE(history->nextAvailable(), FALSE);
+    QCOMPARE(history->prevAvailable(), FALSE);
+    QCOMPARE(history->listAvailable(), TRUE);
+
+
+    history->add("szklanka");
+    QCOMPARE(history->nextAvailable(), FALSE);
+    QCOMPARE(history->prevAvailable(), TRUE);
+
+    history->previous();
+    QCOMPARE(history->nextAvailable(), TRUE);
+    QCOMPARE(history->prevAvailable(), FALSE);
+
+    history->add("pic");
+    QStringList words = history->list();
+    QCOMPARE(words[0], QString("pic"));
+    QCOMPARE(words[1], QString("mleko"));
+
+    history->add("qqq");
+
+    history->previous();
+    history->add("pic");
+
+    words = history->list();
+    QCOMPARE(words[0], QString("qqq"));
+    QCOMPARE(words[1], QString("pic"));
+    QCOMPARE(words[2], QString("mleko"));
+
+    history->setCurrentElement(0);
+    QCOMPARE(history->nextAvailable(), FALSE);
+    QCOMPARE(history->prevAvailable(), TRUE);
+    QCOMPARE(history->listAvailable(), TRUE);
+
+    history->setCurrentElement(1);
+    QCOMPARE(history->nextAvailable(), TRUE);
+    QCOMPARE(history->prevAvailable(), TRUE);
+    QCOMPARE(history->listAvailable(), TRUE);
+
+    history->setMaxSize(1);
+    words = history->list();
+    QCOMPARE(words[0], QString("pic"));
+
+    QCOMPARE(history->nextAvailable(), FALSE);
+    QCOMPARE(history->prevAvailable(), FALSE);
+    QCOMPARE(history->listAvailable(), TRUE);
+}
+
 
 QTEST_APPLESS_MAIN(BackboneTest);