Merge lp:~ted/indicator-applet/messages-blacklist into lp:indicator-applet/messages0.2

Proposed by Ted Gould
Status: Merged
Merge reported by: Ted Gould
Merged at revision: not available
Proposed branch: lp:~ted/indicator-applet/messages-blacklist
Merge into: lp:indicator-applet/messages0.2
Diff against target: None lines
To merge this branch: bzr merge lp:~ted/indicator-applet/messages-blacklist
Reviewer Review Type Date Requested Status
David Barth Needs Information
Review via email: mp+10527@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

This branch adds support for user based blacklists for the launchers as well as a user based configuration directory to add launchers.

Revision history for this message
David Barth (dbarth) wrote :

Looks good.

Some questions / remarks:
 * What's the spurious blacklist_remove (NULL) at the end of blacklist_add?
 * No support yet for removing an item from the blacklist? That can be landed later, though.
 * Nice use of the g_idle_add; i assume this is for when the blacklist will be dynamically edited by the user. Monitoring the directory, like for launchers?

review: Needs Information
Revision history for this message
Ted Gould (ted) wrote :

On Fri, 2009-08-21 at 13:46 +0000, David Barth wrote:
> * What's the spurious blacklist_remove (NULL) at the
> end of blacklist_add?

Compiler complains if there are functions that aren't used, but static.
And I wanted to have the prototype in there. It'll be removed when the
function does something :)

> * No support yet for removing an item from the blacklist?
> That can be landed later, though.

Yeah, since there is no directory monitoring, there is no one who can
remove things right now. That will be with the directory monitoring
branch (next)

> * Nice use of the g_idle_add; i assume this is for when the
> blacklist will be dynamically edited by the user. Monitoring
> the directory, like for launchers?

