pidgin/gtkaccount.c

branch
soc.2008.masterpassword
changeset 34106
1b0c94670bcc
parent 34101
9c3c6a138135
parent 33268
a24713d9bbb3
child 34108
7a07b6857540
equal deleted inserted replaced
34105:95a7fb13796f 34106:1b0c94670bcc
46 #include "gtkutils.h" 46 #include "gtkutils.h"
47 #include "gtkstatusbox.h" 47 #include "gtkstatusbox.h"
48 #include "pidginstock.h" 48 #include "pidginstock.h"
49 #include "minidialog.h" 49 #include "minidialog.h"
50 50
51 #include "gtk3compat.h"
52
51 enum 53 enum
52 { 54 {
53 COLUMN_ICON, 55 COLUMN_ICON,
54 COLUMN_BUDDYICON, 56 COLUMN_BUDDYICON,
55 COLUMN_USERNAME, 57 COLUMN_USERNAME,
247 add_voice_options(dialog); 249 add_voice_options(dialog);
248 250
249 gtk_widget_grab_focus(dialog->protocol_menu); 251 gtk_widget_grab_focus(dialog->protocol_menu);
250 252
251 if (!dialog->prpl_info || !dialog->prpl_info->register_user) { 253 if (!dialog->prpl_info || !dialog->prpl_info->register_user) {
254 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
255 dialog->register_button), FALSE);
252 gtk_widget_hide(dialog->register_button); 256 gtk_widget_hide(dialog->register_button);
253 } else { 257 } else {
254 if (dialog->prpl_info != NULL && 258 if (dialog->prpl_info != NULL &&
255 (dialog->prpl_info->options & OPT_PROTO_REGISTER_NOSCREENNAME)) { 259 (dialog->prpl_info->options & OPT_PROTO_REGISTER_NOSCREENNAME)) {
256 gtk_widget_set_sensitive(dialog->register_button, TRUE); 260 gtk_widget_set_sensitive(dialog->register_button, TRUE);
257 } else { 261 } else {
262 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
263 dialog->register_button), FALSE);
258 gtk_widget_set_sensitive(dialog->register_button, FALSE); 264 gtk_widget_set_sensitive(dialog->register_button, FALSE);
259 } 265 }
260 gtk_widget_show(dialog->register_button); 266 gtk_widget_show(dialog->register_button);
261 } 267 }
262 } 268 }
265 username_focus_cb(GtkWidget *widget, GdkEventFocus *event, AccountPrefsDialog *dialog) 271 username_focus_cb(GtkWidget *widget, GdkEventFocus *event, AccountPrefsDialog *dialog)
266 { 272 {
267 GHashTable *table; 273 GHashTable *table;
268 const char *label; 274 const char *label;
269 275
276 if (!dialog->prpl_info || ! PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(
277 dialog->prpl_info, get_account_text_table)) {
278 return FALSE;
279 }
280
270 table = dialog->prpl_info->get_account_text_table(NULL); 281 table = dialog->prpl_info->get_account_text_table(NULL);
271 label = g_hash_table_lookup(table, "login_label"); 282 label = g_hash_table_lookup(table, "login_label");
272 283
273 if(!strcmp(gtk_entry_get_text(GTK_ENTRY(widget)), label)) { 284 if(!strcmp(gtk_entry_get_text(GTK_ENTRY(widget)), label)) {
274 gtk_entry_set_text(GTK_ENTRY(widget), ""); 285 gtk_entry_set_text(GTK_ENTRY(widget), "");
281 } 292 }
282 293
283 static void 294 static void
284 username_changed_cb(GtkEntry *entry, AccountPrefsDialog *dialog) 295 username_changed_cb(GtkEntry *entry, AccountPrefsDialog *dialog)
285 { 296 {
286 if (dialog->ok_button) 297 gboolean opt_noscreenname = (dialog->prpl_info != NULL &&
287 gtk_widget_set_sensitive(dialog->ok_button, 298 (dialog->prpl_info->options & OPT_PROTO_REGISTER_NOSCREENNAME));
288 *gtk_entry_get_text(entry) != '\0'); 299 gboolean username_valid = purple_validate(dialog->plugin,
300 gtk_entry_get_text(entry));
301
302 if (dialog->ok_button) {
303 if (opt_noscreenname && dialog->register_button &&
304 gtk_toggle_button_get_active(
305 GTK_TOGGLE_BUTTON(dialog->register_button)))
306 gtk_widget_set_sensitive(dialog->ok_button, TRUE);
307 else
308 gtk_widget_set_sensitive(dialog->ok_button,
309 username_valid);
310 }
311
289 if (dialog->register_button) { 312 if (dialog->register_button) {
290 if (dialog->prpl_info != NULL && (dialog->prpl_info->options & OPT_PROTO_REGISTER_NOSCREENNAME)) 313 if (opt_noscreenname)
291 gtk_widget_set_sensitive(dialog->register_button, TRUE); 314 gtk_widget_set_sensitive(dialog->register_button, TRUE);
292 else 315 else
293 gtk_widget_set_sensitive(dialog->register_button, 316 gtk_widget_set_sensitive(dialog->register_button,
294 *gtk_entry_get_text(entry) != '\0'); 317 username_valid);
295 } 318 }
296 } 319 }
297 320
298 static gboolean 321 static gboolean
299 username_nofocus_cb(GtkWidget *widget, GdkEventFocus *event, AccountPrefsDialog *dialog) 322 username_nofocus_cb(GtkWidget *widget, GdkEventFocus *event, AccountPrefsDialog *dialog)
322 345
323 return FALSE; 346 return FALSE;
324 } 347 }
325 348
326 static void 349 static void
350 register_button_cb(GtkWidget *checkbox, AccountPrefsDialog *dialog)
351 {
352 int register_checked = gtk_toggle_button_get_active(
353 GTK_TOGGLE_BUTTON(dialog->register_button));
354 int opt_noscreenname = (dialog->prpl_info != NULL &&
355 (dialog->prpl_info->options & OPT_PROTO_REGISTER_NOSCREENNAME));
356 int register_noscreenname = (opt_noscreenname && register_checked);
357
358 /* get rid of login_label in username field */
359 username_focus_cb(dialog->username_entry, NULL, dialog);
360
361 if (register_noscreenname) {
362 gtk_entry_set_text(GTK_ENTRY(dialog->username_entry), "");
363 gtk_entry_set_text(GTK_ENTRY(dialog->password_entry), "");
364 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->remember_pass_check), FALSE);
365 }
366 gtk_widget_set_sensitive(dialog->username_entry, !register_noscreenname);
367 gtk_widget_set_sensitive(dialog->password_entry, !register_noscreenname);
368 gtk_widget_set_sensitive(dialog->remember_pass_check, !register_noscreenname);
369
370 if (dialog->ok_button) {
371 gtk_widget_set_sensitive(dialog->ok_button,
372 (opt_noscreenname && register_checked) ||
373 *gtk_entry_get_text(GTK_ENTRY(dialog->username_entry))
374 != '\0');
375 }
376
377 username_nofocus_cb(dialog->username_entry, NULL, dialog);
378 }
379
380 static void
327 icon_filesel_choose_cb(const char *filename, gpointer data) 381 icon_filesel_choose_cb(const char *filename, gpointer data)
328 { 382 {
329 AccountPrefsDialog *dialog = data; 383 AccountPrefsDialog *dialog = data;
330 384
331 if (filename != NULL) 385 if (filename != NULL)
353 407
354 static void 408 static void
355 account_dnd_recv(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, 409 account_dnd_recv(GtkWidget *widget, GdkDragContext *dc, gint x, gint y,
356 GtkSelectionData *sd, guint info, guint t, AccountPrefsDialog *dialog) 410 GtkSelectionData *sd, guint info, guint t, AccountPrefsDialog *dialog)
357 { 411 {
358 gchar *name = (gchar *)sd->data; 412 const gchar *name = (gchar *)gtk_selection_data_get_data(sd);
359 413 gint length = gtk_selection_data_get_length(sd);
360 if ((sd->length >= 0) && (sd->format == 8)) { 414 gint format = gtk_selection_data_get_format(sd);
415
416 if ((length >= 0) && (format == 8)) {
361 /* Well, it looks like the drag event was cool. 417 /* Well, it looks like the drag event was cool.
362 * Let's do something with it */ 418 * Let's do something with it */
363 if (!g_ascii_strncasecmp(name, "file://", 7)) { 419 if (!g_ascii_strncasecmp(name, "file://", 7)) {
364 GError *converr = NULL; 420 GError *converr = NULL;
365 gchar *tmp, *rtmp; 421 gchar *tmp, *rtmp;
428 GList *l, *l2; 484 GList *l, *l2;
429 char *username = NULL; 485 char *username = NULL;
430 486
431 if (dialog->protocol_menu != NULL) 487 if (dialog->protocol_menu != NULL)
432 { 488 {
433 #if GTK_CHECK_VERSION(2,12,0)
434 g_object_ref(G_OBJECT(dialog->protocol_menu)); 489 g_object_ref(G_OBJECT(dialog->protocol_menu));
435 #else
436 gtk_widget_ref(dialog->protocol_menu);
437 #endif
438 hbox = g_object_get_data(G_OBJECT(dialog->protocol_menu), "container"); 490 hbox = g_object_get_data(G_OBJECT(dialog->protocol_menu), "container");
439 gtk_container_remove(GTK_CONTAINER(hbox), dialog->protocol_menu); 491 gtk_container_remove(GTK_CONTAINER(hbox), dialog->protocol_menu);
440 } 492 }
441 493
442 if (dialog->login_frame != NULL) 494 if (dialog->login_frame != NULL)
459 /* Protocol */ 511 /* Protocol */
460 if (dialog->protocol_menu == NULL) 512 if (dialog->protocol_menu == NULL)
461 { 513 {
462 dialog->protocol_menu = pidgin_protocol_option_menu_new( 514 dialog->protocol_menu = pidgin_protocol_option_menu_new(
463 dialog->protocol_id, G_CALLBACK(set_account_protocol_cb), dialog); 515 dialog->protocol_id, G_CALLBACK(set_account_protocol_cb), dialog);
464 #if GTK_CHECK_VERSION(2,12,0)
465 g_object_ref(G_OBJECT(dialog->protocol_menu)); 516 g_object_ref(G_OBJECT(dialog->protocol_menu));
466 #else
467 gtk_widget_ref(dialog->protocol_menu);
468 #endif
469 } 517 }
470 518
471 hbox = add_pref_box(dialog, vbox, _("Pro_tocol:"), dialog->protocol_menu); 519 hbox = add_pref_box(dialog, vbox, _("Pro_tocol:"), dialog->protocol_menu);
472 g_object_set_data(G_OBJECT(dialog->protocol_menu), "container", hbox); 520 g_object_set_data(G_OBJECT(dialog->protocol_menu), "container", hbox);
473 521
474 #if GTK_CHECK_VERSION(2,12,0)
475 g_object_unref(G_OBJECT(dialog->protocol_menu)); 522 g_object_unref(G_OBJECT(dialog->protocol_menu));
476 #else
477 gtk_widget_unref(dialog->protocol_menu);
478 #endif
479 523
480 /* Username */ 524 /* Username */
481 dialog->username_entry = gtk_entry_new(); 525 dialog->username_entry = gtk_entry_new();
482 g_object_set(G_OBJECT(dialog->username_entry), "truncate-multiline", TRUE, NULL); 526 g_object_set(G_OBJECT(dialog->username_entry), "truncate-multiline", TRUE, NULL);
483 527
767 char buf[1024]; 811 char buf[1024];
768 char *title, *tmp; 812 char *title, *tmp;
769 const char *str_value; 813 const char *str_value;
770 gboolean bool_value; 814 gboolean bool_value;
771 ProtocolOptEntry *opt_entry; 815 ProtocolOptEntry *opt_entry;
816 const GSList *str_hints;
772 817
773 if (dialog->protocol_frame != NULL) { 818 if (dialog->protocol_frame != NULL) {
774 gtk_notebook_remove_page (GTK_NOTEBOOK(dialog->notebook), 1); 819 gtk_notebook_remove_page (GTK_NOTEBOOK(dialog->notebook), 1);
775 dialog->protocol_frame = NULL; 820 dialog->protocol_frame = NULL;
776 } 821 }
867 str_value = purple_account_get_string(account, 912 str_value = purple_account_get_string(account,
868 purple_account_option_get_setting(option), 913 purple_account_option_get_setting(option),
869 purple_account_option_get_default_string(option)); 914 purple_account_option_get_default_string(option));
870 } 915 }
871 916
872 opt_entry->widget = entry = gtk_entry_new(); 917 str_hints = purple_account_option_string_get_hints(option);
873 if (purple_account_option_get_masked(option)) 918 if (str_hints)
919 {
920 const GSList *hint_it = str_hints;
921 entry = gtk_combo_box_text_new_with_entry();
922 while (hint_it)
923 {
924 const gchar *hint = hint_it->data;
925 hint_it = g_slist_next(hint_it);
926 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(entry),
927 hint);
928 }
929 }
930 else
931 entry = gtk_entry_new();
932
933 opt_entry->widget = entry;
934 if (purple_account_option_string_get_masked(option) && str_hints)
935 g_warn_if_reached();
936 else if (purple_account_option_string_get_masked(option))
874 { 937 {
875 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); 938 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
876 #if !GTK_CHECK_VERSION(2,16,0) 939 #if !GTK_CHECK_VERSION(2,16,0)
877 if (gtk_entry_get_invisible_char(GTK_ENTRY(entry)) == '*') 940 if (gtk_entry_get_invisible_char(GTK_ENTRY(entry)) == '*')
878 gtk_entry_set_invisible_char(GTK_ENTRY(entry), PIDGIN_INVISIBLE_CHAR); 941 gtk_entry_set_invisible_char(GTK_ENTRY(entry), PIDGIN_INVISIBLE_CHAR);
879 #endif /* Less than GTK+ 2.16 */ 942 #endif /* Less than GTK+ 2.16 */
880 } 943 }
881 944
882 if (str_value != NULL) 945 if (str_value != NULL && str_hints)
946 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry))),
947 str_value);
948 else
883 gtk_entry_set_text(GTK_ENTRY(entry), str_value); 949 gtk_entry_set_text(GTK_ENTRY(entry), str_value);
884 950
885 title = g_strdup_printf("_%s:", 951 title = g_strdup_printf("_%s:",
886 purple_account_option_get_text(option)); 952 purple_account_option_get_text(option));
887 add_pref_box(dialog, vbox, title, entry); 953 add_pref_box(dialog, vbox, title, entry);
1033 1099
1034 if (dialog->new_proxy_type == PURPLE_PROXY_USE_GLOBAL || 1100 if (dialog->new_proxy_type == PURPLE_PROXY_USE_GLOBAL ||
1035 dialog->new_proxy_type == PURPLE_PROXY_NONE || 1101 dialog->new_proxy_type == PURPLE_PROXY_NONE ||
1036 dialog->new_proxy_type == PURPLE_PROXY_USE_ENVVAR) { 1102 dialog->new_proxy_type == PURPLE_PROXY_USE_ENVVAR) {
1037 1103
1038 gtk_widget_hide_all(dialog->proxy_vbox); 1104 gtk_widget_hide(dialog->proxy_vbox);
1039 } 1105 }
1040 else 1106 else
1041 gtk_widget_show_all(dialog->proxy_vbox); 1107 gtk_widget_show_all(dialog->proxy_vbox);
1042 } 1108 }
1043 1109
1235 1301
1236 static void 1302 static void
1237 cancel_account_prefs_cb(GtkWidget *w, AccountPrefsDialog *dialog) 1303 cancel_account_prefs_cb(GtkWidget *w, AccountPrefsDialog *dialog)
1238 { 1304 {
1239 account_win_destroy_cb(NULL, NULL, dialog); 1305 account_win_destroy_cb(NULL, NULL, dialog);
1306 }
1307
1308 static void
1309 account_register_cb(PurpleAccount *account, gboolean succeeded, void *user_data)
1310 {
1311 if (succeeded)
1312 {
1313 const PurpleSavedStatus *saved_status = purple_savedstatus_get_current();
1314 purple_signal_emit(pidgin_account_get_handle(), "account-modified", account);
1315
1316 if (saved_status != NULL && purple_account_get_remember_password(account)) {
1317 purple_savedstatus_activate_for_account(saved_status, account);
1318 purple_account_set_enabled(account, PIDGIN_UI, TRUE);
1319 }
1320 }
1321 else
1322 purple_accounts_delete(account);
1240 } 1323 }
1241 1324
1242 static void 1325 static void
1243 ok_account_prefs_cb(GtkWidget *w, AccountPrefsDialog *dialog) 1326 ok_account_prefs_cb(GtkWidget *w, AccountPrefsDialog *dialog)
1244 { 1327 {
1396 1479
1397 opt_entry = l2->data; 1480 opt_entry = l2->data;
1398 1481
1399 switch (opt_entry->type) { 1482 switch (opt_entry->type) {
1400 case PURPLE_PREF_STRING: 1483 case PURPLE_PREF_STRING:
1401 value = gtk_entry_get_text(GTK_ENTRY(opt_entry->widget)); 1484 if (GTK_IS_COMBO_BOX(opt_entry->widget))
1485 value = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(opt_entry->widget));
1486 else
1487 value = gtk_entry_get_text(GTK_ENTRY(opt_entry->widget));
1402 purple_account_set_string(account, opt_entry->setting, value); 1488 purple_account_set_string(account, opt_entry->setting, value);
1403 break; 1489 break;
1404 1490
1405 case PURPLE_PREF_INT: 1491 case PURPLE_PREF_INT:
1406 int_value = atoi(gtk_entry_get_text(GTK_ENTRY(opt_entry->widget))); 1492 int_value = atoi(gtk_entry_get_text(GTK_ENTRY(opt_entry->widget)));
1493 else 1579 else
1494 purple_signal_emit(pidgin_account_get_handle(), "account-modified", account); 1580 purple_signal_emit(pidgin_account_get_handle(), "account-modified", account);
1495 1581
1496 /* If this is a new account, then sign on! */ 1582 /* If this is a new account, then sign on! */
1497 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->register_button))) { 1583 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->register_button))) {
1584 purple_account_set_register_callback(account, account_register_cb, NULL);
1498 purple_account_register(account); 1585 purple_account_register(account);
1499 } else if (new_acct) { 1586 } else if (new_acct) {
1500 const PurpleSavedStatus *saved_status; 1587 const PurpleSavedStatus *saved_status;
1501 1588
1502 saved_status = purple_savedstatus_get_current(); 1589 saved_status = purple_savedstatus_get_current();
1593 button = gtk_check_button_new_with_mnemonic( 1680 button = gtk_check_button_new_with_mnemonic(
1594 _("Create _this new account on the server")); 1681 _("Create _this new account on the server"));
1595 gtk_box_pack_start(GTK_BOX(main_vbox), button, FALSE, FALSE, 0); 1682 gtk_box_pack_start(GTK_BOX(main_vbox), button, FALSE, FALSE, 0);
1596 gtk_widget_show(button); 1683 gtk_widget_show(button);
1597 dialog->register_button = button; 1684 dialog->register_button = button;
1685 g_signal_connect(G_OBJECT(dialog->register_button), "toggled", G_CALLBACK(register_button_cb), dialog);
1598 if (dialog->account == NULL) 1686 if (dialog->account == NULL)
1599 gtk_widget_set_sensitive(button, FALSE); 1687 gtk_widget_set_sensitive(button, FALSE);
1600 1688
1601 if (!dialog->prpl_info || !dialog->prpl_info->register_user) 1689 if (!dialog->prpl_info || !dialog->prpl_info->register_user)
1602 gtk_widget_hide(button); 1690 gtk_widget_hide(button);
1758 static void 1846 static void
1759 drag_data_get_cb(GtkWidget *widget, GdkDragContext *ctx, 1847 drag_data_get_cb(GtkWidget *widget, GdkDragContext *ctx,
1760 GtkSelectionData *data, guint info, guint time, 1848 GtkSelectionData *data, guint info, guint time,
1761 AccountsWindow *dialog) 1849 AccountsWindow *dialog)
1762 { 1850 {
1763 if (data->target == gdk_atom_intern("PURPLE_ACCOUNT", FALSE)) { 1851 GdkAtom target = gtk_selection_data_get_target(data);
1852
1853 if (target == gdk_atom_intern("PURPLE_ACCOUNT", FALSE)) {
1764 GtkTreeRowReference *ref; 1854 GtkTreeRowReference *ref;
1765 GtkTreePath *source_row; 1855 GtkTreePath *source_row;
1766 GtkTreeIter iter; 1856 GtkTreeIter iter;
1767 PurpleAccount *account = NULL; 1857 PurpleAccount *account = NULL;
1768 GValue val; 1858 GValue val;
1829 static void 1919 static void
1830 drag_data_received_cb(GtkWidget *widget, GdkDragContext *ctx, 1920 drag_data_received_cb(GtkWidget *widget, GdkDragContext *ctx,
1831 guint x, guint y, GtkSelectionData *sd, 1921 guint x, guint y, GtkSelectionData *sd,
1832 guint info, guint t, AccountsWindow *dialog) 1922 guint info, guint t, AccountsWindow *dialog)
1833 { 1923 {
1834 if (sd->target == gdk_atom_intern("PURPLE_ACCOUNT", FALSE) && sd->data) { 1924 GdkAtom target = gtk_selection_data_get_target(sd);
1925 const guchar *data = gtk_selection_data_get_data(sd);
1926
1927 if (target == gdk_atom_intern("PURPLE_ACCOUNT", FALSE) && data) {
1835 gint dest_index; 1928 gint dest_index;
1836 PurpleAccount *a = NULL; 1929 PurpleAccount *a = NULL;
1837 GtkTreePath *path = NULL; 1930 GtkTreePath *path = NULL;
1838 GtkTreeViewDropPosition position; 1931 GtkTreeViewDropPosition position;
1839 1932
1840 memcpy(&a, sd->data, sizeof(a)); 1933 memcpy(&a, data, sizeof(a));
1841 1934
1842 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, 1935 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y,
1843 &path, &position)) { 1936 &path, &position)) {
1844 1937
1845 GtkTreeIter iter; 1938 GtkTreeIter iter;
2338 accounts_window = dialog = g_new0(AccountsWindow, 1); 2431 accounts_window = dialog = g_new0(AccountsWindow, 1);
2339 2432
2340 width = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/accounts/dialog/width"); 2433 width = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/accounts/dialog/width");
2341 height = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/accounts/dialog/height"); 2434 height = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/accounts/dialog/height");
2342 2435
2436 #if GTK_CHECK_VERSION(3,0,0)
2437 dialog->window = win = pidgin_create_dialog(_("Accounts"), 0, "accounts", TRUE);
2438 #else
2343 dialog->window = win = pidgin_create_dialog(_("Accounts"), PIDGIN_HIG_BORDER, "accounts", TRUE); 2439 dialog->window = win = pidgin_create_dialog(_("Accounts"), PIDGIN_HIG_BORDER, "accounts", TRUE);
2440 #endif
2344 gtk_window_set_default_size(GTK_WINDOW(win), width, height); 2441 gtk_window_set_default_size(GTK_WINDOW(win), width, height);
2345 2442
2346 g_signal_connect(G_OBJECT(win), "delete_event", 2443 g_signal_connect(G_OBJECT(win), "delete_event",
2347 G_CALLBACK(accedit_win_destroy_cb), accounts_window); 2444 G_CALLBACK(accedit_win_destroy_cb), accounts_window);
2348 2445

mercurial