Merge branch 'master' into google
[mdictionary] / trunk / src / base / backbone / backbone.cpp
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());
     }
 }