2007-02-21 [colin] 2.7.2cvs60
[claws.git] / src / main.c
index 613f5f0194294b69122c8a6e686834f58a04fa02..da489941957cb8df1a0278f3df8e3881b267c566 100644 (file)
@@ -158,9 +158,6 @@ static void lock_socket_input_cb    (gpointer          data,
                                         gint              source,
                                         GdkInputCondition condition);
 
-gchar *get_socket_name         (void);
-
-
 static void open_compose_new           (const gchar    *address,
                                         GPtrArray      *attach_files);
 
@@ -232,7 +229,7 @@ static void startup_notification_complete(gboolean with_window)
 }
 #endif /* HAVE_STARTUP_NOTIFICATION */
 
-void claws_gtk_idle(void) 
+static void claws_gtk_idle(void) 
 {
        while(gtk_events_pending()) {
                gtk_main_iteration();
@@ -240,7 +237,7 @@ void claws_gtk_idle(void)
        g_usleep(50000);
 }
 
-gboolean defer_check_all(void *data)
+static gboolean defer_check_all(void *data)
 {
        gboolean autochk = GPOINTER_TO_INT(data);
 
@@ -250,7 +247,7 @@ gboolean defer_check_all(void *data)
        return FALSE;
 }
 
-gboolean defer_check(void *data)
+static gboolean defer_check(void *data)
 {
        inc_mail(static_mainwindow, prefs_common.newmail_notify_manu);
 
@@ -764,8 +761,8 @@ int main(int argc, char *argv[])
        imap_gtk_init();
        news_gtk_init();
 
-       mainwin = main_window_create
-               (prefs_common.sep_folder | prefs_common.sep_msg << 1);
+       mainwin = main_window_create();
+
        manage_window_focus_in(mainwin->window, NULL, NULL);
        folderview = mainwin->folderview;
 
@@ -959,9 +956,11 @@ int main(int argc, char *argv[])
 
        prefs_destroy_cache();
        
+       compose_reopen_exit_drafts();
+
        sc_starting = FALSE;
        END_TIMING();
-       
+
        gtk_main();
 
        exit_claws(mainwin);
@@ -1008,6 +1007,7 @@ static void exit_claws(MainWindow *mainwin)
 
        main_window_get_size(mainwin);
        main_window_get_position(mainwin);
+
        prefs_common_write_config();
        account_write_config_all();
        addressbook_export_to_file();
@@ -1097,17 +1097,23 @@ static void parse_cmd_opt(int argc, char *argv[])
                        }
                } else if (!strncmp(argv[i], "--attach", 8)) {
                        const gchar *p = argv[i + 1];
-                       gchar *file;
+                       gchar *file = NULL;
 
                        while (p && *p != '\0' && *p != '-') {
                                if (!cmd.attach_files) {
                                        cmd.attach_files = g_ptr_array_new();
                                }
-                               if (*p != G_DIR_SEPARATOR) {
+                               if ((file = g_filename_from_uri(p, NULL, NULL)) != NULL) {
+                                       if (!is_file_exist(file)) {
+                                               g_free(file);
+                                               file = NULL;
+                                       }
+                               }
+                               if (file == NULL && *p != G_DIR_SEPARATOR) {
                                        file = g_strconcat(claws_get_startup_dir(),
                                                           G_DIR_SEPARATOR_S,
                                                           p, NULL);
-                               } else {
+                               } else if (file == NULL) {
                                        file = g_strdup(p);
                                }
                                g_ptr_array_add(cmd.attach_files, file);
@@ -1211,6 +1217,8 @@ static void parse_cmd_opt(int argc, char *argv[])
                                        cmd.subscribe = TRUE;
                                        cmd.subscribe_uri = p;
                                }
+                       } else if (!strcmp(argv[i], "--sync")) {
+                               /* gtk debug */
                        } else {
                                g_print(_("Unknown option\n"));
                                exit(1);
@@ -1224,19 +1232,6 @@ static void parse_cmd_opt(int argc, char *argv[])
        }
 }
 
-static gint get_queued_message_num(void)
-{
-       FolderItem *queue;
-
-       queue = folder_get_default_queue();
-       if (!queue) {
-               return -1;
-       }
-
-       folder_item_scan(queue);
-       return queue->total_msgs;
-}
-
 static void initial_processing(FolderItem *item, gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
@@ -1261,9 +1256,10 @@ static void draft_all_messages(void)
 {
        GList *compose_list = NULL;
        
+       compose_clear_exit_drafts();
        while ((compose_list = compose_get_compose_list()) != NULL) {
                Compose *c = (Compose*)compose_list->data;
-               compose_draft(c);
+               compose_draft(c, COMPOSE_DRAFT_FOR_EXIT);
        }       
 }
 gboolean clean_quit(gpointer data)
@@ -1310,27 +1306,15 @@ void app_will_exit(GtkWidget *widget, gpointer data)
        sc_exiting = TRUE;
        debug_print("exiting\n");
        if (compose_get_compose_list()) {
-               gint val = alertpanel(_("Really quit?"),
-                              _("Composing message exists."),
-                              _("_Save to Draft"), _("_Discard them"), _("Do_n't quit"));
-               switch (val) {
-                       case G_ALERTOTHER:
-                               sc_exiting = FALSE;
-                               return;
-                       case G_ALERTALTERNATE:
-                               break;
-                       default:
-                               draft_all_messages();
-               }
-
-               manage_window_focus_in(mainwin->window, NULL, NULL);
+               draft_all_messages();
        }
 
-       if (prefs_common.warn_queued_on_exit && get_queued_message_num() > 0) {
+       if (prefs_common.warn_queued_on_exit && procmsg_have_queued_mails_fast()) {
                if (alertpanel(_("Queued messages"),
                               _("Some unsent messages are queued. Exit now?"),
                               GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL)
                    != G_ALERTALTERNATE) {
+                       main_window_popup(mainwin);
                        sc_exiting = FALSE;
                        return;
                }
@@ -1338,6 +1322,7 @@ void app_will_exit(GtkWidget *widget, gpointer data)
        }
 
        sock_cleanup();
+       summary_clear_list(mainwin->summaryview);
        if (folderview_get_selected_item(mainwin->folderview))
                folder_item_close(folderview_get_selected_item(mainwin->folderview));
        gtk_main_quit();
@@ -1357,7 +1342,7 @@ gboolean claws_is_starting(void)
  * CLAWS: want this public so crash dialog can delete the
  * lock file too
  */
-gchar *get_socket_name(void)
+gchar *claws_get_socket_name(void)
 {
        static gchar *filename = NULL;
 
@@ -1391,7 +1376,7 @@ static gint prohibit_duplicate_launch(void)
        gint uxsock;
        gchar *path;
 
-       path = get_socket_name();
+       path = claws_get_socket_name();
        uxsock = fd_connect_unix(path);
        if (uxsock < 0) {
                g_unlink(path);
@@ -1498,7 +1483,7 @@ static gint lock_socket_remove(void)
                gdk_input_remove(lock_socket_tag);
        }
        fd_close(lock_socket);
-       filename = get_socket_name();
+       filename = claws_get_socket_name();
        g_unlink(filename);
 #endif