Merge lp:~3v1n0/unity/bfb-quicklist-does-not-close-dash into lp:unity

Proposed by Marco Trevisan (Treviño) on 2012-08-13
Status: Merged
Approved by: Marco Trevisan (Treviño) on 2012-08-14
Approved revision: 2553
Merged at revision: 2561
Proposed branch: lp:~3v1n0/unity/bfb-quicklist-does-not-close-dash
Merge into: lp:unity
Prerequisite: lp:~3v1n0/unity/quicklist-menuitem-clanup
Diff against target: 298 lines (+154/-8)
7 files modified
launcher/BFBLauncherIcon.cpp (+2/-0)
launcher/BamfLauncherIcon.cpp (+2/-2)
launcher/QuicklistMenuItem.cpp (+20/-5)
launcher/QuicklistMenuItem.h (+4/-0)
tests/CMakeLists.txt (+1/-0)
tests/test_bfb_launcher_icon.cpp (+54/-0)
tests/test_quicklist_menu_item.cpp (+71/-1)
To merge this branch: bzr merge lp:~3v1n0/unity/bfb-quicklist-does-not-close-dash
Reviewer Review Type Date Requested Status
Tim Penhey (community) 2012-08-13 Approve on 2012-08-14
Review via email: mp+119378@code.launchpad.net

Commit message

QuicklistMenuitem, BFBLauncherIcon: don't close the Dash when clicking on BFB quicklist items

Description of the change

Add a new property to the quicklist menu items to define if it should close or not the overlay when clicked.

Added unit tests.

