diff options
Diffstat (limited to 'src/setup.c')
| -rw-r--r-- | src/setup.c | 1281 |
1 files changed, 1281 insertions, 0 deletions
diff --git a/src/setup.c b/src/setup.c new file mode 100644 index 0000000..8d54af0 --- /dev/null +++ b/src/setup.c | |||
| @@ -0,0 +1,1281 @@ | |||
| 1 | /* | ||
| 2 | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client | ||
| 3 | * Copyright (C) 1999-2014 Hiroyuki Yamamoto | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 18 | */ | ||
| 19 | |||
| 20 | #ifdef HAVE_CONFIG_H | ||
| 21 | # include "config.h" | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #include <glib.h> | ||
| 25 | #include <glib/gi18n.h> | ||
| 26 | #include <gtk/gtk.h> | ||
| 27 | |||
| 28 | #ifdef G_OS_WIN32 | ||
| 29 | # include <windows.h> | ||
| 30 | # include <winreg.h> | ||
| 31 | # include <wchar.h> | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #include "inputdialog.h" | ||
| 35 | #include "alertpanel.h" | ||
| 36 | #include "mainwindow.h" | ||
| 37 | #include "folderview.h" | ||
| 38 | #include "manage_window.h" | ||
| 39 | #include "account_dialog.h" | ||
| 40 | #include "gtkutils.h" | ||
| 41 | #include "filesel.h" | ||
| 42 | #include "prefs_common.h" | ||
| 43 | #include "stock_pixmap.h" | ||
| 44 | #include "account.h" | ||
| 45 | #include "addressbook.h" | ||
| 46 | #if USE_SSL | ||
| 47 | # include "ssl.h" | ||
| 48 | #endif | ||
| 49 | |||
| 50 | static PangoFontDescription *font_desc; | ||
| 51 | |||
| 52 | static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data); | ||
| 53 | |||
| 54 | |||
| 55 | static void button_toggled(GtkToggleButton *button, GtkWidget *widget) | ||
| 56 | { | ||
| 57 | gboolean is_active; | ||
| 58 | |||
| 59 | is_active = gtk_toggle_button_get_active(button); | ||
| 60 | gtk_widget_set_sensitive(widget, is_active); | ||
| 61 | } | ||
| 62 | |||
| 63 | static void sel_btn_clicked(GtkButton *button, GtkWidget *entry) | ||
| 64 | { | ||
| 65 | gchar *folder; | ||
| 66 | gchar *utf8_folder; | ||
| 67 | gchar *base; | ||
| 68 | |||
| 69 | folder = filesel_select_dir(NULL); | ||
| 70 | if (folder) { | ||
| 71 | utf8_folder = conv_filename_to_utf8(folder); | ||
| 72 | base = g_path_get_basename(utf8_folder); | ||
| 73 | if (!g_ascii_strcasecmp(base, "Mail")) { | ||
| 74 | gtk_entry_set_text(GTK_ENTRY(entry), utf8_folder); | ||
| 75 | } else { | ||
| 76 | gchar *text; | ||
| 77 | |||
| 78 | text = g_strconcat(utf8_folder, G_DIR_SEPARATOR_S, "Mail", NULL); | ||
| 79 | gtk_entry_set_text(GTK_ENTRY(entry), text); | ||
| 80 | g_free(text); | ||
| 81 | } | ||
| 82 | g_free(base); | ||
| 83 | g_free(utf8_folder); | ||
| 84 | g_free(folder); | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | #ifdef G_OS_WIN32 | ||
| 89 | #define MODIFY_LABEL_STYLE() \ | ||
| 90 | { \ | ||
| 91 | GtkStyle *style; \ | ||
| 92 | style = gtk_widget_get_style(dialog); \ | ||
| 93 | gtk_widget_modify_base(label, GTK_STATE_ACTIVE, \ | ||
| 94 | &style->base[GTK_STATE_SELECTED]); \ | ||
| 95 | gtk_widget_modify_text(label, GTK_STATE_ACTIVE, \ | ||
| 96 | &style->text[GTK_STATE_SELECTED]); \ | ||
| 97 | } | ||
| 98 | #else | ||
| 99 | #define MODIFY_LABEL_STYLE() | ||
| 100 | #endif | ||
| 101 | |||
| 102 | void setup_mailbox(void) | ||
| 103 | { | ||
| 104 | MainWindow *mainwin; | ||
| 105 | GtkWidget *dialog; | ||
| 106 | GtkWidget *hbox; | ||
| 107 | GtkWidget *image; | ||
| 108 | GtkWidget *vbox; | ||
| 109 | GtkWidget *label; | ||
| 110 | GtkWidget *radio; | ||
| 111 | GtkWidget *entry; | ||
| 112 | GtkWidget *sel_btn; | ||
| 113 | GtkWidget *ok_btn; | ||
| 114 | gchar *path = NULL; | ||
| 115 | gchar *fullpath; | ||
| 116 | Folder *folder; | ||
| 117 | gint result; | ||
| 118 | |||
| 119 | mainwin = main_window_get(); | ||
| 120 | manage_window_focus_in(mainwin->window, NULL, NULL); | ||
| 121 | |||
| 122 | dialog = gtk_dialog_new(); | ||
| 123 | gtk_window_set_title(GTK_WINDOW(dialog), _("Mailbox setting")); | ||
| 124 | gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, TRUE, FALSE); | ||
| 125 | gtk_widget_set_size_request(dialog, 540 * gtkut_get_dpi_multiplier(), -1); | ||
| 126 | gtk_window_set_position(GTK_WINDOW(dialog), | ||
| 127 | GTK_WIN_POS_CENTER_ON_PARENT); | ||
| 128 | gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); | ||
| 129 | manage_window_set_transient(GTK_WINDOW(dialog)); | ||
| 130 | gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | ||
| 131 | MANAGE_WINDOW_SIGNALS_CONNECT(dialog); | ||
| 132 | gtk_widget_realize(dialog); | ||
| 133 | |||
| 134 | hbox = gtk_hbox_new(FALSE, 12); | ||
| 135 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 12); | ||
| 136 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), | ||
| 137 | hbox, FALSE, FALSE, 0); | ||
| 138 | |||
| 139 | image = stock_pixbuf_widget(dialog, STOCK_PIXMAP_SYLPHEED); | ||
| 140 | |||
| 141 | gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0); | ||
| 142 | gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); | ||
| 143 | |||
| 144 | vbox = gtk_vbox_new(FALSE, 12); | ||
| 145 | gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); | ||
| 146 | |||
| 147 | label = gtk_label_new(_("Mailbox setting")); | ||
| 148 | gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); | ||
| 149 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | ||
| 150 | gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | ||
| 151 | |||
| 152 | if (!font_desc) { | ||
| 153 | gint size; | ||
| 154 | |||
| 155 | size = pango_font_description_get_size | ||
| 156 | (label->style->font_desc); | ||
| 157 | font_desc = pango_font_description_new(); | ||
| 158 | pango_font_description_set_weight | ||
| 159 | (font_desc, PANGO_WEIGHT_BOLD); | ||
| 160 | pango_font_description_set_size | ||
| 161 | (font_desc, size * PANGO_SCALE_LARGE); | ||
| 162 | } | ||
| 163 | if (font_desc) | ||
| 164 | gtk_widget_modify_font(label, font_desc); | ||
| 165 | |||
| 166 | label = gtk_label_new(_("This dialog will make initial setup of mailbox.")); | ||
| 167 | gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); | ||
| 168 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | ||
| 169 | gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | ||
| 170 | gtk_label_set_selectable(GTK_LABEL(label), TRUE); | ||
| 171 | GTK_WIDGET_UNSET_FLAGS(label, GTK_CAN_FOCUS); | ||
| 172 | MODIFY_LABEL_STYLE(); | ||
| 173 | |||
| 174 | vbox = gtk_vbox_new(FALSE, 8); | ||
| 175 | gtk_container_set_border_width(GTK_CONTAINER(vbox), 12); | ||
| 176 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, | ||
| 177 | TRUE, TRUE, 0); | ||
| 178 | |||
| 179 | radio = gtk_radio_button_new_with_label | ||
| 180 | (NULL, _("Create mailbox at the following default location:")); | ||
| 181 | gtk_box_pack_start(GTK_BOX(vbox), radio, FALSE, FALSE, 0); | ||
| 182 | |||
| 183 | fullpath = g_strdup_printf("%s%cMail", get_mail_base_dir(), | ||
| 184 | G_DIR_SEPARATOR); | ||
| 185 | |||
| 186 | label = gtk_label_new(fullpath); | ||
| 187 | gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | ||
| 188 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | ||
| 189 | gtk_label_set_line_wrap(GTK_LABEL(label), FALSE); | ||
| 190 | #if GTK_CHECK_VERSION(2, 6, 0) | ||
| 191 | gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_MIDDLE); | ||
| 192 | #endif | ||
| 193 | gtk_label_set_selectable(GTK_LABEL(label), TRUE); | ||
| 194 | GTK_WIDGET_UNSET_FLAGS(label, GTK_CAN_FOCUS); | ||
| 195 | MODIFY_LABEL_STYLE(); | ||
| 196 | |||
| 197 | g_free(fullpath); | ||
| 198 | |||
| 199 | radio = gtk_radio_button_new_with_label_from_widget | ||
| 200 | (GTK_RADIO_BUTTON(radio), _("Create mailbox at the following location:\n(enter folder name or full folder path)")); | ||
| 201 | gtk_box_pack_start(GTK_BOX(vbox), radio, FALSE, FALSE, 0); | ||
| 202 | |||
| 203 | hbox = gtk_hbox_new(FALSE, 4); | ||
| 204 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | ||
| 205 | |||
| 206 | entry = gtk_entry_new(); | ||
| 207 | gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); | ||
| 208 | |||
| 209 | sel_btn = gtk_button_new_with_label("..."); | ||
| 210 | gtk_box_pack_start(GTK_BOX(hbox), sel_btn, FALSE, FALSE, 0); | ||
| 211 | g_signal_connect(G_OBJECT(sel_btn), "clicked", | ||
| 212 | G_CALLBACK(sel_btn_clicked), entry); | ||
| 213 | |||
| 214 | gtk_widget_set_sensitive(hbox, FALSE); | ||
| 215 | g_signal_connect(G_OBJECT(radio), "toggled", G_CALLBACK(button_toggled), | ||
| 216 | hbox); | ||
| 217 | |||
| 218 | label = gtk_label_new(_("If you want to add a mailbox at another location afterward, please select 'File - Mailbox - Add mailbox...' in the menu.")); | ||
| 219 | gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | ||
| 220 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | ||
| 221 | gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | ||
| 222 | gtk_label_set_selectable(GTK_LABEL(label), TRUE); | ||
| 223 | GTK_WIDGET_UNSET_FLAGS(label, GTK_CAN_FOCUS); | ||
| 224 | MODIFY_LABEL_STYLE(); | ||
| 225 | |||
| 226 | if (prefs_common.comply_gnome_hig) { | ||
| 227 | gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); | ||
| 228 | ok_btn = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, GTK_RESPONSE_OK); | ||
| 229 | } else { | ||
| 230 | ok_btn = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, GTK_RESPONSE_OK); | ||
| 231 | gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); | ||
| 232 | } | ||
| 233 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); | ||
| 234 | gtk_widget_grab_focus(ok_btn); | ||
| 235 | |||
| 236 | gtk_widget_show_all(dialog); | ||
| 237 | |||
| 238 | do { | ||
| 239 | result = gtk_dialog_run(GTK_DIALOG(dialog)); | ||
| 240 | if (result != GTK_RESPONSE_OK) { | ||
| 241 | if (alertpanel(_("Cancel"), _("Continue without creating mailbox?"), GTK_STOCK_YES, GTK_STOCK_NO, NULL) == G_ALERTDEFAULT) | ||
| 242 | break; | ||
| 243 | else | ||
| 244 | continue; | ||
| 245 | } | ||
| 246 | |||
| 247 | if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio))) { | ||
| 248 | path = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); | ||
| 249 | g_strstrip(path); | ||
| 250 | if (*path == '\0') { | ||
| 251 | alertpanel_error(_("Please input folder name or full folder path.")); | ||
| 252 | g_free(path); | ||
| 253 | path = NULL; | ||
| 254 | } | ||
| 255 | } else | ||
| 256 | path = g_strdup("Mail"); | ||
| 257 | |||
| 258 | if (path) { | ||
| 259 | if (folder_find_from_path(path)) { | ||
| 260 | alertpanel_error(_("The mailbox '%s' already exists."), path); | ||
| 261 | g_warning("The mailbox '%s' already exists.", path); | ||
| 262 | g_free(path); | ||
| 263 | path = NULL; | ||
| 264 | } else if (is_path_parent(path, get_rc_dir()) || | ||
| 265 | is_path_parent(path, get_mail_base_dir())) { | ||
| 266 | alertpanel_error(_("The location '%s' includes settings folder. Please specify another location."), path); | ||
| 267 | g_warning("The location '%s' includes settings folder.", path); | ||
| 268 | g_free(path); | ||
| 269 | path = NULL; | ||
| 270 | } | ||
| 271 | } | ||
| 272 | } while (path == NULL); | ||
| 273 | |||
| 274 | gtk_widget_destroy(dialog); | ||
| 275 | if (path == NULL) | ||
| 276 | return; | ||
| 277 | |||
| 278 | if (!strcmp(g_basename(path), "Mail")) | ||
| 279 | folder = folder_new(F_MH, _("Mailbox"), path); | ||
| 280 | else | ||
| 281 | folder = folder_new(F_MH, g_basename(path), path); | ||
| 282 | g_free(path); | ||
| 283 | |||
| 284 | if (folder->klass->create_tree(folder) < 0) { | ||
| 285 | alertpanel_error(_("Creation of the mailbox failed.\n" | ||
| 286 | "Maybe some files already exist, or you don't have the permission to write there.")); | ||
| 287 | folder_destroy(folder); | ||
| 288 | return; | ||
| 289 | } | ||
| 290 | |||
| 291 | folder_add(folder); | ||
| 292 | folder_set_ui_func(folder, scan_tree_func, mainwin); | ||
| 293 | folder->klass->scan_tree(folder); | ||
| 294 | folder_set_ui_func(folder, NULL, NULL); | ||
| 295 | |||
| 296 | folderview_set(mainwin->folderview); | ||
| 297 | } | ||
| 298 | |||
| 299 | static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data) | ||
| 300 | { | ||
| 301 | MainWindow *mainwin = (MainWindow *)data; | ||
| 302 | gchar *str; | ||
| 303 | |||
| 304 | if (item->path) | ||
| 305 | str = g_strdup_printf(_("Scanning folder %s%c%s ..."), | ||
| 306 | LOCAL_FOLDER(folder)->rootpath, | ||
| 307 | G_DIR_SEPARATOR, | ||
| 308 | item->path); | ||
| 309 | else | ||
| 310 | str = g_strdup_printf(_("Scanning folder %s ..."), | ||
| 311 | LOCAL_FOLDER(folder)->rootpath); | ||
| 312 | |||
| 313 | gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar), | ||
| 314 | mainwin->mainwin_cid, str); | ||
| 315 | gtkut_widget_draw_now(mainwin->statusbar); | ||
| 316 | gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar), | ||
| 317 | mainwin->mainwin_cid); | ||
| 318 | g_free(str); | ||
| 319 | } | ||
| 320 | |||
| 321 | static struct | ||
| 322 | { | ||
| 323 | GtkWidget *dialog; | ||
| 324 | GtkWidget *notebook; | ||
| 325 | GtkWidget *prev_btn; | ||
| 326 | GtkWidget *next_btn; | ||
| 327 | GtkWidget *cancel_btn; | ||
| 328 | GtkWidget *pop3_radio; | ||
| 329 | GtkWidget *imap_radio; | ||
| 330 | #if USE_SSL | ||
| 331 | GtkWidget *pop3g_radio; | ||
| 332 | GtkWidget *imapg_radio; | ||
| 333 | #endif | ||
| 334 | GtkWidget *name_entry; | ||
| 335 | GtkWidget *addr_entry; | ||
| 336 | GtkWidget *id_entry; | ||
| 337 | GtkWidget *serv_entry; | ||
| 338 | GtkWidget *smtp_entry; | ||
| 339 | GtkWidget *smtpauth_chkbtn; | ||
| 340 | #if USE_SSL | ||
| 341 | GtkWidget *servssl_chkbtn; | ||
| 342 | GtkWidget *smtpssl_chkbtn; | ||
| 343 | #endif | ||
| 344 | GtkWidget *serv_label_name1; | ||
| 345 | GtkWidget *serv_label_name2; | ||
| 346 | GtkWidget *name_label; | ||
| 347 | GtkWidget *addr_label; | ||
| 348 | GtkWidget *id_label; | ||
| 349 | GtkWidget *serv_label; | ||
| 350 | GtkWidget *smtp_label; | ||
| 351 | gboolean finished; | ||
| 352 | gboolean cancelled; | ||
| 353 | |||
| 354 | gint type; | ||
| 355 | gchar *name; | ||
| 356 | gchar *addr; | ||
| 357 | gchar *userid; | ||
| 358 | gchar *serv; | ||
| 359 | gchar *smtpserv; | ||
| 360 | gushort serv_port; | ||
| 361 | gushort smtp_port; | ||
| 362 | #if USE_SSL | ||
| 363 | gboolean serv_ssl; | ||
| 364 | gboolean smtp_ssl; | ||
| 365 | #endif | ||
| 366 | gboolean smtp_auth; | ||
| 367 | } setupac; | ||
| 368 | |||
| 369 | enum | ||
| 370 | { | ||
| 371 | SETUP_PAGE_START, | ||
| 372 | SETUP_PAGE_ADDRESS, | ||
| 373 | SETUP_PAGE_ACCOUNT, | ||
| 374 | SETUP_PAGE_FINISH | ||
| 375 | }; | ||
| 376 | |||
| 377 | enum | ||
| 378 | { | ||
| 379 | SETUP_TYPE_POP3, | ||
| 380 | SETUP_TYPE_IMAP, | ||
| 381 | #if USE_SSL | ||
| 382 | SETUP_TYPE_POP3G, | ||
| 383 | SETUP_TYPE_IMAPG | ||
| 384 | #endif | ||
| 385 | }; | ||
| 386 | |||
| 387 | #define GMAIL_POP3_SERVER "pop.gmail.com" | ||
| 388 | #define GMAIL_IMAP_SERVER "imap.gmail.com" | ||
| 389 | #define GMAIL_SMTP_SERVER "smtp.gmail.com" | ||
| 390 | #define POP3_PORT 110 | ||
| 391 | #define IMAP_PORT 143 | ||
| 392 | #define SMTP_PORT 25 | ||
| 393 | #define POP3S_PORT 995 | ||
| 394 | #define IMAPS_PORT 993 | ||
| 395 | #define SMTPS_PORT 465 | ||
| 396 | |||
| 397 | static void entry_changed(GtkEditable *editable, gpointer data) | ||
| 398 | { | ||
| 399 | const gchar *name, *addr, *userid, *serv, *smtp; | ||
| 400 | gint page; | ||
| 401 | gboolean next_enable = FALSE; | ||
| 402 | |||
| 403 | page = gtk_notebook_get_current_page(GTK_NOTEBOOK(setupac.notebook)); | ||
| 404 | if (page != SETUP_PAGE_ADDRESS && page != SETUP_PAGE_ACCOUNT) | ||
| 405 | return; | ||
| 406 | |||
| 407 | name = gtk_entry_get_text(GTK_ENTRY(setupac.name_entry)); | ||
| 408 | addr = gtk_entry_get_text(GTK_ENTRY(setupac.addr_entry)); | ||
| 409 | userid = gtk_entry_get_text(GTK_ENTRY(setupac.id_entry)); | ||
| 410 | serv = gtk_entry_get_text(GTK_ENTRY(setupac.serv_entry)); | ||
| 411 | smtp = gtk_entry_get_text(GTK_ENTRY(setupac.smtp_entry)); | ||
| 412 | |||
| 413 | #if USE_SSL | ||
| 414 | if (setupac.type == SETUP_TYPE_POP3G || | ||
| 415 | setupac.type == SETUP_TYPE_IMAPG) { | ||
| 416 | if (GTK_WIDGET(editable) == setupac.addr_entry) | ||
| 417 | gtk_entry_set_text(GTK_ENTRY(setupac.id_entry), addr); | ||
| 418 | } | ||
| 419 | #endif | ||
| 420 | |||
| 421 | if (page == SETUP_PAGE_ADDRESS && name && *name && addr && *addr) | ||
| 422 | next_enable = TRUE; | ||
| 423 | else if (page == SETUP_PAGE_ACCOUNT && | ||
| 424 | userid && *userid && serv && *serv && smtp && *smtp) | ||
| 425 | next_enable = TRUE; | ||
| 426 | |||
| 427 | gtk_dialog_set_response_sensitive(GTK_DIALOG(setupac.dialog), | ||
| 428 | GTK_RESPONSE_ACCEPT, next_enable); | ||
| 429 | } | ||
| 430 | |||
| 431 | static gboolean entry_is_valid(GtkWidget *entry) | ||
| 432 | { | ||
| 433 | const gchar *str, *p; | ||
| 434 | guchar c; | ||
| 435 | |||
| 436 | p = str = gtk_entry_get_text(GTK_ENTRY(entry)); | ||
| 437 | if (!str || *p == '\0') | ||
| 438 | return FALSE; | ||
| 439 | if (!strcmp(str, "(username)@gmail.com")) | ||
| 440 | return FALSE; | ||
| 441 | |||
| 442 | while (*p) { | ||
| 443 | c = *p; | ||
| 444 | if (g_ascii_isspace(c) || c < 32 || c > 127) | ||
| 445 | return FALSE; | ||
| 446 | p++; | ||
| 447 | } | ||
| 448 | |||
| 449 | return TRUE; | ||
| 450 | } | ||
| 451 | |||
| 452 | #define GET_STR(s, m) \ | ||
| 453 | { \ | ||
| 454 | setupac.s = gtk_editable_get_chars(GTK_EDITABLE(setupac.m), 0, -1); \ | ||
| 455 | g_strstrip(setupac.s); \ | ||
| 456 | } | ||
| 457 | |||
| 458 | static void setup_account_response_cb(GtkDialog *dialog, gint response_id, | ||
| 459 | gpointer data) | ||
| 460 | { | ||
| 461 | gint page, prev_page; | ||
| 462 | gboolean next_enable = TRUE; | ||
| 463 | gboolean prev_enable = TRUE; | ||
| 464 | gchar buf[1024]; | ||
| 465 | |||
| 466 | prev_page = page = | ||
| 467 | gtk_notebook_get_current_page(GTK_NOTEBOOK(setupac.notebook)); | ||
| 468 | |||
| 469 | if (response_id == GTK_RESPONSE_CANCEL || | ||
| 470 | response_id == GTK_RESPONSE_DELETE_EVENT) { | ||
| 471 | if (page == SETUP_PAGE_FINISH) { | ||
| 472 | setupac.finished = TRUE; | ||
| 473 | } else { | ||
| 474 | if (alertpanel(_("Cancel"), _("Cancel mail account setup?"), GTK_STOCK_YES, GTK_STOCK_NO, NULL) == G_ALERTDEFAULT) { | ||
| 475 | setupac.finished = TRUE; | ||
| 476 | setupac.cancelled = TRUE; | ||
| 477 | } | ||
| 478 | return; | ||
| 479 | } | ||
| 480 | } else if (response_id == GTK_RESPONSE_ACCEPT) { | ||
| 481 | if (prev_page == SETUP_PAGE_ADDRESS) { | ||
| 482 | if (entry_is_valid(setupac.addr_entry)) { | ||
| 483 | #if USE_SSL | ||
| 484 | if (setupac.type == SETUP_TYPE_POP3G || | ||
| 485 | setupac.type == SETUP_TYPE_IMAPG) | ||
| 486 | gtk_notebook_set_current_page | ||
| 487 | (GTK_NOTEBOOK(setupac.notebook), | ||
| 488 | SETUP_PAGE_FINISH); | ||
| 489 | else | ||
| 490 | #endif | ||
| 491 | gtk_notebook_set_current_page | ||
| 492 | (GTK_NOTEBOOK(setupac.notebook), page + 1); | ||
| 493 | } else | ||
| 494 | alertpanel_error(_("Input value is not valid.")); | ||
| 495 | } else if (prev_page == SETUP_PAGE_ACCOUNT) { | ||
| 496 | if (entry_is_valid(setupac.id_entry) && | ||
| 497 | entry_is_valid(setupac.serv_entry) && | ||
| 498 | entry_is_valid(setupac.smtp_entry)) | ||
| 499 | gtk_notebook_set_current_page | ||
| 500 | (GTK_NOTEBOOK(setupac.notebook), page + 1); | ||
| 501 | else | ||
| 502 | alertpanel_error(_("Input value is not valid.")); | ||
| 503 | } else { | ||
| 504 | gtk_notebook_set_current_page | ||
| 505 | (GTK_NOTEBOOK(setupac.notebook), page + 1); | ||
| 506 | } | ||
| 507 | |||
| 508 | if (prev_page == SETUP_PAGE_START) { | ||
| 509 | setupac.type = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setupac.pop3_radio)) ? SETUP_TYPE_POP3 | ||
| 510 | : gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setupac.imap_radio)) ? SETUP_TYPE_IMAP | ||
| 511 | #if USE_SSL | ||
| 512 | : gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setupac.pop3g_radio)) ? SETUP_TYPE_POP3G | ||
| 513 | : gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setupac.imapg_radio)) ? SETUP_TYPE_IMAPG | ||
| 514 | #endif | ||
| 515 | : SETUP_TYPE_POP3; | ||
| 516 | } | ||
| 517 | } else if (response_id == GTK_RESPONSE_REJECT) { | ||
| 518 | gtk_notebook_set_current_page(GTK_NOTEBOOK(setupac.notebook), | ||
| 519 | page - 1); | ||
| 520 | } else { | ||
| 521 | g_warning("setup_account_response_cb: invalid response_id: %d\n", response_id); | ||
| 522 | } | ||
| 523 | |||
| 524 | page = gtk_notebook_get_current_page(GTK_NOTEBOOK(setupac.notebook)); | ||
| 525 | |||
| 526 | if (page == SETUP_PAGE_START) | ||
| 527 | prev_enable = FALSE; | ||
| 528 | else if (page == SETUP_PAGE_ADDRESS || page == SETUP_PAGE_ACCOUNT) { | ||
| 529 | switch (setupac.type) { | ||
| 530 | case SETUP_TYPE_POP3: | ||
| 531 | gtk_widget_set_sensitive(setupac.id_entry, TRUE); | ||
| 532 | gtk_label_set_text(GTK_LABEL(setupac.serv_label_name1), _("POP3 server:")); | ||
| 533 | gtk_widget_set_sensitive(setupac.serv_entry, TRUE); | ||
| 534 | gtk_widget_set_sensitive(setupac.smtp_entry, TRUE); | ||
| 535 | break; | ||
| 536 | case SETUP_TYPE_IMAP: | ||
| 537 | gtk_widget_set_sensitive(setupac.id_entry, TRUE); | ||
| 538 | gtk_label_set_text(GTK_LABEL(setupac.serv_label_name1), _("IMAP4 server:")); | ||
| 539 | gtk_widget_set_sensitive(setupac.serv_entry, TRUE); | ||
| 540 | gtk_widget_set_sensitive(setupac.smtp_entry, TRUE); | ||
| 541 | break; | ||
| 542 | #if USE_SSL | ||
| 543 | case SETUP_TYPE_POP3G: | ||
| 544 | if (prev_page == SETUP_PAGE_START) | ||
| 545 | gtk_entry_set_text(GTK_ENTRY(setupac.addr_entry), "(username)@gmail.com"); | ||
| 546 | gtk_widget_set_sensitive(setupac.id_entry, FALSE); | ||
| 547 | gtk_label_set_text(GTK_LABEL(setupac.serv_label_name1), _("POP3 server:")); | ||
| 548 | gtk_entry_set_text(GTK_ENTRY(setupac.serv_entry), GMAIL_POP3_SERVER); | ||
| 549 | gtk_widget_set_sensitive(setupac.serv_entry, FALSE); | ||
| 550 | gtk_entry_set_text(GTK_ENTRY(setupac.smtp_entry), GMAIL_SMTP_SERVER); | ||
| 551 | gtk_widget_set_sensitive(setupac.smtp_entry, FALSE); | ||
| 552 | break; | ||
| 553 | case SETUP_TYPE_IMAPG: | ||
| 554 | if (prev_page == SETUP_PAGE_START) | ||
| 555 | gtk_entry_set_text(GTK_ENTRY(setupac.addr_entry), "(username)@gmail.com"); | ||
| 556 | gtk_widget_set_sensitive(setupac.id_entry, FALSE); | ||
| 557 | gtk_label_set_text(GTK_LABEL(setupac.serv_label_name1), _("IMAP4 server:")); | ||
| 558 | gtk_entry_set_text(GTK_ENTRY(setupac.serv_entry), GMAIL_IMAP_SERVER); | ||
| 559 | gtk_widget_set_sensitive(setupac.serv_entry, FALSE); | ||
| 560 | gtk_entry_set_text(GTK_ENTRY(setupac.smtp_entry), GMAIL_SMTP_SERVER); | ||
| 561 | gtk_widget_set_sensitive(setupac.smtp_entry, FALSE); | ||
| 562 | break; | ||
| 563 | #endif /* USE_SSL */ | ||
| 564 | } | ||
| 565 | } else if (page == SETUP_PAGE_FINISH) { | ||
| 566 | prev_enable = FALSE; | ||
| 567 | next_enable = FALSE; | ||
| 568 | gtk_button_set_label(GTK_BUTTON(setupac.cancel_btn), | ||
| 569 | GTK_STOCK_CLOSE); | ||
| 570 | |||
| 571 | switch (setupac.type) { | ||
| 572 | case SETUP_TYPE_POP3: | ||
| 573 | #if USE_SSL | ||
| 574 | setupac.serv_ssl = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setupac.servssl_chkbtn)); | ||
| 575 | setupac.smtp_ssl = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setupac.smtpssl_chkbtn)); | ||
| 576 | setupac.serv_port = setupac.serv_ssl ? POP3S_PORT : POP3_PORT; | ||
| 577 | setupac.smtp_port = setupac.smtp_ssl ? SMTPS_PORT : SMTP_PORT; | ||
| 578 | #else /* !USE_SSL */ | ||
| 579 | setupac.serv_port = POP3_PORT; | ||
| 580 | setupac.smtp_port = SMTP_PORT; | ||
| 581 | #endif /* USE_SSL */ | ||
| 582 | setupac.smtp_auth = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setupac.smtpauth_chkbtn)); | ||
| 583 | gtk_label_set_text(GTK_LABEL(setupac.serv_label_name2), _("POP3 server:")); | ||
| 584 | break; | ||
| 585 | case SETUP_TYPE_IMAP: | ||
| 586 | #if USE_SSL | ||
| 587 | setupac.serv_ssl = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setupac.servssl_chkbtn)); | ||
| 588 | setupac.smtp_ssl = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setupac.smtpssl_chkbtn)); | ||
| 589 | setupac.serv_port = setupac.serv_ssl ? IMAPS_PORT : IMAP_PORT; | ||
| 590 | setupac.smtp_port = setupac.smtp_ssl ? SMTPS_PORT : SMTP_PORT; | ||
| 591 | #else /* !USE_SSL */ | ||
| 592 | setupac.serv_port = IMAP_PORT; | ||
| 593 | setupac.smtp_port = SMTP_PORT; | ||
| 594 | #endif /* USE_SSL */ | ||
| 595 | setupac.smtp_auth = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(setupac.smtpauth_chkbtn)); | ||
| 596 | gtk_label_set_text(GTK_LABEL(setupac.serv_label_name2), _("IMAP4 server:")); | ||
| 597 | break; | ||
| 598 | #if USE_SSL | ||
| 599 | case SETUP_TYPE_POP3G: | ||
| 600 | setupac.serv_ssl = TRUE; | ||
| 601 | setupac.smtp_ssl = TRUE; | ||
| 602 | setupac.smtp_auth = TRUE; | ||
| 603 | setupac.serv_port = POP3S_PORT; | ||
| 604 | setupac.smtp_port = SMTPS_PORT; | ||
| 605 | gtk_label_set_text(GTK_LABEL(setupac.serv_label_name2), _("POP3 server:")); | ||
| 606 | break; | ||
| 607 | case SETUP_TYPE_IMAPG: | ||
| 608 | setupac.serv_ssl = TRUE; | ||
| 609 | setupac.smtp_ssl = TRUE; | ||
| 610 | setupac.smtp_auth = TRUE; | ||
| 611 | setupac.serv_port = IMAPS_PORT; | ||
| 612 | setupac.smtp_port = SMTPS_PORT; | ||
| 613 | gtk_label_set_text(GTK_LABEL(setupac.serv_label_name2), _("IMAP4 server:")); | ||
| 614 | break; | ||
| 615 | #endif /* USE_SSL */ | ||
| 616 | } | ||
| 617 | |||
| 618 | GET_STR(name, name_entry); | ||
| 619 | GET_STR(addr, addr_entry); | ||
| 620 | GET_STR(userid, id_entry); | ||
| 621 | GET_STR(serv, serv_entry); | ||
| 622 | GET_STR(smtpserv, smtp_entry); | ||
| 623 | gtk_label_set_text(GTK_LABEL(setupac.name_label), setupac.name); | ||
| 624 | gtk_label_set_text(GTK_LABEL(setupac.addr_label), setupac.addr); | ||
| 625 | gtk_label_set_text(GTK_LABEL(setupac.id_label), setupac.userid); | ||
| 626 | #if USE_SSL | ||
| 627 | if (setupac.serv_ssl) | ||
| 628 | g_snprintf(buf, sizeof(buf), "%s:%u (SSL)", | ||
| 629 | setupac.serv, setupac.serv_port); | ||
| 630 | else | ||
| 631 | #endif | ||
| 632 | g_snprintf(buf, sizeof(buf), "%s:%u", | ||
| 633 | setupac.serv, setupac.serv_port); | ||
| 634 | gtk_label_set_text(GTK_LABEL(setupac.serv_label), buf); | ||
| 635 | #if USE_SSL | ||
| 636 | if (setupac.smtp_ssl) | ||
| 637 | g_snprintf(buf, sizeof(buf), "%s:%u (SSL)", | ||
| 638 | setupac.smtpserv, setupac.smtp_port); | ||
| 639 | else | ||
| 640 | #endif | ||
| 641 | g_snprintf(buf, sizeof(buf), "%s:%u", | ||
| 642 | setupac.smtpserv, setupac.smtp_port); | ||
| 643 | gtk_label_set_text(GTK_LABEL(setupac.smtp_label), buf); | ||
| 644 | } | ||
| 645 | |||
| 646 | gtk_dialog_set_response_sensitive(GTK_DIALOG(setupac.dialog), | ||
| 647 | GTK_RESPONSE_REJECT, prev_enable); | ||
| 648 | gtk_dialog_set_response_sensitive(GTK_DIALOG(setupac.dialog), | ||
| 649 | GTK_RESPONSE_ACCEPT, next_enable); | ||
| 650 | |||
| 651 | if (page == SETUP_PAGE_ADDRESS || page == SETUP_PAGE_ACCOUNT) | ||
| 652 | entry_changed(GTK_EDITABLE(setupac.addr_entry), NULL); | ||
| 653 | } | ||
| 654 | |||
| 655 | PrefsAccount *setup_account(void) | ||
| 656 | { | ||
| 657 | MainWindow *mainwin; | ||
| 658 | GtkWidget *dialog; | ||
| 659 | GtkWidget *hbox; | ||
| 660 | GtkWidget *image; | ||
| 661 | GtkWidget *vbox; | ||
| 662 | GtkWidget *vbox2; | ||
| 663 | GtkWidget *label; | ||
| 664 | GtkWidget *table; | ||
| 665 | GtkWidget *chkbtn; | ||
| 666 | gint result; | ||
| 667 | PrefsAccount *ac; | ||
| 668 | |||
| 669 | mainwin = main_window_get(); | ||
| 670 | manage_window_focus_in(mainwin->window, NULL, NULL); | ||
| 671 | |||
| 672 | dialog = gtk_dialog_new_with_buttons(_("New account setup"), NULL, GTK_DIALOG_MODAL, NULL); | ||
| 673 | setupac.dialog = dialog; | ||
| 674 | |||
| 675 | setupac.prev_btn = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_GO_BACK, GTK_RESPONSE_REJECT); | ||
| 676 | setupac.next_btn = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_GO_FORWARD, GTK_RESPONSE_ACCEPT); | ||
| 677 | setupac.cancel_btn = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); | ||
| 678 | |||
| 679 | gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, TRUE, FALSE); | ||
| 680 | gtk_widget_set_size_request(dialog, 540 * gtkut_get_dpi_multiplier(), -1); | ||
| 681 | gtk_window_set_position(GTK_WINDOW(dialog), | ||
| 682 | GTK_WIN_POS_CENTER_ON_PARENT); | ||
| 683 | //gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); | ||
| 684 | manage_window_set_transient(GTK_WINDOW(dialog)); | ||
| 685 | gtk_dialog_set_has_separator(GTK_DIALOG(dialog), TRUE); | ||
| 686 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); | ||
| 687 | gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), | ||
| 688 | GTK_RESPONSE_REJECT, FALSE); | ||
| 689 | MANAGE_WINDOW_SIGNALS_CONNECT(dialog); | ||
| 690 | gtk_widget_realize(dialog); | ||
| 691 | |||
| 692 | g_signal_connect(dialog, "response", | ||
| 693 | G_CALLBACK(setup_account_response_cb), NULL); | ||
| 694 | |||
| 695 | hbox = gtk_hbox_new(FALSE, 12); | ||
| 696 | gtk_container_set_border_width(GTK_CONTAINER(hbox), 12); | ||
| 697 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), | ||
| 698 | hbox, FALSE, FALSE, 0); | ||
| 699 | |||
| 700 | image = stock_pixbuf_widget(dialog, STOCK_PIXMAP_SYLPHEED); | ||
| 701 | |||
| 702 | gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0); | ||
| 703 | gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); | ||
| 704 | |||
| 705 | vbox = gtk_vbox_new(FALSE, 12); | ||
| 706 | gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); | ||
| 707 | |||
| 708 | label = gtk_label_new(_("New account setup")); | ||
| 709 | gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); | ||
| 710 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | ||
| 711 | gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | ||
| 712 | |||
| 713 | if (!font_desc) { | ||
| 714 | gint size; | ||
| 715 | |||
| 716 | size = pango_font_description_get_size | ||
| 717 | (label->style->font_desc); | ||
| 718 | font_desc = pango_font_description_new(); | ||
| 719 | pango_font_description_set_weight | ||
| 720 | (font_desc, PANGO_WEIGHT_BOLD); | ||
| 721 | pango_font_description_set_size | ||
| 722 | (font_desc, size * PANGO_SCALE_LARGE); | ||
| 723 | } | ||
| 724 | if (font_desc) | ||
| 725 | gtk_widget_modify_font(label, font_desc); | ||
| 726 | |||
| 727 | label = gtk_label_new(_("This dialog will make initial setup of new mail account.")); | ||
| 728 | gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); | ||
| 729 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | ||
| 730 | gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | ||
| 731 | gtk_label_set_selectable(GTK_LABEL(label), TRUE); | ||
| 732 | GTK_WIDGET_UNSET_FLAGS(label, GTK_CAN_FOCUS); | ||
| 733 | MODIFY_LABEL_STYLE(); | ||
| 734 | |||
| 735 | vbox = gtk_vbox_new(FALSE, 8); | ||
| 736 | gtk_container_set_border_width(GTK_CONTAINER(vbox), 8); | ||
| 737 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, | ||
| 738 | TRUE, TRUE, 0); | ||
| 739 | |||
| 740 | setupac.notebook = gtk_notebook_new(); | ||
| 741 | gtk_notebook_set_show_border(GTK_NOTEBOOK(setupac.notebook), FALSE); | ||
| 742 | gtk_notebook_set_show_tabs(GTK_NOTEBOOK(setupac.notebook), FALSE); | ||
| 743 | gtk_box_pack_start(GTK_BOX(vbox), setupac.notebook, TRUE, TRUE, 0); | ||
| 744 | |||
| 745 | /* Page 1 */ | ||
| 746 | vbox = gtk_vbox_new(FALSE, 12); | ||
| 747 | gtk_notebook_append_page(GTK_NOTEBOOK(setupac.notebook), vbox, NULL); | ||
| 748 | gtk_container_set_border_width(GTK_CONTAINER(vbox), 12); | ||
| 749 | |||
| 750 | label = gtk_label_new(_("Select account type:")); | ||
| 751 | gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 8); | ||
| 752 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | ||
| 753 | |||
| 754 | setupac.pop3_radio = gtk_radio_button_new_with_label(NULL, "POP3"); | ||
| 755 | gtk_box_pack_start(GTK_BOX(vbox), setupac.pop3_radio, FALSE, FALSE, 0); | ||
| 756 | setupac.imap_radio = gtk_radio_button_new_with_label_from_widget | ||
| 757 | (GTK_RADIO_BUTTON(setupac.pop3_radio), "IMAP4"); | ||
| 758 | gtk_box_pack_start(GTK_BOX(vbox), setupac.imap_radio, FALSE, FALSE, 0); | ||
| 759 | #if USE_SSL | ||
| 760 | setupac.pop3g_radio = gtk_radio_button_new_with_label_from_widget | ||
| 761 | (GTK_RADIO_BUTTON(setupac.pop3_radio), "POP3 (Gmail)"); | ||
| 762 | gtk_box_pack_start(GTK_BOX(vbox), setupac.pop3g_radio, FALSE, FALSE, 0); | ||
| 763 | setupac.imapg_radio = gtk_radio_button_new_with_label_from_widget | ||
| 764 | (GTK_RADIO_BUTTON(setupac.pop3_radio), "IMAP4 (Gmail)"); | ||
| 765 | gtk_box_pack_start(GTK_BOX(vbox), setupac.imapg_radio, FALSE, FALSE, 0); | ||
| 766 | #endif | ||
| 767 | |||
| 768 | /* Page 2 */ | ||
| 769 | vbox = gtk_vbox_new(FALSE, 12); | ||
| 770 | gtk_notebook_append_page(GTK_NOTEBOOK(setupac.notebook), vbox, NULL); | ||
| 771 | gtk_container_set_border_width(GTK_CONTAINER(vbox), 12); | ||
| 772 | |||
| 773 | label = gtk_label_new(_("Input your name and mail address:")); | ||
| 774 | gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 8); | ||
| 775 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | ||
| 776 | |||
| 777 | table = gtk_table_new(4, 2, FALSE); | ||
| 778 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | ||
| 779 | gtk_table_set_row_spacings(GTK_TABLE(table), 8); | ||
| 780 | gtk_table_set_col_spacings(GTK_TABLE(table), 8); | ||
| 781 | |||
| 782 | label = gtk_label_new(_("Display name:")); | ||
| 783 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, | ||
| 784 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 785 | gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | ||
| 786 | label = gtk_label_new(_("E-mail address:")); | ||
| 787 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, | ||
| 788 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 789 | gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | ||
| 790 | |||
| 791 | setupac.name_entry = gtk_entry_new(); | ||
| 792 | gtk_table_attach(GTK_TABLE(table), setupac.name_entry, 1, 2, 0, 1, | ||
| 793 | GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0); | ||
| 794 | g_signal_connect(setupac.name_entry, "changed", | ||
| 795 | G_CALLBACK(entry_changed), NULL); | ||
| 796 | setupac.addr_entry = gtk_entry_new(); | ||
| 797 | gtk_table_attach(GTK_TABLE(table), setupac.addr_entry, 1, 2, 3, 4, | ||
| 798 | GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0); | ||
| 799 | g_signal_connect(setupac.addr_entry, "changed", | ||
| 800 | G_CALLBACK(entry_changed), NULL); | ||
| 801 | |||
| 802 | label = gtk_label_new(_("This name will be seen at the side of recipients (e.g. John Doe)")); | ||
| 803 | gtk_table_attach(GTK_TABLE(table), label, 1, 2, 1, 2, | ||
| 804 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 805 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | ||
| 806 | |||
| 807 | /* Page 3 */ | ||
| 808 | vbox = gtk_vbox_new(FALSE, 12); | ||
| 809 | gtk_notebook_append_page(GTK_NOTEBOOK(setupac.notebook), vbox, NULL); | ||
| 810 | gtk_container_set_border_width(GTK_CONTAINER(vbox), 12); | ||
| 811 | gtk_widget_show_all(dialog); | ||
| 812 | |||
| 813 | label = gtk_label_new(_("Input user ID and mail server:")); | ||
| 814 | gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 8); | ||
| 815 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | ||
| 816 | |||
| 817 | table = gtk_table_new(6, 2, FALSE); | ||
| 818 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | ||
| 819 | gtk_table_set_row_spacings(GTK_TABLE(table), 8); | ||
| 820 | gtk_table_set_col_spacings(GTK_TABLE(table), 8); | ||
| 821 | |||
| 822 | label = gtk_label_new(_("User ID:")); | ||
| 823 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, | ||
| 824 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 825 | gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | ||
| 826 | label = gtk_label_new(_("POP3 server:")); | ||
| 827 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, | ||
| 828 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 829 | gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | ||
| 830 | setupac.serv_label_name1 = label; | ||
| 831 | label = gtk_label_new(_("SMTP server:")); | ||
| 832 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, 4, 5, | ||
| 833 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 834 | gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | ||
| 835 | |||
| 836 | setupac.id_entry = gtk_entry_new(); | ||
| 837 | gtk_table_attach(GTK_TABLE(table), setupac.id_entry, 1, 2, 0, 1, | ||
| 838 | GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0); | ||
| 839 | g_signal_connect(setupac.id_entry, "changed", | ||
| 840 | G_CALLBACK(entry_changed), NULL); | ||
| 841 | setupac.serv_entry = gtk_entry_new(); | ||
| 842 | gtk_table_attach(GTK_TABLE(table), setupac.serv_entry, 1, 2, 1, 2, | ||
| 843 | GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0); | ||
| 844 | g_signal_connect(setupac.serv_entry, "changed", | ||
| 845 | G_CALLBACK(entry_changed), NULL); | ||
| 846 | setupac.smtp_entry = gtk_entry_new(); | ||
| 847 | gtk_table_attach(GTK_TABLE(table), setupac.smtp_entry, 1, 2, 4, 5, | ||
| 848 | GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0); | ||
| 849 | g_signal_connect(setupac.smtp_entry, "changed", | ||
| 850 | G_CALLBACK(entry_changed), NULL); | ||
| 851 | |||
| 852 | #if USE_SSL | ||
| 853 | hbox = gtk_hbox_new(FALSE, 12); | ||
| 854 | gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 2, 3, | ||
| 855 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 856 | chkbtn = gtk_check_button_new_with_mnemonic(_("Use SSL")); | ||
| 857 | gtk_box_pack_start(GTK_BOX(hbox), chkbtn, FALSE, FALSE, 0); | ||
| 858 | setupac.servssl_chkbtn = chkbtn; | ||
| 859 | #endif | ||
| 860 | |||
| 861 | hbox = gtk_hbox_new(FALSE, 12); | ||
| 862 | gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 5, 6, | ||
| 863 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 864 | chkbtn = gtk_check_button_new_with_mnemonic(_("Use SMTP authentication")); | ||
| 865 | gtk_box_pack_start(GTK_BOX(hbox), chkbtn, FALSE, FALSE, 0); | ||
| 866 | setupac.smtpauth_chkbtn = chkbtn; | ||
| 867 | #if USE_SSL | ||
| 868 | chkbtn = gtk_check_button_new_with_mnemonic(_("Use SSL")); | ||
| 869 | gtk_box_pack_start(GTK_BOX(hbox), chkbtn, FALSE, FALSE, 0); | ||
| 870 | setupac.smtpssl_chkbtn = chkbtn; | ||
| 871 | #endif | ||
| 872 | |||
| 873 | /* Page 4 */ | ||
| 874 | vbox = gtk_vbox_new(FALSE, 12); | ||
| 875 | gtk_notebook_append_page(GTK_NOTEBOOK(setupac.notebook), vbox, NULL); | ||
| 876 | gtk_container_set_border_width(GTK_CONTAINER(vbox), 12); | ||
| 877 | |||
| 878 | vbox2 = gtk_vbox_new(FALSE, 8); | ||
| 879 | gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, FALSE, 8); | ||
| 880 | |||
| 881 | label = gtk_label_new(_("Your new mail account has been set up with the following settings.")); | ||
| 882 | gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | ||
| 883 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | ||
| 884 | label = gtk_label_new(_("If you want to modify the settings, select\n" | ||
| 885 | "'Configuration - Preferences for current account' or\n" | ||
| 886 | "'Configuration - Edit accounts' in the main menu.")); | ||
| 887 | gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | ||
| 888 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); | ||
| 889 | //gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | ||
| 890 | |||
| 891 | table = gtk_table_new(5, 2, FALSE); | ||
| 892 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | ||
| 893 | gtk_table_set_row_spacings(GTK_TABLE(table), 8); | ||
| 894 | gtk_table_set_col_spacings(GTK_TABLE(table), 8); | ||
| 895 | |||
| 896 | label = gtk_label_new(_("Display name:")); | ||
| 897 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, | ||
| 898 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 899 | gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | ||
| 900 | label = gtk_label_new(_("E-mail address:")); | ||
| 901 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, | ||
| 902 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 903 | gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | ||
| 904 | label = gtk_label_new(_("User ID:")); | ||
| 905 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, | ||
| 906 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 907 | gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | ||
| 908 | setupac.serv_label_name2 = gtk_label_new(_("POP3 server:")); | ||
| 909 | gtk_table_attach(GTK_TABLE(table), setupac.serv_label_name2, 0, 1, 3, 4, | ||
| 910 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 911 | gtk_misc_set_alignment(GTK_MISC(setupac.serv_label_name2), 1, 0.5); | ||
| 912 | label = gtk_label_new(_("SMTP server:")); | ||
| 913 | gtk_table_attach(GTK_TABLE(table), label, 0, 1, 4, 5, | ||
| 914 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 915 | gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | ||
| 916 | |||
| 917 | setupac.name_label = gtk_label_new(""); | ||
| 918 | gtk_table_attach(GTK_TABLE(table), setupac.name_label, 1, 2, 0, 1, | ||
| 919 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 920 | gtk_misc_set_alignment(GTK_MISC(setupac.name_label), 0, 0.5); | ||
| 921 | setupac.addr_label = gtk_label_new(""); | ||
| 922 | gtk_table_attach(GTK_TABLE(table), setupac.addr_label, 1, 2, 1, 2, | ||
| 923 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 924 | gtk_misc_set_alignment(GTK_MISC(setupac.addr_label), 0, 0.5); | ||
| 925 | setupac.id_label = gtk_label_new(""); | ||
| 926 | gtk_table_attach(GTK_TABLE(table), setupac.id_label, 1, 2, 2, 3, | ||
| 927 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 928 | gtk_misc_set_alignment(GTK_MISC(setupac.id_label), 0, 0.5); | ||
| 929 | setupac.serv_label = gtk_label_new(""); | ||
| 930 | gtk_table_attach(GTK_TABLE(table), setupac.serv_label, 1, 2, 3, 4, | ||
| 931 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 932 | gtk_misc_set_alignment(GTK_MISC(setupac.serv_label), 0, 0.5); | ||
| 933 | setupac.smtp_label = gtk_label_new(""); | ||
| 934 | gtk_table_attach(GTK_TABLE(table), setupac.smtp_label, 1, 2, 4, 5, | ||
| 935 | GTK_FILL, GTK_FILL, 0, 0); | ||
| 936 | gtk_misc_set_alignment(GTK_MISC(setupac.smtp_label), 0, 0.5); | ||
| 937 | |||
| 938 | |||
| 939 | gtk_widget_show_all(dialog); | ||
| 940 | |||
| 941 | while (!setupac.finished) | ||
| 942 | result = gtk_dialog_run(GTK_DIALOG(dialog)); | ||
| 943 | |||
| 944 | gtk_widget_destroy(dialog); | ||
| 945 | |||
| 946 | if (setupac.cancelled) { | ||
| 947 | memset(&setupac, 0, sizeof(setupac)); | ||
| 948 | return NULL; | ||
| 949 | } | ||
| 950 | |||
| 951 | /* Create account */ | ||
| 952 | ac = prefs_account_new(); | ||
| 953 | |||
| 954 | if (!cur_account) { | ||
| 955 | account_set_as_default(ac); | ||
| 956 | cur_account = ac; | ||
| 957 | } | ||
| 958 | g_free(ac->account_name); | ||
| 959 | ac->account_name = g_strdup(setupac.addr); | ||
| 960 | g_free(ac->name); | ||
| 961 | ac->name = g_strdup(setupac.name); | ||
| 962 | g_free(ac->address); | ||
| 963 | ac->address = g_strdup(setupac.addr); | ||
| 964 | g_free(ac->recv_server); | ||
| 965 | ac->recv_server = g_strdup(setupac.serv); | ||
| 966 | g_free(ac->smtp_server); | ||
| 967 | ac->smtp_server = g_strdup(setupac.smtpserv); | ||
| 968 | g_free(ac->userid); | ||
| 969 | ac->userid = g_strdup(setupac.userid); | ||
| 970 | #if USE_SSL | ||
| 971 | if (setupac.smtp_ssl) | ||
| 972 | ac->ssl_smtp = SSL_TUNNEL; | ||
| 973 | #endif | ||
| 974 | ac->smtpport = setupac.smtp_port; | ||
| 975 | ac->use_smtp_auth = setupac.smtp_auth; | ||
| 976 | |||
| 977 | switch (setupac.type) { | ||
| 978 | case SETUP_TYPE_POP3: | ||
| 979 | ac->protocol = A_POP3; | ||
| 980 | #if USE_SSL | ||
| 981 | if (setupac.serv_ssl) | ||
| 982 | ac->ssl_pop = SSL_TUNNEL; | ||
| 983 | #endif | ||
| 984 | ac->popport = setupac.serv_port; | ||
| 985 | break; | ||
| 986 | case SETUP_TYPE_IMAP: | ||
| 987 | ac->protocol = A_IMAP4; | ||
| 988 | #if USE_SSL | ||
| 989 | if (setupac.serv_ssl) | ||
| 990 | ac->ssl_imap = SSL_TUNNEL; | ||
| 991 | #endif | ||
| 992 | ac->imapport = setupac.serv_port; | ||
| 993 | break; | ||
| 994 | #if USE_SSL | ||
| 995 | case SETUP_TYPE_POP3G: | ||
| 996 | ac->protocol = A_POP3; | ||
| 997 | ac->ssl_pop = SSL_TUNNEL; | ||
| 998 | ac->popport = setupac.serv_port; | ||
| 999 | break; | ||
| 1000 | case SETUP_TYPE_IMAPG: | ||
| 1001 | ac->protocol = A_IMAP4; | ||
| 1002 | ac->ssl_imap = SSL_TUNNEL; | ||
| 1003 | ac->imapport = setupac.serv_port; | ||
| 1004 | break; | ||
| 1005 | #endif /* USE_SSL */ | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | g_free(ac->sig_text); | ||
| 1009 | ac->sig_text = g_strdup_printf("%s <%s>\\n", ac->name, ac->address); | ||
| 1010 | |||
| 1011 | account_update_lock(); | ||
| 1012 | account_append(ac); | ||
| 1013 | account_write_config_all(); | ||
| 1014 | account_update_unlock(); | ||
| 1015 | account_updated(); | ||
| 1016 | |||
| 1017 | g_free(setupac.name); | ||
| 1018 | g_free(setupac.addr); | ||
| 1019 | g_free(setupac.serv); | ||
| 1020 | g_free(setupac.smtpserv); | ||
| 1021 | g_free(setupac.userid); | ||
| 1022 | memset(&setupac, 0, sizeof(setupac)); | ||
| 1023 | |||
| 1024 | return ac; | ||
| 1025 | } | ||
| 1026 | |||
| 1027 | #ifdef G_OS_WIN32 | ||
| 1028 | struct Identity | ||
| 1029 | { | ||
| 1030 | gchar *name; | ||
| 1031 | gchar *path; | ||
| 1032 | }; | ||
| 1033 | |||
| 1034 | static GSList *get_dbx_source(void) | ||
| 1035 | { | ||
| 1036 | HKEY reg_key, hkey, hkey2; | ||
| 1037 | wchar_t name[1024]; | ||
| 1038 | DWORD size, type, i; | ||
| 1039 | LPWSTR username, store, path; | ||
| 1040 | GSList *src_list = NULL; | ||
| 1041 | |||
| 1042 | if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Identities", 0, KEY_READ, ®_key) != ERROR_SUCCESS) | ||
| 1043 | return NULL; | ||
| 1044 | |||
| 1045 | for (i = 0; ; i++) { | ||
| 1046 | size = sizeof(name); | ||
| 1047 | if (RegEnumKeyExW(reg_key, i, name, &size, 0, 0, 0, 0) != ERROR_SUCCESS) | ||
| 1048 | break; | ||
| 1049 | if (RegOpenKeyExW(reg_key, name, 0, KEY_READ, &hkey) != ERROR_SUCCESS) | ||
| 1050 | continue; | ||
| 1051 | |||
| 1052 | do { | ||
| 1053 | if (RegQueryValueExW(hkey, L"UserName", 0, &type, 0, &size) != ERROR_SUCCESS) | ||
| 1054 | break; | ||
| 1055 | if (type != REG_SZ) | ||
| 1056 | break; | ||
| 1057 | ++size; | ||
| 1058 | username = g_malloc(size); | ||
| 1059 | if (RegQueryValueExW(hkey, L"UserName", 0, &type, (LPBYTE)username, &size) != ERROR_SUCCESS) { | ||
| 1060 | g_free(username); | ||
| 1061 | break; | ||
| 1062 | } | ||
| 1063 | |||
| 1064 | if (RegOpenKeyExW(hkey, L"Software\\Microsoft\\Outlook Express\\5.0", 0, KEY_READ, &hkey2) != ERROR_SUCCESS) { | ||
| 1065 | g_free(username); | ||
| 1066 | break; | ||
| 1067 | } | ||
| 1068 | |||
| 1069 | do { | ||
| 1070 | if (RegQueryValueExW(hkey2, L"Store Root", 0, &type, 0, &size) != ERROR_SUCCESS) | ||
| 1071 | break; | ||
| 1072 | if (type != REG_SZ && type != REG_EXPAND_SZ) | ||
| 1073 | break; | ||
| 1074 | |||
| 1075 | ++size; | ||
| 1076 | store = g_malloc(size); | ||
| 1077 | if (RegQueryValueExW(hkey2, L"Store Root", 0, &type, (LPBYTE)store, &size) != ERROR_SUCCESS) { | ||
| 1078 | g_free(store); | ||
| 1079 | break; | ||
| 1080 | } | ||
| 1081 | |||
| 1082 | if (type == REG_EXPAND_SZ) { | ||
| 1083 | size = MAX_PATH * 2; | ||
| 1084 | path = g_malloc(size); | ||
| 1085 | if (!ExpandEnvironmentStringsW(store, path, size)) { | ||
| 1086 | g_free(path); | ||
| 1087 | path = NULL; | ||
| 1088 | } | ||
| 1089 | } else { | ||
| 1090 | path = store; | ||
| 1091 | store = NULL; | ||
| 1092 | } | ||
| 1093 | |||
| 1094 | if (path) { | ||
| 1095 | struct Identity *ident; | ||
| 1096 | |||
| 1097 | ident = g_new(struct Identity, 1); | ||
| 1098 | ident->name = g_utf16_to_utf8(username, -1, NULL, NULL, NULL); | ||
| 1099 | ident->path = g_utf16_to_utf8(path, -1, NULL, NULL, NULL); | ||
| 1100 | src_list = g_slist_append(src_list, ident); | ||
| 1101 | debug_print("get_dbx_source: username = %s , path = %s\n", ident->name, ident->path); | ||
| 1102 | g_free(path); | ||
| 1103 | } | ||
| 1104 | g_free(store); | ||
| 1105 | } while (0); | ||
| 1106 | g_free(username); | ||
| 1107 | RegCloseKey(hkey2); | ||
| 1108 | } while (0); | ||
| 1109 | RegCloseKey(hkey); | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | RegCloseKey(reg_key); | ||
| 1113 | |||
| 1114 | return src_list; | ||
| 1115 | } | ||
| 1116 | #endif /* G_OS_WIN32 */ | ||
| 1117 | |||
| 1118 | gint setup_import_data(void) | ||
| 1119 | { | ||
| 1120 | #ifdef G_OS_WIN32 | ||
| 1121 | AlertValue val; | ||
| 1122 | GSList *src_list, *cur; | ||
| 1123 | struct Identity *ident; | ||
| 1124 | gchar *src; | ||
| 1125 | Folder *folder; | ||
| 1126 | FolderItem *parent, *dest; | ||
| 1127 | gint ok = 0; | ||
| 1128 | |||
| 1129 | debug_print("setup_import_data\n"); | ||
| 1130 | |||
| 1131 | src_list = get_dbx_source(); | ||
| 1132 | if (!src_list) | ||
| 1133 | return 0; | ||
| 1134 | |||
| 1135 | val = alertpanel(_("Importing mail data"), _("The mail store of Outlook Express was found. Do you want to import the mail data of Outlook Express?\n\n(The folder structure will not be reproduced)"), GTK_STOCK_YES, GTK_STOCK_NO, NULL); | ||
| 1136 | if (val != G_ALERTDEFAULT) { | ||
| 1137 | goto finish; | ||
| 1138 | } | ||
| 1139 | |||
| 1140 | folder = folder_get_default_folder(); | ||
| 1141 | if (!folder) { | ||
| 1142 | g_warning("Cannot get default folder"); | ||
| 1143 | ok = -1; | ||
| 1144 | goto finish; | ||
| 1145 | } | ||
| 1146 | parent = FOLDER_ITEM(folder->node->data); | ||
| 1147 | if (!parent) { | ||
| 1148 | g_warning("Cannot get root folder"); | ||
| 1149 | ok = -1; | ||
| 1150 | goto finish; | ||
| 1151 | } | ||
| 1152 | dest = folder_find_child_item_by_name(parent, _("Imported")); | ||
| 1153 | if (!dest) { | ||
| 1154 | dest = folder->klass->create_folder(folder, parent, _("Imported")); | ||
| 1155 | } | ||
| 1156 | if (!dest) { | ||
| 1157 | g_warning("Cannot create a folder"); | ||
| 1158 | ok = -1; | ||
| 1159 | goto finish; | ||
| 1160 | } | ||
| 1161 | parent = dest; | ||
| 1162 | folderview_append_item(folderview_get(), NULL, parent, TRUE); | ||
| 1163 | folder_write_list(); | ||
| 1164 | |||
| 1165 | for (cur = src_list; cur != NULL; cur = cur->next) { | ||
| 1166 | ident = (struct Identity *)cur->data; | ||
| 1167 | dest = folder_find_child_item_by_name(parent, ident->name); | ||
| 1168 | if (!dest) | ||
| 1169 | dest = folder->klass->create_folder(folder, parent, ident->name); | ||
| 1170 | if (!dest) | ||
| 1171 | continue; | ||
| 1172 | folderview_append_item(folderview_get(), NULL, dest, TRUE); | ||
| 1173 | folder_write_list(); | ||
| 1174 | ok = import_dbx_folders(dest, ident->path); | ||
| 1175 | if (ok < 0) | ||
| 1176 | break; | ||
| 1177 | } | ||
| 1178 | |||
| 1179 | finish: | ||
| 1180 | for (cur = src_list; cur != NULL; cur = cur->next) { | ||
| 1181 | ident = (struct Identity *)cur->data; | ||
| 1182 | g_free(ident->name); | ||
| 1183 | g_free(ident->path); | ||
| 1184 | g_free(ident); | ||
| 1185 | } | ||
| 1186 | g_slist_free(src_list); | ||
| 1187 | |||
| 1188 | if (ok == -1) | ||
| 1189 | alertpanel_error(_("Failed to import the mail data.")); | ||
| 1190 | |||
| 1191 | return ok; | ||
| 1192 | #else /* G_OS_WIN32 */ | ||
| 1193 | return 0; | ||
| 1194 | #endif /* G_OS_WIN32 */ | ||
| 1195 | } | ||
| 1196 | |||
| 1197 | #ifdef G_OS_WIN32 | ||
| 1198 | static gchar *get_wab_file(void) | ||
| 1199 | { | ||
| 1200 | HKEY reg_key; | ||
| 1201 | DWORD type, nbytes; | ||
| 1202 | wchar_t *tmp; | ||
| 1203 | gchar *result = NULL; | ||
| 1204 | |||
| 1205 | if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\WAB\\WAB4\\Wab File Name", 0, KEY_QUERY_VALUE, ®_key) != ERROR_SUCCESS) | ||
| 1206 | return NULL; | ||
| 1207 | if (RegQueryValueExW(reg_key, L"", 0, &type, NULL, &nbytes) == ERROR_SUCCESS && type == REG_SZ) { | ||
| 1208 | tmp = g_new(wchar_t, (nbytes + 1) / 2 + 1); | ||
| 1209 | RegQueryValueExW(reg_key, L"", 0, &type, (LPBYTE)tmp, &nbytes); | ||
| 1210 | tmp[nbytes / 2] = '\0'; | ||
| 1211 | result = g_utf16_to_utf8(tmp, -1, NULL, NULL, NULL); | ||
| 1212 | g_free(tmp); | ||
| 1213 | } | ||
| 1214 | RegCloseKey(reg_key); | ||
| 1215 | |||
| 1216 | return result; | ||
| 1217 | } | ||
| 1218 | #endif /* G_OS_WIN32 */ | ||
| 1219 | |||
| 1220 | gint setup_import_addressbook(void) | ||
| 1221 | { | ||
| 1222 | #ifdef G_OS_WIN32 | ||
| 1223 | AlertValue val; | ||
| 1224 | gchar *appdata; | ||
| 1225 | gchar *wabfile, *ldiffile; | ||
| 1226 | gchar cmdline[MAX_PATH + 1]; | ||
| 1227 | gchar *cpcmdline; | ||
| 1228 | gint ret = 0; | ||
| 1229 | |||
| 1230 | debug_print("setup_import_addressbook\n"); | ||
| 1231 | |||
| 1232 | wabfile = get_wab_file(); | ||
| 1233 | if (!wabfile || !is_file_exist(wabfile)) { | ||
| 1234 | g_free(wabfile); | ||
| 1235 | return 0; | ||
| 1236 | } | ||
| 1237 | |||
| 1238 | val = alertpanel(_("Importing address book"), _("The Windows address book was found. Do you want to import the address book?"), GTK_STOCK_YES, GTK_STOCK_NO, NULL); | ||
| 1239 | if (val != G_ALERTDEFAULT) { | ||
| 1240 | g_free(wabfile); | ||
| 1241 | return 0; | ||
| 1242 | } | ||
| 1243 | |||
| 1244 | ldiffile = g_strconcat(get_tmp_dir(), G_DIR_SEPARATOR_S, "impwab.ldif", | ||
| 1245 | NULL); | ||
| 1246 | g_snprintf(cmdline, sizeof(cmdline), "wabread \"%s\" > \"%s\"", | ||
| 1247 | wabfile, ldiffile); | ||
| 1248 | debug_print("setup_import_addressbook: cmdline: %s\n", cmdline); | ||
| 1249 | cpcmdline = g_win32_locale_filename_from_utf8(cmdline); | ||
| 1250 | if (!cpcmdline) { | ||
| 1251 | g_warning("g_win32_locale_filename_from_utf8() failed"); | ||
| 1252 | g_free(ldiffile); | ||
| 1253 | g_free(wabfile); | ||
| 1254 | return -1; | ||
| 1255 | } | ||
| 1256 | ret = system(cpcmdline); | ||
| 1257 | g_free(cpcmdline); | ||
| 1258 | g_free(wabfile); | ||
| 1259 | if (ret != 0 || !is_file_exist(ldiffile)) { | ||
| 1260 | g_warning("system() failed"); | ||
| 1261 | ret = -1; | ||
| 1262 | goto finish; | ||
| 1263 | } | ||
| 1264 | |||
| 1265 | if (!addressbook_import_ldif_file(ldiffile, _("Imported"))) { | ||
| 1266 | g_warning("setup_import_addressbook: import failed"); | ||
| 1267 | ret = -1; | ||
| 1268 | goto finish; | ||
| 1269 | } | ||
| 1270 | |||
| 1271 | finish: | ||
| 1272 | g_unlink(ldiffile); | ||
| 1273 | g_free(ldiffile); | ||
| 1274 | if (ret < 0) | ||
| 1275 | alertpanel_error(_("Failed to import the address book.")); | ||
| 1276 | |||
| 1277 | return ret; | ||
| 1278 | #else /* G_OS_WIN32 */ | ||
| 1279 | return 0; | ||
| 1280 | #endif /* G_OS_WIN32 */ | ||
| 1281 | } | ||
