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 class ModSet;
45 class ModFile;
46 
87 class WADSEEKER_API Wadseeker : public QObject
88 {
89  Q_OBJECT
90 
91 public:
97  static const QString defaultSites[];
98 
106  static const QString forbiddenWads[];
107 
111  static const QString defaultIdgamesUrl();
112 
118  static QStringList defaultSitesListEncoded();
119 
123  static ModSet filterAllowedOnlyWads(const ModSet &wads);
127  static ModSet filterForbiddenOnlyWads(const ModSet &wads);
128 
138  static bool isForbiddenWad(const ModFile &wad);
139 
143  Wadseeker();
144 
148  ~Wadseeker() override;
149 
156  bool isDownloadingFile(const ModFile &file) const;
157 
167  bool isWorking() const;
168 
181  void setCustomSite(const QString &url);
182 
189  void setCustomSites(const QStringList &urls);
190 
197  void setIdgamesEnabled(bool bEnabled);
198 
202  void setIdgamesUrl(QString archiveURL);
203 
212  void setMaximumConcurrentDownloads(unsigned max);
213 
222  void setMaximumConcurrentSeeks(unsigned max);
223 
234  void setPrimarySites(const QStringList &urlList);
235 
242  void setPrimarySitesToDefault();
243 
253  void setTargetDirectory(const QString &dir);
254 
259  void setWadArchiveEnabled(bool enabled);
260 
273  void skipFileCurrentUrl(const QString &fileName);
274 
281  void skipService(const QString &service);
282 
294  void skipSiteSeek(const QUrl &url);
295 
305  bool startSeek(const ModSet &wads);
306 
313  QString targetDirectory() const;
314 
315 public slots:
320  void abort();
321 
322 signals:
331  void allDone(bool bSuccess);
332 
345  void fileDownloadFinished(const ModFile &filename);
346 
362  void fileDownloadProgress(const ModFile &filename, qint64 done, qint64 total);
363 
372  void fileDownloadStarted(const ModFile &filename, const QUrl &url);
373 
382  void fileInstalled(const ModFile &filename);
383 
391  void message(const QString &msg, WadseekerLib::MessageType type);
392 
401  void seekStarted(const ModSet &filenames);
402 
416  void serviceStarted(const QString &name);
417 
427  void serviceFinished(const QString &name);
428 
432  void siteFinished(const QUrl &site);
433 
437  void siteProgress(const QUrl &site, qint64 bytes, qint64 total);
438 
442  void siteRedirect(const QUrl &oldUrl, const QUrl &newUrl);
443 
447  void siteStarted(const QUrl &site);
448 
449 private:
450  DPtr<Wadseeker> d;
451 
452  void abortSeekers();
453  void abortWwwSeeker();
454  void cleanUpAfterFinish();
455  bool isAllFinished() const;
456 
460  void prepareSeekObjects();
461 
462  void setupIdgamesClients(const QList<WadDownloadInfo> &wadDownloadInfoList);
463  void setupSitesUrls();
464  void setupWadArchiveClient(const QList<WadDownloadInfo> &wadDownloadInfos);
465 
466  void startNextIdgamesClient();
467  void startIdgames();
468  void stopIdgames();
469  void startWadArchiveClient();
470  void stopWadArchiveClient();
471 
472 private slots:
473  void cleanUpIfAllFinished();
474  void fileLinkFound(const QString &filename, const QUrl &url);
475  void fileMirrorLinksFound(const QString &filename, const QList<QUrl> &urls);
476  void idgamesClientFinished(Idgames *pEmitter);
477  void reportBadUrl(const QUrl &url);
478  void wadArchiveFinished();
479  void wadRetrieverDownloadFinished(WadDownloadInfo wadDownloadInfo);
480  void wadRetrieverDownloadProgress(WadDownloadInfo wadDownloadInfo, qint64 current, qint64 total);
481  void wadRetrieverDownloadStarted(WadDownloadInfo wadDownloadInfo, const QUrl &url);
482  void wadRetrieverFinished();
483  void wadRetrieverMessage(const QString &message, WadseekerLib::MessageType type);
484  void wadRetrieverWadInstalled(WadDownloadInfo wadDownloadInfo);
485  void wwwSeekerFinished();
486 };
487 
488 #endif