2005-09-10 [colin] 1.9.14cvs17
[claws.git] / src / compose.c
index 51d50ed2a6933aaa89d88861dda693a3574ac15b..ccad422effce7c4ba8d55af97626f0f160de6053 100644 (file)
@@ -1525,6 +1525,7 @@ void compose_reedit(MsgInfo *msginfo)
                        strcrchomp(buf);
                        gtk_text_buffer_insert(textbuf, &iter, buf, -1);
                }
+               compose_wrap_all_full(compose, FALSE);
                compose->autowrap = prev_autowrap;
                fclose(fp);
        }
@@ -1705,7 +1706,6 @@ void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
                    !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
                        gtk_widget_ensure_style(GTK_WIDGET(entry));
                        if (!bold_style) {
-                               PangoFontDescription *font_desc = NULL;
                                gtkut_convert_int_to_gdk_color
                                        (prefs_common.color_new, &bold_color);
                                bold_style = gtk_style_copy(gtk_widget_get_style
@@ -3102,22 +3102,27 @@ static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter,
                                goto colorize;
                        }
                        debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
-                       startq_offset = gtk_text_iter_get_offset(&iter);
+                       if (startq_offset == -1) 
+                               startq_offset = gtk_text_iter_get_offset(&iter);
                } else {
                        if (startq_offset == -1)
                                noq_offset = gtk_text_iter_get_offset(&iter);
                }
 
-               if (prev_autowrap == FALSE && !force) {
+               if (prev_autowrap == FALSE && !force && !wrap_quote) {
                        goto colorize;
                }
                if (compose_get_line_break_pos(buffer, &iter, &break_pos,
                                               prefs_common.linewrap_len,
                                               quote_len)) {
                        GtkTextIter prev, next, cur;
-
-                       gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
                        
+                       if (prev_autowrap != FALSE || force)
+                               gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
+                       else if (quote_str && wrap_quote)
+                               gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
+                       else 
+                               goto colorize;
                        /* remove trailing spaces */
                        cur = break_pos;
                        gtk_text_iter_backward_char(&cur);
@@ -3800,7 +3805,8 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
        }
        
        /* check for line length limit */
-       if (encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
+       if (action == COMPOSE_WRITE_FOR_SEND &&
+           encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
            check_line_length(buf, 1000, &line) < 0) {
                AlertValue aval;
                gchar *msg;
@@ -3811,10 +3817,8 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
                           "\n"
                           "Send it anyway?"), line + 1);
                aval = alertpanel(_("Warning"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
+               g_free(msg);
                if (aval != G_ALERTDEFAULT) {
-                       g_free(msg);
-                       fclose(fp);
-                       g_free(buf);
                        return -1;
                }
        }
@@ -4059,14 +4063,21 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        if (compose->privacy_system != NULL) {
                fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
                fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
-               fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
                if (compose->use_encryption) {
                        gchar *encdata;
 
                        encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
-                       if (encdata != NULL)
-                               fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n", 
-                                       encdata);
+                       if (encdata != NULL) {
+                               if (strcmp(encdata, "_DONT_ENCRYPT_")) {
+                                       fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
+                                       fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n", 
+                                               encdata);
+                               } /* else we finally dont want to encrypt */
+                       } else {
+                               fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
+                               /* and if encdata was null, it means there's been a problem in 
+                                * key selection */
+                       }
                        g_free(encdata);
                }
        }
@@ -4833,6 +4844,20 @@ static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
        g_free(path);
 }
 
+static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
+                                 GdkAtom clip);
+static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
+                                       Compose *compose)
+{
+       if (event->button == 2) {
+               entry_paste_clipboard(compose, compose->focused_editable, 
+                               prefs_common.linewrap_pastes,
+                               GDK_SELECTION_PRIMARY);
+               return TRUE;
+       }
+       return FALSE;
+}
+
 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 {
        Compose   *compose;
@@ -5018,6 +5043,8 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                         G_CALLBACK(compose_grab_focus_cb), compose);
        g_signal_connect(G_OBJECT(buffer), "insert_text",
                         G_CALLBACK(text_inserted), compose);
+       g_signal_connect(G_OBJECT(text), "button_press_event",
+                        G_CALLBACK(text_clicked), compose);
 
        /* drag and drop */
        gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 
@@ -5541,7 +5568,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
        GtkTextIter iter;
        gchar *qmark;
        gchar *parsed_str;
