void UpdateChecker::gotReplyFromUserRequest() { qDebug("UpdateChecker::gotReplyFromUserRequest"); QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); if (reply) { if (reply->error() == QNetworkReply::NoError) { QRegExp rx_version("^latest_version=(.*)"); QString version; while (reply->canReadLine()) { QByteArray line = reply->readLine().trimmed(); if (rx_version.indexIn(line) != -1) { version = rx_version.cap(1); break; } } if (!version.isEmpty()) { if ((formattedVersion(version) > formattedVersion(Version::with_revision()))) { qDebug("UpdateChecker::gotReplyFromUserRequest: new version found: %s", version.toUtf8().constData()); emit newVersionFound(version); } else { emit noNewVersionFound(version); } } else { emit errorOcurred(1, tr("Failed to get the latest version number") ); } } else { int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); qDebug("UpdateChecker::gotReplyFromUserRequest: status: %d", status); emit errorOcurred((int)reply->error(), reply->errorString()); } reply->deleteLater(); } }
bool QNetworkReplyProto::canReadLine() const { QNetworkReply *item = qscriptvalue_cast<QNetworkReply*>(thisObject()); if (item) return item->canReadLine(); return false; }
void UpdateChecker::gotReply() { qDebug("UpdateChecker::gotReply"); QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); if (reply) { if (reply->error() == QNetworkReply::NoError) { //read data from reply QRegExp rx_version("^version=(.*)"); QString version; while (reply->canReadLine()) { QByteArray line = reply->readLine().trimmed(); //qDebug("line: %s", line.constData()); if (rx_version.indexIn(line) != -1) { version = rx_version.cap(1); //qDebug("version: %s", version.toUtf8().constData()); break; } } if (!version.isEmpty()) { d->last_checked = QDate::currentDate(); //qDebug("last known: %s version: %s", d->last_known_version.toUtf8().constData(), version.toUtf8().constData()); //qDebug("version_with_revision: %s", Version::with_revision().toUtf8().constData()); if ((d->last_known_version != version) && (formattedVersion(version) > formattedVersion(Version::with_revision()))) { qDebug("UpdateChecker::gotReply: new version found: %s", version.toUtf8().constData()); emit newVersionFound(version); } } } else { //get http status code int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); qDebug("UpdateChecker::gotReply: status: %d", status); } reply->deleteLater(); } }