2007-11-16 [colin] 3.0.2cvs140
[claws.git] / src / main.c
index b60e7463831c4bb7d3fa165320725289755536d6..763344bc5e45c2334c3d355cf71ab440c38b9f3d 100644 (file)
 #include "tags.h"
 #ifdef HAVE_LIBETPAN
 #include "imap-thread.h"
+#include "nntp-thread.h"
 #endif
 #include "stock_pixmap.h"
 #ifdef HAVE_VALGRIND
 #include "valgrind.h"
 #endif
-#if USE_OPENSSL
+#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
 #  include "ssl.h"
 #endif
 
 #include "timing.h"
 
 #ifdef MAEMO
+#ifdef CHINOOK
+#include <hildon/hildon-banner.h>
+#include <hildon/hildon-program.h>
+#else
+#include <hildon-widgets/hildon-banner.h>
 #include <hildon-widgets/hildon-program.h>
+#endif
 #include <gtk/gtkmain.h>
 #include <libosso.h>
 #include <libgnomevfs/gnome-vfs-volume.h>
@@ -141,6 +148,10 @@ static GnomeVFSVolumeMonitor *volmon;
 gchar *prog_version;
 gchar *argv0;
 
+#ifdef MAEMO
+HildonProgram *hildon_program;
+#endif
+
 #ifdef HAVE_STARTUP_NOTIFICATION
 static SnLauncheeContext *sn_context = NULL;
 static SnDisplay *sn_display = NULL;
@@ -212,7 +223,6 @@ static void exit_claws                      (MainWindow *mainwin);
 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)
@@ -298,6 +308,8 @@ static void claws_gtk_idle(void)
        g_usleep(50000);
 }
 
+static gboolean sc_starting = FALSE;
+
 static gboolean defer_check_all(void *data)
 {
        gboolean autochk = GPOINTER_TO_INT(data);
@@ -305,6 +317,11 @@ static gboolean defer_check_all(void *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;
 }
 
@@ -312,6 +329,11 @@ static gboolean defer_check(void *data)
 {
        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;
 }
 
@@ -325,6 +347,11 @@ static gboolean defer_jump(void *data)
                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;
 }
 
@@ -407,18 +434,20 @@ backup_mode:
        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());
@@ -435,19 +464,22 @@ static void migrate_common_rc(const gchar *old_rc, const gchar *new_rc)
        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
@@ -622,7 +654,6 @@ static void sc_session_manager_connect(MainWindow *mainwin)
 #endif
 
 static gboolean sc_exiting = FALSE;
-static gboolean sc_starting = FALSE;
 static gboolean show_at_startup = TRUE;
 static gboolean claws_crashed_bool = FALSE;
 
@@ -768,6 +799,7 @@ int main(int argc, char *argv[])
        gboolean crash_file_present = FALSE;
        gint num_folder_class = 0;
        gboolean asked_for_migration = FALSE;
+       gboolean start_done = TRUE;
 
        START_TIMING("startup");
        
@@ -783,12 +815,51 @@ int main(int argc, char *argv[])
                return 0;
        }
 
-       prefs_prepare_cache();
+       debug_print("GTK+ %d.%d.%d / GLib %d.%d.%d\n",
+                  gtk_major_version, gtk_minor_version, gtk_micro_version,
+                  glib_major_version, glib_minor_version, glib_micro_version);
+       debug_print("Compiled-in features:\n");
+#if HAVE_LIBCOMPFACE
+       debug_print(" compface\n");
+#endif
+#if USE_ASPELL
+       debug_print(" aspell\n");
+#endif
+#if USE_GNUTLS
+       debug_print(" gnutls\n");
+#endif
+#if INET6
+       debug_print(" ipv6\n");
+#endif
+#if HAVE_ICONV
+       debug_print(" iconv\n");
+#endif
+#if USE_JPILOT
+       debug_print(" jpilot\n");
+#endif
+#if USE_LDAP
+       debug_print(" ldap\n");
+#endif
+#if HAVE_LIBETPAN
+       debug_print(" libetpan %d.%d\n", LIBETPAN_VERSION_MAJOR, LIBETPAN_VERSION_MINOR);
+#endif
+#if USE_GNOMEPRINT
+       debug_print(" gnomeprint\n");
+#endif
+#if HAVE_LIBSM
+       debug_print(" libsm\n");
+#endif
+#if USE_OPENSSL
+       debug_print(" openssl\n");
+#endif
+
        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();
