Merge lp:~azzar1/unity/fix-778499 into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2335
Proposed branch: lp:~azzar1/unity/fix-778499
Merge into: lp:unity
Diff against target: 121 lines (+37/-3)
5 files modified
plugins/unityshell/src/AbstractLauncherIcon.h (+1/-0)
plugins/unityshell/src/LauncherController.cpp (+6/-3)
plugins/unityshell/src/LauncherIcon.cpp (+6/-0)
tests/autopilot/autopilot/emulators/unity/launcher.py (+11/-0)
tests/autopilot/autopilot/tests/test_launcher.py (+13/-0)
To merge this branch: bzr merge lp:~azzar1/unity/fix-778499
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+103327@code.launchpad.net

Commit message

Set a shortcut for the new apps on the launcher too.

Description of the change

== Problem ==
New apps on the launcher have no shortcut key until something is being closed.

== Fix ==
Call LauncherController::SortAndUpdate when a new bamf icon has been added to the launcher.

== Test ==
App test added.
./tools/autopilot run autopilot.tests.test_launcher.LauncherRevealTests.test_new_icon_has_the_shortcut

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Unity code looks good to me.

The test needs some tuning:

111 + desktop_file = self.KNOWN_APPS['Calculator']['desktop-file']
112 + if self.launcher.model.get_icon_by_desktop_id(desktop_file) != None:
113 + self.skip("Calculator icon is already on the launcher.")
114 +
115 + self.start_app('Calculator')
116 + icon = self.launcher.model.get_icon_by_desktop_id(desktop_file)
117 + self.assertThat(icon.shortcut, GreaterThan(0))

Instead of skipping the test when the calculator is already opened, just close it and you can just do:

self.close_all_app('Calculator')
calc = self.start_app('Calculator')
icon = self.launcher.model.get_icon_by_desktop_id(calc.desktop_file)
self.assertThat(icon.shortcut, Eventually(GreaterThan(0)))

(using eventually to avoid false-negatives)

review: Needs Fixing
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> self.close_all_app('Calculator')

Put this even before the "num_bamf_launcher_icons" check, so that it won't fail just for that icon ;)

Revision history for this message
Andrea Azzarone (azzar1) wrote :

> Unity code looks good to me.
>
> The test needs some tuning:
>
> 111 + desktop_file = self.KNOWN_APPS['Calculator']['desktop-file']
> 112 + if self.launcher.model.get_icon_by_desktop_id(desktop_file)
> != None:
> 113 + self.skip("Calculator icon is already on the launcher.")
> 114 +
> 115 + self.start_app('Calculator')
> 116 + icon =
> self.launcher.model.get_icon_by_desktop_id(desktop_file)
> 117 + self.assertThat(icon.shortcut, GreaterThan(0))
>
> Instead of skipping the test when the calculator is already opened, just close
> it and you can just do:
>
> self.close_all_app('Calculator')
> calc = self.start_app('Calculator')
> icon = self.launcher.model.get_icon_by_desktop_id(calc.desktop_file)
> self.assertThat(icon.shortcut, Eventually(GreaterThan(0)))
>
> (using eventually to avoid false-negatives)

If the Calculator is pinned, closing it will not remove the icon from the launcher.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

You're right... But you can still check for that...

Revision history for this message
Andrea Azzarone (azzar1) wrote :

