Ubuntu Download Manager  0.3.0
A session-wide downloading service
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator
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/common.h>
26 #include <ubuntu/download_manager/download_struct.h>
27 #include <ubuntu/download_manager/group_download_struct.h>
28 
29 
30 namespace Ubuntu {
31 
32 namespace DownloadManager {
33 
34 class Download;
35 class DownloadsList;
36 class Error;
38 
43 typedef std::function<void(Download*)> DownloadCb;
44 
49 typedef std::function<void(DownloadsList*)> DownloadsListCb;
50 
55 typedef std::function<void(const QString&, const QString&, DownloadsList*)> MetadataDownloadsListCb;
56 
61 typedef std::function<void(GroupDownload*)> GroupCb;
62 
81 class Manager : public QObject {
82  Q_OBJECT
83 
84  public:
85  explicit Manager(QObject* parent = 0)
86  : QObject(parent) {}
87 
95  virtual Download* getDownloadForId(const QString& id) = 0;
96 
108  virtual void createDownload(DownloadStruct downStruct) = 0;
109 
125  virtual void createDownload(DownloadStruct downStruct,
126  DownloadCb cb,
127  DownloadCb errCb) = 0;
128 
140  virtual void createDownload(StructList downs,
141  const QString& algorithm,
142  bool allowed3G,
143  const QVariantMap& metadata,
144  StringMap headers) = 0;
145 
161  virtual void createDownload(StructList downs,
162  const QString& algorithm,
163  bool allowed3G,
164  const QVariantMap& metadata,
165  StringMap headers,
166  GroupCb cb,
167  GroupCb errCb) = 0;
177  virtual void getAllDownloads() = 0;
178 
188  virtual void getAllDownloads(DownloadsListCb cb,
189  DownloadsListCb errCb) = 0;
200  virtual void getAllDownloadsWithMetadata(const QString &name,
201  const QString &value) = 0;
214  virtual void getAllDownloadsWithMetadata(const QString &name,
215  const QString &value,
217  MetadataDownloadsListCb errCb) = 0;
218 
224  virtual bool isError() const = 0;
225 
232  virtual Error* lastError() const = 0;
233 
244  virtual void allowMobileDataDownload(bool allowed) = 0;
245 
252  virtual bool isMobileDataDownload() = 0;
253 
260  virtual qulonglong defaultThrottle() = 0;
261 
271  virtual void setDefaultThrottle(qulonglong speed) = 0;
272 
283  virtual void exit() = 0;
284 
297  static Manager* createSessionManager(const QString& path = "", QObject* parent=0);
298 
311  static Manager* createSystemManager(const QString& path = "", QObject* parent=0);
312 
313  signals:
314 
321  void downloadCreated(Download* down);
322  void downloadsFound(DownloadsList* downloads);
323  void downloadsWithMetadataFound(const QString& name,
324  const QString& value,
325  DownloadsList* downloads);
326 
333  void groupCreated(GroupDownload* down);
334 
335 };
336 
337 } // DownloadManager
338 
339 } // Ubuntu
340 
341 #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:56
std::function< void(Download *)> DownloadCb
Definition: manager.h:37
std::function< void(const QString &, const QString &, DownloadsList *)> MetadataDownloadsListCb
Definition: manager.h:55
static Manager * createSessionManager(const QString &path="", QObject *parent=0)
Definition: manager.cpp:32
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:41
virtual void setDefaultThrottle(qulonglong speed)=0
The Download class allows to control a download that was created in the download manager.
Definition: download.h:50
Manager(QObject *parent=0)
Definition: manager.h:85
std::function< void(GroupDownload *)> GroupCb
Definition: manager.h:61
std::function< void(DownloadsList *)> DownloadsListCb
Definition: manager.h:49
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:81
virtual void getAllDownloadsWithMetadata(const QString &name, const QString &value)=0
virtual qulonglong defaultThrottle()=0
virtual Download * getDownloadForId(const QString &id)=0