Merge lp:~mandel/ubuntu-download-manager/remove-q-pimpl into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 203
Merged at revision: 202
Proposed branch: lp:~mandel/ubuntu-download-manager/remove-q-pimpl
Merge into: lp:ubuntu-download-manager
Diff against target: 384 lines (+136/-192)
2 files modified
libubuntudownloadmanager/downloads/queue.cpp (+128/-186)
libubuntudownloadmanager/downloads/queue.h (+8/-6)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/remove-q-pimpl
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+198777@code.launchpad.net

Commit message

Remove the pimpl pattern from the Queue since it is a class not to be shared outside the project.

Description of the change

Remove the pimpl pattern from the Queue since it is a class not to be shared outside the project.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

Looks good.

This only things looks kind of odd to me:
288 + default:
289 + // do nothing
290 + break;
291 + }

But i understand that mmcc already said that was necessary for some reason in a previous branch.
Mike, if you can explain that please, i'll not block the branch for that if you requested it before.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntudownloadmanager/downloads/queue.cpp'
2--- libubuntudownloadmanager/downloads/queue.cpp 2013-11-25 14:46:52 +0000
3+++ libubuntudownloadmanager/downloads/queue.cpp 2013-12-12 16:41:39 +0000
4@@ -25,216 +25,158 @@
5
6 namespace DownloadManager {
7
8-/*
9- * PRIVATE IMPLEMENTATION
10- */
11-
12-class QueuePrivate {
13- Q_DECLARE_PUBLIC(Queue)
14-
15- public:
16- QueuePrivate(SystemNetworkInfo* networkInfo,
17- Queue* parent)
18- : _current(""),
19- _networkInfo(networkInfo),
20- q_ptr(parent) {
21- Q_Q(Queue);
22-
23- q->connect(_networkInfo,
24- SIGNAL(currentNetworkModeChanged(QNetworkInfo::NetworkMode)), q,
25- SLOT(onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode)));
26- }
27-
28- void add(Download* download) {
29- Q_Q(Queue);
30- // connect to the signals and append to the list
31- QString path = download->path();
32- TRACE << path;
33-
34- _sortedPaths.append(path);
35- _downloads[path] = download;
36-
37- q->connect(download, SIGNAL(stateChanged()),
38- q, SLOT(onDownloadStateChanged()));
39- emit q->downloadAdded(path);
40- }
41-
42- void remove(const QString& path) {
43- Q_Q(Queue);
44- TRACE << path;
45-
46- Download* down = _downloads[path];
47- _sortedPaths.removeOne(path);
48- _downloads.remove(path);
49-
50- down->deleteLater();
51- emit q->downloadRemoved(path);
52- }
53-
54- QString currentDownload() {
55- return _current;
56- }
57-
58- QStringList paths() {
59- return _sortedPaths;
60- }
61-
62- QHash<QString, Download*> downloads() {
63- QHash<QString, Download*> downloads;
64- foreach(const QString& path, _sortedPaths) {
65- downloads[path] = _downloads[path];
66- }
67- return downloads;
68- }
69-
70- int size() {
71- return _downloads.size();
72- }
73-
74- void onDownloadStateChanged() {
75- TRACE;
76- Q_Q(Queue);
77- // get the appdownload that emited the signal and
78- // decide what to do with it
79- Download* sender = qobject_cast<Download*>(q->sender());
80- switch (sender->state()) {
81- case Download::START:
82- // only start the download in the update method
83- if (_current.isEmpty())
84- updateCurrentDownload();
85- break;
86- case Download::PAUSE:
87- sender->pauseDownload();
88- if (!_current.isEmpty() && _current == sender->path())
89- updateCurrentDownload();
90- break;
91- case Download::RESUME:
92- // only resume the download in the update method
93- if (_current.isEmpty())
94- updateCurrentDownload();
95- break;
96- case Download::CANCEL:
97- // cancel and remove the download
98- sender->cancelDownload();
99- if (!_current.isEmpty() && _current == sender->path())
100- updateCurrentDownload();
101- else
102- remove(sender->path());
103- break;
104- case Download::ERROR:
105- case Download::FINISH:
106- // remove the registered object in dbus, remove the download
107- // and the adapter from the list
108- if (!_current.isEmpty() && _current == sender->path())
109- updateCurrentDownload();
110- break;
111- default:
112- // do nothing
113- break;
114- }
115- }
116-
117- void onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode mode) {
118- TRACE << mode;
119- if (mode != QNetworkInfo::UnknownMode) {
120- updateCurrentDownload();
121- }
122- }
123-
124- private:
125- void updateCurrentDownload() {
126- TRACE;
127- Q_Q(Queue);
128-
129- if (!_current.isEmpty()) {
130- // check if it was canceled/finished
131- Download* currentDownload = _downloads[_current];
132- Download::State state = currentDownload->state();
133- if (state == Download::CANCEL || state == Download::FINISH
134- || state == Download::ERROR) {
135- qDebug() << "State is CANCEL || FINISH || ERROR";
136- remove(_current);
137- _current = "";
138- } else if (!currentDownload->canDownload()
139- || state == Download::PAUSE) {
140- qDebug() << "States is Cannot Download || PAUSE";
141- _current = "";
142- } else {
143- return;
144- }
145- }
146-
147- // loop via the downloads and choose the first that is
148- // started or resumed
149- foreach(const QString& path, _sortedPaths) {
150- Download* down = _downloads[path];
151- Download::State state = down->state();
152- if (down->canDownload()
153- && (state == Download::START
154- || state == Download::RESUME)) {
155- _current = path;
156- if (state == Download::START)
157- down->startDownload();
158- else
159- down->resumeDownload();
160- break;
161- }
162- }
163-
164- emit q->currentChanged(_current);
165- }
166-
167- private:
168- QString _current;
169- QHash<QString, Download*> _downloads; // quick for access
170- QStringList _sortedPaths; // keep the order
171- SystemNetworkInfo* _networkInfo;
172- Queue* q_ptr;
173-};
174-
175-/*
176- * PUBLIC IMPLEMENTATION
177- */
178-
179 Queue::Queue(SystemNetworkInfo* networkInfo,
180 QObject* parent)
181 : QObject(parent),
182- d_ptr(new QueuePrivate(networkInfo, this)) {
183+ _current(""),
184+ _networkInfo(networkInfo) {
185+ connect(_networkInfo, &SystemNetworkInfo::currentNetworkModeChanged,
186+ this, &Queue::onCurrentNetworkModeChanged);
187 }
188
189 void
190 Queue::add(Download* download) {
191- Q_D(Queue);
192- d->add(download);
193+ // connect to the signals and append to the list
194+ QString path = download->path();
195+ TRACE << path;
196+
197+ _sortedPaths.append(path);
198+ _downloads[path] = download;
199+
200+ connect(download, &Download::stateChanged,
201+ this, &Queue::onDownloadStateChanged);
202+ emit downloadAdded(path);
203+}
204+
205+void
206+Queue::remove(const QString& path) {
207+ TRACE << path;
208+
209+ Download* down = _downloads[path];
210+ _sortedPaths.removeOne(path);
211+ _downloads.remove(path);
212+
213+ down->deleteLater();
214+ emit downloadRemoved(path);
215 }
216
217 QString
218 Queue::currentDownload() {
219- Q_D(Queue);
220- return d->currentDownload();
221+ return _current;
222 }
223
224 QStringList
225 Queue::paths() {
226- Q_D(Queue);
227- return d->paths();
228+ return _sortedPaths;
229 }
230
231-
232 QHash<QString, Download*>
233 Queue::downloads() {
234- Q_D(Queue);
235- return d->downloads();
236+ QHash<QString, Download*> downloads;
237+ foreach(const QString& path, _sortedPaths) {
238+ downloads[path] = _downloads[path];
239+ }
240+ return downloads;
241 }
242
243 int
244 Queue::size() {
245- Q_D(Queue);
246- return d->size();
247-}
248+ return _downloads.size();
249+}
250+
251+void
252+Queue::onDownloadStateChanged() {
253+ TRACE;
254+ // get the appdownload that emited the signal and
255+ // decide what to do with it
256+ Download* down = qobject_cast<Download*>(sender());
257+ switch (down->state()) {
258+ case Download::START:
259+ // only start the download in the update method
260+ if (_current.isEmpty())
261+ updateCurrentDownload();
262+ break;
263+ case Download::PAUSE:
264+ down->pauseDownload();
265+ if (!_current.isEmpty() && _current == down->path())
266+ updateCurrentDownload();
267+ break;
268+ case Download::RESUME:
269+ // only resume the download in the update method
270+ if (_current.isEmpty())
271+ updateCurrentDownload();
272+ break;
273+ case Download::CANCEL:
274+ // cancel and remove the download
275+ down->cancelDownload();
276+ if (!_current.isEmpty() && _current == down->path())
277+ updateCurrentDownload();
278+ else
279+ remove(down->path());
280+ break;
281+ case Download::ERROR:
282+ case Download::FINISH:
283+ // remove the registered object in dbus, remove the download
284+ // and the adapter from the list
285+ if (!_current.isEmpty() && _current == down->path())
286+ updateCurrentDownload();
287+ break;
288+ default:
289+ // do nothing
290+ break;
291+ }
292+}
293+
294+void
295+Queue::onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode mode) {
296+ TRACE << mode;
297+ if (mode != QNetworkInfo::UnknownMode) {
298+ updateCurrentDownload();
299+ }
300+}
301+
302+void
303+Queue::updateCurrentDownload() {
304+ TRACE;
305+ if (!_current.isEmpty()) {
306+ // check if it was canceled/finished
307+ Download* currentDownload = _downloads[_current];
308+ Download::State state = currentDownload->state();
309+ if (state == Download::CANCEL || state == Download::FINISH
310+ || state == Download::ERROR) {
311+ qDebug() << "State is CANCEL || FINISH || ERROR";
312+ remove(_current);
313+ _current = "";
314+ } else if (!currentDownload->canDownload()
315+ || state == Download::PAUSE) {
316+ qDebug() << "States is Cannot Download || PAUSE";
317+ _current = "";
318+ } else {
319+ return;
320+ }
321+ }
322+
323+ // loop via the downloads and choose the first that is
324+ // started or resumed
325+ foreach(const QString& path, _sortedPaths) {
326+ Download* down = _downloads[path];
327+ Download::State state = down->state();
328+ if (down->canDownload()
329+ && (state == Download::START
330+ || state == Download::RESUME)) {
331+ _current = path;
332+ if (state == Download::START)
333+ down->startDownload();
334+ else
335+ down->resumeDownload();
336+ break;
337+ }
338+ }
339+
340+ emit currentChanged(_current);
341+}
342+
343
344 } // DownloadManager
345
346 } // Ubuntu
347-
348-#include "moc_queue.cpp"
349
350=== modified file 'libubuntudownloadmanager/downloads/queue.h'
351--- libubuntudownloadmanager/downloads/queue.h 2013-11-25 14:46:52 +0000
352+++ libubuntudownloadmanager/downloads/queue.h 2013-12-12 16:41:39 +0000
353@@ -32,10 +32,8 @@
354
355 using namespace System;
356
357-class QueuePrivate;
358 class Queue : public QObject {
359 Q_OBJECT
360- Q_DECLARE_PRIVATE(Queue)
361
362 public:
363 explicit Queue(SystemNetworkInfo* networkInfo,
364@@ -56,12 +54,16 @@
365 void downloadRemoved(QString path);
366
367 private:
368- Q_PRIVATE_SLOT(d_func(), void onDownloadStateChanged())
369- Q_PRIVATE_SLOT(d_func(),
370- void onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode mode))
371+ void onDownloadStateChanged();
372+ void onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode mode);
373+ void remove(const QString& path);
374+ void updateCurrentDownload();
375
376 private:
377- QueuePrivate* d_ptr;
378+ QString _current;
379+ QHash<QString, Download*> _downloads; // quick for access
380+ QStringList _sortedPaths; // keep the order
381+ SystemNetworkInfo* _networkInfo;
382 };
383
384 } // DownloadManager

Subscribers

People subscribed via source and target branches