2006-12-11 [colin] 2.6.1cvs18
[claws.git] / src / main.c
index f99cfa74fc838e7cf1df7c9443a6a11d017dc236..3b92373d132146e4d8ad6528189b67b72785b46b 100644 (file)
@@ -51,7 +51,7 @@
 # include <gdk/gdkx.h>
 #endif
 
-#include "sylpheed.h"
+#include "claws.h"
 #include "main.h"
 #include "mainwindow.h"
 #include "folderview.h"
@@ -170,7 +170,7 @@ static void send_queue                      (void);
 static void initial_processing         (FolderItem *item, gpointer data);
 static void quit_signal_handler         (int sig);
 static void install_basic_sighandlers   (void);
-static void exit_sylpheed              (MainWindow *mainwin);
+static void exit_claws                 (MainWindow *mainwin);
 
 #define MAKE_DIR_IF_NOT_EXIST(dir) \
 { \
@@ -234,7 +234,7 @@ static void startup_notification_complete(gboolean with_window)
 }
 #endif /* HAVE_STARTUP_NOTIFICATION */
 
-void sylpheed_gtk_idle(void) 
+void claws_gtk_idle(void) 
 {
        while(gtk_events_pending()) {
                gtk_main_iteration();
@@ -287,6 +287,49 @@ static gboolean migrate_old_config(const gchar *old_cfg_dir, const gchar *new_cf
        return (r == 0);
 }
 
+static void 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];
+       oldfp = g_fopen(old_rc, "r");
+       if (!oldfp)
+               return;
+       newfp = g_fopen(new_rc, "w");
+       if (!newfp) {
+               fclose(oldfp);
+               return;
+       }
+       
+       plugin_path = g_strdup(get_plugin_dir());
+       new_plugin_path = g_strdup(plugin_path);
+       
+       if (strstr(plugin_path, "/claws-mail/")) {
+               gchar *end = g_strdup(strstr(plugin_path, "/claws-mail/")+strlen("/claws-mail/"));
+               *(strstr(plugin_path, "/claws-mail/")) = '\0';
+               old_plugin_path = g_strconcat(plugin_path, "/sylpheed-claws/", end, NULL);
+               g_free(end);
+       } else {
+               old_plugin_path = g_strdup(new_plugin_path);
+       }
+       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);
+               } 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);
+               }
+       }
+       g_free(plugin_path);
+       g_free(new_plugin_path);
+       g_free(old_plugin_path);
+       fclose(oldfp);
+       fclose(newfp);
+}
+
 #ifdef HAVE_LIBSM
 static void
 sc_client_set_value (MainWindow *mainwin,
@@ -468,7 +511,7 @@ int main(int argc, char *argv[])
        gint num_folder_class = 0;
        START_TIMING("startup");
        
-       if (!sylpheed_init(&argc, &argv)) {
+       if (!claws_init(&argc, &argv)) {
                return 0;
        }
 
@@ -478,9 +521,6 @@ int main(int argc, char *argv[])
 
        parse_cmd_opt(argc, argv);
 
-       if (!cmd.exit)
-               plugin_load_all("Common");
-
 #ifdef CRASH_DIALOG
        if (cmd.crash) {
                gtk_set_locale();
@@ -570,6 +610,15 @@ int main(int argc, char *argv[])
                if (r == FALSE && !is_dir_exist(RC_DIR) && make_dir(RC_DIR) < 0)
                        exit(1);
        }
+       if (!is_file_exist(RC_DIR G_DIR_SEPARATOR_S COMMON_RC) &&
+           is_file_exist(RC_DIR G_DIR_SEPARATOR_S OLD_COMMON_RC)) {
+               /* post 2.6 name change */
+               migrate_common_rc(RC_DIR G_DIR_SEPARATOR_S OLD_COMMON_RC,
+                         RC_DIR G_DIR_SEPARATOR_S COMMON_RC);
+       }
+
+       if (!cmd.exit)
+               plugin_load_all("Common");
 
        userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
        gtk_rc_parse(userrc);
@@ -597,11 +646,11 @@ int main(int argc, char *argv[])
        remove_all_files(get_tmp_dir());
        remove_all_files(get_mime_tmp_dir());
 
-       if (is_file_exist("sylpheed.log")) {
-               if (rename_force("sylpheed.log", "sylpheed.log.bak") < 0)
-                       FILE_OP_ERROR("sylpheed.log", "rename");
+       if (is_file_exist("claws.log")) {
+               if (rename_force("claws.log", "claws.log.bak") < 0)
+                       FILE_OP_ERROR("claws.log", "rename");
        }
-       set_log_file("sylpheed.log");
+       set_log_file("claws.log");
 
        CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
 
@@ -680,7 +729,7 @@ int main(int argc, char *argv[])
                        exit(1);
                account_read_config_all();
                if(!account_get_list())
-                       exit_sylpheed(mainwin);
+                       exit_claws(mainwin);
        }
 
        
@@ -698,11 +747,11 @@ int main(int argc, char *argv[])
 
        prefs_matcher_read_config();
 
-       /* make one all-folder processing before using sylpheed */
+       /* make one all-folder processing before using claws */
        main_window_cursor_wait(mainwin);
        folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
 
-       /* if Sylpheed crashed, rebuild caches */
+       /* if claws crashed, rebuild caches */
        if (!cmd.crash && crash_file_present) {
                GTK_EVENTS_FLUSH();
                debug_print("Claws Mail crashed, checking for new messages in local folders\n");
@@ -736,7 +785,7 @@ int main(int argc, char *argv[])
                cmd.status_full_folders = NULL;
        }
 
-       sylpheed_register_idle_function(sylpheed_gtk_idle);
+       claws_register_idle_function(claws_gtk_idle);
 
        prefs_toolbar_init();
 
@@ -766,7 +815,8 @@ int main(int argc, char *argv[])
                                   "mailbox, but could not load it. It is "
                                   "probably provided by an out-of-date "
                                   "external plugin. Please reinstall the "
-                                  "plugin and try again."));
+                                  "plugin and try again.\nIt may also be "
+                                  "due to a failing IMAP account."));
                exit(1);
        }
        
