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  QString colorHtmlMessageNavigation;
101 
102  QStringList customSites;
103 
107  QList<PWad> seekedWads;
108 
109  States state;
110 
115  QList<PWad> successfulWads;
116 
117  QTimer updateTimer;
118  Wadseeker wadseeker;
119 
120  WadseekerInterface(QWidget *parent = nullptr);
121  WadseekerInterface(ServerPtr server, QWidget *parent = nullptr);
122 
123  void appendLog(const QString &message, WadseekerLib::MessageType type, const QString &source);
124  void connectWadseekerObject();
125  void construct();
126  void initMessageColors();
127 
131  void resetTitleToDefault();
132 
133  void setStateDownloading();
134  void setStateWaiting();
135  void setupAutomatic();
136  void setupIdgames();
137  void showEvent(QShowEvent *event) override;
138  void startSeeking(const QList<PWad> &seekedFilesList);
139  void updateProgressBar();
140  void updateTitle();
141 
146  QList<PWad> unsuccessfulWads() const;
147 
148 private slots:
149  void abortService(const QString &service);
150  void abortSite(const QUrl &url);
151  void accept() override;
152  void allDone(bool bSuccess);
153  void fileDownloadSuccessful(const ModFile &filename);
154  void reject() override;
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 showWadsTableContextMenu(const QPoint &position);
164 };
165 
166 #endif