Fix initialization of privacy buttons sensitivity
[claws.git] / src / compose.c
index 7cd07298759170f68e329eae8b82b26ea3a634f0..d17a16d854162c82446e2fef0c360358220b0742 100644 (file)
@@ -490,8 +490,6 @@ static void compose_update_privacy_system_menu_item(Compose * compose, gboolean
 static void activate_privacy_system     (Compose *compose, 
                                          PrefsAccount *account,
                                         gboolean warn);
-static void compose_use_signing(Compose *compose, gboolean use_signing);
-static void compose_use_encryption(Compose *compose, gboolean use_encryption);
 static void compose_toggle_return_receipt_cb(GtkToggleAction *action,
                                         gpointer        data);
 static void compose_toggle_remove_refs_cb(GtkToggleAction *action,
@@ -1321,6 +1319,7 @@ static void compose_force_encryption(Compose *compose, PrefsAccount *account,
                if (privacy_avail && g_slist_length(privacy_avail)) {
                        privacy = (gchar *)(privacy_avail->data);
                }
+               g_slist_free_full(privacy_avail, g_free);
        }
        if (privacy != NULL) {
                if (system) {
@@ -2756,6 +2755,10 @@ void compose_toolbar_cb(gint action, gpointer data)
                compose_check_all(NULL, compose);
                break;
 #endif
+       case A_PRIVACY_SIGN:
+               break;
+       case A_PRIVACY_ENCRYPT:
+               break;
        default:
                break;
        }
@@ -2981,7 +2984,9 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                if (msginfo->inreplyto && *msginfo->inreplyto)
                        compose->inreplyto = g_strdup(msginfo->inreplyto);
 
-               if (msginfo->msgid && *msginfo->msgid)
+               if (msginfo->msgid && *msginfo->msgid &&
+                               compose->folder != NULL &&
+                               compose->folder->stype ==  F_DRAFT)
                        compose->msgid = g_strdup(msginfo->msgid);
        } else {
                if (msginfo->msgid && *msginfo->msgid)
@@ -3868,13 +3873,13 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
        return TRUE;
 }
 
-static void compose_use_signing(Compose *compose, gboolean use_signing)
+void compose_use_signing(Compose *compose, gboolean use_signing)
 {
        compose->use_signing = use_signing;
        cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Sign", use_signing);
 }
 
-static void compose_use_encryption(Compose *compose, gboolean use_encryption)
+void compose_use_encryption(Compose *compose, gboolean use_encryption)
 {
        compose->use_encryption = use_encryption;
        cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Encrypt", use_encryption);
@@ -4082,10 +4087,22 @@ static int compose_itemized_length(GtkTextBuffer *buffer,
        }
 
        clen = g_unichar_to_utf8(wc, ch);
-       if (clen != 1)
-               return 0;
-
-       if (!strchr("*-+", ch[0]))
+       if (!((clen == 1 && strchr("*-+", ch[0])) ||
+           (clen == 3 && (
+               wc == 0x2022 || /* BULLET */
+               wc == 0x2023 || /* TRIANGULAR BULLET */
+               wc == 0x2043 || /* HYPHEN BULLET */
+               wc == 0x204c || /* BLACK LEFTWARDS BULLET */
+               wc == 0x204d || /* BLACK RIGHTWARDS BULLET */
+               wc == 0x2219 || /* BULLET OPERATOR */
+               wc == 0x25d8 || /* INVERSE BULLET */
+               wc == 0x25e6 || /* WHITE BULLET */
+               wc == 0x2619 || /* REVERSED ROTATED FLORAL HEART BULLET */
+               wc == 0x2765 || /* ROTATED HEAVY BLACK HEART BULLET */
+               wc == 0x2767 || /* ROTATED FLORAL HEART BULLET */
+               wc == 0x29be || /* CIRCLED WHITE BULLET */
+               wc == 0x29bf    /* CIRCLED BULLET */
+               ))))
                return 0;
 
        gtk_text_iter_forward_char(&iter);
@@ -5461,7 +5478,7 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
                get_rfc822_date_hide_tz(date, sizeof(date));
        else
                get_rfc822_date(date, sizeof(date));
-       err |= (fprintf(fp, "Resent-Date: %s\n", buf) < 0);
+       err |= (fprintf(fp, "Resent-Date: %s\n", date) < 0);
 
        /* Resent-From */
        if (compose->account->name && *compose->account->name) {
@@ -5611,7 +5628,7 @@ error:
 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gboolean attach_parts)
 {
        GtkTextBuffer *buffer;
-       GtkTextIter start, end;
+       GtkTextIter start, end, tmp;
        gchar *chars, *tmp_enc_file, *content;
        gchar *buf, *msg;
        const gchar *out_codeset;
@@ -5643,10 +5660,20 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
        mimemsg->data.mem = compose_get_header(compose);
 
        /* Create text part MimeInfo */
-       /* get all composed text */
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
-       gtk_text_buffer_get_start_iter(buffer, &start);
        gtk_text_buffer_get_end_iter(buffer, &end);
+       tmp = end;
+
+       /* We make sure that there is a newline at the end. */
+       if (action == COMPOSE_WRITE_FOR_SEND && gtk_text_iter_backward_char(&tmp)) {
+               chars = gtk_text_buffer_get_text(buffer, &tmp, &end, FALSE);
+               if (*chars != '\n') {
+                       gtk_text_buffer_insert(buffer, &end, "\n", 1);
+               }
+       }
+
+       /* get all composed text */
+       gtk_text_buffer_get_start_iter(buffer, &start);
        chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
 
        out_codeset = conv_get_charset_str(compose->out_encoding);
@@ -6423,8 +6450,7 @@ static const gchar *compose_untranslated_header_name(gchar *header_name)
 {
        /* return the untranslated header name, if header_name is a known
           header name, in either its translated or untranslated form, with
-          or without trailing colon. return NULL if no matching header name
-          is found or if header_name is NULL. */
+          or without trailing colon. otherwise, returns header_name. */
        gchar *translated_header_name;
        gchar *translated_header_name_wcolon;
        const gchar *untranslated_header_name;
@@ -6451,7 +6477,7 @@ static const gchar *compose_untranslated_header_name(gchar *header_name)
                }
        }
        debug_print("compose_untranslated_header_name: unknown header '%s'\n", header_name);
-       return NULL;
+       return header_name;
 }
 
 static void compose_add_headerfield_from_headerlist(Compose *compose, 
@@ -8446,6 +8472,10 @@ static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
 
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/Sign", can_sign);
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/Encrypt", can_encrypt);
+       gtk_widget_set_sensitive(compose->toolbar->privacy_sign_btn, can_sign);
+       gtk_widget_set_sensitive(compose->toolbar->privacy_encrypt_btn, can_encrypt);
+       gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(compose->toolbar->privacy_sign_btn), can_sign ? compose->use_signing : FALSE);
+       gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(compose->toolbar->privacy_encrypt_btn), can_encrypt ? compose->use_encryption : FALSE);
 }
 
 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
