Ubuntu Download Manager  1.2.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;
181  virtual void getAllDownloads(const QString& appId, bool uncollected) = 0;
182 
197  virtual void getAllDownloads(const QString& appId,
198  bool uncollected,
199  DownloadsListCb cb,
200  DownloadsListCb errCb) = 0;
211  virtual void getAllDownloadsWithMetadata(const QString &name,
212  const QString &value) = 0;
225  virtual void getAllDownloadsWithMetadata(const QString &name,
226  const QString &value,
227  MetadataDownloadsListCb cb,
228  MetadataDownloadsListCb errCb) = 0;
229 
235  virtual bool isError() const = 0;
236 
243  virtual Error* lastError() const = 0;
244 
255  virtual void allowMobileDataDownload(bool allowed) = 0;
256 
263  virtual bool isMobileDataDownload() = 0;
264 
271  virtual qulonglong defaultThrottle() = 0;
272 
282  virtual void setDefaultThrottle(qulonglong speed) = 0;
283 
294  virtual void exit() = 0;
295 
308  static Manager* createSessionManager(const QString& path = "", QObject* parent=0);
309 
322  static Manager* createSystemManager(const QString& path = "", QObject* parent=0);
323 
324  signals:
325 
332  void downloadCreated(Download* down);
333  void downloadsFound(DownloadsList* downloads);
334  void downloadsWithMetadataFound(const QString& name,
335  const QString& value,
336  DownloadsList* downloads);
337 
344  void groupCreated(GroupDownload* down);
345 
346 };
347 
348 } // DownloadManager
349 
350 } // Ubuntu
351 
352 #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
virtual void getAllDownloads(const QString &appId, bool uncollected)=0
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