Merge lp:~fboucault/bamf-qt/bamf-qt-crashfix702566 into lp:bamf-qt

Proposed by Florian Boucault
Status: Merged
Approved by: Ugo Riboni
Approved revision: 365
Merged at revision: 368
Proposed branch: lp:~fboucault/bamf-qt/bamf-qt-crashfix702566
Merge into: lp:bamf-qt
Diff against target: 416 lines (+241/-16)
10 files modified
CMakeLists.txt (+4/-0)
bamf-application.cpp (+12/-3)
bamf-factory.cpp (+3/-3)
bamf-indicator-proxy.cpp (+26/-0)
bamf-indicator-proxy.h (+61/-0)
bamf-indicator.cpp (+62/-0)
bamf-indicator.h (+55/-0)
bamf-matcher.cpp (+15/-9)
bamf-plugin.cpp (+2/-0)
bamf-window.cpp (+1/-1)
To merge this branch: bzr merge lp:~fboucault/bamf-qt/bamf-qt-crashfix702566
Reviewer Review Type Date Requested Status
Ugo Riboni Pending
Review via email: mp+46439@code.launchpad.net

Description of the change

Added support for indicators (new BamfIndicator class).
Added safeguards for when BamfFactory::view_for_path returns NULL.
Replaced static_cast with qobject_cast for values returned from BamfFactory::view_for_path thus avoiding enforcing wrong casts.

To post a comment you must log in.
Revision history for this message
Florian Boucault (fboucault) wrote :

From Ugo Riboni's previous review:

"""
Functionally it does its job, the crash disappears.

However I don't exactly understand *why* this MR fixes the issue, so I'm not sure I'm the most qualified to review this. Or perhaps some more comments in the code are in order ?

Anyway, please fix the (mostly style) issues below:

* The methods Address and Path in BamfIndicator should return QString() when failing, instead of NULL.
* In the BamfIndicator constructor, please align the arguments on the same line. The same for OnActiveApplicationChanged and OnActiveWindowChanged in BamfMatcher
"""

Revision history for this message
Florian Boucault (fboucault) wrote :

The why this MR fixes the issue is two-folds:
1) using static cast is wrong; a dynamic cast needs to be used so that if the cast fails a NULL pointer is returned. qobject_cast does the same but is smarter about other things.
2) the MR adds NULL pointer checks in relevant places

364. By Florian Boucault

Methods Address and Path in BamfIndicator now return QString() when failing, instead of NULL.

365. By Florian Boucault

Fixed indentation.

Revision history for this message
Florian Boucault (fboucault) wrote :

