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