Ubuntu Download Manager  1.0.0
A session-wide downloading service
manager.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013-2014 Canonical Ltd.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public
6  * License as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the
15  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  * Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H
20 #define UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H
21 
22 #include <functional>
23 #include <QObject>
24 #include <ubuntu/download_manager/metatypes.h>
25 #include <ubuntu/download_manager/download_struct.h>
26 #include <ubuntu/download_manager/group_download_struct.h>
27 
28 
29 namespace Ubuntu {
30 
31 namespace DownloadManager {
32 
33 class Download;
34 class DownloadsList;
35 class Error;
37 
42 typedef std::function<void(Download*)> DownloadCb;
43 
48 typedef std::function<void(DownloadsList*)> DownloadsListCb;
49 
54 typedef std::function<void(const QString&, const QString&, DownloadsList*)> MetadataDownloadsListCb;
55 
60 typedef std::function<void(GroupDownload*)> GroupCb;
61 
80 class Manager : public QObject {
81  Q_OBJECT
82 
83  public:
84  explicit Manager(QObject* parent = 0)
85  : QObject(parent) {}
86 
94  virtual Download* getDownloadForId(const QString& id) = 0;
95 
107  virtual void createDownload(DownloadStruct downStruct) = 0;
108 
124  virtual void createDownload(DownloadStruct downStruct,
125  DownloadCb cb,
126  DownloadCb errCb) = 0;
127 
139  virtual void createDownload(StructList downs,
140  const QString& algorithm,
141  bool allowed3G,
142  const QVariantMap& metadata,
143  StringMap headers) = 0;
144 
160  virtual void createDownload(StructList downs,
161  const QString& algorithm,
162  bool allowed3G,
163  const QVariantMap& metadata,
164  StringMap headers,
165  GroupCb cb,
166  GroupCb errCb) = 0;
176  virtual void getAllDownloads() = 0;
177 
187  virtual void getAllDownloads(DownloadsListCb cb,
188  DownloadsListCb errCb) = 0;
199  virtual void getAllDownloadsWithMetadata(const QString &name,
200  const QString &value) = 0;
213  virtual void getAllDownloadsWithMetadata(const QString &name,
214  const QString &value,
215  MetadataDownloadsListCb cb,
216  MetadataDownloadsListCb errCb) = 0;
217 
223  virtual bool isError() const = 0;
224 
231  virtual Error* lastError() const = 0;
232 
243  virtual void allowMobileDataDownload(bool allowed) = 0;
244 
251  virtual bool isMobileDataDownload() = 0;
252 
259  virtual qulonglong defaultThrottle() = 0;
260 
270  virtual void setDefaultThrottle(qulonglong speed) = 0;
271 
282  virtual void exit() = 0;
283 
296  static Manager* createSessionManager(const QString& path = "", QObject* parent=0);
297 
310  static Manager* createSystemManager(const QString& path = "", QObject* parent=0);
311 
312  signals:
313 
320  void downloadCreated(Download* down);
321  void downloadsFound(DownloadsList* downloads);
322  void downloadsWithMetadataFound(const QString& name,
323  const QString& value,
324  DownloadsList* downloads);
325 
332  void groupCreated(GroupDownload* down);
333 
334 };
335 
336 } // DownloadManager
337 
338 } // Ubuntu
339 
340 #endif // UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H
The Error class is the base class that represents an error in the download manager API...
Definition: error.h:55
std::function< void(Download *)> DownloadCb
Definition: manager.h:36
std::function< void(const QString &, const QString &, DownloadsList *)> MetadataDownloadsListCb
Definition: manager.h:54
static Manager * createSessionManager(const QString &path="", QObject *parent=0)
Definition: manager.cpp:31
void groupCreated(GroupDownload *down)
virtual void createDownload(DownloadStruct downStruct)=0
void downloadsFound(DownloadsList *downloads)
virtual Error * lastError() const =0
virtual void allowMobileDataDownload(bool allowed)=0
virtual bool isError() const =0
virtual bool isMobileDataDownload()=0
static Manager * createSystemManager(const QString &path="", QObject *parent=0)
Definition: manager.cpp:40
virtual void setDefaultThrottle(qulonglong speed)=0
The Download class allows to control a download that was created in the download manager.
Definition: download.h:49
Manager(QObject *parent=0)
Definition: manager.h:84
std::function< void(GroupDownload *)> GroupCb
Definition: manager.h:60
std::function< void(DownloadsList *)> DownloadsListCb
Definition: manager.h:48
void downloadCreated(Download *down)
void downloadsWithMetadataFound(const QString &name, const QString &value, DownloadsList *downloads)
The Manager class is the entry point of the download manager API and allows the client to create down...
Definition: manager.h:80
virtual void getAllDownloadsWithMetadata(const QString &name, const QString &value)=0
virtual qulonglong defaultThrottle()=0
virtual Download * getDownloadForId(const QString &id)=0