yacreader/common/check_new_version.cpp
Luis Ángel San Martín 1bd587d18b A?adido soporte para archivos PDF
Modificados los .pro para a?adir poppler y opengl en todas las plataformas

Corregido bug relacionado con la actualizaci?n del flow al cambiar su configuraci?n

A?adida image de selecci?n de flow en espa?ol

A?adidas 2 im?genes nuevas para los dos tipos de flow nuevos

Corregidos fallos de compilaci?n en sistemas de 64bit y el include GL/glu.h

A?adidas las traducciones al espa?ol de la versi?n 5.5.0

A?adida la actualizaci?n de bibliotecas a la versi?n actual

A?adida carpeta de dependencias para la compilaci?n en Win32
2013-01-13 18:06:23 +01:00

112 lines
2.7 KiB
C++

#include "check_new_version.h"
#include <QMessageBox>
#include <QUrl>
#include <QtGlobal>
#include <QStringList>
#define PREVIOUS_VERSION "5.0.0"
HttpVersionChecker::HttpVersionChecker()
:QWidget()
{
http = new QHttp(this);
connect(http, SIGNAL(requestFinished(int, bool)),
this, SLOT(httpRequestFinished(int, bool)));
connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
connect(http, SIGNAL(readyRead(const QHttpResponseHeader &)),
this, SLOT(read(const QHttpResponseHeader &)));
}
void HttpVersionChecker::get()
{
QUrl url("http://code.google.com/p/yacreader/downloads/list");
QHttp::ConnectionMode mode = QHttp::ConnectionModeHttp;
http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port());
QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/");
if (path.isEmpty())
path = "/";
httpGetId = http->get(path, 0);
}
void HttpVersionChecker::readResponseHeader(const QHttpResponseHeader &responseHeader)
{
}
void HttpVersionChecker::read(const QHttpResponseHeader &){
content.append(http->readAll());
}
void HttpVersionChecker::httpRequestFinished(int requestId, bool error)
{
#ifdef QT_DEBUG
QString response("YACReader-5.0.0 win32.exe");
#else
QString response(content);
#endif
checkNewVersion(response);
}
//TODO escribir prueba unitaria
bool HttpVersionChecker::checkNewVersion(QString sourceContent)
{
#ifdef Q_WS_WIN
QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}win32.*");
#endif
#ifdef Q_WS_X11
QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}X11.*");
#endif
#ifdef Q_WS_MAC
QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}Mac.*");
#endif
int index = 0;
bool newVersion = false;
bool sameVersion = true;
//bool currentVersionIsNewer = false;
#ifdef QT_DEBUG
QString version(PREVIOUS_VERSION);
#else
QString version(VERSION);
#endif
QStringList sl = version.split(".");
if((index = rx.indexIn(sourceContent))!=-1)
{
int length = qMin(sl.size(),(rx.cap(4)!="")?4:3);
for(int i=0;i<length;i++)
{
if(rx.cap(i+1).toInt()<sl.at(i).toInt())
{
return false;
}
if(rx.cap(i+1).toInt()>sl.at(i).toInt()){
newVersion=true;
break;
}
else
sameVersion = sameVersion && rx.cap(i+1).toInt()==sl.at(i).toInt();
}
if(!newVersion && sameVersion)
{
if((sl.size()==3)&&(rx.cap(4)!=""))
newVersion = true;
}
}
if(newVersion == true)
{
emit newVersionDetected();
return true;
}
else
{
return false;
}
}