on xenial help sign in
Make some members/arguments const and add serviceReadyChanged signal.
97ef592Michał Sawicz
plugins/Ubuntu/DownloadDaemonListener/DownloadTracker.cpp+8−6
@@ -26,7 +26,7 @@ DownloadTracker::DownloadTracker(QObject *parent) :
26{
26{
27}
27}
28
28
29−bool DownloadTracker::isServiceReady()
29+bool DownloadTracker::isServiceReady() const
30{
30{
31 bool ready = false;
31 bool ready = false;
32 if(m_adaptor != nullptr) {
32 if(m_adaptor != nullptr) {
@@ -41,9 +41,9 @@ QString DownloadTracker::dbusPath() const
41 return m_dbusPath;
41 return m_dbusPath;
42}
42}
43
43
44−void DownloadTracker::setDbusPath(QString& path)
44+void DownloadTracker::setDbusPath(const QString& path)
45{
45{
46− if(path != "" && m_dbusPath != path){
46+ if(!path.isEmpty() && m_dbusPath != path){
47 m_dbusPath = path;
47 m_dbusPath = path;
48 startService();
48 startService();
49 Q_EMIT dbusPathChanged(m_dbusPath);
49 Q_EMIT dbusPathChanged(m_dbusPath);
@@ -55,9 +55,9 @@ QString DownloadTracker::service() const
55 return m_service;
55 return m_service;
56}
56}
57
57
58−void DownloadTracker::setService(QString& service)
58+void DownloadTracker::setService(const QString& service)
59{
59{
60− if(service != "" && m_service != service){
60+ if(!service.isEmpty() && m_service != service){
61 m_service = service;
61 m_service = service;
62 startService();
62 startService();
63 Q_EMIT serviceChanged(m_service);
63 Q_EMIT serviceChanged(m_service);
@@ -68,7 +68,7 @@ void DownloadTracker::startService()
68{
68{
69 // FIXME update dbus path and service on changes
69 // FIXME update dbus path and service on changes
70 if(!m_service.isEmpty() && !m_dbusPath.isEmpty()) {
70 if(!m_service.isEmpty() && !m_dbusPath.isEmpty()) {
71− m_adaptor = new DownloadTrackerAdaptor(m_service, m_dbusPath, QDBusConnection::sessionBus(), 0);
71+ m_adaptor = new DownloadTrackerAdaptor(m_service, m_dbusPath, QDBusConnection::sessionBus(), this);
72
72
73 connect(m_adaptor, SIGNAL(canceled(bool)), this, SIGNAL(canceled(bool)));
73 connect(m_adaptor, SIGNAL(canceled(bool)), this, SIGNAL(canceled(bool)));
74 connect(m_adaptor, SIGNAL(error(const QString &)), this, SIGNAL(error(const QString &)));
74 connect(m_adaptor, SIGNAL(error(const QString &)), this, SIGNAL(error(const QString &)));
@@ -78,4 +78,6 @@ void DownloadTracker::startService()
78 connect(m_adaptor, SIGNAL(resumed(bool)), this, SIGNAL(resumed(bool)));
78 connect(m_adaptor, SIGNAL(resumed(bool)), this, SIGNAL(resumed(bool)));
79 connect(m_adaptor, SIGNAL(started(bool)), this, SIGNAL(started(bool)));
79 connect(m_adaptor, SIGNAL(started(bool)), this, SIGNAL(started(bool)));
80 }
80 }
81+ // FIXME find a better way of determining if the service is ready
82+ Q_EMIT serviceReadyChanged(m_adaptor->isValid());
81}
83}
plugins/Ubuntu/DownloadDaemonListener/DownloadTracker.h+5−4
@@ -33,21 +33,22 @@ class DownloadTracker : public QObject
33 Q_DISABLE_COPY(DownloadTracker)
33 Q_DISABLE_COPY(DownloadTracker)
34 Q_PROPERTY(QString service READ service WRITE setService NOTIFY serviceChanged)
34 Q_PROPERTY(QString service READ service WRITE setService NOTIFY serviceChanged)
35 Q_PROPERTY(QString dbusPath READ dbusPath WRITE setDbusPath NOTIFY dbusPathChanged)
35 Q_PROPERTY(QString dbusPath READ dbusPath WRITE setDbusPath NOTIFY dbusPathChanged)
36− Q_PROPERTY(bool serviceReady READ isServiceReady)
36+ Q_PROPERTY(bool serviceReady READ isServiceReady NOTIFY serviceReadyChanged)
37
37
38public:
38public:
39 explicit DownloadTracker(QObject *parent = 0);
39 explicit DownloadTracker(QObject *parent = 0);
40
40
41 QString service() const;
41 QString service() const;
42 QString dbusPath() const;
42 QString dbusPath() const;
43+ bool isServiceReady() const;
43
44
44− void setDbusPath(QString& path);
45+ void setDbusPath(const QString& path);
45− void setService(QString& service);
46+ void setService(const QString& service);
46− bool isServiceReady();
47
47
48Q_SIGNALS:
48Q_SIGNALS:
49 void serviceChanged(const QString &service);
49 void serviceChanged(const QString &service);
50 void dbusPathChanged(const QString &dbusPath);
50 void dbusPathChanged(const QString &dbusPath);
51+ void serviceReadyChanged(const bool &serviceReady);
51
52
52 void canceled(bool success);
53 void canceled(bool success);
53 void error(const QString &error);
54 void error(const QString &error);