Merge lp:~azzar1/unity/remove-tray-whitelist 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: 3134
Proposed branch: lp:~azzar1/unity/remove-tray-whitelist
Merge into: lp:unity
Diff against target: 236 lines (+82/-44)
6 files modified
.bzrignore (+1/-0)
com.canonical.Unity.gschema.xml (+0/-7)
panel/PanelTray.cpp (+13/-35)
panel/PanelTray.h (+2/-2)
tests/CMakeLists.txt (+1/-0)
tests/test_panel_tray.cpp (+65/-0)
To merge this branch: bzr merge lp:~azzar1/unity/remove-tray-whitelist
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+146841@code.launchpad.net

Commit message

Remove notification area whitelist.

Description of the change

== Problem ==
Bug #974480: Notification area whitelist is obsolete

== Tests ==
Unit test for filter function added.

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

please bzr add test_panel_tray.cpp

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

> please bzr add test_panel_tray.cpp

Sorry done.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-07-05 04:22:33 +0000
3+++ .bzrignore 2013-02-06 17:05:35 +0000
4@@ -4,3 +4,4 @@
5 .AUTHORS.sed
6 tests/autopilot/dist
7 tests/autopilot/unity.egg-info
8+.bzr-repo
9
10=== modified file 'com.canonical.Unity.gschema.xml'
11--- com.canonical.Unity.gschema.xml 2013-02-01 22:53:51 +0000
12+++ com.canonical.Unity.gschema.xml 2013-02-06 17:05:35 +0000
13@@ -54,13 +54,6 @@
14 <description>This is a detection key for the favorite migration script to know whether the needed migration is done or not.</description>
15 </key>
16 </schema>
17- <schema path="/com/canonical/unity/panel/" id="com.canonical.Unity.Panel" gettext-domain="unity">
18- <key type="as" name="systray-whitelist">
19- <default>[ 'JavaEmbeddedFrame', 'Wine', 'Update-notifier' ]</default>
20- <summary>List of client names, resource classes or wm classes to allow in the Panel's systray implementation.</summary>
21- <description>"" (empty) will not allow any tray icons, "all" will allow all tray icons, otherwise there will be an attempt to match each icon to a value here.</description>
22- </key>
23- </schema>
24 <schema path="/com/canonical/unity/devices/" id="com.canonical.Unity.Devices" gettext-domain="unity">
25 <key type="as" name="blacklist">
26 <default>[]</default>
27
28=== modified file 'panel/PanelTray.cpp'
29--- panel/PanelTray.cpp 2012-11-06 18:19:09 +0000
30+++ panel/PanelTray.cpp 2013-02-06 17:05:35 +0000
31@@ -17,6 +17,8 @@
32 * Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
33 */
34
35+#include <array>
36+
37 #include "PanelTray.h"
38 #include "unity-shared/PanelStyle.h"
39
40@@ -28,6 +30,7 @@
41 {
42 const std::string SETTINGS_NAME = "com.canonical.Unity.Panel";
43 const int PADDING = 3;
44+const std::array<std::string, 2> WHITELIST {{ "JavaEmbeddedFrame", "Wine" }};
45 }
46
47 namespace unity
48@@ -35,17 +38,10 @@
49
50 PanelTray::PanelTray()
51 : View(NUX_TRACKER_LOCATION)
52- , settings_(g_settings_new(SETTINGS_NAME.c_str()))
53 , window_(gtk_window_new(GTK_WINDOW_TOPLEVEL))
54- , whitelist_(g_settings_get_strv(settings_, "systray-whitelist"))
55 {
56 int panel_height = panel::Style::Instance().panel_height;
57
58- whitelist_changed_.Connect(settings_, "changed::systray-whitelist", [&] (GSettings*, gchar*) {
59- g_strfreev(whitelist_);
60- whitelist_ = g_settings_get_strv(settings_, "systray-whitelist");
61- });
62-
63 auto gtkwindow = glib::object_cast<GtkWindow>(window_);
64 gtk_window_set_type_hint(gtkwindow, GDK_WINDOW_TYPE_HINT_DOCK);
65 gtk_window_set_has_resize_grip(gtkwindow, FALSE);
66@@ -81,8 +77,6 @@
67
68 PanelTray::~PanelTray()
69 {
70- g_strfreev(whitelist_);
71-
72 if (gtk_widget_get_realized(window_))
73 {
74 // We call Release since we're deleting the window here manually,
75@@ -133,38 +127,13 @@
76
77 gboolean PanelTray::FilterTrayCallback(NaTray* tray, NaTrayChild* icon, PanelTray* self)
78 {
79- int i = 0;
80- bool accept = false;
81- const char *name = nullptr;
82-
83 glib::String title(na_tray_child_get_title(icon));
84
85 glib::String res_class;
86 glib::String res_name;
87 na_tray_child_get_wm_class(icon, &res_name, &res_class);
88
89- while ((name = self->whitelist_[i]))
90- {
91- if (g_strcmp0(name, "all") == 0)
92- {
93- accept = true;
94- break;
95- }
96- else if (!name || name[0] == '\0')
97- {
98- accept = false;
99- break;
100- }
101- else if ((title && g_str_has_prefix(title, name))
102- || (res_name && g_str_has_prefix(res_name, name))
103- || (res_class && g_str_has_prefix(res_class, name)))
104- {
105- accept = true;
106- break;
107- }
108-
109- i++;
110- }
111+ bool accept = FilterTray(title.Str(), res_name.Str(), res_class.Str());
112
113 if (accept)
114 {
115@@ -183,6 +152,15 @@
116 return accept ? TRUE : FALSE;
117 }
118
119+bool PanelTray::FilterTray(std::string const& title, std::string const& res_name, std::string const& res_class)
120+{
121+ for (auto const& item : WHITELIST)
122+ if (title.find(item) == 0 || res_name.find(item) == 0 || res_class.find(item) == 0)
123+ return true;
124+
125+ return false;
126+}
127+
128 void PanelTray::OnTrayIconRemoved(NaTrayManager* manager, NaTrayChild* removed)
129 {
130 for (auto child : children_)
131
132=== modified file 'panel/PanelTray.h'
133--- panel/PanelTray.h 2012-07-09 08:03:04 +0000
134+++ panel/PanelTray.h 2013-02-06 17:05:35 +0000
135@@ -46,6 +46,8 @@
136 void Sync();
137 Window xid();
138
139+ static bool FilterTray(std::string const& title, std::string const& res_name, std::string const& res_class);
140+
141 protected:
142 void Draw(nux::GraphicsEngine& gfx_content, bool force_draw);
143 std::string GetName() const;
144@@ -59,10 +61,8 @@
145
146 int WidthOfTray();
147
148- glib::Object<GSettings> settings_;
149 glib::Object<GtkWidget> window_;
150 glib::Object<NaTray> tray_;
151- char** whitelist_;
152
153 glib::Signal<void, GSettings*, gchar*> whitelist_changed_;
154 glib::Signal<gboolean, GtkWidget*, cairo_t*> draw_signal_;
155
156=== modified file 'tests/CMakeLists.txt'
157--- tests/CMakeLists.txt 2013-02-01 20:30:27 +0000
158+++ tests/CMakeLists.txt 2013-02-06 17:05:35 +0000
159@@ -217,6 +217,7 @@
160 test_panel_indicators_view.cpp
161 test_panel_menu_view.cpp
162 test_panel_style.cpp
163+ test_panel_tray.cpp
164 test_places_group.cpp
165 test_previews_application.cpp
166 test_previews_generic.cpp
167
168=== added file 'tests/test_panel_tray.cpp'
169--- tests/test_panel_tray.cpp 1970-01-01 00:00:00 +0000
170+++ tests/test_panel_tray.cpp 2013-02-06 17:05:35 +0000
171@@ -0,0 +1,65 @@
172+/*
173+ * Copyright 2013 Canonical Ltd.
174+ *
175+ * This program is free software: you can redistribute it and/or modify it
176+ * under the terms of the GNU General Public License version 3, as published
177+ * by the Free Software Foundation.
178+ *
179+ * This program is distributed in the hope that it will be useful, but
180+ * WITHOUT ANY WARRANTY; without even the implied warranties of
181+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
182+ * PURPOSE. See the GNU General Public License for more details.
183+ *
184+ * You should have received a copy of the GNU General Public License
185+ * version 3 along with this program. If not, see
186+ * <http://www.gnu.org/licenses/>
187+ *
188+ * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
189+ *
190+ */
191+
192+#include <gtest/gtest.h>
193+
194+#include "panel/PanelTray.h"
195+
196+ TEST(TestPanelTray, FilterTray)
197+ {
198+ EXPECT_TRUE(unity::PanelTray::FilterTray("JavaEmbeddedFrame", "", ""));
199+ EXPECT_TRUE(unity::PanelTray::FilterTray("", "JavaEmbeddedFrame", ""));
200+ EXPECT_TRUE(unity::PanelTray::FilterTray("", "", "JavaEmbeddedFrame"));
201+
202+ EXPECT_TRUE(unity::PanelTray::FilterTray("Wine", "", ""));
203+ EXPECT_TRUE(unity::PanelTray::FilterTray("", "Wine", ""));
204+ EXPECT_TRUE(unity::PanelTray::FilterTray("", "", "Wine"));
205+
206+ EXPECT_TRUE(unity::PanelTray::FilterTray("JavaEmbeddedFrameUbuntu", "", ""));
207+ EXPECT_TRUE(unity::PanelTray::FilterTray("", "JavaEmbeddedFrameUbuntu", ""));
208+ EXPECT_TRUE(unity::PanelTray::FilterTray("", "", "JavaEmbeddedFrameUbuntu"));
209+
210+ EXPECT_TRUE(unity::PanelTray::FilterTray("WineUbuntu", "", ""));
211+ EXPECT_TRUE(unity::PanelTray::FilterTray("", "WineUbuntu", ""));
212+ EXPECT_TRUE(unity::PanelTray::FilterTray("", "", "WineUbuntu"));
213+
214+ EXPECT_FALSE(unity::PanelTray::FilterTray("UbuntuJavaEmbeddedFrame", "", ""));
215+ EXPECT_FALSE(unity::PanelTray::FilterTray("", "UbuntuJavaEmbeddedFrame", ""));
216+ EXPECT_FALSE(unity::PanelTray::FilterTray("", "", "UbuntuJavaEmbeddedFrame"));
217+
218+ EXPECT_FALSE(unity::PanelTray::FilterTray("UbuntuWine", "", ""));
219+ EXPECT_FALSE(unity::PanelTray::FilterTray("", "UbuntuWine", ""));
220+ EXPECT_FALSE(unity::PanelTray::FilterTray("", "", "UbuntuWine"));
221+
222+ EXPECT_FALSE(unity::PanelTray::FilterTray("UbuntuJavaEmbeddedFrameUbuntu", "", ""));
223+ EXPECT_FALSE(unity::PanelTray::FilterTray("", "UbuntuJavaEmbeddedFrameUbuntu", ""));
224+ EXPECT_FALSE(unity::PanelTray::FilterTray("", "", "UbuntuJavaEmbeddedFrameUbuntu"));
225+
226+ EXPECT_FALSE(unity::PanelTray::FilterTray("UbuntuWineUbuntu", "", ""));
227+ EXPECT_FALSE(unity::PanelTray::FilterTray("", "UbuntuWineUbuntu", ""));
228+ EXPECT_FALSE(unity::PanelTray::FilterTray("", "", "UbuntuWineUbuntu"));
229+
230+ EXPECT_TRUE(unity::PanelTray::FilterTray("Wine", "Ubuntu", ""));
231+ EXPECT_TRUE(unity::PanelTray::FilterTray("Ubuntu", "JavaEmbeddedFrame", ""));
232+ EXPECT_TRUE(unity::PanelTray::FilterTray("Wine", "JavaEmbeddedFrame", "Ubuntu"));
233+
234+ EXPECT_FALSE(unity::PanelTray::FilterTray("Ubuntu", "Unity", "Hello world!"));
235+}
236+