2007-02-23 [colin] 2.7.2cvs68
[claws.git] / src / compose.c
index 117e2655f7f4d97452ea4d3d94635673c89735ae..a3225687cf5ac9e0c47d368c5764c6bc7e0ac473 100644 (file)
@@ -171,13 +171,6 @@ typedef enum
        COMPOSE_INSERT_NO_FILE
 } ComposeInsertResult;
 
-typedef enum
-{
-       COMPOSE_QUIT_EDITING,
-       COMPOSE_KEEP_EDITING,
-       COMPOSE_AUTO_SAVE
-} ComposeDraftAction;
-
 typedef enum
 {
        COMPOSE_WRITE_FOR_SEND,
@@ -554,7 +547,7 @@ static GtkItemFactoryEntry compose_popup_entries[] =
 static GtkItemFactoryEntry compose_entries[] =
 {
        {N_("/_Message"),                               NULL, NULL, 0, "<Branch>"},
-       {N_("/_Message/_Send"),         "<control>Return",
+       {N_("/_Message/S_end"),         "<control>Return",
                                        compose_send_cb, 0, NULL},
        {N_("/_Message/Send _later"),   "<shift><control>S",
                                        compose_send_later_cb,  0, NULL},
@@ -3788,12 +3781,6 @@ static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter,
                quote_str = compose_get_quote_str(buffer, &iter, &quote_len);
 
                if (quote_str) {
-                       if (!wrap_quote) {
-                               if (startq_offset == -1) {
-                                       startq_offset = gtk_text_iter_get_offset(&iter);
-                               }
-                               goto colorize;
-                       }
                        debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
                        if (startq_offset == -1) 
                                startq_offset = gtk_text_iter_get_offset(&iter);
@@ -3805,6 +3792,9 @@ static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter,
                                else
                                        quotelevel = 2;
                        }
+                       if (!wrap_quote) {
+                               goto colorize;
+                       }
                } else {
                        if (startq_offset == -1)
                                noq_offset = gtk_text_iter_get_offset(&iter);
@@ -3922,6 +3912,7 @@ colorize:
                        gtk_text_buffer_get_iter_at_offset(
                                buffer, &startquote, startq_offset);
                        endquote = iter;
+
                        switch (quotelevel) {
                        case 0: gtk_text_buffer_apply_tag_by_name(
                                        buffer, "quote0", &startquote, &endquote);
@@ -6162,7 +6153,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
 
        compose->tooltips = gtk_tooltips_new();
 
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "compose");
        gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
        gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
 
@@ -7361,7 +7352,7 @@ static void compose_attach_property_create(gboolean *cancelled)
 
        debug_print("Creating attach_property window...\n");
 
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "compose_attach_property");
        gtk_widget_set_size_request(window, 480, -1);
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
        gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
@@ -7984,9 +7975,62 @@ static void compose_send_later_cb(gpointer data, guint action,
        toolbar_main_set_sensitive(mainwindow_get_mainwindow());
 }
 
-void compose_draft (gpointer data) 
+void compose_draft (gpointer data, guint action
 {
-       compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);     
+       compose_draft_cb(data, action, NULL);   
+}
+
+#define DRAFTED_AT_EXIT "drafted_at_exit"
+void compose_clear_exit_drafts(void)
+{
+       gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+                                     DRAFTED_AT_EXIT, NULL);
+       if (is_file_exist(filepath))
+               g_unlink(filepath);
+       
+       g_free(filepath);
+}
+
+static void compose_register_draft(MsgInfo *info)
+{
+       gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+                                     DRAFTED_AT_EXIT, NULL);
+       FILE *fp = fopen(filepath, "ab");
+       
+       if (fp) {
+               fprintf(fp, "%s\t%d\n", folder_item_get_identifier(info->folder), 
+                               info->msgnum);
+               fclose(fp);
+       }
+               
+       g_free(filepath);       
+}
+
+void compose_reopen_exit_drafts(void)
+{
+       gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+                                     DRAFTED_AT_EXIT, NULL);
+       FILE *fp = fopen(filepath, "rb");
+       gchar buf[1024];
+       
+       if (fp) {
+               while (fgets(buf, sizeof(buf), fp)) {
+                       gchar **parts = g_strsplit(buf, "\t", 2);
+                       const gchar *folder = parts[0];
+                       int msgnum = parts[1] ? atoi(parts[1]):-1;
+                       
+                       if (folder && *folder && msgnum > -1) {
+                               FolderItem *item = folder_find_item_from_identifier(folder);
+                               MsgInfo *info = folder_item_get_msginfo(item, msgnum);
+                               if (info)
+                                       compose_reedit(info, FALSE);
+                       }
+                       g_strfreev(parts);
+               }       
+               fclose(fp);
+       }       
+       g_free(filepath);
+       compose_clear_exit_drafts();
 }
 
 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
@@ -8109,12 +8153,15 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
                        procmsg_msginfo_set_flags(newmsginfo, 0,
                                                  MSG_HAS_ATTACHMENT);
 
+               if (action == COMPOSE_DRAFT_FOR_EXIT) {
+                       compose_register_draft(newmsginfo);
+               }
                procmsg_msginfo_free(newmsginfo);
        }
        
        folder_item_scan(draft);
        
-       if (action == COMPOSE_QUIT_EDITING) {
+       if (action == COMPOSE_QUIT_EDITING || action == COMPOSE_DRAFT_FOR_EXIT) {
                lock = FALSE;
                g_mutex_unlock(compose->mutex); /* must be done before closing */
                compose_close(compose);
@@ -8923,10 +8970,13 @@ static void compose_attach_drag_received_cb (GtkWidget          *widget,
            && gtk_drag_get_source_widget(context) != 
                summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
                list = uri_list_extract_filenames((const gchar *)data->data);
-               for (tmp = list; tmp != NULL; tmp = tmp->next)
+               for (tmp = list; tmp != NULL; tmp = tmp->next) {
+                       gchar *utf8_filename = conv_filename_to_utf8((const gchar *)tmp->data);
                        compose_attach_append
                                (compose, (const gchar *)tmp->data,
-                                (const gchar *)tmp->data, NULL);
+                                utf8_filename, NULL);
+                       g_free(utf8_filename);
+               }
                if (list) compose_changed_cb(NULL, compose);
                list_free_strings(list);
                g_list_free(list);