-
+       gint cursor_pos = 0;
        if (!tmpl || !tmpl->value) return;
 
        text = GTK_TEXT_VIEW(compose->text);
@@ -5590,6 +5617,13 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
                gtk_text_buffer_get_start_iter(buffer, &iter);
                gtk_text_buffer_place_cursor(buffer, &iter);
        }
+       
+       if (parsed_str) {
+               cursor_pos = quote_fmt_get_cursor_pos();
+               gtk_text_buffer_get_start_iter(buffer, &iter);
+               gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
+               gtk_text_buffer_place_cursor(buffer, &iter);
+       }
 
        if (parsed_str)
                compose_changed_cb(NULL, compose);
@@ -6529,6 +6563,8 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
                g_unlink(tmp);
                g_free(tmp);
                lock = FALSE;
+               if (action != COMPOSE_AUTO_SAVE)
+                       alertpanel_error(_("Could not save draft."));
                return;
        }
        g_free(tmp);
@@ -6580,6 +6616,8 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
                if (action == COMPOSE_AUTO_SAVE) {
                        compose->autosaved_draft = compose->targetinfo;
                }
+               compose->modified = FALSE;
+               compose_set_title(compose);
        }
 }
 
@@ -6782,17 +6820,16 @@ static void entry_copy_clipboard(GtkWidget *entry)
                        gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
 }
 
-static void entry_paste_clipboard(GtkWidget *entry, gboolean wrap)
+static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, 
+                                 gboolean wrap, GdkAtom clip)
 {
-       if (GTK_IS_EDITABLE(entry))
-               gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
-       else if (GTK_IS_TEXT_VIEW(entry)) {
+       if (GTK_IS_TEXT_VIEW(entry)) {
                GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
                GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
                GtkTextIter start_iter, end_iter;
                gint start, end;
                
-               gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
+               gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
 
                if (contents == NULL)
                        return;
@@ -6809,9 +6846,16 @@ static void entry_paste_clipboard(GtkWidget *entry, gboolean wrap)
                        gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
                        gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
                        gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
+               } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
+                       mark_start = gtk_text_buffer_get_insert(buffer);
+                       gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
+                       gtk_text_iter_backward_char(&start_iter);
+                       compose_beautify_paragraph(compose, &start_iter, TRUE);
                }
                
-       }
+       } else if (GTK_IS_EDITABLE(entry))
+               gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
+       
 }
 
 static void entry_allsel(GtkWidget *entry)
@@ -6880,7 +6924,9 @@ static void compose_paste_cb(Compose *compose)
        BLOCK_WRAP();
        if (compose->focused_editable &&
            GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
-               entry_paste_clipboard(compose->focused_editable, prefs_common.linewrap_pastes);
+               entry_paste_clipboard(compose, compose->focused_editable, 
+                               prefs_common.linewrap_pastes,
+                               GDK_SELECTION_CLIPBOARD);
        UNBLOCK_WRAP();
 }
 
@@ -6900,7 +6946,9 @@ static void compose_paste_as_quote_cb(Compose *compose)
                                    "paste_as_quotation",
                                    GINT_TO_POINTER(paste_as_quotation + 1));
                prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
-               entry_paste_clipboard(compose->focused_editable, prefs_common.linewrap_pastes);
+               entry_paste_clipboard(compose, compose->focused_editable, 
+                               prefs_common.linewrap_pastes,
+                               GDK_SELECTION_CLIPBOARD);
                prefs_common.linewrap_quote = wrap_quote;
        }
 }
@@ -6912,7 +6960,8 @@ static void compose_paste_no_wrap_cb(Compose *compose)
        BLOCK_WRAP();
        if (compose->focused_editable &&
            GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
-               entry_paste_clipboard(compose->focused_editable, FALSE);
+               entry_paste_clipboard(compose, compose->focused_editable, FALSE,
+                       GDK_SELECTION_CLIPBOARD);
        UNBLOCK_WRAP();
 }
 
@@ -6923,7 +6972,8 @@ static void compose_paste_wrap_cb(Compose *compose)
        BLOCK_WRAP();
        if (compose->focused_editable &&
            GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
-               entry_paste_clipboard(compose->focused_editable, TRUE);
+               entry_paste_clipboard(compose, compose->focused_editable, TRUE,
+                       GDK_SELECTION_CLIPBOARD);
        UNBLOCK_WRAP();
 }