Sat, 17 Nov 2007 00:12:30 +0000
This merge has the effect of reverting the hinting code from trunk.
| 6371 | 1 | /** |
| 2 | * @file gtkprivacy.c GTK+ Privacy UI | |
|
16254
eeb2bba4dc94
Rename the Doxygen group from gtkui to pidgin.
Richard Laager <rlaager@pidgin.im>
parents:
15931
diff
changeset
|
3 | * @ingroup pidgin |
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
4 | */ |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
5 | |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
6 | /* pidgin |
| 6371 | 7 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
8 | * Pidgin is the legal property of its developers, whose names are too numerous |
| 8046 | 9 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 10 | * source distribution. | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13775
diff
changeset
|
11 | * |
| 6371 | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by | |
| 14 | * the Free Software Foundation; either version 2 of the License, or | |
| 15 | * (at your option) any later version. | |
| 16 | * | |
| 17 | * This program is distributed in the hope that it will be useful, | |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | * GNU General Public License for more details. | |
| 21 | * | |
| 22 | * You should have received a copy of the GNU General Public License | |
| 23 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18327
diff
changeset
|
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 6371 | 25 | */ |
| 9791 | 26 | #include "internal.h" |
| 15577 | 27 | #include "pidgin.h" |
| 6371 | 28 | |
| 29 | #include "connection.h" | |
| 30 | #include "debug.h" | |
| 31 | #include "privacy.h" | |
| 32 | #include "request.h" | |
| 33 | #include "util.h" | |
| 34 | ||
|
11111
4621d9b973a4
[gaim-migrate @ 13163]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11047
diff
changeset
|
35 | #include "gtkblist.h" |
| 6371 | 36 | #include "gtkprivacy.h" |
| 37 | #include "gtkutils.h" | |
| 38 | ||
| 39 | typedef struct | |
| 40 | { | |
| 41 | GtkWidget *win; | |
| 42 | ||
| 43 | GtkWidget *type_menu; | |
| 44 | ||
| 45 | GtkWidget *add_button; | |
| 46 | GtkWidget *remove_button; | |
| 47 | GtkWidget *clear_button; | |
| 48 | ||
| 49 | GtkWidget *button_box; | |
| 50 | GtkWidget *allow_widget; | |
| 51 | GtkWidget *block_widget; | |
| 52 | ||
| 53 | GtkListStore *allow_store; | |
| 54 | GtkListStore *block_store; | |
| 55 | ||
| 56 | GtkWidget *allow_list; | |
| 57 | GtkWidget *block_list; | |
| 58 | ||
| 59 | gboolean in_allow_list; | |
| 60 | ||
| 15884 | 61 | PurpleAccount *account; |
| 6371 | 62 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
63 | } PidginPrivacyDialog; |
| 6371 | 64 | |
| 65 | typedef struct | |
| 66 | { | |
| 15884 | 67 | PurpleAccount *account; |
| 6371 | 68 | char *name; |
| 69 | gboolean block; | |
| 70 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
71 | } PidginPrivacyRequestData; |
| 6371 | 72 | |
| 73 | static struct | |
| 74 | { | |
| 75 | const char *text; | |
| 76 | int num; | |
| 77 | ||
|
21091
07fe1a99c47b
Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@pidgin.im>
parents:
20147
diff
changeset
|
78 | } const menu_entries[] = |
| 6371 | 79 | { |
| 15884 | 80 | { N_("Allow all users to contact me"), PURPLE_PRIVACY_ALLOW_ALL }, |
| 81 | { N_("Allow only the users on my buddy list"), PURPLE_PRIVACY_ALLOW_BUDDYLIST }, | |
| 82 | { N_("Allow only the users below"), PURPLE_PRIVACY_ALLOW_USERS }, | |
| 83 | { N_("Block all users"), PURPLE_PRIVACY_DENY_ALL }, | |
| 84 | { N_("Block only the users below"), PURPLE_PRIVACY_DENY_USERS } | |
| 6371 | 85 | }; |
| 86 | ||
|
21091
07fe1a99c47b
Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@pidgin.im>
parents:
20147
diff
changeset
|
87 | static const size_t menu_entry_count = sizeof(menu_entries) / sizeof(*menu_entries); |
| 6371 | 88 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
89 | static PidginPrivacyDialog *privacy_dialog = NULL; |
| 6371 | 90 | |
| 91 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
92 | rebuild_allow_list(PidginPrivacyDialog *dialog) |
| 6371 | 93 | { |
| 94 | GSList *l; | |
| 95 | GtkTreeIter iter; | |
| 96 | ||
| 97 | gtk_list_store_clear(dialog->allow_store); | |
| 98 | ||
| 99 | for (l = dialog->account->permit; l != NULL; l = l->next) { | |
| 100 | gtk_list_store_append(dialog->allow_store, &iter); | |
| 101 | gtk_list_store_set(dialog->allow_store, &iter, 0, l->data, -1); | |
| 102 | } | |
| 103 | } | |
| 104 | ||
| 105 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
106 | rebuild_block_list(PidginPrivacyDialog *dialog) |
| 6371 | 107 | { |
| 108 | GSList *l; | |
| 109 | GtkTreeIter iter; | |
| 110 | ||
| 111 | gtk_list_store_clear(dialog->block_store); | |
| 112 | ||
| 113 | for (l = dialog->account->deny; l != NULL; l = l->next) { | |
| 114 | gtk_list_store_append(dialog->block_store, &iter); | |
| 115 | gtk_list_store_set(dialog->block_store, &iter, 0, l->data, -1); | |
| 116 | } | |
| 117 | } | |
| 118 | ||
| 119 | static const char * | |
| 120 | find_permit_block_by_name(GSList *list, const char *name) | |
| 121 | { | |
| 122 | const char *temp_name; | |
| 123 | GSList *l; | |
| 124 | ||
| 125 | for (l = list; l != NULL; l = l->next) { | |
| 126 | temp_name = (const char *)l->data; | |
| 127 | ||
| 15884 | 128 | /* Should this use purple_normalize()? */ |
| 129 | if (!purple_utf8_strcasecmp(name, temp_name)) | |
| 6371 | 130 | return temp_name; |
| 131 | } | |
| 132 | ||
| 133 | return NULL; | |
| 134 | } | |
| 135 | ||
| 136 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
137 | user_selected_cb(GtkTreeSelection *sel, PidginPrivacyDialog *dialog) |
| 6371 | 138 | { |
| 139 | gtk_widget_set_sensitive(dialog->remove_button, TRUE); | |
| 140 | } | |
| 141 | ||
| 142 | static GtkWidget * | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
143 | build_list(PidginPrivacyDialog *dialog, GtkListStore *model, |
| 6371 | 144 | GtkWidget **ret_treeview) |
| 145 | { | |
| 146 | GtkWidget *sw; | |
| 147 | GtkWidget *treeview; | |
| 148 | GtkCellRenderer *rend; | |
| 149 | GtkTreeViewColumn *column; | |
| 150 | GtkTreeSelection *sel; | |
| 151 | ||
| 152 | sw = gtk_scrolled_window_new(NULL, NULL); | |
| 153 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
| 13775 | 154 | GTK_POLICY_AUTOMATIC, |
| 155 | GTK_POLICY_AUTOMATIC); | |
|
7931
315fd3921a40
[gaim-migrate @ 8602]
Mark Doliner <markdoliner@pidgin.im>
parents:
7165
diff
changeset
|
156 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); |
| 6371 | 157 | |
| 158 | treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | |
| 159 | *ret_treeview = treeview; | |
| 160 | ||
| 161 | rend = gtk_cell_renderer_text_new(); | |
| 162 | ||
| 163 | column = gtk_tree_view_column_new_with_attributes(NULL, rend, | |
| 164 | "text", 0, | |
| 165 | NULL); | |
| 166 | gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(column), TRUE); | |
| 167 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
| 168 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); | |
|
7931
315fd3921a40
[gaim-migrate @ 8602]
Mark Doliner <markdoliner@pidgin.im>
parents:
7165
diff
changeset
|
169 | gtk_container_add(GTK_CONTAINER(sw), treeview); |
|
6374
0bbc59035c89
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
170 | |
| 6371 | 171 | gtk_widget_show(treeview); |
| 172 | ||
| 173 | sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | |
| 174 | ||
| 175 | g_signal_connect(G_OBJECT(sel), "changed", | |
| 176 | G_CALLBACK(user_selected_cb), dialog); | |
| 177 | ||
|
6374
0bbc59035c89
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
178 | gtk_widget_set_size_request(sw, -1, 200); |
|
0bbc59035c89
[gaim-migrate @ 6879]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
179 | |
| 6371 | 180 | return sw; |
| 181 | } | |
| 182 | ||
| 183 | static GtkWidget * | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
184 | build_allow_list(PidginPrivacyDialog *dialog) |
| 6371 | 185 | { |
| 186 | GtkWidget *widget; | |
| 187 | GtkWidget *list; | |
| 188 | ||
| 189 | dialog->allow_store = gtk_list_store_new(1, G_TYPE_STRING); | |
| 190 | ||
|
11047
1b0452e2f2a9
[gaim-migrate @ 12972]
Richard Laager <rlaager@pidgin.im>
parents:
10704
diff
changeset
|
191 | gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(dialog->allow_store), 0, GTK_SORT_ASCENDING); |
|
1b0452e2f2a9
[gaim-migrate @ 12972]
Richard Laager <rlaager@pidgin.im>
parents:
10704
diff
changeset
|
192 | |
| 6371 | 193 | widget = build_list(dialog, dialog->allow_store, &list); |
| 194 | ||
| 195 | dialog->allow_list = list; | |
| 196 | ||
| 197 | rebuild_allow_list(dialog); | |
| 198 | ||
| 199 | return widget; | |
| 200 | } | |
| 201 | ||
| 202 | static GtkWidget * | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
203 | build_block_list(PidginPrivacyDialog *dialog) |
| 6371 | 204 | { |
| 205 | GtkWidget *widget; | |
| 206 | GtkWidget *list; | |
| 207 | ||
| 208 | dialog->block_store = gtk_list_store_new(1, G_TYPE_STRING); | |
| 209 | ||
|
11047
1b0452e2f2a9
[gaim-migrate @ 12972]
Richard Laager <rlaager@pidgin.im>
parents:
10704
diff
changeset
|
210 | gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(dialog->block_store), 0, GTK_SORT_ASCENDING); |
|
1b0452e2f2a9
[gaim-migrate @ 12972]
Richard Laager <rlaager@pidgin.im>
parents:
10704
diff
changeset
|
211 | |
| 6371 | 212 | widget = build_list(dialog, dialog->block_store, &list); |
| 213 | ||
| 214 | dialog->block_list = list; | |
| 215 | ||
| 216 | rebuild_block_list(dialog); | |
| 217 | ||
| 218 | return widget; | |
| 219 | } | |
| 220 | ||
| 221 | static gint | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
222 | destroy_cb(GtkWidget *w, GdkEvent *event, PidginPrivacyDialog *dialog) |
| 6371 | 223 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
224 | pidgin_privacy_dialog_hide(); |
| 6371 | 225 | |
| 226 | return 0; | |
| 227 | } | |
| 228 | ||
| 229 | static void | |
| 15884 | 230 | select_account_cb(GtkWidget *dropdown, PurpleAccount *account, |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
231 | PidginPrivacyDialog *dialog) |
| 6371 | 232 | { |
| 233 | int i; | |
| 234 | ||
| 235 | dialog->account = account; | |
| 236 | ||
| 237 | for (i = 0; i < menu_entry_count; i++) { | |
| 238 | if (menu_entries[i].num == account->perm_deny) { | |
| 239 | gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), i); | |
| 240 | break; | |
| 241 | } | |
| 242 | } | |
| 243 | ||
| 244 | rebuild_allow_list(dialog); | |
| 245 | rebuild_block_list(dialog); | |
| 246 | } | |
| 247 | ||
|
10704
99a466f384d2
[gaim-migrate @ 12288]
Mark Doliner <markdoliner@pidgin.im>
parents:
10535
diff
changeset
|
248 | /* |
|
99a466f384d2
[gaim-migrate @ 12288]
Mark Doliner <markdoliner@pidgin.im>
parents:
10535
diff
changeset
|
249 | * TODO: Setting the permit/deny setting needs to go through privacy.c |
|
99a466f384d2
[gaim-migrate @ 12288]
Mark Doliner <markdoliner@pidgin.im>
parents:
10535
diff
changeset
|
250 | * Even better: the privacy API needs to not suck. |
|
99a466f384d2
[gaim-migrate @ 12288]
Mark Doliner <markdoliner@pidgin.im>
parents:
10535
diff
changeset
|
251 | */ |
| 6371 | 252 | static void |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
253 | type_changed_cb(GtkOptionMenu *optmenu, PidginPrivacyDialog *dialog) |
| 6371 | 254 | { |
|
8275
e4c1bfcbced6
[gaim-migrate @ 8999]
Mark Doliner <markdoliner@pidgin.im>
parents:
8175
diff
changeset
|
255 | int new_type = menu_entries[gtk_option_menu_get_history(optmenu)].num; |
| 6371 | 256 | |
|
8520
0a0fe6abc212
[gaim-migrate @ 9259]
Mark Doliner <markdoliner@pidgin.im>
parents:
8275
diff
changeset
|
257 | dialog->account->perm_deny = new_type; |
| 15884 | 258 | serv_set_permit_deny(purple_account_get_connection(dialog->account)); |
| 6371 | 259 | |
| 260 | gtk_widget_hide(dialog->allow_widget); | |
| 261 | gtk_widget_hide(dialog->block_widget); | |
| 262 | gtk_widget_hide(dialog->button_box); | |
| 263 | ||
| 15884 | 264 | if (new_type == PURPLE_PRIVACY_ALLOW_USERS) { |
| 6371 | 265 | gtk_widget_show(dialog->allow_widget); |
| 266 | gtk_widget_show(dialog->button_box); | |
| 267 | dialog->in_allow_list = TRUE; | |
| 268 | } | |
| 15884 | 269 | else if (new_type == PURPLE_PRIVACY_DENY_USERS) { |
| 6371 | 270 | gtk_widget_show(dialog->block_widget); |
| 271 | gtk_widget_show(dialog->button_box); | |
| 272 | dialog->in_allow_list = FALSE; | |
| 273 | } | |
|
10147
a4897a5bcf8d
[gaim-migrate @ 11224]
Peter Lawler <pidgin@bleeter.id.au>
parents:
9791
diff
changeset
|
274 | |
| 15884 | 275 | purple_blist_schedule_save(); |
| 276 | pidgin_blist_refresh(purple_get_blist()); | |
| 6371 | 277 | } |
| 278 | ||
| 279 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
280 | add_cb(GtkWidget *button, PidginPrivacyDialog *dialog) |
| 6371 | 281 | { |
| 282 | if (dialog->in_allow_list) | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
283 | pidgin_request_add_permit(dialog->account, NULL); |
| 6371 | 284 | else |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
285 | pidgin_request_add_block(dialog->account, NULL); |
| 6371 | 286 | } |
| 287 | ||
| 288 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
289 | remove_cb(GtkWidget *button, PidginPrivacyDialog *dialog) |
| 6371 | 290 | { |
| 291 | GtkTreeIter iter; | |
| 292 | GtkTreeModel *model; | |
| 293 | GtkTreeSelection *sel; | |
| 294 | char *name; | |
| 295 | ||
| 296 | if (dialog->in_allow_list && dialog->allow_store == NULL) | |
| 297 | return; | |
| 298 | ||
| 299 | if (!dialog->in_allow_list && dialog->block_store == NULL) | |
| 300 | return; | |
| 301 | ||
| 302 | if (dialog->in_allow_list) { | |
| 303 | model = GTK_TREE_MODEL(dialog->allow_store); | |
| 304 | sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->allow_list)); | |
| 305 | } | |
| 306 | else { | |
| 307 | model = GTK_TREE_MODEL(dialog->block_store); | |
| 308 | sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->block_list)); | |
| 309 | } | |
| 310 | ||
| 311 | if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
| 312 | gtk_tree_model_get(model, &iter, 0, &name, -1); | |
| 313 | else | |
| 314 | return; | |
| 315 | ||
| 316 | if (dialog->in_allow_list) { | |
|
6375
2378950122af
[gaim-migrate @ 6880]
Christian Hammond <chipx86@chipx86.com>
parents:
6374
diff
changeset
|
317 | if (find_permit_block_by_name(dialog->account->permit, name)) |
| 15884 | 318 | purple_privacy_permit_remove(dialog->account, name, FALSE); |
| 6371 | 319 | } |
| 320 | else { | |
|
6375
2378950122af
[gaim-migrate @ 6880]
Christian Hammond <chipx86@chipx86.com>
parents:
6374
diff
changeset
|
321 | if (find_permit_block_by_name(dialog->account->deny, name)) |
| 15884 | 322 | purple_privacy_deny_remove(dialog->account, name, FALSE); |
| 6371 | 323 | } |
|
13149
895f0495b7db
[gaim-migrate @ 15511]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12852
diff
changeset
|
324 | g_free(name); |
| 6371 | 325 | } |
| 326 | ||
| 327 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
328 | clear_cb(GtkWidget *button, PidginPrivacyDialog *dialog) |
| 6371 | 329 | { |
| 8556 | 330 | GSList *l; |
| 331 | if (dialog->in_allow_list) | |
| 332 | l = dialog->account->permit; | |
| 333 | else | |
| 334 | l = dialog->account->deny; | |
| 335 | while (l) { | |
| 336 | char *user; | |
| 337 | user = l->data; | |
| 338 | l = l->next; | |
| 339 | if (dialog->in_allow_list) | |
| 15884 | 340 | purple_privacy_permit_remove(dialog->account, user, FALSE); |
| 8556 | 341 | else |
| 15884 | 342 | purple_privacy_deny_remove(dialog->account, user, FALSE); |
| 8556 | 343 | } |
| 6371 | 344 | } |
| 345 | ||
| 346 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
347 | close_cb(GtkWidget *button, PidginPrivacyDialog *dialog) |
| 6371 | 348 | { |
|
7165
6547d94b0725
[gaim-migrate @ 7732]
Mark Doliner <markdoliner@pidgin.im>
parents:
6646
diff
changeset
|
349 | gtk_widget_destroy(dialog->win); |
|
6547d94b0725
[gaim-migrate @ 7732]
Mark Doliner <markdoliner@pidgin.im>
parents:
6646
diff
changeset
|
350 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
351 | pidgin_privacy_dialog_hide(); |
| 6371 | 352 | } |
| 353 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
354 | static PidginPrivacyDialog * |
| 6371 | 355 | privacy_dialog_new(void) |
| 356 | { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
357 | PidginPrivacyDialog *dialog; |
| 6371 | 358 | GtkWidget *bbox; |
| 359 | GtkWidget *hbox; | |
| 360 | GtkWidget *vbox; | |
| 361 | GtkWidget *button; | |
| 362 | GtkWidget *dropdown; | |
| 363 | GtkWidget *label; | |
| 364 | GtkWidget *menu; | |
| 365 | int selected = 0; | |
| 366 | int i; | |
| 367 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
368 | dialog = g_new0(PidginPrivacyDialog, 1); |
| 6371 | 369 | |
|
21228
870d44935aac
disapproval of revision '8887817a113a675c97719f7053941df51bccacdc'
Richard Laager <rlaager@pidgin.im>
parents:
21227
diff
changeset
|
370 | dialog->win = pidgin_create_window(_("Privacy"), PIDGIN_HIG_BORDER, "privacy", TRUE); |
| 6371 | 371 | |
| 372 | g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
| 373 | G_CALLBACK(destroy_cb), dialog); | |
| 374 | ||
| 375 | /* Main vbox */ | |
| 15882 | 376 | vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER); |
| 6371 | 377 | gtk_container_add(GTK_CONTAINER(dialog->win), vbox); |
| 378 | gtk_widget_show(vbox); | |
| 379 | ||
| 380 | /* Description label */ | |
| 381 | label = gtk_label_new( | |
| 382 | _("Changes to privacy settings take effect immediately.")); | |
| 383 | ||
| 384 | gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
| 385 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 386 | gtk_widget_show(label); | |
| 387 | ||
| 388 | /* Hbox for the accounts drop-down and label. */ | |
| 15882 | 389 | hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER); |
| 6371 | 390 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
| 391 | gtk_widget_show(hbox); | |
| 392 | ||
| 393 | /* "Set privacy for:" label */ | |
| 394 | label = gtk_label_new(_("Set privacy for:")); | |
| 395 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 396 | gtk_widget_show(label); | |
| 397 | ||
| 398 | /* Accounts drop-down */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
399 | dropdown = pidgin_account_option_menu_new(NULL, FALSE, |
|
12852
dc6be215f15e
[gaim-migrate @ 15202]
Richard Laager <rlaager@pidgin.im>
parents:
12849
diff
changeset
|
400 | G_CALLBACK(select_account_cb), NULL, dialog); |
| 6371 | 401 | gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
| 402 | gtk_widget_show(dropdown); | |
| 15568 | 403 | pidgin_set_accessible_label (dropdown, label); |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
404 | dialog->account = pidgin_account_option_menu_get_selected(dropdown); |
| 6371 | 405 | |
| 406 | /* Add the drop-down list with the allow/block types. */ | |
| 407 | dialog->type_menu = gtk_option_menu_new(); | |
| 408 | gtk_box_pack_start(GTK_BOX(vbox), dialog->type_menu, FALSE, FALSE, 0); | |
| 409 | gtk_widget_show(dialog->type_menu); | |
| 410 | ||
| 411 | /* Build the menu for that. */ | |
| 412 | menu = gtk_menu_new(); | |
| 413 | ||
| 414 | for (i = 0; i < menu_entry_count; i++) { | |
| 15568 | 415 | pidgin_new_item(menu, _(menu_entries[i].text)); |
| 6371 | 416 | |
| 417 | if (menu_entries[i].num == dialog->account->perm_deny) | |
| 418 | selected = i; | |
| 419 | } | |
| 420 | ||
| 421 | gtk_option_menu_set_menu(GTK_OPTION_MENU(dialog->type_menu), menu); | |
| 422 | gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), selected); | |
| 423 | ||
| 424 | g_signal_connect(G_OBJECT(dialog->type_menu), "changed", | |
| 425 | G_CALLBACK(type_changed_cb), dialog); | |
| 426 | ||
| 427 | /* Build the treeview for the allow list. */ | |
| 428 | dialog->allow_widget = build_allow_list(dialog); | |
| 429 | gtk_box_pack_start(GTK_BOX(vbox), dialog->allow_widget, TRUE, TRUE, 0); | |
| 430 | ||
| 431 | /* Build the treeview for the block list. */ | |
| 432 | dialog->block_widget = build_block_list(dialog); | |
| 433 | gtk_box_pack_start(GTK_BOX(vbox), dialog->block_widget, TRUE, TRUE, 0); | |
| 434 | ||
| 435 | /* Add the button box for Add, Remove, Clear */ | |
| 436 | dialog->button_box = bbox = gtk_hbutton_box_new(); | |
| 437 | gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD); | |
| 438 | gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
| 439 | ||
| 440 | /* Add button */ | |
| 441 | button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
| 442 | dialog->add_button = button; | |
| 443 | gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 444 | gtk_widget_show(button); | |
| 445 | ||
| 446 | g_signal_connect(G_OBJECT(button), "clicked", | |
| 447 | G_CALLBACK(add_cb), dialog); | |
| 448 | ||
| 449 | /* Remove button */ | |
| 450 | button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); | |
| 451 | dialog->remove_button = button; | |
| 452 | gtk_widget_set_sensitive(button, FALSE); | |
| 453 | gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 454 | gtk_widget_show(button); | |
| 455 | ||
| 456 | g_signal_connect(G_OBJECT(button), "clicked", | |
| 457 | G_CALLBACK(remove_cb), dialog); | |
| 458 | ||
| 459 | /* Clear button */ | |
| 460 | button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
| 461 | dialog->clear_button = button; | |
| 462 | gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 463 | gtk_widget_show(button); | |
| 464 | ||
| 465 | g_signal_connect(G_OBJECT(button), "clicked", | |
| 466 | G_CALLBACK(clear_cb), dialog); | |
| 467 | ||
| 468 | /* Another button box. */ | |
| 469 | bbox = gtk_hbutton_box_new(); | |
| 470 | gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
| 471 | gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
| 472 | gtk_widget_show(bbox); | |
| 473 | ||
| 474 | /* Close button */ | |
| 475 | button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
| 476 | gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 477 | gtk_widget_show(button); | |
| 478 | ||
| 479 | g_signal_connect(G_OBJECT(button), "clicked", | |
| 480 | G_CALLBACK(close_cb), dialog); | |
| 481 | ||
| 15884 | 482 | if (dialog->account->perm_deny == PURPLE_PRIVACY_ALLOW_USERS) { |
| 6371 | 483 | gtk_widget_show(dialog->allow_widget); |
| 484 | gtk_widget_show(dialog->button_box); | |
| 485 | dialog->in_allow_list = TRUE; | |
| 486 | } | |
| 15884 | 487 | else if (dialog->account->perm_deny == PURPLE_PRIVACY_DENY_USERS) { |
| 6371 | 488 | gtk_widget_show(dialog->block_widget); |
| 489 | gtk_widget_show(dialog->button_box); | |
| 490 | dialog->in_allow_list = FALSE; | |
| 491 | } | |
| 492 | ||
| 493 | return dialog; | |
| 494 | } | |
| 495 | ||
| 496 | void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
497 | pidgin_privacy_dialog_show(void) |
| 6371 | 498 | { |
| 15884 | 499 | g_return_if_fail(purple_connections_get_all() != NULL); |
|
10352
802e7ab5b838
[gaim-migrate @ 11569]
Mark Doliner <markdoliner@pidgin.im>
parents:
10148
diff
changeset
|
500 | |
| 6371 | 501 | if (privacy_dialog == NULL) |
| 502 | privacy_dialog = privacy_dialog_new(); | |
| 503 | ||
| 504 | gtk_widget_show(privacy_dialog->win); | |
| 505 | gdk_window_raise(privacy_dialog->win->window); | |
| 506 | } | |
| 507 | ||
| 508 | void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
509 | pidgin_privacy_dialog_hide(void) |
| 6371 | 510 | { |
| 511 | if (privacy_dialog == NULL) | |
| 512 | return; | |
| 513 | ||
|
7165
6547d94b0725
[gaim-migrate @ 7732]
Mark Doliner <markdoliner@pidgin.im>
parents:
6646
diff
changeset
|
514 | g_free(privacy_dialog); |
| 6371 | 515 | privacy_dialog = NULL; |
| 516 | } | |
| 517 | ||
| 518 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
519 | destroy_request_data(PidginPrivacyRequestData *data) |
| 6371 | 520 | { |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13775
diff
changeset
|
521 | g_free(data->name); |
| 6371 | 522 | g_free(data); |
| 523 | } | |
| 524 | ||
| 525 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
526 | confirm_permit_block_cb(PidginPrivacyRequestData *data, int option) |
| 6371 | 527 | { |
| 528 | if (data->block) | |
| 15884 | 529 | purple_privacy_deny(data->account, data->name, FALSE, FALSE); |
| 6371 | 530 | else |
| 15884 | 531 | purple_privacy_allow(data->account, data->name, FALSE, FALSE); |
| 6371 | 532 | |
| 533 | destroy_request_data(data); | |
| 534 | } | |
| 535 | ||
| 536 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
537 | add_permit_block_cb(PidginPrivacyRequestData *data, const char *name) |
| 6371 | 538 | { |
| 539 | data->name = g_strdup(name); | |
| 540 | ||
| 541 | confirm_permit_block_cb(data, 0); | |
| 542 | } | |
| 543 | ||
| 544 | void | |
| 15884 | 545 | pidgin_request_add_permit(PurpleAccount *account, const char *name) |
| 6371 | 546 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
547 | PidginPrivacyRequestData *data; |
| 6371 | 548 | |
| 549 | g_return_if_fail(account != NULL); | |
| 550 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
551 | data = g_new0(PidginPrivacyRequestData, 1); |
| 6371 | 552 | data->account = account; |
| 553 | data->name = g_strdup(name); | |
| 554 | data->block = FALSE; | |
| 555 | ||
| 556 | if (name == NULL) { | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
557 | purple_request_input(account, _("Permit User"), |
| 6371 | 558 | _("Type a user you permit to contact you."), |
| 559 | _("Please enter the name of the user you wish to be " | |
| 560 | "able to contact you."), | |
| 8697 | 561 | NULL, FALSE, FALSE, NULL, |
| 12603 | 562 | _("_Permit"), G_CALLBACK(add_permit_block_cb), |
| 6371 | 563 | _("Cancel"), G_CALLBACK(destroy_request_data), |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16254
diff
changeset
|
564 | account, name, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
565 | data); |
| 6371 | 566 | } |
| 567 | else { | |
| 568 | char *primary = g_strdup_printf(_("Allow %s to contact you?"), name); | |
| 569 | char *secondary = | |
| 570 | g_strdup_printf(_("Are you sure you wish to allow " | |
| 571 | "%s to contact you?"), name); | |
| 572 | ||
| 573 | ||
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
574 | purple_request_action(account, _("Permit User"), primary, secondary, |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16254
diff
changeset
|
575 | 0, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16254
diff
changeset
|
576 | account, name, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
577 | data, 2, |
| 12603 | 578 | _("_Permit"), G_CALLBACK(confirm_permit_block_cb), |
| 6371 | 579 | _("Cancel"), G_CALLBACK(destroy_request_data)); |
| 580 | ||
| 581 | g_free(primary); | |
| 582 | g_free(secondary); | |
| 583 | } | |
| 584 | } | |
| 585 | ||
| 586 | void | |
| 15884 | 587 | pidgin_request_add_block(PurpleAccount *account, const char *name) |
| 6371 | 588 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
589 | PidginPrivacyRequestData *data; |
| 6371 | 590 | |
| 591 | g_return_if_fail(account != NULL); | |
| 592 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
593 | data = g_new0(PidginPrivacyRequestData, 1); |
| 6371 | 594 | data->account = account; |
| 595 | data->name = g_strdup(name); | |
| 596 | data->block = TRUE; | |
| 597 | ||
| 598 | if (name == NULL) { | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
599 | purple_request_input(account, _("Block User"), |
| 6371 | 600 | _("Type a user to block."), |
| 601 | _("Please enter the name of the user you wish to block."), | |
| 8697 | 602 | NULL, FALSE, FALSE, NULL, |
| 12603 | 603 | _("_Block"), G_CALLBACK(add_permit_block_cb), |
| 6371 | 604 | _("Cancel"), G_CALLBACK(destroy_request_data), |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16254
diff
changeset
|
605 | account, name, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
606 | data); |
| 6371 | 607 | } |
| 608 | else { | |
| 609 | char *primary = g_strdup_printf(_("Block %s?"), name); | |
| 610 | char *secondary = | |
| 611 | g_strdup_printf(_("Are you sure you want to block %s?"), name); | |
| 612 | ||
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
613 | purple_request_action(account, _("Block User"), primary, secondary, |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16254
diff
changeset
|
614 | 0, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16254
diff
changeset
|
615 | account, name, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
616 | data, 2, |
| 12603 | 617 | _("_Block"), G_CALLBACK(confirm_permit_block_cb), |
| 6371 | 618 | _("Cancel"), G_CALLBACK(destroy_request_data)); |
| 619 | ||
| 620 | g_free(primary); | |
| 621 | g_free(secondary); | |
| 622 | } | |
| 623 | } | |
| 624 | ||
| 625 | static void | |
| 15884 | 626 | pidgin_permit_added_removed(PurpleAccount *account, const char *name) |
| 6371 | 627 | { |
| 628 | if (privacy_dialog != NULL) | |
| 629 | rebuild_allow_list(privacy_dialog); | |
| 630 | } | |
| 631 | ||
| 632 | static void | |
| 15884 | 633 | pidgin_deny_added_removed(PurpleAccount *account, const char *name) |
| 6371 | 634 | { |
| 635 | if (privacy_dialog != NULL) | |
| 636 | rebuild_block_list(privacy_dialog); | |
| 637 | } | |
| 638 | ||
| 15884 | 639 | static PurplePrivacyUiOps privacy_ops = |
| 6371 | 640 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
641 | pidgin_permit_added_removed, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
642 | pidgin_permit_added_removed, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
643 | pidgin_deny_added_removed, |
|
16752
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
644 | pidgin_deny_added_removed, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
645 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
646 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
647 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
648 | NULL |
| 6371 | 649 | }; |
| 650 | ||
| 15884 | 651 | PurplePrivacyUiOps * |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
652 | pidgin_privacy_get_ui_ops(void) |
| 6371 | 653 | { |
| 654 | return &privacy_ops; | |
| 655 | } | |
| 656 | ||
| 657 | void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
658 | pidgin_privacy_init(void) |
| 6371 | 659 | { |
| 660 | } |