2005-11-08 [wwp] 1.9.100cvs1
[claws.git] / src / main.c
index 4986c27dfcf4e777a47f1ede1d711e0b175c76f6..3b35b587e46a0fb3f89c4c1aa0db45df900ee531 100644 (file)
@@ -138,6 +138,7 @@ static struct RemoteCmd {
        gboolean crash;
        int online_mode;
        gchar   *crash_params;
+       gboolean exit;
 } cmd;
 
 static void parse_cmd_opt(int argc, char *argv[]);
@@ -219,6 +220,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 */
 
@@ -246,6 +249,29 @@ gboolean defer_check(void *data)
        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[])
 {
        gchar *userrc;
@@ -316,6 +342,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);
@@ -328,10 +366,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());
@@ -427,6 +461,8 @@ int main(int argc, char *argv[])
                        exit_sylpheed(mainwin);
        }
 
+       gtk_window_deiconify(GTK_WINDOW(mainwin->window));
+
 #ifdef HAVE_LIBETPAN
        imap_main_init();
 #endif 
@@ -640,7 +676,7 @@ static void parse_cmd_opt(int argc, char *argv[])
                } else if (!strncmp(argv[i], "--send", 6)) {
                        cmd.send = TRUE;
                } else if (!strncmp(argv[i], "--version", 9)) {
-                       puts("Sylpheed version " VERSION);
+                       puts("Sylpheed-Claws version " VERSION);
                        exit(0);
                } else if (!strncmp(argv[i], "--status-full", 13)) {
                        const gchar *p = argv[i + 1];
@@ -687,6 +723,7 @@ static void parse_cmd_opt(int argc, char *argv[])
                               "                         show the status of each folder"));
                        g_print("%s\n", _("  --online               switch to online mode"));
                        g_print("%s\n", _("  --offline              switch to offline mode"));
+                       g_print("%s\n", _("  --exit                 exit Sylpheed-Claws"));
                        g_print("%s\n", _("  --debug                debug mode"));
                        g_print("%s\n", _("  --help                 display this help and exit"));
                        g_print("%s\n", _("  --version              output version information and exit"));
@@ -701,6 +738,8 @@ static void parse_cmd_opt(int argc, char *argv[])
                } else if (!strncmp(argv[i], "--config-dir", sizeof "--config-dir" - 1)) {
                        puts(RC_DIR);
                        exit(0);
+               } else if (!strncmp(argv[i], "--exit", 6)) {
+                       cmd.exit = TRUE;
                }
                
        }
@@ -934,6 +973,8 @@ static gint prohibit_duplicate_launch(void)
                        if (!strncmp(buf, ".\n", 2)) break;
                        fputs(buf, stdout);
                }
+       } else if (cmd.exit) {
+               fd_write_all(uxsock, "exit\n", 5);
        } else
                fd_write_all(uxsock, "popup\n", 6);
 
@@ -1032,6 +1073,8 @@ static void lock_socket_input_cb(gpointer data,
                fd_write_all(sock, ".\n", 2);
                g_free(status);
                if (folders) g_ptr_array_free(folders, TRUE);
+       } else if (!strncmp(buf, "exit", 4)) {
+               app_will_exit(NULL, mainwin);
        }
 
        fd_close(sock);