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