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 <QObject>
28 #include <QString>
29 #include <QStringList>
30 #include <QUrl>
31 
32 #include "dptr.h"
33 #include "entities/waddownloadinfo.h"
34 #include "wadseekerexportinfo.h"
35 #include "wadseekermessagetype.h"
36 
37 #define WADSEEKER_CONNECT_TIMEOUT_SECONDS_DEFAULT 30
38 #define WADSEEKER_DOWNLOAD_TIMEOUT_SECONDS_DEFAULT 120
39 
40 class Idgames;
41 class WadArchiveClient;
42 class WadRetriever;
43 class WWWSeeker;
44 
85 class WADSEEKER_API Wadseeker : public QObject
86 {
87  Q_OBJECT
88 
89  public:
95  static const QString defaultSites[];
96 
104  static const QString forbiddenWads[];
105 
109  static const QString defaultIdgamesUrl();
110 
116  static QStringList defaultSitesListEncoded();
117 
121  static QStringList filterAllowedOnlyWads(const QStringList &wads);
125  static QStringList filterForbiddenOnlyWads(const QStringList &wads);
126 
136  static bool isForbiddenWad(const QString& wad);
137 
141  Wadseeker();
142 
146  ~Wadseeker();
147 
154  bool isDownloadingFile(const QString& file) const;
155 
165  bool isWorking() const;
166 
177  void setCustomSite(const QString& url);
178 
185  void setIdgamesEnabled(bool bEnabled);
186 
190  void setIdgamesUrl(QString archiveURL);
191 
200  void setMaximumConcurrentDownloads(unsigned max);
201 
210  void setMaximumConcurrentSeeks(unsigned max);
211 
222  void setPrimarySites(const QStringList& urlList);
223 
230  void setPrimarySitesToDefault();
231 
241  void setTargetDirectory(const QString& dir);
242 
247  void setWadArchiveEnabled(bool enabled);
248 
261  void skipFileCurrentUrl(const QString& fileName);
262 
269  void skipService(const QString &service);
270 
282  void skipSiteSeek(const QUrl& url);
283 
293  bool startSeek(const QStringList& wads);
294 
301  QString targetDirectory() const;
302 
303  public slots:
308  void abort();
309 
310  signals:
319  void allDone(bool bSuccess);
320 
333  void fileDownloadFinished(const QString& filename);
334 
350  void fileDownloadProgress(const QString& filename, qint64 done, qint64 total);
351 
360  void fileDownloadStarted(const QString& filename, const QUrl& url);
361 
370  void fileInstalled(const QString& filename);
371 
379  void message(const QString& msg, WadseekerLib::MessageType type);
380 
389  void seekStarted(const QStringList& filenames);
390 
404  void serviceStarted(const QString &name);
405 
415  void serviceFinished(const QString &name);
416 
420  void siteFinished(const QUrl& site);
421 
425  void siteProgress(const QUrl& site, qint64 bytes, qint64 total);
426 
430  void siteRedirect(const QUrl& oldUrl, const QUrl& newUrl);
431 
435  void siteStarted(const QUrl& site);
436 
437  private:
438  DPtr<Wadseeker> d;
439 
440  void abortSeekers();
441  void abortWwwSeeker();
442  void cleanUpAfterFinish();
443  bool isAllFinished() const;
444 
448  void prepareSeekObjects();
449 
450  void setupIdgamesClients(const QList<WadDownloadInfo>& wadDownloadInfoList);
451  void setupSitesUrls();
452  void setupWadArchiveClient(const QList<WadDownloadInfo> &wadDownloadInfos);
453 
454  void startNextIdgamesClient();
455  void startIdgames();
456  void stopIdgames();
457  void startWadArchiveClient();
458  void stopWadArchiveClient();
459 
460  private slots:
461  void cleanUpIfAllFinished();
462  void fileLinkFound(const QString& filename, const QUrl& url);
463  void fileMirrorLinksFound(const QString& filename, const QList<QUrl>& urls);
464  void idgamesClientFinished(Idgames* pEmitter);
465  void reportBadUrl(const QUrl &url);
466  void wadArchiveFinished();
467  void wadRetrieverDownloadFinished(WadDownloadInfo wadDownloadInfo);
468  void wadRetrieverDownloadProgress(WadDownloadInfo wadDownloadInfo, qint64 current, qint64 total);
469  void wadRetrieverDownloadStarted(WadDownloadInfo wadDownloadInfo, const QUrl& url);
470  void wadRetrieverFinished();
471  void wadRetrieverMessage(const QString& message, WadseekerLib::MessageType type);
472  void wadRetrieverWadInstalled(WadDownloadInfo wadDownloadInfo);
473  void wwwSeekerFinished();
474 };
475 
476 #endif
477 
Main controlling class.
Definition: wadseeker.h:85