Marble

DownloadQueueSet.h
1// SPDX-FileCopyrightText: 2009 Jens-Michael Hoffmann <jmho@c-xx.com>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef MARBLE_DOWNLOADQUEUESET_H
6#define MARBLE_DOWNLOADQUEUESET_H
7
8#include <QList>
9#include <QObject>
10#include <QQueue>
11#include <QSet>
12#include <QStack>
13
14#include "DownloadPolicy.h"
15
16class QUrl;
17
18namespace Marble
19{
20
21class HttpJob;
22
23/**
24 Life of a HttpJob
25 =================
26 - Job is added to the QueueSet (by calling addJob() )
27 the HttpJob is put into the m_jobQueue where it waits for "activation"
28 signal jobAdded is emitted
29 - Job is activated
30 Job is moved from m_jobQueue to m_activeJobs and signals of the job
31 are connected to slots (local or HttpDownloadManager)
32 Job is executed by calling the jobs execute() method
33
34 now there are different possibilities:
35 1) Job emits jobDone (some error occurred, or canceled (kio))
36 Job is disconnected
37 signal jobRemoved is emitted
38 Job is either moved from m_activeJobs to m_retryQueue
39 or destroyed and blacklisted
40
41 2) Job emits redirected
42 Job is removed from m_activeJobs, disconnected and destroyed
43 signal jobRemoved is emitted
44 (HttpDownloadManager creates new Job with new source url)
45
46 3) Job emits dataReceived
47 Job is removed from m_activeJobs, disconnected and destroyed
48 signal jobRemoved is emitted
49
50 so we can conclude following rules:
51 - Job is only connected to signals when in "active" state
52
53
54 questions:
55 - update of initiatorId needed?
56 "We update the initiatorId as the previous initiator
57 likely doesn't exist anymore"
58 - blacklist or black list?
59
60 */
61
63{
65
66public:
67 explicit DownloadQueueSet(QObject *const parent = nullptr);
68 explicit DownloadQueueSet(const DownloadPolicy &policy, QObject *const parent = nullptr);
69 ~DownloadQueueSet() override;
70
71 DownloadPolicy downloadPolicy() const;
72 void setDownloadPolicy(const DownloadPolicy &);
73
74 bool canAcceptJob(const QUrl &sourceUrl, const QString &destinationFileName) const;
75 void addJob(HttpJob *const job);
76
77 void activateJobs();
78 void retryJobs();
79 void purgeJobs();
80
82 void jobAdded();
83 void jobRemoved();
84 void jobRetry();
85 void jobFinished(const QByteArray &data, const QString &destinationFileName, const QString &id);
86 void jobRedirected(const QUrl &newSourceUrl, const QString &destinationFileName, const QString &id, DownloadUsage);
87 void progressChanged(int active, int queued);
88
89private Q_SLOTS:
90 void finishJob(HttpJob *job, const QByteArray &data);
91 void redirectJob(HttpJob *job, const QUrl &newSourceUrl);
92 void retryOrBlacklistJob(HttpJob *job, const int errorCode);
93
94private:
95 void activateJob(HttpJob *const job);
96 void deactivateJob(HttpJob *const job);
97 bool jobIsActive(const QString &destinationFileName) const;
98 bool jobIsQueued(const QString &destinationFileName) const;
99 bool jobIsWaitingForRetry(const QString &destinationFileName) const;
100 bool jobIsBlackListed(const QUrl &sourceUrl) const;
101
102 DownloadPolicy m_downloadPolicy;
103
104 /** This is the first stage a job enters, from this queue it will get
105 * into the activatedJobs container.
106 */
107 class JobStack
108 {
109 public:
110 bool contains(const QString &destinationFileName) const;
111 int count() const;
112 bool isEmpty() const;
113 HttpJob *pop();
114 void push(HttpJob *const);
115
116 private:
117 QStack<HttpJob *> m_jobs;
118 QSet<QString> m_jobsContent;
119 };
120 JobStack m_jobs;
121
122 /// Contains the jobs which are currently being downloaded.
123 QList<HttpJob *> m_activeJobs;
124
125 /** Contains jobs which failed to download and which are scheduled for
126 * retry according to retry settings.
127 */
128 QQueue<HttpJob *> m_retryQueue;
129
130 /// Contains the blacklisted source urls
131 QSet<QString> m_jobBlackList;
132};
133
134}
135
136#endif
Binds a QML item to a specific geodetic location in screen coordinates.
DownloadUsage
This enum is used to describe the type of download.
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:08:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.