mirror of
https://github.com/YACReader/yacreader
synced 2025-06-03 00:58:32 -04:00
SelectVolume loads covers from ComicVine
This commit is contained in:
parent
9938167a90
commit
80d0236010
@ -9,9 +9,9 @@ static const QString CV_WEB_ADDRESS = "http://www.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=json&limit=100&resources=volume"
|
||||
"&field_list=name,start_year,publisher,id,image,count_of_issues"
|
||||
"&field_list=name,start_year,publisher,id,image,count_of_issues,deck"
|
||||
"&query=%1&page=%2";
|
||||
//http://www.comicvine.com/api/search/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&format=json&limit=100&resources=volume&field_list=name,start_year,publisher,id,image,count_of_issues&query=superman
|
||||
//http://www.comicvine.com/api/search/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&format=json&limit=100&resources=volume&field_list=name,start_year,publisher,id,image,count_of_issues,deck&query=superman
|
||||
|
||||
//gets the detail for a volume %1
|
||||
static const QString CV_SERIES_DETAIL = CV_WEB_ADDRESS + "/volume/4050-%1/?api_key=" + CV_API_KEY +
|
||||
@ -54,6 +54,7 @@ void ComicVineClient::proccessVolumesSearchData(const QByteArray & data)
|
||||
{
|
||||
QString json(data);
|
||||
emit searchResult(json);
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void ComicVineClient::queryTimeOut()
|
||||
|
@ -13,6 +13,7 @@ public:
|
||||
|
||||
signals:
|
||||
void searchResult(QString);
|
||||
void finished();
|
||||
public slots:
|
||||
void search(const QString & query, int page = 0);
|
||||
void getSeriesDetail(const QString & id);
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
|
||||
ComicVineDialog::ComicVineDialog(QWidget *parent) :
|
||||
QDialog(parent),comicVineClient(new ComicVineClient)
|
||||
QDialog(parent)
|
||||
{
|
||||
doLayout();
|
||||
doStackedWidgets();
|
||||
@ -77,11 +77,11 @@ void ComicVineDialog::doLayout()
|
||||
void ComicVineDialog::doStackedWidgets()
|
||||
{
|
||||
doLoading();
|
||||
content->addWidget(seriesQuestion = new SeriesQuestion);
|
||||
content->addWidget(searchSingleComic = new SearchSingleComic);
|
||||
content->addWidget(searchVolume = new SearchVolume);
|
||||
content->addWidget(selectVolume = new SelectVolume);
|
||||
content->addWidget(selectComic = new SelectComic);
|
||||
content->addWidget(seriesQuestionWidget = new SeriesQuestion);
|
||||
content->addWidget(searchSingleComicWidget = new SearchSingleComic);
|
||||
content->addWidget(searchVolumeWidget = new SearchVolume);
|
||||
content->addWidget(selectVolumeWidget = new SelectVolume);
|
||||
content->addWidget(selectComicWidget = new SelectComic);
|
||||
}
|
||||
|
||||
void ComicVineDialog::doConnections()
|
||||
@ -89,16 +89,14 @@ void ComicVineDialog::doConnections()
|
||||
connect(closeButton,SIGNAL(clicked()),this,SLOT(close()));
|
||||
connect(nextButton,SIGNAL(clicked()),this,SLOT(goNext()));
|
||||
connect(searchButton,SIGNAL(clicked()),this,SLOT(search()));
|
||||
|
||||
connect(comicVineClient,SIGNAL(searchResult(QString)),this,SLOT(debugClientResults(QString)));
|
||||
}
|
||||
|
||||
void ComicVineDialog::goNext()
|
||||
{
|
||||
//
|
||||
if(content->currentWidget() == seriesQuestion)
|
||||
if(content->currentWidget() == seriesQuestionWidget)
|
||||
{
|
||||
if(seriesQuestion->getYes())
|
||||
if(seriesQuestionWidget->getYes())
|
||||
{
|
||||
QString volumeSearchString = comics[0].getParentFolderName();
|
||||
|
||||
@ -107,7 +105,7 @@ void ComicVineDialog::goNext()
|
||||
else
|
||||
{
|
||||
showLoading();
|
||||
comicVineClient->search(volumeSearchString);
|
||||
searchVolume(volumeSearchString);
|
||||
status = AutoSearching;
|
||||
}
|
||||
|
||||
@ -120,12 +118,12 @@ void ComicVineDialog::goNext()
|
||||
titleHeader->setSubTitle(tr("comic %1 of %2 - %3").arg(currentIndex+1).arg(comics.length()).arg(title));
|
||||
showLoading();
|
||||
|
||||
comicVineClient->search(title);
|
||||
searchVolume(title);
|
||||
status = AutoSearching;
|
||||
mode = SingleComicInList;
|
||||
}
|
||||
}
|
||||
else if (content->currentWidget() == searchSingleComic) {
|
||||
else if (content->currentWidget() == searchSingleComicWidget) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -148,7 +146,7 @@ void ComicVineDialog::show()
|
||||
titleHeader->setSubTitle(title);
|
||||
showLoading();
|
||||
|
||||
comicVineClient->search(title);
|
||||
searchVolume(title);
|
||||
status = AutoSearching;
|
||||
mode = SingleComic;
|
||||
}else if(comics.length()>1)
|
||||
@ -205,7 +203,7 @@ void ComicVineDialog::debugClientResults(const QString & string)
|
||||
void ComicVineDialog::showSeriesQuestion()
|
||||
{
|
||||
status = AskingForInfo;
|
||||
content->setCurrentWidget(seriesQuestion);
|
||||
content->setCurrentWidget(seriesQuestionWidget);
|
||||
backButton->setHidden(true);
|
||||
skipButton->setHidden(true);
|
||||
nextButton->setVisible(true);
|
||||
@ -216,7 +214,7 @@ void ComicVineDialog::showSeriesQuestion()
|
||||
void ComicVineDialog::showSearchSingleComic()
|
||||
{
|
||||
status = AskingForInfo;
|
||||
content->setCurrentWidget(searchSingleComic);
|
||||
content->setCurrentWidget(searchSingleComicWidget);
|
||||
backButton->setHidden(true);
|
||||
skipButton->setHidden(true);
|
||||
nextButton->setHidden(true);
|
||||
@ -227,7 +225,7 @@ void ComicVineDialog::showSearchSingleComic()
|
||||
void ComicVineDialog::showSearchVolume()
|
||||
{
|
||||
status = AskingForInfo;
|
||||
content->setCurrentWidget(searchVolume);
|
||||
content->setCurrentWidget(searchVolumeWidget);
|
||||
backButton->setHidden(true);
|
||||
nextButton->setHidden(true);
|
||||
searchButton->setVisible(true);
|
||||
@ -241,14 +239,14 @@ void ComicVineDialog::showSearchVolume()
|
||||
|
||||
void ComicVineDialog::showSelectVolume(const QString & json)
|
||||
{
|
||||
content->setCurrentWidget(selectVolume);
|
||||
selectVolume->load(json);
|
||||
content->setCurrentWidget(selectVolumeWidget);
|
||||
selectVolumeWidget->load(json);
|
||||
}
|
||||
|
||||
void ComicVineDialog::showSelectComic(const QString &json)
|
||||
{
|
||||
content->setCurrentWidget(selectComic);
|
||||
selectComic->load(json);
|
||||
content->setCurrentWidget(selectComicWidget);
|
||||
selectComicWidget->load(json);
|
||||
}
|
||||
|
||||
void ComicVineDialog::showLoading()
|
||||
@ -273,22 +271,30 @@ void ComicVineDialog::search()
|
||||
}
|
||||
}
|
||||
|
||||
void ComicVineDialog::searchVolume(const QString &v)
|
||||
{
|
||||
ComicVineClient * comicVineClient = new ComicVineClient;
|
||||
connect(comicVineClient,SIGNAL(searchResult(QString)),this,SLOT(debugClientResults(QString)));
|
||||
connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater()));
|
||||
comicVineClient->search(v);
|
||||
}
|
||||
|
||||
void ComicVineDialog::launchSearchVolume()
|
||||
{
|
||||
showLoading();
|
||||
//TODO: check if volume info is empty.
|
||||
comicVineClient->search(searchVolume->getVolumeInfo());
|
||||
searchVolume(searchVolumeWidget->getVolumeInfo());
|
||||
}
|
||||
|
||||
void ComicVineDialog::launchSearchComic()
|
||||
{
|
||||
showLoading();
|
||||
|
||||
QString volumeInfo = searchSingleComic->getVolumeInfo();
|
||||
QString comicInfo = searchSingleComic->getComicInfo();
|
||||
int comicNumber = searchSingleComic->getComicNumber();
|
||||
QString volumeInfo = searchSingleComicWidget->getVolumeInfo();
|
||||
QString comicInfo = searchSingleComicWidget->getComicInfo();
|
||||
int comicNumber = searchSingleComicWidget->getComicNumber();
|
||||
|
||||
if(comicInfo.isEmpty() && comicNumber == -1)
|
||||
comicVineClient->search(volumeInfo);
|
||||
searchVolume(volumeInfo);
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ protected slots:
|
||||
void showSearchVolume();
|
||||
void showLoading();
|
||||
void search();
|
||||
void searchVolume(const QString & v);
|
||||
void launchSearchVolume();
|
||||
void launchSearchComic();
|
||||
void showSelectVolume(const QString & json);
|
||||
@ -65,8 +66,6 @@ private:
|
||||
ScrapperMode mode;
|
||||
ScrapperStatus status;
|
||||
|
||||
ComicVineClient * comicVineClient;
|
||||
|
||||
int currentIndex;
|
||||
|
||||
TitleHeader * titleHeader;
|
||||
@ -90,11 +89,11 @@ private:
|
||||
|
||||
QList<ComicDB> comics;
|
||||
|
||||
SeriesQuestion * seriesQuestion;
|
||||
SearchSingleComic * searchSingleComic;
|
||||
SearchVolume * searchVolume;
|
||||
SelectVolume * selectVolume;
|
||||
SelectComic * selectComic;
|
||||
SeriesQuestion * seriesQuestionWidget;
|
||||
SearchSingleComic * searchSingleComicWidget;
|
||||
SearchVolume * searchVolumeWidget;
|
||||
SelectVolume * selectVolumeWidget;
|
||||
SelectComic * selectComicWidget;
|
||||
};
|
||||
|
||||
#endif // COMIC_VINE_DIALOG_H
|
||||
|
@ -28,15 +28,18 @@ void VolumesModel::load(const QString &json)
|
||||
int numResults = sc.property("number_of_total_results").toString().toInt(); //fix to weird behaviour using hasNext
|
||||
QScriptValueIterator it(sc.property("results"));
|
||||
bool test;
|
||||
QScriptValue resultsValue;
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
QString numIssues = it.value().property("count_of_issues").toString();
|
||||
QString year = it.value().property("start_year").toString();
|
||||
QString name = it.value().property("name").toString();
|
||||
QString publisher = it.value().property("publisher").property("name").toString();
|
||||
QString url = it.value().property("image").property("screen_url").toString();
|
||||
resultsValue = it.value();
|
||||
QString numIssues = resultsValue.property("count_of_issues").toString();
|
||||
QString year = resultsValue.property("start_year").toString();
|
||||
QString name = resultsValue.property("name").toString();
|
||||
QString publisher = resultsValue.property("publisher").property("name").toString();
|
||||
QString url = resultsValue.property("image").property("medium_url").toString();
|
||||
QString deck = resultsValue.property("deck").toString();
|
||||
QStringList & l = *(new QStringList);
|
||||
l << name << year << numIssues << publisher << url;
|
||||
l << name << year << numIssues << publisher << url << deck;
|
||||
test = name.isEmpty() && year.isEmpty() && numIssues.isEmpty() && url.isEmpty();
|
||||
if(numResults>0 && !test)
|
||||
_data.push_back(&l);
|
||||
|
@ -21,6 +21,7 @@ public:
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
@ -28,11 +29,14 @@ public slots:
|
||||
private:
|
||||
QList <QList <QString> * > _data;
|
||||
|
||||
public:
|
||||
enum Column {
|
||||
SERIES,
|
||||
SERIES = 0,
|
||||
YEAR,
|
||||
ISSUES,
|
||||
PUBLISHER
|
||||
PUBLISHER,
|
||||
COVER_URL,
|
||||
DECK
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -6,8 +6,10 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QScrollBar>
|
||||
#include <QModelIndex>
|
||||
|
||||
#include "volumes_model.h"
|
||||
#include "http_worker.h"
|
||||
|
||||
SelectVolume::SelectVolume(QWidget *parent)
|
||||
:QWidget(parent),model(0)
|
||||
@ -40,8 +42,11 @@ SelectVolume::SelectVolume(QWidget *parent)
|
||||
|
||||
//widgets
|
||||
cover = new QLabel();
|
||||
cover->setScaledContents(true);
|
||||
cover->setAlignment(Qt::AlignTop|Qt::AlignHCenter);
|
||||
detailLabel = new QLabel();
|
||||
detailLabel->setStyleSheet(labelStylesheet);
|
||||
detailLabel->setWordWrap(true);
|
||||
tableVolumes = new QTableView();
|
||||
tableVolumes->setStyleSheet(tableStylesheet);
|
||||
|
||||
@ -78,17 +83,23 @@ SelectVolume::SelectVolume(QWidget *parent)
|
||||
|
||||
tableVolumes->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
//connections
|
||||
connect(tableVolumes,SIGNAL(clicked(QModelIndex)),this,SLOT(loadVolumeInfo(QModelIndex)));
|
||||
|
||||
left->addWidget(cover);
|
||||
left->addWidget(detailLabel);
|
||||
left->addStretch();
|
||||
leftWidget->setMaximumWidth(168);
|
||||
leftWidget->setMaximumWidth(180);
|
||||
leftWidget->setLayout(left);
|
||||
left->setContentsMargins(0,0,0,0);
|
||||
leftWidget->setContentsMargins(0,0,0,0);
|
||||
|
||||
content->addWidget(leftWidget);
|
||||
content->addWidget(tableVolumes,0,Qt::AlignRight);
|
||||
content->addWidget(tableVolumes,0,Qt::AlignRight|Qt::AlignTop);
|
||||
|
||||
l->addSpacing(15);
|
||||
l->addWidget(label);
|
||||
l->addSpacing(5);
|
||||
l->addLayout(content);
|
||||
l->addStretch();
|
||||
|
||||
@ -99,7 +110,7 @@ SelectVolume::SelectVolume(QWidget *parent)
|
||||
|
||||
void SelectVolume::load(const QString & json)
|
||||
{
|
||||
VolumesModel * tempM = new VolumesModel();;
|
||||
VolumesModel * tempM = new VolumesModel();
|
||||
tempM->load(json);
|
||||
tableVolumes->setModel(tempM);
|
||||
|
||||
@ -107,11 +118,47 @@ void SelectVolume::load(const QString & json)
|
||||
|
||||
tableVolumes->setFixedSize(419,341);
|
||||
|
||||
if(tempM->rowCount()>0)
|
||||
{
|
||||
tableVolumes->selectRow(0);
|
||||
loadVolumeInfo(tempM->index(0,0));
|
||||
}
|
||||
|
||||
if(model != 0)
|
||||
delete model;
|
||||
else
|
||||
model = tempM;
|
||||
}
|
||||
|
||||
|
||||
SelectVolume::~SelectVolume() {}
|
||||
|
||||
void SelectVolume::loadVolumeInfo(const QModelIndex & mi)
|
||||
{
|
||||
QStringList * data = static_cast<QStringList *>(mi.internalPointer());
|
||||
QString coverURL = data->at(VolumesModel::COVER_URL);
|
||||
QString deck = data->at(VolumesModel::DECK);
|
||||
|
||||
//cover->setText(coverURL);
|
||||
detailLabel->setText(deck);
|
||||
|
||||
HttpWorker * search = new HttpWorker(coverURL);
|
||||
connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(setCover(const QByteArray &)));
|
||||
connect(search,SIGNAL(timeout()),this,SLOT(queryTimeOut())); //TODO
|
||||
connect(search,SIGNAL(finished()),search,SLOT(deleteLater()));
|
||||
search->get();
|
||||
}
|
||||
|
||||
void SelectVolume::setCover(const QByteArray & data)
|
||||
{
|
||||
QPixmap p;
|
||||
p.loadFromData(data);
|
||||
int w = p.width();
|
||||
int h = p.height();
|
||||
|
||||
cover->setPixmap(p);
|
||||
float aspectRatio = static_cast<float>(w)/h;
|
||||
|
||||
cover->setFixedSize(180,static_cast<int>(180/aspectRatio));
|
||||
|
||||
cover->update();
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
class QLabel;
|
||||
class QTableView;
|
||||
class VolumesModel;
|
||||
class QModelIndex;
|
||||
|
||||
class SelectVolume : public QWidget
|
||||
{
|
||||
@ -14,6 +15,9 @@ public:
|
||||
SelectVolume(QWidget * parent = 0);
|
||||
void load(const QString & json);
|
||||
virtual ~SelectVolume();
|
||||
public slots:
|
||||
void loadVolumeInfo(const QModelIndex & mi);
|
||||
void setCover(const QByteArray &);
|
||||
private:
|
||||
QLabel * cover;
|
||||
QLabel * detailLabel;
|
||||
|
Loading…
x
Reference in New Issue
Block a user