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
=== modified file '.bzrignore'
--- .bzrignore 2012-07-05 04:22:33 +0000
+++ .bzrignore 2013-02-06 17:05:35 +0000
@@ -4,3 +4,4 @@
4.AUTHORS.sed4.AUTHORS.sed
5tests/autopilot/dist5tests/autopilot/dist
6tests/autopilot/unity.egg-info6tests/autopilot/unity.egg-info
7.bzr-repo
78
=== modified file 'com.canonical.Unity.gschema.xml'
--- com.canonical.Unity.gschema.xml 2013-02-01 22:53:51 +0000
+++ com.canonical.Unity.gschema.xml 2013-02-06 17:05:35 +0000
@@ -54,13 +54,6 @@
54 <description>This is a detection key for the favorite migration script to know whether the needed migration is done or not.</description>54 <description>This is a detection key for the favorite migration script to know whether the needed migration is done or not.</description>
55 </key>55 </key>
56 </schema>56 </schema>
57 <schema path="/com/canonical/unity/panel/" id="com.canonical.Unity.Panel" gettext-domain="unity">
58 <key type="as" name="systray-whitelist">
59 <default>[ 'JavaEmbeddedFrame', 'Wine', 'Update-notifier' ]</default>
60 <summary>List of client names, resource classes or wm classes to allow in the Panel's systray implementation.</summary>
61 <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>
62 </key>
63 </schema>
64 <schema path="/com/canonical/unity/devices/" id="com.canonical.Unity.Devices" gettext-domain="unity">57 <schema path="/com/canonical/unity/devices/" id="com.canonical.Unity.Devices" gettext-domain="unity">
65 <key type="as" name="blacklist">58 <key type="as" name="blacklist">
66 <default>[]</default>59 <default>[]</default>
6760
=== modified file 'panel/PanelTray.cpp'
--- panel/PanelTray.cpp 2012-11-06 18:19:09 +0000
+++ panel/PanelTray.cpp 2013-02-06 17:05:35 +0000
@@ -17,6 +17,8 @@
17 * Marco Trevisan (Treviño) <3v1n0@ubuntu.com>17 * Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
18 */18 */
1919
20#include <array>
21
20#include "PanelTray.h"22#include "PanelTray.h"
21#include "unity-shared/PanelStyle.h"23#include "unity-shared/PanelStyle.h"
2224
@@ -28,6 +30,7 @@
28{30{
29const std::string SETTINGS_NAME = "com.canonical.Unity.Panel";31const std::string SETTINGS_NAME = "com.canonical.Unity.Panel";
30const int PADDING = 3;32const int PADDING = 3;
33const std::array<std::string, 2> WHITELIST {{ "JavaEmbeddedFrame", "Wine" }};
31}34}
3235
33namespace unity36namespace unity
@@ -35,17 +38,10 @@
3538
36PanelTray::PanelTray()39PanelTray::PanelTray()
37 : View(NUX_TRACKER_LOCATION)40 : View(NUX_TRACKER_LOCATION)
38 , settings_(g_settings_new(SETTINGS_NAME.c_str()))
39 , window_(gtk_window_new(GTK_WINDOW_TOPLEVEL))41 , window_(gtk_window_new(GTK_WINDOW_TOPLEVEL))
40 , whitelist_(g_settings_get_strv(settings_, "systray-whitelist"))
41{42{
42 int panel_height = panel::Style::Instance().panel_height;43 int panel_height = panel::Style::Instance().panel_height;
4344
44 whitelist_changed_.Connect(settings_, "changed::systray-whitelist", [&] (GSettings*, gchar*) {
45 g_strfreev(whitelist_);
46 whitelist_ = g_settings_get_strv(settings_, "systray-whitelist");
47 });
48
49 auto gtkwindow = glib::object_cast<GtkWindow>(window_);45 auto gtkwindow = glib::object_cast<GtkWindow>(window_);
50 gtk_window_set_type_hint(gtkwindow, GDK_WINDOW_TYPE_HINT_DOCK);46 gtk_window_set_type_hint(gtkwindow, GDK_WINDOW_TYPE_HINT_DOCK);
51 gtk_window_set_has_resize_grip(gtkwindow, FALSE);47 gtk_window_set_has_resize_grip(gtkwindow, FALSE);
@@ -81,8 +77,6 @@
8177
82PanelTray::~PanelTray()78PanelTray::~PanelTray()
83{79{
84 g_strfreev(whitelist_);
85
86 if (gtk_widget_get_realized(window_))80 if (gtk_widget_get_realized(window_))
87 {81 {
88 // We call Release since we're deleting the window here manually,82 // We call Release since we're deleting the window here manually,
@@ -133,38 +127,13 @@
133127
134gboolean PanelTray::FilterTrayCallback(NaTray* tray, NaTrayChild* icon, PanelTray* self)128gboolean PanelTray::FilterTrayCallback(NaTray* tray, NaTrayChild* icon, PanelTray* self)
135{129{
136 int i = 0;
137 bool accept = false;
138 const char *name = nullptr;
139
140 glib::String title(na_tray_child_get_title(icon));130 glib::String title(na_tray_child_get_title(icon));
141131
142 glib::String res_class;132 glib::String res_class;
143 glib::String res_name;133 glib::String res_name;
144 na_tray_child_get_wm_class(icon, &res_name, &res_class);134 na_tray_child_get_wm_class(icon, &res_name, &res_class);
145135
146 while ((name = self->whitelist_[i]))136 bool accept = FilterTray(title.Str(), res_name.Str(), res_class.Str());
147 {
148 if (g_strcmp0(name, "all") == 0)
149 {
150 accept = true;
151 break;
152 }
153 else if (!name || name[0] == '\0')
154 {
155 accept = false;
156 break;
157 }
158 else if ((title && g_str_has_prefix(title, name))
159 || (res_name && g_str_has_prefix(res_name, name))
160 || (res_class && g_str_has_prefix(res_class, name)))
161 {
162 accept = true;
163 break;
164 }
165
166 i++;
167 }
168137
169 if (accept)138 if (accept)
170 {139 {
@@ -183,6 +152,15 @@
183 return accept ? TRUE : FALSE;152 return accept ? TRUE : FALSE;
184}153}
185154
155bool PanelTray::FilterTray(std::string const& title, std::string const& res_name, std::string const& res_class)
156{
157 for (auto const& item : WHITELIST)
158 if (title.find(item) == 0 || res_name.find(item) == 0 || res_class.find(item) == 0)
159 return true;
160
161 return false;
162}
163
186void PanelTray::OnTrayIconRemoved(NaTrayManager* manager, NaTrayChild* removed)164void PanelTray::OnTrayIconRemoved(NaTrayManager* manager, NaTrayChild* removed)
187{165{
188 for (auto child : children_)166 for (auto child : children_)
189167
=== modified file 'panel/PanelTray.h'
--- panel/PanelTray.h 2012-07-09 08:03:04 +0000
+++ panel/PanelTray.h 2013-02-06 17:05:35 +0000
@@ -46,6 +46,8 @@
46 void Sync();46 void Sync();
47 Window xid();47 Window xid();
4848
49 static bool FilterTray(std::string const& title, std::string const& res_name, std::string const& res_class);
50
49protected:51protected:
50 void Draw(nux::GraphicsEngine& gfx_content, bool force_draw);52 void Draw(nux::GraphicsEngine& gfx_content, bool force_draw);
51 std::string GetName() const;53 std::string GetName() const;
@@ -59,10 +61,8 @@
5961
60 int WidthOfTray();62 int WidthOfTray();
6163
62 glib::Object<GSettings> settings_;
63 glib::Object<GtkWidget> window_;64 glib::Object<GtkWidget> window_;
64 glib::Object<NaTray> tray_;65 glib::Object<NaTray> tray_;
65 char** whitelist_;
6666
67 glib::Signal<void, GSettings*, gchar*> whitelist_changed_;67 glib::Signal<void, GSettings*, gchar*> whitelist_changed_;
68 glib::Signal<gboolean, GtkWidget*, cairo_t*> draw_signal_;68 glib::Signal<gboolean, GtkWidget*, cairo_t*> draw_signal_;
6969
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2013-02-01 20:30:27 +0000
+++ tests/CMakeLists.txt 2013-02-06 17:05:35 +0000
@@ -217,6 +217,7 @@
217 test_panel_indicators_view.cpp217 test_panel_indicators_view.cpp
218 test_panel_menu_view.cpp218 test_panel_menu_view.cpp
219 test_panel_style.cpp219 test_panel_style.cpp
220 test_panel_tray.cpp
220 test_places_group.cpp221 test_places_group.cpp
221 test_previews_application.cpp222 test_previews_application.cpp
222 test_previews_generic.cpp223 test_previews_generic.cpp
223224
=== added file 'tests/test_panel_tray.cpp'
--- tests/test_panel_tray.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_panel_tray.cpp 2013-02-06 17:05:35 +0000
@@ -0,0 +1,65 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
18 *
19 */
20
21#include <gtest/gtest.h>
22
23#include "panel/PanelTray.h"
24
25 TEST(TestPanelTray, FilterTray)
26 {
27 EXPECT_TRUE(unity::PanelTray::FilterTray("JavaEmbeddedFrame", "", ""));
28 EXPECT_TRUE(unity::PanelTray::FilterTray("", "JavaEmbeddedFrame", ""));
29 EXPECT_TRUE(unity::PanelTray::FilterTray("", "", "JavaEmbeddedFrame"));
30
31 EXPECT_TRUE(unity::PanelTray::FilterTray("Wine", "", ""));
32 EXPECT_TRUE(unity::PanelTray::FilterTray("", "Wine", ""));
33 EXPECT_TRUE(unity::PanelTray::FilterTray("", "", "Wine"));
34
35 EXPECT_TRUE(unity::PanelTray::FilterTray("JavaEmbeddedFrameUbuntu", "", ""));
36 EXPECT_TRUE(unity::PanelTray::FilterTray("", "JavaEmbeddedFrameUbuntu", ""));
37 EXPECT_TRUE(unity::PanelTray::FilterTray("", "", "JavaEmbeddedFrameUbuntu"));
38
39 EXPECT_TRUE(unity::PanelTray::FilterTray("WineUbuntu", "", ""));
40 EXPECT_TRUE(unity::PanelTray::FilterTray("", "WineUbuntu", ""));
41 EXPECT_TRUE(unity::PanelTray::FilterTray("", "", "WineUbuntu"));
42
43 EXPECT_FALSE(unity::PanelTray::FilterTray("UbuntuJavaEmbeddedFrame", "", ""));
44 EXPECT_FALSE(unity::PanelTray::FilterTray("", "UbuntuJavaEmbeddedFrame", ""));
45 EXPECT_FALSE(unity::PanelTray::FilterTray("", "", "UbuntuJavaEmbeddedFrame"));
46
47 EXPECT_FALSE(unity::PanelTray::FilterTray("UbuntuWine", "", ""));
48 EXPECT_FALSE(unity::PanelTray::FilterTray("", "UbuntuWine", ""));
49 EXPECT_FALSE(unity::PanelTray::FilterTray("", "", "UbuntuWine"));
50
51 EXPECT_FALSE(unity::PanelTray::FilterTray("UbuntuJavaEmbeddedFrameUbuntu", "", ""));
52 EXPECT_FALSE(unity::PanelTray::FilterTray("", "UbuntuJavaEmbeddedFrameUbuntu", ""));
53 EXPECT_FALSE(unity::PanelTray::FilterTray("", "", "UbuntuJavaEmbeddedFrameUbuntu"));
54
55 EXPECT_FALSE(unity::PanelTray::FilterTray("UbuntuWineUbuntu", "", ""));
56 EXPECT_FALSE(unity::PanelTray::FilterTray("", "UbuntuWineUbuntu", ""));
57 EXPECT_FALSE(unity::PanelTray::FilterTray("", "", "UbuntuWineUbuntu"));
58
59 EXPECT_TRUE(unity::PanelTray::FilterTray("Wine", "Ubuntu", ""));
60 EXPECT_TRUE(unity::PanelTray::FilterTray("Ubuntu", "JavaEmbeddedFrame", ""));
61 EXPECT_TRUE(unity::PanelTray::FilterTray("Wine", "JavaEmbeddedFrame", "Ubuntu"));
62
63 EXPECT_FALSE(unity::PanelTray::FilterTray("Ubuntu", "Unity", "Hello world!"));
64}
65