Mercurial > pidgin.yaz
annotate src/gtkprivacy.c @ 10529:5091a2782616
[gaim-migrate @ 11850]
[19:43] <maqu1na> hey marv, actually no.. its Irving Cordova
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Wed, 19 Jan 2005 01:44:59 +0000 |
parents | 9903182f2aac |
children | f175ff63d571 |
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 GtkWidget *sep; | |
381 int selected = 0; | |
382 int i; | |
383 | |
384 dialog = g_new0(GaimGtkPrivacyDialog, 1); | |
385 | |
386 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
387 gtk_window_set_resizable(GTK_WINDOW(dialog->win), FALSE); | |
388 gtk_window_set_role(GTK_WINDOW(dialog->win), "privacy"); | |
389 gtk_window_set_title(GTK_WINDOW(dialog->win), _("Privacy")); | |
390 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
391 | |
392 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
393 G_CALLBACK(destroy_cb), dialog); | |
394 | |
395 /* Main vbox */ | |
396 vbox = gtk_vbox_new(FALSE, 12); | |
397 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
398 gtk_widget_show(vbox); | |
399 | |
400 /* Description label */ | |
401 label = gtk_label_new( | |
402 _("Changes to privacy settings take effect immediately.")); | |
403 | |
404 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
405 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
406 gtk_widget_show(label); | |
407 | |
408 /* Hbox for the accounts drop-down and label. */ | |
409 hbox = gtk_hbox_new(FALSE, 12); | |
410 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
411 gtk_widget_show(hbox); | |
412 | |
413 /* "Set privacy for:" label */ | |
414 label = gtk_label_new(_("Set privacy for:")); | |
415 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
416 gtk_widget_show(label); | |
417 | |
418 /* Accounts drop-down */ | |
8940 | 419 dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE, |
6371 | 420 G_CALLBACK(select_account_cb), |
6646
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
421 check_account_func, dialog); |
6371 | 422 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
423 gtk_widget_show(dropdown); | |
8137 | 424 gaim_set_accessible_label (dropdown, label); |
8940 | 425 dialog->account = gaim_gtk_account_option_menu_get_selected(dropdown); |
6371 | 426 |
427 /* Add the drop-down list with the allow/block types. */ | |
428 dialog->type_menu = gtk_option_menu_new(); | |
429 gtk_box_pack_start(GTK_BOX(vbox), dialog->type_menu, FALSE, FALSE, 0); | |
430 gtk_widget_show(dialog->type_menu); | |
431 | |
432 /* Build the menu for that. */ | |
433 menu = gtk_menu_new(); | |
434 | |
435 for (i = 0; i < menu_entry_count; i++) { | |
436 gaim_new_item(menu, _(menu_entries[i].text)); | |
437 | |
438 if (menu_entries[i].num == dialog->account->perm_deny) | |
439 selected = i; | |
440 } | |
441 | |
442 gtk_option_menu_set_menu(GTK_OPTION_MENU(dialog->type_menu), menu); | |
443 gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), selected); | |
444 | |
445 g_signal_connect(G_OBJECT(dialog->type_menu), "changed", | |
446 G_CALLBACK(type_changed_cb), dialog); | |
447 | |
448 /* Build the treeview for the allow list. */ | |
449 dialog->allow_widget = build_allow_list(dialog); | |
450 gtk_box_pack_start(GTK_BOX(vbox), dialog->allow_widget, TRUE, TRUE, 0); | |
451 | |
452 /* Build the treeview for the block list. */ | |
453 dialog->block_widget = build_block_list(dialog); | |
454 gtk_box_pack_start(GTK_BOX(vbox), dialog->block_widget, TRUE, TRUE, 0); | |
455 | |
456 /* Add the button box for Add, Remove, Clear */ | |
457 dialog->button_box = bbox = gtk_hbutton_box_new(); | |
458 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD); | |
459 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
460 | |
461 /* Add button */ | |
462 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
463 dialog->add_button = button; | |
464 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
465 gtk_widget_show(button); | |
466 | |
467 g_signal_connect(G_OBJECT(button), "clicked", | |
468 G_CALLBACK(add_cb), dialog); | |
469 | |
470 /* Remove button */ | |
471 button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); | |
472 dialog->remove_button = button; | |
473 gtk_widget_set_sensitive(button, FALSE); | |
474 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
475 gtk_widget_show(button); | |
476 | |
477 g_signal_connect(G_OBJECT(button), "clicked", | |
478 G_CALLBACK(remove_cb), dialog); | |
479 | |
480 /* Clear button */ | |
481 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
482 dialog->clear_button = button; | |
483 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
484 gtk_widget_show(button); | |
485 | |
486 g_signal_connect(G_OBJECT(button), "clicked", | |
487 G_CALLBACK(clear_cb), dialog); | |
488 | |
489 /* Separator */ | |
490 sep = gtk_hseparator_new(); | |
491 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
492 gtk_widget_show(sep); | |
493 | |
494 /* Another button box. */ | |
495 bbox = gtk_hbutton_box_new(); | |
496 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
497 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
498 gtk_widget_show(bbox); | |
499 | |
500 /* Close button */ | |
501 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
502 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
503 gtk_widget_show(button); | |
504 | |
505 g_signal_connect(G_OBJECT(button), "clicked", | |
506 G_CALLBACK(close_cb), dialog); | |
507 | |
8175 | 508 if (dialog->account->perm_deny == GAIM_PRIVACY_ALLOW_USERS) { |
6371 | 509 gtk_widget_show(dialog->allow_widget); |
510 gtk_widget_show(dialog->button_box); | |
511 dialog->in_allow_list = TRUE; | |
512 } | |
8175 | 513 else if (dialog->account->perm_deny == GAIM_PRIVACY_DENY_USERS) { |
6371 | 514 gtk_widget_show(dialog->block_widget); |
515 gtk_widget_show(dialog->button_box); | |
516 dialog->in_allow_list = FALSE; | |
517 } | |
518 | |
519 return dialog; | |
520 } | |
521 | |
522 void | |
523 gaim_gtk_privacy_dialog_show(void) | |
524 { | |
10352 | 525 g_return_if_fail(gaim_connections_get_all() != NULL); |
526 | |
6371 | 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 } |