wadseekerinterface.h
1 //------------------------------------------------------------------------------
2 // wadseekerinterface.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; 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 "serverapi/serverptr.h"
27 #include "wadseeker/wadseeker.h"
28 #include "dptr.h"
29 #include <QDialog>
30 #include <QStringList>
31 #include <QTimer>
32 
33 class QModelIndex;
34 
41 class WadseekerInterface : public QDialog
42 {
43  Q_OBJECT
44 
45  public:
46  static bool isInstantiated();
47 
48  static WadseekerInterface *create(QWidget* parent = NULL);
49  static WadseekerInterface *create(ServerPtr server, QWidget* parent = NULL);
51 
52  bool isAutomatic() { return bAutomatic; }
53 
54  void setCustomSite(const QString& site)
55  {
56  this->customSite = site;
57  }
58 
67  void setWads(const QStringList& wads);
68 
69  Wadseeker& wadseekerRef() { return wadseeker; }
70 
71  private:
72  enum States
73  {
74  Downloading = 0,
75  Waiting = 1
76  };
77 
79 
80  static const int UPDATE_INTERVAL_MS;
81  static WadseekerInterface *currentInstance;
82 
83  bool bAutomatic;
84  bool bFirstShown;
85 
86  // Setup for customization in the future.
87  QString colorHtmlMessageFatalError;
88  QString colorHtmlMessageError;
89  QString colorHtmlMessageNotice;
90 
91  QString customSite;
92 
96  QStringList seekedWads;
97 
98  States state;
99 
104  QStringList successfulWads;
105 
106  QTimer updateTimer;
107  Wadseeker wadseeker;
108 
109  WadseekerInterface(QWidget* parent = NULL);
110  WadseekerInterface(ServerPtr server, QWidget* parent = NULL);
111 
112  void connectWadseekerObject();
113  void construct();
114  void displayMessage(const QString& message, WadseekerLib::MessageType type, bool bPrependErrorsWithMessageType);
115  void initMessageColors();
116 
120  void resetTitleToDefault();
121 
122  void setStateDownloading();
123  void setStateWaiting();
124  void setupIdgames();
125  void showEvent(QShowEvent* event);
126  void startSeeking(const QStringList& seekedFilesList);
127  void updateProgressBar();
128  void updateTitle();
129 
134  QStringList unsuccessfulWads() const;
135 
136  private slots:
137  void accept();
138  void allDone(bool bSuccess);
139  void fileDownloadSuccessful(const QString& filename);
140  void reject();
141  void message(const QString& message, WadseekerLib::MessageType type);
142  void registerUpdateRequest();
143  void seekStarted(const QStringList& filenames);
144  void siteFinished(const QUrl& site);
145  void siteProgress(const QUrl& site, qint64 bytes, qint64 total);
146  void siteRedirect(const QUrl& oldUrl, const QUrl& newUrl);
147  void siteStarted(const QUrl& site);
148  void wadsTableRightClicked(const QModelIndex& index, const QPoint& cursorPosition);
149 };
150 
151 #endif
void setWads(const QStringList &wads)
Sets WADs to seek.
Wadseeker dialog box, only one instance is allowed.