Lomiri
Loading...
Searching...
No Matches
DownloadTracker.cpp
1/*
2 * Copyright (C) 2013-2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, as
6 * published by the Free Software Foundation; either version 2.1 or 3.0
7 * of the License.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of both the GNU Lesser General Public
16 * License along with this program. If not, see <http://www.gnu.org/licenses/>
17 *
18 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
19 */
20
21
22#include "DownloadTracker.h"
23
24DownloadTracker::DownloadTracker(QObject *parent)
25 : QObject(parent)
26 , m_adaptor(nullptr)
27{
28}
29
30bool DownloadTracker::isServiceReady() const
31{
32 bool ready = false;
33 if(m_adaptor != nullptr) {
34 ready = m_adaptor->isValid();
35 }
36
37 return ready;
38}
39
40QString DownloadTracker::dbusPath() const
41{
42 return m_dbusPath;
43}
44
45void DownloadTracker::setDbusPath(const QString& path)
46{
47 if(m_dbusPath != path){
48 m_dbusPath = path;
49 startService();
50 Q_EMIT dbusPathChanged(m_dbusPath);
51 }
52}
53
54QString DownloadTracker::service() const
55{
56 return m_service;
57}
58
59void DownloadTracker::setService(const QString& service)
60{
61 if(m_service != service){
62 m_service = service;
63 startService();
64 Q_EMIT serviceChanged(m_service);
65 }
66}
67
68void DownloadTracker::startService()
69{
70 // FIXME update dbus path and service on changes
71 if(!m_service.isEmpty() && !m_dbusPath.isEmpty()) {
72 m_adaptor = new DownloadTrackerAdaptor(m_service, m_dbusPath, QDBusConnection::sessionBus(), this);
73
74 connect(m_adaptor, &DownloadTrackerAdaptor::canceled, this, &DownloadTracker::canceled);
75 connect(m_adaptor, &DownloadTrackerAdaptor::error, this, &DownloadTracker::error);
76 connect(m_adaptor, &DownloadTrackerAdaptor::finished, this, &DownloadTracker::finished);
77 connect(m_adaptor, &DownloadTrackerAdaptor::paused, this, &DownloadTracker::paused);
78 connect(m_adaptor, static_cast<void (DownloadTrackerAdaptor::*)(qulonglong, qulonglong)>(&DownloadTrackerAdaptor::progress), this, &DownloadTracker::progress);
79 connect(m_adaptor, &DownloadTrackerAdaptor::resumed, this, &DownloadTracker::resumed);
80 connect(m_adaptor, &DownloadTrackerAdaptor::started, this, &DownloadTracker::started);
81 connect(m_adaptor, &DownloadTrackerAdaptor::processing, this, &DownloadTracker::processing);
82 }
83 // FIXME find a better way of determining if the service is ready
84 Q_EMIT serviceReadyChanged(m_adaptor && m_adaptor->isValid());
85}