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
=== modified file 'src/messages-service.c'
--- src/messages-service.c 2009-08-20 03:54:33 +0000
+++ src/messages-service.c 2009-08-21 01:52:12 +0000
@@ -50,6 +50,14 @@
50static void remove_eclipses (AppMenuItem * ai);50static void remove_eclipses (AppMenuItem * ai);
51static gboolean build_launcher (gpointer data);51static gboolean build_launcher (gpointer data);
52static gboolean build_launchers (gpointer data);52static gboolean build_launchers (gpointer data);
53static gboolean blacklist_init (gpointer data);
54static gboolean blacklist_add (gpointer data);
55static void blacklist_remove (const gchar * definition_file);
56
57
58/*
59 * Server List
60 */
5361
54typedef struct _serverList_t serverList_t;62typedef struct _serverList_t serverList_t;
55struct _serverList_t {63struct _serverList_t {
@@ -86,6 +94,10 @@
86 return g_strcmp0(pan, pbn);94 return g_strcmp0(pan, pbn);
87}95}
8896
97/*
98 * Item List
99 */
100
89typedef struct _imList_t imList_t;101typedef struct _imList_t imList_t;
90struct _imList_t {102struct _imList_t {
91 IndicateListenerServer * server;103 IndicateListenerServer * server;
@@ -124,6 +136,10 @@
124 return (gint)(im_menu_item_get_seconds(IM_MENU_ITEM(pb->menuitem)) - im_menu_item_get_seconds(IM_MENU_ITEM(pa->menuitem)));136 return (gint)(im_menu_item_get_seconds(IM_MENU_ITEM(pb->menuitem)) - im_menu_item_get_seconds(IM_MENU_ITEM(pa->menuitem)));
125}137}
126138
139/*
140 * Launcher List
141 */
142
127typedef struct _launcherList_t launcherList_t;143typedef struct _launcherList_t launcherList_t;
128struct _launcherList_t {144struct _launcherList_t {
129 LauncherMenuItem * menuitem;145 LauncherMenuItem * menuitem;
@@ -143,6 +159,128 @@
143 return g_strcmp0(pan, pbn);159 return g_strcmp0(pan, pbn);
144}160}
145161
162/*
163 * Black List
164 */
165
166static GHashTable * blacklist = NULL;
167
168/* Initialize the black list and start to setup
169 handlers for it. */
170static gboolean
171blacklist_init (gpointer data)
172{
173 blacklist = g_hash_table_new_full(g_str_hash, g_str_equal,
174 g_free, g_free);
175
176 gchar * blacklistdir = g_build_filename(g_get_user_config_dir(), USER_BLACKLIST_DIR, NULL);
177 g_debug("Looking at blacklist: %s", blacklistdir);
178 if (!g_file_test(blacklistdir, G_FILE_TEST_IS_DIR)) {
179 g_free(blacklistdir);
180 return FALSE;
181 }
182
183 GError * error = NULL;
184 GDir * dir = g_dir_open(blacklistdir, 0, &error);
185 if (dir == NULL) {
186 g_warning("Unable to open blacklist directory (%s): %s", blacklistdir, error->message);
187 g_error_free(error);
188 g_free(blacklistdir);
189 return FALSE;
190 }
191
192 const gchar * filename = NULL;
193 while ((filename = g_dir_read_name(dir)) != NULL) {
194 g_debug("Found file: %s", filename);
195 gchar * path = g_build_filename(blacklistdir, filename, NULL);
196 g_idle_add(blacklist_add, path);
197 }
198
199 g_dir_close(dir);
200 g_free(blacklistdir);
201
202 return FALSE;
203}
204
205/* Add a definition file into the black list and eclipse
206 and launchers that have the same file. */
207static gboolean
208blacklist_add (gpointer udata)
209{
210 gchar * definition_file = (gchar *)udata;
211 /* Dump the file */
212 gchar * desktop;
213 g_file_get_contents(definition_file, &desktop, NULL, NULL);
214 if (desktop == NULL) {
215 g_warning("Couldn't get data out of: %s", definition_file);
216 return FALSE;
217 }
218
219 /* Clean up the data */
220 gchar * trimdesktop = pango_trim_string(desktop);
221 g_free(desktop);
222
223 /* Check for conflicts */
224 gpointer data = g_hash_table_lookup(blacklist, trimdesktop);
225 if (data != NULL) {
226 gchar * oldfile = (gchar *)data;
227 if (!g_strcmp0(oldfile, definition_file)) {
228 g_warning("Already added file '%s'", oldfile);
229 } else {
230 g_warning("Already have desktop file '%s' in blacklist file '%s' not adding from '%s'", trimdesktop, oldfile, definition_file);
231 }
232
233 g_free(trimdesktop);
234 g_free(definition_file);
235 return FALSE;
236 }
237
238 /* Actually blacklist this thing */
239 g_hash_table_insert(blacklist, trimdesktop, definition_file);
240 g_debug("Adding Blacklist item '%s' for desktop '%s'", definition_file, trimdesktop);
241
242 /* Go through and eclipse folks */
243 GList * launcher;
244 for (launcher = launcherList; launcher != NULL; launcher = launcher->next) {
245 launcherList_t * item = (launcherList_t *)launcher->data;
246 if (!g_strcmp0(trimdesktop, launcher_menu_item_get_desktop(item->menuitem))) {
247 launcher_menu_item_set_eclipsed(item->menuitem, TRUE);
248 }
249 }
250
251 blacklist_remove(NULL);
252 return FALSE;
253}
254
255/* Remove a black list item based on the definition file
256 and uneclipse those launchers blocked by it. */
257static void
258blacklist_remove (const gchar * definition_file)
259{
260
261 return;
262}
263
264/* Check to see if a particular desktop file is
265 in the blacklist. */
266static gboolean
267blacklist_check (const gchar * desktop_file)
268{
269 g_debug("Checking blacklist for: %s", desktop_file);
270 if (blacklist == NULL) return FALSE;
271
272 if (g_hash_table_lookup(blacklist, desktop_file)) {
273 g_debug("\tFound!");
274 return TRUE;
275 }
276
277 return FALSE;
278}
279
280/*
281 * More code
282 */
283
146static void 284static void
147server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data)285server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data)
148{286{
@@ -555,6 +693,8 @@
555 const gchar * aidesktop = app_menu_item_get_desktop(ai);693 const gchar * aidesktop = app_menu_item_get_desktop(ai);
556 if (aidesktop == NULL) return;694 if (aidesktop == NULL) return;
557695
696 if (blacklist_check(aidesktop)) return;
697
558 GList * llitem;698 GList * llitem;
559 for (llitem = launcherList; llitem != NULL; llitem = llitem->next) {699 for (llitem = launcherList; llitem != NULL; llitem = llitem->next) {
560 launcherList_t * ll = (launcherList_t *)llitem->data;700 launcherList_t * ll = (launcherList_t *)llitem->data;
@@ -602,6 +742,10 @@
602 dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem));742 dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem));
603 resort_menu(root_menuitem);743 resort_menu(root_menuitem);
604744
745 if (blacklist_check(launcher_menu_item_get_desktop(ll->menuitem))) {
746 launcher_menu_item_set_eclipsed(ll->menuitem, TRUE);
747 }
748
605 return FALSE;749 return FALSE;
606}750}
607751
@@ -612,12 +756,14 @@
612static gboolean756static gboolean
613build_launchers (gpointer data)757build_launchers (gpointer data)
614{758{
615 if (!g_file_test(SYSTEM_APPS_DIR, G_FILE_TEST_IS_DIR)) {759 gchar * directory = (gchar *)data;
760
761 if (!g_file_test(directory, G_FILE_TEST_IS_DIR)) {
616 return FALSE;762 return FALSE;
617 }763 }
618764
619 GError * error = NULL;765 GError * error = NULL;
620 GDir * dir = g_dir_open(SYSTEM_APPS_DIR, 0, &error);766 GDir * dir = g_dir_open(directory, 0, &error);
621 if (dir == NULL) {767 if (dir == NULL) {
622 g_warning("Unable to open system apps directory: %s", error->message);768 g_warning("Unable to open system apps directory: %s", error->message);
623 g_error_free(error);769 g_error_free(error);
@@ -627,7 +773,7 @@
627 const gchar * filename = NULL;773 const gchar * filename = NULL;
628 while ((filename = g_dir_read_name(dir)) != NULL) {774 while ((filename = g_dir_read_name(dir)) != NULL) {
629 g_debug("Found file: %s", filename);775 g_debug("Found file: %s", filename);
630 gchar * path = g_build_filename(SYSTEM_APPS_DIR, filename, NULL);776 gchar * path = g_build_filename(directory, filename, NULL);
631 g_idle_add(build_launcher, path);777 g_idle_add(build_launcher, path);
632 }778 }
633779
@@ -670,10 +816,15 @@
670 g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), root_menuitem);816 g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), root_menuitem);
671 g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), root_menuitem);817 g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), root_menuitem);
672818
673 g_idle_add(build_launchers, NULL);819 g_idle_add(blacklist_init, NULL);
820 g_idle_add(build_launchers, SYSTEM_APPS_DIR);
821 gchar * userdir = g_build_filename(g_get_user_config_dir(), USER_APPS_DIR, NULL);
822 g_idle_add(build_launchers, userdir);
674823
675 mainloop = g_main_loop_new(NULL, FALSE);824 mainloop = g_main_loop_new(NULL, FALSE);
676 g_main_loop_run(mainloop);825 g_main_loop_run(mainloop);
677826
827 g_free(userdir);
828
678 return 0;829 return 0;
679}830}

Subscribers

People subscribed via source and target branches