diff options
| author | Jonathan Bauer | 2011-03-21 11:47:21 +0100 |
|---|---|---|
| committer | Jonathan Bauer | 2011-03-21 11:47:21 +0100 |
| commit | e7329f1acbb02d6f4b1ab2be66282291bff60ccf (patch) | |
| tree | db88b2fea7c36081778fe34c10d1f2883a634824 /src/sysInfo.cpp | |
| parent | small steps towards const correctness... (diff) | |
| download | fbgui-e7329f1acbb02d6f4b1ab2be66282291bff60ccf.tar.gz fbgui-e7329f1acbb02d6f4b1ab2be66282291bff60ccf.tar.xz fbgui-e7329f1acbb02d6f4b1ab2be66282291bff60ccf.zip | |
minor code convention fixes
Diffstat (limited to 'src/sysInfo.cpp')
| -rw-r--r-- | src/sysInfo.cpp | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/src/sysInfo.cpp b/src/sysInfo.cpp deleted file mode 100644 index e7ed8a8..0000000 --- a/src/sysInfo.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "sysInfo.h" - - -// ------------------------------------------------------------------------------------------------ -sysInfo::sysInfo(){} -// ------------------------------------------------------------------------------------------------ -sysInfo::~sysInfo(){} -// ------------------------------------------------------------------------------------------------ -const QString sysInfo::getInfo(const QString& infoName){ - qxtLog->debug() << "[sysInfo] requested " << infoName; - if (infoName == QString("mac")) - return getMACAddress(); - else if (infoName == QString("ip")) - return getIPAddress(); - else if (infoName == QString("all")) - return getAllInfos(); - else if (infoName == QString("json")) - return getNames(); - /* unknown code */ - return "info_error"; -} -// ------------------------------------------------------------------------------------------------ -const QString sysInfo::getMACAddress(){ - // Returns MAC address of eth0 for now - QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0")); - if (!qni.isValid()){ - qxtLog->debug() << "No interface matching \"eth0\" found."; - return "no_eth0"; - } - //eth0_index = qni.index(); - return qni.hardwareAddress(); -} -// ------------------------------------------------------------------------------------------------ -const QString sysInfo::getIPAddress(){ - // Again for eth0 only at the moment. - // TODO: this doesn't quite work yet... - QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0")); - QList<QHostAddress> addrlist = qni.allAddresses(); - // This is does not return the right IP atm... - foreach(QHostAddress addr, addrlist){ - if (addr.protocol() == QAbstractSocket::IPv4Protocol && addr != QHostAddress::LocalHost){ - return addr.toString(); - } - } - // still here? - qxtLog->debug() << "ip_error"; - return "ip_error"; -} -// ------------------------------------------------------------------------------------------------ -const QByteArray sysInfo::getNames(){ - - QVariantMap foo; - foo.insert("name", "foo"); - foo.insert("type", 123); - - QVariantMap fooo; - fooo.insert("name", "boo"); - fooo.insert("type", 321); - - QVariantList jsonV; - jsonV << foo << fooo; - - QJson::Serializer serializer; - QByteArray json = serializer.serialize(jsonV); - - qxtLog->debug() << json; - return json; - -} -// ------------------------------------------------------------------------------------------------ -QString sysInfo::getAllInfos(){ - QVariantMap infos; - infos.insert("mac", getMACAddress()); - infos.insert("ip", getIPAddress()); - infos.insert("whoami", getScriptOutput("whoami")); - //infos.insert("pwd", getScriptOutput("pwd")); - - //QJson::Serializer serializer; - QByteArray json = serializer.serialize(infos); - - qxtLog->debug() << json; - return json; -} -// ------------------------------------------------------------------------------------------------ -QString sysInfo::getScriptOutput(QString cmd) -{ - QProcess *process = new QProcess(); - qDebug()<<"try to open: "<<cmd; - process->start(cmd, QIODevice::ReadOnly); - - if (!process->waitForStarted() ) - qDebug()<<"process couldn't get opened"; - - QString output; - process->waitForFinished(); - - QTextStream *txt_stream = new QTextStream(process); - - while(!txt_stream->atEnd() ) - { - qDebug()<<"read output: "; - QString tmp_str = txt_stream->readLine(); - output += tmp_str; - qDebug()<<tmp_str; - } - qDebug()<<"process finished: "; - return output; -} - |