To post a comment you must log in.
Tim Penhey (thumper) 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 'launcher/BFBLauncherIcon.cpp'
2--- launcher/BFBLauncherIcon.cpp 2012-08-02 11:30:02 +0000
3+++ launcher/BFBLauncherIcon.cpp 2012-08-13 16:20:26 +0000
4@@ -119,6 +119,7 @@
5 dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Dash Home"));
6 dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
7 dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
8+ dbusmenu_menuitem_property_set_bool(menu_item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY, true);
9
10 g_signal_connect(menu_item,
11 DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
12@@ -138,6 +139,7 @@
13 dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, lens->name);
14 dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
15 dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
16+ dbusmenu_menuitem_property_set_bool(menu_item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY, true);
17
18 g_signal_connect(menu_item,
19 DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
20
21=== modified file 'launcher/BamfLauncherIcon.cpp'
22--- launcher/BamfLauncherIcon.cpp 2012-08-02 11:30:02 +0000
23+++ launcher/BamfLauncherIcon.cpp 2012-08-13 16:20:26 +0000
24@@ -977,7 +977,7 @@
25 if (dbusmenu_menuitem_property_get_bool(item, DBUSMENU_MENUITEM_PROP_VISIBLE))
26 {
27 first_separator_needed = true;
28- dbusmenu_menuitem_property_set_bool(item, "unity-use-markup", FALSE);
29+ dbusmenu_menuitem_property_set_bool(item, QuicklistMenuItem::MARKUP_ENABLED_PROPERTY, FALSE);
30
31 result.push_back(item);
32 }
33@@ -1039,7 +1039,7 @@
34 DBUSMENU_MENUITEM_PROP_ENABLED,
35 true);
36 dbusmenu_menuitem_property_set_bool(item,
37- "unity-use-markup",
38+ QuicklistMenuItem::MARKUP_ENABLED_PROPERTY,
39 true);
40
41 _gsignals.Add(new glib::Signal<void, DbusmenuMenuitem*, int>(item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
42
43=== modified file 'launcher/QuicklistMenuItem.cpp'
44--- launcher/QuicklistMenuItem.cpp 2012-08-13 16:20:26 +0000
45+++ launcher/QuicklistMenuItem.cpp 2012-08-13 16:20:26 +0000
46@@ -28,6 +28,8 @@
47
48 namespace unity
49 {
50+const char* QuicklistMenuItem::MARKUP_ENABLED_PROPERTY = "unity-use-markup";
51+const char* QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY = "unity-overlay-item";
52
53 NUX_IMPLEMENT_OBJECT_TYPE(QuicklistMenuItem);
54
55@@ -127,12 +129,16 @@
56
57 void QuicklistMenuItem::Activate() const
58 {
59- if (!_menu_item)
60+ if (!_menu_item || !GetSelectable())
61 return;
62
63 dbusmenu_menuitem_handle_event(_menu_item, "clicked", nullptr, 0);
64- UBusManager manager;
65- manager.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST);
66+
67+ if (!IsOverlayQuicklist())
68+ {
69+ UBusManager manager;
70+ manager.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST);
71+ }
72 }
73
74 void QuicklistMenuItem::Select(bool select)
75@@ -333,7 +339,7 @@
76 {
77 if (IsMarkupEnabled() != enabled)
78 {
79- dbusmenu_menuitem_property_set_bool(_menu_item, "unity-use-markup", enabled);
80+ dbusmenu_menuitem_property_set_bool(_menu_item, MARKUP_ENABLED_PROPERTY, enabled);
81
82 _text = "";
83 InitializeText();
84@@ -345,10 +351,19 @@
85 if (!_menu_item)
86 return false;
87
88- gboolean markup = dbusmenu_menuitem_property_get_bool(_menu_item, "unity-use-markup");
89+ gboolean markup = dbusmenu_menuitem_property_get_bool(_menu_item, MARKUP_ENABLED_PROPERTY);
90 return (markup != FALSE);
91 }
92
93+bool QuicklistMenuItem::IsOverlayQuicklist() const
94+{
95+ if (!_menu_item)
96+ return false;
97+
98+ gboolean overlay = dbusmenu_menuitem_property_get_bool(_menu_item, OVERLAY_MENU_ITEM_PROPERTY);
99+ return (overlay != FALSE);
100+}
101+
102 unsigned QuicklistMenuItem::GetCairoSurfaceWidth() const
103 {
104 if (!_normalTexture[0])
105
106=== modified file 'launcher/QuicklistMenuItem.h'
107--- launcher/QuicklistMenuItem.h 2012-08-13 16:20:26 +0000
108+++ launcher/QuicklistMenuItem.h 2012-08-13 16:20:26 +0000
109@@ -61,6 +61,7 @@
110
111 void EnableLabelMarkup(bool enabled);
112 bool IsMarkupEnabled() const;
113+ bool IsOverlayQuicklist() const;
114
115 void Activate() const;
116
117@@ -79,6 +80,9 @@
118 sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseClick;
119 sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseDrag;
120
121+ static const char* MARKUP_ENABLED_PROPERTY;
122+ static const char* OVERLAY_MENU_ITEM_PROPERTY;
123+
124 protected:
125 // Introspection
126 std::string GetName() const;
127
128=== modified file 'tests/CMakeLists.txt'
129--- tests/CMakeLists.txt 2012-08-13 16:20:26 +0000
130+++ tests/CMakeLists.txt 2012-08-13 16:20:26 +0000
131@@ -200,6 +200,7 @@
132 add_executable(test-gtest
133 test_main.cpp
134 test_bamflaunchericon.cpp
135+ test_bfb_launcher_icon.cpp
136 test_dashview_impl.cpp
137 test_edge_barrier_controller.cpp
138 test_launcher.cpp
139
140=== added file 'tests/test_bfb_launcher_icon.cpp'
141--- tests/test_bfb_launcher_icon.cpp 1970-01-01 00:00:00 +0000
142+++ tests/test_bfb_launcher_icon.cpp 2012-08-13 16:20:26 +0000
143@@ -0,0 +1,54 @@
144+/*
145+ * Copyright 2012 Canonical Ltd.
146+ *
147+ * This program is free software: you can redistribute it and/or modify it
148+ * under the terms of the GNU General Public License version 3, as published
149+ * by the Free Software Foundation.
150+ *
151+ * This program is distributed in the hope that it will be useful, but
152+ * WITHOUT ANY WARRANTY; without even the implied warranties of
153+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
154+ * PURPOSE. See the GNU General Public License for more details.
155+ *
156+ * You should have received a copy of the GNU General Public License
157+ * version 3 along with this program. If not, see
158+ * <http://www.gnu.org/licenses/>
159+ *
160+ * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
161+ */
162+
163+#include <gmock/gmock.h>
164+
165+#include "BFBLauncherIcon.h"
166+
167+using namespace unity;
168+using namespace unity::launcher;
169+
170+namespace
171+{
172+
173+class MockBFBLauncherIcon : public BFBLauncherIcon
174+{
175+public:
176+ MockBFBLauncherIcon()
177+ : BFBLauncherIcon(LauncherHideMode::LAUNCHER_HIDE_NEVER)
178+ {}
179+
180+ std::list<DbusmenuMenuitem*> GetMenus()
181+ {
182+ return BFBLauncherIcon::GetMenus();
183+ }
184+};
185+
186+TEST(TestBFBLauncherIcon, OverlayMenus)
187+{
188+ MockBFBLauncherIcon bfb;
189+
190+ for (auto menu_item : bfb.GetMenus())
191+ {
192+ bool overlay_item = dbusmenu_menuitem_property_get_bool(menu_item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY);
193+ ASSERT_TRUE(overlay_item);
194+ }
195+}
196+
197+}
198
199=== modified file 'tests/test_quicklist_menu_item.cpp'
200--- tests/test_quicklist_menu_item.cpp 2012-08-13 16:20:26 +0000
201+++ tests/test_quicklist_menu_item.cpp 2012-08-13 16:20:26 +0000
202@@ -20,12 +20,16 @@
203
204 #include <gmock/gmock.h>
205 #include <libdbusmenu-glib/client.h>
206+#include <UnityCore/GLibSignal.h>
207
208 #include "QuicklistMenuItem.h"
209 #include "QuicklistMenuItemCheckmark.h"
210 #include "QuicklistMenuItemLabel.h"
211 #include "QuicklistMenuItemRadio.h"
212 #include "QuicklistMenuItemSeparator.h"
213+#include "unity-shared/UBusWrapper.h"
214+#include "unity-shared/UBusMessages.h"
215+#include "test_utils.h"
216
217 using namespace unity;
218 using namespace testing;
219@@ -64,7 +68,7 @@
220 {
221 dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "A Label");
222 dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
223- dbusmenu_menuitem_property_set_bool(item, "unity-use-markup", true);
224+ dbusmenu_menuitem_property_set_bool(item, QuicklistMenuItem::MARKUP_ENABLED_PROPERTY, true);
225
226 nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item));
227
228@@ -104,4 +108,70 @@
229 EXPECT_FALSE(qlitem->GetSelectable());
230 }
231
232+TEST_F(TestQuicklistMenuItem, OverlayMenuitem)
233+{
234+ dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label");
235+ dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
236+
237+ nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item));
238+
239+ EXPECT_FALSE(qlitem->IsOverlayQuicklist());
240+
241+ dbusmenu_menuitem_property_set_bool(item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY, true);
242+ EXPECT_TRUE(qlitem->IsOverlayQuicklist());
243+}
244+
245+TEST_F(TestQuicklistMenuItem, ItemActivate)
246+{
247+ dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label");
248+ dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
249+
250+ nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item));
251+
252+ bool item_activated = false;
253+ glib::Signal<void, DbusmenuMenuitem*, int> signal(item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
254+ [&] (DbusmenuMenuitem* menu_item, int time) {
255+ EXPECT_EQ(menu_item, item);
256+ item_activated = true;
257+ });
258+
259+ qlitem->Activate();
260+ EXPECT_TRUE(item_activated);
261+}
262+
263+TEST_F(TestQuicklistMenuItem, ItemActivateClosesDash)
264+{
265+ dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label");
266+ dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
267+
268+ nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item));
269+
270+ bool closes_dash = false;
271+ UBusManager manager;
272+ manager.RegisterInterest(UBUS_PLACE_VIEW_CLOSE_REQUEST, [&] (GVariant*) { closes_dash = true; });
273+
274+ qlitem->Activate();
275+ Utils::WaitUntil(closes_dash);
276+
277+ EXPECT_TRUE(closes_dash);
278+}
279+
280+TEST_F(TestQuicklistMenuItem, OverlayItemActivateDoesNotCloseDash)
281+{
282+ dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label");
283+ dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
284+ dbusmenu_menuitem_property_set_bool(item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY, true);
285+
286+ nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item));
287+
288+ bool closes_dash = false;
289+ UBusManager manager;
290+ manager.RegisterInterest(UBUS_PLACE_VIEW_CLOSE_REQUEST, [&] (GVariant*) { closes_dash = true; });
291+
292+ qlitem->Activate();
293+ Utils::WaitForTimeoutMSec(100);
294+
295+ EXPECT_FALSE(closes_dash);
296+}
297+
298 }