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