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 class Idgames;
38 class WadArchiveClient;
39 class WadRetriever;
40 class WWWSeeker;
41 class ModSet;
42 class ModFile;
43 
84 class WADSEEKER_API Wadseeker : public QObject
85 {
86  Q_OBJECT
87 
88 public:
94  static const QString defaultSites[];
95 
103  static const QString forbiddenWads[];
104 
108  static const QString defaultIdgamesUrl();
109 
115  static QStringList defaultSitesListEncoded();
116 
120  static ModSet filterAllowedOnlyWads(const ModSet &wads);
124  static ModSet filterForbiddenOnlyWads(const ModSet &wads);
125 
135  static bool isForbiddenWad(const ModFile &wad);
136 
140  Wadseeker();
141 
145  ~Wadseeker() override;
146 
153  bool isDownloadingFile(const ModFile &file) const;
154 
164  bool isWorking() const;
165 
178  void setCustomSite(const QString &url);
179 
186  void setCustomSites(const QStringList &urls);
187 
194  void setIdgamesEnabled(bool bEnabled);
195 
199  void setIdgamesUrl(QString archiveURL);
200 
209  void setMaximumConcurrentDownloads(unsigned max);
210 
219  void setMaximumConcurrentSeeks(unsigned max);
220 
231  void setPrimarySites(const QStringList &urlList);
232 
239  void setPrimarySitesToDefault();
240 
250  void setTargetDirectory(const QString &dir);
251 
256  void setWadArchiveEnabled(bool enabled);
257 
270  void skipFileCurrentUrl(const QString &fileName);
271 
278  void skipService(const QString &service);
279 
291  void skipSiteSeek(const QUrl &url);
292 
302  bool startSeek(const ModSet &wads);
303 
310  QString targetDirectory() const;
311 
312 public slots:
317  void abort();
318 
319 signals:
328  void allDone(bool bSuccess);
329 
342  void fileDownloadFinished(const ModFile &filename);
343 
359  void fileDownloadProgress(const ModFile &filename, qint64 done, qint64 total);
360 
369  void fileDownloadStarted(const ModFile &filename, const QUrl &url);
370 
379  void fileInstalled(const ModFile &filename);
380 
388  void message(const QString &msg, WadseekerLib::MessageType type);
389 
398  void seekStarted(const ModSet &filenames);
399 
413  void serviceStarted(const QString &name);
414 
424  void serviceFinished(const QString &name);
425 
429  void siteFinished(const QUrl &site);
430 
434  void siteProgress(const QUrl &site, qint64 bytes, qint64 total);
435 
439  void siteRedirect(const QUrl &oldUrl, const QUrl &newUrl);
440 
444  void siteStarted(const QUrl &site);
445 
446 private:
447  DPtr<Wadseeker> d;
448 
449  void abortSeekers();
450  void abortWwwSeeker();
451  void cleanUpAfterFinish();
452  bool isAllFinished() const;
453 
457  void prepareSeekObjects();
458 
459  void setupIdgamesClients(const QList<WadDownloadInfo> &wadDownloadInfoList);
460  void setupSitesUrls();
461  void setupWadArchiveClient(const QList<WadDownloadInfo> &wadDownloadInfos);
462 
463  void startNextIdgamesClient();
464  void startIdgames();
465  void stopIdgames();
466  void startWadArchiveClient();
467  void stopWadArchiveClient();
468 
469 private slots:
470  void cleanUpIfAllFinished();
471  void fileLinkFound(const QString &filename, const QUrl &url);
472  void fileMirrorLinksFound(const QString &filename, const QList<QUrl> &urls);
473  void idgamesClientFinished(Idgames *pEmitter);
474  void reportBadUrl(const QUrl &url);
475  void wadArchiveFinished();
476  void wadRetrieverDownloadFinished(WadDownloadInfo wadDownloadInfo);
477  void wadRetrieverDownloadProgress(WadDownloadInfo wadDownloadInfo, qint64 current, qint64 total);
478  void wadRetrieverDownloadStarted(WadDownloadInfo wadDownloadInfo, const QUrl &url);
479  void wadRetrieverFinished();
480  void wadRetrieverMessage(const QString &message, WadseekerLib::MessageType type);
481  void wadRetrieverWadInstalled(WadDownloadInfo wadDownloadInfo);
482  void wwwSeekerFinished();
483 };
484 
485 #endif