Merge lp:~ted/indicator-applet/messages-blacklist into lp:indicator-applet/messages0.2
- messages-blacklist
- Merge into messages
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Barth | Needs Information | ||
Review via email: mp+10527@code.launchpad.net |
Commit message
Description of the change
Ted Gould (ted) wrote : | # |
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?
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
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 | 50 | static void remove_eclipses (AppMenuItem * ai); | 50 | static void remove_eclipses (AppMenuItem * ai); |
6 | 51 | static gboolean build_launcher (gpointer data); | 51 | static gboolean build_launcher (gpointer data); |
7 | 52 | static gboolean build_launchers (gpointer data); | 52 | static gboolean build_launchers (gpointer data); |
8 | 53 | static gboolean blacklist_init (gpointer data); | ||
9 | 54 | static gboolean blacklist_add (gpointer data); | ||
10 | 55 | static void blacklist_remove (const gchar * definition_file); | ||
11 | 56 | |||
12 | 57 | |||
13 | 58 | /* | ||
14 | 59 | * Server List | ||
15 | 60 | */ | ||
16 | 53 | 61 | ||
17 | 54 | typedef struct _serverList_t serverList_t; | 62 | typedef struct _serverList_t serverList_t; |
18 | 55 | struct _serverList_t { | 63 | struct _serverList_t { |
19 | @@ -86,6 +94,10 @@ | |||
20 | 86 | return g_strcmp0(pan, pbn); | 94 | return g_strcmp0(pan, pbn); |
21 | 87 | } | 95 | } |
22 | 88 | 96 | ||
23 | 97 | /* | ||
24 | 98 | * Item List | ||
25 | 99 | */ | ||
26 | 100 | |||
27 | 89 | typedef struct _imList_t imList_t; | 101 | typedef struct _imList_t imList_t; |
28 | 90 | struct _imList_t { | 102 | struct _imList_t { |
29 | 91 | IndicateListenerServer * server; | 103 | IndicateListenerServer * server; |
30 | @@ -124,6 +136,10 @@ | |||
31 | 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))); |
32 | 125 | } | 137 | } |
33 | 126 | 138 | ||
34 | 139 | /* | ||
35 | 140 | * Launcher List | ||
36 | 141 | */ | ||
37 | 142 | |||
38 | 127 | typedef struct _launcherList_t launcherList_t; | 143 | typedef struct _launcherList_t launcherList_t; |
39 | 128 | struct _launcherList_t { | 144 | struct _launcherList_t { |
40 | 129 | LauncherMenuItem * menuitem; | 145 | LauncherMenuItem * menuitem; |
41 | @@ -143,6 +159,128 @@ | |||
42 | 143 | return g_strcmp0(pan, pbn); | 159 | return g_strcmp0(pan, pbn); |
43 | 144 | } | 160 | } |
44 | 145 | 161 | ||
45 | 162 | /* | ||
46 | 163 | * Black List | ||
47 | 164 | */ | ||
48 | 165 | |||
49 | 166 | static GHashTable * blacklist = NULL; | ||
50 | 167 | |||
51 | 168 | /* Initialize the black list and start to setup | ||
52 | 169 | handlers for it. */ | ||
53 | 170 | static gboolean | ||
54 | 171 | blacklist_init (gpointer data) | ||
55 | 172 | { | ||
56 | 173 | blacklist = g_hash_table_new_full(g_str_hash, g_str_equal, | ||
57 | 174 | g_free, g_free); | ||
58 | 175 | |||
59 | 176 | gchar * blacklistdir = g_build_filename(g_get_user_config_dir(), USER_BLACKLIST_DIR, NULL); | ||
60 | 177 | g_debug("Looking at blacklist: %s", blacklistdir); | ||
61 | 178 | if (!g_file_test(blacklistdir, G_FILE_TEST_IS_DIR)) { | ||
62 | 179 | g_free(blacklistdir); | ||
63 | 180 | return FALSE; | ||
64 | 181 | } | ||
65 | 182 | |||
66 | 183 | GError * error = NULL; | ||
67 | 184 | GDir * dir = g_dir_open(blacklistdir, 0, &error); | ||
68 | 185 | if (dir == NULL) { | ||
69 | 186 | g_warning("Unable to open blacklist directory (%s): %s", blacklistdir, error->message); | ||
70 | 187 | g_error_free(error); | ||
71 | 188 | g_free(blacklistdir); | ||
72 | 189 | return FALSE; | ||
73 | 190 | } | ||
74 | 191 | |||
75 | 192 | const gchar * filename = NULL; | ||
76 | 193 | while ((filename = g_dir_read_name(dir)) != NULL) { | ||
77 | 194 | g_debug("Found file: %s", filename); | ||
78 | 195 | gchar * path = g_build_filename(blacklistdir, filename, NULL); | ||
79 | 196 | g_idle_add(blacklist_add, path); | ||
80 | 197 | } | ||
81 | 198 | |||
82 | 199 | g_dir_close(dir); | ||
83 | 200 | g_free(blacklistdir); | ||
84 | 201 | |||
85 | 202 | return FALSE; | ||
86 | 203 | } | ||
87 | 204 | |||
88 | 205 | /* Add a definition file into the black list and eclipse | ||
89 | 206 | and launchers that have the same file. */ | ||
90 | 207 | static gboolean | ||
91 | 208 | blacklist_add (gpointer udata) | ||
92 | 209 | { | ||
93 | 210 | gchar * definition_file = (gchar *)udata; | ||
94 | 211 | /* Dump the file */ | ||
95 | 212 | gchar * desktop; | ||
96 | 213 | g_file_get_contents(definition_file, &desktop, NULL, NULL); | ||
97 | 214 | if (desktop == NULL) { | ||
98 | 215 | g_warning("Couldn't get data out of: %s", definition_file); | ||
99 | 216 | return FALSE; | ||
100 | 217 | } | ||
101 | 218 | |||
102 | 219 | /* Clean up the data */ | ||
103 | 220 | gchar * trimdesktop = pango_trim_string(desktop); | ||
104 | 221 | g_free(desktop); | ||
105 | 222 | |||
106 | 223 | /* Check for conflicts */ | ||
107 | 224 | gpointer data = g_hash_table_lookup(blacklist, trimdesktop); | ||
108 | 225 | if (data != NULL) { | ||
109 | 226 | gchar * oldfile = (gchar *)data; | ||
110 | 227 | if (!g_strcmp0(oldfile, definition_file)) { | ||
111 | 228 | g_warning("Already added file '%s'", oldfile); | ||
112 | 229 | } else { | ||
113 | 230 | g_warning("Already have desktop file '%s' in blacklist file '%s' not adding from '%s'", trimdesktop, oldfile, definition_file); | ||
114 | 231 | } | ||
115 | 232 | |||
116 | 233 | g_free(trimdesktop); | ||
117 | 234 | g_free(definition_file); | ||
118 | 235 | return FALSE; | ||
119 | 236 | } | ||
120 | 237 | |||
121 | 238 | /* Actually blacklist this thing */ | ||
122 | 239 | g_hash_table_insert(blacklist, trimdesktop, definition_file); | ||
123 | 240 | g_debug("Adding Blacklist item '%s' for desktop '%s'", definition_file, trimdesktop); | ||
124 | 241 | |||
125 | 242 | /* Go through and eclipse folks */ | ||
126 | 243 | GList * launcher; | ||
127 | 244 | for (launcher = launcherList; launcher != NULL; launcher = launcher->next) { | ||
128 | 245 | launcherList_t * item = (launcherList_t *)launcher->data; | ||
129 | 246 | if (!g_strcmp0(trimdesktop, launcher_menu_item_get_desktop(item->menuitem))) { | ||
130 | 247 | launcher_menu_item_set_eclipsed(item->menuitem, TRUE); | ||
131 | 248 | } | ||
132 | 249 | } | ||
133 | 250 | |||
134 | 251 | blacklist_remove(NULL); | ||
135 | 252 | return FALSE; | ||
136 | 253 | } | ||
137 | 254 | |||
138 | 255 | /* Remove a black list item based on the definition file | ||
139 | 256 | and uneclipse those launchers blocked by it. */ | ||
140 | 257 | static void | ||
141 | 258 | blacklist_remove (const gchar * definition_file) | ||
142 | 259 | { | ||
143 | 260 | |||
144 | 261 | return; | ||
145 | 262 | } | ||
146 | 263 | |||
147 | 264 | /* Check to see if a particular desktop file is | ||
148 | 265 | in the blacklist. */ | ||
149 | 266 | static gboolean | ||
150 | 267 | blacklist_check (const gchar * desktop_file) | ||
151 | 268 | { | ||
152 | 269 | g_debug("Checking blacklist for: %s", desktop_file); | ||
153 | 270 | if (blacklist == NULL) return FALSE; | ||
154 | 271 | |||
155 | 272 | if (g_hash_table_lookup(blacklist, desktop_file)) { | ||
156 | 273 | g_debug("\tFound!"); | ||
157 | 274 | return TRUE; | ||
158 | 275 | } | ||
159 | 276 | |||
160 | 277 | return FALSE; | ||
161 | 278 | } | ||
162 | 279 | |||
163 | 280 | /* | ||
164 | 281 | * More code | ||
165 | 282 | */ | ||
166 | 283 | |||
167 | 146 | static void | 284 | static void |
168 | 147 | server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) | 285 | server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) |
169 | 148 | { | 286 | { |
170 | @@ -555,6 +693,8 @@ | |||
171 | 555 | const gchar * aidesktop = app_menu_item_get_desktop(ai); | 693 | const gchar * aidesktop = app_menu_item_get_desktop(ai); |
172 | 556 | if (aidesktop == NULL) return; | 694 | if (aidesktop == NULL) return; |
173 | 557 | 695 | ||
174 | 696 | if (blacklist_check(aidesktop)) return; | ||
175 | 697 | |||
176 | 558 | GList * llitem; | 698 | GList * llitem; |
177 | 559 | for (llitem = launcherList; llitem != NULL; llitem = llitem->next) { | 699 | for (llitem = launcherList; llitem != NULL; llitem = llitem->next) { |
178 | 560 | launcherList_t * ll = (launcherList_t *)llitem->data; | 700 | launcherList_t * ll = (launcherList_t *)llitem->data; |
179 | @@ -602,6 +742,10 @@ | |||
180 | 602 | dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem)); | 742 | dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem)); |
181 | 603 | resort_menu(root_menuitem); | 743 | resort_menu(root_menuitem); |
182 | 604 | 744 | ||
183 | 745 | if (blacklist_check(launcher_menu_item_get_desktop(ll->menuitem))) { | ||
184 | 746 | launcher_menu_item_set_eclipsed(ll->menuitem, TRUE); | ||
185 | 747 | } | ||
186 | 748 | |||
187 | 605 | return FALSE; | 749 | return FALSE; |
188 | 606 | } | 750 | } |
189 | 607 | 751 | ||
190 | @@ -612,12 +756,14 @@ | |||
191 | 612 | static gboolean | 756 | static gboolean |
192 | 613 | build_launchers (gpointer data) | 757 | build_launchers (gpointer data) |
193 | 614 | { | 758 | { |
195 | 615 | if (!g_file_test(SYSTEM_APPS_DIR, G_FILE_TEST_IS_DIR)) { | 759 | gchar * directory = (gchar *)data; |
196 | 760 | |||
197 | 761 | if (!g_file_test(directory, G_FILE_TEST_IS_DIR)) { | ||
198 | 616 | return FALSE; | 762 | return FALSE; |
199 | 617 | } | 763 | } |
200 | 618 | 764 | ||
201 | 619 | GError * error = NULL; | 765 | GError * error = NULL; |
203 | 620 | GDir * dir = g_dir_open(SYSTEM_APPS_DIR, 0, &error); | 766 | GDir * dir = g_dir_open(directory, 0, &error); |
204 | 621 | if (dir == NULL) { | 767 | if (dir == NULL) { |
205 | 622 | g_warning("Unable to open system apps directory: %s", error->message); | 768 | g_warning("Unable to open system apps directory: %s", error->message); |
206 | 623 | g_error_free(error); | 769 | g_error_free(error); |
207 | @@ -627,7 +773,7 @@ | |||
208 | 627 | const gchar * filename = NULL; | 773 | const gchar * filename = NULL; |
209 | 628 | while ((filename = g_dir_read_name(dir)) != NULL) { | 774 | while ((filename = g_dir_read_name(dir)) != NULL) { |
210 | 629 | g_debug("Found file: %s", filename); | 775 | g_debug("Found file: %s", filename); |
212 | 630 | gchar * path = g_build_filename(SYSTEM_APPS_DIR, filename, NULL); | 776 | gchar * path = g_build_filename(directory, filename, NULL); |
213 | 631 | g_idle_add(build_launcher, path); | 777 | g_idle_add(build_launcher, path); |
214 | 632 | } | 778 | } |
215 | 633 | 779 | ||
216 | @@ -670,10 +816,15 @@ | |||
217 | 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); |
218 | 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); |
219 | 672 | 818 | ||
221 | 673 | g_idle_add(build_launchers, NULL); | 819 | g_idle_add(blacklist_init, NULL); |
222 | 820 | g_idle_add(build_launchers, SYSTEM_APPS_DIR); | ||
223 | 821 | gchar * userdir = g_build_filename(g_get_user_config_dir(), USER_APPS_DIR, NULL); | ||
224 | 822 | g_idle_add(build_launchers, userdir); | ||
225 | 674 | 823 | ||
226 | 675 | mainloop = g_main_loop_new(NULL, FALSE); | 824 | mainloop = g_main_loop_new(NULL, FALSE); |
227 | 676 | g_main_loop_run(mainloop); | 825 | g_main_loop_run(mainloop); |
228 | 677 | 826 | ||
229 | 827 | g_free(userdir); | ||
230 | 828 | |||
231 | 678 | return 0; | 829 | return 0; |
232 | 679 | } | 830 | } |
This branch adds support for user based blacklists for the launchers as well as a user based configuration directory to add launchers.