Marble

DownloadQueueSet.h
1 // SPDX-FileCopyrightText: 2009 Jens-Michael Hoffmann <[email protected]>
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 <QQueue>
10 #include <QObject>
11 #include <QSet>
12 #include <QStack>
13 
14 #include "DownloadPolicy.h"
15 
16 class QUrl;
17 
18 namespace Marble
19 {
20 
21 class 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 {
64  Q_OBJECT
65 
66  public:
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,
75  const QString& destinationFileName ) const;
76  void addJob( HttpJob * const job );
77 
78  void activateJobs();
79  void retryJobs();
80  void purgeJobs();
81 
82  Q_SIGNALS:
83  void jobAdded();
84  void jobRemoved();
85  void jobRetry();
86  void jobFinished( const QByteArray& data, const QString& destinationFileName,
87  const QString& id );
88  void jobRedirected( const QUrl& newSourceUrl, const QString& destinationFileName,
89  const QString& id, DownloadUsage );
90  void progressChanged( int active, int queued );
91 
92  private Q_SLOTS:
93  void finishJob( HttpJob * job, const QByteArray& data );
94  void redirectJob( HttpJob * job, const QUrl& newSourceUrl );
95  void retryOrBlacklistJob( HttpJob * job, const int errorCode );
96 
97  private:
98  void activateJob( HttpJob * const job );
99  void deactivateJob( HttpJob * const job );
100  bool jobIsActive( const QString& destinationFileName ) const;
101  bool jobIsQueued( const QString& destinationFileName ) const;
102  bool jobIsWaitingForRetry( const QString& destinationFileName ) const;
103  bool jobIsBlackListed( const QUrl& sourceUrl ) const;
104 
105  DownloadPolicy m_downloadPolicy;
106 
107  /** This is the first stage a job enters, from this queue it will get
108  * into the activatedJobs container.
109  */
110  class JobStack
111  {
112  public:
113  bool contains( const QString& destinationFileName ) const;
114  int count() const;
115  bool isEmpty() const;
116  HttpJob * pop();
117  void push( HttpJob * const );
118  private:
119  QStack<HttpJob*> m_jobs;
120  QSet<QString> m_jobsContent;
121  };
122  JobStack m_jobs;
123 
124  /// Contains the jobs which are currently being downloaded.
125  QList<HttpJob*> m_activeJobs;
126 
127  /** Contains jobs which failed to download and which are scheduled for
128  * retry according to retry settings.
129  */
130  QQueue<HttpJob*> m_retryQueue;
131 
132  /// Contains the blacklisted source urls
133  QSet<QString> m_jobBlackList;
134 };
135 
136 }
137 
138 #endif
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
DownloadUsage
This enum is used to describe the type of download.
Definition: MarbleGlobal.h:153
Binds a QML item to a specific geodetic location in screen coordinates.
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Sep 27 2023 04:09:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.