#include "config.h" #include #include #include #include #include "defines.h" /** * Constructor. Calls load(). */ Config::Config(QString conf):QObject(){ configfile = conf; load(); }; /** * Parses the configfile into the internal lookuptables. Because the configfile * is essential it quits the whole application if this failes. */ void Config::load(){ QFile file( configfile ); if ( !file.open( IO_ReadOnly ) ){ qFatal("Reading configfile %s failed - try giving it as parameter",configfile.ascii()); qApp->exit(-1); } QTextStream t(&file); QString s; QString key; QString val; QString section; while ( !t.eof() ) { s = t.readLine(); //read line s = s.section('#',0,0); //strip comment s = s.stripWhiteSpace(); //strip whitespaces if(s.isEmpty()) continue; //strip empty lines key = s.section('=',0,0); val = s.section('=',1,1); key = key.stripWhiteSpace(); val = val.stripWhiteSpace(); if(key.startsWith("[") and key.endsWith("]")){ section = key.mid(1,key.length()-2); // qDebug("Config section %s",section.latin1()); }else{ // qDebug("Config option %s , %s",key.latin1(),val.latin1()); if(section == "programs"){ programs[key]=val; }else if(section == "buttons"){ buttons[key]=val; }else{ general[key]=val; } } } file.close(); } /** * Returns the action defined for the given LIRC button or "" if no * action is defined */ QString Config::getLIRCbutton(QString btn){ lut::Iterator it = buttons.find(btn); if(it == buttons.end()){ return ""; }else{ return it.data(); } } /** * Returns the value of the given global option or "" if no value * was found */ QString Config::getOption(QString opt){ lut::Iterator it = general.find(opt); if(it == general.end()){ return ""; }else{ return it.data(); } } /** * Returns the configured program for the given file or "" if none * was specified */ QString Config::getProgram(QString file){ lut::Iterator it; for ( it = programs.begin(); it != programs.end(); ++it ) { if(file.endsWith(it.key())){ return it.data(); } } return ""; } /** * Returns true if the given path is a defined mountpoint */ bool Config::isMountPoint(QString dir){ lut::Iterator it; for (int i =1; i <= MOUNTPOINTS; i++){ it = general.find(QString("mount%1").arg(i)); if(it == general.end()){ continue; }else{ if(it.data() == dir) return true; } } return false; }