diff options
author | Kris Moore <kris@pcbsd.org> | 2014-09-04 11:42:13 -0400 |
---|---|---|
committer | Kris Moore <kris@pcbsd.org> | 2014-09-04 11:42:13 -0400 |
commit | 71737f70949bd25f9aa8bc4e7d03039ba83c6cb1 (patch) | |
tree | ab29e864d1ae59d10cc6875af9541e3ad306b2fb /libLumina/LuminaUtils.cpp | |
parent | Initial commit (diff) | |
download | lumina-71737f70949bd25f9aa8bc4e7d03039ba83c6cb1.tar.gz lumina-71737f70949bd25f9aa8bc4e7d03039ba83c6cb1.tar.bz2 lumina-71737f70949bd25f9aa8bc4e7d03039ba83c6cb1.zip |
Initial import of the lumina code from pcbsd git repo
Diffstat (limited to 'libLumina/LuminaUtils.cpp')
-rw-r--r-- | libLumina/LuminaUtils.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp new file mode 100644 index 00000000..8a652e96 --- /dev/null +++ b/libLumina/LuminaUtils.cpp @@ -0,0 +1,66 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2013, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "LuminaUtils.h" + +int LUtils::runCmd(QString cmd, QStringList args){ + QProcess *proc = new QProcess; + proc->setProcessChannelMode(QProcess::MergedChannels); + if(args.isEmpty()){ + proc->start(cmd); + }else{ + proc->start(cmd, args); + } + while(!proc->waitForFinished(300)){ + QCoreApplication::processEvents(); + } + int ret = proc->exitCode(); + delete proc; + return ret; + +} + +QStringList LUtils::getCmdOutput(QString cmd, QStringList args){ + QProcess *proc = new QProcess; + proc->setProcessChannelMode(QProcess::MergedChannels); + if(args.isEmpty()){ + proc->start(cmd); + }else{ + proc->start(cmd,args); + } + while(!proc->waitForFinished(300)){ + QCoreApplication::processEvents(); + } + QStringList out = QString(proc->readAllStandardOutput()).split("\n"); + delete proc; + return out; +} + +QStringList LUtils::readFile(QString filepath){ + QStringList out; + QFile file(filepath); + if(file.open(QIODevice::Text | QIODevice::ReadOnly)){ + QTextStream in(&file); + while(!in.atEnd()){ + out << in.readLine(); + } + file.close(); + } + return out; +} + +bool LUtils::writeFile(QString filepath, QStringList contents, bool overwrite){ + QFile file(filepath); + QFile::OpenMode mode = overwrite ? (QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate) : (QIODevice::WriteOnly | QIODevice::Text); + bool ok = false; + if(file.open( mode ) ){ + QTextStream out(&file); + for(int i=0; i<contents.length(); i++){ out << contents[i]; } + file.close(); + ok = true; + } + return ok; +} |