@@ -816,7 +866,7 @@ int main(int argc, char *argv[])
        END_TIMING();
        gtk_main();
 
-       exit_sylpheed(mainwin);
+       exit_claws(mainwin);
 
        return 0;
 }
@@ -835,7 +885,7 @@ static void save_all_caches(FolderItem *item, gpointer data)
 
 static gboolean sc_exiting = FALSE;
 
-static void exit_sylpheed(MainWindow *mainwin)
+static void exit_claws(MainWindow *mainwin)
 {
        gchar *filename;
 
@@ -918,7 +968,7 @@ static void exit_sylpheed(MainWindow *mainwin)
        gtkaspell_checkers_quit();
 #endif
        plugin_unload_all("Common");
-       sylpheed_done();
+       claws_done();
 }
 
 static void parse_cmd_opt(int argc, char *argv[])
@@ -958,7 +1008,7 @@ static void parse_cmd_opt(int argc, char *argv[])
                                        cmd.attach_files = g_ptr_array_new();
                                }
                                if (*p != G_DIR_SEPARATOR) {
-                                       file = g_strconcat(sylpheed_get_startup_dir(),
+                                       file = g_strconcat(claws_get_startup_dir(),
                                                           G_DIR_SEPARATOR_S,
                                                           p, NULL);
                                } else {
@@ -1141,7 +1191,7 @@ gboolean clean_quit(gpointer data)
                
        draft_all_messages();
        emergency_exit = TRUE;
-       exit_sylpheed(static_mainwindow);
+       exit_claws(static_mainwindow);
        exit(0);
 
        return FALSE;
@@ -1191,7 +1241,7 @@ void app_will_exit(GtkWidget *widget, gpointer data)
        gtk_main_quit();
 }
 
-gboolean sylpheed_is_exiting(void)
+gboolean claws_is_exiting(void)
 {
        return sc_exiting;
 }