File indexing completed on 2025-01-05 03:59:36
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2007 Torsten Rahn <tackat@kde.org> 0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org> 0005 // SPDX-FileCopyrightText: 2009 Jens-Michael Hoffmann <jensmh@gmx.de> 0006 // 0007 0008 // 0009 // The HttpDownloadManager manages http downloads. 0010 // 0011 0012 #ifndef MARBLE_HTTPDOWNLOADMANAGER_H 0013 #define MARBLE_HTTPDOWNLOADMANAGER_H 0014 0015 #include <QObject> 0016 0017 #include "MarbleGlobal.h" 0018 #include "digikam_export.h" 0019 0020 class QUrl; 0021 0022 namespace Marble 0023 { 0024 0025 class DownloadPolicy; 0026 class StoragePolicy; 0027 0028 /** 0029 * @short This class manages scheduled downloads. 0030 * 0031 * The downloadmanager offers a maximum number of active jobs and a 0032 * limit for pending jobs. it also takes care that the job queue 0033 * won't be polluted by jobs that timed out already. 0034 * 0035 * @author Torsten Rahn 0036 */ 0037 0038 class DIGIKAM_EXPORT HttpDownloadManager : public QObject 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 /** 0044 * Creates a new http download manager. 0045 * 0046 * @note HttpDownloadManager doesn't take ownership of @p policy. 0047 * 0048 * @param policy The storage policy for this manager. 0049 */ 0050 explicit HttpDownloadManager( StoragePolicy *policy ); 0051 0052 /** 0053 * Destroys the http download manager. 0054 */ 0055 ~HttpDownloadManager() override; 0056 0057 /** 0058 * Switches loading on/off, useful for offline mode. 0059 */ 0060 void setDownloadEnabled( const bool enable ); 0061 void addDownloadPolicy( const DownloadPolicy& ); 0062 0063 static QByteArray userAgent(const QString &platform, const QString &plugin); 0064 0065 public Q_SLOTS: 0066 0067 /** 0068 * Adds a new job with a sourceUrl, destination file name and given id. 0069 */ 0070 void addJob( const QUrl& sourceUrl, const QString& destFilename, const QString &id, 0071 const DownloadUsage usage ); 0072 0073 0074 Q_SIGNALS: 0075 void downloadComplete( const QString&, const QString& ); 0076 0077 /** 0078 * This signal is Q_EMITted if a file is downloaded and the data argument 0079 * contains the files content. The HttpDownloadManager takes care to save 0080 * it using the given storage policy. 0081 */ 0082 void downloadComplete( const QByteArray &data, const QString& initiatorId ); 0083 0084 /** 0085 * Signal is Q_EMITted when a new job is added to the queue. 0086 */ 0087 void jobAdded(); 0088 0089 /** 0090 * Signal is Q_EMITted when a job is removed from the queue. 0091 * The job might be completed or blacklisted. 0092 */ 0093 void jobRemoved(); 0094 0095 /** 0096 * A job was queued, activated or removed (finished, failed) 0097 */ 0098 void progressChanged( int active, int queued ); 0099 0100 private: 0101 Q_DISABLE_COPY( HttpDownloadManager ) 0102 0103 class Private; 0104 Private * const d; 0105 0106 Q_PRIVATE_SLOT( d, void finishJob( const QByteArray&, const QString&, const QString& id ) ) 0107 Q_PRIVATE_SLOT( d, void requeue() ) 0108 Q_PRIVATE_SLOT( d, void startRetryTimer() ) 0109 }; 0110 0111 } 0112 0113 #endif // MARBLE_HTTPDOWNLOADMANAGER_H