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