Silent up a compiler warning by making the ComposeCallAdvancedAction
[claws.git] / src / compose.c
index 21274bb5c0e7308fd669a3850b3e72810876fc9c..024bfca3f0383d94ce99e321ef36b6ef2cf8a092 100644 (file)
@@ -122,7 +122,8 @@ enum
 
 typedef enum
 {
-       COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
+       COMPOSE_CALL_ADVANCED_ACTION_UNDEFINED = -1,
+       COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE = 0,
        COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
        COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
        COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
@@ -183,6 +184,20 @@ typedef enum {
 #define COMPOSE_DRAFT_TIMEOUT_UNSET -1
 #define COMPOSE_DRAFT_TIMEOUT_FORBIDDEN -2
 
+static GdkColor default_header_bgcolor = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor default_header_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
 static GList *compose_list = NULL;
 static GSList *extra_headers = NULL;
 
@@ -197,7 +212,7 @@ static Compose *compose_create                      (PrefsAccount   *account,
                                                 ComposeMode     mode,
                                                 gboolean batch);
 
-static void compose_entry_mark_default_to      (Compose          *compose,
+static void compose_entry_indicate     (Compose          *compose,
                                         const gchar      *address);
 static Compose *compose_followup_and_reply_to  (MsgInfo        *msginfo,
                                         ComposeQuoteMode        quote_mode,
@@ -555,7 +570,7 @@ static void compose_check_backwards    (GtkAction *action, gpointer data);
 static void compose_check_forwards_go     (GtkAction *action, gpointer data);
 #endif
 
-static PrefsAccount *compose_guess_forward_account_from_msginfo        (MsgInfo *msginfo);
+static PrefsAccount *compose_find_account      (MsgInfo *msginfo);
 
 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose);
 
@@ -1756,9 +1771,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
        cm_return_val_if_fail(msginfo != NULL, NULL);
        cm_return_val_if_fail(msginfo->folder != NULL, NULL);
 
-       if (!account && 
-           !(account = compose_guess_forward_account_from_msginfo
-                               (msginfo)))
+       if (!account && !(account = compose_find_account(msginfo)))
                account = cur_account;
 
        if (!prefs_common.forward_as_attachment)
@@ -1962,8 +1975,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
 
        /* guess account from first selected message */
        if (!account && 
-           !(account = compose_guess_forward_account_from_msginfo
-                               (msginfo_list->data)))
+           !(account = compose_find_account(msginfo_list->data)))
                account = cur_account;
 
        cm_return_val_if_fail(account != NULL, NULL);
@@ -2643,6 +2655,7 @@ void compose_entry_append(Compose *compose, const gchar *address,
                        while (*tmp == ' ' || *tmp == '\t')
                                tmp++;
                        compose_add_header_entry(compose, header, tmp, pref_type);
+                       compose_entry_indicate(compose, tmp);
                        g_free(o_tmp);
                        continue;
                }
@@ -2655,50 +2668,26 @@ void compose_entry_append(Compose *compose, const gchar *address,
                while (*tmp == ' ' || *tmp == '\t')
                        tmp++;
                compose_add_header_entry(compose, header, tmp, pref_type);
+               compose_entry_indicate(compose, tmp);
                g_free(o_tmp);          
        }
 }
 
-static void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
+static void compose_entry_indicate(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_header_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_header_color);
                }
        }
 }
@@ -2714,7 +2703,7 @@ void compose_toolbar_cb(gint action, gpointer data)
        case A_SEND:
                compose_send_cb(NULL, compose);
                break;
-       case A_SENDL:
+       case A_SEND_LATER:
                compose_send_later_cb(NULL, compose);
                break;
        case A_DRAFT:
@@ -3246,17 +3235,23 @@ static void compose_set_folder_prefs(Compose *compose, FolderItem *folder,
        if (respect_default_to && folder->prefs->enable_default_to) {
                compose_entry_append(compose, folder->prefs->default_to,
                                        COMPOSE_TO, PREF_FOLDER);
-               compose_entry_mark_default_to(compose, folder->prefs->default_to);
+               compose_entry_indicate(compose, folder->prefs->default_to);
        }
-       if (folder->prefs->enable_default_cc)
+       if (folder->prefs->enable_default_cc) {
                compose_entry_append(compose, folder->prefs->default_cc,
                                        COMPOSE_CC, PREF_FOLDER);
-       if (folder->prefs->enable_default_bcc)
+               compose_entry_indicate(compose, folder->prefs->default_cc);
+       }
+       if (folder->prefs->enable_default_bcc) {
                compose_entry_append(compose, folder->prefs->default_bcc,
                                        COMPOSE_BCC, PREF_FOLDER);
-       if (folder->prefs->enable_default_replyto)
+               compose_entry_indicate(compose, folder->prefs->default_bcc);
+       }
+       if (folder->prefs->enable_default_replyto) {
                compose_entry_append(compose, folder->prefs->default_replyto,
                                        COMPOSE_REPLYTO, PREF_FOLDER);
+               compose_entry_indicate(compose, folder->prefs->default_replyto);
+       }
 }
 
 static void compose_reply_set_subject(Compose *compose, MsgInfo *msginfo)
@@ -3335,7 +3330,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                        compose_entry_append(compose,
                            msginfo->folder->prefs->default_reply_to,
                            COMPOSE_TO, PREF_FOLDER);
-                       compose_entry_mark_default_to(compose,
+                       compose_entry_indicate(compose,
                                msginfo->folder->prefs->default_reply_to);
                } else {
                        gchar *tmp1 = NULL;
@@ -5038,12 +5033,16 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                }
                if (!found_other) {
                        AlertValue aval;
+                       gchar *text;
                        if (compose->batch) {
                                gtk_widget_show_all(compose->window);
                        }
+                       text = g_strdup_printf(_("The only recipient is the default '%s' address. Send anyway?"),
+                                          prefs_common_translated_header_name("Cc"));
                        aval = alertpanel(_("Send"),
-                                         _("The only recipient is the default CC address. Send anyway?"),
+                                         text,
                                          GTK_STOCK_CANCEL, g_strconcat("+", _("_Send"), NULL), NULL);
+                       g_free(text);
                        if (aval != G_ALERTALTERNATE)
                                return FALSE;
                }
@@ -5070,12 +5069,16 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                }
                if (!found_other) {
                        AlertValue aval;
+                       gchar *text;
                        if (compose->batch) {
                                gtk_widget_show_all(compose->window);
                        }
+                       text = g_strdup_printf(_("The only recipient is the default '%s' address. Send anyway?"),
+                                          prefs_common_translated_header_name("Bcc"));
                        aval = alertpanel(_("Send"),
-                                         _("The only recipient is the default BCC address. Send anyway?"),
+                                         text,
                                          GTK_STOCK_CANCEL, g_strconcat("+", _("_Send"), NULL), NULL);
+                       g_free(text);
                        if (aval != G_ALERTALTERNATE)
                                return FALSE;
                }
@@ -7509,6 +7512,11 @@ static Compose *compose_create(PrefsAccount *account,
 
        cm_return_val_if_fail(account != NULL, NULL);
 
+       gtkut_convert_int_to_gdk_color(prefs_common.default_header_bgcolor,
+                                          &default_header_bgcolor);
+       gtkut_convert_int_to_gdk_color(prefs_common.default_header_color,
+                                          &default_header_color);
+
        debug_print("Creating compose window...\n");
        compose = g_new0(Compose, 1);
 
@@ -8155,6 +8163,14 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
                                                       ac->address);
                                gtk_entry_set_text(GTK_ENTRY(from_name), from);
                        }
+                       if (cur_account != compose->account) {
+                               gtk_widget_modify_base(
+                                       GTK_WIDGET(from_name),
+                                       GTK_STATE_NORMAL, &default_header_bgcolor);
+                               gtk_widget_modify_text(
+                                       GTK_WIDGET(from_name),
+                                       GTK_STATE_NORMAL, &default_header_color);
+                       }
                }
                COMBOBOX_ADD(menu, name, ac->account_id);
                g_free(name);
@@ -8646,6 +8662,20 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
 #endif
 }
 
