Mercurial > pidgin
annotate src/gtkprivacy.c @ 13936:669898e6aa11
[gaim-migrate @ 16467]
Minor enhancements for the combobox.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 09 Jul 2006 00:54:31 +0000 |
parents | 3ac2d64a74a0 |
children | 8bda65b88e49 |
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 */ | |
9791 | 25 #include "internal.h" |
26 #include "gtkgaim.h" | |
6371 | 27 |
28 #include "connection.h" | |
29 #include "debug.h" | |
30 #include "privacy.h" | |
31 #include "request.h" | |
32 #include "util.h" | |
33 | |
11111
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11047
diff
changeset
|
34 #include "gtkblist.h" |
6371 | 35 #include "gtkprivacy.h" |
36 #include "gtkutils.h" | |
37 | |
38 typedef struct | |
39 { | |
40 GtkWidget *win; | |
41 | |
42 GtkWidget *type_menu; | |
43 | |
44 GtkWidget *add_button; | |
45 GtkWidget *remove_button; | |
46 GtkWidget *clear_button; | |
47 | |
48 GtkWidget *button_box; | |
49 GtkWidget *allow_widget; | |
50 GtkWidget *block_widget; | |
51 | |
52 GtkListStore *allow_store; | |
53 GtkListStore *block_store; | |
54 | |
55 GtkWidget *allow_list; | |
56 GtkWidget *block_list; | |
57 | |
58 gboolean in_allow_list; | |
59 | |
60 GaimAccount *account; | |
61 | |
62 } GaimGtkPrivacyDialog; | |
63 | |
64 typedef struct | |
65 { | |
66 GaimAccount *account; | |
67 char *name; | |
68 gboolean block; | |
69 | |
70 } GaimGtkPrivacyRequestData; | |
71 | |
72 static struct | |
73 { | |
74 const char *text; | |
75 int num; | |
76 | |
77 } menu_entries[] = | |
78 { | |
8175 | 79 { N_("Allow all users to contact me"), GAIM_PRIVACY_ALLOW_ALL }, |
80 { N_("Allow only the users on my buddy list"), GAIM_PRIVACY_ALLOW_BUDDYLIST }, | |
81 { N_("Allow only the users below"), GAIM_PRIVACY_ALLOW_USERS }, | |
82 { N_("Block all users"), GAIM_PRIVACY_DENY_ALL }, | |
83 { N_("Block only the users below"), GAIM_PRIVACY_DENY_USERS } | |
6371 | 84 }; |
85 | |
86 static size_t menu_entry_count = sizeof(menu_entries) / sizeof(*menu_entries); | |
87 | |
88 static GaimGtkPrivacyDialog *privacy_dialog = NULL; | |
89 | |
90 static void | |
91 rebuild_allow_list(GaimGtkPrivacyDialog *dialog) | |
92 { | |
93 GSList *l; | |
94 GtkTreeIter iter; | |
95 | |
96 gtk_list_store_clear(dialog->allow_store); | |
97 | |
98 for (l = dialog->account->permit; l != NULL; l = l->next) { | |
99 gtk_list_store_append(dialog->allow_store, &iter); | |
100 gtk_list_store_set(dialog->allow_store, &iter, 0, l->data, -1); | |
101 } | |
102 } | |
103 | |
104 static void | |
105 rebuild_block_list(GaimGtkPrivacyDialog *dialog) | |
106 { | |
107 GSList *l; | |
108 GtkTreeIter iter; | |
109 | |
110 gtk_list_store_clear(dialog->block_store); | |
111 | |
112 for (l = dialog->account->deny; l != NULL; l = l->next) { | |
113 gtk_list_store_append(dialog->block_store, &iter); | |
114 gtk_list_store_set(dialog->block_store, &iter, 0, l->data, -1); | |
115 } | |
116 } | |
117 | |
118 static const char * | |
119 find_permit_block_by_name(GSList *list, const char *name) | |
120 { | |
121 const char *temp_name; | |
122 GSList *l; | |
123 | |
124 for (l = list; l != NULL; l = l->next) { | |
125 temp_name = (const char *)l->data; | |
126 | |
10425 | 127 /* Should this use gaim_normalize()? */ |
6371 | 128 if (!gaim_utf8_strcasecmp(name, temp_name)) |
129 return temp_name; | |
130 } | |
131 | |
132 return NULL; | |
133 } | |
134 | |
135 static void | |
136 user_selected_cb(GtkTreeSelection *sel, GaimGtkPrivacyDialog *dialog) | |
137 { | |
138 gtk_widget_set_sensitive(dialog->remove_button, TRUE); | |
139 } | |
140 | |
141 static GtkWidget * | |
142 build_list(GaimGtkPrivacyDialog *dialog, GtkListStore *model, | |
143 GtkWidget **ret_treeview) | |
144 { | |
145 GtkWidget *sw; | |
146 GtkWidget *treeview; | |
147 GtkCellRenderer *rend; | |
148 GtkTreeViewColumn *column; | |
149 GtkTreeSelection *sel; | |
150 | |
151 sw = gtk_scrolled_window_new(NULL, NULL); | |
152 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
13773
3ac2d64a74a0
[gaim-migrate @ 16185]
Richard Laager <rlaager@wiktel.com>
parents:
13148
diff
changeset
|
153 GTK_POLICY_AUTOMATIC, |
3ac2d64a74a0
[gaim-migrate @ 16185]
Richard Laager <rlaager@wiktel.com>
parents:
13148
diff
changeset
|
154 GTK_POLICY_AUTOMATIC); |
7931 | 155 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); |
6371 | 156 |
157 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | |
158 *ret_treeview = treeview; | |
159 | |
160 rend = gtk_cell_renderer_text_new(); | |
161 | |
162 column = gtk_tree_view_column_new_with_attributes(NULL, rend, | |
163 "text", 0, | |
164 NULL); | |
165 gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
166 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
167 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); | |
7931 | 168 gtk_container_add(GTK_CONTAINER(sw), treeview); |
6374
ca73fdf3eb38
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
169 |
6371 | 170 gtk_widget_show(treeview); |
171 | |
172 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | |
173 | |
174 g_signal_connect(G_OBJECT(sel), "changed", | |
175 G_CALLBACK(user_selected_cb), dialog); | |
176 | |
6374
ca73fdf3eb38
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
177 gtk_widget_set_size_request(sw, -1, 200); |
ca73fdf3eb38
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
178 |
6371 | 179 return sw; |
180 } | |
181 | |
182 static GtkWidget * | |
183 build_allow_list(GaimGtkPrivacyDialog *dialog) | |
184 { | |
185 GtkWidget *widget; | |
186 GtkWidget *list; | |
187 | |
188 dialog->allow_store = gtk_list_store_new(1, G_TYPE_STRING); | |
189 | |
11047
61c7edaca933
[gaim-migrate @ 12972]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
190 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(dialog->allow_store), 0, GTK_SORT_ASCENDING); |
61c7edaca933
[gaim-migrate @ 12972]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
191 |
6371 | 192 widget = build_list(dialog, dialog->allow_store, &list); |
193 | |
194 dialog->allow_list = list; | |
195 | |
196 rebuild_allow_list(dialog); | |
197 | |
198 return widget; | |
199 } | |
200 | |
201 static GtkWidget * | |
202 build_block_list(GaimGtkPrivacyDialog *dialog) | |
203 { | |
204 GtkWidget *widget; | |
205 GtkWidget *list; | |
206 | |
207 dialog->block_store = gtk_list_store_new(1, G_TYPE_STRING); | |
208 | |
11047
61c7edaca933
[gaim-migrate @ 12972]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
209 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(dialog->block_store), 0, GTK_SORT_ASCENDING); |
61c7edaca933
[gaim-migrate @ 12972]
Richard Laager <rlaager@wiktel.com>
parents:
10704
diff
changeset
|
210 |
6371 | 211 widget = build_list(dialog, dialog->block_store, &list); |
212 | |
213 dialog->block_list = list; | |
214 | |
215 rebuild_block_list(dialog); | |
216 | |
217 return widget; | |
218 } | |
219 | |
220 static gint | |
221 destroy_cb(GtkWidget *w, GdkEvent *event, GaimGtkPrivacyDialog *dialog) | |
222 { | |
7165 | 223 gaim_gtk_privacy_dialog_hide(); |
6371 | 224 |
225 return 0; | |
226 } | |
227 | |
228 static void | |
229 select_account_cb(GtkWidget *dropdown, GaimAccount *account, | |
230 GaimGtkPrivacyDialog *dialog) | |
231 { | |
232 int i; | |
233 | |
234 dialog->account = account; | |
235 | |
236 for (i = 0; i < menu_entry_count; i++) { | |
237 if (menu_entries[i].num == account->perm_deny) { | |
238 gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), i); | |
239 break; | |
240 } | |
241 } | |
242 | |
243 rebuild_allow_list(dialog); | |
244 rebuild_block_list(dialog); | |
245 } | |
246 | |
10704 | 247 /* |
248 * TODO: Setting the permit/deny setting needs to go through privacy.c | |
249 * Even better: the privacy API needs to not suck. | |
250 */ | |
6371 | 251 static void |
252 type_changed_cb(GtkOptionMenu *optmenu, GaimGtkPrivacyDialog *dialog) | |
253 { | |
8275 | 254 int new_type = menu_entries[gtk_option_menu_get_history(optmenu)].num; |
6371 | 255 |
8520 | 256 dialog->account->perm_deny = new_type; |
6371 | 257 serv_set_permit_deny(gaim_account_get_connection(dialog->account)); |
258 | |
259 gtk_widget_hide(dialog->allow_widget); | |
260 gtk_widget_hide(dialog->block_widget); | |
261 gtk_widget_hide(dialog->button_box); | |
262 | |
8175 | 263 if (new_type == GAIM_PRIVACY_ALLOW_USERS) { |
6371 | 264 gtk_widget_show(dialog->allow_widget); |
265 gtk_widget_show(dialog->button_box); | |
266 dialog->in_allow_list = TRUE; | |
267 } | |
8175 | 268 else if (new_type == GAIM_PRIVACY_DENY_USERS) { |
6371 | 269 gtk_widget_show(dialog->block_widget); |
270 gtk_widget_show(dialog->button_box); | |
271 dialog->in_allow_list = FALSE; | |
272 } | |
10147 | 273 |
10704 | 274 gaim_blist_schedule_save(); |
11111
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11047
diff
changeset
|
275 gaim_gtk_blist_refresh(gaim_get_blist()); |
6371 | 276 } |
277 | |
278 static void | |
279 add_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
280 { | |
281 if (dialog->in_allow_list) | |
282 gaim_gtk_request_add_permit(dialog->account, NULL); | |
283 else | |
284 gaim_gtk_request_add_block(dialog->account, NULL); | |
285 } | |
286 | |
287 static void | |
288 remove_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
289 { | |
290 GtkTreeIter iter; | |
291 GtkTreeModel *model; | |
292 GtkTreeSelection *sel; | |
293 char *name; | |
294 | |
295 if (dialog->in_allow_list && dialog->allow_store == NULL) | |
296 return; | |
297 | |
298 if (!dialog->in_allow_list && dialog->block_store == NULL) | |
299 return; | |
300 | |
301 if (dialog->in_allow_list) { | |
302 model = GTK_TREE_MODEL(dialog->allow_store); | |
303 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->allow_list)); | |
304 } | |
305 else { | |
306 model = GTK_TREE_MODEL(dialog->block_store); | |
307 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->block_list)); | |
308 } | |
309 | |
310 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
311 gtk_tree_model_get(model, &iter, 0, &name, -1); | |
312 else | |
313 return; | |
314 | |
315 if (dialog->in_allow_list) { | |
6375
72023626d5b8
[gaim-migrate @ 6880]
Christian Hammond <chipx86@chipx86.com>
parents:
6374
diff
changeset
|
316 if (find_permit_block_by_name(dialog->account->permit, name)) |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
317 gaim_privacy_permit_remove(dialog->account, name, FALSE); |
6371 | 318 } |
319 else { | |
6375
72023626d5b8
[gaim-migrate @ 6880]
Christian Hammond <chipx86@chipx86.com>
parents:
6374
diff
changeset
|
320 if (find_permit_block_by_name(dialog->account->deny, name)) |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
321 gaim_privacy_deny_remove(dialog->account, name, FALSE); |
6371 | 322 } |
13148
cb53596ff3d2
[gaim-migrate @ 15511]
Richard Laager <rlaager@wiktel.com>
parents:
12852
diff
changeset
|
323 g_free(name); |
6371 | 324 } |
325 | |
326 static void | |
327 clear_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
328 { | |
8556 | 329 GSList *l; |
330 if (dialog->in_allow_list) | |
331 l = dialog->account->permit; | |
332 else | |
333 l = dialog->account->deny; | |
334 while (l) { | |
335 char *user; | |
336 user = l->data; | |
337 l = l->next; | |
338 if (dialog->in_allow_list) | |
339 gaim_privacy_permit_remove(dialog->account, user, FALSE); | |
340 else | |
341 gaim_privacy_deny_remove(dialog->account, user, FALSE); | |
342 } | |
6371 | 343 } |
344 | |
345 static void | |
7165 | 346 close_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) |
6371 | 347 { |
7165 | 348 gtk_widget_destroy(dialog->win); |
349 | |
6371 | 350 gaim_gtk_privacy_dialog_hide(); |
351 } | |
352 | |
353 static GaimGtkPrivacyDialog * | |
354 privacy_dialog_new(void) | |
355 { | |
356 GaimGtkPrivacyDialog *dialog; | |
357 GtkWidget *bbox; | |
358 GtkWidget *hbox; | |
359 GtkWidget *vbox; | |
360 GtkWidget *button; | |
361 GtkWidget *dropdown; | |
362 GtkWidget *label; | |
363 GtkWidget *menu; | |
364 int selected = 0; | |
365 int i; | |
366 | |
367 dialog = g_new0(GaimGtkPrivacyDialog, 1); | |
368 | |
369 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
370 gtk_window_set_resizable(GTK_WINDOW(dialog->win), FALSE); | |
371 gtk_window_set_role(GTK_WINDOW(dialog->win), "privacy"); | |
372 gtk_window_set_title(GTK_WINDOW(dialog->win), _("Privacy")); | |
11243 | 373 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), GAIM_HIG_BORDER); |
6371 | 374 |
375 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
376 G_CALLBACK(destroy_cb), dialog); | |
377 | |
378 /* Main vbox */ | |
11243 | 379 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
6371 | 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. */ | |
11243 | 392 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER); |
6371 | 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 */ | |
8940 | 402 dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE, |
12852
9e9c8601e5f2
[gaim-migrate @ 15202]
Richard Laager <rlaager@wiktel.com>
parents:
12849
diff
changeset
|
403 G_CALLBACK(select_account_cb), NULL, dialog); |
6371 | 404 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
405 gtk_widget_show(dropdown); | |
8137 | 406 gaim_set_accessible_label (dropdown, label); |
8940 | 407 dialog->account = gaim_gtk_account_option_menu_get_selected(dropdown); |
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 /* Another button box. */ | |
472 bbox = gtk_hbutton_box_new(); | |
473 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
474 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
475 gtk_widget_show(bbox); | |
476 | |
477 /* Close button */ | |
478 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
479 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
480 gtk_widget_show(button); | |
481 | |
482 g_signal_connect(G_OBJECT(button), "clicked", | |
483 G_CALLBACK(close_cb), dialog); | |
484 | |
8175 | 485 if (dialog->account->perm_deny == GAIM_PRIVACY_ALLOW_USERS) { |
6371 | 486 gtk_widget_show(dialog->allow_widget); |
487 gtk_widget_show(dialog->button_box); | |
488 dialog->in_allow_list = TRUE; | |
489 } | |
8175 | 490 else if (dialog->account->perm_deny == GAIM_PRIVACY_DENY_USERS) { |
6371 | 491 gtk_widget_show(dialog->block_widget); |
492 gtk_widget_show(dialog->button_box); | |
493 dialog->in_allow_list = FALSE; | |
494 } | |
495 | |
496 return dialog; | |
497 } | |
498 | |
499 void | |
500 gaim_gtk_privacy_dialog_show(void) | |
501 { | |
10352 | 502 g_return_if_fail(gaim_connections_get_all() != NULL); |
503 | |
6371 | 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."), | |
8697 | 566 NULL, FALSE, FALSE, NULL, |
12603
e4e47871c373
[gaim-migrate @ 14938]
Richard Laager <rlaager@wiktel.com>
parents:
11243
diff
changeset
|
567 _("_Permit"), G_CALLBACK(add_permit_block_cb), |
6371 | 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, | |
12603
e4e47871c373
[gaim-migrate @ 14938]
Richard Laager <rlaager@wiktel.com>
parents:
11243
diff
changeset
|
580 _("_Permit"), G_CALLBACK(confirm_permit_block_cb), |
6371 | 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."), | |
8697 | 604 NULL, FALSE, FALSE, NULL, |
12603
e4e47871c373
[gaim-migrate @ 14938]
Richard Laager <rlaager@wiktel.com>
parents:
11243
diff
changeset
|
605 _("_Block"), G_CALLBACK(add_permit_block_cb), |
6371 | 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, | |
12603
e4e47871c373
[gaim-migrate @ 14938]
Richard Laager <rlaager@wiktel.com>
parents:
11243
diff
changeset
|
616 _("_Block"), G_CALLBACK(confirm_permit_block_cb), |
6371 | 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 } |