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