wadseekerinterface.h
1 //------------------------------------------------------------------------------
2 // wadseekerinterface.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2009 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __WADSEEKERINTERFACE_H_
24 #define __WADSEEKERINTERFACE_H_
25 
26 #include "dptr.h"
27 #include "serverapi/serverptr.h"
28 #include "wadseeker/wadseeker.h"
29 #include <QDialog>
30 #include <QStringList>
31 #include <QTimer>
32 
33 class QModelIndex;
34 class PWad;
35 class ModSet;
36 class ModFile;
37 
44 class WadseekerInterface : public QDialog
45 {
46  Q_OBJECT
47 
48 public:
49  static bool isInstantiated();
50 
51  static WadseekerInterface *create(QWidget *parent = nullptr);
52  static WadseekerInterface *create(ServerPtr server, QWidget *parent = nullptr);
53  static WadseekerInterface *createAutoNoGame(QWidget *parent = nullptr);
54  ~WadseekerInterface() override;
55 
56  bool isAutomatic()
57  {
58  return bAutomatic;
59  }
60 
61  void setCustomSites(const QStringList &sites)
62  {
63  this->customSites = sites;
64  }
65 
74  void setWads(const QList<PWad> &wads);
75 
76  Wadseeker &wadseekerRef()
77  {
78  return wadseeker;
79  }
80 
81 private:
82  enum States
83  {
84  Downloading = 0,
85  Waiting = 1
86  };
87 
89 
90  static const int UPDATE_INTERVAL_MS;
91  static WadseekerInterface *currentInstance;
92 
93  bool bAutomatic;
94  bool bFirstShown;
95 
96  // Setup for customization in the future.
97  QString colorHtmlMessageFatalError;
98  QString colorHtmlMessageError;
99  QString colorHtmlMessageNotice;
100 
101  QStringList customSites;
102 
106  QList<PWad> seekedWads;
107 
108  States state;
109 
114  QList<PWad> successfulWads;
115 
116  QTimer updateTimer;
117  Wadseeker wadseeker;
118 
119  WadseekerInterface(QWidget *parent = nullptr);
120  WadseekerInterface(ServerPtr server, QWidget *parent = nullptr);
121 
122  void connectWadseekerObject();
123  void construct();
124  void displayMessage(const QString &message, WadseekerLib::MessageType type, bool bPrependErrorsWithMessageType);
125  void initMessageColors();
126 
130  void resetTitleToDefault();
131 
132  void setStateDownloading();
133  void setStateWaiting();
134  void setupAutomatic();
135  void setupIdgames();
136  void showEvent(QShowEvent *event) override;
137  void startSeeking(const QList<PWad> &seekedFilesList);
138  void updateProgressBar();
139  void updateTitle();
140 
145  QList<PWad> unsuccessfulWads() const;
146 
147 private slots:
148  void abortService(const QString &service);
149  void abortSite(const QUrl &url);
150  void accept() override;
151  void allDone(bool bSuccess);
152  void fileDownloadSuccessful(const ModFile &filename);
153  void reject() override;
154  void message(const QString &message, WadseekerLib::MessageType type);
155  void registerUpdateRequest();
156  void seekStarted(const ModSet &filenames);
157  void serviceStarted(const QString &service);
158  void serviceFinished(const QString &service);
159  void siteFinished(const QUrl &site);
160  void siteProgress(const QUrl &site, qint64 bytes, qint64 total);
161  void siteRedirect(const QUrl &oldUrl, const QUrl &newUrl);
162  void siteStarted(const QUrl &site);
163  void wadsTableRightClicked(const QModelIndex &index, const QPoint &cursorPosition);
164 };
165 
166 #endif