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
=== modified file 'plugins/unityshell/src/AbstractLauncherIcon.h'
--- plugins/unityshell/src/AbstractLauncherIcon.h 2012-04-11 15:49:58 +0000
+++ plugins/unityshell/src/AbstractLauncherIcon.h 2012-04-24 18:13:37 +0000
@@ -215,6 +215,7 @@
215215
216 sigc::signal<void, AbstractLauncherIcon::Ptr> needs_redraw;216 sigc::signal<void, AbstractLauncherIcon::Ptr> needs_redraw;
217 sigc::signal<void, AbstractLauncherIcon::Ptr> remove;217 sigc::signal<void, AbstractLauncherIcon::Ptr> remove;
218 sigc::signal<void> visibility_changed;
218219
219 sigc::connection needs_redraw_connection;220 sigc::connection needs_redraw_connection;
220 sigc::connection on_icon_added_connection;221 sigc::connection on_icon_added_connection;
221222
=== modified file 'plugins/unityshell/src/LauncherController.cpp'
--- plugins/unityshell/src/LauncherController.cpp 2012-04-21 21:32:26 +0000
+++ plugins/unityshell/src/LauncherController.cpp 2012-04-24 18:13:37 +0000
@@ -497,7 +497,7 @@
497 std::stringstream shortcut_string;497 std::stringstream shortcut_string;
498 shortcut_string << (shortcut % 10);498 shortcut_string << (shortcut % 10);
499 icon->SetShortcut(shortcut_string.str()[0]);499 icon->SetShortcut(shortcut_string.str()[0]);
500 shortcut++;500 ++shortcut;
501 }501 }
502 // reset shortcut502 // reset shortcut
503 else503 else
@@ -607,6 +607,8 @@
607 else607 else
608 model_->ReorderBefore(result, other, false);608 model_->ReorderBefore(result, other, false);
609 }609 }
610
611 SortAndUpdate();
610}612}
611613
612void Controller::Impl::OnFavoriteStoreFavoriteRemoved(std::string const& entry)614void Controller::Impl::OnFavoriteStoreFavoriteRemoved(std::string const& entry)
@@ -738,10 +740,11 @@
738 return;740 return;
739 }741 }
740742
741 AbstractLauncherIcon::Ptr icon (new BamfLauncherIcon(app));743 AbstractLauncherIcon::Ptr icon(new BamfLauncherIcon(app));
744 icon->visibility_changed.connect(sigc::mem_fun(self, &Impl::SortAndUpdate));
742 icon->SetSortPriority(self->sort_priority_++);745 icon->SetSortPriority(self->sort_priority_++);
743
744 self->RegisterIcon(icon);746 self->RegisterIcon(icon);
747 self->SortAndUpdate();
745}748}
746749
747AbstractLauncherIcon::Ptr Controller::Impl::CreateFavorite(const char* file_path)750AbstractLauncherIcon::Ptr Controller::Impl::CreateFavorite(const char* file_path)
748751
=== modified file 'plugins/unityshell/src/LauncherIcon.cpp'
--- plugins/unityshell/src/LauncherIcon.cpp 2012-04-11 15:49:58 +0000
+++ plugins/unityshell/src/LauncherIcon.cpp 2012-04-24 18:13:37 +0000
@@ -202,6 +202,7 @@
202 .add("icon_type", _icon_type)202 .add("icon_type", _icon_type)
203 .add("tooltip_text", tooltip_text())203 .add("tooltip_text", tooltip_text())
204 .add("sort_priority", _sort_priority)204 .add("sort_priority", _sort_priority)
205 .add("shortcut", _shortcut)
205 .add("monitors_visibility", g_variant_builder_end(&monitors_builder))206 .add("monitors_visibility", g_variant_builder_end(&monitors_builder))
206 .add("active", GetQuirk(QUIRK_ACTIVE))207 .add("active", GetQuirk(QUIRK_ACTIVE))
207 .add("visible", GetQuirk(QUIRK_VISIBLE))208 .add("visible", GetQuirk(QUIRK_VISIBLE))
@@ -853,6 +854,11 @@
853 UBusServer* ubus = ubus_server_get_default();854 UBusServer* ubus = ubus_server_get_default();
854 ubus_server_send_message(ubus, UBUS_LAUNCHER_ICON_URGENT_CHANGED, g_variant_new_boolean(value));855 ubus_server_send_message(ubus, UBUS_LAUNCHER_ICON_URGENT_CHANGED, g_variant_new_boolean(value));
855 }856 }
857
858 if (quirk == QUIRK_VISIBLE)
859 {
860 visibility_changed.emit();
861 }
856}862}
857863
858gboolean864gboolean
859865
=== modified file 'tests/autopilot/autopilot/emulators/unity/launcher.py'
--- tests/autopilot/autopilot/emulators/unity/launcher.py 2012-04-17 23:17:32 +0000
+++ tests/autopilot/autopilot/emulators/unity/launcher.py 2012-04-24 18:13:37 +0000
@@ -301,6 +301,13 @@
301 else:301 else:
302 return self.get_children_by_type(SimpleLauncherIcon)302 return self.get_children_by_type(SimpleLauncherIcon)
303303
304 def get_bamf_launcher_icons(self, visible_only=True):
305 """Get a list of bamf launcher icons in this launcher."""
306 if visible_only:
307 return self.get_children_by_type(BamfLauncherIcon, visible=True)
308 else:
309 return self.get_children_by_type(BamfLauncherIcon)
310
304 def get_launcher_icons_for_monitor(self, monitor, visible_only=True):311 def get_launcher_icons_for_monitor(self, monitor, visible_only=True):
305 """Get a list of launcher icons for provided monitor."""312 """Get a list of launcher icons for provided monitor."""
306 icons = []313 icons = []
@@ -345,3 +352,7 @@
345 def num_launcher_icons(self):352 def num_launcher_icons(self):
346 """Get the number of icons in the launcher model."""353 """Get the number of icons in the launcher model."""
347 return len(self.get_launcher_icons())354 return len(self.get_launcher_icons())
355
356 def num_bamf_launcher_icons(self, visible_only=True):
357 """Get the number of bamf icons in the launcher model."""
358 return len(self.get_bamf_launcher_icons(visible_only))
348359
=== modified file 'tests/autopilot/autopilot/tests/test_launcher.py'
--- tests/autopilot/autopilot/tests/test_launcher.py 2012-04-18 07:33:15 +0000
+++ tests/autopilot/autopilot/tests/test_launcher.py 2012-04-24 18:13:37 +0000
@@ -499,6 +499,19 @@
499 sleep(5)499 sleep(5)
500 self.assertThat(self.launcher_instance.is_showing, Equals(False))500 self.assertThat(self.launcher_instance.is_showing, Equals(False))
501501
502 def test_new_icon_has_the_shortcut(self):
503 """New icons should have an associated shortcut"""
504 if self.launcher.model.num_bamf_launcher_icons() >= 10:
505 self.skip("There are already more than 9 icons in the launcher")
506
507 desktop_file = self.KNOWN_APPS['Calculator']['desktop-file']
508 if self.launcher.model.get_icon_by_desktop_id(desktop_file) != None:
509 self.skip("Calculator icon is already on the launcher.")
510
511 self.start_app('Calculator')
512 icon = self.launcher.model.get_icon_by_desktop_id(desktop_file)
513 self.assertThat(icon.shortcut, GreaterThan(0))
514
502515
503class LauncherVisualTests(LauncherTestCase):516class LauncherVisualTests(LauncherTestCase):
504 """Tests for visual aspects of the launcher (icon saturation etc.)."""517 """Tests for visual aspects of the launcher (icon saturation etc.)."""