Merge branch 'google' of ssh://drop.maemo.org/git/mdictionary into google
authorBartosz Szatkowski <bulislaw@linux.com>
Mon, 30 Aug 2010 07:31:11 +0000 (09:31 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Mon, 30 Aug 2010 07:31:11 +0000 (09:31 +0200)
data/mdictionary.defaults [deleted file]
trunk/src/base/backbone/ConfigGenerator.cpp
trunk/src/base/backbone/ConfigGenerator.h
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/src/base/base.pro
trunk/src/base/mdictionary.config [new file with mode: 0644]
trunk/src/base/xslt2.qrc

diff --git a/data/mdictionary.defaults b/data/mdictionary.defaults
deleted file mode 100644 (file)
index ca7c907..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-[%General]
-plugin_path=/usr/lib/mdictionary
-history_size=10
-search_limit=15
-
-[dictionary_0]
-type=xdxf
-path=/usr/lib/mdictionary/eng-us.xdxf
-_default_=true
-
-[dictionary_1]
-type=xdxf
-path=/usr/lib/mdictionary/eng-thai.xdxf
-_default_=true
index 0c36b9b..049d757 100644 (file)
 #include "ConfigGenerator.h"
 
 bool ConfigGenerator::generateCss(QString file) {
+    return generateFile(":/xsl/style.css", file);
+}
+
+
+
+bool ConfigGenerator::generateDefaultConfig(QString file) {
+    return generateFile(":/config/mdictionary.config", file);
+}
+
+
+
+bool ConfigGenerator::generateFile(QString source, QString file) {
     QFile _file(file);
     if(_file.exists())
         return true;
-    QFile cssFile(":/xsl/style.css");
-    if(cssFile.copy(file)) {
+    QFile srcFile(source);
+    if(srcFile.copy(file)) {
         _file.setPermissions(QFile::ReadOwner | QFile::WriteOwner |
             QFile::ReadGroup | QFile::WriteGroup | QFile::ReadOther);
         return true;
index 1b43115..9ae26c8 100644 (file)
 
 #include <QFile>
 #include <QString>
+#include <QDebug>
 
 /*! ConfigGenerator generatesconfiguration files (with default values),
 if given file dosent exists.
-
-For now only css is generateed in this way, but iam planign to refactor all
-configuration files to work that way.
 */
 class ConfigGenerator {
 
@@ -46,6 +44,17 @@ public:
             return true; if file dosent exists but cannot be generated returns false
     */
     bool generateCss(QString file);
+
+
+    /*! Generates default configuration files
+        \param file file to be generated
+        \return if file was generated - returns true; if file alredy exists
+            return true; if file dosent exists but cannot be generated returns false
+    */
+    bool generateDefaultConfig(QString file);
+
+private:
+    bool generateFile(QString source, QString file);
 };
 
 #endif // CONFIGGENERATOR_H
index 10116c7..fca9ef4 100644 (file)
@@ -71,34 +71,22 @@ public:
 
 void Backbone::init() {
 
+   _dictNum = 0;
    _dir = QDir::homePath() + "/.mdictionary/";
    if(!_configPath.size())
        _configPath = _dir + "mdictionary.config";
-   if(!_defaultConfigPath.size())
-       _defaultConfigPath = _dir + "mdictionary.defaults";
    if(!_pluginPath.size())
        _pluginPath = "/usr/lib/mdictionary";
-   _historyLen = 10;
-   _searchLimit = 15;
 
    //Install default config files
    ConfigGenerator confGen;
    confGen.generateCss(_dir + "style.css");
+   confGen.generateDefaultConfig(_configPath);
 
-
-
-   loadPrefs(_defaultConfigPath);
-
-   // Default configuration are stored in separate config file and we dont want
-   // to update it
-   _defaultPluginPath = _pluginPath;
-   _defaultHistoryLen = _historyLen;
-   _defaultSearchLimit = _searchLimit;
    loadPrefs(_configPath);
 
    loadPlugins();
 
-   loadDicts(_defaultConfigPath, true);
    loadDicts(_configPath);
 
    connect(&_resultWatcher, SIGNAL(finished()), this, SLOT(translationReady()));
@@ -114,8 +102,7 @@ void Backbone::init() {
    QThreadPool::globalInstance()->setMaxThreadCount(
            QThreadPool::globalInstance()->maxThreadCount()+1);
 
-   _history = new History(5, this);
-   _dictNum = 0;
+   _history = new History(_historyLen, this);
 }
 
 
@@ -127,7 +114,6 @@ Backbone::Backbone(QString pluginPath, QString configPath, bool dry,
     _pluginPath = pluginPath;
     _configPath = configPath;
 
-    _defaultConfigPath = configPath;
     dryRun = false;
     if(dry)
         dryRun = true;
@@ -157,6 +143,7 @@ Backbone::~Backbone()
 
 
 Backbone::Backbone(const Backbone &b) :QObject(b.parent()) {
+    init();
     _dicts = QHash<CommonDictInterface*, bool > (b._dicts);
     _plugins = QList<CommonDictInterface* > (b._plugins);
     _result = QHash<QString, Translation* > (b._result);
@@ -264,6 +251,8 @@ void Backbone::addDictionary(CommonDictInterface *dict, bool active) {
              SIGNAL(notify(Notify::NotifyType,QString)));
  }
 
+
+
  void Backbone::removeDictionary(CommonDictInterface *dict) {
      _dicts.remove(dict);
      delete dict;
@@ -311,6 +300,9 @@ void Backbone::translationReady() {
     }
 }
 
+
+
+
 QStringList Backbone::getFilesFromDir(QString dir, QStringList nameFilter) {
     QDir plug(QDir::toNativeSeparators(dir));
     if(!plug.exists()) {
@@ -341,7 +333,6 @@ void Backbone::loadPlugins() {
             Q_EMIT notify(Notify::Error,
                     QString("%1 plugin cannot be loaded: %2.")
                     .arg(file).arg(loader.errorString()));
-            qDebug()<< file << " " << loader.errorString();
             continue;
         }
         QObject *pl = loader.instance();
@@ -404,17 +395,7 @@ void Backbone::savePrefs(QSettings *set) {
 
 
 
-void Backbone::saveDefaultPrefs(QSettings *set) {
-    if(dryRun)
-        return;
-    set->setValue("general/plugin_path", _defaultPluginPath);
-    set->setValue("general/history_size", _defaultHistoryLen);
-    set->setValue("general/search_limit", _defaultSearchLimit);
-}
-
-
-
-void Backbone::loadDicts(QString fileName, bool _default) {
+void Backbone::loadDicts(QString fileName) {
     if(dryRun)
         return;
 
@@ -453,9 +434,6 @@ void Backbone::loadDicts(QString fileName, bool _default) {
         }
         bool active = set.value("active",1).toBool();
 
-        if(_default)
-            plugSet->setValue("_default_", "true");
-
         set.endGroup();
         addInternalDictionary(plug->getNew(plugSet), active);
     }
@@ -480,22 +458,12 @@ void Backbone::dictUpdated() {
     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());
+        saveState(&set, dict->settings(), _dicts[dict], dict->hash());
     }
 }
 
index cf44ae6..55b3ebb 100644 (file)
@@ -303,12 +303,10 @@ private:
     QFutureWatcher<QString> _htmlResultWatcher;
 
 
-    QString _pluginPath, _defaultPluginPath;
+    QString _pluginPath;
     QString _configPath;
-    QString _defaultConfigPath;
     QString _dir;
-    int _defaultSearchLimit;
-    int _historyLen, _defaultHistoryLen;
+    int _historyLen;
 
     bool dryRun; // mainly for testing - when true then doesn't bother configs etc
     bool stopped; // true when user stops searching/fetching
@@ -323,12 +321,11 @@ private:
     QStringList getFilesFromDir(QString dir, QStringList nameFilter);
     void loadPlugins(); //< locate and load plugins
     void loadPrefs(QString fileName);
-    void loadDicts(QString fileName, bool _default=false);
+    void loadDicts(QString fileName);
 
     void saveState(QSettings*, Settings*, bool, uint);
     void addInternalDictionary(CommonDictInterface*, bool);
     void savePrefs(QSettings*);
-    void saveDefaultPrefs(QSettings*);
 
     CommonDictInterface* plugin(QString type); // search for given type plugin
     QList<CommonDictInterface*> activeDicts();
index b43f9e0..aec27f2 100644 (file)
@@ -73,10 +73,7 @@ unix {
     # MAKE INSTALL
     INSTALLS += target \
         desktop \
-        icon64 \
-        configs
-    configs.path = ~/.mdictionary
-    configs.files += ../../../data/mdictionary.defaults
+        icon64
     target.path = $$BINDIR
     maemo5 { 
         desktop.path = $$DATADIR/applications/hildon
diff --git a/trunk/src/base/mdictionary.config b/trunk/src/base/mdictionary.config
new file mode 100644 (file)
index 0000000..35c8b85
--- /dev/null
@@ -0,0 +1,12 @@
+[general]
+plugin_path=/usr/lib/mdictionary
+history_size=10
+search_limit=15
+
+[dictionary_0]
+type=xdxf
+path=/usr/lib/mdictionary/eng-us.xdxf
+
+[dictionary_1]
+type=xdxf
+path=/usr/lib/mdictionary/eng-thai.xdxf
index 818243c..243b9b6 100644 (file)
@@ -3,4 +3,7 @@
         <file>xsl.xsl</file>
         <file>style.css</file>
     </qresource>
+    <qresource prefix="/config">
+        <file>mdictionary.config</file>
+    </qresource>
 </RCC>