Mercurial > pidgin.yaz
annotate src/gtkprivacy.c @ 7561:cdfdbabd3266
[gaim-migrate @ 8175]
Move conversation placement from a core pref to a UI pref.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Tue, 18 Nov 2003 23:24:05 +0000 |
parents | a230b7bca1fb |
children | 2a781d4178ba |
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 { | |
7165 | 224 gaim_gtk_privacy_dialog_hide(); |
6371 | 225 |
226 return 0; | |
227 } | |
228 | |
229 static void | |
230 select_account_cb(GtkWidget *dropdown, GaimAccount *account, | |
231 GaimGtkPrivacyDialog *dialog) | |
232 { | |
233 int i; | |
234 | |
235 dialog->account = account; | |
236 | |
237 for (i = 0; i < menu_entry_count; i++) { | |
238 if (menu_entries[i].num == account->perm_deny) { | |
239 gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), i); | |
240 break; | |
241 } | |
242 } | |
243 | |
244 rebuild_allow_list(dialog); | |
245 rebuild_block_list(dialog); | |
246 } | |
247 | |
248 static void | |
249 type_changed_cb(GtkOptionMenu *optmenu, GaimGtkPrivacyDialog *dialog) | |
250 { | |
251 int new_type = gtk_option_menu_get_history(optmenu); | |
252 | |
253 dialog->account->perm_deny = menu_entries[new_type].num; | |
254 serv_set_permit_deny(gaim_account_get_connection(dialog->account)); | |
255 gaim_blist_save(); | |
256 | |
257 gtk_widget_hide(dialog->allow_widget); | |
258 gtk_widget_hide(dialog->block_widget); | |
259 gtk_widget_hide(dialog->button_box); | |
260 | |
261 if (new_type == 2) { | |
262 gtk_widget_show(dialog->allow_widget); | |
263 gtk_widget_show(dialog->button_box); | |
264 dialog->in_allow_list = TRUE; | |
265 } | |
266 else if (new_type == 4) { | |
267 gtk_widget_show(dialog->block_widget); | |
268 gtk_widget_show(dialog->button_box); | |
269 dialog->in_allow_list = FALSE; | |
270 } | |
271 } | |
272 | |
273 static void | |
274 add_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
275 { | |
276 if (dialog->in_allow_list) | |
277 gaim_gtk_request_add_permit(dialog->account, NULL); | |
278 else | |
279 gaim_gtk_request_add_block(dialog->account, NULL); | |
280 } | |
281 | |
282 static void | |
283 remove_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
284 { | |
285 GtkTreeIter iter; | |
286 GtkTreeModel *model; | |
287 GtkTreeSelection *sel; | |
288 char *name; | |
289 | |
290 if (dialog->in_allow_list && dialog->allow_store == NULL) | |
291 return; | |
292 | |
293 if (!dialog->in_allow_list && dialog->block_store == NULL) | |
294 return; | |
295 | |
296 if (dialog->in_allow_list) { | |
297 model = GTK_TREE_MODEL(dialog->allow_store); | |
298 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->allow_list)); | |
299 } | |
300 else { | |
301 model = GTK_TREE_MODEL(dialog->block_store); | |
302 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->block_list)); | |
303 } | |
304 | |
305 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
306 gtk_tree_model_get(model, &iter, 0, &name, -1); | |
307 else | |
308 return; | |
309 | |
310 if (dialog->in_allow_list) { | |
6375
72023626d5b8
[gaim-migrate @ 6880]
Christian Hammond <chipx86@chipx86.com>
parents:
6374
diff
changeset
|
311 if (find_permit_block_by_name(dialog->account->permit, name)) |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
312 gaim_privacy_permit_remove(dialog->account, name, FALSE); |
6371 | 313 } |
314 else { | |
6375
72023626d5b8
[gaim-migrate @ 6880]
Christian Hammond <chipx86@chipx86.com>
parents:
6374
diff
changeset
|
315 if (find_permit_block_by_name(dialog->account->deny, name)) |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
316 gaim_privacy_deny_remove(dialog->account, name, FALSE); |
6371 | 317 } |
318 } | |
319 | |
320 static void | |
321 clear_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
322 { | |
323 } | |
324 | |
325 static void | |
7165 | 326 close_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) |
6371 | 327 { |
7165 | 328 gtk_widget_destroy(dialog->win); |
329 | |
6371 | 330 gaim_gtk_privacy_dialog_hide(); |
331 } | |
332 | |
6646
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
333 static gboolean |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
334 check_account_func(GaimAccount *account) |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
335 { |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
336 GaimConnection *gc = gaim_account_get_connection(account); |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
337 GaimPluginProtocolInfo *prpl_info = NULL; |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
338 |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
339 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
340 |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
341 return (prpl_info->set_permit_deny != NULL); |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
342 } |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
343 |
6371 | 344 static GaimGtkPrivacyDialog * |
345 privacy_dialog_new(void) | |
346 { | |
347 GaimGtkPrivacyDialog *dialog; | |
348 GaimConnection *gc; | |
349 GtkWidget *bbox; | |
350 GtkWidget *hbox; | |
351 GtkWidget *vbox; | |
352 GtkWidget *button; | |
353 GtkWidget *dropdown; | |
354 GtkWidget *label; | |
355 GtkWidget *menu; | |
356 GtkWidget *sep; | |
357 int selected = 0; | |
358 int i; | |
359 | |
360 dialog = g_new0(GaimGtkPrivacyDialog, 1); | |
361 | |
362 gc = (GaimConnection *)gaim_connections_get_all()->data; | |
363 dialog->account = gaim_connection_get_account(gc); | |
364 | |
365 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
366 gtk_window_set_resizable(GTK_WINDOW(dialog->win), FALSE); | |
367 gtk_window_set_role(GTK_WINDOW(dialog->win), "privacy"); | |
368 gtk_window_set_title(GTK_WINDOW(dialog->win), _("Privacy")); | |
369 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
370 | |
371 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
372 G_CALLBACK(destroy_cb), dialog); | |
373 | |
374 gtk_widget_realize(dialog->win); | |
375 | |
376 /* Main vbox */ | |
377 vbox = gtk_vbox_new(FALSE, 12); | |
378 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
379 gtk_widget_show(vbox); | |
380 | |
381 /* Description label */ | |
382 label = gtk_label_new( | |
383 _("Changes to privacy settings take effect immediately.")); | |
384 | |
385 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
386 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
387 gtk_widget_show(label); | |
388 | |
389 /* Hbox for the accounts drop-down and label. */ | |
390 hbox = gtk_hbox_new(FALSE, 12); | |
391 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
392 gtk_widget_show(hbox); | |
393 | |
394 /* "Set privacy for:" label */ | |
395 label = gtk_label_new(_("Set privacy for:")); | |
396 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
397 gtk_widget_show(label); | |
398 | |
399 /* Accounts drop-down */ | |
400 dropdown = gaim_gtk_account_option_menu_new(dialog->account, FALSE, | |
401 G_CALLBACK(select_account_cb), | |
6646
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
402 check_account_func, dialog); |
6371 | 403 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
404 gtk_widget_show(dropdown); | |
405 | |
406 /* Add the drop-down list with the allow/block types. */ | |
407 dialog->type_menu = gtk_option_menu_new(); | |
408 gtk_box_pack_start(GTK_BOX(vbox), dialog->type_menu, FALSE, FALSE, 0); | |
409 gtk_widget_show(dialog->type_menu); | |
410 | |
411 /* Build the menu for that. */ | |
412 menu = gtk_menu_new(); | |
413 | |
414 for (i = 0; i < menu_entry_count; i++) { | |
415 gaim_new_item(menu, _(menu_entries[i].text)); | |
416 | |
417 if (menu_entries[i].num == dialog->account->perm_deny) | |
418 selected = i; | |
419 } | |
420 | |
421 gtk_option_menu_set_menu(GTK_OPTION_MENU(dialog->type_menu), menu); | |
422 gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), selected); | |
423 | |
424 g_signal_connect(G_OBJECT(dialog->type_menu), "changed", | |
425 G_CALLBACK(type_changed_cb), dialog); | |
426 | |
427 /* Build the treeview for the allow list. */ | |
428 dialog->allow_widget = build_allow_list(dialog); | |
429 gtk_box_pack_start(GTK_BOX(vbox), dialog->allow_widget, TRUE, TRUE, 0); | |
430 | |
431 /* Build the treeview for the block list. */ | |
432 dialog->block_widget = build_block_list(dialog); | |
433 gtk_box_pack_start(GTK_BOX(vbox), dialog->block_widget, TRUE, TRUE, 0); | |
434 | |
435 /* Add the button box for Add, Remove, Clear */ | |
436 dialog->button_box = bbox = gtk_hbutton_box_new(); | |
437 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD); | |
438 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
439 | |
440 /* Add button */ | |
441 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
442 dialog->add_button = button; | |
443 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
444 gtk_widget_show(button); | |
445 | |
446 g_signal_connect(G_OBJECT(button), "clicked", | |
447 G_CALLBACK(add_cb), dialog); | |
448 | |
449 /* Remove button */ | |
450 button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); | |
451 dialog->remove_button = button; | |
452 gtk_widget_set_sensitive(button, FALSE); | |
453 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
454 gtk_widget_show(button); | |
455 | |
456 g_signal_connect(G_OBJECT(button), "clicked", | |
457 G_CALLBACK(remove_cb), dialog); | |
458 | |
459 /* Clear button */ | |
460 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
461 dialog->clear_button = button; | |
462 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
463 gtk_widget_show(button); | |
464 | |
465 g_signal_connect(G_OBJECT(button), "clicked", | |
466 G_CALLBACK(clear_cb), dialog); | |
467 | |
468 /* Separator */ | |
469 sep = gtk_hseparator_new(); | |
470 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
471 gtk_widget_show(sep); | |
472 | |
473 /* Another button box. */ | |
474 bbox = gtk_hbutton_box_new(); | |
475 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
476 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
477 gtk_widget_show(bbox); | |
478 | |
479 /* Close button */ | |
480 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
481 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
482 gtk_widget_show(button); | |
483 | |
484 g_signal_connect(G_OBJECT(button), "clicked", | |
485 G_CALLBACK(close_cb), dialog); | |
486 | |
487 if (dialog->account->perm_deny == 2) { | |
488 gtk_widget_show(dialog->allow_widget); | |
489 gtk_widget_show(dialog->button_box); | |
490 dialog->in_allow_list = TRUE; | |
491 } | |
492 else if (dialog->account->perm_deny == 4) { | |
493 gtk_widget_show(dialog->block_widget); | |
494 gtk_widget_show(dialog->button_box); | |
495 dialog->in_allow_list = FALSE; | |
496 } | |
497 | |
498 return dialog; | |
499 } | |
500 | |
501 void | |
502 gaim_gtk_privacy_dialog_show(void) | |
503 { | |
504 if (privacy_dialog == NULL) | |
505 privacy_dialog = privacy_dialog_new(); | |
506 | |
507 gtk_widget_show(privacy_dialog->win); | |
508 gdk_window_raise(privacy_dialog->win->window); | |
509 } | |
510 | |
511 void | |
512 gaim_gtk_privacy_dialog_hide(void) | |
513 { | |
514 if (privacy_dialog == NULL) | |
515 return; | |
516 | |
7165 | 517 g_free(privacy_dialog); |
6371 | 518 privacy_dialog = NULL; |
519 } | |
520 | |
521 static void | |
522 destroy_request_data(GaimGtkPrivacyRequestData *data) | |
523 { | |
524 if (data->name != NULL) | |
525 g_free(data->name); | |
526 | |
527 g_free(data); | |
528 } | |
529 | |
530 static void | |
531 confirm_permit_block_cb(GaimGtkPrivacyRequestData *data, int option) | |
532 { | |
533 if (data->block) | |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
534 gaim_privacy_deny_add(data->account, data->name, FALSE); |
6371 | 535 else |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
536 gaim_privacy_permit_add(data->account, data->name, FALSE); |
6371 | 537 |
538 destroy_request_data(data); | |
539 } | |
540 | |
541 static void | |
542 add_permit_block_cb(GaimGtkPrivacyRequestData *data, const char *name) | |
543 { | |
544 data->name = g_strdup(name); | |
545 | |
546 confirm_permit_block_cb(data, 0); | |
547 } | |
548 | |
549 void | |
550 gaim_gtk_request_add_permit(GaimAccount *account, const char *name) | |
551 { | |
552 GaimGtkPrivacyRequestData *data; | |
553 | |
554 g_return_if_fail(account != NULL); | |
555 | |
556 data = g_new0(GaimGtkPrivacyRequestData, 1); | |
557 data->account = account; | |
558 data->name = g_strdup(name); | |
559 data->block = FALSE; | |
560 | |
561 if (name == NULL) { | |
562 gaim_request_input(account, _("Permit User"), | |
563 _("Type a user you permit to contact you."), | |
564 _("Please enter the name of the user you wish to be " | |
565 "able to contact you."), | |
566 NULL, FALSE, FALSE, | |
567 _("Permit"), G_CALLBACK(add_permit_block_cb), | |
568 _("Cancel"), G_CALLBACK(destroy_request_data), | |
569 data); | |
570 } | |
571 else { | |
572 char *primary = g_strdup_printf(_("Allow %s to contact you?"), name); | |
573 char *secondary = | |
574 g_strdup_printf(_("Are you sure you wish to allow " | |
575 "%s to contact you?"), name); | |
576 | |
577 | |
578 gaim_request_action(account, _("Permit User"), primary, secondary, | |
579 0, data, 2, | |
580 _("Permit"), G_CALLBACK(confirm_permit_block_cb), | |
581 _("Cancel"), G_CALLBACK(destroy_request_data)); | |
582 | |
583 g_free(primary); | |
584 g_free(secondary); | |
585 } | |
586 } | |
587 | |
588 void | |
589 gaim_gtk_request_add_block(GaimAccount *account, const char *name) | |
590 { | |
591 GaimGtkPrivacyRequestData *data; | |
592 | |
593 g_return_if_fail(account != NULL); | |
594 | |
595 data = g_new0(GaimGtkPrivacyRequestData, 1); | |
596 data->account = account; | |
597 data->name = g_strdup(name); | |
598 data->block = TRUE; | |
599 | |
600 if (name == NULL) { | |
601 gaim_request_input(account, _("Block User"), | |
602 _("Type a user to block."), | |
603 _("Please enter the name of the user you wish to block."), | |
604 NULL, FALSE, FALSE, | |
605 _("Block"), G_CALLBACK(add_permit_block_cb), | |
606 _("Cancel"), G_CALLBACK(destroy_request_data), | |
607 data); | |
608 } | |
609 else { | |
610 char *primary = g_strdup_printf(_("Block %s?"), name); | |
611 char *secondary = | |
612 g_strdup_printf(_("Are you sure you want to block %s?"), name); | |
613 | |
614 gaim_request_action(account, _("Block User"), primary, secondary, | |
615 0, data, 2, | |
616 _("Block"), G_CALLBACK(confirm_permit_block_cb), | |
617 _("Cancel"), G_CALLBACK(destroy_request_data)); | |
618 | |
619 g_free(primary); | |
620 g_free(secondary); | |
621 } | |
622 } | |
623 | |
624 static void | |
625 gaim_gtk_permit_added_removed(GaimAccount *account, const char *name) | |
626 { | |
627 if (privacy_dialog != NULL) | |
628 rebuild_allow_list(privacy_dialog); | |
629 } | |
630 | |
631 static void | |
632 gaim_gtk_deny_added_removed(GaimAccount *account, const char *name) | |
633 { | |
634 if (privacy_dialog != NULL) | |
635 rebuild_block_list(privacy_dialog); | |
636 } | |
637 | |
638 static GaimPrivacyUiOps privacy_ops = | |
639 { | |
640 gaim_gtk_permit_added_removed, | |
641 gaim_gtk_permit_added_removed, | |
642 gaim_gtk_deny_added_removed, | |
643 gaim_gtk_deny_added_removed | |
644 }; | |
645 | |
646 GaimPrivacyUiOps * | |
647 gaim_gtk_privacy_get_ui_ops(void) | |
648 { | |
649 return &privacy_ops; | |
650 } | |
651 | |
652 void | |
653 gaim_gtk_privacy_init(void) | |
654 { | |
655 } |