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 
179  void setCustomSite(const QString &url);
180 
187  void setIdgamesEnabled(bool bEnabled);
188 
192  void setIdgamesUrl(QString archiveURL);
193 
202  void setMaximumConcurrentDownloads(unsigned max);
203 
212  void setMaximumConcurrentSeeks(unsigned max);
213 
224  void setPrimarySites(const QStringList &urlList);
225 
232  void setPrimarySitesToDefault();
233 
243  void setTargetDirectory(const QString &dir);
244 
249  void setWadArchiveEnabled(bool enabled);
250 
263  void skipFileCurrentUrl(const QString &fileName);
264 
271  void skipService(const QString &service);
272 
284  void skipSiteSeek(const QUrl &url);
285 
295  bool startSeek(const ModSet &wads);
296 
303  QString targetDirectory() const;
304 
305 public slots:
310  void abort();
311 
312 signals:
321  void allDone(bool bSuccess);
322 
335  void fileDownloadFinished(const ModFile &filename);
336 
352  void fileDownloadProgress(const ModFile &filename, qint64 done, qint64 total);
353 
362  void fileDownloadStarted(const ModFile &filename, const QUrl &url);
363 
372  void fileInstalled(const ModFile &filename);
373 
381  void message(const QString &msg, WadseekerLib::MessageType type);
382 
391  void seekStarted(const ModSet &filenames);
392 
406  void serviceStarted(const QString &name);
407 
417  void serviceFinished(const QString &name);
418 
422  void siteFinished(const QUrl &site);
423 
427  void siteProgress(const QUrl &site, qint64 bytes, qint64 total);
428 
432  void siteRedirect(const QUrl &oldUrl, const QUrl &newUrl);
433 
437  void siteStarted(const QUrl &site);
438 
439 private:
440  DPtr<Wadseeker> d;
441 
442  void abortSeekers();
443  void abortWwwSeeker();
444  void cleanUpAfterFinish();
445  bool isAllFinished() const;
446 
450  void prepareSeekObjects();
451 
452  void setupIdgamesClients(const QList<WadDownloadInfo> &wadDownloadInfoList);
453  void setupSitesUrls();
454  void setupWadArchiveClient(const QList<WadDownloadInfo> &wadDownloadInfos);
455 
456  void startNextIdgamesClient();
457  void startIdgames();
458  void stopIdgames();
459  void startWadArchiveClient();
460  void stopWadArchiveClient();
461 
462 private slots:
463  void cleanUpIfAllFinished();
464  void fileLinkFound(const QString &filename, const QUrl &url);
465  void fileMirrorLinksFound(const QString &filename, const QList<QUrl> &urls);
466  void idgamesClientFinished(Idgames *pEmitter);
467  void reportBadUrl(const QUrl &url);
468  void wadArchiveFinished();
469  void wadRetrieverDownloadFinished(WadDownloadInfo wadDownloadInfo);
470  void wadRetrieverDownloadProgress(WadDownloadInfo wadDownloadInfo, qint64 current, qint64 total);
471  void wadRetrieverDownloadStarted(WadDownloadInfo wadDownloadInfo, const QUrl &url);
472  void wadRetrieverFinished();
473  void wadRetrieverMessage(const QString &message, WadseekerLib::MessageType type);
474  void wadRetrieverWadInstalled(WadDownloadInfo wadDownloadInfo);
475  void wwwSeekerFinished();
476 };
477 
478 #endif
Main controlling class.
Definition: wadseeker.h:87