1 /*
2  * appmenu-gtk-module
3  * Copyright 2012 Canonical Ltd.
4  * Copyright (C) 2015-2017 Konstantin Pugin <ria.freelander@gmail.com>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Authors: Ryan Lortie <desrt@desrt.ca>
20  *          William Hua <william.hua@canonical.com>
21  *          Konstantin Pugin <ria.freelander@gmail.com>
22  *          Lester Carballo Perez <lestcape@gmail.com>
23  */
24 
25 #include <gtk/gtk.h>
26 
27 #include "blacklist.h"
28 #include "consts.h"
29 
30 static const char *const BLACKLIST[] = { "acroread",
31 	                                 "emacs",
32 	                                 "emacs23",
33 	                                 "emacs23-lucid",
34 	                                 "emacs24",
35 	                                 "emacs24-lucid",
36 	                                 "budgie-panel",
37 	                                 "mate-panel",
38 	                                 "mate-menu",
39 	                                 "vala-panel",
40 	                                 "wrapper-1.0",
41 	                                 "wrapper-2.0",
42 	                                 "indicator-applet",
43 	                                 "mate-indicator-applet",
44 	                                 "mate-indicator-applet-appmenu",
45 	                                 "mate-indicator-applet-complete",
46 	                                 "appmenu-mate",
47 	                                 NULL };
48 
is_string_in_array(const char * string,GVariant * array)49 static bool is_string_in_array(const char *string, GVariant *array)
50 {
51 	GVariantIter iter;
52 	char *element;
53 
54 	g_return_val_if_fail(array != NULL, false);
55 	g_return_val_if_fail(g_variant_is_of_type(array, G_VARIANT_TYPE("as")), false);
56 
57 	g_variant_iter_init(&iter, array);
58 	while (g_variant_iter_loop(&iter, "&s", &element))
59 	{
60 		if (g_strcmp0(element, string) == 0)
61 			return true;
62 	}
63 
64 	return false;
65 }
66 
is_listed(const char * name,const char * key)67 static bool is_listed(const char *name, const char *key)
68 {
69 	GSettings *settings       = g_settings_new(UNITY_GTK_MODULE_SCHEMA);
70 	g_autoptr(GVariant) array = g_settings_get_value(settings, key);
71 	bool listed               = is_string_in_array(name, array);
72 	g_clear_object(&settings);
73 	return listed;
74 }
75 
76 G_GNUC_INTERNAL
is_blacklisted(const char * name)77 bool is_blacklisted(const char *name)
78 {
79 	guint n;
80 	guint i;
81 
82 	n = sizeof(BLACKLIST) / sizeof(const char *);
83 
84 	for (i = 0; i < n; i++)
85 	{
86 		if (g_strcmp0(name, BLACKLIST[i]) == 0)
87 			return !is_listed(name, WHITELIST_KEY);
88 	}
89 
90 	return is_listed(name, BLACKLIST_KEY);
91 }
92