Ubuntu Download Manager  0.9.0
A session-wide downloading service
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 
35 
36 #include "download.h"
37 
38 class QDBusConnection;
39 class QDBusObjectPath;
40 
41 namespace Ubuntu {
42 
43 namespace DownloadManager {
44 
45 class Error;
46 class UBUNTU_TRANSFERS_PRIVATE DownloadImpl : public Download {
47  Q_OBJECT
48 
49  // allow the manager to create downloads
50  friend class ManagerImpl;
51  friend class DownloadPCW;
52  friend class MetadataDownloadsListManagerPCW;
53  friend class DownloadsListManagerPCW;
54  friend class DownloadManagerPCW;
55 
56  public:
57  virtual ~DownloadImpl();
58 
59  void start();
60  void pause();
61  void resume();
62  void cancel();
63 
64  void allowMobileDownload(bool allowed);
65  bool isMobileDownloadAllowed();
66 
67  void setDestinationDir(const QString& path);
68  void setHeaders(QMap<QString, QString> headers);
69  QMap<QString, QString> headers();
70  QVariantMap metadata();
71  void setMetadata(QVariantMap map);
72  void setThrottle(qulonglong speed);
73  qulonglong throttle();
74 
75  QString id() const;
76  qulonglong progress();
77  qulonglong totalSize();
78 
79  bool isError() const;
80  Error* error() const;
81 
82  QString clickPackage() const;
83  bool showInIndicator() const;
84  QString title() const;
85 
86  protected:
87  DownloadImpl(const QDBusConnection& conn, Error* err, QObject* parent = 0);
88  DownloadImpl(const QDBusConnection& conn,
89  const QString& servicePath,
90  const QDBusObjectPath& objectPath,
91  QObject* parent = 0);
92 
93  private:
94  void setLastError(Error* err);
95  void setLastError(const QDBusError& err);
96  void onHttpError(HttpErrorStruct);
97  void onNetworkError(NetworkErrorStruct);
98  void onProcessError(ProcessErrorStruct);
99  void onAuthError(AuthErrorStruct);
100  void onPropertiesChanged(const QString& interfaceName,
101  const QVariantMap& changedProperties,
102  const QStringList& invalidatedProperties);
103 
104  private:
105  QString _id;
106  bool _isError = false;
107  Error* _lastError = nullptr;
108  DownloadInterface* _dbusInterface = nullptr;
109  PropertiesInterface* _propertiesInterface = nullptr;
110  QDBusConnection _conn;
111  QString _servicePath;
112 
113 };
114 
115 } // Ubuntu
116 
117 } // DownloadManager
118 
119 #endif // UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_IMPL_H