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