Merge lp:~3v1n0/unity/avoid-duplicate-icons into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Superseded
Proposed branch: lp:~3v1n0/unity/avoid-duplicate-icons
Merge into: lp:unity
Diff against target: 172 lines (+59/-6)
5 files modified
plugins/unityshell/src/BamfLauncherIcon.cpp (+2/-1)
plugins/unityshell/src/LauncherController.cpp (+4/-3)
tests/autopilot/autopilot/emulators/bamf.py (+10/-0)
tests/autopilot/autopilot/tests/__init__.py (+6/-2)
tests/autopilot/autopilot/tests/test_launcher.py (+37/-0)
To merge this branch: bzr merge lp:~3v1n0/unity/avoid-duplicate-icons
Reviewer Review Type Date Requested Status
Thomi Richards (community) Needs Fixing
Review via email: mp+103594@code.launchpad.net

This proposal has been superseded by a proposal from 2012-04-26.

Commit message

LauncherController: flag any bamf view that we control with an icon using the "unity-seen" qdata to avoid icons duplication

Description of the change

We need to flag a bamf view that we control using an icon using the "unity-seen" qdata, or unity will duplicate it on bamfdaemon respawn.

This needs lp:~3v1n0/bamf/lib-factory-xids-matching to properly work.

AP tests included.

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi,

Please try and replace the call() lines with this:

call("kill `pidof %s`" % (app['process-name']), shell=True)

Don't use pkill -f - it's dangerous. Once making these changes, please ensure that all the tests still pass.

130 + self.start_app("Calculator")
131 + self.start_app("System Settings")
132 + os.spawnlp(os.P_NOWAIT, "xterm", "xterm", "-title", "Autopilot XTerm", "-e", "sh")
133 + self.addCleanup(call, ["killall", "xterm"])
134 +
135 + # FIXME bamf emulator should wait until a window is open
136 + sleep(1)
137 + [xterm_win] = [w for w in self.bamf.get_open_windows() if w.name == "Autopilot XTerm"]
138 + self.assertTrue(xterm_win.is_focused)

Please put all this in a method called "start_test_apps or something similar, then call it from your test.

154 + same_desktop = [i for i in bamf_icons if i.desktop_file == icon.desktop_file]
155 + self.assertThat(len(same_desktop), Equals(1))

Can you use 'get_icon_by_desktop_file' on the launcher model, to avoid this?

157 + same_appid = [i for i in bamf_icons if i.application_id == icon.application_id]
158 + self.assertThat(len(same_appid), Equals(1))

Similar thing here... we should probable add something to the launcher model like this:

