Ubuntu Download Manager  0.6.0
A session-wide downloading service
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator
download_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_DOWNLOAD_IMPL_H
20 #define UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_IMPL_H
21 
22 #include <QDBusConnection>
23 #include <QDBusObjectPath>
24 #include <QObject>
25 #include <QVariantMap>
26 #include <QString>
27 
28 #include <ubuntu/transfers/visibility.h>
29 #include <ubuntu/download_manager/metatypes.h>
30 
34 
35 #include "download.h"
36 
37 class QDBusConnection;
38 class QDBusObjectPath;
39 
40 namespace Ubuntu {
41 
42 namespace DownloadManager {
43 
44 class Error;
45 class UBUNTU_TRANSFERS_PRIVATE DownloadImpl : public Download {
46  Q_OBJECT
47 
48  // allow the manager to create downloads
49  friend class ManagerImpl;
50  friend class DownloadPCW;
51  friend class MetadataDownloadsListManagerPCW;
52  friend class DownloadsListManagerPCW;
53  friend class DownloadManagerPCW;
54 
55  public:
56  virtual ~DownloadImpl();
57 
58  void start();
59  void pause();
60  void resume();
61  void cancel();
62 
63  void allowMobileDownload(bool allowed);
64  bool isMobileDownloadAllowed();
65 
66  void setDestinationDir(const QString& path);
67  void setHeaders(QMap<QString, QString> headers);
68  QMap<QString, QString> headers();
69  void setThrottle(qulonglong speed);
70  qulonglong throttle();
71 
72  QString id() const;
73  QVariantMap metadata();
74  qulonglong progress();
75  qulonglong totalSize();
76 
77  bool isError() const;
78  Error* error() const;
79 
80  protected:
81  DownloadImpl(const QDBusConnection& conn, Error* err, QObject* parent = 0);
82  DownloadImpl(const QDBusConnection& conn,
83  const QString& servicePath,
84  const QDBusObjectPath& objectPath,
85  QObject* parent = 0);
86 
87  private:
88  void setLastError(Error* err);
89  void setLastError(const QDBusError& err);
90  void onHttpError(HttpErrorStruct);
91  void onNetworkError(NetworkErrorStruct);
92  void onProcessError(ProcessErrorStruct);
93  void onAuthError(AuthErrorStruct);
94 
95  private:
96  QString _id;
97  bool _isError = false;
98  Error* _lastError = nullptr;
99  DownloadInterface* _dbusInterface = nullptr;
100  QDBusConnection _conn;
101  QString _servicePath;
102 
103 };
104 
105 } // Ubuntu
106 
107 } // DownloadManager
108 
109 #endif // UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_IMPL_H