1 #ifndef COMIC_VINE_DIALOG_H
2 #define COMIC_VINE_DIALOG_H
3 
4 #include <QDialog>
5 
6 #include "comic_db.h"
7 
8 class QPushButton;
9 class QStackedWidget;
10 class QLabel;
11 class QRadioButton;
12 class ComicVineClient;
13 class QTableView;
14 class TitleHeader;
15 class SeriesQuestion;
16 class SearchSingleComic;
17 class SearchVolume;
18 class SelectComic;
19 class SelectVolume;
20 class SortVolumeComics;
21 
22 //TODO this should use a QStateMachine
23 //----------------------------------------
24 class ComicVineDialog : public QDialog
25 {
26     Q_OBJECT
27 public:
28     explicit ComicVineDialog(QWidget *parent = nullptr);
29     QString databasePath;
30     QString basePath;
31     void setComics(const QList<ComicDB> &comics);
32     QSize sizeHint() const override;
33     QSize minimumSizeHint() const override;
34 
35 signals:
36 
37 public slots:
38     void show();
39 
40 protected slots:
41     void goNext();
42     void goBack();
43     void debugClientResults(const QString &string);
44     //show widget methods
45     void showSeriesQuestion();
46     void showSearchSingleComic();
47     void showSearchVolume();
48     void showLoading(const QString &message = "");
49     void search();
50     void searchVolume(const QString &v, int page = 1);
51     void getVolumeComicsInfo(const QString &vID, int page = 1);
52     void launchSearchVolume();
53     void launchSearchComic();
54     void showSelectVolume(const QString &json);
55     void showSelectVolume();
56     void showSelectComic(const QString &json);
57     void showSortVolumeComics(const QString &json);
58     void queryTimeOut();
59     void getComicsInfo(QList<QPair<ComicDB, QString>> &matchingInfo, int count, const QString &publisher);
60     void getComicInfo(const QString &comicId, int count, const QString &publisher);
61     ComicDB parseComicInfo(ComicDB &comic, const QString &json, int count, const QString &publisher);
62     void setLoadingMessage(const QString &message);
63     void goToNextComic();
64 
65 private:
66     QString getCharacters(const QVariant &json_characters);
67     QMap<QString, QString> getAuthors(const QVariant &json_authors);
68     QPair<QString, QString> getFirstStoryArcIdAndName(const QVariant &json_story_arcs);
69     QPair<QString, QString> getArcNumberAndArcCount(const QString &storyArcId, const QString &comicId);
70 
71     void toggleSkipButton();
72 
73     enum ScraperMode {
74         SingleComic, //the scraper has been opened for a single comic
75         Volume, //the scraper is trying to get comics info for a whole volume
76         SingleComicInList //the scraper has been opened for a list of unrelated comics
77     };
78 
79     enum ScraperStatus {
80         AutoSearching,
81         AskingForInfo,
82         SelectingComic,
83         SelectingSeries,
84         SearchingSingleComic,
85         SearchingVolume,
86         SortingComics,
87         GettingVolumeComics
88     };
89 
90     ScraperMode mode;
91     ScraperStatus status;
92 
93     int currentIndex;
94 
95     TitleHeader *titleHeader;
96 
97     QPushButton *skipButton;
98     QPushButton *backButton;
99     QPushButton *nextButton;
100     QPushButton *searchButton;
101     QPushButton *closeButton;
102 
103     //stacked widgets
104     QStackedWidget *content;
105 
106     QWidget *infoNotFound;
107     QWidget *singleComicBrowser;
108 
109     QLabel *loadingMessage;
110 
111     void doLayout();
112     void doStackedWidgets();
113     void doLoading();
114     void doConnections();
115 
116     QList<ComicDB> comics;
117 
118     SeriesQuestion *seriesQuestionWidget;
119     SearchSingleComic *searchSingleComicWidget;
120     SearchVolume *searchVolumeWidget;
121     SelectVolume *selectVolumeWidget;
122     SelectComic *selectComicWidget;
123     SortVolumeComics *sortVolumeComicsWidget;
124 
125     QString currentVolumeSearchString;
126     QString currentVolumeId;
127 };
128 
129 #endif // COMIC_VINE_DIALOG_H
130