2005-09-18 [colin] 1.9.14cvs39
[claws.git] / src / compose.c
index 344c1f9a659f043fd6ffe609cf4366990f4513d7..92530ce5f723d92a09a04336e852c4645ebde746 100644 (file)
@@ -785,8 +785,6 @@ static GdkColor uri_color = {
        (gushort)0
 };
 
-static GtkTextTag *no_wrap_tag = NULL;
-
 static void compose_create_tags(GtkTextView *text, Compose *compose)
 {
        GtkTextBuffer *buffer;
@@ -815,7 +813,7 @@ static void compose_create_tags(GtkTextView *text, Compose *compose)
        gtk_text_buffer_create_tag(buffer, "link",
                                         "foreground-gdk", &uri_color,
                                         NULL);
-       no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
+       compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
 }
 
 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
@@ -2078,7 +2076,19 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
                lastp = strchr(p, '\n');
                len = lastp ? lastp - p + 1 : -1;
 
-               gtk_text_buffer_insert(buffer, &iter, p, len);
+               if (g_utf8_validate(p, -1, NULL)) { 
+                       gtk_text_buffer_insert(buffer, &iter, p, len);
+               } else {
+                       gchar *tmpin = g_strdup(p);
+                       gchar *tmpout = NULL;
+                       tmpin[len] = '\0';
+                       tmpout = conv_codeset_strdup
+                               (tmpin, conv_get_locale_charset_str(),
+                                CS_INTERNAL);
+                       gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
+                       g_free(tmpin);
+                       g_free(tmpout);
+               }
 
                if (lastp)
                        p = lastp + 1;
@@ -3088,7 +3098,7 @@ static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter,
                gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
                gint walk_pos;
                
-               if (gtk_text_iter_has_tag(&iter, no_wrap_tag) && !force)
+               if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
                        goto colorize;
 
                uri_start = uri_stop = -1;
@@ -4063,14 +4073,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);
                }
        }
@@ -4353,6 +4370,7 @@ static gchar *compose_get_header(Compose *compose)
 
        /* Subject */
        str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
+
        if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
                g_strstrip(str);
                if (*str != '\0') {
@@ -4533,6 +4551,12 @@ static void compose_convert_header(Compose *compose, gchar *dest, gint len, gcha
        subst_char(tmpstr, '\r', ' ');
        g_strchomp(tmpstr);
 
+       if (!g_utf8_validate(tmpstr, -1, NULL)) {
+               gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
+               conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
+               g_free(tmpstr);
+               tmpstr = mybuf;
+       }
        conv_encode_header_full(dest, len, tmpstr, header_len, addr_field, 
                conv_get_charset_str(compose->out_encoding));
        g_free(tmpstr);
@@ -4839,13 +4863,45 @@ static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
 
 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
                                  GdkAtom clip);
+
+#define BLOCK_WRAP() {                                                 \
+       prev_autowrap = compose->autowrap;                              \
+       buffer = gtk_text_view_get_buffer(                              \
+                                       GTK_TEXT_VIEW(compose->text));  \
+       compose->autowrap = FALSE;                                      \
+                                                                       \
+       g_signal_handlers_block_by_func(G_OBJECT(buffer),               \
+                               G_CALLBACK(compose_changed_cb),         \
+                               compose);                               \
+       g_signal_handlers_block_by_func(G_OBJECT(buffer),               \
+                               G_CALLBACK(text_inserted),              \
+                               compose);                               \
+}
+#define UNBLOCK_WRAP() {                                               \
+       compose->autowrap = prev_autowrap;                              \
+       if (compose->autowrap)                                          \
+               compose_wrap_all(compose);                              \
+                                                                       \
+       g_signal_handlers_unblock_by_func(G_OBJECT(buffer),             \
+                               G_CALLBACK(compose_changed_cb),         \
+                               compose);                               \
+       g_signal_handlers_unblock_by_func(G_OBJECT(buffer),             \
+                               G_CALLBACK(text_inserted),              \
+                               compose);                               \
+}
+
+
 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
                                        Compose *compose)
 {
+       gint prev_autowrap;
+       GtkTextBuffer *buffer;
        if (event->button == 2) {
+               BLOCK_WRAP();
                entry_paste_clipboard(compose, compose->focused_editable, 
                                prefs_common.linewrap_pastes,
                                GDK_SELECTION_PRIMARY);
+               UNBLOCK_WRAP();
                return TRUE;
        }
        return FALSE;
@@ -4917,6 +4973,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                geometry.max_width = gdk_screen_width();
                geometry.max_height = gdk_screen_height();
        }
