Commit 496eb90cd2684ba2a2b08181884f31c74862c1cc

Authored by Thiago Rocha
1 parent 5757e377
Exists in master

Refactor para criação da classe OperatingSystem

cacic-teste/testcacic.cpp
@@ -88,7 +88,8 @@ void CTestCacic::testInterfaceDeRede(){ @@ -88,7 +88,8 @@ void CTestCacic::testInterfaceDeRede(){
88 88
89 void CTestCacic::testpegarOS(){ 89 void CTestCacic::testpegarOS(){
90 //basta que seja um retorno válido, não precisa validar todos. 90 //basta que seja um retorno válido, não precisa validar todos.
91 - QVERIFY(OCacicComp.getOs() != -1 ); 91 +
  92 + QVERIFY(OCacicComp.getOs().getIdSo() != -1 );
92 } 93 }
93 94
94 void CTestCacic::testConsole() 95 void CTestCacic::testConsole()
src/cacic_computer.cpp
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 CACIC_Computer::CACIC_Computer() 3 CACIC_Computer::CACIC_Computer()
4 { 4 {
5 - os = pegarOS(); 5 + operatingSystem = OperatingSystem();
6 networkInterface = networkInterfacesRunning(); 6 networkInterface = networkInterfacesRunning();
7 usuario = pegarUsu(); 7 usuario = pegarUsu();
8 } 8 }
@@ -70,50 +70,6 @@ QJsonObject CACIC_Computer::toJsonObject() @@ -70,50 +70,6 @@ QJsonObject CACIC_Computer::toJsonObject()
70 // json.insert("network", network); 70 // json.insert("network", network);
71 } 71 }
72 72
73 -  
74 -/*pegarOS  
75 - * @return: int;  
76 - * retorna um id referente a versão do SO.  
77 - * 48 = Windows XP  
78 - * 128 = Windows Vista  
79 - * 144 = Windows 7  
80 - * 160 = Windows 8  
81 - * 176 = Windows 8.1  
82 - * 200 = Linux  
83 - * 0 = unkown  
84 - */  
85 -int CACIC_Computer::pegarOS(){  
86 -/*Não entendi o que você tentou fazer aqui, mas não funcionou.  
87 - * Você chegou a testar? Comenta o que era pra fazer.  
88 - * ======  
89 - * Não testei, mas quis pegar os valores definidos no enum do QSysInfo  
90 - * para Windows e, em vez de retornar estes valores ( que estão  
91 - * comentados acima), retornar os valores do enum da própria CACIC_Computer.  
92 - */  
93 -//#if defined (Q_OS_WIN) || defined(Q_OS_CYGWIN)  
94 -// if(QSysInfo::WindowsVersion == QSysInfo::WV_XP)  
95 -// return WIN_XP;  
96 -// else if(QSysInfo::WindowsVersion == QSysInfo::WV_VISTA)  
97 -// return WIN_VISTA;  
98 -// else if(QSysInfo::WindowsVersion == QSysInfo::WV_WINDOWS7)  
99 -// return WIN_7;  
100 -// else if(QSysInfo::WindowsVersion == QSysInfo::WV_WINDOWS8)  
101 -// return WIN_8;  
102 -// else if(QSysInfo::WindowsVersion == QSysInfo::WV_WINDOWS8_1)  
103 -// return WIN_8_1;  
104 -#if defined (Q_OS_WIN)  
105 - return QSysInfo::WindowsVersion;  
106 -#elif defined(Q_OS_MAC)  
107 - return MAC;  
108 -#elif defined (Q_OS_LINUX)  
109 -  
110 - //TODO: extrair info de distro do "cat /etc/*release"  
111 - return LINUX_ARCH;  
112 -#else  
113 - return -1;  
114 -#endif  
115 -}  
116 -  
117 /* 73 /*
118 * PegarUsu() 74 * PegarUsu()
119 * @return: std::string; 75 * @return: std::string;
@@ -135,9 +91,9 @@ std::string CACIC_Computer::pegarUsu(){ @@ -135,9 +91,9 @@ std::string CACIC_Computer::pegarUsu(){
135 /* 91 /*
136 * getters/setters 92 * getters/setters
137 */ 93 */
138 -int CACIC_Computer::getOs() const 94 +OperatingSystem CACIC_Computer::getOs() const
139 { 95 {
140 - return os; 96 + return operatingSystem;
141 } 97 }
142 98
143 std::string CACIC_Computer::getUser() const { 99 std::string CACIC_Computer::getUser() const {
src/cacic_computer.h
@@ -8,40 +8,26 @@ @@ -8,40 +8,26 @@
8 #include <QtNetwork/QtNetwork> 8 #include <QtNetwork/QtNetwork>
9 #include <QSysInfo> 9 #include <QSysInfo>
10 10
11 -#include <stdio.h>  
12 -#include <unistd.h>  
13 -#include <sys/types.h> 11 +#include <operatingsystem.h>
14 12
15 class CACIC_Computer 13 class CACIC_Computer
16 { 14 {
17 public: 15 public:
18 CACIC_Computer(); 16 CACIC_Computer();
19 17
20 - int getOs() const; 18 + OperatingSystem getOs() const;
21 std::string getUser() const; 19 std::string getUser() const;
22 QList<QVariantMap> getNetworkInterface() const; 20 QList<QVariantMap> getNetworkInterface() const;
23 QList<QVariantMap> networkInterfacesRunning(); 21 QList<QVariantMap> networkInterfacesRunning();
24 QJsonObject toJsonObject(); 22 QJsonObject toJsonObject();
25 23
26 - enum OsList {  
27 - WIN_XP,  
28 - WIN_VISTA,  
29 - WIN_7,  
30 - WIN_8,  
31 - WIN_8_1,  
32 - MAC,  
33 - LINUX_DEBIAN,  
34 - LINUX_UBUNTU,  
35 - LINUX_ARCH  
36 - };  
37 - static const enum OsList OsList;  
38 -  
39 private: 24 private:
  25 +
  26 + OperatingSystem operatingSystem;
40 int pegarOS(); 27 int pegarOS();
41 std::string pegarUsu(); 28 std::string pegarUsu();
42 29
43 QList<QVariantMap> networkInterface; 30 QList<QVariantMap> networkInterface;
44 - int os;  
45 std::string usuario; 31 std::string usuario;
46 32
47 }; 33 };
src/operatingsystem.cpp 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +#include "operatingsystem.h"
  2 +
  3 +/*pegarOS
  4 + * @return: int;
  5 + * retorna um id referente a versão do SO.
  6 + * 48 = Windows XP
  7 + * 128 = Windows Vista
  8 + * 144 = Windows 7
  9 + * 160 = Windows 8
  10 + * 176 = Windows 8.1
  11 + * 200 = Linux
  12 + */
  13 +int OperatingSystem::pegarOS(){
  14 +#if defined (Q_OS_WIN)
  15 + return QSysInfo::WindowsVersion;
  16 +#elif defined (Q_OS_LINUX)
  17 + return 200;
  18 +#else
  19 + return 0;
  20 +#endif
  21 +}
  22 +
  23 +int OperatingSystem::getIdSo() const
  24 +{
  25 + return idSo;
  26 +}
  27 +
  28 +void OperatingSystem::setIdSo(int value)
  29 +{
  30 + idSo = value;
  31 +}
  32 +
  33 +OperatingSystem::OperatingSystem()
  34 +{
  35 +}
src/operatingsystem.h 0 → 100644
@@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
  1 +#ifndef OPERATINGSYSTEM_H
  2 +#define OPERATINGSYSTEM_H
  3 +
  4 +#include <QtCore>
  5 +#include <QSysInfo>
  6 +
  7 +class OperatingSystem
  8 +{
  9 +private:
  10 + int idSo;
  11 +
  12 + int pegarOS();
  13 +public:
  14 + OperatingSystem();
  15 +
  16 + enum OsList {
  17 + MAC,
  18 + LINUX_DEBIAN,
  19 + LINUX_UBUNTU,
  20 + LINUX_ARCH
  21 + };
  22 + static const enum OsList OsList;
  23 +
  24 + int getIdSo() const;
  25 + void setIdSo(int value);
  26 +};
  27 +
  28 +#endif // OPERATINGSYSTEM_H