@@ -8502,8 +8532,18 @@ static void compose_update_privacy_system_menu_item(Compose * compose, gboolean
 
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/Sign", can_sign);
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/Encrypt", can_encrypt);
-}      
+       if (compose->toolbar->privacy_sign_btn != NULL) {
+               gtk_widget_set_sensitive(
+                       GTK_WIDGET(compose->toolbar->privacy_sign_btn),
+                       can_sign);
+       }
+       if (compose->toolbar->privacy_encrypt_btn != NULL) {
+               gtk_widget_set_sensitive(
+                       GTK_WIDGET(compose->toolbar->privacy_encrypt_btn),
+                       can_encrypt);
+       }
+}
+
 static void compose_set_out_encoding(Compose *compose)
 {
        CharSet out_encoding;
@@ -8793,7 +8833,7 @@ static void compose_template_apply_fields_error(const gchar *header)
        tr = g_strdup(C_("'%s' stands for a header name",
                                  "Template '%s' format error."));
        text = g_strdup_printf(tr, prefs_common_translated_header_name(header));
-       alertpanel_error(text);
+       alertpanel_error("%s", text);
 
        g_free(text);
        g_free(tr);
@@ -11362,6 +11402,7 @@ static void compose_toggle_sign_cb(GtkToggleAction *action, gpointer data)
        Compose *compose = (Compose *)data;
 
        compose->use_signing = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+       gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(compose->toolbar->privacy_sign_btn), compose->use_signing);
 }
 
 static void compose_toggle_encrypt_cb(GtkToggleAction *action, gpointer data)
@@ -11369,6 +11410,7 @@ static void compose_toggle_encrypt_cb(GtkToggleAction *action, gpointer data)
        Compose *compose = (Compose *)data;
 
        compose->use_encryption = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+       gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(compose->toolbar->privacy_encrypt_btn), compose->use_encryption);
 }
 
 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)