def get_icon_by_filter(self, **kwargs):
        """Gets a launcher icon that matches the filter specified.

        Returns None if there is no such launcher icon.
        """
        icons = self.get_children_by_type(SimpleLauncherIcon, **kwargs)
        if len(icons):
            return icons[0]

        return None

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/BamfLauncherIcon.cpp'
2--- plugins/unityshell/src/BamfLauncherIcon.cpp 2012-04-26 00:35:37 +0000
3+++ plugins/unityshell/src/BamfLauncherIcon.cpp 2012-04-26 04:05:20 +0000
4@@ -144,7 +144,7 @@
5 {
6 g_object_set_qdata(G_OBJECT(_bamf_app.RawPtr()),
7 g_quark_from_static_string("unity-seen"),
8- GINT_TO_POINTER(0));
9+ GUINT_TO_POINTER(0));
10
11 if (_fill_supported_types_id != 0)
12 g_source_remove(_fill_supported_types_id);
13@@ -491,6 +491,7 @@
14 variant::BuilderWrapper(builder)
15 .add("desktop_file", DesktopFile())
16 .add("desktop_id", GetDesktopID())
17+ .add("application_id", GPOINTER_TO_UINT(_bamf_app.RawPtr()))
18 .add("xids", g_variant_builder_end(&xids_builder))
19 .add("sticky", IsSticky());
20 }
21
22=== modified file 'plugins/unityshell/src/LauncherController.cpp'
23--- plugins/unityshell/src/LauncherController.cpp 2012-04-24 21:57:01 +0000
24+++ plugins/unityshell/src/LauncherController.cpp 2012-04-26 04:05:20 +0000
25@@ -740,6 +740,7 @@
26 return;
27 }
28
29+ g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GUINT_TO_POINTER(1));
30 AbstractLauncherIcon::Ptr icon(new BamfLauncherIcon(app));
31 icon->visibility_changed.connect(sigc::mem_fun(self, &Impl::SortAndUpdate));
32 icon->SetSortPriority(self->sort_priority_++);
33@@ -762,9 +763,8 @@
34 return result;
35 }
36
37- g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GINT_TO_POINTER(1));
38-
39 bamf_view_set_sticky(BAMF_VIEW(app), true);
40+ g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GUINT_TO_POINTER(1));
41 AbstractLauncherIcon::Ptr icon (new BamfLauncherIcon(app));
42 icon->SetSortPriority(sort_priority_++);
43 result = icon;
44@@ -790,6 +790,7 @@
45 }
46
47 bamf_view_set_sticky(BAMF_VIEW(app), true);
48+ g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GUINT_TO_POINTER(1));
49 result = new SoftwareCenterLauncherIcon(app, aptdaemon_trans_id, icon_path);
50 result->SetSortPriority(sort_priority_++);
51
52@@ -831,8 +832,8 @@
53
54 if (g_object_get_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen")))
55 continue;
56- g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GINT_TO_POINTER(1));
57
58+ g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GUINT_TO_POINTER(1));
59 AbstractLauncherIcon::Ptr icon(new BamfLauncherIcon(app));
60 icon->SetSortPriority(sort_priority_++);
61 RegisterIcon(icon);
62
63=== modified file 'tests/autopilot/autopilot/emulators/bamf.py'
64--- tests/autopilot/autopilot/emulators/bamf.py 2012-04-16 00:34:04 +0000
65+++ tests/autopilot/autopilot/emulators/bamf.py 2012-04-26 04:05:20 +0000
66@@ -254,6 +254,16 @@
67 return self._x_win
68
69 @property
70+ def name(self):
71+ """Get the window name.
72+
73+ Note: This may change according to the current locale. If you want a unique
74+ string to match windows against, use the x_id instead.
75+
76+ """
77+ return self._view_iface.Name()
78+
79+ @property
80 def title(self):
81 """Get the window title.
82
83
84=== modified file 'tests/autopilot/autopilot/tests/__init__.py'
85--- tests/autopilot/autopilot/tests/__init__.py 2012-04-24 22:26:55 +0000
86+++ tests/autopilot/autopilot/tests/__init__.py 2012-04-26 04:05:20 +0000
87@@ -224,6 +224,10 @@
88 'desktop-file': 'remmina.desktop',
89 'process-name': 'remmina',
90 },
91+ 'System Settings' : {
92+ 'desktop-file': 'gnome-control-center.desktop',
93+ 'process-name': 'gnome-control-center',
94+ },
95 'Text Editor' : {
96 'desktop-file': 'gedit.desktop',
97 'process-name': 'gedit',
98@@ -266,14 +270,14 @@
99 app = self.KNOWN_APPS[app_name]
100 self.bamf.launch_application(app['desktop-file'], files)
101 apps = self.bamf.get_running_applications_by_desktop_file(app['desktop-file'])
102- self.addCleanup(call, ["killall", app['process-name']])
103+ self.addCleanup(call, "kill `pidof %s`" % (app['process-name']), shell=True)
104 self.assertThat(len(apps), Equals(1))
105 return apps[0]
106
107 def close_all_app(self, app_name):
108 """Close all instances of the app_name."""
109 app = self.KNOWN_APPS[app_name]
110- call(["killall", app['process-name']])
111+ self.addCleanup(call, "kill `pidof %s`" % (app['process-name']), shell=True)
112 super(LoggedTestCase, self).tearDown()
113
114 def get_app_instances(self, app_name):
115
116=== modified file 'tests/autopilot/autopilot/tests/test_launcher.py'
117--- tests/autopilot/autopilot/tests/test_launcher.py 2012-04-23 16:41:53 +0000
118+++ tests/autopilot/autopilot/tests/test_launcher.py 2012-04-26 04:05:20 +0000
119@@ -8,9 +8,12 @@
120 # by the Free Software Foundation.
121
122 import logging
123+import os
124+from subprocess import call
125 from testtools.matchers import Equals, NotEquals, LessThan, GreaterThan
126 from time import sleep
127
128+from autopilot.emulators.bamf import Bamf
129 from autopilot.emulators.unity.icons import BFBLauncherIcon
130 from autopilot.emulators.X11 import ScreenGeometry
131 from autopilot.matchers import Eventually
132@@ -568,6 +571,40 @@
133 for icon in self.launcher.model.get_launcher_icons():
134 self.assertThat(icon.desaturated, Eventually(Equals(False)))
135
136+ def test_kill_bamfdaemon_does_not_duplicate_icons(self):
137+ """Killing bamfdaemon should not duplicate any launcher icon."""
138+ self.start_app("Calculator")
139+ self.start_app("System Settings")
140+ # We launch also xterm without using self.start_app since it's an application
141+ # without .desktop file.
142+ os.spawnlp(os.P_NOWAIT, "xterm", "xterm", "-title", "Autopilot XTerm", "-e", "sh")
143+ self.addCleanup(call, ["pkill", "xterm"])
144+
145+ # FIXME bamf emulator should wait until a window is open
146+ sleep(1)
147+ [xterm_win] = [w for w in self.bamf.get_open_windows() if w.name == "Autopilot XTerm"]
148+ self.assertTrue(xterm_win.is_focused)
149+
150+ call(["pkill", "bamfdaemon"])
151+ sleep(1)
152+
153+ # This should ensure that bamfdaemon is reloaded again
154+ self.bamf = Bamf()
155+ [calc] = self.get_app_instances("Calculator")
156+ calc_icon = self.launcher.model.get_icon_by_desktop_id(calc.desktop_file)
157+ self.launcher_instance.click_launcher_icon(calc_icon)
158+ sleep(1)
159+ self.assertTrue(calc.is_active)
160+
161+ bamf_icons = self.launcher.model.get_bamf_launcher_icons()
162+ for icon in bamf_icons:
163+ if len(icon.desktop_file):
164+ same_desktop = [i for i in bamf_icons if i.desktop_file == icon.desktop_file]
165+ self.assertThat(len(same_desktop), Equals(1))
166+
167+ same_appid = [i for i in bamf_icons if i.application_id == icon.application_id]
168+ self.assertThat(len(same_appid), Equals(1))
169+
170
171 class LauncherCaptureTests(AutopilotTestCase):
172 """Test the launchers ability to capture/not capture the mouse."""