Merge lp:~nick-dedekind/qmenumodel/lp1385331.led into lp:qmenumodel

Proposed by Nick Dedekind
Status: Merged
Approved by: Albert Astals Cid
Approved revision: 117
Merged at revision: 115
Proposed branch: lp:~nick-dedekind/qmenumodel/lp1385331.led
Merge into: lp:qmenumodel
Diff against target: 117 lines (+38/-2)
3 files modified
debian/changelog (+6/-0)
libqmenumodel/src/qdbusactiongroup.cpp (+23/-2)
libqmenumodel/src/qdbusactiongroup.h (+9/-0)
To merge this branch: bzr merge lp:~nick-dedekind/qmenumodel/lp1385331.led
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+241422@code.launchpad.net

Commit message

Add support for overriding QDBusActionGroup state parser

Description of the change

Add support for overriding QDBusActionGroup state parser

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

bump version

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Albert Astals Cid (aacid) wrote :

Should we delete m_actionStateParser in m_actionStateParser ?

review: Needs Fixing
Revision history for this message
Albert Astals Cid (aacid) wrote :

I meant:

Should we delete m_actionStateParser in setActionStateParser ?

Revision history for this message
Albert Astals Cid (aacid) wrote :

But...

Having a look at how setActionStateParser is used in https://code.launchpad.net/~nick-dedekind/unity8/lp1385331.led/+merge/241417 it seems it should not be deleted, but the code still makes me a bit unhappy since it's the typical structure in which you need to delete m_actionStateParser otherwise you leak the one you created in the constructor.

What about instead this change adding a
  Q_INVOKABLE QVariant actionState(const QString &name, ActionStateParser* actionStateParser);
?

So if it is passed you use it and otherwise you use Converter::toQVariant ?

review: Needs Information
Revision history for this message
Albert Astals Cid (aacid) wrote :

After reading the code more i see my suggestion is not implementable without a big-ish rework (and maybe not at all) so i'll be happy enough if you add a comment to setActionStateParser saying that the class does not take ownership of actionStateParser

review: Needs Fixing
117. By Nick Dedekind

added comment

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> After reading the code more i see my suggestion is not implementable without a
> big-ish rework (and maybe not at all) so i'll be happy enough if you add a
> comment to setActionStateParser saying that the class does not take ownership
> of actionStateParser

done

Revision history for this message
Albert Astals Cid (aacid) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2014-10-13 09:36:50 +0000
3+++ debian/changelog 2014-12-10 16:23:52 +0000
4@@ -1,3 +1,9 @@
5+qmenumodel (0.2.9-0ubuntu1) UNRELEASED; urgency=medium
6+
7+ * Added support for overriding QDBusActionGroup state parser
8+
9+ -- Nick Dedekind <nick.dedekind@canonical.com> Tue, 11 Nov 2014 15:25:11 +0000
10+
11 qmenumodel (0.2.8+14.10.20141013-0ubuntu1) utopic; urgency=low
12
13 [ Nick Dedekind ]
14
15=== modified file 'libqmenumodel/src/qdbusactiongroup.cpp'
16--- libqmenumodel/src/qdbusactiongroup.cpp 2014-10-10 17:28:11 +0000
17+++ libqmenumodel/src/qdbusactiongroup.cpp 2014-12-10 16:23:52 +0000
18@@ -17,6 +17,7 @@
19 * Renato Araujo Oliveira Filho <renato@canonical.com>
20 */
21
22+#include "actionstateparser.h"
23 #include "qdbusactiongroup.h"
24 #include "qstateaction.h"
25 #include "converter.h"
26@@ -58,7 +59,8 @@
27 QDBusActionGroup::QDBusActionGroup(QObject *parent)
28 :QObject(parent),
29 QDBusObject(this),
30- m_actionGroup(NULL)
31+ m_actionGroup(NULL),
32+ m_actionStateParser(new ActionStateParser(this))
33 {
34 }
35
36@@ -89,7 +91,13 @@
37 {
38 QVariant result;
39 GVariant *state = g_action_group_get_action_state(m_actionGroup, name.toUtf8().data());
40- result = Converter::toQVariant(state);
41+
42+ if (m_actionStateParser != NULL) {
43+ result = m_actionStateParser->toQVariant(state);
44+ } else {
45+ result = Converter::toQVariant(state);
46+ }
47+
48 if (state) {
49 g_variant_unref(state);
50 }
51@@ -190,6 +198,19 @@
52 }
53 }
54
55+ActionStateParser* QDBusActionGroup::actionStateParser() const
56+{
57+ return m_actionStateParser;
58+}
59+
60+void QDBusActionGroup::setActionStateParser(ActionStateParser* actionStateParser)
61+{
62+ if (m_actionStateParser != actionStateParser) {
63+ m_actionStateParser = actionStateParser;
64+ Q_EMIT actionStateParserChanged(actionStateParser);
65+ }
66+}
67+
68 /*! \internal */
69 void QDBusActionGroup::clear()
70 {
71
72=== modified file 'libqmenumodel/src/qdbusactiongroup.h'
73--- libqmenumodel/src/qdbusactiongroup.h 2013-08-09 08:01:43 +0000
74+++ libqmenumodel/src/qdbusactiongroup.h 2014-12-10 16:23:52 +0000
75@@ -26,6 +26,7 @@
76 #include <QVariant>
77
78 class QStateAction;
79+class ActionStateParser;
80
81 typedef char gchar;
82 typedef void* gpointer;
83@@ -40,6 +41,7 @@
84 Q_PROPERTY(QString busName READ busName WRITE setBusName NOTIFY busNameChanged)
85 Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath NOTIFY objectPathChanged)
86 Q_PROPERTY(int status READ status NOTIFY statusChanged)
87+ Q_PROPERTY(ActionStateParser* actionStateParser READ actionStateParser WRITE setActionStateParser NOTIFY actionStateParserChanged)
88
89 public:
90 QDBusActionGroup(QObject *parent=0);
91@@ -52,6 +54,10 @@
92 Q_INVOKABLE QStateAction *action(const QString &name);
93 Q_INVOKABLE QVariant actionState(const QString &name);
94
95+ ActionStateParser* actionStateParser() const;
96+ // Ownership of the actionStateParser is not passed to this object.
97+ void setActionStateParser(ActionStateParser* actionStateParser);
98+
99 Q_SIGNALS:
100 void busTypeChanged(DBusEnums::BusType type);
101 void busNameChanged(const QString &busNameChanged);
102@@ -60,6 +66,7 @@
103 void actionAppear(const QString &name);
104 void actionVanish(const QString &name);
105 void actionStateChanged(const QString &name, QVariant state);
106+ void actionStateParserChanged(ActionStateParser* parser);
107
108 public Q_SLOTS:
109 void start();
110@@ -77,6 +84,8 @@
111 int m_signalActionRemovedId;
112 int m_signalStateChangedId;
113
114+ ActionStateParser* m_actionStateParser;
115+
116 // workaround to support int as busType
117 void setIntBusType(int busType);
118

Subscribers

People subscribed via source and target branches