Ubuntu Download Manager  0.3.0
A session-wide downloading service
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator
manager_impl.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_IMPL_H
20 #define UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_IMPL_H
21 
22 #include <QDBusConnection>
23 #include <QDBusObjectPath>
24 #include <ubuntu/transfers/visibility.h>
25 #include <ubuntu/transfers/system/dbus_connection.h>
26 #include "download.h"
27 #include "error.h"
28 #include "group_download.h"
29 #include "manager_interface.h"
31 #include "manager.h"
32 
33 
34 class QDBusConnection;
35 
36 namespace Ubuntu {
37 
38 namespace DownloadManager {
39 
40 class Download;
41 class Error;
42 class GroupDownload;
43 class ManagerInterface;
44 
45 class UBUNTU_TRANSFERS_PRIVATE ManagerImpl : public Manager {
46  Q_OBJECT
47 
48  // allow watchers to emit the signals
49  friend class Manager;
50  friend class DownloadManagerPCW;
51  friend class GroupManagerPCW;
52 
53  public:
54  virtual ~ManagerImpl();
55  virtual Download* getDownloadForId(const QString& id);
56  virtual void createDownload(DownloadStruct downStruct);
57  virtual void createDownload(DownloadStruct downStruct,
58  DownloadCb cb,
59  DownloadCb errCb);
60  virtual void createDownload(StructList downs,
61  const QString &algorithm,
62  bool allowed3G,
63  const QVariantMap &metadata,
64  StringMap headers);
65  virtual void createDownload(StructList downs,
66  const QString &algorithm,
67  bool allowed3G,
68  const QVariantMap &metadata,
69  StringMap headers,
70  GroupCb cb,
71  GroupCb errCb);
72  virtual void getAllDownloads();
73  virtual void getAllDownloads(DownloadsListCb cb,
74  DownloadsListCb errCb);
75  virtual void getAllDownloadsWithMetadata(const QString &name,
76  const QString &value);
77  virtual void getAllDownloadsWithMetadata(const QString &name,
78  const QString &value,
81 
82  bool isError() const;
83  Error* lastError() const;
84  void allowMobileDataDownload(bool allowed);
85  bool isMobileDataDownload();
86  qulonglong defaultThrottle();
87  void setDefaultThrottle(qulonglong speed);
88  void exit();
89 
90  protected:
91  ManagerImpl(const QDBusConnection& conn,
92  const QString& path = "",
93  QObject* parent= 0);
94  // used for testing purposes
95  ManagerImpl(const QDBusConnection& conn,
96  const QString& path,
97  ManagerInterface* interface,
98  QObject* parent);
99 
100  private:
101  void init();
102  void onWatcherDone();
103  void setLastError(const QDBusError& err);
104 
105  private:
106  bool _isError = false;
107  QDBusConnection _conn;
108  QString _servicePath;
109  Error* _lastError = nullptr;
110  ManagerInterface* _dbusInterface = nullptr;
111 
112 };
113 
114 } // DownloadManager
115 
116 } // Ubuntu
117 
118 #endif // UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H
std::function< void(Download *)> DownloadCb
Definition: manager.h:36
std::function< void(const QString &, const QString &, DownloadsList *)> MetadataDownloadsListCb
Definition: manager.h:54
std::function< void(GroupDownload *)> GroupCb
Definition: manager.h:60
std::function< void(DownloadsList *)> DownloadsListCb
Definition: manager.h:48