Revision 2164 src/main.c
| main.c (revision 2164) | ||
|---|---|---|
| 1 | 1 |
/* |
| 2 | 2 |
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 |
* Copyright (C) 1999-2008 Hiroyuki Yamamoto
|
|
| 3 |
* Copyright (C) 1999-2009 Hiroyuki Yamamoto
|
|
| 4 | 4 |
* |
| 5 | 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 | 6 |
* it under the terms of the GNU General Public License as published by |
| ... | ... | |
| 75 | 75 |
#include "logwindow.h" |
| 76 | 76 |
#include "folder.h" |
| 77 | 77 |
#include "setup.h" |
| 78 |
#include "sylmain.h" |
|
| 78 | 79 |
#include "utils.h" |
| 79 | 80 |
#include "gtkutils.h" |
| 80 | 81 |
#include "socket.h" |
| 81 | 82 |
#include "stock_pixmap.h" |
| 82 | 83 |
#include "trayicon.h" |
| 84 |
#include "plugin.h" |
|
| 85 |
#include "plugin_manager.h" |
|
| 86 |
#include "foldersel.h" |
|
| 87 |
#include "update_check.h" |
|
| 83 | 88 |
|
| 84 | 89 |
#if USE_GPGME |
| 85 | 90 |
# include "rfc2015.h" |
| ... | ... | |
| 136 | 141 |
static void check_gpg (void); |
| 137 | 142 |
static void set_log_handlers (gboolean enable); |
| 138 | 143 |
static void register_system_events (void); |
| 144 |
static void plugin_init (void); |
|
| 139 | 145 |
|
| 140 | 146 |
static gchar *get_socket_name (void); |
| 141 | 147 |
static gint prohibit_duplicate_launch (void); |
| ... | ... | |
| 174 | 180 |
exit(val); \ |
| 175 | 181 |
} |
| 176 | 182 |
|
| 183 |
static void load_cb(GObject *obj, GModule *module, gpointer data) |
|
| 184 |
{
|
|
| 185 |
g_print("load_cb: %p (%s), %p\n", module, module ? g_module_name(module) : "(null)", data);
|
|
| 186 |
} |
|
| 177 | 187 |
|
| 178 | 188 |
int main(int argc, char *argv[]) |
| 179 | 189 |
{
|
| ... | ... | |
| 183 | 193 |
#ifdef G_OS_WIN32 |
| 184 | 194 |
GList *iconlist = NULL; |
| 185 | 195 |
#endif |
| 196 |
GObject *syl_app; |
|
| 186 | 197 |
|
| 187 | 198 |
app_init(); |
| 188 | 199 |
parse_cmd_opt(argc, argv); |
| 189 | 200 |
|
| 190 |
sock_init(); |
|
| 191 |
#if USE_SSL |
|
| 192 |
ssl_init(); |
|
| 193 |
#endif |
|
| 194 |
|
|
| 195 | 201 |
/* check and create (unix domain) socket for remote operation */ |
| 196 | 202 |
lock_socket = prohibit_duplicate_launch(); |
| 197 | 203 |
if (lock_socket < 0) return 0; |
| ... | ... | |
| 205 | 211 |
gtk_set_locale(); |
| 206 | 212 |
gtk_init(&argc, &argv); |
| 207 | 213 |
|
| 214 |
syl_app = syl_app_create(); |
|
| 215 |
|
|
| 208 | 216 |
gdk_rgb_init(); |
| 209 | 217 |
gtk_widget_set_default_colormap(gdk_rgb_get_cmap()); |
| 210 | 218 |
gtk_widget_set_default_visual(gdk_rgb_get_visual()); |
| ... | ... | |
| 324 | 332 |
|
| 325 | 333 |
inc_autocheck_timer_init(mainwin); |
| 326 | 334 |
|
| 335 |
plugin_init(); |
|
| 336 |
|
|
| 337 |
g_signal_emit_by_name(syl_app, "init-done"); |
|
| 338 |
|
|
| 327 | 339 |
remote_command_exec(); |
| 340 |
if (prefs_common.auto_update_check) |
|
| 341 |
update_check(FALSE); |
|
| 328 | 342 |
|
| 329 | 343 |
gtk_main(); |
| 330 | 344 |
|
| ... | ... | |
| 568 | 582 |
|
| 569 | 583 |
static void app_init(void) |
| 570 | 584 |
{
|
| 571 |
#ifdef G_OS_WIN32 |
|
| 572 |
gchar *newpath; |
|
| 573 |
const gchar *lang_env; |
|
| 585 |
syl_init(); |
|
| 574 | 586 |
|
| 575 |
/* disable locale variable such as "LANG=1041" */ |
|
| 576 |
|
|
| 577 |
#define DISABLE_DIGIT_LOCALE(envstr) \ |
|
| 578 |
{ \
|
|
| 579 |
lang_env = g_getenv(envstr); \ |
|
| 580 |
if (lang_env && g_ascii_isdigit(lang_env[0])) \ |
|
| 581 |
g_unsetenv(envstr); \ |
|
| 582 |
} |
|
| 583 |
|
|
| 584 |
DISABLE_DIGIT_LOCALE("LC_ALL");
|
|
| 585 |
DISABLE_DIGIT_LOCALE("LANG");
|
|
| 586 |
DISABLE_DIGIT_LOCALE("LC_CTYPE");
|
|
| 587 |
DISABLE_DIGIT_LOCALE("LC_MESSAGES");
|
|
| 588 |
|
|
| 589 |
#undef DISABLE_DIGIT_LOCALE |
|
| 590 |
|
|
| 591 |
g_unsetenv("LANGUAGE");
|
|
| 592 |
#endif |
|
| 593 |
|
|
| 594 |
#ifdef HAVE_LOCALE_H |
|
| 595 |
setlocale(LC_ALL, ""); |
|
| 596 |
#endif |
|
| 597 |
|
|
| 598 | 587 |
prog_version = PROG_VERSION; |
| 599 |
set_startup_dir(); |
|
| 600 | 588 |
|
| 601 | 589 |
#ifdef G_OS_WIN32 |
| 602 |
/* include startup directory into %PATH% for GSpawn */ |
|
| 603 |
newpath = g_strconcat(get_startup_dir(), ";", g_getenv("PATH"), NULL);
|
|
| 604 |
g_setenv("PATH", newpath, TRUE);
|
|
| 605 |
g_free(newpath); |
|
| 606 |
#endif |
|
| 607 |
|
|
| 608 |
#ifdef ENABLE_NLS |
|
| 609 |
if (g_path_is_absolute(LOCALEDIR)) |
|
| 610 |
bindtextdomain(PACKAGE, LOCALEDIR); |
|
| 611 |
else {
|
|
| 612 |
gchar *locale_dir; |
|
| 613 |
|
|
| 614 |
locale_dir = g_strconcat(get_startup_dir(), G_DIR_SEPARATOR_S, |
|
| 615 |
LOCALEDIR, NULL); |
|
| 616 |
#ifdef G_OS_WIN32 |
|
| 617 |
{
|
|
| 618 |
gchar *locale_dir_; |
|
| 619 |
|
|
| 620 |
locale_dir_ = g_locale_from_utf8(locale_dir, -1, |
|
| 621 |
NULL, NULL, NULL); |
|
| 622 |
if (locale_dir_) {
|
|
| 623 |
g_free(locale_dir); |
|
| 624 |
locale_dir = locale_dir_; |
|
| 625 |
} |
|
| 626 |
} |
|
| 627 |
#endif /* G_OS_WIN32 */ |
|
| 628 |
bindtextdomain(PACKAGE, locale_dir); |
|
| 629 |
g_free(locale_dir); |
|
| 630 |
} |
|
| 631 |
|
|
| 632 |
bind_textdomain_codeset(PACKAGE, CS_UTF_8); |
|
| 633 |
textdomain(PACKAGE); |
|
| 634 |
#endif /* ENABLE_NLS */ |
|
| 635 |
|
|
| 636 |
#ifdef G_OS_WIN32 |
|
| 637 | 590 |
read_ini_file(); |
| 638 | 591 |
#endif |
| 639 | 592 |
} |
| ... | ... | |
| 704 | 657 |
} |
| 705 | 658 |
#endif /* !G_OS_WIN32 */ |
| 706 | 659 |
|
| 707 |
if (!is_dir_exist(get_rc_dir())) {
|
|
| 708 |
if (make_dir_hier(get_rc_dir()) < 0) |
|
| 709 |
exit(1); |
|
| 710 |
} |
|
| 711 |
|
|
| 712 |
MAKE_DIR_IF_NOT_EXIST(get_mail_base_dir()); |
|
| 713 |
|
|
| 714 |
CHDIR_EXIT_IF_FAIL(get_rc_dir(), 1); |
|
| 715 |
|
|
| 716 |
MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir()); |
|
| 717 |
MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir()); |
|
| 718 |
MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir()); |
|
| 719 |
MAKE_DIR_IF_NOT_EXIST(get_tmp_dir()); |
|
| 720 |
MAKE_DIR_IF_NOT_EXIST(UIDL_DIR); |
|
| 721 |
|
|
| 722 |
/* remove temporary files */ |
|
| 723 |
remove_all_files(get_tmp_dir()); |
|
| 724 |
remove_all_files(get_mime_tmp_dir()); |
|
| 660 |
syl_setup_rc_dir(); |
|
| 725 | 661 |
} |
| 726 | 662 |
|
| 727 | 663 |
void app_will_exit(gboolean force) |
| ... | ... | |
| 760 | 696 |
manage_window_focus_in(mainwin->window, NULL, NULL); |
| 761 | 697 |
} |
| 762 | 698 |
|
| 699 |
g_signal_emit_by_name(syl_app_get(), "app-exit"); |
|
| 700 |
|
|
| 763 | 701 |
inc_autocheck_timer_remove(); |
| 764 | 702 |
|
| 765 | 703 |
if (prefs_common.clean_on_exit) |
| ... | ... | |
| 773 | 711 |
procmsg_remove_all_cached_messages(FOLDER(ac->folder)); |
| 774 | 712 |
} |
| 775 | 713 |
|
| 714 |
syl_plugin_unload_all(); |
|
| 715 |
|
|
| 776 | 716 |
trayicon_destroy(mainwin->tray_icon); |
| 777 | 717 |
|
| 778 | 718 |
/* save all state before exiting */ |
| 779 |
folder_write_list(); |
|
| 780 | 719 |
summary_write_cache(mainwin->summaryview); |
| 781 |
|
|
| 782 | 720 |
main_window_get_size(mainwin); |
| 783 | 721 |
main_window_get_position(mainwin); |
| 784 |
prefs_common_write_config(); |
|
| 785 |
filter_write_config(); |
|
| 786 |
account_write_config_all(); |
|
| 722 |
syl_save_all_state(); |
|
| 787 | 723 |
addressbook_export_to_file(); |
| 788 | 724 |
|
| 789 | 725 |
filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL); |
| 790 | 726 |
gtk_accel_map_save(filename); |
| 791 | 727 |
g_free(filename); |
| 792 | 728 |
|
| 793 |
/* remove temporary files */ |
|
| 794 |
remove_all_files(get_tmp_dir()); |
|
| 795 |
remove_all_files(get_mime_tmp_dir()); |
|
| 796 |
|
|
| 797 |
set_log_handlers(FALSE); |
|
| 798 |
close_log_file(); |
|
| 729 |
/* remove temporary files, close log file, socket cleanup */ |
|
| 730 |
syl_cleanup(); |
|
| 799 | 731 |
lock_socket_remove(); |
| 800 | 732 |
|
| 801 |
#if USE_SSL |
|
| 802 |
ssl_done(); |
|
| 803 |
#endif |
|
| 804 | 733 |
cleanup_console(); |
| 805 |
sock_cleanup(); |
|
| 806 | 734 |
|
| 807 | 735 |
if (gtk_main_level() > 0) |
| 808 | 736 |
gtk_main_quit(); |
| ... | ... | |
| 1080 | 1008 |
} |
| 1081 | 1009 |
#endif |
| 1082 | 1010 |
|
| 1011 |
static void plugin_init(void) |
|
| 1012 |
{
|
|
| 1013 |
MainWindow *mainwin; |
|
| 1014 |
|
|
| 1015 |
mainwin = main_window_get(); |
|
| 1016 |
|
|
| 1017 |
if (syl_plugin_init_lib() != 0) |
|
| 1018 |
return; |
|
| 1019 |
|
|
| 1020 |
syl_plugin_add_symbol("prog_version", prog_version);
|
|
| 1021 |
syl_plugin_add_symbol("main_window_get", main_window_get);
|
|
| 1022 |
syl_plugin_add_symbol("main_window_popup", main_window_popup);
|
|
| 1023 |
syl_plugin_add_symbol("app_will_exit", app_will_exit);
|
|
| 1024 |
syl_plugin_add_symbol("main_window_menu_factory",
|
|
| 1025 |
mainwin->menu_factory); |
|
| 1026 |
|
|
| 1027 |
syl_plugin_add_symbol("folderview", mainwin->folderview);
|
|
| 1028 |
syl_plugin_add_symbol("folderview_get_selected_item",
|
|
| 1029 |
folderview_get_selected_item); |
|
| 1030 |
syl_plugin_add_symbol("folderview_mail_popup_factory",
|
|
| 1031 |
mainwin->folderview->mail_factory); |
|
| 1032 |
|
|
| 1033 |
syl_plugin_add_symbol("summaryview", mainwin->summaryview);
|
|
| 1034 |
syl_plugin_add_symbol("summary_select_by_msgnum",
|
|
| 1035 |
summary_select_by_msgnum); |
|
| 1036 |
syl_plugin_add_symbol("summary_select_by_msginfo",
|
|
| 1037 |
summary_select_by_msginfo); |
|
| 1038 |
|
|
| 1039 |
syl_plugin_add_symbol("messageview_create_with_new_window",
|
|
| 1040 |
messageview_create_with_new_window); |
|
| 1041 |
syl_plugin_add_symbol("messageview_show", messageview_show);
|
|
| 1042 |
|
|
| 1043 |
syl_plugin_add_symbol("foldersel_folder_sel",
|
|
| 1044 |
foldersel_folder_sel); |
|
| 1045 |
syl_plugin_add_symbol("foldersel_folder_sel_full",
|
|
| 1046 |
foldersel_folder_sel_full); |
|
| 1047 |
syl_plugin_add_symbol("input_dialog", input_dialog);
|
|
| 1048 |
syl_plugin_add_symbol("input_dialog_with_invisible",
|
|
| 1049 |
input_dialog_with_invisible); |
|
| 1050 |
|
|
| 1051 |
syl_plugin_add_symbol("manage_window_set_transient",
|
|
| 1052 |
manage_window_set_transient); |
|
| 1053 |
syl_plugin_add_symbol("manage_window_signals_connect",
|
|
| 1054 |
manage_window_signals_connect); |
|
| 1055 |
syl_plugin_add_symbol("manage_window_get_focus_window",
|
|
| 1056 |
manage_window_get_focus_window); |
|
| 1057 |
|
|
| 1058 |
syl_plugin_add_symbol("inc_mail", inc_mail);
|
|
| 1059 |
syl_plugin_add_symbol("inc_lock", inc_lock);
|
|
| 1060 |
syl_plugin_add_symbol("inc_unlock", inc_unlock);
|
|
| 1061 |
|
|
| 1062 |
syl_plugin_signal_connect("plugin-load", G_CALLBACK(load_cb), NULL);
|
|
| 1063 |
|
|
| 1064 |
#ifdef G_OS_WIN32 |
|
| 1065 |
{
|
|
| 1066 |
gchar *path; |
|
| 1067 |
path = g_strconcat(get_startup_dir(), G_DIR_SEPARATOR_S, |
|
| 1068 |
"plugins", NULL); |
|
| 1069 |
syl_plugin_load_all(path); |
|
| 1070 |
g_free(path); |
|
| 1071 |
} |
|
| 1072 |
#else |
|
| 1073 |
syl_plugin_load_all(PLUGINDIR); |
|
| 1074 |
#endif |
|
| 1075 |
} |
|
| 1076 |
|
|
| 1083 | 1077 |
static gchar *get_socket_name(void) |
| 1084 | 1078 |
{
|
| 1085 | 1079 |
static gchar *filename = NULL; |
Also available in: Unified diff