Ubuntu Download Manager  1.2.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  void collected();
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  QString filePath();
75  Download::State state();
76 
77  QString id() const;
78  qulonglong progress();
79  qulonglong totalSize();
80 
81  bool isError() const;
82  Error* error() const;
83 
84  QString clickPackage() const;
85  bool showInIndicator() const;
86  QString title() const;
87  QString destinationApp() const;
88 
89  protected:
90  DownloadImpl(const QDBusConnection& conn, Error* err, QObject* parent = 0);
91  DownloadImpl(const QDBusConnection& conn,
92  const QString& servicePath,
93  const QDBusObjectPath& objectPath,
94  QObject* parent = 0);
95 
96  private:
97  void setLastError(Error* err);
98  void setLastError(const QDBusError& err);
99  void onHttpError(HttpErrorStruct);
100  void onNetworkError(NetworkErrorStruct);
101  void onProcessError(ProcessErrorStruct);
102  void onAuthError(AuthErrorStruct);
103  void onHashError(HashErrorStruct);
104  void onPropertiesChanged(const QString& interfaceName,
105  const QVariantMap& changedProperties,
106  const QStringList& invalidatedProperties);
107  void onFinished(const QString& path);
108 
109  private:
110  QString _id;
111  bool _isError = false;
112  Error* _lastError = nullptr;
113  DownloadInterface* _dbusInterface = nullptr;
114  PropertiesInterface* _propertiesInterface = nullptr;
115  QDBusConnection _conn;
116  QString _servicePath;
117 
118 };
119 
120 } // Ubuntu
121 
122 } // DownloadManager
123