Merge lp:~attente/unity-gtk-module/1243413 into lp:unity-gtk-module/14.04

Proposed by William Hua
Status: Merged
Approved by: Charles Kerr
Approved revision: 311
Merged at revision: 308
Proposed branch: lp:~attente/unity-gtk-module/1243413
Merge into: lp:unity-gtk-module/14.04
Diff against target: 171 lines (+96/-14)
6 files modified
configure.ac (+2/-0)
data/Makefile.am (+3/-0)
data/com.canonical.unity-gtk-module.gschema.xml (+15/-0)
debian/control (+1/-1)
debian/unity-gtk-module-common.install (+1/-0)
src/main.c (+74/-13)
To merge this branch: bzr merge lp:~attente/unity-gtk-module/1243413
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+195311@code.launchpad.net

Commit message

Add a GSettings schema that allows the user to set a blacklist and whitelist for unity-gtk-module (LP: #1243413).

Description of the change

Add a GSettings schema that allows the user to set a blacklist and whitelist for unity-gtk-module (LP: #1243413).

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :

Thank you for doing this!

Revision history for this message
Charles Kerr (charlesk) wrote :

Leaks

- in is_blacklisted(), the GSettings and GVariants are leaked if the code returns while looping through g_variant_iter_next()

Tweaks

- in is_blacklisted(), we reload the GSetting from disk each time is_blacklisted() is called -- sometimes even twice per call. Seems like we'd have less overhead if we loaded it once and kept it as a private field.

- in is_blacklisted(), code duplication where we get a GSettings value as a variant & walk it looking for a key. That duplication would go away if it was extracted into its own method.

review: Needs Fixing
lp:~attente/unity-gtk-module/1243413 updated
311. By William Hua

Fix leaks and remove duplicate code.

Revision history for this message
William Hua (attente) wrote :

Thanks Charles!

is_blacklisted is only called once when the module is first loaded. I'm thinking it's probably better to unref the GSettings object as soon as it's done with it rather than keeping it around for the life of the process. If you still disagree though, I'll fix it.

But agreed on your other points, hopefully those are fixed now.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Thanks for clarifying when is_blacklisted is called(), sounds good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2013-07-02 16:17:36 +0000
3+++ configure.ac 2013-11-15 20:04:12 +0000
4@@ -23,6 +23,8 @@
5
6 AM_PATH_PYTHON
7
8+GLIB_GSETTINGS
9+
10 AC_SUBST([GTK_VERSION], [$with_gtk])
11 AC_SUBST([GTK_MODULE_DIR], [$with_gtk_module_dir])
12
13
14=== modified file 'data/Makefile.am'
15--- data/Makefile.am 2013-07-02 16:17:36 +0000
16+++ data/Makefile.am 2013-11-15 20:04:12 +0000
17@@ -1,3 +1,6 @@
18+gsettings_SCHEMAS = com.canonical.unity-gtk-module.gschema.xml
19+@GSETTINGS_RULES@
20+
21 pkgconfigdir = $(libdir)/pkgconfig
22 pkgconfig_DATA = unity-gtk$(GTK_VERSION)-parser.pc
23
24
25=== added file 'data/com.canonical.unity-gtk-module.gschema.xml'
26--- data/com.canonical.unity-gtk-module.gschema.xml 1970-01-01 00:00:00 +0000
27+++ data/com.canonical.unity-gtk-module.gschema.xml 2013-11-15 20:04:12 +0000
28@@ -0,0 +1,15 @@
29+<?xml version="1.0" encoding="UTF-8"?>
30+<schemalist>
31+ <schema id="com.canonical.unity-gtk-module" path="/com/canonical/unity-gtk-module/">
32+ <key name="blacklist" type="as">
33+ <summary>Application blacklist</summary>
34+ <description>List of applications where unity-gtk-module should be disabled.</description>
35+ <default>[]</default>
36+ </key>
37+ <key name="whitelist" type="as">
38+ <summary>Application whitelist</summary>
39+ <description>List of applications where unity-gtk-module should be enabled.</description>
40+ <default>[]</default>
41+ </key>
42+ </schema>
43+</schemalist>
44
45=== modified file 'debian/control'
46--- debian/control 2013-07-16 10:42:29 +0000
47+++ debian/control 2013-11-15 20:04:12 +0000
48@@ -32,7 +32,7 @@
49 Description: Common files for GtkMenuShell D-Bus exporter
50 This GTK+ module exports GtkMenuShells over D-Bus.
51 .
52- This package contains common Xsession.d scripts.
53+ This package contains common data files.
54
55 Package: libunity-gtk2-parser0
56 Architecture: any
57
58=== modified file 'debian/unity-gtk-module-common.install'
59--- debian/unity-gtk-module-common.install 2013-07-02 16:21:42 +0000
60+++ debian/unity-gtk-module-common.install 2013-11-15 20:04:12 +0000
61@@ -1,1 +1,2 @@
62+usr/share/glib-2.0/schemas/*
63 usr/share/upstart/sessions/*
64
65=== modified file 'src/main.c'
66--- src/main.c 2013-10-31 21:15:16 +0000
67+++ src/main.c 2013-11-15 20:04:12 +0000
68@@ -21,6 +21,30 @@
69 #include <gdk/gdkx.h>
70 #include "unity-gtk-parser.h"
71
72+/*
73+ * Default list of apps which should not be patched.
74+ * Use xprop | grep CLASS to find the name to use.
75+ */
76+static const char * const BLACKLIST[] =
77+{
78+ "Eclipse",
79+ "acroread",
80+ "emacs",
81+ "emacs23",
82+ "emacs23-lucid",
83+ "emacs24",
84+ "emacs24-lucid",
85+ "freeciv",
86+ "freeciv-gtk2",
87+ "glade",
88+ "gwyddion",
89+ NULL
90+};
91+
92+#define UNITY_GTK_MODULE_SCHEMA "com.canonical.unity-gtk-module"
93+#define BLACKLIST_KEY "blacklist"
94+#define WHITELIST_KEY "whitelist"
95+
96 #define _GTK_UNIQUE_BUS_NAME "_GTK_UNIQUE_BUS_NAME"
97 #define _UNITY_OBJECT_PATH "_UNITY_OBJECT_PATH"
98 #define _GTK_MENUBAR_OBJECT_PATH "_GTK_MENUBAR_OBJECT_PATH"
99@@ -90,22 +114,59 @@
100 gint *natural_height);
101 #endif
102
103-/* Crude blacklist to avoid patching innocent apps.
104- Use xprop | grep CLASS to find the name to use */
105+static gboolean
106+is_string_in_array (const gchar *string,
107+ GVariant *array)
108+{
109+ GVariantIter iter;
110+ const gchar *element;
111+
112+ g_return_val_if_fail (array != NULL, FALSE);
113+ g_return_val_if_fail (g_variant_is_of_type (array, G_VARIANT_TYPE ("as")), FALSE);
114+
115+ g_variant_iter_init (&iter, array);
116+ while (g_variant_iter_next (&iter, "&s", &element))
117+ {
118+ if (g_strcmp0 (element, string) == 0)
119+ return TRUE;
120+ }
121+
122+ return FALSE;
123+}
124+
125+static gboolean
126+is_listed (const gchar *name,
127+ const gchar *key)
128+{
129+ GSettings *settings;
130+ GVariant *array;
131+ gboolean listed;
132+
133+ settings = g_settings_new (UNITY_GTK_MODULE_SCHEMA);
134+ array = g_settings_get_value (settings, key);
135+ listed = is_string_in_array (name, array);
136+
137+ g_variant_unref (array);
138+ g_object_unref (settings);
139+
140+ return listed;
141+}
142+
143 static gboolean
144 is_blacklisted (const gchar *name)
145 {
146- return g_strcmp0 (name, "Eclipse") == 0 ||
147- g_strcmp0 (name, "emacs") == 0 ||
148- g_strcmp0 (name, "emacs23") == 0 ||
149- g_strcmp0 (name, "emacs23-lucid") == 0 ||
150- g_strcmp0 (name, "emacs24") == 0 ||
151- g_strcmp0 (name, "emacs24-lucid") == 0 ||
152- g_strcmp0 (name, "freeciv") == 0 ||
153- g_strcmp0 (name, "freeciv-gtk2") == 0 ||
154- g_strcmp0 (name, "glade") == 0 ||
155- g_strcmp0 (name, "acroread") == 0 ||
156- g_strcmp0 (name, "gwyddion") == 0;
157+ guint n;
158+ guint i;
159+
160+ n = sizeof (BLACKLIST) / sizeof (const char *);
161+
162+ for (i = 0; i < n; i++)
163+ {
164+ if (g_strcmp0 (name, BLACKLIST[i]) == 0)
165+ return !is_listed (name, WHITELIST_KEY);
166+ }
167+
168+ return is_listed (name, BLACKLIST_KEY);
169 }
170
171 static gboolean

Subscribers

People subscribed via source and target branches