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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2011-01-13 17:57:36 +0000
+++ CMakeLists.txt 2011-01-17 04:32:10 +0000
@@ -13,6 +13,8 @@
13 bamf-control.cpp13 bamf-control.cpp
14 bamf-control-proxy.cpp14 bamf-control-proxy.cpp
15 bamf-factory.cpp15 bamf-factory.cpp
16 bamf-indicator.cpp
17 bamf-indicator-proxy.cpp
16 bamf-matcher.cpp18 bamf-matcher.cpp
17 bamf-matcher-proxy.cpp19 bamf-matcher-proxy.cpp
18 bamf-view.cpp20 bamf-view.cpp
@@ -27,6 +29,8 @@
27 bamf-control.h29 bamf-control.h
28 bamf-control-proxy.h30 bamf-control-proxy.h
29 bamf-factory.h31 bamf-factory.h
32 bamf-indicator.h
33 bamf-indicator-proxy.h
30 bamf-list.h34 bamf-list.h
31 bamf-matcher.h35 bamf-matcher.h
32 bamf-matcher-proxy.h36 bamf-matcher-proxy.h
3337
=== modified file 'bamf-application.cpp'
--- bamf-application.cpp 2010-12-21 09:56:42 +0000
+++ bamf-application.cpp 2011-01-17 04:32:10 +0000
@@ -85,7 +85,10 @@
85 BamfViewList *children = this->children();85 BamfViewList *children = this->children();
86 for(int i = 0; i < children->size(); ++i)86 for(int i = 0; i < children->size(); ++i)
87 {87 {
88 result.prepend(static_cast<BamfWindow *>(children->at(i)));88 BamfWindow* window = qobject_cast<BamfWindow *>(children->at(i));
89 if (window != NULL) {
90 result.prepend(window);
91 }
89 }92 }
90 delete children;93 delete children;
91 return new BamfWindowList(result);94 return new BamfWindowList(result);
@@ -95,13 +98,19 @@
95BamfApplication::OnWindowAdded(const QString &path)98BamfApplication::OnWindowAdded(const QString &path)
96{99{
97 BamfView *view = BamfFactory::get_default().view_for_path(path);100 BamfView *view = BamfFactory::get_default().view_for_path(path);
98 WindowAdded(static_cast<BamfWindow *>(view));101 BamfWindow* window = qobject_cast<BamfWindow *>(view);
102 if (window != NULL) {
103 WindowAdded(window);
104 }
99}105}
100106
101void107void
102BamfApplication::OnWindowRemoved(const QString &path)108BamfApplication::OnWindowRemoved(const QString &path)
103{109{
104 BamfView *view = BamfFactory::get_default().view_for_path(path);110 BamfView *view = BamfFactory::get_default().view_for_path(path);
105 WindowRemoved(static_cast<BamfWindow *>(view));111 BamfWindow* window = qobject_cast<BamfWindow *>(view);
112 if (window != NULL) {
113 WindowRemoved(window);
114 }
106}115}
107116
108117
=== modified file 'bamf-factory.cpp'
--- bamf-factory.cpp 2010-12-21 09:56:42 +0000
+++ bamf-factory.cpp 2011-01-17 04:32:10 +0000
@@ -22,7 +22,7 @@
22#include "bamf-view.h"22#include "bamf-view.h"
23#include "bamf-application.h"23#include "bamf-application.h"
24#include "bamf-window.h"24#include "bamf-window.h"
25//#include "bamf-indicator.h"25#include "bamf-indicator.h"
2626
27BamfFactory::BamfFactory() :27BamfFactory::BamfFactory() :
28 m_views(NULL)28 m_views(NULL)
@@ -48,8 +48,8 @@
48 view = static_cast<BamfView *>(new BamfApplication(path));48 view = static_cast<BamfView *>(new BamfApplication(path));
49 else if (type == "window")49 else if (type == "window")
50 view = static_cast<BamfView *>(new BamfWindow(path));50 view = static_cast<BamfView *>(new BamfWindow(path));
51 //else if (type == "indicator")51 else if (type == "indicator")
52 // view = static_cast<BamfView *>(new BamfIndicator(path));52 view = static_cast<BamfView *>(new BamfIndicator(path));
5353
54 if (view != NULL)54 if (view != NULL)
55 {55 {
5656
=== added file 'bamf-indicator-proxy.cpp'
--- bamf-indicator-proxy.cpp 1970-01-01 00:00:00 +0000
+++ bamf-indicator-proxy.cpp 2011-01-17 04:32:10 +0000
@@ -0,0 +1,26 @@
1/*
2 * This file was generated by qdbusxml2cpp version 0.7
3 * Command line was: qdbusxml2cpp bamf-indicator-glue.xml -p bamf-indicator-proxy
4 *
5 * qdbusxml2cpp is Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 *
7 * This is an auto-generated file.
8 * This file may have been hand-edited. Look for HAND-EDIT comments
9 * before re-generating it.
10 */
11
12#include "bamf-indicator-proxy.h"
13
14/*
15 * Implementation of interface class OrgAyatanaBamfIndicatorInterface
16 */
17
18OrgAyatanaBamfIndicatorInterface::OrgAyatanaBamfIndicatorInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
19 : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
20{
21}
22
23OrgAyatanaBamfIndicatorInterface::~OrgAyatanaBamfIndicatorInterface()
24{
25}
26
027
=== added file 'bamf-indicator-proxy.h'
--- bamf-indicator-proxy.h 1970-01-01 00:00:00 +0000
+++ bamf-indicator-proxy.h 2011-01-17 04:32:10 +0000
@@ -0,0 +1,61 @@
1/*
2 * This file was generated by qdbusxml2cpp version 0.7
3 * Command line was: qdbusxml2cpp bamf-indicator-glue.xml -p bamf-indicator-proxy
4 *
5 * qdbusxml2cpp is Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 *
7 * This is an auto-generated file.
8 * Do not edit! All changes made to it will be lost.
9 */
10
11#ifndef BAMF-INDICATOR-PROXY_H_1294953124
12#define BAMF-INDICATOR-PROXY_H_1294953124
13
14#include <QtCore/QObject>
15#include <QtCore/QByteArray>
16#include <QtCore/QList>
17#include <QtCore/QMap>
18#include <QtCore/QString>
19#include <QtCore/QStringList>
20#include <QtCore/QVariant>
21#include <QtDBus/QtDBus>
22
23/*
24 * Proxy class for interface org.ayatana.bamf.indicator
25 */
26class OrgAyatanaBamfIndicatorInterface: public QDBusAbstractInterface
27{
28 Q_OBJECT
29public:
30 static inline const char *staticInterfaceName()
31 { return "org.ayatana.bamf.indicator"; }
32
33public:
34 OrgAyatanaBamfIndicatorInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
35
36 ~OrgAyatanaBamfIndicatorInterface();
37
38public Q_SLOTS: // METHODS
39 inline QDBusPendingReply<QString> Address()
40 {
41 QList<QVariant> argumentList;
42 return asyncCallWithArgumentList(QLatin1String("Address"), argumentList);
43 }
44
45 inline QDBusPendingReply<QString> Path()
46 {
47 QList<QVariant> argumentList;
48 return asyncCallWithArgumentList(QLatin1String("Path"), argumentList);
49 }
50
51Q_SIGNALS: // SIGNALS
52};
53
54namespace org {
55 namespace ayatana {
56 namespace bamf {
57 typedef ::OrgAyatanaBamfIndicatorInterface indicator;
58 }
59 }
60}
61#endif
062
=== added file 'bamf-indicator.cpp'
--- bamf-indicator.cpp 1970-01-01 00:00:00 +0000
+++ bamf-indicator.cpp 2011-01-17 04:32:10 +0000
@@ -0,0 +1,62 @@
1/*
2 * Copyright (C) 2010 Canonical, Ltd.
3 *
4 * Authors:
5 * Olivier Tilloy <olivier.tilloy@canonical.com>
6 *
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; version 3.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
21#include "bamf-indicator.h"
22#include "bamf-indicator-proxy.h"
23#include "bamf-factory.h"
24
25BamfIndicator::BamfIndicator(QString path) :
26 BamfView(path), m_indicator_proxy(NULL)
27{
28 m_indicator_proxy = new OrgAyatanaBamfIndicatorInterface("org.ayatana.bamf", path,
29 QDBusConnection::sessionBus(),
30 static_cast<QObject*>(this));
31}
32
33BamfIndicator::~BamfIndicator()
34{
35 delete m_indicator_proxy;
36}
37
38const QString
39BamfIndicator::address() const
40{
41 QDBusPendingReply<QString> reply = m_indicator_proxy->Address();
42 reply.waitForFinished();
43 if (reply.isError()) {
44 qWarning() << reply.error();
45 return QString();
46 } else {
47 return reply.value();
48 }
49}
50
51const QString
52BamfIndicator::path() const
53{
54 QDBusPendingReply<QString> reply = m_indicator_proxy->Path();
55 reply.waitForFinished();
56 if (reply.isError()) {
57 qWarning() << reply.error();
58 return QString();
59 } else {
60 return reply.value();
61 }
62}
063
=== added file 'bamf-indicator.h'
--- bamf-indicator.h 1970-01-01 00:00:00 +0000
+++ bamf-indicator.h 2011-01-17 04:32:10 +0000
@@ -0,0 +1,55 @@
1/*
2 * Copyright (C) 2010 Canonical, Ltd.
3 *
4 * Authors:
5 * Florian Boucault <florian.boucault@canonical.com>
6 *
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; version 3.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef QT_BAMF_INDICATOR_H
22#define QT_BAMF_INDICATOR_H
23
24#include <QtCore/QObject>
25
26#include "bamf-view.h"
27
28class OrgAyatanaBamfIndicatorInterface;
29
30class BamfIndicator: public BamfView
31{
32 Q_OBJECT
33
34 Q_PROPERTY(QString address READ address);
35 Q_PROPERTY(QString path READ path);
36
37friend class BamfFactory;
38
39private:
40 BamfIndicator(QString path);
41 ~BamfIndicator();
42 BamfIndicator(BamfIndicator const&);
43 void operator=(BamfIndicator const&);
44
45public:
46 // getters
47 const QString address() const;
48 const QString path() const;
49
50private:
51 OrgAyatanaBamfIndicatorInterface *m_indicator_proxy;
52};
53
54#endif
55
056
=== modified file 'bamf-matcher.cpp'
--- bamf-matcher.cpp 2010-12-21 09:56:42 +0000
+++ bamf-matcher.cpp 2011-01-17 04:32:10 +0000
@@ -62,7 +62,7 @@
62 return NULL;62 return NULL;
6363
64 BamfView *view = BamfFactory::get_default().view_for_path(path);64 BamfView *view = BamfFactory::get_default().view_for_path(path);
65 return static_cast<BamfApplication *>(view);65 return qobject_cast<BamfApplication *>(view);
66 }66 }
67}67}
6868
@@ -80,7 +80,7 @@
80 return NULL;80 return NULL;
8181
82 BamfView *view = BamfFactory::get_default().view_for_path(path);82 BamfView *view = BamfFactory::get_default().view_for_path(path);
83 return static_cast<BamfWindow *>(view);83 return qobject_cast<BamfWindow *>(view);
84 }84 }
85}85}
8686
@@ -98,7 +98,7 @@
98 return NULL;98 return NULL;
9999
100 BamfView *view = BamfFactory::get_default().view_for_path(path);100 BamfView *view = BamfFactory::get_default().view_for_path(path);
101 return static_cast<BamfApplication *>(view);101 return qobject_cast<BamfApplication *>(view);
102 }102 }
103}103}
104104
@@ -127,7 +127,10 @@
127 QStringList list = reply.value();127 QStringList list = reply.value();
128 for (int i = 0; i < list.size(); ++i) {128 for (int i = 0; i < list.size(); ++i) {
129 BamfView *view = BamfFactory::get_default().view_for_path(list.at(i));129 BamfView *view = BamfFactory::get_default().view_for_path(list.at(i));
130 result.prepend(static_cast<BamfApplication *>(view));130 BamfApplication* application = qobject_cast<BamfApplication *>(view);
131 if (application != NULL) {
132 result.prepend(application);
133 }
131 }134 }
132 }135 }
133 return new BamfApplicationList(result);136 return new BamfApplicationList(result);
@@ -145,7 +148,10 @@
145 QStringList list = reply.value();148 QStringList list = reply.value();
146 for (int i = 0; i < list.size(); ++i) {149 for (int i = 0; i < list.size(); ++i) {
147 BamfView *view = BamfFactory::get_default().view_for_path(list.at(i));150 BamfView *view = BamfFactory::get_default().view_for_path(list.at(i));
148 result.prepend(static_cast<BamfApplication *>(view));151 BamfApplication* application = qobject_cast<BamfApplication *>(view);
152 if (application != NULL) {
153 result.prepend(application);
154 }
149 }155 }
150 }156 }
151 return new BamfApplicationList(result);157 return new BamfApplicationList(result);
@@ -156,8 +162,8 @@
156{162{
157 BamfView *former = BamfFactory::get_default().view_for_path(old_active);163 BamfView *former = BamfFactory::get_default().view_for_path(old_active);
158 BamfView *current = BamfFactory::get_default().view_for_path(new_active);164 BamfView *current = BamfFactory::get_default().view_for_path(new_active);
159 ActiveApplicationChanged(static_cast<BamfApplication *>(former),165 ActiveApplicationChanged(qobject_cast<BamfApplication *>(former),
160 static_cast<BamfApplication *>(current));166 qobject_cast<BamfApplication *>(current));
161}167}
162168
163void169void
@@ -165,8 +171,8 @@
165{171{
166 BamfView *former = BamfFactory::get_default().view_for_path(old_active);172 BamfView *former = BamfFactory::get_default().view_for_path(old_active);
167 BamfView *current = BamfFactory::get_default().view_for_path(new_active);173 BamfView *current = BamfFactory::get_default().view_for_path(new_active);
168 ActiveWindowChanged(static_cast<BamfWindow *>(former),174 ActiveWindowChanged(qobject_cast<BamfWindow *>(former),
169 static_cast<BamfWindow *>(current));175 qobject_cast<BamfWindow *>(current));
170}176}
171177
172void178void
173179
=== modified file 'bamf-plugin.cpp'
--- bamf-plugin.cpp 2011-01-13 17:57:36 +0000
+++ bamf-plugin.cpp 2011-01-17 04:32:10 +0000
@@ -27,6 +27,7 @@
27#include "bamf-view.h"27#include "bamf-view.h"
28#include "bamf-application.h"28#include "bamf-application.h"
29#include "bamf-window.h"29#include "bamf-window.h"
30#include "bamf-indicator.h"
30#include "bamf-control.h"31#include "bamf-control.h"
31#include "bamf-matcher.h"32#include "bamf-matcher.h"
3233
@@ -42,6 +43,7 @@
42 qmlRegisterUncreatableType<BamfApplication>(uri, 0, 2, "BamfApplication", message);43 qmlRegisterUncreatableType<BamfApplication>(uri, 0, 2, "BamfApplication", message);
43 qmlRegisterUncreatableType<BamfApplicationList>(uri, 0, 2, "BamfApplicationList", message);44 qmlRegisterUncreatableType<BamfApplicationList>(uri, 0, 2, "BamfApplicationList", message);
44 qmlRegisterUncreatableType<BamfWindow>(uri, 0, 2, "BamfWindow", message);45 qmlRegisterUncreatableType<BamfWindow>(uri, 0, 2, "BamfWindow", message);
46 qmlRegisterUncreatableType<BamfIndicator>(uri, 0, 2, "BamfIndicator", message);
45 qmlRegisterUncreatableType<BamfWindowList>(uri, 0, 2, "BamfWindowList", message);47 qmlRegisterUncreatableType<BamfWindowList>(uri, 0, 2, "BamfWindowList", message);
46 qmlRegisterUncreatableType<BamfControl>(uri, 0, 2, "BamfControl", message);48 qmlRegisterUncreatableType<BamfControl>(uri, 0, 2, "BamfControl", message);
47 qmlRegisterUncreatableType<BamfMatcher>(uri, 0, 2, "BamfMatcher", message);49 qmlRegisterUncreatableType<BamfMatcher>(uri, 0, 2, "BamfMatcher", message);
4850
=== modified file 'bamf-window.cpp'
--- bamf-window.cpp 2010-12-21 09:56:42 +0000
+++ bamf-window.cpp 2011-01-17 04:32:10 +0000
@@ -47,7 +47,7 @@
47 return NULL;47 return NULL;
48 } else {48 } else {
49 BamfView *view = BamfFactory::get_default().view_for_path(reply.value());49 BamfView *view = BamfFactory::get_default().view_for_path(reply.value());
50 return static_cast<BamfWindow *>(view);50 return qobject_cast<BamfWindow *>(view);
51 }51 }
52}52}
5353

Subscribers

People subscribed via source and target branches

to all changes: