Commit c489d97bb7ac17dec116d3ab92672c1884809fef

Authored by Thiago Rocha
1 parent 21581204
Exists in master

Correção da coleta do usuário no linux.

Showing 2 changed files with 14 additions and 1 deletions   Show diff stats
src/cacic_computer.cpp
@@ -45,6 +45,7 @@ QJsonObject CACIC_Computer::toJsonObject() @@ -45,6 +45,7 @@ QJsonObject CACIC_Computer::toJsonObject()
45 QJsonObject json; 45 QJsonObject json;
46 QJsonArray network; 46 QJsonArray network;
47 int count = 1; 47 int count = 1;
  48 +qDebug() << QString::fromStdString(this->usuario);
48 json["usuario"] = QJsonValue::fromVariant(QString::fromStdString(this->usuario)); 49 json["usuario"] = QJsonValue::fromVariant(QString::fromStdString(this->usuario));
49 json["operatingSystem"] = this->oOperatingSystem.toJsonObject(); 50 json["operatingSystem"] = this->oOperatingSystem.toJsonObject();
50 foreach(QVariantMap auxMap, this->getNetworkInterface()){ 51 foreach(QVariantMap auxMap, this->getNetworkInterface()){
@@ -62,16 +63,25 @@ QJsonObject CACIC_Computer::toJsonObject() @@ -62,16 +63,25 @@ QJsonObject CACIC_Computer::toJsonObject()
62 * retorna o usuario logado no sistema. (erro, retorna o usuário que está executando.) 63 * retorna o usuario logado no sistema. (erro, retorna o usuário que está executando.)
63 */ 64 */
64 std::string CACIC_Computer::pegarUsu(){ 65 std::string CACIC_Computer::pegarUsu(){
  66 +#if defined(Q_OS_WINDOWS)
65 QString text; 67 QString text;
66 QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); 68 QStringList environment = QProcessEnvironment::systemEnvironment().toStringList();
67 foreach (text, environment) { 69 foreach (text, environment) {
68 if (text.contains("USER=" , Qt::CaseInsensitive) || 70 if (text.contains("USER=" , Qt::CaseInsensitive) ||
69 text.contains("USERNAME=", Qt::CaseInsensitive) ){ 71 text.contains("USERNAME=", Qt::CaseInsensitive) ){
70 QStringList split = text.split("="); 72 QStringList split = text.split("=");
71 -// qDebug() << split[1]; 73 +
72 return split[1].toStdString(); 74 return split[1].toStdString();
73 } 75 }
74 } 76 }
  77 +
  78 +#elif defined(Q_OS_LINUX)
  79 +
  80 + QString user = console("who").split(" ")[0];
  81 + return user.toStdString();
  82 +
  83 +#endif
  84 +
75 return "0"; 85 return "0";
76 } 86 }
77 /* 87 /*
src/cacic_computer.h
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 #include <QtNetwork/QtNetwork> 8 #include <QtNetwork/QtNetwork>
9 #include <QSysInfo> 9 #include <QSysInfo>
10 #include "operatingsystem.h" 10 #include "operatingsystem.h"
  11 +#include "console.h"
11 12
12 class CACIC_Computer 13 class CACIC_Computer
13 { 14 {
@@ -26,6 +27,8 @@ private: @@ -26,6 +27,8 @@ private:
26 int pegarOS(); 27 int pegarOS();
27 std::string pegarUsu(); 28 std::string pegarUsu();
28 29
  30 + ConsoleObject console;
  31 +
29 QList<QVariantMap> networkInterface; 32 QList<QVariantMap> networkInterface;
30 std::string usuario; 33 std::string usuario;
31 34