Ubuntu Download Manager  1.0.0
A session-wide downloading service
download_impl.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013-2015 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 #pragma once
20 
21 #include <QDBusConnection>
22 #include <QDBusObjectPath>
23 #include <QObject>
24 #include <QVariantMap>
25 #include <QString>
26 
27 #include <ubuntu/transfers/visibility.h>
28 #include <ubuntu/download_manager/metatypes.h>
29 
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  QVariantMap metadata();
70  void setMetadata(QVariantMap map);
71  void setThrottle(qulonglong speed);
72  qulonglong throttle();
73 
74  QString id() const;
75  qulonglong progress();
76  qulonglong totalSize();
77 
78  bool isError() const;
79  Error* error() const;
80 
81  QString clickPackage() const;
82  bool showInIndicator() const;
83  QString title() const;
84 
85  protected:
86  DownloadImpl(const QDBusConnection& conn, Error* err, QObject* parent = 0);
87  DownloadImpl(const QDBusConnection& conn,
88  const QString& servicePath,
89  const QDBusObjectPath& objectPath,
90  QObject* parent = 0);
91 
92  private:
93  void setLastError(Error* err);
94  void setLastError(const QDBusError& err);
95  void onHttpError(HttpErrorStruct);
96  void onNetworkError(NetworkErrorStruct);
97  void onProcessError(ProcessErrorStruct);
98  void onAuthError(AuthErrorStruct);
99  void onHashError(HashErrorStruct);
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