Mon, 26 Nov 2007 08:47:08 +0000
Patch from fmoo. This makes a lot of the windows closeable with Escape. There
may be other windows that need this.
The buttons at the bottom don't quite line up properly. That needs to be fixed.
Closes #2137.
| 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 | |
|
22000
5e7708f58d3d
Patch from fmoo. This makes a lot of the windows closeable with Escape. There
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
370 | dialog->win = pidgin_create_dialog(_("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 */ | |
|
22000
5e7708f58d3d
Patch from fmoo. This makes a lot of the windows closeable with Escape. There
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
376 | vbox = pidgin_dialog_get_vbox_with_properties(GTK_DIALOG(dialog->win), FALSE, PIDGIN_HIG_BORDER); |
| 6371 | 377 | |
| 378 | /* Description label */ | |
| 379 | label = gtk_label_new( | |
| 380 | _("Changes to privacy settings take effect immediately.")); | |
| 381 | ||
| 382 | gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
| 383 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 384 | gtk_widget_show(label); | |
| 385 | ||
| 386 | /* Hbox for the accounts drop-down and label. */ | |
| 15882 | 387 | hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER); |
| 6371 | 388 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
| 389 | gtk_widget_show(hbox); | |
| 390 | ||
| 391 | /* "Set privacy for:" label */ | |
| 392 | label = gtk_label_new(_("Set privacy for:")); | |
| 393 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 394 | gtk_widget_show(label); | |
| 395 | ||
| 396 | /* Accounts drop-down */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
397 | dropdown = pidgin_account_option_menu_new(NULL, FALSE, |
|
12852
dc6be215f15e
[gaim-migrate @ 15202]
Richard Laager <rlaager@pidgin.im>
parents:
12849
diff
changeset
|
398 | G_CALLBACK(select_account_cb), NULL, dialog); |
| 6371 | 399 | gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
| 400 | gtk_widget_show(dropdown); | |
| 15568 | 401 | pidgin_set_accessible_label (dropdown, label); |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
402 | dialog->account = pidgin_account_option_menu_get_selected(dropdown); |
| 6371 | 403 | |
| 404 | /* Add the drop-down list with the allow/block types. */ | |
| 405 | dialog->type_menu = gtk_option_menu_new(); | |
| 406 | gtk_box_pack_start(GTK_BOX(vbox), dialog->type_menu, FALSE, FALSE, 0); | |
| 407 | gtk_widget_show(dialog->type_menu); | |
| 408 | ||
| 409 | /* Build the menu for that. */ | |
| 410 | menu = gtk_menu_new(); | |
| 411 | ||
| 412 | for (i = 0; i < menu_entry_count; i++) { | |
| 15568 | 413 | pidgin_new_item(menu, _(menu_entries[i].text)); |
| 6371 | 414 | |
| 415 | if (menu_entries[i].num == dialog->account->perm_deny) | |
| 416 | selected = i; | |
| 417 | } | |
| 418 | ||
| 419 | gtk_option_menu_set_menu(GTK_OPTION_MENU(dialog->type_menu), menu); | |
| 420 | gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), selected); | |
| 421 | ||
| 422 | g_signal_connect(G_OBJECT(dialog->type_menu), "changed", | |
| 423 | G_CALLBACK(type_changed_cb), dialog); | |
| 424 | ||
| 425 | /* Build the treeview for the allow list. */ | |
| 426 | dialog->allow_widget = build_allow_list(dialog); | |
| 427 | gtk_box_pack_start(GTK_BOX(vbox), dialog->allow_widget, TRUE, TRUE, 0); | |
| 428 | ||
| 429 | /* Build the treeview for the block list. */ | |
| 430 | dialog->block_widget = build_block_list(dialog); | |
| 431 | gtk_box_pack_start(GTK_BOX(vbox), dialog->block_widget, TRUE, TRUE, 0); | |
| 432 | ||
| 433 | /* Add the button box for Add, Remove, Clear */ | |
| 434 | dialog->button_box = bbox = gtk_hbutton_box_new(); | |
| 435 | gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD); | |
| 436 | gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
| 437 | ||
| 438 | /* Add button */ | |
| 439 | button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
| 440 | dialog->add_button = button; | |
| 441 | gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 442 | gtk_widget_show(button); | |
| 443 | ||
| 444 | g_signal_connect(G_OBJECT(button), "clicked", | |
| 445 | G_CALLBACK(add_cb), dialog); | |
| 446 | ||
| 447 | /* Remove button */ | |
| 448 | button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); | |
| 449 | dialog->remove_button = button; | |
| 450 | gtk_widget_set_sensitive(button, FALSE); | |
| 451 | gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 452 | gtk_widget_show(button); | |
| 453 | ||
| 454 | g_signal_connect(G_OBJECT(button), "clicked", | |
| 455 | G_CALLBACK(remove_cb), dialog); | |
| 456 | ||
| 457 | /* Clear button */ | |
| 458 | button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | |
| 459 | dialog->clear_button = button; | |
| 460 | gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 461 | gtk_widget_show(button); | |
| 462 | ||
| 463 | g_signal_connect(G_OBJECT(button), "clicked", | |
| 464 | G_CALLBACK(clear_cb), dialog); | |
| 465 | ||
| 466 | /* Another button box. */ | |
|
22000
5e7708f58d3d
Patch from fmoo. This makes a lot of the windows closeable with Escape. There
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
467 | bbox = pidgin_dialog_get_action_area(GTK_DIALOG(dialog->win)); |
| 6371 | 468 | gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |
| 469 | ||
| 470 | /* Close button */ | |
| 471 | button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
| 472 | gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 473 | gtk_widget_show(button); | |
| 474 | ||
| 475 | g_signal_connect(G_OBJECT(button), "clicked", | |
| 476 | G_CALLBACK(close_cb), dialog); | |
| 477 | ||
| 15884 | 478 | if (dialog->account->perm_deny == PURPLE_PRIVACY_ALLOW_USERS) { |
| 6371 | 479 | gtk_widget_show(dialog->allow_widget); |
| 480 | gtk_widget_show(dialog->button_box); | |
| 481 | dialog->in_allow_list = TRUE; | |
| 482 | } | |
| 15884 | 483 | else if (dialog->account->perm_deny == PURPLE_PRIVACY_DENY_USERS) { |
| 6371 | 484 | gtk_widget_show(dialog->block_widget); |
| 485 | gtk_widget_show(dialog->button_box); | |
| 486 | dialog->in_allow_list = FALSE; | |
| 487 | } | |
| 488 | ||
| 489 | return dialog; | |
| 490 | } | |
| 491 | ||
| 492 | void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
493 | pidgin_privacy_dialog_show(void) |
| 6371 | 494 | { |
| 15884 | 495 | g_return_if_fail(purple_connections_get_all() != NULL); |
|
10352
802e7ab5b838
[gaim-migrate @ 11569]
Mark Doliner <markdoliner@pidgin.im>
parents:
10148
diff
changeset
|
496 | |
| 6371 | 497 | if (privacy_dialog == NULL) |
| 498 | privacy_dialog = privacy_dialog_new(); | |
| 499 | ||
| 500 | gtk_widget_show(privacy_dialog->win); | |
| 501 | gdk_window_raise(privacy_dialog->win->window); | |
| 502 | } | |
| 503 | ||
| 504 | void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
505 | pidgin_privacy_dialog_hide(void) |
| 6371 | 506 | { |
| 507 | if (privacy_dialog == NULL) | |
| 508 | return; | |
| 509 | ||
|
7165
6547d94b0725
[gaim-migrate @ 7732]
Mark Doliner <markdoliner@pidgin.im>
parents:
6646
diff
changeset
|
510 | g_free(privacy_dialog); |
| 6371 | 511 | privacy_dialog = NULL; |
| 512 | } | |
| 513 | ||
| 514 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
515 | destroy_request_data(PidginPrivacyRequestData *data) |
| 6371 | 516 | { |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13775
diff
changeset
|
517 | g_free(data->name); |
| 6371 | 518 | g_free(data); |
| 519 | } | |
| 520 | ||
| 521 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
522 | confirm_permit_block_cb(PidginPrivacyRequestData *data, int option) |
| 6371 | 523 | { |
| 524 | if (data->block) | |
| 15884 | 525 | purple_privacy_deny(data->account, data->name, FALSE, FALSE); |
| 6371 | 526 | else |
| 15884 | 527 | purple_privacy_allow(data->account, data->name, FALSE, FALSE); |
| 6371 | 528 | |
| 529 | destroy_request_data(data); | |
| 530 | } | |
| 531 | ||
| 532 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
533 | add_permit_block_cb(PidginPrivacyRequestData *data, const char *name) |
| 6371 | 534 | { |
| 535 | data->name = g_strdup(name); | |
| 536 | ||
| 537 | confirm_permit_block_cb(data, 0); | |
| 538 | } | |
| 539 | ||
| 540 | void | |
| 15884 | 541 | pidgin_request_add_permit(PurpleAccount *account, const char *name) |
| 6371 | 542 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
543 | PidginPrivacyRequestData *data; |
| 6371 | 544 | |
| 545 | g_return_if_fail(account != NULL); | |
| 546 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
547 | data = g_new0(PidginPrivacyRequestData, 1); |
| 6371 | 548 | data->account = account; |
| 549 | data->name = g_strdup(name); | |
| 550 | data->block = FALSE; | |
| 551 | ||
| 552 | if (name == NULL) { | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
553 | purple_request_input(account, _("Permit User"), |
| 6371 | 554 | _("Type a user you permit to contact you."), |
| 555 | _("Please enter the name of the user you wish to be " | |
| 556 | "able to contact you."), | |
| 8697 | 557 | NULL, FALSE, FALSE, NULL, |
| 12603 | 558 | _("_Permit"), G_CALLBACK(add_permit_block_cb), |
| 6371 | 559 | _("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
|
560 | account, name, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
561 | data); |
| 6371 | 562 | } |
| 563 | else { | |
| 564 | char *primary = g_strdup_printf(_("Allow %s to contact you?"), name); | |
| 565 | char *secondary = | |
| 566 | g_strdup_printf(_("Are you sure you wish to allow " | |
| 567 | "%s to contact you?"), name); | |
| 568 | ||
| 569 | ||
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
570 | 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
|
571 | 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
|
572 | account, name, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
573 | data, 2, |
| 12603 | 574 | _("_Permit"), G_CALLBACK(confirm_permit_block_cb), |
| 6371 | 575 | _("Cancel"), G_CALLBACK(destroy_request_data)); |
| 576 | ||
| 577 | g_free(primary); | |
| 578 | g_free(secondary); | |
| 579 | } | |
| 580 | } | |
| 581 | ||
| 582 | void | |
| 15884 | 583 | pidgin_request_add_block(PurpleAccount *account, const char *name) |
| 6371 | 584 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
585 | PidginPrivacyRequestData *data; |
| 6371 | 586 | |
| 587 | g_return_if_fail(account != NULL); | |
| 588 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
589 | data = g_new0(PidginPrivacyRequestData, 1); |
| 6371 | 590 | data->account = account; |
| 591 | data->name = g_strdup(name); | |
| 592 | data->block = TRUE; | |
| 593 | ||
| 594 | if (name == NULL) { | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
595 | purple_request_input(account, _("Block User"), |
| 6371 | 596 | _("Type a user to block."), |
| 597 | _("Please enter the name of the user you wish to block."), | |
| 8697 | 598 | NULL, FALSE, FALSE, NULL, |
| 12603 | 599 | _("_Block"), G_CALLBACK(add_permit_block_cb), |
| 6371 | 600 | _("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
|
601 | account, name, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
602 | data); |
| 6371 | 603 | } |
| 604 | else { | |
| 605 | char *primary = g_strdup_printf(_("Block %s?"), name); | |
| 606 | char *secondary = | |
| 607 | g_strdup_printf(_("Are you sure you want to block %s?"), name); | |
| 608 | ||
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
609 | 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
|
610 | 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
|
611 | account, name, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
612 | data, 2, |
| 12603 | 613 | _("_Block"), G_CALLBACK(confirm_permit_block_cb), |
| 6371 | 614 | _("Cancel"), G_CALLBACK(destroy_request_data)); |
| 615 | ||
| 616 | g_free(primary); | |
| 617 | g_free(secondary); | |
| 618 | } | |
| 619 | } | |
| 620 | ||
| 621 | static void | |
| 15884 | 622 | pidgin_permit_added_removed(PurpleAccount *account, const char *name) |
| 6371 | 623 | { |
| 624 | if (privacy_dialog != NULL) | |
| 625 | rebuild_allow_list(privacy_dialog); | |
| 626 | } | |
| 627 | ||
| 628 | static void | |
| 15884 | 629 | pidgin_deny_added_removed(PurpleAccount *account, const char *name) |
| 6371 | 630 | { |
| 631 | if (privacy_dialog != NULL) | |
| 632 | rebuild_block_list(privacy_dialog); | |
| 633 | } | |
| 634 | ||
| 15884 | 635 | static PurplePrivacyUiOps privacy_ops = |
| 6371 | 636 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
637 | pidgin_permit_added_removed, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
638 | pidgin_permit_added_removed, |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
639 | 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
|
640 | 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
|
641 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
642 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
643 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
644 | NULL |
| 6371 | 645 | }; |
| 646 | ||
| 15884 | 647 | PurplePrivacyUiOps * |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
648 | pidgin_privacy_get_ui_ops(void) |
| 6371 | 649 | { |
| 650 | return &privacy_ops; | |
| 651 | } | |
| 652 | ||
| 653 | void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15486
diff
changeset
|
654 | pidgin_privacy_init(void) |
| 6371 | 655 | { |
| 656 | } |