Exactly. So the idea is that we can use the same functions when we have
files popup and disappear.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/messages-service.c'
2--- src/messages-service.c 2009-08-20 03:54:33 +0000
3+++ src/messages-service.c 2009-08-21 01:52:12 +0000
4@@ -50,6 +50,14 @@
5 static void remove_eclipses (AppMenuItem * ai);
6 static gboolean build_launcher (gpointer data);
7 static gboolean build_launchers (gpointer data);
8+static gboolean blacklist_init (gpointer data);
9+static gboolean blacklist_add (gpointer data);
10+static void blacklist_remove (const gchar * definition_file);
11+
12+
13+/*
14+ * Server List
15+ */
16
17 typedef struct _serverList_t serverList_t;
18 struct _serverList_t {
19@@ -86,6 +94,10 @@
20 return g_strcmp0(pan, pbn);
21 }
22
23+/*
24+ * Item List
25+ */
26+
27 typedef struct _imList_t imList_t;
28 struct _imList_t {
29 IndicateListenerServer * server;
30@@ -124,6 +136,10 @@
31 return (gint)(im_menu_item_get_seconds(IM_MENU_ITEM(pb->menuitem)) - im_menu_item_get_seconds(IM_MENU_ITEM(pa->menuitem)));
32 }
33
34+/*
35+ * Launcher List
36+ */
37+
38 typedef struct _launcherList_t launcherList_t;
39 struct _launcherList_t {
40 LauncherMenuItem * menuitem;
41@@ -143,6 +159,128 @@
42 return g_strcmp0(pan, pbn);
43 }
44
45+/*
46+ * Black List
47+ */
48+
49+static GHashTable * blacklist = NULL;
50+
51+/* Initialize the black list and start to setup
52+ handlers for it. */
53+static gboolean
54+blacklist_init (gpointer data)
55+{
56+ blacklist = g_hash_table_new_full(g_str_hash, g_str_equal,
57+ g_free, g_free);
58+
59+ gchar * blacklistdir = g_build_filename(g_get_user_config_dir(), USER_BLACKLIST_DIR, NULL);
60+ g_debug("Looking at blacklist: %s", blacklistdir);
61+ if (!g_file_test(blacklistdir, G_FILE_TEST_IS_DIR)) {
62+ g_free(blacklistdir);
63+ return FALSE;
64+ }
65+
66+ GError * error = NULL;
67+ GDir * dir = g_dir_open(blacklistdir, 0, &error);
68+ if (dir == NULL) {
69+ g_warning("Unable to open blacklist directory (%s): %s", blacklistdir, error->message);
70+ g_error_free(error);
71+ g_free(blacklistdir);
72+ return FALSE;
73+ }
74+
75+ const gchar * filename = NULL;
76+ while ((filename = g_dir_read_name(dir)) != NULL) {
77+ g_debug("Found file: %s", filename);
78+ gchar * path = g_build_filename(blacklistdir, filename, NULL);
79+ g_idle_add(blacklist_add, path);
80+ }
81+
82+ g_dir_close(dir);
83+ g_free(blacklistdir);
84+
85+ return FALSE;
86+}
87+
88+/* Add a definition file into the black list and eclipse
89+ and launchers that have the same file. */
90+static gboolean
91+blacklist_add (gpointer udata)
92+{
93+ gchar * definition_file = (gchar *)udata;
94+ /* Dump the file */
95+ gchar * desktop;
96+ g_file_get_contents(definition_file, &desktop, NULL, NULL);
97+ if (desktop == NULL) {
98+ g_warning("Couldn't get data out of: %s", definition_file);
99+ return FALSE;
100+ }
101+
102+ /* Clean up the data */
103+ gchar * trimdesktop = pango_trim_string(desktop);
104+ g_free(desktop);
105+
106+ /* Check for conflicts */
107+ gpointer data = g_hash_table_lookup(blacklist, trimdesktop);
108+ if (data != NULL) {
109+ gchar * oldfile = (gchar *)data;
110+ if (!g_strcmp0(oldfile, definition_file)) {
111+ g_warning("Already added file '%s'", oldfile);
112+ } else {
113+ g_warning("Already have desktop file '%s' in blacklist file '%s' not adding from '%s'", trimdesktop, oldfile, definition_file);
114+ }
115+
116+ g_free(trimdesktop);
117+ g_free(definition_file);
118+ return FALSE;
119+ }
120+
121+ /* Actually blacklist this thing */
122+ g_hash_table_insert(blacklist, trimdesktop, definition_file);
123+ g_debug("Adding Blacklist item '%s' for desktop '%s'", definition_file, trimdesktop);
124+
125+ /* Go through and eclipse folks */
126+ GList * launcher;
127+ for (launcher = launcherList; launcher != NULL; launcher = launcher->next) {
128+ launcherList_t * item = (launcherList_t *)launcher->data;
129+ if (!g_strcmp0(trimdesktop, launcher_menu_item_get_desktop(item->menuitem))) {
130+ launcher_menu_item_set_eclipsed(item->menuitem, TRUE);
131+ }
132+ }
133+
134+ blacklist_remove(NULL);
135+ return FALSE;
136+}
137+
138+/* Remove a black list item based on the definition file
139+ and uneclipse those launchers blocked by it. */
140+static void
141+blacklist_remove (const gchar * definition_file)
142+{
143+
144+ return;
145+}
146+
147+/* Check to see if a particular desktop file is
148+ in the blacklist. */
149+static gboolean
150+blacklist_check (const gchar * desktop_file)
151+{
152+ g_debug("Checking blacklist for: %s", desktop_file);
153+ if (blacklist == NULL) return FALSE;
154+
155+ if (g_hash_table_lookup(blacklist, desktop_file)) {
156+ g_debug("\tFound!");
157+ return TRUE;
158+ }
159+
160+ return FALSE;
161+}
162+
163+/*
164+ * More code
165+ */
166+
167 static void
168 server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data)
169 {
170@@ -555,6 +693,8 @@
171 const gchar * aidesktop = app_menu_item_get_desktop(ai);
172 if (aidesktop == NULL) return;
173
174+ if (blacklist_check(aidesktop)) return;
175+
176 GList * llitem;
177 for (llitem = launcherList; llitem != NULL; llitem = llitem->next) {
178 launcherList_t * ll = (launcherList_t *)llitem->data;
179@@ -602,6 +742,10 @@
180 dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem));
181 resort_menu(root_menuitem);
182
183+ if (blacklist_check(launcher_menu_item_get_desktop(ll->menuitem))) {
184+ launcher_menu_item_set_eclipsed(ll->menuitem, TRUE);
185+ }
186+
187 return FALSE;
188 }
189
190@@ -612,12 +756,14 @@
191 static gboolean
192 build_launchers (gpointer data)
193 {
194- if (!g_file_test(SYSTEM_APPS_DIR, G_FILE_TEST_IS_DIR)) {
195+ gchar * directory = (gchar *)data;
196+
197+ if (!g_file_test(directory, G_FILE_TEST_IS_DIR)) {
198 return FALSE;
199 }
200
201 GError * error = NULL;
202- GDir * dir = g_dir_open(SYSTEM_APPS_DIR, 0, &error);
203+ GDir * dir = g_dir_open(directory, 0, &error);
204 if (dir == NULL) {
205 g_warning("Unable to open system apps directory: %s", error->message);
206 g_error_free(error);
207@@ -627,7 +773,7 @@
208 const gchar * filename = NULL;
209 while ((filename = g_dir_read_name(dir)) != NULL) {
210 g_debug("Found file: %s", filename);
211- gchar * path = g_build_filename(SYSTEM_APPS_DIR, filename, NULL);
212+ gchar * path = g_build_filename(directory, filename, NULL);
213 g_idle_add(build_launcher, path);
214 }
215
216@@ -670,10 +816,15 @@
217 g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), root_menuitem);
218 g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), root_menuitem);
219
220- g_idle_add(build_launchers, NULL);
221+ g_idle_add(blacklist_init, NULL);
222+ g_idle_add(build_launchers, SYSTEM_APPS_DIR);
223+ gchar * userdir = g_build_filename(g_get_user_config_dir(), USER_APPS_DIR, NULL);
224+ g_idle_add(build_launchers, userdir);
225
226 mainloop = g_main_loop_new(NULL, FALSE);
227 g_main_loop_run(mainloop);
228
229+ g_free(userdir);
230+
231 return 0;
232 }

Subscribers

People subscribed via source and target branches