@@ -835,7 +906,7 @@ int main(int argc, char *argv[])
        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();
@@ -1009,7 +1080,6 @@ int main(int argc, char *argv[])
        prefs_display_header_read_config();
        /* prefs_filtering_read_config(); */
        addressbook_read_file();
-       renderer_read_config();
 
        gtkut_widget_init();
        stock_pixbuf_gdk(NULL, STOCK_PIXMAP_CLAWS_MAIL_ICON, &icon);
@@ -1025,8 +1095,8 @@ int main(int argc, char *argv[])
 #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, 
@@ -1037,6 +1107,7 @@ int main(int argc, char *argv[])
                return OSSO_ERROR;
        }
 
+#ifndef CHINOOK
        /* Add handler for Exit D-BUS messages */
        result = osso_application_set_exit_cb(appdata->osso_context,
                                                exit_event_handler,
@@ -1044,6 +1115,7 @@ int main(int argc, char *argv[])
        if (result != OSSO_OK) {
                return OSSO_ERROR;
        }
+#endif
 #endif
        manage_window_focus_in(mainwin->window, NULL, NULL);
        folderview = mainwin->folderview;
@@ -1097,7 +1169,6 @@ int main(int argc, char *argv[])
 #endif
                        exit(1);
                }
-               account_read_config_all();
                if(!account_get_list()) {
                        exit_claws(mainwin);
 #ifdef G_OS_WIN32
@@ -1119,6 +1190,7 @@ int main(int argc, char *argv[])
 #ifdef HAVE_LIBETPAN
        imap_main_init(prefs_common.skip_ssl_cert_check);
        imap_main_set_timeout(prefs_common.io_timeout_secs);
+       nntp_main_init(prefs_common.skip_ssl_cert_check);
 #endif 
        account_set_missing_folder();
        folder_set_missing_folders();
@@ -1266,10 +1338,13 @@ int main(int argc, char *argv[])
        }
 
        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);
@@ -1292,6 +1367,7 @@ int main(int argc, char *argv[])
        }
        
        if (cmd.target) {
+               start_done = FALSE;
                g_timeout_add(500, defer_jump, (gpointer)cmd.target);
        }
 
@@ -1299,7 +1375,11 @@ int main(int argc, char *argv[])
        
        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();
@@ -1374,6 +1454,7 @@ static void exit_claws(MainWindow *mainwin)
 
 #ifdef HAVE_LIBETPAN
        imap_main_done();
+       nntp_main_done();
 #endif
        /* delete crashfile */
        if (!cmd.crash)
@@ -1408,6 +1489,7 @@ static void exit_claws(MainWindow *mainwin)
        prefs_message_done();
        prefs_other_done();
        prefs_receive_done();
+       prefs_logging_done();
        prefs_send_done();
        tags_write_tags();
 #ifdef USE_ASPELL       
@@ -1475,7 +1557,7 @@ static void parse_cmd_opt(int argc, char *argv[])
                        cmd.send = TRUE;
                } else if (!strncmp(argv[i], "--version", 9) ||
                           !strncmp(argv[i], "-v", 2)) {
-                       g_print("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];
@@ -1522,7 +1604,7 @@ static void parse_cmd_opt(int argc, char *argv[])
                        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"));
@@ -1532,6 +1614,8 @@ static void parse_cmd_opt(int argc, char *argv[])
                        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);
@@ -1540,8 +1624,10 @@ static void parse_cmd_opt(int argc, char *argv[])
                        cmd.crash_params = g_strdup(argv[i + 1]);
                        i++;
                } else if (!strncmp(argv[i], "--config-dir", sizeof "--config-dir" - 1)) {
-                       g_print(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)) {
@@ -1708,10 +1794,15 @@ gboolean claws_is_starting(void)
 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
@@ -1999,11 +2090,9 @@ static void send_queue(void)
                }
        }
        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.");
@@ -2054,10 +2143,6 @@ static void install_basic_sighandlers()
 }
 
 #ifdef MAEMO
-HildonProgram *hildon_program(void)
-{
-       return static_hildonprogram;
-}
 osso_context_t *get_osso_context(void)
 {
        return static_osso_context;