Commit 05f61cfd645b8fc482e1c005a4a2a0f3bfd506db

Authored by Thiago Rocha
1 parent 4f983034
Exists in master

Coleta impressoras cadastradas no CUPS do Linux.

Showing 2 changed files with 33 additions and 0 deletions   Show diff stats
src/cacic_hardware.cpp
... ... @@ -10,6 +10,10 @@ void cacic_hardware::iniciaColeta()
10 10 #elif defined(Q_OS_LINUX)
11 11 OperatingSystem operatingSystem;
12 12  
  13 +
  14 + // Como criaremos pacotes agora, todas essas verificações podiam só
  15 + // ser incluídas como dependências.
  16 +
13 17 // se o shell retorna erro ao tentar utilizar o lshw ou o dmidecode, instala o mesmo
14 18 if( console("lshw").contains("/bin/sh:") ){ qDebug() << "lshw nao instalado.";
15 19 if(operatingSystem.getIdOs() == OperatingSystem::LINUX_ARCH)
... ... @@ -288,6 +292,7 @@ QJsonObject cacic_hardware::coletaLinux()
288 292 coletaLinuxBios(hardware);
289 293 coletaLinuxMotherboard(hardware);
290 294 coletaLinuxIsNotebook(hardware);
  295 + coletaLinuxPrinters(hardware);
291 296  
292 297 return hardware;
293 298 }
... ... @@ -435,6 +440,33 @@ void cacic_hardware::coletaLinuxIsNotebook(QJsonObject &amp;hardware)
435 440  
436 441 }
437 442  
  443 +void cacic_hardware::coletaLinuxPrinters(QJsonObject &hardware)
  444 +{
  445 + QStringList consoleOutput;
  446 +
  447 + if( console("lpstat").contains("/bin/sh:") ) { // Cups não instalado
  448 + return;
  449 + } else {
  450 +
  451 + consoleOutput = console("lpstat -a").split("\n");
  452 + consoleOutput.removeLast(); // remover o último elemento que é somente vazio
  453 +
  454 + if( consoleOutput[0].contains("No destination") )
  455 + return;
  456 +
  457 + QJsonArray printersList;
  458 + foreach(QString line, consoleOutput ) {
  459 +
  460 + if ( line.split(" ")[1] == QString("accepting") ) {
  461 + QString printerName = line.split(" ")[0];
  462 + printersList.append(QJsonValue::fromVariant(printerName));
  463 + }
  464 + }
  465 + hardware["printers"] = printersList;
  466 + }
  467 +
  468 +}
  469 +
438 470 #endif
439 471 QJsonObject cacic_hardware::toJsonObject() {
440 472 return coletaHardware;
... ...
src/cacic_hardware.h
... ... @@ -34,6 +34,7 @@ private:
34 34 void coletaLinuxBios(QJsonObject &hardware);
35 35 void coletaLinuxMotherboard(QJsonObject &hardware);
36 36 void coletaLinuxIsNotebook(QJsonObject &hardware);
  37 + void coletaLinuxPrinters(QJsonObject &hardware);
37 38 #endif
38 39  
39 40 CCacic oCacic;
... ...