+
        gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
                                      &geometry, GDK_HINT_MAX_SIZE);
        if (!geometry.min_width) {
@@ -6413,10 +6470,26 @@ static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
                                      gpointer data)
 {
        Compose *compose = (Compose *)data;
-
+       GtkTreeSelection *attach_selection;
+       gint attach_nr_selected;
+       GtkItemFactory *ifactory;
+       
        if (!event) return FALSE;
 
        if (event->button == 3) {
+               attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
+               attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
+               ifactory = gtk_item_factory_from_widget(compose->popupmenu);
+                       
+               if (attach_nr_selected > 0)
+               {
+                       menu_set_sensitive(ifactory, "/Remove", TRUE);
+                       menu_set_sensitive(ifactory, "/Properties...", TRUE);
+               } else {
+                       menu_set_sensitive(ifactory, "/Remove", FALSE);
+                       menu_set_sensitive(ifactory, "/Properties...", FALSE);
+               }
+                       
                gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
                               NULL, NULL, event->button, event->time);
                return TRUE;                           
@@ -6884,32 +6957,6 @@ static void compose_copy_cb(Compose *compose)
                entry_copy_clipboard(compose->focused_editable);
 }
 
-#define BLOCK_WRAP() {                                                 \
-       prev_autowrap = compose->autowrap;                              \
-       buffer = gtk_text_view_get_buffer(                              \
-                                       GTK_TEXT_VIEW(compose->text));  \
-       compose->autowrap = FALSE;                                      \
-                                                                       \
-       g_signal_handlers_block_by_func(G_OBJECT(buffer),               \
-                               G_CALLBACK(compose_changed_cb),         \
-                               compose);                               \
-       g_signal_handlers_block_by_func(G_OBJECT(buffer),               \
-                               G_CALLBACK(text_inserted),              \
-                               compose);                               \
-}
-#define UNBLOCK_WRAP() {                                               \
-       compose->autowrap = prev_autowrap;                              \
-       if (compose->autowrap)                                          \
-               compose_wrap_all(compose);                              \
-                                                                       \
-       g_signal_handlers_unblock_by_func(G_OBJECT(buffer),             \
-                               G_CALLBACK(compose_changed_cb),         \
-                               compose);                               \
-       g_signal_handlers_unblock_by_func(G_OBJECT(buffer),             \
-                               G_CALLBACK(text_inserted),              \
-                               compose);                               \
-}
-
 static void compose_paste_cb(Compose *compose)
 {
        gint prev_autowrap;
@@ -7270,6 +7317,28 @@ static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
                gtk_editable_set_position(GTK_EDITABLE(widget), 
                        strlen(str));
                g_free(str);
+               if (widget->parent && widget->parent->parent
+                && widget->parent->parent->parent) {
+                       if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
+                               gint y = widget->allocation.y;
+                               gint height = widget->allocation.height;
+                               GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
+                                       (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
+
+                               if (y < (int)shown->value) {
+                                       gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
+                               }
+                               if (y + height > (int)shown->value + (int)shown->page_size) {
+                                       if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
+                                               gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), 
+                                                       y + height - (int)shown->page_size - 1);
+                                       } else {
+                                               gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), 
+                                                       (int)shown->upper - (int)shown->page_size - 1);
+                                       }
+                               }
+                       }
+               }
        }
 
        if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))