From 845fdf994f8ba164511025d312ca859166c33de5 Mon Sep 17 00:00:00 2001 From: Thiago Rocha Date: Fri, 15 Aug 2014 10:20:15 -0300 Subject: [PATCH] Alteração no testConsole para passar somente no Linux e no coletaIdOs para retornar distribuição. --- cacic-teste/testcacic.cpp | 6 ++++-- src/console.h | 7 +++++-- src/operatingsystem.cpp | 20 ++++++++++++++++++-- src/operatingsystem.h | 4 ++++ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/cacic-teste/testcacic.cpp b/cacic-teste/testcacic.cpp index b643498..9b85316 100644 --- a/cacic-teste/testcacic.cpp +++ b/cacic-teste/testcacic.cpp @@ -94,9 +94,11 @@ void CTestCacic::testpegarOS(){ void CTestCacic::testConsole() { ConsoleObject console; - -// QVERIFY(console("echo teste").toStdString() == "teste\n"); +#if defined(Q_OS_LINUX) + QVERIFY(console("echo teste").toStdString() == "teste\n"); +#else QVERIFY(false); +#endif } void CTestCacic::testPegarUsu(){ diff --git a/src/console.h b/src/console.h index 068dc67..5cd4377 100644 --- a/src/console.h +++ b/src/console.h @@ -11,14 +11,18 @@ class ConsoleObject:public std::unary_function public: -#if defined(Q_OS_LINUX) + QString operator() (std::string input) { QProcess* process = new QProcess(); +#if defined(Q_OS_LINUX) QStringList options; options << "-c" << QString::fromStdString(input); process->start("/bin/sh", options); +#elif defined(Q_OS_WIN) + process->start(input); +#endif process->waitForFinished(); QString output = process->readAll(); // qDebug() << output; @@ -26,7 +30,6 @@ public: delete process; return output; } -#endif }; #endif // CONSOLE_H diff --git a/src/operatingsystem.cpp b/src/operatingsystem.cpp index 5b43c4a..937b288 100644 --- a/src/operatingsystem.cpp +++ b/src/operatingsystem.cpp @@ -6,6 +6,7 @@ OperatingSystem::OperatingSystem() this->nomeOs = this->coletaNomeOs(); } + /*pegarOS * @return: int; * retorna um id referente a versão do SO. @@ -14,13 +15,28 @@ OperatingSystem::OperatingSystem() * 144 = Windows 7 * 160 = Windows 8 * 176 = Windows 8.1 - * 200 = Linux + * [enum] = Linux */ int OperatingSystem::coletaIdOs(){ #if defined (Q_OS_WIN) return QSysInfo::WindowsVersion; #elif defined (Q_OS_LINUX) - return LINUX_ARCH; + + ConsoleObject console; + QStringList catOutput = console("cat /etc/*release").split("\n"); + + QString line; + foreach(line, catOutput) { + if(line.contains("PRETTY_NAME")) { + if( line.contains("Arch")) + return LINUX_ARCH; + else if( line.contains("Debian")) + return LINUX_DEBIAN; + else if( line.contains("Ubuntu")) + return LINUX_UBUNTU; + } + } + #else return 0; #endif diff --git a/src/operatingsystem.h b/src/operatingsystem.h index 2356846..96ef2e0 100644 --- a/src/operatingsystem.h +++ b/src/operatingsystem.h @@ -2,8 +2,12 @@ #define OPERATINGSYSTEM_H #include +#include +#include #include + #include +#include class OperatingSystem { -- libgit2 0.21.2