Merge lp:~mandel/ubuntu-download-manager/emit-finish into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Merged at revision: 79
Proposed branch: lp:~mandel/ubuntu-download-manager/emit-finish
Merge into: lp:ubuntu-download-manager
Diff against target: 108 lines (+35/-4)
2 files modified
libubuntudownloadmanager/download_queue.cpp (+34/-4)
libubuntudownloadmanager/download_queue.h (+1/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/emit-finish
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+176047@code.launchpad.net

Commit message

Connect to the destroyed signal to ensure that all signals are emitted BEFORE we remove the object from DBus.

Description of the change

Connect to the destroyed signal to ensure that all signals are emitted BEFORE we remove the object from DBus.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntudownloadmanager/download_queue.cpp'
2--- libubuntudownloadmanager/download_queue.cpp 2013-07-20 15:53:38 +0000
3+++ libubuntudownloadmanager/download_queue.cpp 2013-07-21 10:55:28 +0000
4@@ -16,6 +16,8 @@
5 * Boston, MA 02110-1301, USA.
6 */
7
8+#include <QDebug>
9+#include <QSignalMapper>
10 #include "download_queue.h"
11
12 /*
13@@ -28,6 +30,7 @@
14 Q_DECLARE_PUBLIC(DownloadQueue)
15 public:
16 explicit DownloadQueuePrivate(SystemNetworkInfo* networkInfo, DownloadQueue* parent);
17+ ~DownloadQueuePrivate();
18
19 void add(Download* download, DownloadAdaptor* adaptor);
20 void add(const QPair<Download*, DownloadAdaptor*>& value);
21@@ -38,12 +41,14 @@
22 QHash<QString, Download*> downloads();
23
24 void onDownloadStateChanged();
25+ void onDestroyed(const QString& path);
26 void onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode mode);
27
28 private:
29 void updateCurrentDownload();
30
31 private:
32+ QSignalMapper* _mapper;
33 QString _current;
34 DownloadList _downloads; // quick for access
35 QStringList _sortedPaths; // keep the order in witch the downloads have been added
36@@ -57,8 +62,19 @@
37 q_ptr(parent)
38 {
39 Q_Q(DownloadQueue);
40+ _mapper = new QSignalMapper();
41+
42 q->connect(_networkInfo, SIGNAL(currentNetworkModeChanged(QNetworkInfo::NetworkMode)),
43 q, SLOT(onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode)));
44+
45+ q->connect(_mapper, SIGNAL(mapped(const QString&)),
46+ q, SLOT(onDestroyed(const QString&)));
47+}
48+
49+DownloadQueuePrivate::~DownloadQueuePrivate()
50+{
51+ if (_mapper != NULL)
52+ delete _mapper;
53 }
54
55 void DownloadQueuePrivate::add(Download* download, DownloadAdaptor* adaptor)
56@@ -82,15 +98,22 @@
57
58 void DownloadQueuePrivate::remove(const QString& path)
59 {
60+ qDebug() << __FUNCTION__ << path;
61+
62 Q_Q(DownloadQueue);
63+
64 QPair<Download*, DownloadAdaptor*> pair = _downloads[path];
65- pair.first->deleteLater();
66- pair.second->deleteLater();
67 _sortedPaths.removeOne(path);
68 _downloads.remove(path);
69
70- // emit the signal that it was removed
71- emit q->downloadRemoved(path);
72+ // connect to the adaptor destroyed event to ensure that we have emitted all signals, else
73+ // we might have a race condition where the object path is removed from dbus to early
74+ q->connect(pair.second, SIGNAL(destroyed(QObject*)),
75+ _mapper, SLOT(map(QObject*)));
76+ _mapper->setMapping(pair.first, path);
77+
78+ pair.second->deleteLater();
79+ pair.first->deleteLater();
80 }
81
82 QString DownloadQueuePrivate::currentDownload()
83@@ -154,6 +177,13 @@
84 }
85 }
86
87+void DownloadQueuePrivate::onDestroyed(const QString &path)
88+{
89+ qDebug() << __FUNCTION__;
90+ Q_Q(DownloadQueue);
91+ emit q->downloadRemoved(path);
92+}
93+
94 void DownloadQueuePrivate::onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode mode)
95 {
96 Q_UNUSED(mode);
97
98=== modified file 'libubuntudownloadmanager/download_queue.h'
99--- libubuntudownloadmanager/download_queue.h 2013-07-12 10:45:37 +0000
100+++ libubuntudownloadmanager/download_queue.h 2013-07-21 10:55:28 +0000
101@@ -49,6 +49,7 @@
102
103 private:
104 Q_PRIVATE_SLOT(d_func(), void onDownloadStateChanged())
105+ Q_PRIVATE_SLOT(d_func(), void onDestroyed(const QString& path))
106 Q_PRIVATE_SLOT(d_func(), void onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode mode))
107
108 private:

Subscribers

People subscribed via source and target branches