mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 13:04:28 -04:00
Added comic vine API key input dialog, YACReader's api key will not longer be used. The user will be responsible for getting his/her own API key.
This commit is contained in:
67
YACReaderLibrary/comic_vine/api_key_dialog.cpp
Normal file
67
YACReaderLibrary/comic_vine/api_key_dialog.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include "api_key_dialog.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
|
||||
#include "yacreader_global.h"
|
||||
|
||||
ApiKeyDialog::ApiKeyDialog(QWidget *parent) :
|
||||
QDialog(parent)
|
||||
{
|
||||
QVBoxLayout * layout = new QVBoxLayout;
|
||||
QHBoxLayout * buttonsLayout = new QHBoxLayout;
|
||||
|
||||
settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor
|
||||
settings->beginGroup("ComicVine");
|
||||
|
||||
QLabel * info = new QLabel(tr("Before you can connect to Comic Vine, you need your own API key. Please, get one free <a href=\"http://www.comicvine.com/api/\">here</a>"));
|
||||
info->setWordWrap(true);
|
||||
edit = new QLineEdit();
|
||||
edit->setPlaceholderText(tr("Paste here your Comic Vine API key"));
|
||||
connect(edit,SIGNAL(textChanged(QString)),this,SLOT(enableAccept(QString)));
|
||||
|
||||
acceptButton = new QPushButton(tr("Accept"));
|
||||
acceptButton->setDisabled(true);
|
||||
connect(acceptButton,SIGNAL(clicked()),this,SLOT(saveApiKey()));
|
||||
|
||||
cancelButton = new QPushButton(tr("Cancel"));
|
||||
connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
|
||||
|
||||
layout->addWidget(info);
|
||||
layout->addWidget(edit);
|
||||
layout->addStretch();
|
||||
|
||||
buttonsLayout->addStretch();
|
||||
buttonsLayout->addWidget(acceptButton);
|
||||
buttonsLayout->addWidget(cancelButton);
|
||||
|
||||
layout->addLayout(buttonsLayout);
|
||||
|
||||
setLayout(layout);
|
||||
|
||||
resize(400,150);
|
||||
|
||||
if(settings->contains(COMIC_VINE_API_KEY))
|
||||
edit->setText(settings->value(COMIC_VINE_API_KEY).toString());
|
||||
}
|
||||
|
||||
ApiKeyDialog::~ApiKeyDialog()
|
||||
{
|
||||
delete settings;
|
||||
}
|
||||
|
||||
void ApiKeyDialog::enableAccept(const QString &text)
|
||||
{
|
||||
//TODO key validation
|
||||
acceptButton->setEnabled(!text.isEmpty());
|
||||
}
|
||||
|
||||
void ApiKeyDialog::saveApiKey()
|
||||
{
|
||||
settings->setValue(COMIC_VINE_API_KEY,edit->text());
|
||||
accept();
|
||||
}
|
31
YACReaderLibrary/comic_vine/api_key_dialog.h
Normal file
31
YACReaderLibrary/comic_vine/api_key_dialog.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef API_KEY_DIALOG_H
|
||||
#define API_KEY_DIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class QPushButton;
|
||||
class QLineEdit;
|
||||
class QSettings;
|
||||
|
||||
class ApiKeyDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ApiKeyDialog(QWidget *parent = 0);
|
||||
~ApiKeyDialog();
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
protected slots:
|
||||
void enableAccept(const QString & text);
|
||||
void saveApiKey();
|
||||
|
||||
protected:
|
||||
QPushButton * acceptButton;
|
||||
QPushButton * cancelButton;
|
||||
QLineEdit * edit;
|
||||
QSettings * settings;
|
||||
};
|
||||
|
||||
#endif // API_KEY_DIALOG_H
|
@ -19,7 +19,8 @@ HEADERS += \
|
||||
comic_vine/model/volume_comics_model.h \
|
||||
comic_vine/scraper_scroll_label.h \
|
||||
comic_vine/scraper_results_paginator.h \
|
||||
comic_vine/scraper_selector.h
|
||||
comic_vine/scraper_selector.h \
|
||||
comic_vine/api_key_dialog.h
|
||||
|
||||
SOURCES += \
|
||||
comic_vine/comic_vine_dialog.cpp \
|
||||
@ -41,4 +42,5 @@ SOURCES += \
|
||||
comic_vine/model/volume_comics_model.cpp \
|
||||
comic_vine/scraper_scroll_label.cpp \
|
||||
comic_vine/scraper_results_paginator.cpp \
|
||||
comic_vine/scraper_selector.cpp
|
||||
comic_vine/scraper_selector.cpp \
|
||||
comic_vine/api_key_dialog.cpp
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
//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_API_KEY = "%CV_API_KEY%"; //get from settings
|
||||
static const QString CV_API_KEY_DEFAULT = "46680bebb358f1de690a5a365e15d325f9649f91";
|
||||
|
||||
static const QString CV_WEB_ADDRESS = "http://www.comicvine.com/api";
|
||||
|
||||
@ -43,13 +44,19 @@ static const QString CV_COVER_URL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key="
|
||||
ComicVineClient::ComicVineClient(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor
|
||||
settings->beginGroup("ComicVine");
|
||||
}
|
||||
|
||||
ComicVineClient::~ComicVineClient()
|
||||
{
|
||||
delete settings;
|
||||
}
|
||||
|
||||
//CV_SEARCH
|
||||
void ComicVineClient::search(const QString & query, int page)
|
||||
{
|
||||
HttpWorker * search = new HttpWorker(CV_SEARCH.arg(query).arg(page));
|
||||
HttpWorker * search = new HttpWorker(QString(CV_SEARCH).replace(CV_API_KEY,settings->value(COMIC_VINE_API_KEY,CV_API_KEY_DEFAULT).toString()).arg(query).arg(page));
|
||||
connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessVolumesSearchData(const QByteArray &)));
|
||||
connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut()));
|
||||
connect(search,SIGNAL(finished()),search,SLOT(deleteLater()));
|
||||
@ -87,7 +94,7 @@ void ComicVineClient::proccessComicDetailData(const QByteArray &data)
|
||||
//CV_SERIES_DETAIL
|
||||
void ComicVineClient::getSeriesDetail(const QString & id)
|
||||
{
|
||||
HttpWorker * search = new HttpWorker(CV_SERIES_DETAIL.arg(id));
|
||||
HttpWorker * search = new HttpWorker(QString(CV_SERIES_DETAIL).replace(CV_API_KEY,settings->value(COMIC_VINE_API_KEY,CV_API_KEY_DEFAULT).toString()).arg(id));
|
||||
connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessSeriesDetailData(const QByteArray &)));
|
||||
connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut()));
|
||||
connect(search,SIGNAL(finished()),search,SLOT(deleteLater()));
|
||||
@ -106,7 +113,7 @@ void ComicVineClient::getSeriesCover(const QString & url)
|
||||
//CV_COMIC_IDS
|
||||
void ComicVineClient::getVolumeComicsInfo(const QString & idVolume, int page)
|
||||
{
|
||||
HttpWorker * search = new HttpWorker(CV_COMICS_INFO.arg(idVolume).arg((page-1)*100)); //page on works for search, using offset instead
|
||||
HttpWorker * search = new HttpWorker(QString(CV_COMICS_INFO).replace(CV_API_KEY,settings->value(COMIC_VINE_API_KEY,CV_API_KEY_DEFAULT).toString()).arg(idVolume).arg((page-1)*100)); //page on works for search, using offset instead
|
||||
connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(processVolumeComicsInfo(const QByteArray &)));
|
||||
connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut())); //TODO
|
||||
connect(search,SIGNAL(finished()),search,SLOT(deleteLater()));
|
||||
@ -122,7 +129,7 @@ void ComicVineClient::getComicId(const QString & id, int comicNumber)
|
||||
//CV_COMIC_DETAIL
|
||||
QByteArray ComicVineClient::getComicDetail(const QString & id, bool & outError, bool & outTimeout)
|
||||
{
|
||||
HttpWorker * search = new HttpWorker(CV_COMIC_DETAIL.arg(id));
|
||||
HttpWorker * search = new HttpWorker(QString(CV_COMIC_DETAIL).replace(CV_API_KEY,settings->value(COMIC_VINE_API_KEY,CV_API_KEY_DEFAULT).toString()).arg(id));
|
||||
|
||||
//connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessComicDetailData(const QByteArray &)));
|
||||
//connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut()));
|
||||
@ -140,7 +147,7 @@ QByteArray ComicVineClient::getComicDetail(const QString & id, bool & outError,
|
||||
//CV_COMIC_DETAIL
|
||||
void ComicVineClient::getComicDetailAsync(const QString & id)
|
||||
{
|
||||
HttpWorker * search = new HttpWorker(CV_COMIC_DETAIL.arg(id));
|
||||
HttpWorker * search = new HttpWorker(QString(CV_COMIC_DETAIL).replace(CV_API_KEY,settings->value(COMIC_VINE_API_KEY,CV_API_KEY_DEFAULT).toString()).arg(id));
|
||||
|
||||
connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessComicDetailData(const QByteArray &)));
|
||||
connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut()));
|
||||
|
@ -4,12 +4,14 @@
|
||||
#include "http_worker.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
|
||||
class ComicVineClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ComicVineClient(QObject *parent = 0);
|
||||
~ComicVineClient();
|
||||
|
||||
signals:
|
||||
void searchResult(QString);
|
||||
@ -37,5 +39,8 @@ protected slots:
|
||||
void processVolumeComicsInfo(const QByteArray & data);
|
||||
void proccessComicDetailData(const QByteArray & data);
|
||||
|
||||
protected:
|
||||
QSettings * settings;
|
||||
|
||||
};
|
||||
#endif // COMIC_VINE_CLIENT_H
|
||||
|
@ -259,7 +259,7 @@ void ComicVineDialog::debugClientResults(const QString & string)
|
||||
//QMessageBox::information(0,"Result", QString("Number of results : %1").arg(p.getNumResults()));
|
||||
if(p.responseError())
|
||||
{
|
||||
QMessageBox::critical(0,tr("Error connecting to ComicVine"), tr("unknown error"));
|
||||
QMessageBox::critical(0,tr("Error connecting to ComicVine"), p.errorDescription());
|
||||
goBack();
|
||||
}
|
||||
else
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <QDebug>
|
||||
|
||||
ResponseParser::ResponseParser(QObject *parent) :
|
||||
QObject(parent),error(false),numResults(-1),currentPage(-1),totalPages(-1)
|
||||
QObject(parent),error(false),numResults(-1),currentPage(-1),totalPages(-1),errorTxt("None")
|
||||
{
|
||||
}
|
||||
|
||||
@ -13,6 +13,11 @@ bool ResponseParser::responseError()
|
||||
return error;
|
||||
}
|
||||
|
||||
QString ResponseParser::errorDescription()
|
||||
{
|
||||
return errorTxt;
|
||||
}
|
||||
|
||||
qint32 ResponseParser::getNumResults()
|
||||
{
|
||||
return numResults;
|
||||
@ -28,16 +33,33 @@ qint32 ResponseParser::getTotalPages()
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
bool ResponseParser::isError(qint32 error)
|
||||
{
|
||||
switch(error)
|
||||
{
|
||||
case 100:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ResponseParser::loadJSONResponse(const QString &response)
|
||||
{
|
||||
QScriptEngine engine;
|
||||
QScriptValue sc;
|
||||
sc = engine.evaluate("(" + response + ")");
|
||||
|
||||
if (!sc.property("error").isValid() && sc.property("error").toString() != "OK")
|
||||
errorTxt = "None";
|
||||
|
||||
if (!sc.property("status_code").isValid() || isError(sc.property("status_code").toInt32()))
|
||||
{
|
||||
error = true;
|
||||
qDebug("Error detected");
|
||||
if(sc.property("error").isValid())
|
||||
errorTxt = sc.property("error").toString();
|
||||
else
|
||||
errorTxt = "Unknown error";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -9,9 +9,11 @@ class ResponseParser : public QObject
|
||||
public:
|
||||
explicit ResponseParser(QObject *parent = 0);
|
||||
bool responseError();
|
||||
QString errorDescription();
|
||||
qint32 getNumResults();
|
||||
qint32 getCurrentPage();
|
||||
qint32 getTotalPages();
|
||||
bool isError(qint32 error);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
@ -19,6 +21,7 @@ public slots:
|
||||
|
||||
protected:
|
||||
bool error;
|
||||
QString errorTxt;
|
||||
qint32 numResults;
|
||||
qint32 currentPage;
|
||||
qint32 totalPages;
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "yacreader_treeview.h"
|
||||
|
||||
#include "comic_vine_dialog.h"
|
||||
#include "api_key_dialog.h"
|
||||
//#include "yacreader_social_dialog.h"
|
||||
|
||||
#include "classic_comics_view.h"
|
||||
@ -1649,6 +1650,18 @@ void LibraryWindow::showProperties()
|
||||
}
|
||||
|
||||
void LibraryWindow::showComicVineScraper()
|
||||
{
|
||||
QSettings s(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor
|
||||
s.beginGroup("ComicVine");
|
||||
|
||||
if(!s.contains(COMIC_VINE_API_KEY))
|
||||
{
|
||||
ApiKeyDialog d;
|
||||
d.exec();
|
||||
}
|
||||
|
||||
//check if the api key was inserted
|
||||
if(s.contains(COMIC_VINE_API_KEY))
|
||||
{
|
||||
QModelIndexList indexList = getSelectedComics();
|
||||
|
||||
@ -1662,6 +1675,7 @@ void LibraryWindow::showComicVineScraper()
|
||||
|
||||
comicVineDialog->show();
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryWindow::setRemoveError()
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "yacreader_flow_gl.h"
|
||||
#include "yacreader_flow_config_widget.h"
|
||||
#include "yacreader_gl_flow_config_widget.h"
|
||||
#include "api_key_dialog.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
@ -42,12 +43,22 @@ OptionsDialog::OptionsDialog(QWidget * parent)
|
||||
|
||||
sw->hide();
|
||||
|
||||
QVBoxLayout * apiKeyLayout = new QVBoxLayout();
|
||||
QPushButton * apiKeyButton = new QPushButton(tr("Edit Comic Vine API key"));
|
||||
apiKeyLayout->addWidget(apiKeyButton);
|
||||
|
||||
QGroupBox * apiKeyBox = new QGroupBox(tr("Comic Vine API key"));
|
||||
apiKeyBox->setLayout(apiKeyLayout);
|
||||
|
||||
connect(apiKeyButton,SIGNAL(clicked()),this,SLOT(editApiKey()));
|
||||
|
||||
QWidget * comicFlowW = new QWidget;
|
||||
comicFlowW->setLayout(flowLayout);
|
||||
|
||||
QWidget * generalW = new QWidget;
|
||||
generalW->setLayout(generalLayout);
|
||||
generalLayout->addWidget(shortcutsBox);
|
||||
generalLayout->addWidget(apiKeyBox);
|
||||
generalLayout->addStretch();
|
||||
|
||||
tabWidget->addTab(comicFlowW,tr("Comic Flow"));
|
||||
@ -65,5 +76,11 @@ OptionsDialog::OptionsDialog(QWidget * parent)
|
||||
|
||||
}
|
||||
|
||||
void OptionsDialog::editApiKey()
|
||||
{
|
||||
ApiKeyDialog d;
|
||||
d.exec();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -12,6 +12,9 @@ class OptionsDialog : public YACReaderOptionsDialog
|
||||
Q_OBJECT
|
||||
public:
|
||||
OptionsDialog(QWidget * parent = 0);
|
||||
|
||||
public slots:
|
||||
void editApiKey();
|
||||
};
|
||||
|
||||
|
||||
|
@ -65,6 +65,8 @@
|
||||
|
||||
#define LIBRARIES "LIBRARIES"
|
||||
|
||||
#define COMIC_VINE_API_KEY "COMIC_VINE_API_KEY"
|
||||
|
||||
namespace YACReader
|
||||
{
|
||||
|
||||
|
Reference in New Issue
Block a user