2005-10-26 [colin] 1.9.15cvs111
[claws.git] / src / main.c
index 9d0b93e23172c7cc04fc486d78f414c0d7f7e67a..bae9fdbb695f78e938b031ab29f5c21a69852e43 100644 (file)
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -219,6 +219,8 @@ static void startup_notification_complete(gboolean with_window)
                sn_launchee_context_unref(sn_context);
                sn_display_unref(sn_display);
        }
+       if (with_window)
+               gtk_widget_destroy(hack);
 }
 #endif /* HAVE_STARTUP_NOTIFICATION */
 
@@ -226,6 +228,47 @@ void sylpheed_gtk_idle(void)
 {
        while(gtk_events_pending())
                gtk_main_iteration();
+       usleep(50000);
+}
+
+gboolean defer_check_all(void *data)
+{
+       gboolean autochk = GPOINTER_TO_INT(data);
+
+       inc_all_account_mail(static_mainwindow, autochk, 
+                       prefs_common.newmail_notify_manu);
+
+       return FALSE;
+}
+
+gboolean defer_check(void *data)
+{
+       inc_mail(static_mainwindow, prefs_common.newmail_notify_manu);
+
+       return FALSE;
+}
+
+static gboolean migrate_old_config(const gchar *old_cfg_dir, const gchar *new_cfg_dir)
+{
+       gchar *message = g_strdup_printf(_("Configuration for Sylpheed-Claws %s found.\n"
+                        "Do you want to migrate this configuration?"),
+                        !strcmp(old_cfg_dir, OLD_GTK1_RC_DIR)?
+                               _("1.0.5 or previous"):_("1.9.15 or previous"));
+       gint r = 0;
+       GtkWidget *window = NULL;
+       if (alertpanel(_("Migration of configuration"),
+                      message,
+                      GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
+               return FALSE;
+       
+       window = label_window_create(_("Copying configuration..."));
+       GTK_EVENTS_FLUSH();
+       r = copy_dir(old_cfg_dir, new_cfg_dir);
+       gtk_widget_destroy(window);
+       if (r != 0) {
+               alertpanel_error(_("Migration failed!"));
+       }
+       return (r == 0);
 }
 
 int main(int argc, char *argv[])
@@ -298,6 +341,18 @@ int main(int argc, char *argv[])
                             G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
        gtk_rc_parse(userrc);
        g_free(userrc);
+
+       CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
+       if (!is_dir_exist(RC_DIR)) {
+               gboolean r = FALSE;
+               if (is_dir_exist(OLD_GTK2_RC_DIR))
+                       r = migrate_old_config(OLD_GTK2_RC_DIR, RC_DIR);
+               else if (is_dir_exist(OLD_GTK1_RC_DIR))
+                       r = migrate_old_config(OLD_GTK1_RC_DIR, RC_DIR);
+               if (r == FALSE && !is_dir_exist(RC_DIR) && make_dir(RC_DIR) < 0)
+                       exit(1);
+       }
+
        userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
        gtk_rc_parse(userrc);
        g_free(userrc);
@@ -310,10 +365,6 @@ int main(int argc, char *argv[])
                                       "gtk-can-change-accels",
                                       (glong)TRUE, "XProperty");
 
-       CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
-
-       MAKE_DIR_IF_NOT_EXIST(RC_DIR);
-
        CHDIR_RETURN_VAL_IF_FAIL(get_rc_dir(), 1);
 
        MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
@@ -372,6 +423,7 @@ int main(int argc, char *argv[])
        gtk_window_set_default_icon(icon);
 
        folderview_initialize();
+
        mh_gtk_init();
        imap_gtk_init();
        news_gtk_init();
@@ -380,6 +432,9 @@ int main(int argc, char *argv[])
                (prefs_common.sep_folder | prefs_common.sep_msg << 1);
        folderview = mainwin->folderview;
 
+       gtk_clist_freeze(GTK_CLIST(mainwin->folderview->ctree));
+       folder_item_update_freeze();
+
        /* register the callback of unix domain socket input */
 #ifdef G_OS_UNIX
        lock_socket_tag = gdk_input_add(lock_socket,
@@ -405,6 +460,8 @@ int main(int argc, char *argv[])
                        exit_sylpheed(mainwin);
        }
 
+       gtk_window_deiconify(mainwin->window);
+
 #ifdef HAVE_LIBETPAN
        imap_main_init();
 #endif 
@@ -417,13 +474,14 @@ int main(int argc, char *argv[])
        /* make one all-folder processing before using sylpheed */
        main_window_cursor_wait(mainwin);
        folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
-       main_window_cursor_normal(mainwin);
 
        /* if Sylpheed crashed, rebuild caches */
        if (!cmd.crash && crash_file_present) {
                debug_print("Sylpheed crashed, checking for new messages in local folders\n");
+               folder_item_update_thaw();
                folderview_check_new(NULL);
                folder_clean_cache_memory_force();
+               folder_item_update_freeze();
        }
        /* make the crash-indicator file */
        str_write_to_file("foo", get_crashfile_name());
@@ -437,9 +495,9 @@ int main(int argc, char *argv[])
        signal(SIGPIPE, SIG_IGN);
 #endif
        if (cmd.online_mode == ONLINE_MODE_OFFLINE)
-               main_window_toggle_work_offline(mainwin, TRUE);
+               main_window_toggle_work_offline(mainwin, TRUE, FALSE);
        if (cmd.online_mode == ONLINE_MODE_ONLINE)
-               main_window_toggle_work_offline(mainwin, FALSE);
+               main_window_toggle_work_offline(mainwin, FALSE, FALSE);
 
        if (cmd.status_folders) {
                g_ptr_array_free(cmd.status_folders, TRUE);
@@ -461,15 +519,16 @@ int main(int argc, char *argv[])
 #ifdef HAVE_STARTUP_NOTIFICATION
        startup_notification_complete(FALSE);
 #endif
+       folder_item_update_thaw();
+       gtk_clist_thaw(GTK_CLIST(mainwin->folderview->ctree));
+       main_window_cursor_normal(mainwin);
 
        if (cmd.receive_all)
-               inc_all_account_mail(mainwin, FALSE, 
-                                    prefs_common.newmail_notify_manu);
+               g_timeout_add(1000, defer_check_all, GINT_TO_POINTER(FALSE));
        else if (prefs_common.chk_on_startup)
-               inc_all_account_mail(mainwin, TRUE, 
-                                    prefs_common.newmail_notify_manu);
+               g_timeout_add(1000, defer_check_all, GINT_TO_POINTER(TRUE));
        else if (cmd.receive)
-               inc_mail(mainwin, prefs_common.newmail_notify_manu);
+               g_timeout_add(1000, defer_check, NULL);
        else
                gtk_widget_grab_focus(folderview->ctree);
 
@@ -763,11 +822,11 @@ gboolean clean_quit(gpointer data)
 void app_will_exit(GtkWidget *widget, gpointer data)
 {
        MainWindow *mainwin = data;
-       
+
        if (compose_get_compose_list()) {
                gint val = alertpanel(_("Really quit?"),
                               _("Composing message exists."),
-                              _("Draft them"), _("Discard them"), _("Don't quit"));
+                              _("_Save to Draft"), _("_Discard them"), _("Do_n't quit"));
                switch (val) {
                        case G_ALERTOTHER:
                                return;
@@ -776,7 +835,7 @@ void app_will_exit(GtkWidget *widget, gpointer data)
                        default:
                                draft_all_messages();
                }
-               
+
                manage_window_focus_in(mainwin->window, NULL, NULL);
        }
 
@@ -806,7 +865,7 @@ gchar *get_socket_name(void)
        static gchar *filename = NULL;
 
        if (filename == NULL) {
-               filename = g_strdup_printf("%s%csylpheed-%d",
+               filename = g_strdup_printf("%s%csylpheed-claws-%d",
                                           g_get_tmp_dir(), G_DIR_SEPARATOR,
 #if HAVE_GETUID
                                           getuid());
@@ -993,9 +1052,9 @@ static void lock_socket_input_cb(gpointer data,
        } else if (!strncmp(buf, "send", 4)) {
                send_queue();
        } else if (!strncmp(buf, "online", 6)) {
-               main_window_toggle_work_offline(mainwin, FALSE);
+               main_window_toggle_work_offline(mainwin, FALSE, FALSE);
        } else if (!strncmp(buf, "offline", 7)) {
-               main_window_toggle_work_offline(mainwin, TRUE);
+               main_window_toggle_work_offline(mainwin, TRUE, FALSE);
        } else if (!strncmp(buf, "status-full", 11) ||
                   !strncmp(buf, "status", 6)) {
                gchar *status;