mirror of
https://github.com/YACReader/yacreader
synced 2025-06-03 00:58:32 -04:00
HttpWorker added, performs a http request in a background thread
ComicVineDialog, work in progress...
This commit is contained in:
parent
2de876f5a9
commit
a18401c2fb
@ -59,7 +59,8 @@ HEADERS += $$PWD/comic.h \
|
||||
$$PWD/../common/comic_db.h \
|
||||
$$PWD/../common/folder.h \
|
||||
$$PWD/../common/library_item.h \
|
||||
$$PWD/yacreader_local_client.h
|
||||
$$PWD/yacreader_local_client.h \
|
||||
$$PWD/../common/http_worker.h
|
||||
|
||||
SOURCES += $$PWD/comic.cpp \
|
||||
$$PWD/configuration.cpp \
|
||||
@ -90,7 +91,8 @@ SOURCES += $$PWD/comic.cpp \
|
||||
$$PWD/../common/comic_db.cpp \
|
||||
$$PWD/../common/folder.cpp \
|
||||
$$PWD/../common/library_item.cpp \
|
||||
$$PWD/yacreader_local_client.cpp
|
||||
$$PWD/yacreader_local_client.cpp \
|
||||
$$PWD/../common/http_worker.cpp
|
||||
|
||||
include($$PWD/../custom_widgets/custom_widgets_yacreader.pri)
|
||||
include($$PWD/../compressed_archive/wrapper.pri)
|
||||
|
@ -77,7 +77,9 @@ HEADERS += comic_flow.h \
|
||||
yacreader_local_server.h \
|
||||
yacreader_main_toolbar.h \
|
||||
comics_remover.h \
|
||||
comic_vine_dialog.h
|
||||
comic_vine_dialog.h \
|
||||
comic_vine_client.h \
|
||||
../common/http_worker.h
|
||||
|
||||
SOURCES += comic_flow.cpp \
|
||||
create_library_dialog.cpp \
|
||||
@ -117,7 +119,9 @@ SOURCES += comic_flow.cpp \
|
||||
yacreader_local_server.cpp \
|
||||
yacreader_main_toolbar.cpp \
|
||||
comics_remover.cpp \
|
||||
comic_vine_dialog.cpp
|
||||
comic_vine_dialog.cpp \
|
||||
comic_vine_client.cpp \
|
||||
../common/http_worker.cpp
|
||||
|
||||
|
||||
include(./server/server.pri)
|
||||
|
79
YACReaderLibrary/comic_vine_client.cpp
Normal file
79
YACReaderLibrary/comic_vine_client.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
#include "comic_vine_client.h"
|
||||
|
||||
//this is the API key used by YACReader to access Comic Vine
|
||||
//please, do not use it in your own software, get one for free at Comic Vine
|
||||
static const QString CV_API_KEY = "46680bebb358f1de690a5a365e15d325f9649f91";
|
||||
|
||||
static const QString CV_WEB_ADDRESS = "http://comicvine.com/api";
|
||||
|
||||
//gets any volumen containing any comic matching 'query'
|
||||
static const QString CV_SEARCH = CV_WEB_ADDRESS + "/search/?api_key=" + CV_API_KEY +
|
||||
"&format=xml&limit=100&resources=volume"
|
||||
"&field_list=name,start_year,publisher,id,image,count_of_issues"
|
||||
"&query=%1&page=%2";
|
||||
|
||||
//gets the detail for a volume %1
|
||||
static const QString CV_SERIES_DETAIL = CV_WEB_ADDRESS + "/volume/4050-%1/?api_key=" + CV_API_KEY +
|
||||
"&format=xml&field_list=name,start_year,publisher,image,count_of_issues,id";
|
||||
|
||||
//gets ids for comics in a volume id %1
|
||||
static const QString CV_COMIC_IDS = CV_WEB_ADDRESS + "/issues/?api_key=" + CV_API_KEY +
|
||||
"&format=xml&field_list=name,issue_number,id,image&filter=volume:%1&page=%1";//offset??
|
||||
|
||||
//gets id for comic number %2 in a volume id %1
|
||||
static const QString CV_COMIC_ID = CV_WEB_ADDRESS + "/issues/?api_key=" + CV_API_KEY +
|
||||
"&format=xml&field_list=name,issue_number,id,image"
|
||||
"&filter=volume:%1,issue_number:%2";
|
||||
//gets comic detail
|
||||
static const QString CV_COMIC_DETAIL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=xml";
|
||||
|
||||
//gets comic cover URL
|
||||
static const QString CV_COVER_URL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=xml&field_list=image";
|
||||
|
||||
//gets comics matching name %1 and number %2
|
||||
//http://comicvine.com/api/issues/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&limit=20&filter=name:super,issue_number:15
|
||||
|
||||
ComicVineClient::ComicVineClient(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ComicVineClient::search(const QString & query, int page)
|
||||
{
|
||||
CVSearch * search = new CVSearch(query,page);
|
||||
connect(search,SIGNAL(dataReady(const QByteArry &)),this,SLOT(proccessVolumesSearchData(const QByteArry &)));
|
||||
connect(search,SIGNAL(finished()),search,SLOT(deleteLater()));
|
||||
search->get();
|
||||
}
|
||||
|
||||
void ComicVineClient::proccessVolumesSearchData(const QByteArray & data)
|
||||
{
|
||||
QString xml(data);
|
||||
}
|
||||
|
||||
void ComicVineClient::getSeriesDetail(const QString & id)
|
||||
{
|
||||
}
|
||||
|
||||
void ComicVineClient::getComicIds(const QString & id, int page)
|
||||
{
|
||||
}
|
||||
|
||||
void ComicVineClient::getComicId(const QString & id, int comicNumber)
|
||||
{
|
||||
}
|
||||
|
||||
void ComicVineClient::getComicDetail(const QString & id)
|
||||
{
|
||||
}
|
||||
|
||||
void ComicVineClient::getCoverURL(const QString & id)
|
||||
{
|
||||
}
|
||||
|
||||
//CVSearch
|
||||
CVSearch::CVSearch(const QString & query, int page)
|
||||
:HttpWorker(CV_SEARCH.arg(query).arg(page))
|
||||
{
|
||||
}
|
34
YACReaderLibrary/comic_vine_client.h
Normal file
34
YACReaderLibrary/comic_vine_client.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef COMIC_VINE_CLIENT_H
|
||||
#define COMIC_VINE_CLIENT_H
|
||||
|
||||
#include "http_worker.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class ComicVineClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ComicVineClient(QObject *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void search(const QString & query, int page = 0);
|
||||
void getSeriesDetail(const QString & id);
|
||||
void getComicIds(const QString & id, int page = 0);
|
||||
void getComicId(const QString & id, int comicNumber);
|
||||
void getComicDetail(const QString & id);
|
||||
void getCoverURL(const QString & id);
|
||||
private slots:
|
||||
void proccessVolumesSearchData(const QByteArray & data);
|
||||
|
||||
};
|
||||
|
||||
class CVSearch : public HttpWorker
|
||||
{
|
||||
public:
|
||||
CVSearch(const QString & query, int page=0);
|
||||
};
|
||||
|
||||
#endif // COMIC_VINE_CLIENT_H
|
@ -1,10 +1,105 @@
|
||||
#include "comic_vine_dialog.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QStackedWidget>
|
||||
#include <QRadioButton>
|
||||
|
||||
ComicVineDialog::ComicVineDialog(QWidget *parent) :
|
||||
QDialog(parent)
|
||||
{
|
||||
doLayout();
|
||||
doStackedWidgets();
|
||||
doConnections();
|
||||
}
|
||||
|
||||
void ComicVineDialog::doLayout()
|
||||
{
|
||||
setStyleSheet(""
|
||||
"QDialog {background-color: #404040; }"
|
||||
"");
|
||||
|
||||
QString dialogButtonsStyleSheet = "QPushButton {border: 1px solid #242424; background: #2e2e2e; color:white; padding: 5px 26px 5px 26px; font-size:12px;font-family:Arial; font-weight:bold;}";
|
||||
|
||||
QLabel * mainTitleLabel = new QLabel(tr("SEARCH"));
|
||||
QLabel * subTitleLabel = new QLabel(tr("%1 comics selected"));
|
||||
|
||||
mainTitleLabel->setStyleSheet("QLabel {color:white; font-size:18px;font-family:Arial;}");
|
||||
subTitleLabel->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}");
|
||||
|
||||
nextButton = new QPushButton(tr("next"));
|
||||
closeButton = new QPushButton(tr("close"));
|
||||
|
||||
nextButton->setStyleSheet(dialogButtonsStyleSheet);
|
||||
closeButton->setStyleSheet(dialogButtonsStyleSheet);
|
||||
|
||||
content = new QStackedWidget(this);
|
||||
//
|
||||
|
||||
QVBoxLayout * mainLayout = new QVBoxLayout;
|
||||
QHBoxLayout * titleLayout = new QHBoxLayout;
|
||||
QVBoxLayout * titleLabelsLayout = new QVBoxLayout;
|
||||
QHBoxLayout * buttonLayout = new QHBoxLayout;
|
||||
|
||||
titleLabelsLayout->addWidget(mainTitleLabel);
|
||||
titleLabelsLayout->addWidget(subTitleLabel);
|
||||
titleLabelsLayout->setSpacing(0);
|
||||
|
||||
titleLayout->addLayout(titleLabelsLayout);
|
||||
|
||||
buttonLayout->addStretch();
|
||||
buttonLayout->addWidget(nextButton);
|
||||
buttonLayout->addWidget(closeButton);
|
||||
buttonLayout->setContentsMargins(0,0,0,0);
|
||||
|
||||
mainLayout->addLayout(titleLayout);
|
||||
mainLayout->addWidget(content);
|
||||
mainLayout->addStretch();
|
||||
mainLayout->addLayout(buttonLayout);
|
||||
|
||||
mainLayout->setContentsMargins(26,16,26,11);
|
||||
|
||||
setLayout(mainLayout);
|
||||
setFixedSize(672,529);
|
||||
}
|
||||
|
||||
void ComicVineDialog::doStackedWidgets()
|
||||
{
|
||||
doSeriesQuestion();
|
||||
}
|
||||
void ComicVineDialog::doSeriesQuestion()
|
||||
{
|
||||
QWidget * w = new QWidget;
|
||||
QVBoxLayout * l = new QVBoxLayout;
|
||||
|
||||
QLabel * questionLabel = new QLabel(tr("You are trying to get information for various comics at once, are they part of the same series?"));
|
||||
questionLabel->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}");
|
||||
QRadioButton * yes = new QRadioButton(tr("yes"));
|
||||
QRadioButton * no = new QRadioButton(tr("no"));
|
||||
|
||||
QString rbStyle = "QRadioButton {margin-left:27px; margin-top:5px; color:white;font-size:12px;font-family:Arial;}"
|
||||
"QRadioButton::indicator {width:11px;height:11px;}"
|
||||
"QRadioButton::indicator::unchecked {image : url(:/images/comic_vine/radioUnchecked.png);}"
|
||||
"QRadioButton::indicator::checked {image : url(:/images/comic_vine/radioChecked.png);}";
|
||||
yes->setStyleSheet(rbStyle);
|
||||
no->setStyleSheet(rbStyle);
|
||||
|
||||
yes->setChecked(true);
|
||||
|
||||
l->addSpacing(35);
|
||||
l->addWidget(questionLabel);
|
||||
l->addWidget(yes);
|
||||
l->addWidget(no);
|
||||
l->addStretch();
|
||||
|
||||
l->setContentsMargins(0,0,0,0);
|
||||
w->setLayout(l);
|
||||
w->setContentsMargins(0,0,0,0);
|
||||
content->addWidget(w);
|
||||
}
|
||||
|
||||
void ComicVineDialog::doConnections()
|
||||
{
|
||||
connect(closeButton,SIGNAL(pressed()),this,SLOT(close()));
|
||||
}
|
@ -3,6 +3,9 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class QPushButton;
|
||||
class QStackedWidget;
|
||||
|
||||
class ComicVineDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -12,7 +15,21 @@ public:
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QPushButton * nextButton;
|
||||
QPushButton * closeButton;
|
||||
|
||||
//stacked widgets
|
||||
QStackedWidget * content;
|
||||
|
||||
QWidget * infoNotFound;
|
||||
QWidget * singleComicBrowser;
|
||||
|
||||
void doLayout();
|
||||
void doStackedWidgets();
|
||||
void doSeriesQuestion();
|
||||
void doConnections();
|
||||
};
|
||||
|
||||
#endif // COMIC_VINE_DIALOG_H
|
||||
|
@ -1,65 +1,65 @@
|
||||
<RCC>
|
||||
<qresource prefix="/" >
|
||||
<file>../images/folder.png</file>
|
||||
<file>../images/icon.png</file>
|
||||
<file>../images/iconLibrary.png</file>
|
||||
<file>../images/new.png</file>
|
||||
<file>../images/openLibrary.png</file>
|
||||
<file>../images/removeLibraryIcon.png</file>
|
||||
<file>../images/updateLibraryIcon.png</file>
|
||||
<file>../images/comicFolder.png</file>
|
||||
<file>../images/notCover.png</file>
|
||||
<file>../images/edit.png</file>
|
||||
<file>../images/editIcon.png</file>
|
||||
<file>../images/flow1.png</file>
|
||||
<file>../images/flow2.png</file>
|
||||
<file>../images/flow3.png</file>
|
||||
<file>../images/flow4.png</file>
|
||||
<file>../images/flow5.png</file>
|
||||
<file>../images/importLibrary.png</file>
|
||||
<file>../images/importLibraryIcon.png</file>
|
||||
<file>../images/exportLibrary.png</file>
|
||||
<file>../images/exportLibraryIcon.png</file>
|
||||
<file>../images/open.png</file>
|
||||
<file>../images/coversPackage.png</file>
|
||||
<file>../images/setRead.png</file>
|
||||
<!--<file>../images/setAllRead.png</file>-->
|
||||
<file>../images/setUnread.png</file>
|
||||
<!--<file>../images/setAllUnread.png</file>-->
|
||||
<file>../images/showMarks.png</file>
|
||||
<file>../images/editComic.png</file>
|
||||
<file>../images/selectAll.png</file>
|
||||
<file>../images/hideComicFlow.png</file>
|
||||
<file>../images/exportComicsInfo.png</file>
|
||||
<file>../images/importComicsInfo.png</file>
|
||||
<file>../images/exportComicsInfoIcon.png</file>
|
||||
<file>../images/importComicsInfoIcon.png</file>
|
||||
<file>../images/db.png</file>
|
||||
<file>../images/asignNumber.png</file>
|
||||
<file>../images/defaultCover.png</file>
|
||||
<file>../images/iphoneConfig.png</file>
|
||||
<file>../images/onStartFlowSelection.png</file>
|
||||
<file>../images/onStartFlowSelection_es.png</file>
|
||||
<file>../images/useNewFlowButton.png</file>
|
||||
<file>../images/useOldFlowButton.png</file>
|
||||
<file>../images/serverConfigBackground.png</file>
|
||||
<file>../images/noLibrariesIcon.png</file>
|
||||
<file>../images/noLibrariesLine.png</file>
|
||||
<file>../images/importingIcon.png</file>
|
||||
<file>../images/updatingIcon.png</file>
|
||||
<file>../images/importTopCoversDecoration.png</file>
|
||||
<file>../images/importBottomCoversDecoration.png</file>
|
||||
<file>../images/glowLine.png</file>
|
||||
<file>../images/clearSearch.png</file>
|
||||
<file>../images/iconSearch.png</file>
|
||||
<file>../images/readRibbon.png</file>
|
||||
<file>../images/readingRibbon.png</file>
|
||||
<file>../images/shownCovers.png</file>
|
||||
<file>../images/hiddenCovers.png</file>
|
||||
<file>../images/trash.png</file>
|
||||
<file>../images/setReadButton.png</file>
|
||||
<file>../images/openInYACReader.png</file>
|
||||
<!--<file>../images/deleting_progress/imgTopLeft.png</file>
|
||||
<qresource prefix="/" >
|
||||
<file>../images/folder.png</file>
|
||||
<file>../images/icon.png</file>
|
||||
<file>../images/iconLibrary.png</file>
|
||||
<file>../images/new.png</file>
|
||||
<file>../images/openLibrary.png</file>
|
||||
<file>../images/removeLibraryIcon.png</file>
|
||||
<file>../images/updateLibraryIcon.png</file>
|
||||
<file>../images/comicFolder.png</file>
|
||||
<file>../images/notCover.png</file>
|
||||
<file>../images/edit.png</file>
|
||||
<file>../images/editIcon.png</file>
|
||||
<file>../images/flow1.png</file>
|
||||
<file>../images/flow2.png</file>
|
||||
<file>../images/flow3.png</file>
|
||||
<file>../images/flow4.png</file>
|
||||
<file>../images/flow5.png</file>
|
||||
<file>../images/importLibrary.png</file>
|
||||
<file>../images/importLibraryIcon.png</file>
|
||||
<file>../images/exportLibrary.png</file>
|
||||
<file>../images/exportLibraryIcon.png</file>
|
||||
<file>../images/open.png</file>
|
||||
<file>../images/coversPackage.png</file>
|
||||
<file>../images/setRead.png</file>
|
||||
<!--<file>../images/setAllRead.png</file>-->
|
||||
<file>../images/setUnread.png</file>
|
||||
<!--<file>../images/setAllUnread.png</file>-->
|
||||
<file>../images/showMarks.png</file>
|
||||
<file>../images/editComic.png</file>
|
||||
<file>../images/selectAll.png</file>
|
||||
<file>../images/hideComicFlow.png</file>
|
||||
<file>../images/exportComicsInfo.png</file>
|
||||
<file>../images/importComicsInfo.png</file>
|
||||
<file>../images/exportComicsInfoIcon.png</file>
|
||||
<file>../images/importComicsInfoIcon.png</file>
|
||||
<file>../images/db.png</file>
|
||||
<file>../images/asignNumber.png</file>
|
||||
<file>../images/defaultCover.png</file>
|
||||
<file>../images/iphoneConfig.png</file>
|
||||
<file>../images/onStartFlowSelection.png</file>
|
||||
<file>../images/onStartFlowSelection_es.png</file>
|
||||
<file>../images/useNewFlowButton.png</file>
|
||||
<file>../images/useOldFlowButton.png</file>
|
||||
<file>../images/serverConfigBackground.png</file>
|
||||
<file>../images/noLibrariesIcon.png</file>
|
||||
<file>../images/noLibrariesLine.png</file>
|
||||
<file>../images/importingIcon.png</file>
|
||||
<file>../images/updatingIcon.png</file>
|
||||
<file>../images/importTopCoversDecoration.png</file>
|
||||
<file>../images/importBottomCoversDecoration.png</file>
|
||||
<file>../images/glowLine.png</file>
|
||||
<file>../images/clearSearch.png</file>
|
||||
<file>../images/iconSearch.png</file>
|
||||
<file>../images/readRibbon.png</file>
|
||||
<file>../images/readingRibbon.png</file>
|
||||
<file>../images/shownCovers.png</file>
|
||||
<file>../images/hiddenCovers.png</file>
|
||||
<file>../images/trash.png</file>
|
||||
<file>../images/setReadButton.png</file>
|
||||
<file>../images/openInYACReader.png</file>
|
||||
<!--<file>../images/deleting_progress/imgTopLeft.png</file>
|
||||
<file>../images/deleting_progress/imgTopMiddle.png</file>
|
||||
<file>../images/deleting_progress/imgTopRight.png</file>
|
||||
<file>../images/deleting_progress/imgLeftMiddle.png</file>
|
||||
@ -75,19 +75,21 @@
|
||||
<file>../images/social_dialog/shadow.png</file>
|
||||
<file>../images/social_dialog/twitter.png</file>
|
||||
<file>../images/social_dialog/separator.png</file>-->
|
||||
<file>../images/main_toolbar/divider.png</file>
|
||||
<file>../images/collapsed_branch_osx.png</file>
|
||||
<file>../images/expanded_branch_osx.png</file>
|
||||
<file>../images/folder_macosx.png</file>
|
||||
<file>../images/libraryIconSelected.png</file>
|
||||
<file>../images/libraryOptions.png</file>
|
||||
<file>../images/branch-open.png</file>
|
||||
<file>../images/branch-closed.png</file>
|
||||
<file>../images/expanded_branch_selected.png</file>
|
||||
<file>../images/collapsed_branch_selected.png</file>
|
||||
<file>../images/previousCoverPage.png</file>
|
||||
<file>../images/nextCoverPage.png</file>
|
||||
<file>../images/getInfo.png</file>
|
||||
<!--<file>../images/busy_background.png</file>-->
|
||||
</qresource>
|
||||
<file>../images/main_toolbar/divider.png</file>
|
||||
<file>../images/collapsed_branch_osx.png</file>
|
||||
<file>../images/expanded_branch_osx.png</file>
|
||||
<file>../images/folder_macosx.png</file>
|
||||
<file>../images/libraryIconSelected.png</file>
|
||||
<file>../images/libraryOptions.png</file>
|
||||
<file>../images/branch-open.png</file>
|
||||
<file>../images/branch-closed.png</file>
|
||||
<file>../images/expanded_branch_selected.png</file>
|
||||
<file>../images/collapsed_branch_selected.png</file>
|
||||
<file>../images/previousCoverPage.png</file>
|
||||
<file>../images/nextCoverPage.png</file>
|
||||
<file>../images/getInfo.png</file>
|
||||
<file>../images/comic_vine/radioChecked.png</file>
|
||||
<file>../images/comic_vine/radioUnchecked.png</file>
|
||||
<!--<file>../images/busy_background.png</file>-->
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -13,80 +13,15 @@
|
||||
#define PREVIOUS_VERSION "6.0.0"
|
||||
|
||||
HttpVersionChecker::HttpVersionChecker()
|
||||
:QThread()
|
||||
:HttpWorker("https://bitbucket.org/luisangelsm/yacreader/wiki/Home")
|
||||
{
|
||||
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 &)));
|
||||
connect(this,SIGNAL(dataReady(const QByteArray &)),this,SLOT(checkNewVersion(const QByteArray &)));
|
||||
}
|
||||
|
||||
void HttpVersionChecker::get()
|
||||
void HttpVersionChecker::checkNewVersion(const QByteArray & data)
|
||||
{
|
||||
this->start();
|
||||
|
||||
checkNewVersion(QString(data));
|
||||
}
|
||||
|
||||
void HttpVersionChecker::run()
|
||||
{
|
||||
QNetworkAccessManager manager;
|
||||
QEventLoop q;
|
||||
QTimer tT;
|
||||
|
||||
tT.setSingleShot(true);
|
||||
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
|
||||
connect(&manager, SIGNAL(finished(QNetworkReply*)),&q, SLOT(quit()));
|
||||
QNetworkReply *reply = manager.get(QNetworkRequest(
|
||||
QUrl("https://bitbucket.org/luisangelsm/yacreader/wiki/Home")));
|
||||
|
||||
tT.start(5000); // 5s timeout
|
||||
q.exec();
|
||||
|
||||
if(tT.isActive()){
|
||||
// download complete
|
||||
checkNewVersion(reply->readAll());
|
||||
tT.stop();
|
||||
} else {
|
||||
// timeout
|
||||
}
|
||||
|
||||
/*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);
|
||||
exec();*/
|
||||
}
|
||||
void HttpVersionChecker::readResponseHeader(const QHttpResponseHeader &responseHeader)
|
||||
{
|
||||
Q_UNUSED(responseHeader)
|
||||
}
|
||||
|
||||
void HttpVersionChecker::read(const QHttpResponseHeader &){
|
||||
content.append(http->readAll());
|
||||
}
|
||||
|
||||
void HttpVersionChecker::httpRequestFinished(int requestId, bool error)
|
||||
{
|
||||
Q_UNUSED(requestId)
|
||||
#ifdef QT_DEBUG
|
||||
QString response("YACReader-5.0.0 win32.exe");
|
||||
#else
|
||||
QString response(content);
|
||||
#endif
|
||||
if(!error)
|
||||
checkNewVersion(response);
|
||||
exit();
|
||||
}
|
||||
|
||||
//TODO escribir prueba unitaria
|
||||
bool HttpVersionChecker::checkNewVersion(QString sourceContent)
|
||||
{
|
||||
|
@ -1,31 +1,27 @@
|
||||
#ifndef __CHECKUPDATE_H
|
||||
#define __CHECKUPDATE_H
|
||||
|
||||
#include "http_worker.h"
|
||||
#include "yacreader_global.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QHttp>
|
||||
#include <QHttpResponseHeader>
|
||||
#include <QByteArray>
|
||||
#include <QThread>
|
||||
#include "yacreader_global.h"
|
||||
|
||||
class HttpVersionChecker : public QThread
|
||||
class HttpVersionChecker : public HttpWorker
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HttpVersionChecker();
|
||||
bool thereIsNewVersion();
|
||||
public slots:
|
||||
void httpRequestFinished(int requestId, bool error);
|
||||
void readResponseHeader(const QHttpResponseHeader &);
|
||||
void read(const QHttpResponseHeader &);
|
||||
void get();
|
||||
|
||||
private:
|
||||
void run();
|
||||
QHttp *http;
|
||||
int httpGetId;
|
||||
QByteArray content;
|
||||
bool found;
|
||||
private slots:
|
||||
bool checkNewVersion(QString sourceContent);
|
||||
void checkNewVersion(const QByteArray & data);
|
||||
signals:
|
||||
void newVersionDetected();
|
||||
};
|
||||
|
47
common/http_worker.cpp
Normal file
47
common/http_worker.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include "http_worker.h"
|
||||
#include <QMessageBox>
|
||||
#include <QUrl>
|
||||
#include <QtGlobal>
|
||||
#include <QStringList>
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QEventLoop>
|
||||
#include <QTimer>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#define PREVIOUS_VERSION "6.0.0"
|
||||
|
||||
HttpWorker::HttpWorker(const QString & urlString)
|
||||
:QThread(),url(urlString)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void HttpWorker::get()
|
||||
{
|
||||
this->start();
|
||||
}
|
||||
|
||||
void HttpWorker::run()
|
||||
{
|
||||
QNetworkAccessManager manager;
|
||||
QEventLoop q;
|
||||
QTimer tT;
|
||||
|
||||
tT.setSingleShot(true);
|
||||
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
|
||||
connect(&manager, SIGNAL(finished(QNetworkReply*)),&q, SLOT(quit()));
|
||||
QNetworkReply *reply = manager.get(QNetworkRequest(url));
|
||||
|
||||
tT.start(5000); // 5s timeout
|
||||
q.exec();
|
||||
|
||||
if(tT.isActive()){
|
||||
// download complete
|
||||
emit dataReady(reply->readAll());
|
||||
tT.stop();
|
||||
} else {
|
||||
emit timeout();
|
||||
}
|
||||
}
|
29
common/http_worker.h
Normal file
29
common/http_worker.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef __HTTP_WORKER_H
|
||||
#define __HTTP_WORKER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QHttp>
|
||||
#include <QHttpResponseHeader>
|
||||
#include <QByteArray>
|
||||
#include <QThread>
|
||||
#include <QUrl>
|
||||
#include "yacreader_global.h"
|
||||
|
||||
class HttpWorker : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HttpWorker(const QString & urlString);
|
||||
public slots:
|
||||
void get();
|
||||
private:
|
||||
void run();
|
||||
QUrl url;
|
||||
int httpGetId;
|
||||
QByteArray content;
|
||||
signals:
|
||||
void dataReady(const QByteArray &);
|
||||
void timeout();
|
||||
};
|
||||
|
||||
#endif
|
BIN
images/comic_vine/radioChecked.png
Normal file
BIN
images/comic_vine/radioChecked.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 236 B |
BIN
images/comic_vine/radioUnchecked.png
Normal file
BIN
images/comic_vine/radioUnchecked.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 189 B |
Loading…
x
Reference in New Issue
Block a user