2006-07-05 [colin] 2.3.1cvs61
[claws.git] / src / compose.c
index adf85707705f44c7d63cf5e318874a4ca72cc5dd..2df9191b1d23dc762e7e1e9303395c81de097262 100644 (file)
@@ -325,7 +325,9 @@ static void compose_undo_state_changed              (UndoMain       *undostruct,
 static void compose_create_header_entry        (Compose *compose);
 static void compose_add_header_entry   (Compose *compose, gchar *header, gchar *text);
 static void compose_update_priority_menu_item(Compose * compose);
-
+#if USE_ASPELL
+static void compose_spell_menu_changed (void *data);
+#endif
 static void compose_add_field_list     ( Compose *compose,
                                          GList *listAddress );
 
@@ -958,6 +960,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
            compose->gtkaspell) 
                gtkaspell_change_dict(compose->gtkaspell, 
                    item->prefs->default_dictionary);
+       compose_spell_menu_changed(compose);
 #endif
 
        if (account->auto_sig)
@@ -1809,6 +1812,9 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                compose_destroy(compose);
                return NULL;
        }
+       
+       compose->sig_str = compose_get_signature_str(compose);
+       
        return compose;
 }
 
@@ -2680,7 +2686,9 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
        GtkTextMark *mark;
        GtkTextIter iter, iter_end;
        gint cur_pos;
+       gchar *search = NULL;
        gboolean prev_autowrap;
+       gboolean found = FALSE, shift = FALSE;
 
        
        g_return_if_fail(compose->account != NULL);
@@ -2698,8 +2706,9 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
 
        gtk_text_buffer_get_end_iter(buffer, &iter);
 
-       if (replace && compose->sig_str) {
-               gboolean found;
+       search = compose->sig_str;
+again:
+       if (replace && search) {
                GtkTextIter first_iter, start_iter, end_iter;
 
                gtk_text_buffer_get_start_iter(buffer, &first_iter);
@@ -2708,7 +2717,7 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
                        found = FALSE;
                else
                        found = gtk_text_iter_forward_search(&first_iter,
-                                                            compose->sig_str,
+                                                            search,
                                                             GTK_TEXT_SEARCH_TEXT_ONLY,
                                                             &start_iter, &end_iter,
                                                             NULL);
@@ -2717,6 +2726,12 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
                        gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
                        iter = start_iter;
                }
+       } 
+       if (replace && !found && search && strlen(search) > 2
+       &&  search[0] == '\n' && search[1] == '\n') {
+               search ++;
+               shift = TRUE;
+               goto again;
        }
 
        g_free(compose->sig_str);
@@ -2725,7 +2740,10 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
                compose->sig_str = g_strdup("");
 
        cur_pos = gtk_text_iter_get_offset(&iter);
-       gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
+       if (shift && found)
+               gtk_text_buffer_insert(buffer, &iter, compose->sig_str + 1, -1);
+       else
+               gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
        /* skip \n\n */
        gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
        gtk_text_iter_forward_char(&iter);
@@ -3502,6 +3520,7 @@ static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter,
                        {"http://",  strcasestr, get_uri_part,   make_uri_string},
                        {"https://", strcasestr, get_uri_part,   make_uri_string},
                        {"ftp://",   strcasestr, get_uri_part,   make_uri_string},
+                       {"sftp://",  strcasestr, get_uri_part,   make_uri_string},
                        {"www.",     strcasestr, get_uri_part,   make_http_string},
                        {"mailto:",  strcasestr, get_uri_part,   make_uri_string},
                        {"@",        strcasestr, get_email_part, make_email_string}
