Mercurial > pidgin
annotate src/gtkprivacy.c @ 8150:20262ccefdd8
[gaim-migrate @ 8862]
Nope, it's humor. Trust me, I know--I define it.
Oh, also, this should make oscar ssi lists take precedence over
local lists. So if you sign on while you're in Rome and delete
someone, the next time you sign in with Gaim the dude will be
deleted from your local list as well.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 20 Jan 2004 15:27:33 +0000 |
parents | 4971193f761d |
children | f347c8d25cf5 |
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 */ | |
25 #include "gtkinternal.h" | |
26 | |
27 #include "connection.h" | |
28 #include "debug.h" | |
29 #include "privacy.h" | |
30 #include "request.h" | |
31 #include "util.h" | |
32 | |
33 #include "gtkprivacy.h" | |
34 #include "gtkutils.h" | |
35 | |
36 typedef enum | |
37 { | |
38 GAIM_GTK_PRIVACY_ALLOW_ALL = 0, | |
39 GAIM_GTK_PRIVACY_ALLOW_BUDDYLIST, | |
40 GAIM_GTK_PRIVACY_ALLOW_USERS, | |
41 GAIM_GTK_PRIVACY_DENY_ALL, | |
42 GAIM_GTK_PRIVACY_DENY_USERS | |
43 | |
44 } GaimGtkPrivacyType; | |
45 | |
46 typedef struct | |
47 { | |
48 GtkWidget *win; | |
49 | |
50 GtkWidget *type_menu; | |
51 | |
52 GtkWidget *add_button; | |
53 GtkWidget *remove_button; | |
54 GtkWidget *clear_button; | |
55 | |
56 GtkWidget *button_box; | |
57 GtkWidget *allow_widget; | |
58 GtkWidget *block_widget; | |
59 | |
60 GtkListStore *allow_store; | |
61 GtkListStore *block_store; | |
62 | |
63 GtkWidget *allow_list; | |
64 GtkWidget *block_list; | |
65 | |
66 gboolean in_allow_list; | |
67 | |
68 GaimAccount *account; | |
69 | |
70 } GaimGtkPrivacyDialog; | |
71 | |
72 typedef struct | |
73 { | |
74 GaimAccount *account; | |
75 char *name; | |
76 gboolean block; | |
77 | |
78 } GaimGtkPrivacyRequestData; | |
79 | |
80 static struct | |
81 { | |
82 const char *text; | |
83 int num; | |
84 | |
85 } menu_entries[] = | |
86 { | |
87 { N_("Allow all users to contact me"), 1 }, | |
88 { N_("Allow only the users on my buddy list"), 5 }, | |
89 { N_("Allow only the users below"), 3 }, | |
90 { N_("Block all users"), 2 }, | |
91 { N_("Block the users below"), 4 } | |
92 }; | |
93 | |
94 static size_t menu_entry_count = sizeof(menu_entries) / sizeof(*menu_entries); | |
95 | |
96 static GaimGtkPrivacyDialog *privacy_dialog = NULL; | |
97 | |
98 static void | |
99 rebuild_allow_list(GaimGtkPrivacyDialog *dialog) | |
100 { | |
101 GSList *l; | |
102 GtkTreeIter iter; | |
103 | |
104 gtk_list_store_clear(dialog->allow_store); | |
105 | |
106 for (l = dialog->account->permit; l != NULL; l = l->next) { | |
107 gtk_list_store_append(dialog->allow_store, &iter); | |
108 gtk_list_store_set(dialog->allow_store, &iter, 0, l->data, -1); | |
109 } | |
110 } | |
111 | |
112 static void | |
113 rebuild_block_list(GaimGtkPrivacyDialog *dialog) | |
114 { | |
115 GSList *l; | |
116 GtkTreeIter iter; | |
117 | |
118 gtk_list_store_clear(dialog->block_store); | |
119 | |
120 for (l = dialog->account->deny; l != NULL; l = l->next) { | |
121 gtk_list_store_append(dialog->block_store, &iter); | |
122 gtk_list_store_set(dialog->block_store, &iter, 0, l->data, -1); | |
123 } | |
124 } | |
125 | |
126 static const char * | |
127 find_permit_block_by_name(GSList *list, const char *name) | |
128 { | |
129 const char *temp_name; | |
130 GSList *l; | |
131 | |
132 for (l = list; l != NULL; l = l->next) { | |
133 temp_name = (const char *)l->data; | |
134 | |
135 if (!gaim_utf8_strcasecmp(name, temp_name)) | |
136 return temp_name; | |
137 } | |
138 | |
139 return NULL; | |
140 } | |
141 | |
142 static void | |
143 user_selected_cb(GtkTreeSelection *sel, GaimGtkPrivacyDialog *dialog) | |
144 { | |
145 gtk_widget_set_sensitive(dialog->remove_button, TRUE); | |
146 } | |
147 | |
148 static GtkWidget * | |
149 build_list(GaimGtkPrivacyDialog *dialog, GtkListStore *model, | |
150 GtkWidget **ret_treeview) | |
151 { | |
152 GtkWidget *sw; | |
153 GtkWidget *treeview; | |
154 GtkCellRenderer *rend; | |
155 GtkTreeViewColumn *column; | |
156 GtkTreeSelection *sel; | |
157 | |
158 sw = gtk_scrolled_window_new(NULL, NULL); | |
159 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
7931 | 160 GTK_POLICY_AUTOMATIC, |
161 GTK_POLICY_ALWAYS); | |
162 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
6371 | 163 |
164 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | |
165 *ret_treeview = treeview; | |
166 | |
167 rend = gtk_cell_renderer_text_new(); | |
168 | |
169 column = gtk_tree_view_column_new_with_attributes(NULL, rend, | |
170 "text", 0, | |
171 NULL); | |
172 gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
173 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
174 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); | |
7931 | 175 gtk_container_add(GTK_CONTAINER(sw), treeview); |
6374
ca73fdf3eb38
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
176 |
6371 | 177 gtk_widget_show(treeview); |
178 | |
179 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | |
180 | |
181 g_signal_connect(G_OBJECT(sel), "changed", | |
182 G_CALLBACK(user_selected_cb), dialog); | |
183 | |
6374
ca73fdf3eb38
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
184 gtk_widget_set_size_request(sw, -1, 200); |
ca73fdf3eb38
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
185 |
6371 | 186 return sw; |
187 } | |
188 | |
189 static GtkWidget * | |
190 build_allow_list(GaimGtkPrivacyDialog *dialog) | |
191 { | |
192 GtkWidget *widget; | |
193 GtkWidget *list; | |
194 | |
195 dialog->allow_store = gtk_list_store_new(1, G_TYPE_STRING); | |
196 | |
197 widget = build_list(dialog, dialog->allow_store, &list); | |
198 | |
199 dialog->allow_list = list; | |
200 | |
201 rebuild_allow_list(dialog); | |
202 | |
203 return widget; | |
204 } | |
205 | |
206 static GtkWidget * | |
207 build_block_list(GaimGtkPrivacyDialog *dialog) | |
208 { | |
209 GtkWidget *widget; | |
210 GtkWidget *list; | |
211 | |
212 dialog->block_store = gtk_list_store_new(1, G_TYPE_STRING); | |
213 | |
214 widget = build_list(dialog, dialog->block_store, &list); | |
215 | |
216 dialog->block_list = list; | |
217 | |
218 rebuild_block_list(dialog); | |
219 | |
220 return widget; | |
221 } | |
222 | |
223 static gint | |
224 destroy_cb(GtkWidget *w, GdkEvent *event, GaimGtkPrivacyDialog *dialog) | |
225 { | |
7165 | 226 gaim_gtk_privacy_dialog_hide(); |
6371 | 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 | |
7165 | 328 close_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) |
6371 | 329 { |
7165 | 330 gtk_widget_destroy(dialog->win); |
331 | |
6371 | 332 gaim_gtk_privacy_dialog_hide(); |
333 } | |
334 | |
6646
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
335 static gboolean |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
336 check_account_func(GaimAccount *account) |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
337 { |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
338 GaimConnection *gc = gaim_account_get_connection(account); |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
339 GaimPluginProtocolInfo *prpl_info = NULL; |
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 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); |
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 return (prpl_info->set_permit_deny != NULL); |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
344 } |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
345 |
6371 | 346 static GaimGtkPrivacyDialog * |
347 privacy_dialog_new(void) | |
348 { | |
349 GaimGtkPrivacyDialog *dialog; | |
350 GaimConnection *gc; | |
351 GtkWidget *bbox; | |
352 GtkWidget *hbox; | |
353 GtkWidget *vbox; | |
354 GtkWidget *button; | |
355 GtkWidget *dropdown; | |
356 GtkWidget *label; | |
357 GtkWidget *menu; | |
358 GtkWidget *sep; | |
359 int selected = 0; | |
360 int i; | |
361 | |
362 dialog = g_new0(GaimGtkPrivacyDialog, 1); | |
363 | |
364 gc = (GaimConnection *)gaim_connections_get_all()->data; | |
365 dialog->account = gaim_connection_get_account(gc); | |
366 | |
367 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
368 gtk_window_set_resizable(GTK_WINDOW(dialog->win), FALSE); | |
369 gtk_window_set_role(GTK_WINDOW(dialog->win), "privacy"); | |
370 gtk_window_set_title(GTK_WINDOW(dialog->win), _("Privacy")); | |
371 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
372 | |
373 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
374 G_CALLBACK(destroy_cb), dialog); | |
375 | |
376 gtk_widget_realize(dialog->win); | |
377 | |
378 /* Main vbox */ | |
379 vbox = gtk_vbox_new(FALSE, 12); | |
380 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
381 gtk_widget_show(vbox); | |
382 | |
383 /* Description label */ | |
384 label = gtk_label_new( | |
385 _("Changes to privacy settings take effect immediately.")); | |
386 | |
387 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
388 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
389 gtk_widget_show(label); | |
390 | |
391 /* Hbox for the accounts drop-down and label. */ | |
392 hbox = gtk_hbox_new(FALSE, 12); | |
393 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
394 gtk_widget_show(hbox); | |
395 | |
396 /* "Set privacy for:" label */ | |
397 label = gtk_label_new(_("Set privacy for:")); | |
398 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
399 gtk_widget_show(label); | |
400 | |
401 /* Accounts drop-down */ | |
402 dropdown = gaim_gtk_account_option_menu_new(dialog->account, FALSE, | |
403 G_CALLBACK(select_account_cb), | |
6646
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
404 check_account_func, dialog); |
6371 | 405 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
406 gtk_widget_show(dropdown); | |
8137 | 407 gaim_set_accessible_label (dropdown, label); |
6371 | 408 |
409 /* Add the drop-down list with the allow/block types. */ | |
410 dialog->type_menu = gtk_option_menu_new(); | |
411 gtk_box_pack_start(GTK_BOX(vbox), dialog->type_menu, FALSE, FALSE, 0); | |
412 gtk_widget_show(dialog->type_menu); | |
413 | |
414 /* Build the menu for that. */ | |
415 menu = gtk_menu_new(); | |
416 | |
417 for (i = 0; i < menu_entry_count; i++) { | |
418 gaim_new_item(menu, _(menu_entries[i].text)); | |
419 | |
420 if (menu_entries[i].num == dialog->account->perm_deny) | |
421 selected = i; | |
422 } | |
423 | |
424 gtk_option_menu_set_menu(GTK_OPTION_MENU(dialog->type_menu), menu); | |
425 gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), selected); | |
426 | |
427 g_signal_connect(G_OBJECT(dialog->type_menu), "changed", | |
428 G_CALLBACK(type_changed_cb), dialog); | |
429 | |
430 /* Build the treeview for the allow list. */ | |
431 dialog->allow_widget = build_allow_list(dialog); | |
432 gtk_box_pack_start(GTK_BOX(vbox), dialog->allow_widget, TRUE, TRUE, 0); | |
433 | |
434 /* Build the treeview for the block list. */ | |
435 dialog->block_widget = build_block_list(dialog); | |
436 gtk_box_pack_start(GTK_BOX(vbox), dialog->block_widget, TRUE, TRUE, 0); | |
437 | |
438 /* Add the button box for Add, Remove, Clear */ | |
439 dialog->button_box = bbox = gtk_hbutton_box_new(); | |
440 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD); | |
441 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
442 | |
443 /* Add button */ | |
444 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
445 dialog->add_button = button; | |
446 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
447 gtk_widget_show(button); | |
448 | |
449 g_signal_connect(G_OBJECT(button), "clicked", | |
450 G_CALLBACK(add_cb), dialog); | |
451 | |
452 /* Remove button */ | |
453 button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); | |
454 dialog->remove_button = button; | |
455 gtk_widget_set_sensitive(button, FALSE); | |
456 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
457 gtk_widget_show(button); | |
458 | |
459 g_signal_connect(G_OBJECT(button), "clicked", | |
460 G_CALLBACK(remove_cb), dialog); | |
461 | |
462 /* Clear button */ | |
463 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
464 dialog->clear_button = button; | |
465 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
466 gtk_widget_show(button); | |
467 | |
468 g_signal_connect(G_OBJECT(button), "clicked", | |
469 G_CALLBACK(clear_cb), dialog); | |
470 | |
471 /* Separator */ | |
472 sep = gtk_hseparator_new(); | |
473 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
474 gtk_widget_show(sep); | |
475 | |
476 /* Another button box. */ | |
477 bbox = gtk_hbutton_box_new(); | |
478 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
479 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
480 gtk_widget_show(bbox); | |
481 | |
482 /* Close button */ | |
483 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
484 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
485 gtk_widget_show(button); | |
486 | |
487 g_signal_connect(G_OBJECT(button), "clicked", | |
488 G_CALLBACK(close_cb), dialog); | |
489 | |
490 if (dialog->account->perm_deny == 2) { | |
491 gtk_widget_show(dialog->allow_widget); | |
492 gtk_widget_show(dialog->button_box); | |
493 dialog->in_allow_list = TRUE; | |
494 } | |
495 else if (dialog->account->perm_deny == 4) { | |
496 gtk_widget_show(dialog->block_widget); | |
497 gtk_widget_show(dialog->button_box); | |
498 dialog->in_allow_list = FALSE; | |
499 } | |
500 | |
501 return dialog; | |
502 } | |
503 | |
504 void | |
505 gaim_gtk_privacy_dialog_show(void) | |
506 { | |
507 if (privacy_dialog == NULL) | |
508 privacy_dialog = privacy_dialog_new(); | |
509 | |
510 gtk_widget_show(privacy_dialog->win); | |
511 gdk_window_raise(privacy_dialog->win->window); | |
512 } | |
513 | |
514 void | |
515 gaim_gtk_privacy_dialog_hide(void) | |
516 { | |
517 if (privacy_dialog == NULL) | |
518 return; | |
519 | |
7165 | 520 g_free(privacy_dialog); |
6371 | 521 privacy_dialog = NULL; |
522 } | |
523 | |
524 static void | |
525 destroy_request_data(GaimGtkPrivacyRequestData *data) | |
526 { | |
527 if (data->name != NULL) | |
528 g_free(data->name); | |
529 | |
530 g_free(data); | |
531 } | |
532 | |
533 static void | |
534 confirm_permit_block_cb(GaimGtkPrivacyRequestData *data, int option) | |
535 { | |
536 if (data->block) | |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
537 gaim_privacy_deny_add(data->account, data->name, FALSE); |
6371 | 538 else |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
539 gaim_privacy_permit_add(data->account, data->name, FALSE); |
6371 | 540 |
541 destroy_request_data(data); | |
542 } | |
543 | |
544 static void | |
545 add_permit_block_cb(GaimGtkPrivacyRequestData *data, const char *name) | |
546 { | |
547 data->name = g_strdup(name); | |
548 | |
549 confirm_permit_block_cb(data, 0); | |
550 } | |
551 | |
552 void | |
553 gaim_gtk_request_add_permit(GaimAccount *account, const char *name) | |
554 { | |
555 GaimGtkPrivacyRequestData *data; | |
556 | |
557 g_return_if_fail(account != NULL); | |
558 | |
559 data = g_new0(GaimGtkPrivacyRequestData, 1); | |
560 data->account = account; | |
561 data->name = g_strdup(name); | |
562 data->block = FALSE; | |
563 | |
564 if (name == NULL) { | |
565 gaim_request_input(account, _("Permit User"), | |
566 _("Type a user you permit to contact you."), | |
567 _("Please enter the name of the user you wish to be " | |
568 "able to contact you."), | |
569 NULL, FALSE, FALSE, | |
570 _("Permit"), G_CALLBACK(add_permit_block_cb), | |
571 _("Cancel"), G_CALLBACK(destroy_request_data), | |
572 data); | |
573 } | |
574 else { | |
575 char *primary = g_strdup_printf(_("Allow %s to contact you?"), name); | |
576 char *secondary = | |
577 g_strdup_printf(_("Are you sure you wish to allow " | |
578 "%s to contact you?"), name); | |
579 | |
580 | |
581 gaim_request_action(account, _("Permit User"), primary, secondary, | |
582 0, data, 2, | |
583 _("Permit"), G_CALLBACK(confirm_permit_block_cb), | |
584 _("Cancel"), G_CALLBACK(destroy_request_data)); | |
585 | |
586 g_free(primary); | |
587 g_free(secondary); | |
588 } | |
589 } | |
590 | |
591 void | |
592 gaim_gtk_request_add_block(GaimAccount *account, const char *name) | |
593 { | |
594 GaimGtkPrivacyRequestData *data; | |
595 | |
596 g_return_if_fail(account != NULL); | |
597 | |
598 data = g_new0(GaimGtkPrivacyRequestData, 1); | |
599 data->account = account; | |
600 data->name = g_strdup(name); | |
601 data->block = TRUE; | |
602 | |
603 if (name == NULL) { | |
604 gaim_request_input(account, _("Block User"), | |
605 _("Type a user to block."), | |
606 _("Please enter the name of the user you wish to block."), | |
607 NULL, FALSE, FALSE, | |
608 _("Block"), G_CALLBACK(add_permit_block_cb), | |
609 _("Cancel"), G_CALLBACK(destroy_request_data), | |
610 data); | |
611 } | |
612 else { | |
613 char *primary = g_strdup_printf(_("Block %s?"), name); | |
614 char *secondary = | |
615 g_strdup_printf(_("Are you sure you want to block %s?"), name); | |
616 | |
617 gaim_request_action(account, _("Block User"), primary, secondary, | |
618 0, data, 2, | |
619 _("Block"), G_CALLBACK(confirm_permit_block_cb), | |
620 _("Cancel"), G_CALLBACK(destroy_request_data)); | |
621 | |
622 g_free(primary); | |
623 g_free(secondary); | |
624 } | |
625 } | |
626 | |
627 static void | |
628 gaim_gtk_permit_added_removed(GaimAccount *account, const char *name) | |
629 { | |
630 if (privacy_dialog != NULL) | |
631 rebuild_allow_list(privacy_dialog); | |
632 } | |
633 | |
634 static void | |
635 gaim_gtk_deny_added_removed(GaimAccount *account, const char *name) | |
636 { | |
637 if (privacy_dialog != NULL) | |
638 rebuild_block_list(privacy_dialog); | |
639 } | |
640 | |
641 static GaimPrivacyUiOps privacy_ops = | |
642 { | |
643 gaim_gtk_permit_added_removed, | |
644 gaim_gtk_permit_added_removed, | |
645 gaim_gtk_deny_added_removed, | |
646 gaim_gtk_deny_added_removed | |
647 }; | |
648 | |
649 GaimPrivacyUiOps * | |
650 gaim_gtk_privacy_get_ui_ops(void) | |
651 { | |
652 return &privacy_ops; | |
653 } | |
654 | |
655 void | |
656 gaim_gtk_privacy_init(void) | |
657 { | |
658 } |