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