/*************************************************************************** * This file is part of awesome-widgets * * * * awesome-widgets is free software: you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation, either version 3 of the * * License, or (at your option) any later version. * * * * awesome-widgets is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ #include "extscript.h" #include #include #include #include ExtScript::ExtScript(const QString scriptName, const QStringList directories, const bool debugCmd) : QObject(0), name(scriptName), dirs(directories), debug(debugCmd) { } ExtScript::~ExtScript() { if (debug) qDebug() << PDEBUG; } void ExtScript::addDirectory(const QString dir) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Directory" << dir; QString absPath = QDir(dir).absolutePath(); if (!QDir(absPath).exists()) return; for (int i=0; i settings; for (int i=0; i newSettings = getConfigurationFromFile(fileName); for (int i=0; i settings) { if (settings.contains(QString("ACTIVE"))) { if (settings[QString("ACTIVE")] == QString("true")) setActive(true); else setActive(false); } if (settings.contains(QString("INTERVAL"))) { setInterval(settings[QString("INTERVAL")].toInt()); } if (settings.contains(QString("PREFIX"))) { setPrefix(settings[QString("PREFIX")]); } if (settings.contains(QString("OUTPUT"))) { if (settings[QString("OUTPUT")] == QString("true")) setHasOutput(true); else setHasOutput(false); } if (settings.contains(QString("REDIRECT"))) { setRedirect((Redirect)settings[QString("REDIRECT")].toInt()); } } QMap ExtScript::getConfigurationFromFile(const QString fileName) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "File" << fileName; QMap settings; QFile configFile(fileName); QString fileStr; if (!configFile.open(QIODevice::ReadOnly)) return settings; while (true) { fileStr = QString(configFile.readLine()).trimmed(); if ((fileStr.isEmpty()) && (!configFile.atEnd())) continue; if ((fileStr[0] == QChar('#')) && (!configFile.atEnd())) continue; if ((fileStr[0] == QChar(';')) && (!configFile.atEnd())) continue; if (fileStr.contains(QChar('='))) settings[fileStr.split(QChar('='))[0]] = fileStr.split(QChar('='))[1]; if (configFile.atEnd()) break; } configFile.close(); for (int i=0; i