Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 11 Aug 2010 10:34:01 +0000 (12:34 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 11 Aug 2010 10:34:01 +0000 (12:34 +0200)
Conflicts:
trunk/tests/mDictionaryTests/mDictionaryTests.pro.user
trunk/tests/mDictionaryTests/tst_Backbone.cpp

data/mdictionary.defaults [new file with mode: 0644]
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/src/includes/settings.h
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/tests/mDictionaryTests/mDictionaryTests.pro.user [deleted file]
trunk/tests/mDictionaryTests/tst_Backbone.cpp

diff --git a/data/mdictionary.defaults b/data/mdictionary.defaults
new file mode 100644 (file)
index 0000000..16de5f6
--- /dev/null
@@ -0,0 +1,4 @@
+[%General]
+plugin_path=/usr/lib/mdictiona
+history_length=10
+search_limit=15
index 83da538..ce169e9 100644 (file)
 
 void Backbone::init() {
    _interval = 250; //msec
+   dryRun = false;
 
    if(!_configPath.size())
-       _configPath = QDir::homePath() + "/.mdictionary";
-
-   loadPrefs();
-
-
+       _configPath = QDir::homePath() + "/.mdictionary/mdictionary.config";
+   if(!_defaultConfigPath.size())
+       _defaultConfigPath = QDir::homePath() + "/.mdictionary/mdictionary.defaults";
    if(!_pluginPath.size())
-       _pluginPath = "/usr/lib/mdictionary/";
+       _pluginPath = "/usr/lib/mdictionary";
+   _historyLen = 10;
+   _searchLimit = 15;
+
+   loadPrefs(_defaultConfigPath);
+   _defaultPluginPath = _pluginPath;
+   _defaultHistoryLen = _historyLen;
+   _defaultSearchLimit = _searchLimit;
+   loadPrefs(_configPath);
 
    loadPlugins();
-   loadDicts();
+
+   loadDicts(_defaultConfigPath, true);
+   loadDicts(_configPath);
 
    connect(&_timerSearch, SIGNAL(timeout()), this, SLOT(translationReady()));
    connect(&_timerHtmlSearch, SIGNAL(timeout()), this,
@@ -49,9 +58,11 @@ void Backbone::init() {
 Backbone::Backbone(QString pluginPath, QString configPath, QObject *parent)
     : QObject(parent)
 {
+    init();
+    dryRun = true;
     _pluginPath = pluginPath;
     _configPath = configPath;
-    init();
+    _defaultConfigPath = configPath;
 }
 
 
@@ -124,7 +135,7 @@ QMultiHash<QString, Translation*> Backbone::result() {
 
 void Backbone::stopSearching() {
     _timerSearch.stop();
-    _innerResult.clear();
+    _timerHtmlSearch.stop();
     foreach(CommonDictInterface* dict, _dicts.keys())
         dict->stop();
 }
@@ -230,9 +241,12 @@ QStringList Backbone::getFilesFromDir(QString dir, QStringList nameFilter) {
 
 
 void Backbone::loadPlugins() {
+    if(dryRun)
+        return;
     QStringList nameFilter;
     nameFilter << "*.so";
     QStringList files = getFilesFromDir(_pluginPath, nameFilter);
+    qDebug() << files;
 
     foreach(QString file, files) {
         QPluginLoader loader(file);
@@ -244,10 +258,6 @@ void Backbone::loadPlugins() {
 
         CommonDictInterface *plugin = qobject_cast<CommonDictInterface*>(pl);
         _plugins.append(plugin);
-       // addDictionary(plugin->getNew(0)); //TODO change 0 to real settings
-        //Settings* set = new Settings();
-        //set->setValue("path", "dict2.xdxf");
-        //addDictionary(plugin->getNew(set));
     }
 }
 
@@ -262,12 +272,17 @@ CommonDictInterface* Backbone::plugin(QString type) {
 
 
 
-void Backbone::loadPrefs() {
-    QDir confDir(_configPath);
-    if(!confDir.exists())
-        qDebug() << "Configuration file dosn't exists (" << _configPath << ")";
+void Backbone::loadPrefs(QString fileName) {
+    if(dryRun)
+        return;
+    QFileInfo file(QDir::toNativeSeparators(fileName));
+    QDir confDir(file.dir());
+    if(!confDir.exists()){
+        qDebug() << "Configuration file dosn't exists ("
+                << file.filePath() << ")";
         return;
-    QSettings set(_configPath + "/mdictionary.config", QSettings::IniFormat);
+    }
+    QSettings set(file.filePath(), QSettings::IniFormat);
     _pluginPath = set.value("general/plugin_path", _pluginPath).toString();
     _historyLen = set.value("general/history_length", 10).toInt();
     _searchLimit = set.value("general/search_limit", 15).toInt();
@@ -275,12 +290,39 @@ void Backbone::loadPrefs() {
 
 
 
-void Backbone::loadDicts() {
-    QDir confDir(_configPath);
-    if(!confDir.exists())
-        qDebug() << confDir.mkpath(_configPath);
+void Backbone::savePrefs(QSettings *set) {
+    if(dryRun)
+        return;
+    set->setValue("general/plugin_path", _pluginPath);
+    set->setValue("general/history_length", _historyLen);
+    set->setValue("general/search_limit", _searchLimit);
+}
+
+
 
-    QSettings set(_configPath + "/mdictionary.config", QSettings::IniFormat);
+void Backbone::saveDefaultPrefs(QSettings *set) {
+    if(dryRun)
+        return;
+    set->setValue("general/plugin_path", _defaultPluginPath);
+    set->setValue("general/history_length", _defaultHistoryLen);
+    set->setValue("general/search_limit", _defaultSearchLimit);
+}
+
+
+
+void Backbone::loadDicts(QString fileName, bool _default) {
+    if(dryRun)
+        return;
+    QFileInfo file(QDir::toNativeSeparators(fileName));
+    qDebug() << file.filePath();
+    QDir confDir(file.dir());
+    if(!confDir.exists()){
+        qDebug() << "Configuration file dosn't exists ("
+                << file.filePath() << ")";
+        return;
+    }
+
+    QSettings set(file.filePath(), QSettings::IniFormat);
     QStringList dicts = set.childGroups();
     foreach(QString dict, dicts) {
         if(!dict.contains("dictionary_"))
@@ -296,9 +338,14 @@ void Backbone::loadDicts() {
         Settings* plugSet = new Settings();
         set.beginGroup(dict);
         QStringList items = set.childKeys();
-        foreach(QString item, items)
+        foreach(QString item, items) {
             plugSet->setValue(item, set.value(item, "").toString());
+        }
         bool active = set.value("active",1).toBool();
+
+        if(_default)
+            plugSet->setValue("_default_", "true");
+
         set.endGroup();
         addInternalDictionary(plug->getNew(plugSet), active);
     }
@@ -307,18 +354,40 @@ void Backbone::loadDicts() {
 
 
 void Backbone::dictUpdated() {
-    QDir confDir(_configPath);
+    if(dryRun)
+        return;
+    QFileInfo file(QDir::toNativeSeparators(_configPath));
+    QDir confDir(file.dir());
     if(!confDir.exists())
-        qDebug() << confDir.mkpath(_configPath);
-    QSettings set(_configPath + "/mdictionary.config", QSettings::IniFormat);
-    foreach(CommonDictInterface* dict, _dicts.keys())
-        saveState(&set, dict->settings(), _dicts[dict], dict->hash());
+        confDir.mkpath(file.dir().path());
+    QSettings set(file.filePath(), QSettings::IniFormat);
+    set.clear();
+
+    QFileInfo defFile(QDir::toNativeSeparators(_defaultConfigPath));
+    QDir defConfDir(defFile.dir());
+    if(!defConfDir.exists())
+        defConfDir.mkpath(defFile.dir().path());
+    QSettings defSet(defFile.filePath(), QSettings::IniFormat);
+    defSet.clear();
+    savePrefs(&set);
+    saveDefaultPrefs(&defSet);
+
+    foreach(CommonDictInterface* dict, _dicts.keys()){
+        if(!dict || !dict->settings())
+            continue;
+        if(!dict->settings()->keys().contains("_default_"))
+            saveState(&set, dict->settings(), _dicts[dict], dict->hash());
+        else
+            saveState(&defSet, dict->settings(), _dicts[dict], dict->hash());
+    }
 }
 
 
 
 void Backbone::saveState(QSettings* set, Settings* plugSet, bool active
                          , uint hash) {
+    if(dryRun)
+        return;
     if(!set || !plugSet)
         return;
     QString section;
index 749b8de..74a3737 100644 (file)
@@ -156,22 +156,25 @@ private:
     QStringList _htmlResult;
     QTimer _timerSearch, _timerHtmlSearch;
     QTime _time;
-    QString _pluginPath;
+    QString _pluginPath, _defaultPluginPath;
     QString _configPath;
-    int _searchLimit;
+    QString _defaultConfigPath;
+    int _searchLimit, _defaultSearchLimit;
     int _activeSearchNum;
     int _interval; //Search fetching timer.timeout interval in msec
-    int _historyLen;
+    int _historyLen, _defaultHistoryLen;
+    bool dryRun;
 
     void init();
     QStringList getFilesFromDir(QString dir, QStringList nameFilter);
     void loadPlugins(); //< locate and load plugins
-    void loadPrefs();
-    void loadDicts();
+    void loadPrefs(QString fileName);
+    void loadDicts(QString fileName, bool _default=false);
     void saveState(QSettings*, Settings*, bool, uint);
-    CommonDictInterface* plugin(QString type); //< search for given type plugin
     void addInternalDictionary(CommonDictInterface*, bool);
-    //void writeConfig(QString key, QString value);
+    void savePrefs(QSettings*);
+    void saveDefaultPrefs(QSettings*);
+    CommonDictInterface* plugin(QString type); //< search for given type plugin
 
     History* _history;
 
index 3487e02..ae529f6 100644 (file)
@@ -34,6 +34,9 @@ class CommonDictInterface;
 class Settings {
   public:
     Settings(){}
+    Settings(const Settings* set) {
+        _settings = QHash<QString, QString>(set->_settings);
+    }
 
     /*! \returns value fo given key
          \param key
@@ -50,7 +53,7 @@ class Settings {
         _settings.insert(key, value);
     }
 
-    QList<QString> keys() {
+    QList<QString> keys() const {
         return _settings.keys();
     }
 
index 6d69003..17881b7 100644 (file)
@@ -40,8 +40,9 @@ XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
 
     _wordsCount = 0;
 
-    setPath("/usr/lib/mdictionary/dict.xdxf");
     stopped = false;
+
+
 }
 
 QString XdxfPlugin::langFrom() const {   
@@ -177,8 +178,12 @@ void XdxfPlugin::setPath(QString path){
 
 CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
     XdxfPlugin *plugin = new XdxfPlugin();
-    if(settings)
+    if(settings){
         plugin->setPath(settings->value("path"));
+        QStringList list = settings->keys();
+        foreach(QString key, list)
+            plugin->settings()->setValue(key, settings->value(key));
+    }
     return  plugin;
 }
 
diff --git a/trunk/tests/mDictionaryTests/mDictionaryTests.pro.user b/trunk/tests/mDictionaryTests/mDictionaryTests.pro.user
deleted file mode 100644 (file)
index fa63c14..0000000
+++ /dev/null
@@ -1,249 +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">4.6.2 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">/scratchbox/users/mateusz/home/mateusz/mdictionary/trunk/tests/mDictionaryTests</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">9</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">false</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">4.6.2 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">/scratchbox/users/mateusz/home/mateusz/mdictionary/trunk/tests/mDictionaryTests</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">9</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">false</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 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">/scratchbox/users/mateusz/home/mateusz/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">4</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 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">/scratchbox/users/mateusz/home/mateusz/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">4</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.4" 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">/scratchbox/users/mateusz/home/mateusz/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">6</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.5" 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">/scratchbox/users/mateusz/home/mateusz/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">6</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">6</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 eac34cb..51614e2 100644 (file)
@@ -54,6 +54,7 @@ private Q_SLOTS:
     void searchTest();
     void translationTest();
     void historyTest();
+    void multiTranslationTest();
     void quitTest();
 };
 
@@ -71,17 +72,20 @@ void BackboneTest::init()
     for(int i = 0; i < total; i++) {
         dict[i] = new CommonDictInterfaceMock();
         CommonDictInterfaceMock * cd = (CommonDictInterfaceMock*) dict[i];
-        cd->tov = "to" + QString(i);
-        cd->fromv = "from" + QString(i);
-        cd->namev = "name" + QString(i);
-        cd->typev = "type" + QString(i);
+        cd->tov =   QString("to%1").arg(i);
+        cd->fromv = QString("from%1").arg(i);
+        cd->namev = QString("name%1").arg(i);
+        cd->typev = QString("type%1").arg(i);
     }
-    back = new Backbone("vim");
+    back = new Backbone("empty","empty");
+    qDebug() << back->getDictionaries().size();
+    addDicts();
 }
 
 void BackboneTest::addDicts() {
-    for(int i = 0; i < total; i++)
+    for(int i = 0; i < total; i++) {
         back->addDictionary(dict[i]);
+    }
 }
 
 
@@ -93,16 +97,15 @@ void BackboneTest::cleanup()
 
 
 
+
 void BackboneTest::addDictionaryTest()
 {
-    addDicts();
     QCOMPARE(back->getDictionaries().size(), total);
     for(int i = 0; i < total; i++)
         QCOMPARE(back->getDictionaries().keys().contains(dict[i]), QBool(true));
 }
 
 void BackboneTest::removeDictionaryTest() {
-    addDicts();
     for(int i = 0; i < total-1; i++)
         back->removeDictionary(dict[i]);
 
@@ -114,7 +117,6 @@ void BackboneTest::removeDictionaryTest() {
 
 
 void BackboneTest::selectedDictionaryTest() {
-    addDicts();
     QList<CommonDictInterface* > selected;
     back->selectedDictionaries(selected);
     foreach(bool d, back->getDictionaries().values())
@@ -189,14 +191,13 @@ void BackboneTest::translationTest() {
     QSignalSpy translatS(back, SIGNAL(ready()));
     QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
 
-    addDicts();
 
     QTime time;
     time.start();
     QString list("nic");
     back->search(list);
     qDebug() << "Time for backbone.search: " << time.elapsed();
-    usleep(2000);
+    usleep(1000);
     time.start();
     back->translationReady();
     qDebug() << "Time for backbone->translation: " << time.elapsed();
@@ -205,6 +206,29 @@ 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++) {