Mercurial > pidgin
annotate src/gtkprivacy.c @ 10951:84d8279259c9
[gaim-migrate @ 12751]
sf patch #1211745 (kind of), from Richard Laager
The image drag-and-drop dialog is missing a space so two
words run together.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 31 May 2005 23:36:16 +0000 |
parents | a4ae4fb7f939 |
children | 61c7edaca933 |
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 | |
10704 | 242 /* |
243 * TODO: Setting the permit/deny setting needs to go through privacy.c | |
244 * Even better: the privacy API needs to not suck. | |
245 */ | |
6371 | 246 static void |
247 type_changed_cb(GtkOptionMenu *optmenu, GaimGtkPrivacyDialog *dialog) | |
248 { | |
8275 | 249 int new_type = menu_entries[gtk_option_menu_get_history(optmenu)].num; |
6371 | 250 |
8520 | 251 dialog->account->perm_deny = new_type; |
6371 | 252 serv_set_permit_deny(gaim_account_get_connection(dialog->account)); |
253 | |
254 gtk_widget_hide(dialog->allow_widget); | |
255 gtk_widget_hide(dialog->block_widget); | |
256 gtk_widget_hide(dialog->button_box); | |
257 | |
8175 | 258 if (new_type == GAIM_PRIVACY_ALLOW_USERS) { |
6371 | 259 gtk_widget_show(dialog->allow_widget); |
260 gtk_widget_show(dialog->button_box); | |
261 dialog->in_allow_list = TRUE; | |
262 } | |
8175 | 263 else if (new_type == GAIM_PRIVACY_DENY_USERS) { |
6371 | 264 gtk_widget_show(dialog->block_widget); |
265 gtk_widget_show(dialog->button_box); | |
266 dialog->in_allow_list = FALSE; | |
267 } | |
10147 | 268 |
10704 | 269 gaim_blist_schedule_save(); |
6371 | 270 } |
271 | |
272 static void | |
273 add_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
274 { | |
275 if (dialog->in_allow_list) | |
276 gaim_gtk_request_add_permit(dialog->account, NULL); | |
277 else | |
278 gaim_gtk_request_add_block(dialog->account, NULL); | |
279 } | |
280 | |
281 static void | |
282 remove_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
283 { | |
284 GtkTreeIter iter; | |
285 GtkTreeModel *model; | |
286 GtkTreeSelection *sel; | |
287 char *name; | |
288 | |
289 if (dialog->in_allow_list && dialog->allow_store == NULL) | |
290 return; | |
291 | |
292 if (!dialog->in_allow_list && dialog->block_store == NULL) | |
293 return; | |
294 | |
295 if (dialog->in_allow_list) { | |
296 model = GTK_TREE_MODEL(dialog->allow_store); | |
297 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->allow_list)); | |
298 } | |
299 else { | |
300 model = GTK_TREE_MODEL(dialog->block_store); | |
301 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->block_list)); | |
302 } | |
303 | |
304 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
305 gtk_tree_model_get(model, &iter, 0, &name, -1); | |
306 else | |
307 return; | |
308 | |
309 if (dialog->in_allow_list) { | |
6375
72023626d5b8
[gaim-migrate @ 6880]
Christian Hammond <chipx86@chipx86.com>
parents:
6374
diff
changeset
|
310 if (find_permit_block_by_name(dialog->account->permit, name)) |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
311 gaim_privacy_permit_remove(dialog->account, name, FALSE); |
6371 | 312 } |
313 else { | |
6375
72023626d5b8
[gaim-migrate @ 6880]
Christian Hammond <chipx86@chipx86.com>
parents:
6374
diff
changeset
|
314 if (find_permit_block_by_name(dialog->account->deny, name)) |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
315 gaim_privacy_deny_remove(dialog->account, name, FALSE); |
6371 | 316 } |
317 } | |
318 | |
319 static void | |
320 clear_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) | |
321 { | |
8556 | 322 GSList *l; |
323 if (dialog->in_allow_list) | |
324 l = dialog->account->permit; | |
325 else | |
326 l = dialog->account->deny; | |
327 while (l) { | |
328 char *user; | |
329 user = l->data; | |
330 l = l->next; | |
331 if (dialog->in_allow_list) | |
332 gaim_privacy_permit_remove(dialog->account, user, FALSE); | |
333 else | |
334 gaim_privacy_deny_remove(dialog->account, user, FALSE); | |
335 } | |
6371 | 336 } |
337 | |
338 static void | |
7165 | 339 close_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog) |
6371 | 340 { |
7165 | 341 gtk_widget_destroy(dialog->win); |
342 | |
6371 | 343 gaim_gtk_privacy_dialog_hide(); |
344 } | |
345 | |
6646
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
346 static gboolean |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
347 check_account_func(GaimAccount *account) |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
348 { |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
349 GaimConnection *gc = gaim_account_get_connection(account); |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
350 GaimPluginProtocolInfo *prpl_info = 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 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); |
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 return (prpl_info->set_permit_deny != NULL); |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
355 } |
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
356 |
8938 | 357 gboolean |
358 gaim_gtk_privacy_is_showable() | |
359 { | |
360 GList *c; | |
361 GaimConnection *gc; | |
362 | |
363 for (c = gaim_connections_get_all(); c != NULL; c = c->next) { | |
364 gc = c->data; | |
365 | |
366 if (check_account_func(gaim_connection_get_account(gc))) | |
367 return TRUE; | |
368 } | |
369 | |
370 return FALSE; | |
371 } | |
372 | |
6371 | 373 static GaimGtkPrivacyDialog * |
374 privacy_dialog_new(void) | |
375 { | |
376 GaimGtkPrivacyDialog *dialog; | |
377 GtkWidget *bbox; | |
378 GtkWidget *hbox; | |
379 GtkWidget *vbox; | |
380 GtkWidget *button; | |
381 GtkWidget *dropdown; | |
382 GtkWidget *label; | |
383 GtkWidget *menu; | |
384 int selected = 0; | |
385 int i; | |
386 | |
387 dialog = g_new0(GaimGtkPrivacyDialog, 1); | |
388 | |
389 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
390 gtk_window_set_resizable(GTK_WINDOW(dialog->win), FALSE); | |
391 gtk_window_set_role(GTK_WINDOW(dialog->win), "privacy"); | |
392 gtk_window_set_title(GTK_WINDOW(dialog->win), _("Privacy")); | |
393 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
394 | |
395 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
396 G_CALLBACK(destroy_cb), dialog); | |
397 | |
398 /* Main vbox */ | |
399 vbox = gtk_vbox_new(FALSE, 12); | |
400 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
401 gtk_widget_show(vbox); | |
402 | |
403 /* Description label */ | |
404 label = gtk_label_new( | |
405 _("Changes to privacy settings take effect immediately.")); | |
406 | |
407 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
408 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
409 gtk_widget_show(label); | |
410 | |
411 /* Hbox for the accounts drop-down and label. */ | |
412 hbox = gtk_hbox_new(FALSE, 12); | |
413 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
414 gtk_widget_show(hbox); | |
415 | |
416 /* "Set privacy for:" label */ | |
417 label = gtk_label_new(_("Set privacy for:")); | |
418 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
419 gtk_widget_show(label); | |
420 | |
421 /* Accounts drop-down */ | |
8940 | 422 dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE, |
6371 | 423 G_CALLBACK(select_account_cb), |
6646
b89d98f0bf79
[gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
424 check_account_func, dialog); |
6371 | 425 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
426 gtk_widget_show(dropdown); | |
8137 | 427 gaim_set_accessible_label (dropdown, label); |
8940 | 428 dialog->account = gaim_gtk_account_option_menu_get_selected(dropdown); |
6371 | 429 |
430 /* Add the drop-down list with the allow/block types. */ | |
431 dialog->type_menu = gtk_option_menu_new(); | |
432 gtk_box_pack_start(GTK_BOX(vbox), dialog->type_menu, FALSE, FALSE, 0); | |
433 gtk_widget_show(dialog->type_menu); | |
434 | |
435 /* Build the menu for that. */ | |
436 menu = gtk_menu_new(); | |
437 | |
438 for (i = 0; i < menu_entry_count; i++) { | |
439 gaim_new_item(menu, _(menu_entries[i].text)); | |
440 | |
441 if (menu_entries[i].num == dialog->account->perm_deny) | |
442 selected = i; | |
443 } | |
444 | |
445 gtk_option_menu_set_menu(GTK_OPTION_MENU(dialog->type_menu), menu); | |
446 gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), selected); | |
447 | |
448 g_signal_connect(G_OBJECT(dialog->type_menu), "changed", | |
449 G_CALLBACK(type_changed_cb), dialog); | |
450 | |
451 /* Build the treeview for the allow list. */ | |
452 dialog->allow_widget = build_allow_list(dialog); | |
453 gtk_box_pack_start(GTK_BOX(vbox), dialog->allow_widget, TRUE, TRUE, 0); | |
454 | |
455 /* Build the treeview for the block list. */ | |
456 dialog->block_widget = build_block_list(dialog); | |
457 gtk_box_pack_start(GTK_BOX(vbox), dialog->block_widget, TRUE, TRUE, 0); | |
458 | |
459 /* Add the button box for Add, Remove, Clear */ | |
460 dialog->button_box = bbox = gtk_hbutton_box_new(); | |
461 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD); | |
462 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
463 | |
464 /* Add button */ | |
465 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
466 dialog->add_button = button; | |
467 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
468 gtk_widget_show(button); | |
469 | |
470 g_signal_connect(G_OBJECT(button), "clicked", | |
471 G_CALLBACK(add_cb), dialog); | |
472 | |
473 /* Remove button */ | |
474 button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); | |
475 dialog->remove_button = button; | |
476 gtk_widget_set_sensitive(button, FALSE); | |
477 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
478 gtk_widget_show(button); | |
479 | |
480 g_signal_connect(G_OBJECT(button), "clicked", | |
481 G_CALLBACK(remove_cb), dialog); | |
482 | |
483 /* Clear button */ | |
484 button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
485 dialog->clear_button = button; | |
486 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
487 gtk_widget_show(button); | |
488 | |
489 g_signal_connect(G_OBJECT(button), "clicked", | |
490 G_CALLBACK(clear_cb), dialog); | |
491 | |
492 /* Another button box. */ | |
493 bbox = gtk_hbutton_box_new(); | |
494 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
495 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
496 gtk_widget_show(bbox); | |
497 | |
498 /* Close button */ | |
499 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
500 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
501 gtk_widget_show(button); | |
502 | |
503 g_signal_connect(G_OBJECT(button), "clicked", | |
504 G_CALLBACK(close_cb), dialog); | |
505 | |
8175 | 506 if (dialog->account->perm_deny == GAIM_PRIVACY_ALLOW_USERS) { |
6371 | 507 gtk_widget_show(dialog->allow_widget); |
508 gtk_widget_show(dialog->button_box); | |
509 dialog->in_allow_list = TRUE; | |
510 } | |
8175 | 511 else if (dialog->account->perm_deny == GAIM_PRIVACY_DENY_USERS) { |
6371 | 512 gtk_widget_show(dialog->block_widget); |
513 gtk_widget_show(dialog->button_box); | |
514 dialog->in_allow_list = FALSE; | |
515 } | |
516 | |
517 return dialog; | |
518 } | |
519 | |
520 void | |
521 gaim_gtk_privacy_dialog_show(void) | |
522 { | |
10352 | 523 g_return_if_fail(gaim_connections_get_all() != NULL); |
524 | |
6371 | 525 if (privacy_dialog == NULL) |
526 privacy_dialog = privacy_dialog_new(); | |
527 | |
528 gtk_widget_show(privacy_dialog->win); | |
529 gdk_window_raise(privacy_dialog->win->window); | |
530 } | |
531 | |
532 void | |
533 gaim_gtk_privacy_dialog_hide(void) | |
534 { | |
535 if (privacy_dialog == NULL) | |
536 return; | |
537 | |
7165 | 538 g_free(privacy_dialog); |
6371 | 539 privacy_dialog = NULL; |
540 } | |
541 | |
542 static void | |
543 destroy_request_data(GaimGtkPrivacyRequestData *data) | |
544 { | |
545 if (data->name != NULL) | |
546 g_free(data->name); | |
547 | |
548 g_free(data); | |
549 } | |
550 | |
551 static void | |
552 confirm_permit_block_cb(GaimGtkPrivacyRequestData *data, int option) | |
553 { | |
554 if (data->block) | |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
555 gaim_privacy_deny_add(data->account, data->name, FALSE); |
6371 | 556 else |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6375
diff
changeset
|
557 gaim_privacy_permit_add(data->account, data->name, FALSE); |
6371 | 558 |
559 destroy_request_data(data); | |
560 } | |
561 | |
562 static void | |
563 add_permit_block_cb(GaimGtkPrivacyRequestData *data, const char *name) | |
564 { | |
565 data->name = g_strdup(name); | |
566 | |
567 confirm_permit_block_cb(data, 0); | |
568 } | |
569 | |
570 void | |
571 gaim_gtk_request_add_permit(GaimAccount *account, const char *name) | |
572 { | |
573 GaimGtkPrivacyRequestData *data; | |
574 | |
575 g_return_if_fail(account != NULL); | |
576 | |
577 data = g_new0(GaimGtkPrivacyRequestData, 1); | |
578 data->account = account; | |
579 data->name = g_strdup(name); | |
580 data->block = FALSE; | |
581 | |
582 if (name == NULL) { | |
583 gaim_request_input(account, _("Permit User"), | |
584 _("Type a user you permit to contact you."), | |
585 _("Please enter the name of the user you wish to be " | |
586 "able to contact you."), | |
8697 | 587 NULL, FALSE, FALSE, NULL, |
6371 | 588 _("Permit"), G_CALLBACK(add_permit_block_cb), |
589 _("Cancel"), G_CALLBACK(destroy_request_data), | |
590 data); | |
591 } | |
592 else { | |
593 char *primary = g_strdup_printf(_("Allow %s to contact you?"), name); | |
594 char *secondary = | |
595 g_strdup_printf(_("Are you sure you wish to allow " | |
596 "%s to contact you?"), name); | |
597 | |
598 | |
599 gaim_request_action(account, _("Permit User"), primary, secondary, | |
600 0, data, 2, | |
601 _("Permit"), G_CALLBACK(confirm_permit_block_cb), | |
602 _("Cancel"), G_CALLBACK(destroy_request_data)); | |
603 | |
604 g_free(primary); | |
605 g_free(secondary); | |
606 } | |
607 } | |
608 | |
609 void | |
610 gaim_gtk_request_add_block(GaimAccount *account, const char *name) | |
611 { | |
612 GaimGtkPrivacyRequestData *data; | |
613 | |
614 g_return_if_fail(account != NULL); | |
615 | |
616 data = g_new0(GaimGtkPrivacyRequestData, 1); | |
617 data->account = account; | |
618 data->name = g_strdup(name); | |
619 data->block = TRUE; | |
620 | |
621 if (name == NULL) { | |
622 gaim_request_input(account, _("Block User"), | |
623 _("Type a user to block."), | |
624 _("Please enter the name of the user you wish to block."), | |
8697 | 625 NULL, FALSE, FALSE, NULL, |
6371 | 626 _("Block"), G_CALLBACK(add_permit_block_cb), |
627 _("Cancel"), G_CALLBACK(destroy_request_data), | |
628 data); | |
629 } | |
630 else { | |
631 char *primary = g_strdup_printf(_("Block %s?"), name); | |
632 char *secondary = | |
633 g_strdup_printf(_("Are you sure you want to block %s?"), name); | |
634 | |
635 gaim_request_action(account, _("Block User"), primary, secondary, | |
636 0, data, 2, | |
637 _("Block"), G_CALLBACK(confirm_permit_block_cb), | |
638 _("Cancel"), G_CALLBACK(destroy_request_data)); | |
639 | |
640 g_free(primary); | |
641 g_free(secondary); | |
642 } | |
643 } | |
644 | |
645 static void | |
646 gaim_gtk_permit_added_removed(GaimAccount *account, const char *name) | |
647 { | |
648 if (privacy_dialog != NULL) | |
649 rebuild_allow_list(privacy_dialog); | |
650 } | |
651 | |
652 static void | |
653 gaim_gtk_deny_added_removed(GaimAccount *account, const char *name) | |
654 { | |
655 if (privacy_dialog != NULL) | |
656 rebuild_block_list(privacy_dialog); | |
657 } | |
658 | |
659 static GaimPrivacyUiOps privacy_ops = | |
660 { | |
661 gaim_gtk_permit_added_removed, | |
662 gaim_gtk_permit_added_removed, | |
663 gaim_gtk_deny_added_removed, | |
664 gaim_gtk_deny_added_removed | |
665 }; | |
666 | |
667 GaimPrivacyUiOps * | |
668 gaim_gtk_privacy_get_ui_ops(void) | |
669 { | |
670 return &privacy_ops; | |
671 } | |
672 | |
673 void | |
674 gaim_gtk_privacy_init(void) | |
675 { | |
676 } |