wadseeker.h
1 //------------------------------------------------------------------------------
2 // wadseeker.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 __WADSEEKER_H_
24 #define __WADSEEKER_H_
25 
26 #include <QList>
27 #include <QString>
28 #include <QStringList>
29 #include <QUrl>
30 
31 #include "entities/waddownloadinfo.h"
32 #include "wadseekerexportinfo.h"
33 #include "wadseekermessagetype.h"
34 
35 #define WADSEEKER_CONNECT_TIMEOUT_SECONDS_DEFAULT 30
36 #define WADSEEKER_DOWNLOAD_TIMEOUT_SECONDS_DEFAULT 120
37 
38 class Idgames;
39 class WadArchiveClient;
40 class WadRetriever;
41 class WWWSeeker;
42 
83 class WADSEEKER_API Wadseeker : public QObject
84 {
85  Q_OBJECT
86 
87  public:
93  static const QString defaultSites[];
94 
102  static const QString forbiddenWads[];
103 
107  static const QString defaultIdgamesUrl();
108 
114  static QStringList defaultSitesListEncoded();
115 
119  static QStringList filterAllowedOnlyWads(const QStringList &wads);
123  static QStringList filterForbiddenOnlyWads(const QStringList &wads);
124 
134  static bool isForbiddenWad(const QString& wad);
135 
139  Wadseeker();
140 
144  ~Wadseeker();
145 
152  bool isDownloadingFile(const QString& file) const;
153 
163  bool isWorking() const;
164 
175  void setCustomSite(const QUrl& url);
176 
183  void setIdgamesEnabled(bool bEnabled);
184 
188  void setIdgamesUrl(QString archiveURL);
189 
198  void setMaximumConcurrentDownloads(unsigned max);
199 
208  void setMaximumConcurrentSeeks(unsigned max);
209 
220  void setPrimarySites(const QStringList& urlList);
221 
228  void setPrimarySitesToDefault();
229 
239  void setTargetDirectory(const QString& dir);
240 
245  void setWadArchiveEnabled(bool enabled);
246 
259  void skipFileCurrentUrl(const QString& fileName);
260 
272  void skipSiteSeek(const QUrl& url);
273 
283  bool startSeek(const QStringList& wads);
284 
291  QString targetDirectory() const;
292 
293  public slots:
298  void abort();
299 
300  signals:
309  void allDone(bool bSuccess);
310 
323  void fileDownloadFinished(const QString& filename);
324 
340  void fileDownloadProgress(const QString& filename, qint64 done, qint64 total);
341 
350  void fileDownloadStarted(const QString& filename, const QUrl& url);
351 
360  void fileInstalled(const QString& filename);
361 
369  void message(const QString& msg, WadseekerLib::MessageType type);
370 
379  void seekStarted(const QStringList& filenames);
380 
384  void siteFinished(const QUrl& site);
385 
389  void siteProgress(const QUrl& site, qint64 bytes, qint64 total);
390 
394  void siteRedirect(const QUrl& oldUrl, const QUrl& newUrl);
395 
399  void siteStarted(const QUrl& site);
400 
401  private:
402  class SeekParameters
403  {
404  public:
405  bool bIdgamesEnabled;
406  bool bWadArchiveEnabled;
407  QUrl customSiteUrl;
408  QString idgamesUrl;
409  unsigned maxConcurrentDownloads;
410  unsigned maxConcurrentSeeks;
411  QString saveDirectoryPath;
412  QStringList seekedWads;
413  QStringList sitesUrls;
414 
415  SeekParameters();
416  };
417 
418  class PrivData
419  {
420  public:
421  bool bIsAborting;
422 
435  QList<Idgames* > idgamesClients;
436 
437  SeekParameters seekParameters;
438 
444  SeekParameters* seekParametersForCurrentSeek;
445 
446  WadArchiveClient* wadArchiveClient;
447  WadRetriever* wadRetriever;
448  WWWSeeker* wwwSeeker;
449  };
450 
451  PrivData d;
452 
453  void cleanUpAfterFinish();
454  bool isAllFinished() const;
455 
459  void prepareSeekObjects();
460 
461  void setupIdgamesClients(const QList<WadDownloadInfo>& wadDownloadInfoList);
462  void setupSitesUrls();
463  void setupWadArchiveClient(const QList<WadDownloadInfo> &wadDownloadInfos);
464 
465  void startNextIdgamesClient();
466  void startWadArchiveClient();
467 
468  private slots:
469  void cleanUpIfAllFinished();
470  void fileLinkFound(const QString& filename, const QUrl& url);
471  void fileMirrorLinksFound(const QString& filename, const QList<QUrl>& urls);
472  void idgamesClientFinished(Idgames* pEmitter);
473  void reportBadUrl(const QUrl &url);
474  void wadRetrieverDownloadFinished(WadDownloadInfo wadDownloadInfo);
475  void wadRetrieverDownloadProgress(WadDownloadInfo wadDownloadInfo, qint64 current, qint64 total);
476  void wadRetrieverDownloadStarted(WadDownloadInfo wadDownloadInfo, const QUrl& url);
477  void wadRetrieverFinished();
478  void wadRetrieverMessage(const QString& message, WadseekerLib::MessageType type);
479  void wadRetrieverWadInstalled(WadDownloadInfo wadDownloadInfo);
480  void wwwSeekerFinished();
481 };
482 
483 #endif
484 
Main controlling class.
Definition: wadseeker.h:83