@@ -3878,8 +3897,11 @@ static void compose_select_account(Compose *compose, PrefsAccount *account,
                                       
        activate_privacy_system(compose, account, FALSE);
 
-       if (!init && compose->mode != COMPOSE_REDIRECT)
+       if (!init && compose->mode != COMPOSE_REDIRECT) {
+               undo_block(compose->undostruct);
                compose_insert_sig(compose, TRUE);
+               undo_unblock(compose->undostruct);
+       }
 }
 
 gboolean compose_check_for_valid_recipient(Compose *compose) {
@@ -4056,6 +4078,7 @@ gint compose_send(Compose *compose)
                        alertpanel_error(_("Could not queue message for sending:\n\n"
                                           "Charset conversion failed."));
                } else if (val == -3) {
+                       if (privacy_peek_error())
                        alertpanel_error(_("Could not queue message for sending:\n\n"
                                           "Signature failed: %s"), privacy_get_error());
                } else if (val == -2 && errno != 0) {
@@ -6158,7 +6181,7 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
        g_return_val_if_fail(accounts != NULL, NULL);
 
        optmenubox = gtk_event_box_new();
-       optmenu = gtkut_sc_combobox_create(optmenubox);
+       optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
        menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
 
        hbox = gtk_hbox_new(FALSE, 6);
@@ -6972,7 +6995,7 @@ static void compose_attach_property_create(gboolean *cancelled)
        gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
                         GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       optmenu = gtkut_sc_combobox_create(NULL);
+       optmenu = gtkut_sc_combobox_create(NULL, TRUE);
        optmenu_menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
 
        COMBOBOX_ADD(optmenu_menu, "7bit", ENC_7BIT);
@@ -7516,6 +7539,7 @@ static void compose_send_later_cb(gpointer data, guint action,
        } else if (val == -2) {
                alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
        } else if (val == -3) {
+               if (privacy_peek_error())
                alertpanel_error(_("Could not queue message for sending:\n\n"
                                   "Signature failed: %s"), privacy_get_error());
        } else if (val == -4) {
@@ -8501,48 +8525,47 @@ static void compose_insert_drag_received_cb (GtkWidget          *widget,
 {
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
-       AlertValue val = G_ALERTDEFAULT;
-
-       switch (prefs_common.compose_dnd_mode) {
-               case COMPOSE_DND_ASK:
-                       val = alertpanel_full(_("Insert or attach?"),
-                                _("Do you want to insert the contents of the file(s) "
-                                  "into the message body, or attach it to the email?"),
-                                 GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
-                                 TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
-                       break;
-               case COMPOSE_DND_INSERT:
-                       val = G_ALERTALTERNATE;
-                       break;
-               case COMPOSE_DND_ATTACH:
-                       val = G_ALERTOTHER;
-                       break;
-               default:
-                       /* unexpected case */
-                       g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
-       }
-
-       if (val & G_ALERTDISABLE) {
-               val &= ~G_ALERTDISABLE;
-               /* remember what action to perform by default, only if we don't click Cancel */
-               if (val == G_ALERTALTERNATE)
-                       prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
-               else
-                       if (val == G_ALERTOTHER)
-                               prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
-       }
-       
-       if (val == G_ALERTDEFAULT) {
-               gtk_drag_finish(drag_context, FALSE, FALSE, time);
-               return;
-       } else if (val == G_ALERTOTHER) {
-               compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
-               return;
-       } 
 
        /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
         * does not work */
        if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
+               AlertValue val = G_ALERTDEFAULT;
+
+               switch (prefs_common.compose_dnd_mode) {
+                       case COMPOSE_DND_ASK:
+                               val = alertpanel_full(_("Insert or attach?"),
+                                        _("Do you want to insert the contents of the file(s) "
+                                          "into the message body, or attach it to the email?"),
+                                         GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
+                                         TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
+                               break;
+                       case COMPOSE_DND_INSERT:
+                               val = G_ALERTALTERNATE;
+                               break;
+                       case COMPOSE_DND_ATTACH:
+                               val = G_ALERTOTHER;
+                               break;
+                       default:
+                               /* unexpected case */
+                               g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
+               }
+
+               if (val & G_ALERTDISABLE) {
+                       val &= ~G_ALERTDISABLE;
+                       /* remember what action to perform by default, only if we don't click Cancel */
+                       if (val == G_ALERTALTERNATE)
+                               prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
+                       else if (val == G_ALERTOTHER)
+                                       prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
+               }
+
+               if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
+                       gtk_drag_finish(drag_context, FALSE, FALSE, time);
+                       return;
+               } else if (val == G_ALERTOTHER) {
+                       compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
+                       return;
+               } 
                list = uri_list_extract_filenames((const gchar *)data->data);
                for (tmp = list; tmp != NULL; tmp = tmp->next) {
                        compose_insert_file(compose, (const gchar *)tmp->data);