The 2 stylistic issues raised are now fixed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2011-01-13 17:57:36 +0000
3+++ CMakeLists.txt 2011-01-17 04:32:10 +0000
4@@ -13,6 +13,8 @@
5 bamf-control.cpp
6 bamf-control-proxy.cpp
7 bamf-factory.cpp
8+ bamf-indicator.cpp
9+ bamf-indicator-proxy.cpp
10 bamf-matcher.cpp
11 bamf-matcher-proxy.cpp
12 bamf-view.cpp
13@@ -27,6 +29,8 @@
14 bamf-control.h
15 bamf-control-proxy.h
16 bamf-factory.h
17+ bamf-indicator.h
18+ bamf-indicator-proxy.h
19 bamf-list.h
20 bamf-matcher.h
21 bamf-matcher-proxy.h
22
23=== modified file 'bamf-application.cpp'
24--- bamf-application.cpp 2010-12-21 09:56:42 +0000
25+++ bamf-application.cpp 2011-01-17 04:32:10 +0000
26@@ -85,7 +85,10 @@
27 BamfViewList *children = this->children();
28 for(int i = 0; i < children->size(); ++i)
29 {
30- result.prepend(static_cast<BamfWindow *>(children->at(i)));
31+ BamfWindow* window = qobject_cast<BamfWindow *>(children->at(i));
32+ if (window != NULL) {
33+ result.prepend(window);
34+ }
35 }
36 delete children;
37 return new BamfWindowList(result);
38@@ -95,13 +98,19 @@
39 BamfApplication::OnWindowAdded(const QString &path)
40 {
41 BamfView *view = BamfFactory::get_default().view_for_path(path);
42- WindowAdded(static_cast<BamfWindow *>(view));
43+ BamfWindow* window = qobject_cast<BamfWindow *>(view);
44+ if (window != NULL) {
45+ WindowAdded(window);
46+ }
47 }
48
49 void
50 BamfApplication::OnWindowRemoved(const QString &path)
51 {
52 BamfView *view = BamfFactory::get_default().view_for_path(path);
53- WindowRemoved(static_cast<BamfWindow *>(view));
54+ BamfWindow* window = qobject_cast<BamfWindow *>(view);
55+ if (window != NULL) {
56+ WindowRemoved(window);
57+ }
58 }
59
60
61=== modified file 'bamf-factory.cpp'
62--- bamf-factory.cpp 2010-12-21 09:56:42 +0000
63+++ bamf-factory.cpp 2011-01-17 04:32:10 +0000
64@@ -22,7 +22,7 @@
65 #include "bamf-view.h"
66 #include "bamf-application.h"
67 #include "bamf-window.h"
68-//#include "bamf-indicator.h"
69+#include "bamf-indicator.h"
70
71 BamfFactory::BamfFactory() :
72 m_views(NULL)
73@@ -48,8 +48,8 @@
74 view = static_cast<BamfView *>(new BamfApplication(path));
75 else if (type == "window")
76 view = static_cast<BamfView *>(new BamfWindow(path));
77- //else if (type == "indicator")
78- // view = static_cast<BamfView *>(new BamfIndicator(path));
79+ else if (type == "indicator")
80+ view = static_cast<BamfView *>(new BamfIndicator(path));
81
82 if (view != NULL)
83 {
84
85=== added file 'bamf-indicator-proxy.cpp'
86--- bamf-indicator-proxy.cpp 1970-01-01 00:00:00 +0000
87+++ bamf-indicator-proxy.cpp 2011-01-17 04:32:10 +0000
88@@ -0,0 +1,26 @@
89+/*
90+ * This file was generated by qdbusxml2cpp version 0.7
91+ * Command line was: qdbusxml2cpp bamf-indicator-glue.xml -p bamf-indicator-proxy
92+ *
93+ * qdbusxml2cpp is Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
94+ *
95+ * This is an auto-generated file.
96+ * This file may have been hand-edited. Look for HAND-EDIT comments
97+ * before re-generating it.
98+ */
99+
100+#include "bamf-indicator-proxy.h"
101+
102+/*
103+ * Implementation of interface class OrgAyatanaBamfIndicatorInterface
104+ */
105+
106+OrgAyatanaBamfIndicatorInterface::OrgAyatanaBamfIndicatorInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
107+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
108+{
109+}
110+
111+OrgAyatanaBamfIndicatorInterface::~OrgAyatanaBamfIndicatorInterface()
112+{
113+}
114+
115
116=== added file 'bamf-indicator-proxy.h'
117--- bamf-indicator-proxy.h 1970-01-01 00:00:00 +0000
118+++ bamf-indicator-proxy.h 2011-01-17 04:32:10 +0000
119@@ -0,0 +1,61 @@
120+/*
121+ * This file was generated by qdbusxml2cpp version 0.7
122+ * Command line was: qdbusxml2cpp bamf-indicator-glue.xml -p bamf-indicator-proxy
123+ *
124+ * qdbusxml2cpp is Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
125+ *
126+ * This is an auto-generated file.
127+ * Do not edit! All changes made to it will be lost.
128+ */
129+
130+#ifndef BAMF-INDICATOR-PROXY_H_1294953124
131+#define BAMF-INDICATOR-PROXY_H_1294953124
132+
133+#include <QtCore/QObject>
134+#include <QtCore/QByteArray>
135+#include <QtCore/QList>
136+#include <QtCore/QMap>
137+#include <QtCore/QString>
138+#include <QtCore/QStringList>
139+#include <QtCore/QVariant>
140+#include <QtDBus/QtDBus>
141+
142+/*
143+ * Proxy class for interface org.ayatana.bamf.indicator
144+ */
145+class OrgAyatanaBamfIndicatorInterface: public QDBusAbstractInterface
146+{
147+ Q_OBJECT
148+public:
149+ static inline const char *staticInterfaceName()
150+ { return "org.ayatana.bamf.indicator"; }
151+
152+public:
153+ OrgAyatanaBamfIndicatorInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
154+
155+ ~OrgAyatanaBamfIndicatorInterface();
156+
157+public Q_SLOTS: // METHODS
158+ inline QDBusPendingReply<QString> Address()
159+ {
160+ QList<QVariant> argumentList;
161+ return asyncCallWithArgumentList(QLatin1String("Address"), argumentList);
162+ }
163+
164+ inline QDBusPendingReply<QString> Path()
165+ {
166+ QList<QVariant> argumentList;
167+ return asyncCallWithArgumentList(QLatin1String("Path"), argumentList);
168+ }
169+
170+Q_SIGNALS: // SIGNALS
171+};
172+
173+namespace org {
174+ namespace ayatana {
175+ namespace bamf {
176+ typedef ::OrgAyatanaBamfIndicatorInterface indicator;
177+ }
178+ }
179+}
180+#endif
181
182=== added file 'bamf-indicator.cpp'
183--- bamf-indicator.cpp 1970-01-01 00:00:00 +0000
184+++ bamf-indicator.cpp 2011-01-17 04:32:10 +0000
185@@ -0,0 +1,62 @@
186+/*
187+ * Copyright (C) 2010 Canonical, Ltd.
188+ *
189+ * Authors:
190+ * Olivier Tilloy <olivier.tilloy@canonical.com>
191+ *
192+ * This library is free software; you can redistribute it and/or modify
193+ * it under the terms of the GNU Lesser General Public License
194+ * as published by the Free Software Foundation; version 3.
195+ *
196+ * This library is distributed in the hope that it will be useful,
197+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
198+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
199+ * GNU Lesser General Public License for more details.
200+ *
201+ * You should have received a copy of the GNU Lesser General Public
202+ * License along with this program. If not, see
203+ * <http://www.gnu.org/licenses/>.
204+ */
205+
206+#include "bamf-indicator.h"
207+#include "bamf-indicator-proxy.h"
208+#include "bamf-factory.h"
209+
210+BamfIndicator::BamfIndicator(QString path) :
211+ BamfView(path), m_indicator_proxy(NULL)
212+{
213+ m_indicator_proxy = new OrgAyatanaBamfIndicatorInterface("org.ayatana.bamf", path,
214+ QDBusConnection::sessionBus(),
215+ static_cast<QObject*>(this));
216+}
217+
218+BamfIndicator::~BamfIndicator()
219+{
220+ delete m_indicator_proxy;
221+}
222+
223+const QString
224+BamfIndicator::address() const
225+{
226+ QDBusPendingReply<QString> reply = m_indicator_proxy->Address();
227+ reply.waitForFinished();
228+ if (reply.isError()) {
229+ qWarning() << reply.error();
230+ return QString();
231+ } else {
232+ return reply.value();
233+ }
234+}
235+
236+const QString
237+BamfIndicator::path() const
238+{
239+ QDBusPendingReply<QString> reply = m_indicator_proxy->Path();
240+ reply.waitForFinished();
241+ if (reply.isError()) {
242+ qWarning() << reply.error();
243+ return QString();
244+ } else {
245+ return reply.value();
246+ }
247+}
248
249=== added file 'bamf-indicator.h'
250--- bamf-indicator.h 1970-01-01 00:00:00 +0000
251+++ bamf-indicator.h 2011-01-17 04:32:10 +0000
252@@ -0,0 +1,55 @@
253+/*
254+ * Copyright (C) 2010 Canonical, Ltd.
255+ *
256+ * Authors:
257+ * Florian Boucault <florian.boucault@canonical.com>
258+ *
259+ * This library is free software; you can redistribute it and/or modify
260+ * it under the terms of the GNU Lesser General Public License
261+ * as published by the Free Software Foundation; version 3.
262+ *
263+ * This library is distributed in the hope that it will be useful,
264+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
265+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
266+ * GNU Lesser General Public License for more details.
267+ *
268+ * You should have received a copy of the GNU Lesser General Public
269+ * License along with this program. If not, see
270+ * <http://www.gnu.org/licenses/>.
271+ */
272+
273+#ifndef QT_BAMF_INDICATOR_H
274+#define QT_BAMF_INDICATOR_H
275+
276+#include <QtCore/QObject>
277+
278+#include "bamf-view.h"
279+
280+class OrgAyatanaBamfIndicatorInterface;
281+
282+class BamfIndicator: public BamfView
283+{
284+ Q_OBJECT
285+
286+ Q_PROPERTY(QString address READ address);
287+ Q_PROPERTY(QString path READ path);
288+
289+friend class BamfFactory;
290+
291+private:
292+ BamfIndicator(QString path);
293+ ~BamfIndicator();
294+ BamfIndicator(BamfIndicator const&);
295+ void operator=(BamfIndicator const&);
296+
297+public:
298+ // getters
299+ const QString address() const;
300+ const QString path() const;
301+
302+private:
303+ OrgAyatanaBamfIndicatorInterface *m_indicator_proxy;
304+};
305+
306+#endif
307+
308
309=== modified file 'bamf-matcher.cpp'
310--- bamf-matcher.cpp 2010-12-21 09:56:42 +0000
311+++ bamf-matcher.cpp 2011-01-17 04:32:10 +0000
312@@ -62,7 +62,7 @@
313 return NULL;
314
315 BamfView *view = BamfFactory::get_default().view_for_path(path);
316- return static_cast<BamfApplication *>(view);
317+ return qobject_cast<BamfApplication *>(view);
318 }
319 }
320
321@@ -80,7 +80,7 @@
322 return NULL;
323
324 BamfView *view = BamfFactory::get_default().view_for_path(path);
325- return static_cast<BamfWindow *>(view);
326+ return qobject_cast<BamfWindow *>(view);
327 }
328 }
329
330@@ -98,7 +98,7 @@
331 return NULL;
332
333 BamfView *view = BamfFactory::get_default().view_for_path(path);
334- return static_cast<BamfApplication *>(view);
335+ return qobject_cast<BamfApplication *>(view);
336 }
337 }
338
339@@ -127,7 +127,10 @@
340 QStringList list = reply.value();
341 for (int i = 0; i < list.size(); ++i) {
342 BamfView *view = BamfFactory::get_default().view_for_path(list.at(i));
343- result.prepend(static_cast<BamfApplication *>(view));
344+ BamfApplication* application = qobject_cast<BamfApplication *>(view);
345+ if (application != NULL) {
346+ result.prepend(application);
347+ }
348 }
349 }
350 return new BamfApplicationList(result);
351@@ -145,7 +148,10 @@
352 QStringList list = reply.value();
353 for (int i = 0; i < list.size(); ++i) {
354 BamfView *view = BamfFactory::get_default().view_for_path(list.at(i));
355- result.prepend(static_cast<BamfApplication *>(view));
356+ BamfApplication* application = qobject_cast<BamfApplication *>(view);
357+ if (application != NULL) {
358+ result.prepend(application);
359+ }
360 }
361 }
362 return new BamfApplicationList(result);
363@@ -156,8 +162,8 @@
364 {
365 BamfView *former = BamfFactory::get_default().view_for_path(old_active);
366 BamfView *current = BamfFactory::get_default().view_for_path(new_active);
367- ActiveApplicationChanged(static_cast<BamfApplication *>(former),
368- static_cast<BamfApplication *>(current));
369+ ActiveApplicationChanged(qobject_cast<BamfApplication *>(former),
370+ qobject_cast<BamfApplication *>(current));
371 }
372
373 void
374@@ -165,8 +171,8 @@
375 {
376 BamfView *former = BamfFactory::get_default().view_for_path(old_active);
377 BamfView *current = BamfFactory::get_default().view_for_path(new_active);
378- ActiveWindowChanged(static_cast<BamfWindow *>(former),
379- static_cast<BamfWindow *>(current));
380+ ActiveWindowChanged(qobject_cast<BamfWindow *>(former),
381+ qobject_cast<BamfWindow *>(current));
382 }
383
384 void
385
386=== modified file 'bamf-plugin.cpp'
387--- bamf-plugin.cpp 2011-01-13 17:57:36 +0000
388+++ bamf-plugin.cpp 2011-01-17 04:32:10 +0000
389@@ -27,6 +27,7 @@
390 #include "bamf-view.h"
391 #include "bamf-application.h"
392 #include "bamf-window.h"
393+#include "bamf-indicator.h"
394 #include "bamf-control.h"
395 #include "bamf-matcher.h"
396
397@@ -42,6 +43,7 @@
398 qmlRegisterUncreatableType<BamfApplication>(uri, 0, 2, "BamfApplication", message);
399 qmlRegisterUncreatableType<BamfApplicationList>(uri, 0, 2, "BamfApplicationList", message);
400 qmlRegisterUncreatableType<BamfWindow>(uri, 0, 2, "BamfWindow", message);
401+ qmlRegisterUncreatableType<BamfIndicator>(uri, 0, 2, "BamfIndicator", message);
402 qmlRegisterUncreatableType<BamfWindowList>(uri, 0, 2, "BamfWindowList", message);
403 qmlRegisterUncreatableType<BamfControl>(uri, 0, 2, "BamfControl", message);
404 qmlRegisterUncreatableType<BamfMatcher>(uri, 0, 2, "BamfMatcher", message);
405
406=== modified file 'bamf-window.cpp'
407--- bamf-window.cpp 2010-12-21 09:56:42 +0000
408+++ bamf-window.cpp 2011-01-17 04:32:10 +0000
409@@ -47,7 +47,7 @@
410 return NULL;
411 } else {
412 BamfView *view = BamfFactory::get_default().view_for_path(reply.value());
413- return static_cast<BamfWindow *>(view);
414+ return qobject_cast<BamfWindow *>(view);
415 }
416 }
417

Subscribers

People subscribed via source and target branches

to all changes: