fix colouring of auto-filled headers
[claws.git] / src / compose.c
index afe00fc351c9fc931b5bd1a6d2b87572f530a12f..3e89d66513d4d717e256358622ce834266c441d3 100644 (file)
@@ -183,6 +183,20 @@ typedef enum {
 #define COMPOSE_DRAFT_TIMEOUT_UNSET -1
 #define COMPOSE_DRAFT_TIMEOUT_FORBIDDEN -2
 
+static GdkColor default_to_bgcolor = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor default_to_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
 static GList *compose_list = NULL;
 static GSList *extra_headers = NULL;
 
@@ -2661,44 +2675,19 @@ void compose_entry_append(Compose *compose, const gchar *address,
 
 static void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
 {
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       static GdkColor yellow;
-       static GdkColor black;
-       static gboolean yellow_initialised = FALSE;
-#else
-       static GdkColor yellow = { (guint32)0, (guint16)0xf5, (guint16)0xf6, (guint16)0xbe };
-       static GdkColor black = { (guint32)0, (guint16)0x0, (guint16)0x0, (guint16)0x0 };
-#endif
        GSList *h_list;
        GtkEntry *entry;
                
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       if (!yellow_initialised) {
-               gdk_color_parse("#f5f6be", &yellow);
-               gdk_color_parse("#000000", &black);
-               yellow_initialised = gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &yellow, FALSE, TRUE);
-               yellow_initialised &= gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &black, FALSE, TRUE);
-       }
-#endif
-
        for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
                entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
                if (gtk_entry_get_text(entry) && 
                    !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
-#if !GTK_CHECK_VERSION(3, 0, 0)
-                       if (yellow_initialised) {
-#endif
                                gtk_widget_modify_base(
                                        GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
-                                       GTK_STATE_NORMAL, &yellow);
+                                       GTK_STATE_NORMAL, &default_to_bgcolor);
                                gtk_widget_modify_text(
                                        GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
-                                       GTK_STATE_NORMAL, &black);
-#if !GTK_CHECK_VERSION(3, 0, 0)
-                       }
-#endif
+                                       GTK_STATE_NORMAL, &default_to_color);
                }
        }
 }
@@ -5671,8 +5660,12 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
            privacy_system_can_sign(compose->privacy_system)) {
                encoding = ENC_QUOTED_PRINTABLE;
        }
-       
+
+#ifdef G_OS_WIN32
+       debug_print("main text: %Id bytes encoded as %s in %d\n",
+#else
        debug_print("main text: %zd bytes encoded as %s in %d\n",
+#endif
                strlen(buf), out_codeset, encoding);
 
        /* check for line length limit */
@@ -8099,6 +8092,11 @@ static Compose *compose_create(PrefsAccount *account,
                gtk_widget_show(window);
        }
        
+       gtkut_convert_int_to_gdk_color(prefs_common.default_to_bgcolor,
+                                          &default_to_bgcolor);
+       gtkut_convert_int_to_gdk_color(prefs_common.default_to_color,
+                                          &default_to_color);
+
        return compose;
 }
 
@@ -9738,15 +9736,7 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
        gint account_id = 0;
        GtkTreeModel *menu;
        GtkTreeIter iter;
-       GSList *list, *saved_list = NULL;
-       HeaderEntryState *state;
-       GtkRcStyle *style = NULL;
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       static GdkColor yellow;
-       static gboolean color_set = FALSE;
-#else
-       static GdkColor yellow = { (guint32)0, (guint32)0xf5, (guint32)0xf6, (guint32)0xbe };
-#endif
+       GSList *list = NULL;
 
        /* Get ID of active account in the combo box */
        menu = gtk_combo_box_get_model(optmenu);
@@ -9762,33 +9752,8 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
                for (list = compose->header_list; list; list = list->next) {
                        ComposeHeaderEntry *hentry=(ComposeHeaderEntry *)list->data;
                        
-                       if (hentry->type == PREF_ACCOUNT || !list->next) {
+                       if (hentry->type == PREF_ACCOUNT || !list->next)
                                compose_destroy_headerentry(compose, hentry);
-                               continue;
-                       }
-                       
-                       state = g_malloc0(sizeof(HeaderEntryState));
-                       state->header = gtk_editable_get_chars(GTK_EDITABLE(
-                                       gtk_bin_get_child(GTK_BIN(hentry->combo))), 0, -1);
-                       state->entry = gtk_editable_get_chars(
-                                       GTK_EDITABLE(hentry->entry), 0, -1);
-                       state->type = hentry->type;
-                               
-#if !GTK_CHECK_VERSION(3, 0, 0)
-                       if (!color_set) {
-                               gdk_color_parse("#f5f6be", &yellow);
-                               color_set = gdk_colormap_alloc_color(
-                                                       gdk_colormap_get_system(),
-                                                       &yellow, FALSE, TRUE);
-                       }
-#endif
-                               
-                       style = gtk_widget_get_modifier_style(hentry->entry);
-                       state->entry_marked = gdk_color_equal(&yellow,
-                                               &style->base[GTK_STATE_NORMAL]);
-
-                       saved_list = g_slist_append(saved_list, state);
-                       compose_destroy_headerentry(compose, hentry);
                }
 
                compose->header_last = NULL;
@@ -9797,31 +9762,21 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
                compose->header_nextrow = 1;
                compose_create_header_entry(compose);
                
-               if (ac->set_autocc && ac->auto_cc)
+               if (ac->set_autocc && ac->auto_cc) {
                        compose_entry_append(compose, ac->auto_cc,
                                                COMPOSE_CC, PREF_ACCOUNT);
-
-               if (ac->set_autobcc && ac->auto_bcc) 
+                       compose_entry_mark_default_to(compose, ac->auto_cc);
+               }
+               if (ac->set_autobcc && ac->auto_bcc) {
                        compose_entry_append(compose, ac->auto_bcc,
                                                COMPOSE_BCC, PREF_ACCOUNT);
-       
-               if (ac->set_autoreplyto && ac->auto_replyto)
+                       compose_entry_mark_default_to(compose, ac->auto_bcc);
+               }
+               if (ac->set_autoreplyto && ac->auto_replyto) {
                        compose_entry_append(compose, ac->auto_replyto,
                                                COMPOSE_REPLYTO, PREF_ACCOUNT);
-               
-               for (list = saved_list; list; list = list->next) {
-                       state = (HeaderEntryState *) list->data;
-                       
-                       compose_add_header_entry(compose, state->header,
-                                               state->entry, state->type);
-                       if (state->entry_marked)
-                               compose_entry_mark_default_to(compose, state->entry);
-                       
-                       g_free(state->header);  
-                       g_free(state->entry);
-                       g_free(state);
+                       compose_entry_mark_default_to(compose, ac->auto_replyto);
                }
-               g_slist_free(saved_list);
                
                combobox_select_by_data(GTK_COMBO_BOX(compose->header_last->combo),
                                        (ac->protocol == A_NNTP) ? 
@@ -11347,6 +11302,8 @@ static void compose_insert_drag_received_cb (GtkWidget          *widget,
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
        GdkAtom type;
+       guint num_files;
+       gchar *msg;
 
        /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
         * does not work */
@@ -11356,6 +11313,7 @@ static void compose_insert_drag_received_cb (GtkWidget          *widget,
                const gchar* ddata = (const gchar *)gtk_selection_data_get_data(data);
 
                list = uri_list_extract_filenames(ddata);
+               num_files = g_list_length(list);
                if (list == NULL && strstr(ddata, "://")) {
                        /* Assume a list of no files, and data has ://, is a remote link */
                        gchar *tmpdata = g_strstrip(g_strdup(ddata));
@@ -11371,11 +11329,18 @@ static void compose_insert_drag_received_cb (GtkWidget                *widget,
                }
                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?"),
+                               msg = g_strdup_printf(
+                                               ngettext(
+                                                       "Do you want to insert the contents of the file "
+                                                       "into the message body, or attach it to the email?",
+                                                       "Do you want to insert the contents of the %d files "
+                                                       "into the message body, or attach them to the email?",
+                                                       num_files),
+                                               num_files);
+                               val = alertpanel_full(_("Insert or attach?"), msg,
                                          GTK_STOCK_CANCEL, g_strconcat("+", _("_Insert"), NULL), _("_Attach"),
                                          TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
+                               g_free(msg);
                                break;
                        case COMPOSE_DND_INSERT:
                                val = G_ALERTALTERNATE;
@@ -11734,9 +11699,6 @@ static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo
        if (msginfo->folder->prefs->enable_default_account)
                account = account_find_from_id(msginfo->folder->prefs->default_account);
                
-       if (!account) 
-               account = msginfo->folder->folder->account;
-               
        if (!account && msginfo->to && prefs_common.forward_account_autosel) {
                gchar *to;
                Xstrdup_a(to, msginfo->to, return NULL);
@@ -11763,6 +11725,9 @@ static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo
                        account = account_find_from_address(buf, FALSE);
                 }
        }
+
+       if (!account)
+               account = msginfo->folder->folder->account;
        
        return account;
 }