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