Merge lp:~charlesk/hud/qtgactiongroup-cleanup into lp:hud/14.04

Proposed by Charles Kerr
Status: Merged
Approved by: Pete Woods
Approved revision: 382
Merged at revision: 382
Proposed branch: lp:~charlesk/hud/qtgactiongroup-cleanup
Merge into: lp:hud/14.04
Diff against target: 147 lines (+16/-43)
3 files modified
libqtgmenu/internal/QtGActionGroup.cpp (+14/-39)
libqtgmenu/internal/QtGActionGroup.h (+0/-4)
libqtgmenu/internal/QtGMenuUtils.cpp (+2/-0)
To merge this branch: bzr merge lp:~charlesk/hud/qtgactiongroup-cleanup
Reviewer Review Type Date Requested Status
Marcus Tomlinson (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+211383@code.launchpad.net

Commit message

Simplify the implementation of QtGActionGroup.

This started off with the intent of removing the overhead of g_action_group_list_actions() in QtGActionGroup::Action(), but then I found QtGActionGroup::Action() was only called in the object's constructor and destructor, so it made more sense to remove the function altogether.

Summary of changes:

  * Plugged GVariant leak in QtGActionGroup::TriggerAction()

  * Plugged char* leak in QtGMenuUtils::makeStringListQVariant

  * ActionGroup ctor calls g_action_group_list_actions() once instead of n+1 times

  * ActionGroup dtor calls g_action_group_list_actions() once instead of n times

  * Removed unused public method Size()

  * Removed newly-unused public method Action()

  * Removed newly-unused field m_size

Description of the change

* Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)
  * Yes
 * Did you build your software in a clean sbuild/pbuilder chroot or ppa?
  * Yes
 * Did you build your software in a clean sbuild/pbuilder armhf chroot or ppa?
  * Yes
 * Has your component "TestPlan” been executed successfully on emulator, N4?
  * Yes
 * Has a 5 minute exploratory testing run been executed on N4?
  * Yes
 * If you changed the packaging (debian), did you subscribe a core-dev to this MP?
  * N/A
 * If you changed the UI, did you subscribe the design-reviewers to this MP?
  * No change
 * What components might get impacted by your changes?
  * Unity7
  * Unity8
 * Have you requested review by the teams of these owning components?
  * Yes

Check List:
https://wiki.ubuntu.com/Process/Merges/Checklists/hud

Test Plan:
https://wiki.ubuntu.com/Process/Merges/TestPlan/hud

Silo:
<waiting for silo>

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
Marcus Tomlinson (marcustomlinson) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libqtgmenu/internal/QtGActionGroup.cpp'
2--- libqtgmenu/internal/QtGActionGroup.cpp 2014-03-11 05:41:28 +0000
3+++ libqtgmenu/internal/QtGActionGroup.cpp 2014-03-17 18:40:44 +0000
4@@ -27,22 +27,16 @@
5 {
6 ConnectCallbacks();
7
8- gchar** actions_list = g_action_group_list_actions( m_action_group );
9+ auto actions_list = g_action_group_list_actions( m_action_group );
10 if( actions_list )
11 {
12- while( actions_list[m_size] != nullptr )
13+ for( int i = 0; actions_list[i]; ++i )
14 {
15- ++m_size;
16+ emit ActionAdded( actions_list[i] );
17 }
18
19 g_strfreev( actions_list );
20 }
21-
22- // add initial items
23- for( int i = 0; i < m_size; ++i )
24- {
25- emit ActionAdded( Action( i ) );
26- }
27 }
28
29 QtGActionGroup::~QtGActionGroup()
30@@ -52,9 +46,15 @@
31 return;
32 }
33
34- for( int i = 0; i < m_size; ++i )
35+ auto actions_list = g_action_group_list_actions( m_action_group );
36+ if( actions_list )
37 {
38- emit ActionRemoved( Action( i ) );
39+ for( int i = 0; actions_list[i]; ++i )
40+ {
41+ emit ActionRemoved( actions_list[i] );
42+ }
43+
44+ g_strfreev( actions_list );
45 }
46
47 DisconnectCallbacks();
48@@ -70,28 +70,6 @@
49 return m_action_group;
50 }
51
52-int QtGActionGroup::Size() const
53-{
54- return m_size;
55-}
56-
57-QString QtGActionGroup::Action( int index )
58-{
59- if( index >= m_size )
60- {
61- return QString();
62- }
63-
64- QString action_name;
65- gchar** actions_list = g_action_group_list_actions( m_action_group );
66-
67- action_name = QString( actions_list[index] );
68-
69- g_strfreev( actions_list );
70-
71- return action_name;
72-}
73-
74 void QtGActionGroup::TriggerAction( QString action_name, bool checked )
75 {
76 QString prefix = action_name.left( action_name.indexOf( '.' ) );
77@@ -117,15 +95,16 @@
78 {
79 GVariant* param = g_variant_new_string( action.c_str() );
80 g_action_group_activate_action( m_action_group, action.c_str(), param );
81+ g_variant_unref( param );
82 }
83 }
84 }
85
86 void QtGActionGroup::EmitStates()
87 {
88- gchar** actions_list = g_action_group_list_actions( m_action_group );
89+ auto actions_list = g_action_group_list_actions( m_action_group );
90
91- for( int i = 0; i < m_size; ++i )
92+ for( int i = 0; actions_list && actions_list[i]; ++i )
93 {
94 gchar* action_name = actions_list[i];
95
96@@ -158,8 +137,6 @@
97 action_name );
98 if( type != nullptr )
99 emit self->ActionParameterized( self->m_action_prefix + "." + action_name, type != nullptr );
100-
101- ++self->m_size;
102 }
103
104 void QtGActionGroup::ActionRemovedCallback( GActionGroup* action_group, gchar* action_name,
105@@ -167,8 +144,6 @@
106 {
107 QtGActionGroup* self = reinterpret_cast< QtGActionGroup* >( user_data );
108 emit self->ActionRemoved( action_name );
109-
110- --self->m_size;
111 }
112
113 void QtGActionGroup::ActionEnabledCallback( GActionGroup* action_group, gchar* action_name,
114
115=== modified file 'libqtgmenu/internal/QtGActionGroup.h'
116--- libqtgmenu/internal/QtGActionGroup.h 2014-03-11 05:31:53 +0000
117+++ libqtgmenu/internal/QtGActionGroup.h 2014-03-17 18:40:44 +0000
118@@ -37,9 +37,6 @@
119 virtual ~QtGActionGroup();
120
121 GActionGroup* ActionGroup() const;
122- int Size() const;
123-
124- QString Action( int index );
125
126 Q_SIGNALS:
127 void ActionAdded( QString action_name );
128@@ -66,7 +63,6 @@
129 void DisconnectCallbacks();
130
131 private:
132- int m_size = 0;
133
134 QString m_action_prefix;
135 GActionGroup* m_action_group = nullptr;
136
137=== modified file 'libqtgmenu/internal/QtGMenuUtils.cpp'
138--- libqtgmenu/internal/QtGMenuUtils.cpp 2013-11-20 04:28:46 +0000
139+++ libqtgmenu/internal/QtGMenuUtils.cpp 2014-03-17 18:40:44 +0000
140@@ -92,6 +92,8 @@
141 while( stringArray[i] != NULL )
142 value << QString::fromUtf8( stringArray[i++] );
143
144+ g_free (const_cast<gchar**>(stringArray));
145+
146 return QVariant::fromValue( value );
147 }
148

Subscribers

People subscribed via source and target branches