Yeah but keep in mind that tests should be as clean as possible, and adding another if statement will add clutter to the test. But I will do as you want...

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Ok.. fair enough.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/AbstractLauncherIcon.h'
2--- plugins/unityshell/src/AbstractLauncherIcon.h 2012-04-11 15:49:58 +0000
3+++ plugins/unityshell/src/AbstractLauncherIcon.h 2012-04-24 18:13:37 +0000
4@@ -215,6 +215,7 @@
5
6 sigc::signal<void, AbstractLauncherIcon::Ptr> needs_redraw;
7 sigc::signal<void, AbstractLauncherIcon::Ptr> remove;
8+ sigc::signal<void> visibility_changed;
9
10 sigc::connection needs_redraw_connection;
11 sigc::connection on_icon_added_connection;
12
13=== modified file 'plugins/unityshell/src/LauncherController.cpp'
14--- plugins/unityshell/src/LauncherController.cpp 2012-04-21 21:32:26 +0000
15+++ plugins/unityshell/src/LauncherController.cpp 2012-04-24 18:13:37 +0000
16@@ -497,7 +497,7 @@
17 std::stringstream shortcut_string;
18 shortcut_string << (shortcut % 10);
19 icon->SetShortcut(shortcut_string.str()[0]);
20- shortcut++;
21+ ++shortcut;
22 }
23 // reset shortcut
24 else
25@@ -607,6 +607,8 @@
26 else
27 model_->ReorderBefore(result, other, false);
28 }
29+
30+ SortAndUpdate();
31 }
32
33 void Controller::Impl::OnFavoriteStoreFavoriteRemoved(std::string const& entry)
34@@ -738,10 +740,11 @@
35 return;
36 }
37
38- AbstractLauncherIcon::Ptr icon (new BamfLauncherIcon(app));
39+ AbstractLauncherIcon::Ptr icon(new BamfLauncherIcon(app));
40+ icon->visibility_changed.connect(sigc::mem_fun(self, &Impl::SortAndUpdate));
41 icon->SetSortPriority(self->sort_priority_++);
42-
43 self->RegisterIcon(icon);
44+ self->SortAndUpdate();
45 }
46
47 AbstractLauncherIcon::Ptr Controller::Impl::CreateFavorite(const char* file_path)
48
49=== modified file 'plugins/unityshell/src/LauncherIcon.cpp'
50--- plugins/unityshell/src/LauncherIcon.cpp 2012-04-11 15:49:58 +0000
51+++ plugins/unityshell/src/LauncherIcon.cpp 2012-04-24 18:13:37 +0000
52@@ -202,6 +202,7 @@
53 .add("icon_type", _icon_type)
54 .add("tooltip_text", tooltip_text())
55 .add("sort_priority", _sort_priority)
56+ .add("shortcut", _shortcut)
57 .add("monitors_visibility", g_variant_builder_end(&monitors_builder))
58 .add("active", GetQuirk(QUIRK_ACTIVE))
59 .add("visible", GetQuirk(QUIRK_VISIBLE))
60@@ -853,6 +854,11 @@
61 UBusServer* ubus = ubus_server_get_default();
62 ubus_server_send_message(ubus, UBUS_LAUNCHER_ICON_URGENT_CHANGED, g_variant_new_boolean(value));
63 }
64+
65+ if (quirk == QUIRK_VISIBLE)
66+ {
67+ visibility_changed.emit();
68+ }
69 }
70
71 gboolean
72
73=== modified file 'tests/autopilot/autopilot/emulators/unity/launcher.py'
74--- tests/autopilot/autopilot/emulators/unity/launcher.py 2012-04-17 23:17:32 +0000
75+++ tests/autopilot/autopilot/emulators/unity/launcher.py 2012-04-24 18:13:37 +0000
76@@ -301,6 +301,13 @@
77 else:
78 return self.get_children_by_type(SimpleLauncherIcon)
79
80+ def get_bamf_launcher_icons(self, visible_only=True):
81+ """Get a list of bamf launcher icons in this launcher."""
82+ if visible_only:
83+ return self.get_children_by_type(BamfLauncherIcon, visible=True)
84+ else:
85+ return self.get_children_by_type(BamfLauncherIcon)
86+
87 def get_launcher_icons_for_monitor(self, monitor, visible_only=True):
88 """Get a list of launcher icons for provided monitor."""
89 icons = []
90@@ -345,3 +352,7 @@
91 def num_launcher_icons(self):
92 """Get the number of icons in the launcher model."""
93 return len(self.get_launcher_icons())
94+
95+ def num_bamf_launcher_icons(self, visible_only=True):
96+ """Get the number of bamf icons in the launcher model."""
97+ return len(self.get_bamf_launcher_icons(visible_only))
98
99=== modified file 'tests/autopilot/autopilot/tests/test_launcher.py'
100--- tests/autopilot/autopilot/tests/test_launcher.py 2012-04-18 07:33:15 +0000
101+++ tests/autopilot/autopilot/tests/test_launcher.py 2012-04-24 18:13:37 +0000
102@@ -499,6 +499,19 @@
103 sleep(5)
104 self.assertThat(self.launcher_instance.is_showing, Equals(False))
105
106+ def test_new_icon_has_the_shortcut(self):
107+ """New icons should have an associated shortcut"""
108+ if self.launcher.model.num_bamf_launcher_icons() >= 10:
109+ self.skip("There are already more than 9 icons in the launcher")
110+
111+ desktop_file = self.KNOWN_APPS['Calculator']['desktop-file']
112+ if self.launcher.model.get_icon_by_desktop_id(desktop_file) != None:
113+ self.skip("Calculator icon is already on the launcher.")
114+
115+ self.start_app('Calculator')
116+ icon = self.launcher.model.get_icon_by_desktop_id(desktop_file)
117+ self.assertThat(icon.shortcut, GreaterThan(0))
118+
119
120 class LauncherVisualTests(LauncherTestCase):
121 """Tests for visual aspects of the launcher (icon saturation etc.)."""