#include "configengine.h" #include #include ConfigEngine::ConfigEngine() { } QHash ConfigEngine::confmap; void ConfigEngine::init(){ QString cpath = QDir::currentPath(); cpath += "/configuration/base_config.ini"; QFile conFile (cpath); conFile.open(QIODevice::ReadOnly); QString confstr = conFile.readAll(); conFile.close(); foreach(QString line, confstr.split("\n")){ if(line.length() > 1 && line.contains("=") && !line.startsWith("#")){ // bypasss "broken" lines QString key = line.left(line.indexOf("=")); if(key.contains(" ")){ key = key.trimmed(); } QString value = line.right(line.length()-(line.indexOf("=")+1)); // while(value.startsWith(" ")){ // bad fix? lol // value = value.right(value.length()-1); // } // /* trim broken data */ // if(value.contains("\r")){ // value = value.replace("\r", ""); // } // if(value.contains("\t")){ // value = value.replace("\t", ""); // } value = value.trimmed(); /* replace "key strings" */ if(value.contains("@workdir@")){ value = value.replace("@workdir@", QDir::currentPath()); } // more to come later confmap.insert(key, value); } } } QString ConfigEngine::getValue(QString key){ return confmap.value(key, NULL); } void ConfigEngine::saveConfig(){ // todo: write this, it's not used yet though. } void ConfigEngine::setValue(QString key, QString newval){ confmap.insert(key, newval); }