Mercurial > pidgin.yaz
annotate src/gtkprivacy.c @ 10284:f776e117c17b
[gaim-migrate @ 11454]
Several MSN memory leaks identified and fixed by Miah Gregory and Felipe
Contreras, plus my own fix for bug 1075347.
As normal, thank them for fixes, blame me for breakages.
Did I mention the new MSN icon? It rocks!
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Wed, 01 Dec 2004 02:30:47 +0000 |
parents | 946aa96fa103 |
children | 5879593a6a10 |
rev | line source |
---|---|
6371 | 1 /** |
2 * @file gtkprivacy.c GTK+ Privacy UI | |
3 * @ingroup gtkui | |
4 * | |
5 * gaim | |
6 * | |
8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
6371 | 10 * |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
9791 | 25 #include "internal.h" |
26 #include "gtkgaim.h" | |
6371 | 27 |
28 #include "connection.h" | |
29 #include "debug.h" | |
30 #include "privacy.h" | |
31 #include "request.h" | |
32 #include "util.h" | |
33 | |
34 #include "gtkprivacy.h" | |
35 #include "gtkutils.h" | |
36 | |
37 typedef struct | |
38 { | |
39 GtkWidget *win; | |
40 | |
41 GtkWidget *type_menu; | |
42 | |
43 GtkWidget *add_button; | |
44 GtkWidget *remove_button; | |
45 GtkWidget *clear_button; | |
46 | |
47 GtkWidget *button_box; | |
48 GtkWidget *allow_widget; | |
49 GtkWidget *block_widget; | |
50 | |
51 GtkListStore *allow_store; | |
52 GtkListStore *block_store; | |
53 | |
54 GtkWidget *allow_list; | |
55 GtkWidget *block_list; | |
56 | |
57 gboolean in_allow_list; | |
58 | |
59 GaimAccount *account; | |
60 | |
61 } GaimGtkPrivacyDialog; | |
62 | |
63 typedef struct | |
64 { | |
65 GaimAccount *account; | |
66 char *name; | |
67 gboolean block; | |
68 | |
69 } GaimGtkPrivacyRequestData; | |
70 | |
71 static struct | |
72 { | |
73 const char *text; | |
74 int num; | |
75 | |
76 } menu_entries[] = | |
77 { | |
8175 | 78 { N_("Allow all users to contact me"), GAIM_PRIVACY_ALLOW_ALL }, |
79 { N_("Allow only the users on my buddy list"), GAIM_PRIVACY_ALLOW_BUDDYLIST }, | |
80 { N_("Allow only the users below"), GAIM_PRIVACY_ALLOW_USERS }, | |
81 { N_("Block all users"), GAIM_PRIVACY_DENY_ALL }, | |
82 { N_("Block only the users below"), GAIM_PRIVACY_DENY_USERS } | |
6371 | 83 }; |
84 | |
85 static size_t menu_entry_count = sizeof(menu_entries) / sizeof(*menu_entries); | |
86 | |
87 static GaimGtkPrivacyDialog *privacy_dialog = NULL; | |
88 | |
89 static void | |
90 rebuild_allow_list(GaimGtkPrivacyDialog *dialog) | |
91 { | |
92 GSList *l; | |
93 GtkTreeIter iter; | |
94 | |
95 gtk_list_store_clear(dialog->allow_store); | |
96 | |
97 for (l = dialog->account->permit; l != NULL; l = l->next) { | |
98 gtk_list_store_append(dialog->allow_store, &iter); | |
99 gtk_list_store_set(dialog->allow_store, &iter, 0, l->data, -1); | |
100 } | |
101 } | |
102 | |
103 static void | |
104 rebuild_block_list(GaimGtkPrivacyDialog *dialog) | |
105 { | |
106 GSList *l; | |
107 GtkTreeIter iter; | |
108 | |
109 gtk_list_store_clear(dialog->block_store); | |
110 | |
111 for (l = dialog->account->deny; l != NULL; l = l->next) { | |
112 gtk_list_store_append(dialog->block_store, &iter); | |
113 gtk_list_store_set(dialog->block_store, &iter, 0, l->data, -1); | |
114 } | |
115 } | |
116 | |
117 static const char * | |
118 find_permit_block_by_name(GSList *list, const char *name) | |
119 { | |
120 const char *temp_name; | |
121 GSList *l; | |
122 | |
123 for (l = list; l != NULL; l = l->next) { | |
124 temp_name = (const char *)l->data; | |
125 | |
126 if (!gaim_utf8_strcasecmp(name, temp_name)) | |
127 return temp_name; | |
128 } | |
129 | |
130 return NULL; | |
131 } | |
132 | |
133 static void | |
134 user_selected_cb(GtkTreeSelection *sel, GaimGtkPrivacyDialog *dialog) | |
135 { | |
136 gtk_widget_set_sensitive(dialog->remove_button, TRUE); | |
137 } | |
138 | |
139 static GtkWidget * | |
140 build_list(GaimGtkPrivacyDialog *dialog, GtkListStore *model, | |
141 GtkWidget **ret_treeview) | |
142 { | |
143 GtkWidget *sw; | |
144 GtkWidget *treeview; | |
145 GtkCellRenderer *rend; | |
146 GtkTreeViewColumn *column; | |
147 GtkTreeSelection *sel; | |
148 | |
149 sw = gtk_scrolled_window_new(NULL, NULL); | |
150 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
7931 | 151 GTK_POLICY_AUTOMATIC, |
152 GTK_POLICY_ALWAYS); | |
153 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
6371 | 154 |
155 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | |
156 *ret_treeview = treeview; | |
157 | |
158 rend = gtk_cell_renderer_text_new(); | |
159 | |
160 column = gtk_tree_view_column_new_with_attributes(NULL, rend, | |
161 "text", 0, | |
162 NULL); | |
163 gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
164 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
165 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); | |
7931 | 166 gtk_container_add(GTK_CONTAINER(sw), treeview); |
6374
ca73fdf3eb38
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
167 |
6371 | 168 gtk_widget_show(treeview); |
169 | |
170 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | |
171 | |
172 g_signal_connect(G_OBJECT(sel), "changed", | |
173 G_CALLBACK(user_selected_cb), dialog); | |
174 | |
6374
ca73fdf3eb38
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
175 gtk_widget_set_size_request(sw, -1, 200); |
ca73fdf3eb38
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
176 |
6371 | 177 return sw; |
178 } | |
179 | |
180 static GtkWidget * | |
181 build_allow_list(GaimGtkPrivacyDialog *dialog) | |
182 { | |
183 GtkWidget *widget; | |
184 GtkWidget *list; | |
185 | |
186 dialog->allow_store = gtk_list_store_new(1, G_TYPE_STRING); | |
187 | |
188 widget = build_list(dialog, dialog->allow_store, &list); | |
189 | |
190 dialog->allow_list = list; | |
191 | |
192 rebuild_allow_list(dialog); | |
193 | |
194 return widget; | |
195 } | |
196 | |
197 static GtkWidget * | |
198 build_block_list(GaimGtkPrivacyDialog *dialog) | |
199 { | |
200 GtkWidget *widget; | |
201 GtkWidget *list; | |
202 | |
203 dialog->block_store = gtk_list_store_new(1, G_TYPE_STRING); | |
204 | |
205 widget = build_list(dialog, dialog->block_store, &list); | |
206 | |
207 dialog->block_list = list; | |
208 | |
209 rebuild_block_list(dialog); | |
210 | |
211 return widget; | |
212 } | |
213 | |
214 static gint | |
215 destroy_cb(GtkWidget *w, GdkEvent *event, GaimGtkPrivacyDialog *dialog) | |
216 { | |
7165 | 217 gaim_gtk_privacy_dialog_hide(); |
6371 | 218 |
219 return 0; | |
220 } | |
221 | |
222 static void | |
223 select_account_cb(GtkWidget *dropdown, GaimAccount *account, | |
224 GaimGtkPrivacyDialog *dialog) | |
225 { | |
226 int i; | |
227 | |
228 dialog->account = account; | |
229 | |
230 for (i = 0; i < menu_entry_count; i++) { | |
231 if (menu_entries[i].num == account->perm_deny) { | |
232 gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), i); | |
233 break; | |
234 } | |
235 } | |
236 | |
237 rebuild_allow_list(dialog); | |
238 rebuild_block_list(dialog); | |
239 } | |
240 | |
241 static void | |
242 type_changed_cb(GtkOptionMenu *optmenu, GaimGtkPrivacyDialog *dialog) | |
243 { | |
8275 | 244 int new_type = menu_entries[gtk_option_menu_get_history(optmenu)].num; |
6371 | 245 |
8520 | 246 dialog->account->perm_deny = new_type; |
6371 | 247 serv_set_permit_deny(gaim_account_get_connection(dialog->account)); |
248 | |
249 gtk_widget_hide(dialog->allow_widget); | |
250 gtk_widget_hide(dialog->block_widget); | |
251 gtk_widget_hide(dialog->button_box); | |
252 | |
8175 | 253 if (new_type == GAIM_PRIVACY_ALLOW_USERS) { |
6371 | 254 gtk_widget_show(dialog->allow_widget); |
255 gtk_widget_show(dialog->button_box); | |
256 dialog->in_allow_list = TRUE; | |
257 } | |
8175 | 258 else if (new_type == GAIM_PRIVACY_DENY_USERS) { |
6371 | 259 gtk_widget_show(dialog->block_widget); |
260 gtk_widget_show(dialog->button_box); | |
261 dialog->in_allow_list = FALSE; | |
262 } | |
10147 | 263 |
264 gaim_blist_sync(); | |
6371 | 265 } |
266 | |
267 static void | |
268 add_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
269 { | |
270 if (dialog->in_allow_list) | |
271 gaim_gtk_request_add_permit(dialog->account, NULL); | |
272 else | |
273 gaim_gtk_request_add_block(dialog->account, NULL); | |
274 } | |
275 | |
276 static void | |
277 remove_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
278 { | |
279 GtkTreeIter iter; | |
280 GtkTreeModel *model; | |
281 GtkTreeSelection *sel; | |
282 char *name; | |
283 | |
284 if (dialog->in_allow_list && dialog->allow_store == NULL) | |
285 return; | |
286 | |
287 if (!dialog->in_allow_list && dialog->block_store == NULL) | |
288 return; | |
289 | |
290 if (dialog->in_allow_list) { | |
291 model = GTK_TREE_MODEL(dialog->allow_store); | |
292 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->allow_list)); | |
293 } | |
294 else { | |
295 model = GTK_TREE_MODEL(dialog->block_store); | |
296 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->block_list)); | |
297 } | |
298 | |
299 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
300 gtk_tree_model_get(model, &iter, 0, &name, -1); | |
301 else | |
302 return; | |
303 | |
304 if (dialog->in_allow_list) { | |
6375
72023626d5b8
[gaim-migrate @ 6880]
Christian Hammond <chipx86@chipx86.com>
parents:
6374
diff
changeset
|
305 if (find_permit_block_by_name(dialog->account->permit, name)) |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
306 gaim_privacy_permit_remove(dialog->account, name, FALSE); |
6371 | 307 } |
308 else { | |
6375
72023626d5b8
[gaim-migrate @ 6880]
Christian Hammond <chipx86@chipx86.com>
parents:
6374
diff
changeset
|
309 if (find_permit_block_by_name(dialog->account->deny, name)) |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
310 gaim_privacy_deny_remove(dialog->account, name, FALSE); |
6371 | 311 } |
312 } | |
313 | |
314 static void | |
315 clear_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
316 { | |
8556 | 317 GSList *l; |
318 if (dialog->in_allow_list) | |
319 l = dialog->account->permit; | |
320 else | |
321 l = dialog->account->deny; | |
322 while (l) { | |
323 char *user; | |
324 user = l->data; | |
325 l = l->next; | |
326 if (dialog->in_allow_list) | |
327 gaim_privacy_permit_remove(dialog->account, user, FALSE); | |
328 else | |
329 gaim_privacy_deny_remove(dialog->account, user, FALSE); | |
330 } | |
6371 | 331 } |
332 | |
333 static void | |
7165 | 334 close_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) |
6371 | 335 { |
7165 | 336 gtk_widget_destroy(dialog->win); |
337 | |
6371 | 338 gaim_gtk_privacy_dialog_hide(); |
339 } | |
340 | |
6646
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
341 static gboolean |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
342 check_account_func(GaimAccount *account) |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
343 { |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
344 GaimConnection *gc = gaim_account_get_connection(account); |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
345 GaimPluginProtocolInfo *prpl_info = NULL; |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
346 |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
347 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
348 |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
349 return (prpl_info->set_permit_deny != NULL); |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
350 } |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
351 |
8938 | 352 gboolean |
353 gaim_gtk_privacy_is_showable() | |
354 { | |
355 GList *c; | |
356 GaimConnection *gc; | |
357 | |
358 for (c = gaim_connections_get_all(); c != NULL; c = c->next) { | |
359 gc = c->data; | |
360 | |
361 if (check_account_func(gaim_connection_get_account(gc))) | |
362 return TRUE; | |
363 } | |
364 | |
365 return FALSE; | |
366 } | |
367 | |
6371 | 368 static GaimGtkPrivacyDialog * |
369 privacy_dialog_new(void) | |
370 { | |
371 GaimGtkPrivacyDialog *dialog; | |
372 GtkWidget *bbox; | |
373 GtkWidget *hbox; | |
374 GtkWidget *vbox; | |
375 GtkWidget *button; | |
376 GtkWidget *dropdown; | |
377 GtkWidget *label; | |
378 GtkWidget *menu; | |
379 GtkWidget *sep; | |
380 int selected = 0; | |
381 int i; | |
382 | |
383 dialog = g_new0(GaimGtkPrivacyDialog, 1); | |
384 | |
385 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
386 gtk_window_set_resizable(GTK_WINDOW(dialog->win), FALSE); | |
387 gtk_window_set_role(GTK_WINDOW(dialog->win), "privacy"); | |
388 gtk_window_set_title(GTK_WINDOW(dialog->win), _("Privacy")); | |
389 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
390 | |
391 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
392 G_CALLBACK(destroy_cb), dialog); | |
393 | |
394 /* Main vbox */ | |
395 vbox = gtk_vbox_new(FALSE, 12); | |
396 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
397 gtk_widget_show(vbox); | |
398 | |
399 /* Description label */ | |
400 label = gtk_label_new( | |
401 _("Changes to privacy settings take effect immediately.")); | |
402 | |
403 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
404 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
405 gtk_widget_show(label); | |
406 | |
407 /* Hbox for the accounts drop-down and label. */ | |
408 hbox = gtk_hbox_new(FALSE, 12); | |
409 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
410 gtk_widget_show(hbox); | |
411 | |
412 /* "Set privacy for:" label */ | |
413 label = gtk_label_new(_("Set privacy for:")); | |
414 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
415 gtk_widget_show(label); | |
416 | |
417 /* Accounts drop-down */ | |
8940 | 418 dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE, |
6371 | 419 G_CALLBACK(select_account_cb), |
6646
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
420 check_account_func, dialog); |
6371 | 421 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
422 gtk_widget_show(dropdown); | |
8137 | 423 gaim_set_accessible_label (dropdown, label); |
8940 | 424 dialog->account = gaim_gtk_account_option_menu_get_selected(dropdown); |
6371 | 425 |
426 /* Add the drop-down list with the allow/block types. */ | |
427 dialog->type_menu = gtk_option_menu_new(); | |
428 gtk_box_pack_start(GTK_BOX(vbox), dialog->type_menu, FALSE, FALSE, 0); | |
429 gtk_widget_show(dialog->type_menu); | |
430 | |
431 /* Build the menu for that. */ | |
432 menu = gtk_menu_new(); | |
433 | |
434 for (i = 0; i < menu_entry_count; i++) { | |
435 gaim_new_item(menu, _(menu_entries[i].text)); | |
436 | |
437 if (menu_entries[i].num == dialog->account->perm_deny) | |
438 selected = i; | |
439 } | |
440 | |
441 gtk_option_menu_set_menu(GTK_OPTION_MENU(dialog->type_menu), menu); | |
442 gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), selected); | |
443 | |
444 g_signal_connect(G_OBJECT(dialog->type_menu), "changed", | |
445 G_CALLBACK(type_changed_cb), dialog); | |
446 | |
447 /* Build the treeview for the allow list. */ | |
448 dialog->allow_widget = build_allow_list(dialog); | |
449 gtk_box_pack_start(GTK_BOX(vbox), dialog->allow_widget, TRUE, TRUE, 0); | |
450 | |
451 /* Build the treeview for the block list. */ | |
452 dialog->block_widget = build_block_list(dialog); | |
453 gtk_box_pack_start(GTK_BOX(vbox), dialog->block_widget, TRUE, TRUE, 0); | |
454 | |
455 /* Add the button box for Add, Remove, Clear */ | |
456 dialog->button_box = bbox = gtk_hbutton_box_new(); | |
457 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD); | |
458 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
459 | |
460 /* Add button */ | |
461 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
462 dialog->add_button = button; | |
463 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
464 gtk_widget_show(button); | |
465 | |
466 g_signal_connect(G_OBJECT(button), "clicked", | |
467 G_CALLBACK(add_cb), dialog); | |
468 | |
469 /* Remove button */ | |
470 button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); | |
471 dialog->remove_button = button; | |
472 gtk_widget_set_sensitive(button, FALSE); | |
473 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
474 gtk_widget_show(button); | |
475 | |
476 g_signal_connect(G_OBJECT(button), "clicked", | |
477 G_CALLBACK(remove_cb), dialog); | |
478 | |
479 /* Clear button */ | |
480 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
481 dialog->clear_button = button; | |
482 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
483 gtk_widget_show(button); | |
484 | |
485 g_signal_connect(G_OBJECT(button), "clicked", | |
486 G_CALLBACK(clear_cb), dialog); | |
487 | |
488 /* Separator */ | |
489 sep = gtk_hseparator_new(); | |
490 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
491 gtk_widget_show(sep); | |
492 | |
493 /* Another button box. */ | |
494 bbox = gtk_hbutton_box_new(); | |
495 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
496 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
497 gtk_widget_show(bbox); | |
498 | |
499 /* Close button */ | |
500 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
501 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
502 gtk_widget_show(button); | |
503 | |
504 g_signal_connect(G_OBJECT(button), "clicked", | |
505 G_CALLBACK(close_cb), dialog); | |
506 | |
8175 | 507 if (dialog->account->perm_deny == GAIM_PRIVACY_ALLOW_USERS) { |
6371 | 508 gtk_widget_show(dialog->allow_widget); |
509 gtk_widget_show(dialog->button_box); | |
510 dialog->in_allow_list = TRUE; | |
511 } | |
8175 | 512 else if (dialog->account->perm_deny == GAIM_PRIVACY_DENY_USERS) { |
6371 | 513 gtk_widget_show(dialog->block_widget); |
514 gtk_widget_show(dialog->button_box); | |
515 dialog->in_allow_list = FALSE; | |
516 } | |
517 | |
518 return dialog; | |
519 } | |
520 | |
521 void | |
522 gaim_gtk_privacy_dialog_show(void) | |
523 { | |
524 if (privacy_dialog == NULL) | |
525 privacy_dialog = privacy_dialog_new(); | |
526 | |
527 gtk_widget_show(privacy_dialog->win); | |
528 gdk_window_raise(privacy_dialog->win->window); | |
529 } | |
530 | |
531 void | |
532 gaim_gtk_privacy_dialog_hide(void) | |
533 { | |
534 if (privacy_dialog == NULL) | |
535 return; | |
536 | |
7165 | 537 g_free(privacy_dialog); |
6371 | 538 privacy_dialog = NULL; |
539 } | |
540 | |
541 static void | |
542 destroy_request_data(GaimGtkPrivacyRequestData *data) | |
543 { | |
544 if (data->name != NULL) | |
545 g_free(data->name); | |
546 | |
547 g_free(data); | |
548 } | |
549 | |
550 static void | |
551 confirm_permit_block_cb(GaimGtkPrivacyRequestData *data, int option) | |
552 { | |
553 if (data->block) | |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
554 gaim_privacy_deny_add(data->account, data->name, FALSE); |
6371 | 555 else |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
556 gaim_privacy_permit_add(data->account, data->name, FALSE); |
6371 | 557 |
558 destroy_request_data(data); | |
559 } | |
560 | |
561 static void | |
562 add_permit_block_cb(GaimGtkPrivacyRequestData *data, const char *name) | |
563 { | |
564 data->name = g_strdup(name); | |
565 | |
566 confirm_permit_block_cb(data, 0); | |
567 } | |
568 | |
569 void | |
570 gaim_gtk_request_add_permit(GaimAccount *account, const char *name) | |
571 { | |
572 GaimGtkPrivacyRequestData *data; | |
573 | |
574 g_return_if_fail(account != NULL); | |
575 | |
576 data = g_new0(GaimGtkPrivacyRequestData, 1); | |
577 data->account = account; | |
578 data->name = g_strdup(name); | |
579 data->block = FALSE; | |
580 | |
581 if (name == NULL) { | |
582 gaim_request_input(account, _("Permit User"), | |
583 _("Type a user you permit to contact you."), | |
584 _("Please enter the name of the user you wish to be " | |
585 "able to contact you."), | |
8697 | 586 NULL, FALSE, FALSE, NULL, |
6371 | 587 _("Permit"), G_CALLBACK(add_permit_block_cb), |
588 _("Cancel"), G_CALLBACK(destroy_request_data), | |
589 data); | |
590 } | |
591 else { | |
592 char *primary = g_strdup_printf(_("Allow %s to contact you?"), name); | |
593 char *secondary = | |
594 g_strdup_printf(_("Are you sure you wish to allow " | |
595 "%s to contact you?"), name); | |
596 | |
597 | |
598 gaim_request_action(account, _("Permit User"), primary, secondary, | |
599 0, data, 2, | |
600 _("Permit"), G_CALLBACK(confirm_permit_block_cb), | |
601 _("Cancel"), G_CALLBACK(destroy_request_data)); | |
602 | |
603 g_free(primary); | |
604 g_free(secondary); | |
605 } | |
606 } | |
607 | |
608 void | |
609 gaim_gtk_request_add_block(GaimAccount *account, const char *name) | |
610 { | |
611 GaimGtkPrivacyRequestData *data; | |
612 | |
613 g_return_if_fail(account != NULL); | |
614 | |
615 data = g_new0(GaimGtkPrivacyRequestData, 1); | |
616 data->account = account; | |
617 data->name = g_strdup(name); | |
618 data->block = TRUE; | |
619 | |
620 if (name == NULL) { | |
621 gaim_request_input(account, _("Block User"), | |
622 _("Type a user to block."), | |
623 _("Please enter the name of the user you wish to block."), | |
8697 | 624 NULL, FALSE, FALSE, NULL, |
6371 | 625 _("Block"), G_CALLBACK(add_permit_block_cb), |
626 _("Cancel"), G_CALLBACK(destroy_request_data), | |
627 data); | |
628 } | |
629 else { | |
630 char *primary = g_strdup_printf(_("Block %s?"), name); | |
631 char *secondary = | |
632 g_strdup_printf(_("Are you sure you want to block %s?"), name); | |
633 | |
634 gaim_request_action(account, _("Block User"), primary, secondary, | |
635 0, data, 2, | |
636 _("Block"), G_CALLBACK(confirm_permit_block_cb), | |
637 _("Cancel"), G_CALLBACK(destroy_request_data)); | |
638 | |
639 g_free(primary); | |
640 g_free(secondary); | |
641 } | |
642 } | |
643 | |
644 static void | |
645 gaim_gtk_permit_added_removed(GaimAccount *account, const char *name) | |
646 { | |
647 if (privacy_dialog != NULL) | |
648 rebuild_allow_list(privacy_dialog); | |
649 } | |
650 | |
651 static void | |
652 gaim_gtk_deny_added_removed(GaimAccount *account, const char *name) | |
653 { | |
654 if (privacy_dialog != NULL) | |
655 rebuild_block_list(privacy_dialog); | |
656 } | |
657 | |
658 static GaimPrivacyUiOps privacy_ops = | |
659 { | |
660 gaim_gtk_permit_added_removed, | |
661 gaim_gtk_permit_added_removed, | |
662 gaim_gtk_deny_added_removed, | |
663 gaim_gtk_deny_added_removed | |
664 }; | |
665 | |
666 GaimPrivacyUiOps * | |
667 gaim_gtk_privacy_get_ui_ops(void) | |
668 { | |
669 return &privacy_ops; | |
670 } | |
671 | |
672 void | |
673 gaim_gtk_privacy_init(void) | |
674 { | |
675 } |