internet_police.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "internet_police.h"
  2. Internet_Police::Internet_Police(QObject *parent) :
  3. QObject(parent)
  4. {
  5. this->internetManager = new QNetworkAccessManager(this);
  6. //
  7. // connette lo slot per la ricezione da internet:
  8. connect(this->internetManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
  9. }
  10. void Internet_Police::finished(QNetworkReply *reply)
  11. {
  12. if (reply->error() == QNetworkReply::NoError) {
  13. QString buffer = QString(reply->readAll());
  14. qDebug(buffer.toAscii().constData());
  15. if (buffer.contains("non risulta")) { // auto non rubata
  16. emit vehicleValid();
  17. }
  18. else {
  19. QString tmp;
  20. QVariantList modelReturned;
  21. //ui->lblTargaOttenuta->setText(ui->txtPlate->text().toUpper());
  22. buffer = buffer.mid(buffer.indexOf(plate) + plate.length()); // si posiziona dopo la targa
  23. tmp = buffer.mid(buffer.indexOf("Telaio"));
  24. tmp = tmp.mid(tmp.indexOf("#FF0000'>") + 9);
  25. buffer = buffer.mid(buffer.indexOf("#FF0000'>") + 9);
  26. modelReturned.append(tmp.mid(0, tmp.indexOf("</"))); // prende il telaio
  27. tmp = buffer.mid(buffer.indexOf("Modello"));
  28. tmp = tmp.mid(tmp.indexOf("#FF0000'>") + 9);
  29. buffer = buffer.mid(buffer.indexOf("#FF0000'>") + 9);
  30. modelReturned.append(tmp.mid(0, tmp.indexOf("</"))); // prende il modello
  31. tmp = buffer.mid(buffer.indexOf("Fabbrica"));
  32. tmp = tmp.mid(tmp.indexOf("#FF0000'>") + 9);
  33. buffer = buffer.mid(buffer.indexOf("#FF0000'>") + 9);
  34. modelReturned.append(tmp.mid(0, tmp.indexOf("</"))); // prende la fabbrica
  35. tmp = buffer.mid(buffer.indexOf("Tipo"));
  36. tmp = tmp.mid(tmp.indexOf("#FF0000'>") + 9);
  37. buffer = buffer.mid(buffer.indexOf("#FF0000'>") + 9);
  38. modelReturned.append(tmp.mid(0, tmp.indexOf("</"))); // prende il tipo
  39. buffer = buffer.mid(buffer.indexOf("#FF0000'>") + 9);
  40. tmp = buffer.mid(buffer.indexOf("<p"));
  41. tmp = tmp.mid(0, tmp.indexOf("</p>") + 4);
  42. tmp = tmp.replace("size=\"5\"", "size=\"2\"");
  43. modelReturned.append(tmp); // prende le note
  44. emit searchCompleted(modelReturned);
  45. }
  46. }
  47. else
  48. ; // informa che non è possibile collegarsi online per la verifica delle informazioni
  49. reply->deleteLater();
  50. }
  51. Internet_Police::~Internet_Police()
  52. {
  53. }
  54. void Internet_Police::on_cmdSend_clicked(QString plate)
  55. {
  56. this->plate = plate;
  57. this->internetManager->get(QNetworkRequest(QUrl(QString(URL_REQUEST) + "NumeroTarga=" + plate.trimmed() + "&NumeroTelaio=")));
  58. }