2006-02-12 [colin] 2.0.0cvs45
[claws.git] / src / main.c
index 0869b66d22616ace0e0ea6bfdc89b6ea914d50cb..324a9d6c2f89d922bdd4f3b8c229235054ea340b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -139,6 +139,8 @@ static struct RemoteCmd {
        int online_mode;
        gchar   *crash_params;
        gboolean exit;
+       gboolean subscribe;
+       const gchar *subscribe_uri;
 } cmd;
 
 static void parse_cmd_opt(int argc, char *argv[]);
@@ -229,7 +231,7 @@ void sylpheed_gtk_idle(void)
 {
        while(gtk_events_pending())
                gtk_main_iteration();
-       usleep(50000);
+       g_usleep(50000);
 }
 
 gboolean defer_check_all(void *data)
@@ -259,7 +261,7 @@ static gboolean migrate_old_config(const gchar *old_cfg_dir, const gchar *new_cf
        GtkWidget *window = NULL;
        if (alertpanel(_("Migration of configuration"),
                       message,
-                      GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
+                      GTK_STOCK_NO, GTK_STOCK_YES, NULL) != G_ALERTALTERNATE)
                return FALSE;
        
        window = label_window_create(_("Copying configuration..."));
@@ -319,6 +321,9 @@ int main(int argc, char *argv[])
                lock_socket_remove();
                return 0;
        }
+       
+       if (cmd.exit)
+               return 0;
 #endif
        g_thread_init(NULL);
        /* gdk_threads_init(); */
@@ -368,6 +373,7 @@ int main(int argc, char *argv[])
 
        CHDIR_RETURN_VAL_IF_FAIL(get_rc_dir(), 1);
 
+       MAKE_DIR_IF_NOT_EXIST(get_mail_base_dir());
        MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
        MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
        MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
@@ -515,6 +521,15 @@ int main(int argc, char *argv[])
 
        plugin_load_all("GTK2");
        
+       if (!folder_have_mailbox()) {
+               alertpanel_error(_("Sylpheed-Claws has detected a configured "
+                                  "mailbox, but could not load it. It is "
+                                  "probably provided by an out-of-date "
+                                  "external plugin. Please reinstall the "
+                                  "plugin and try again."));
+               exit(1);
+       }
+       
        static_mainwindow = mainwin;
 
 #ifdef HAVE_STARTUP_NOTIFICATION
@@ -540,6 +555,9 @@ int main(int argc, char *argv[])
                g_ptr_array_free(cmd.attach_files, TRUE);
                cmd.attach_files = NULL;
        }
+       if (cmd.subscribe)
+               folder_subscribe(cmd.subscribe_uri);
+
        if (cmd.send)
                send_queue();
        
@@ -605,7 +623,7 @@ static void exit_sylpheed(MainWindow *mainwin)
 
        lock_socket_remove();
 
-       main_window_destroy(mainwin);
+       main_window_destroy_all();
        
        plugin_unload_all("GTK2");
 
@@ -656,6 +674,12 @@ static void parse_cmd_opt(int argc, char *argv[])
                                        cmd.compose_mailto = p;
                                i++;
                        }
+               } else if (!strncmp(argv[i], "--subscribe", 11)) {
+                       const gchar *p = argv[i + 1];
+                       if (p && *p != '\0' && *p != '-') {
+                               cmd.subscribe = TRUE;
+                               cmd.subscribe_uri = p;
+                       }
                } else if (!strncmp(argv[i], "--attach", 8)) {
                        const gchar *p = argv[i + 1];
                        gchar *file;
@@ -712,6 +736,7 @@ static void parse_cmd_opt(int argc, char *argv[])
                        g_print(_("Usage: %s [OPTION]...\n"), base);
 
                        g_print("%s\n", _("  --compose [address]    open composition window"));
+                       g_print("%s\n", _("  --subscribe [uri]      subscribe to the given URI if possible"));
                        g_print("%s\n", _("  --attach file1 [file2]...\n"
                                  "                         open composition window with specified files\n"
                                  "                         attached"));
@@ -740,6 +765,26 @@ static void parse_cmd_opt(int argc, char *argv[])
                        exit(0);
                } else if (!strncmp(argv[i], "--exit", 6)) {
                        cmd.exit = TRUE;
+               } else if (i == 1 && argc == 2) {
+                       /* only one parameter. Do something intelligent about it */
+                       if (strstr(argv[i], "@") && !strstr(argv[i], "://")) {
+                               const gchar *p = argv[i];
+
+                               cmd.compose = TRUE;
+                               cmd.compose_mailto = NULL;
+                               if (p && *p != '\0' && *p != '-') {
+                                       if (!strncmp(p, "mailto:", 7))
+                                               cmd.compose_mailto = p + 7;
+                                       else
+                                               cmd.compose_mailto = p;
+                               }
+                       } else if (strstr(argv[i], "://")) {
+                               const gchar *p = argv[i];
+                               if (p && *p != '\0' && *p != '-') {
+                                       cmd.subscribe = TRUE;
+                                       cmd.subscribe_uri = p;
+                               }
+                       }
                }
                
        }
@@ -846,8 +891,8 @@ void app_will_exit(GtkWidget *widget, gpointer data)
        if (prefs_common.warn_queued_on_exit && get_queued_message_num() > 0) {
                if (alertpanel(_("Queued messages"),
                               _("Some unsent messages are queued. Exit now?"),
-                              GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL)
-                   != G_ALERTDEFAULT)
+                              GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL)
+                   != G_ALERTALTERNATE)
                        return;
                manage_window_focus_in(mainwin->window, NULL, NULL);
        }
@@ -944,6 +989,10 @@ static gint prohibit_duplicate_launch(void)
 
                fd_write_all(uxsock, compose_str, strlen(compose_str));
                g_free(compose_str);
+       } else if (cmd.subscribe) {
+               gchar *str = g_strdup_printf("subscribe %s\n", cmd.subscribe_uri);
+               fd_write_all(uxsock, str, strlen(str));
+               g_free(str);
        } else if (cmd.send) {
                fd_write_all(uxsock, "send\n", 5);
        } else if (cmd.online_mode == ONLINE_MODE_ONLINE) {
@@ -1055,6 +1104,9 @@ static void lock_socket_input_cb(gpointer data,
                g_free(mailto);
        } else if (!strncmp(buf, "compose", 7)) {
                open_compose_new(buf + strlen("compose") + 1, NULL);
+       } else if (!strncmp(buf, "subscribe", 9)) {
+               main_window_popup(mainwin);
+               folder_subscribe(buf + strlen("subscribe") + 1);
        } else if (!strncmp(buf, "send", 4)) {
                send_queue();
        } else if (!strncmp(buf, "online", 6)) {
@@ -1120,6 +1172,7 @@ static void quit_signal_handler(int sig)
 
 static void install_basic_sighandlers()
 {
+#ifndef G_OS_WIN32
        sigset_t    mask;
        struct sigaction act;
 
@@ -1150,4 +1203,5 @@ static void install_basic_sighandlers()
 #endif 
 
        sigprocmask(SIG_UNBLOCK, &mask, 0);
+#endif /* !G_OS_WIN32 */
 }