+static void compose_template_apply_fields_error(const gchar *header)
+{
+       gchar *tr;
+       gchar *text;
+
+       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);
+
+       g_free(text);
+       g_free(tr);
+}
+
 static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 {
        MsgInfo* dummyinfo = NULL;
@@ -8673,7 +8703,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
                buf = quote_fmt_get_buffer();
                if (buf == NULL) {
-                       alertpanel_error(_("Template From format error."));
+                       compose_template_apply_fields_error("From");
                } else {
                        gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
                }
@@ -8691,7 +8721,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
                buf = quote_fmt_get_buffer();
                if (buf == NULL) {
-                       alertpanel_error(_("Template To format error."));
+                       compose_template_apply_fields_error("To");
                } else {
                        compose_entry_append(compose, buf, COMPOSE_TO, PREF_TEMPLATE);
                }
@@ -8709,7 +8739,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
                buf = quote_fmt_get_buffer();
                if (buf == NULL) {
-                       alertpanel_error(_("Template Cc format error."));
+                       compose_template_apply_fields_error("Cc");
                } else {
                        compose_entry_append(compose, buf, COMPOSE_CC, PREF_TEMPLATE);
                }
@@ -8727,7 +8757,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
                buf = quote_fmt_get_buffer();
                if (buf == NULL) {
-                       alertpanel_error(_("Template Bcc format error."));
+                       compose_template_apply_fields_error("Bcc");
                } else {
                        compose_entry_append(compose, buf, COMPOSE_BCC, PREF_TEMPLATE);
                }
@@ -8745,7 +8775,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
                buf = quote_fmt_get_buffer();
                if (buf == NULL) {
-                       alertpanel_error(_("Template Reply-To format error."));
+                       compose_template_apply_fields_error("Reply-To");
                } else {
                        compose_entry_append(compose, buf, COMPOSE_REPLYTO, PREF_TEMPLATE);
                }
@@ -8764,7 +8794,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
                buf = quote_fmt_get_buffer();
                if (buf == NULL) {
-                       alertpanel_error(_("Template subject format error."));
+                       compose_template_apply_fields_error("Subject");
                } else {
                        gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
                }
@@ -9364,6 +9394,14 @@ static void compose_exec_ext_editor(Compose *compose)
 #endif /* G_OS_UNIX */
 }
 
+static gboolean compose_can_autosave(Compose *compose)
+{
+       if (compose->privacy_system && compose->use_encryption)
+               return prefs_common.autosave && prefs_common.autosave_encrypted;
+       else
+               return prefs_common.autosave;
+}
+
 #ifdef G_OS_UNIX
 static gboolean compose_get_ext_editor_cmd_valid()
 {
@@ -9514,7 +9552,10 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
                gtk_text_buffer_set_text(buffer, "", -1);
                compose_insert_file(compose, compose->exteditor_file);
                compose_changed_cb(NULL, compose);
-               compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
+
+               /* Check if we should save the draft or not */
+               if (compose_can_autosave(compose))
+                 compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
 
                if (claws_unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
@@ -9744,13 +9785,6 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
        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
 
        /* Get ID of active account in the combo box */
        menu = gtk_combo_box_get_model(optmenu);
@@ -9770,26 +9804,12 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
                                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);
@@ -9804,29 +9824,25 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
                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) 
+               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_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->header);
                        g_free(state->entry);
                        g_free(state);
                }
                g_slist_free(saved_list);
-               
+
                combobox_select_by_data(GTK_COMBO_BOX(compose->header_last->combo),
                                        (ac->protocol == A_NNTP) ? 
                                        COMPOSE_NEWSGROUPS : COMPOSE_TO);
@@ -10400,14 +10416,6 @@ void compose_close_toolbar(Compose *compose)
        compose_close_cb(NULL, compose);
 }
 
-static gboolean compose_can_autosave(Compose *compose)
-{
-       if (compose->privacy_system && compose->use_encryption)
-               return prefs_common.autosave && prefs_common.autosave_encrypted;
-       else
-               return prefs_common.autosave;
-}
-
 static void compose_close_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
@@ -11052,14 +11060,14 @@ static ComposeCallAdvancedAction compose_call_advanced_action_from_path(GtkActio
        DO_ACTION("Edit/Advanced/DelForwWord", COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD);
        DO_ACTION("Edit/Advanced/DelLine", COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE);
        DO_ACTION("Edit/Advanced/DelEndLine", COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END);
-       return -1;
+       return COMPOSE_CALL_ADVANCED_ACTION_UNDEFINED;
 }
 
 static void compose_advanced_action_cb(GtkAction *gaction, gpointer data)
 {
        Compose *compose = (Compose *)data;
        GtkTextView *text = GTK_TEXT_VIEW(compose->text);
-       ComposeCallAdvancedAction action = -1;
+       ComposeCallAdvancedAction action = COMPOSE_CALL_ADVANCED_ACTION_UNDEFINED;
        
        action = compose_call_advanced_action_from_path(gaction);
 
@@ -11737,7 +11745,7 @@ static void compose_check_forwards_go(GtkAction *action, gpointer data)
  *\brief       Guess originating forward account from MsgInfo and several 
  *             "common preference" settings. Return NULL if no guess. 
  */
-static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
+static PrefsAccount *compose_find_account(MsgInfo *msginfo)
 {
        PrefsAccount *account = NULL;