| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#pragma once |
| 19 |
#include <QStringList> |
| 20 |
#include <QNetworkAccessManager> |
| 21 |
#include <QNetworkReply> |
| 22 |
#include <QQmlListProperty> |
| 23 |
#include "discoveredrelease.h" |
| 24 |
|
| 25 |
class Scanner : public QObject { |
| 26 |
Q_OBJECT |
| 27 |
Q_PROPERTY(bool finishedScan READ finishedScan NOTIFY signalFinished) |
| 28 |
Q_PROPERTY(bool isAuto READ isAuto WRITE setIsAuto NOTIFY isAutoChanged) |
| 29 |
Q_PROPERTY(bool isActive READ isActive WRITE setIsActive NOTIFY isActiveChanged) |
| 30 |
Q_PROPERTY(int findExisting READ findExisting WRITE setFindExisting NOTIFY findExistingChanged) |
| 31 |
Q_PROPERTY(DiscoveredRelease* curRelease READ curRelease NOTIFY curReleaseChanged) |
| 32 |
|
| 33 |
Q_PROPERTY(QQmlListProperty<DiscoveredRelease> history READ history NOTIFY historyChanged) |
| 34 |
public: |
| 35 |
Scanner() |
| 36 |
: QObject() |
| 37 |
, _finishedScan(false) |
| 38 |
, _isAuto(false) |
| 39 |
, _isActive(false) |
| 40 |
, _findExisting(0) |
| 41 |
, _scansActive(0) |
| 42 |
, _curRelease(NULL) |
| 43 |
{ |
| 44 |
_manager = new QNetworkAccessManager(); |
| 45 |
} |
| 46 |
virtual ~Scanner() {} |
| 47 |
bool isAuto() const { return _isAuto; } |
| 48 |
bool isActive() const { return _isActive; } |
| 49 |
int findExisting() const { return _findExisting; } |
| 50 |
QString softwareRelease() const { return _softwareRelease; } |
| 51 |
DiscoveredRelease* curRelease() { return _curRelease; } |
| 52 |
QQmlListProperty<DiscoveredRelease> history() { |
| 53 |
return QQmlListProperty<DiscoveredRelease>(this, _history); |
| 54 |
} |
| 55 |
void completeScan() { |
| 56 |
_scansActive--; |
| 57 |
if (_scansActive < 0) |
| 58 |
_scansActive = 0; |
| 59 |
if (_scansActive == 0) { |
| 60 |
|
| 61 |
if (_curRelease->srVersion().startsWith('1')) { |
| 62 |
if (_findExisting != 2 && (_findExisting != 1 || _curRelease->baseUrl() != "")) { |
| 63 |
setIsAuto(false); |
| 64 |
} |
| 65 |
_history.prepend(_curRelease); |
| 66 |
emit historyChanged(); |
| 67 |
} else { |
| 68 |
_curRelease->setSrVersion(tr("No Release")); |
| 69 |
} |
| 70 |
setIsActive(false); |
| 71 |
finishedFunc(); |
| 72 |
} |
| 73 |
emit curReleaseChanged(); |
| 74 |
} |
| 75 |
|
| 76 |
void finishedFunc() { |
| 77 |
emit signalFinished(); |
| 78 |
_finishedScan = true; emit signalFinished(); |
| 79 |
_finishedScan = false; |
| 80 |
} |
| 81 |
void setIsAuto(bool isAuto) { _isAuto = isAuto; emit isAutoChanged(); } |
| 82 |
void setIsActive(bool isActive) { _isActive = isActive; emit isActiveChanged(); } |
| 83 |
void setFindExisting(int findExisting) { _findExisting = findExisting; emit findExistingChanged(); } |
| 84 |
|
| 85 |
Q_INVOKABLE void clearHistory(); |
| 86 |
Q_INVOKABLE void exportHistory(); |
| 87 |
Q_INVOKABLE void reverseLookup(QString OSver); |
| 88 |
Q_INVOKABLE void generatePotentialLinks(); |
| 89 |
|
| 90 |
bool finishedScan() const { return _finishedScan; } |
| 91 |
|
| 92 |
private slots: |
| 93 |
void newSRVersion(); |
| 94 |
void validateDownload(); |
| 95 |
void serverError(QNetworkReply::NetworkError err); |
| 96 |
|
| 97 |
Q_SIGNALS: |
| 98 |
void signalFinished(); |
| 99 |
void isAutoChanged(); |
| 100 |
void isActiveChanged(); |
| 101 |
void findExistingChanged(); |
| 102 |
void softwareReleaseChanged(); |
| 103 |
void curReleaseChanged(); |
| 104 |
void historyChanged(); |
| 105 |
|
| 106 |
private: |
| 107 |
bool _finishedScan; |
| 108 |
bool _isAuto, _isActive; |
| 109 |
int _findExisting; |
| 110 |
int _scansActive; |
| 111 |
QString _softwareRelease; |
| 112 |
DiscoveredRelease* _curRelease; |
| 113 |
QList<DiscoveredRelease*> _history; |
| 114 |
QNetworkAccessManager* _manager; |
| 115 |
|
| 116 |
void appendNewLink(QString *potentialText, QString linkType, QString hwType, QString version); |
| 117 |
}; |