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