#include "timing.h"
#ifdef MAEMO
+#include <hildon-widgets/hildon-banner.h>
#include <hildon-widgets/hildon-program.h>
#include <gtk/gtkmain.h>
#include <libosso.h>
static MainWindow *static_mainwindow;
#ifdef MAEMO
-static HildonProgram *static_hildonprogram;
static osso_context_t *static_osso_context;
void exit_event_handler(gboolean die_now, gpointer data)
g_usleep(50000);
}
+static gboolean sc_starting = FALSE;
+
static gboolean defer_check_all(void *data)
{
gboolean autochk = GPOINTER_TO_INT(data);
inc_all_account_mail(static_mainwindow, autochk,
prefs_common.newmail_notify_manu);
+ if (sc_starting) {
+ sc_starting = FALSE;
+ main_window_set_menu_sensitive(static_mainwindow);
+ toolbar_main_set_sensitive(static_mainwindow);
+ }
return FALSE;
}
{
inc_mail(static_mainwindow, prefs_common.newmail_notify_manu);
+ if (sc_starting) {
+ sc_starting = FALSE;
+ main_window_set_menu_sensitive(static_mainwindow);
+ toolbar_main_set_sensitive(static_mainwindow);
+ }
return FALSE;
}
defer_check(NULL);
}
mainwindow_jump_to(data, FALSE);
+ if (sc_starting) {
+ sc_starting = FALSE;
+ main_window_set_menu_sensitive(static_mainwindow);
+ toolbar_main_set_sensitive(static_mainwindow);
+ }
return FALSE;
}
return (r == 0);
}
-static void migrate_common_rc(const gchar *old_rc, const gchar *new_rc)
+static int migrate_common_rc(const gchar *old_rc, const gchar *new_rc)
{
FILE *oldfp, *newfp;
gchar *plugin_path, *old_plugin_path, *new_plugin_path;
gchar buf[BUFFSIZE];
+ gboolean err = FALSE;
+
oldfp = g_fopen(old_rc, "r");
if (!oldfp)
- return;
+ return -1;
newfp = g_fopen(new_rc, "w");
if (!newfp) {
fclose(oldfp);
- return;
+ return -1;
}
plugin_path = g_strdup(get_plugin_dir());
debug_print("replacing %s with %s\n", old_plugin_path, new_plugin_path);
while (fgets(buf, sizeof(buf), oldfp)) {
if (strncmp(buf, old_plugin_path, strlen(old_plugin_path))) {
- fputs(buf, newfp);
+ err |= (fputs(buf, newfp) == EOF);
} else {
debug_print("->replacing %s", buf);
debug_print(" with %s%s", new_plugin_path, buf+strlen(old_plugin_path));
- fputs(new_plugin_path, newfp);
- fputs(buf+strlen(old_plugin_path), newfp);
+ err |= (fputs(new_plugin_path, newfp) == EOF);
+ err |= (fputs(buf+strlen(old_plugin_path), newfp) == EOF);
}
}
g_free(plugin_path);
g_free(new_plugin_path);
g_free(old_plugin_path);
fclose(oldfp);
- fclose(newfp);
+ if (fclose(newfp) == EOF)
+ err = TRUE;
+
+ return (err ? -1:0);
}
#ifdef HAVE_LIBSM
#endif
static gboolean sc_exiting = FALSE;
-static gboolean sc_starting = FALSE;
static gboolean show_at_startup = TRUE;
static gboolean claws_crashed_bool = FALSE;
}
#endif
+#ifdef G_OS_WIN32
+static FILE* win32_debug_fp=NULL;
+static guint win32_log_handler_app_id;
+static guint win32_log_handler_glib_id;
+static guint win32_log_handler_gtk_id;
+
+static void win32_print_stdout(const gchar *string)
+{
+ if (win32_debug_fp) {
+ fprintf(win32_debug_fp, string);
+ fflush(win32_debug_fp);
+ }
+}
+
+static void win32_print_stderr(const gchar *string)
+{
+ if (win32_debug_fp) {
+ fprintf(win32_debug_fp, string);
+ fflush(win32_debug_fp);
+ }
+}
+
+static void win32_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar* message, gpointer user_data)
+{
+ if (win32_debug_fp) {
+ const gchar* type;
+
+ switch(log_level & G_LOG_LEVEL_MASK)
+ {
+ case G_LOG_LEVEL_ERROR:
+ type="error";
+ break;
+ case G_LOG_LEVEL_CRITICAL:
+ type="critical";
+ break;
+ case G_LOG_LEVEL_WARNING:
+ type="warning";
+ break;
+ case G_LOG_LEVEL_MESSAGE:
+ type="message";
+ break;
+ case G_LOG_LEVEL_INFO:
+ type="info";
+ break;
+ case G_LOG_LEVEL_DEBUG:
+ type="debug";
+ break;
+ default:
+ type="N/A";
+ }
+ if (log_domain)
+ fprintf(win32_debug_fp, "%s: %s: %s", log_domain, type, message);
+ else
+ fprintf(win32_debug_fp, "%s: %s", type, message);
+ fflush(win32_debug_fp);
+ }
+}
+
+static void win32_open_log(void)
+{
+ if (is_file_exist("claws-win32.log")) {
+ if (rename_force("claws-win32.log", "claws-win32.log.bak") < 0)
+ FILE_OP_ERROR("claws-win32.log", "rename");
+ }
+ win32_debug_fp = fopen("claws-win32.log", "w");
+ if (win32_debug_fp)
+ {
+ g_set_print_handler(win32_print_stdout);
+ g_set_printerr_handler(win32_print_stdout);
+ win32_log_handler_app_id = g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+ | G_LOG_FLAG_RECURSION, win32_log, NULL);
+ win32_log_handler_glib_id = g_log_set_handler("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+ | G_LOG_FLAG_RECURSION, win32_log, NULL);
+ win32_log_handler_gtk_id = g_log_set_handler("Gtk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+ | G_LOG_FLAG_RECURSION, win32_log, NULL);
+ }
+}
+
+static void win32_close_log(void)
+{
+ if (win32_debug_fp)
+ {
+ g_log_remove_handler("", win32_log_handler_app_id);
+ g_log_remove_handler("GLib", win32_log_handler_glib_id);
+ g_log_remove_handler("Gtk", win32_log_handler_gtk_id);
+ fclose(win32_debug_fp);
+ win32_debug_fp=NULL;
+ }
+}
+#endif
+
int main(int argc, char *argv[])
{
#ifdef MAEMO
gboolean crash_file_present = FALSE;
gint num_folder_class = 0;
gboolean asked_for_migration = FALSE;
+ gboolean start_done = TRUE;
START_TIMING("startup");
sc_starting = TRUE;
+#ifdef G_OS_WIN32
+ win32_open_log();
+#endif
if (!claws_init(&argc, &argv)) {
+#ifdef G_OS_WIN32
+ win32_close_log();
+#endif
return 0;
}
- prefs_prepare_cache();
prog_version = PROG_VERSION;
argv0 = g_strdup(argv[0]);
parse_cmd_opt(argc, argv);
+ prefs_prepare_cache();
+
#ifdef CRASH_DIALOG
if (cmd.crash) {
gtk_set_locale();
gtk_init(&argc, &argv);
crash_main(cmd.crash_params);
+#ifdef G_OS_WIN32
+ win32_close_log();
+#endif
return 0;
}
crash_install_handlers();
if (osso_context == NULL) {
return OSSO_ERROR;
}
- static_hildonprogram = HILDON_PROGRAM(hildon_program_get_instance());
+ hildon_program = HILDON_PROGRAM(hildon_program_get_instance());
static_osso_context = osso_context;
#endif
gdk_rgb_init();
"currently available. This will cause "
"crashes. You need to upgrade GTK+ or "
"recompile Claws Mail."));
+#ifdef G_OS_WIN32
+ win32_close_log();
+#endif
exit(1);
}
#else
"currently available. This will cause "
"crashes. You need to recompile "
"Claws Mail."));
+#ifdef G_OS_WIN32
+ win32_close_log();
+#endif
exit(1);
}
#endif
gtk_rc_parse(userrc);
g_free(userrc);
+#ifdef G_OS_WIN32
+ CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_home_dir(), 1, win32_close_log(););
+#else
CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
+#endif
/* no config dir exists. See if we can migrate an old config. */
if (!is_dir_exist(RC_DIR)) {
/* If migration failed or the user didn't want to do it,
* we create a new one (and we'll hit wizard later).
*/
- if (r == FALSE && !is_dir_exist(RC_DIR) && make_dir(RC_DIR) < 0)
+ if (r == FALSE && !is_dir_exist(RC_DIR) && make_dir(RC_DIR) < 0) {
+#ifdef G_OS_WIN32
+ win32_close_log();
+#endif
exit(1);
}
+ }
if (!is_file_exist(RC_DIR G_DIR_SEPARATOR_S COMMON_RC) &&
gtk_accel_map_load (userrc);
g_free(userrc);
+#ifdef G_OS_WIN32
+ CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_rc_dir(), 1, win32_close_log(););
+#else
CHDIR_RETURN_VAL_IF_FAIL(get_rc_dir(), 1);
+#endif
MAKE_DIR_IF_NOT_EXIST(get_mail_base_dir());
MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
}
set_log_file(LOG_DEBUG_FILTERING, "filtering.log");
+#ifdef G_OS_WIN32
+ CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_home_dir(), 1, win32_close_log(););
+#else
CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
+#endif
folder_system_init();
prefs_common_read_config();
#ifdef MAEMO
AppData *appdata;
appdata = g_new0(AppData, 1);
- appdata->program = static_hildonprogram;
- appdata->window = mainwin->window;
+ appdata->program = hildon_program;
+ appdata->window = HILDON_WINDOW(mainwin->window);
appdata->osso_context = osso_context;
result = osso_rpc_set_cb_f(appdata->osso_context,
OSSO_SERVICE,
if (!run_wizard(mainwin, TRUE)) {
if (asked_for_migration)
remove_dir_recursive(RC_DIR);
+#ifdef G_OS_WIN32
+ win32_close_log();
+#endif
exit(1);
}
main_window_reflect_prefs_all_now();
if (!run_wizard(mainwin, FALSE)) {
if (asked_for_migration)
remove_dir_recursive(RC_DIR);
+#ifdef G_OS_WIN32
+ win32_close_log();
+#endif
exit(1);
}
- account_read_config_all();
if(!account_get_list()) {
exit_claws(mainwin);
+#ifdef G_OS_WIN32
+ win32_close_log();
+#endif
exit(1);
}
}
"external plugin. Please reinstall the "
"plugin and try again."));
exit_claws(mainwin);
+#ifdef G_OS_WIN32
+ win32_close_log();
+#endif
exit(1);
}
}
}
if (cmd.receive_all && !cmd.target) {
+ start_done = FALSE;
g_timeout_add(1000, defer_check_all, GINT_TO_POINTER(FALSE));
} else if (prefs_common.chk_on_startup && !cmd.target) {
+ start_done = FALSE;
g_timeout_add(1000, defer_check_all, GINT_TO_POINTER(TRUE));
} else if (cmd.receive && !cmd.target) {
+ start_done = FALSE;
g_timeout_add(1000, defer_check, NULL);
} else {
gtk_widget_grab_focus(folderview->ctree);
}
if (cmd.target) {
+ start_done = FALSE;
g_timeout_add(500, defer_jump, (gpointer)cmd.target);
}
compose_reopen_exit_drafts();
- sc_starting = FALSE;
+ if (start_done) {
+ sc_starting = FALSE;
+ main_window_set_menu_sensitive(mainwin);
+ toolbar_main_set_sensitive(mainwin);
+ }
END_TIMING();
gtk_main();
#ifdef MAEMO
osso_deinitialize(osso_context);
+#endif
+#ifdef G_OS_WIN32
+ win32_close_log();
#endif
exit_claws(mainwin);
cmd.send = TRUE;
} else if (!strncmp(argv[i], "--version", 9) ||
!strncmp(argv[i], "-v", 2)) {
- puts("Claws Mail version " VERSION);
+ g_print("Claws Mail version " VERSION "\n");
exit(0);
} else if (!strncmp(argv[i], "--status-full", 13)) {
const gchar *p = argv[i + 1];
g_print("%s\n", _(" --send send all queued messages"));
g_print("%s\n", _(" --status [folder]... show the total number of messages"));
g_print("%s\n", _(" --status-full [folder]...\n"
- " show the status of each folder"));
+ " show the status of each folder"));
g_print("%s\n", _(" --select folder[/msg] jumps to the specified folder/message\n"
" folder is a folder id like 'folder/sub_folder'"));
g_print("%s\n", _(" --online switch to online mode"));
g_print("%s\n", _(" --help -h display this help and exit"));
g_print("%s\n", _(" --version -v output version information and exit"));
g_print("%s\n", _(" --config-dir output configuration directory"));
+ g_print("%s\n", _(" --alternate-config-dir [dir]\n"
+ " use specified configuration directory"));
g_free(base);
exit(1);
cmd.crash_params = g_strdup(argv[i + 1]);
i++;
} else if (!strncmp(argv[i], "--config-dir", sizeof "--config-dir" - 1)) {
- puts(RC_DIR);
+ g_print(RC_DIR "\n");
exit(0);
+ } else if (!strncmp(argv[i], "--alternate-config-dir", sizeof "--alternate-config-dir" - 1) && i+1 < argc) {
+ set_rc_dir(argv[i+1]);
} else if (!strncmp(argv[i], "--exit", 6) ||
!strncmp(argv[i], "--quit", 6) ||
!strncmp(argv[i], "-q", 2)) {
gchar *claws_get_socket_name(void)
{
static gchar *filename = NULL;
-
+ const gchar *socket_dir = NULL;
+
+ if (rc_dir_is_alt())
+ socket_dir = get_rc_dir();
+ else
+ socket_dir = g_get_tmp_dir();
if (filename == NULL) {
filename = g_strdup_printf("%s%cclaws-mail-%d",
- g_get_tmp_dir(), G_DIR_SEPARATOR,
+ socket_dir, G_DIR_SEPARATOR,
#if HAVE_GETUID
getuid());
#else
memset(buf, 0, sizeof(buf));
fd_gets(uxsock, buf, sizeof(buf));
if (strcmp2(buf, x_display)) {
- printf("Claws Mail is already running on display %s.\n",
+ g_print("Claws Mail is already running on display %s.\n",
buf);
} else {
fd_close(uxsock);
}
}
if (errstr) {
- gchar *tmp = g_strdup_printf(_("Some errors occurred "
+ alertpanel_error_log(_("Some errors occurred "
"while sending queued messages:\n%s"), errstr);
g_free(errstr);
- alertpanel_error_log(tmp);
- g_free(tmp);
} else if (error) {
alertpanel_error_log("Some errors occurred "
"while sending queued messages.");
}
#ifdef MAEMO
-HildonProgram *hildon_program(void)
-{
- return static_hildonprogram;
-}
osso_context_t *get_osso_context(void)
{
return static_osso_context;