Fix CID 1491093: attrib leaked if attvalue is null
[claws.git] / src / prefs_compose_writing.c
blob740f73a313df8ef01f972ae77e87a33aadcea9e5
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2005-2024 the Claws Mail Team and Colin Leroy <colin@colino.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #include "claws-features.h"
22 #endif
24 #include "defs.h"
26 #include <stdio.h>
27 #include <stdlib.h>
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 #include <gdk/gdkkeysyms.h>
34 #include "prefs_common.h"
35 #include "prefs_gtk.h"
37 #include "gtk/gtkutils.h"
38 #include "gtk/prefswindow.h"
39 #include "gtk/menu.h"
41 #include "manage_window.h"
43 #include "quote_fmt.h"
44 #include "prefs_template.h"
45 #include "alertpanel.h"
46 #include "combobox.h"
48 typedef struct _WritingPage
50 PrefsPage page;
52 GtkWidget *window;
54 GtkWidget *checkbtn_autoextedit;
55 GtkWidget *checkbtn_reply_account_autosel;
56 GtkWidget *checkbtn_forward_account_autosel;
57 GtkWidget *checkbtn_reedit_account_autosel;
58 GtkWidget *spinbtn_undolevel;
59 GtkWidget *checkbtn_reply_with_quote;
60 GtkWidget *checkbtn_default_reply_list;
61 GtkWidget *checkbtn_forward_as_attachment;
62 GtkWidget *checkbtn_redirect_keep_from;
63 GtkWidget *checkbtn_autosave;
64 GtkWidget *spinbtn_autosave_length;
65 GtkWidget *checkbtn_autosave_encrypted;
66 GtkWidget *checkbtn_warn_large_insert;
67 GtkWidget *spinbtn_warn_large_insert_size;
68 GtkWidget *optmenu_dnd_insert_or_attach;
69 GtkWidget *checkbtn_warn_pasted_attachments;
70 } WritingPage;
72 static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *window,
73 gpointer data)
75 WritingPage *prefs_writing = (WritingPage *) _page;
77 GtkWidget *vbox1;
78 GtkWidget *vbox2;
79 GtkWidget *checkbtn_autoextedit;
80 GtkWidget *frame;
81 GtkWidget *hbox_autosel;
82 GtkWidget *checkbtn_reply_account_autosel;
83 GtkWidget *checkbtn_forward_account_autosel;
84 GtkWidget *checkbtn_reedit_account_autosel;
86 GtkWidget *hbox_undolevel;
87 GtkWidget *label_undolevel;
88 GtkAdjustment *spinbtn_undolevel_adj;
89 GtkWidget *spinbtn_undolevel;
91 GtkWidget *hbox_warn_large_insert;
92 GtkWidget *checkbtn_warn_large_insert;
93 GtkAdjustment *spinbtn_warn_large_insert_adj;
94 GtkWidget *spinbtn_warn_large_insert_size;
95 GtkWidget *label_warn_large_insert_size;
97 GtkWidget *checkbtn_reply_with_quote;
98 GtkWidget *checkbtn_default_reply_list;
100 GtkWidget *checkbtn_forward_as_attachment;
101 GtkWidget *checkbtn_redirect_keep_from;
103 GtkWidget *hbox_autosave;
104 GtkWidget *checkbtn_autosave;
105 GtkAdjustment *spinbtn_autosave_adj;
106 GtkWidget *spinbtn_autosave_length;
107 GtkWidget *label_autosave_length;
109 GtkWidget *hbox_autosave_encrypted;
110 GtkWidget *checkbtn_autosave_encrypted;
112 GtkWidget *hbox_dnd_insert_or_attach;
113 GtkWidget *label_dnd_insert_or_attach;
114 GtkWidget *optmenu_dnd_insert_or_attach;
115 GtkWidget *checkbtn_warn_pasted_attachments;
116 GtkListStore *menu;
117 GtkTreeIter iter;
118 gchar *text;
120 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
121 gtk_widget_show (vbox1);
122 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
124 /* Account autoselection */
125 PACK_FRAME(vbox1, frame, _("Automatic account selection"));
127 hbox_autosel = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, VSPACING_NARROW);
128 gtk_widget_show (hbox_autosel);
129 gtk_container_add (GTK_CONTAINER (frame), hbox_autosel);
130 gtk_container_set_border_width (GTK_CONTAINER (hbox_autosel), 8);
132 PACK_CHECK_BUTTON (hbox_autosel, checkbtn_reply_account_autosel,
133 _("when replying"));
134 PACK_CHECK_BUTTON (hbox_autosel, checkbtn_forward_account_autosel,
135 _("when forwarding"));
136 PACK_CHECK_BUTTON (hbox_autosel, checkbtn_reedit_account_autosel,
137 _("when re-editing"));
139 /* Editing */
140 vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Editing"));
142 /* Editing: automatically start the text editor */
143 PACK_CHECK_BUTTON (vbox2, checkbtn_autoextedit,
144 _("Automatically launch the external editor"));
146 /* Editing: automatically save draft */
147 hbox_autosave = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
148 gtk_widget_show (hbox_autosave);
149 gtk_box_pack_start (GTK_BOX (vbox2), hbox_autosave, FALSE, FALSE, 0);
151 PACK_CHECK_BUTTON (hbox_autosave, checkbtn_autosave,
152 _("Automatically save message to Drafts folder every"));
154 spinbtn_autosave_adj = GTK_ADJUSTMENT(gtk_adjustment_new (50, 0, 1000, 1, 10, 0));
155 spinbtn_autosave_length = gtk_spin_button_new
156 (GTK_ADJUSTMENT (spinbtn_autosave_adj), 1, 0);
157 gtk_widget_show (spinbtn_autosave_length);
158 gtk_box_pack_start (GTK_BOX (hbox_autosave), spinbtn_autosave_length, FALSE, FALSE, 0);
159 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_autosave_length), TRUE);
161 label_autosave_length = gtk_label_new(_("characters"));
162 gtk_widget_show (label_autosave_length);
163 gtk_box_pack_start (GTK_BOX (hbox_autosave), label_autosave_length, FALSE, FALSE, 0);
165 /* Editing: automatically save draft when encrypted */
166 hbox_autosave_encrypted = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
167 gtk_box_pack_start(GTK_BOX(hbox_autosave_encrypted), gtk_label_new(" "), FALSE, FALSE, 0);
168 gtk_widget_show_all (hbox_autosave_encrypted);
169 gtk_box_pack_start (GTK_BOX (vbox2), hbox_autosave_encrypted, FALSE, FALSE, 0);
171 PACK_CHECK_BUTTON (hbox_autosave_encrypted, checkbtn_autosave_encrypted,
172 _("Even if message is to be encrypted"));
174 /* Editing: undo level */
175 hbox_undolevel = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
176 gtk_widget_show (hbox_undolevel);
177 gtk_box_pack_start (GTK_BOX (vbox2), hbox_undolevel, FALSE, FALSE, 0);
179 label_undolevel = gtk_label_new (_("Undo level"));
180 gtk_widget_show (label_undolevel);
181 gtk_box_pack_start (GTK_BOX (hbox_undolevel), label_undolevel, FALSE, FALSE, 0);
183 spinbtn_undolevel_adj = GTK_ADJUSTMENT(gtk_adjustment_new (50, 0, 100, 1, 10, 0));
184 spinbtn_undolevel = gtk_spin_button_new
185 (GTK_ADJUSTMENT (spinbtn_undolevel_adj), 1, 0);
186 gtk_widget_show (spinbtn_undolevel);
187 gtk_box_pack_start (GTK_BOX (hbox_undolevel), spinbtn_undolevel, FALSE, FALSE, 0);
188 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_undolevel), TRUE);
190 /* Editing: warn when inserting large files in message body */
191 hbox_warn_large_insert = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
192 gtk_widget_show (hbox_warn_large_insert);
193 gtk_box_pack_start (GTK_BOX (vbox2), hbox_warn_large_insert, FALSE, FALSE, 0);
195 PACK_CHECK_BUTTON (hbox_warn_large_insert, checkbtn_warn_large_insert,
196 _("Warn when inserting a file into the message body which is larger than"));
198 spinbtn_warn_large_insert_adj = GTK_ADJUSTMENT(gtk_adjustment_new (50, 0, 10000, 1, 10, 0));
199 spinbtn_warn_large_insert_size = gtk_spin_button_new
200 (GTK_ADJUSTMENT (spinbtn_warn_large_insert_adj), 1, 0);
201 gtk_widget_show (spinbtn_warn_large_insert_size);
202 gtk_box_pack_start (GTK_BOX (hbox_warn_large_insert),
203 spinbtn_warn_large_insert_size, FALSE, FALSE, 0);
204 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_warn_large_insert_size),
205 TRUE);
207 label_warn_large_insert_size = gtk_label_new(_("KiB"));
208 gtk_widget_show (label_warn_large_insert_size);
209 gtk_box_pack_start (GTK_BOX (hbox_warn_large_insert),
210 label_warn_large_insert_size, FALSE, FALSE, 0);
212 /* Replying */
213 vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Replying"));
215 PACK_CHECK_BUTTON (vbox2, checkbtn_reply_with_quote,
216 _("Reply will quote by default"));
218 PACK_CHECK_BUTTON (vbox2, checkbtn_default_reply_list,
219 _("Reply button invokes mailing list reply"));
221 vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Forwarding"));
223 PACK_CHECK_BUTTON (vbox2, checkbtn_forward_as_attachment,
224 _("Forward as attachment"));
226 text = g_strdup_printf(_("Keep the original '%s' header when redirecting"),
227 prefs_common_translated_header_name("From"));
228 PACK_CHECK_BUTTON (vbox2, checkbtn_redirect_keep_from, text);
229 g_free(text);
231 /* dnd insert or attach */
232 label_dnd_insert_or_attach = gtk_label_new (_("When dropping files into the Compose window"));
233 gtk_label_set_xalign(GTK_LABEL(label_dnd_insert_or_attach), 0.0);
234 gtk_widget_show (label_dnd_insert_or_attach);
236 optmenu_dnd_insert_or_attach = gtkut_sc_combobox_create(NULL, FALSE);
237 gtk_widget_show (optmenu_dnd_insert_or_attach);
239 menu = GTK_LIST_STORE(gtk_combo_box_get_model(
240 GTK_COMBO_BOX(optmenu_dnd_insert_or_attach)));
241 COMBOBOX_ADD (menu, _("Ask"), COMPOSE_DND_ASK);
242 COMBOBOX_ADD (menu, _("Insert"), COMPOSE_DND_INSERT);
243 COMBOBOX_ADD (menu, _("Attach"), COMPOSE_DND_ATTACH);
245 hbox_dnd_insert_or_attach = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 20);
246 gtk_widget_show(hbox_dnd_insert_or_attach);
247 gtk_box_pack_start(GTK_BOX(vbox1), hbox_dnd_insert_or_attach, FALSE, FALSE, 0);
248 gtk_box_pack_start(GTK_BOX(hbox_dnd_insert_or_attach),
249 label_dnd_insert_or_attach, FALSE, FALSE, 0);
250 gtk_box_pack_start(GTK_BOX(hbox_dnd_insert_or_attach),
251 optmenu_dnd_insert_or_attach, FALSE, FALSE, 0);
253 PACK_CHECK_BUTTON(vbox1, checkbtn_warn_pasted_attachments, _("Warn when pasting files as attachments"));
255 SET_TOGGLE_SENSITIVITY (checkbtn_autosave, spinbtn_autosave_length);
256 SET_TOGGLE_SENSITIVITY (checkbtn_autosave, label_autosave_length);
257 SET_TOGGLE_SENSITIVITY (checkbtn_autosave, checkbtn_autosave_encrypted);
259 SET_TOGGLE_SENSITIVITY (checkbtn_warn_large_insert, spinbtn_warn_large_insert_size);
260 SET_TOGGLE_SENSITIVITY (checkbtn_warn_large_insert, label_warn_large_insert_size);
262 prefs_writing->checkbtn_autoextedit = checkbtn_autoextedit;
263 prefs_writing->checkbtn_reply_account_autosel = checkbtn_reply_account_autosel;
264 prefs_writing->checkbtn_forward_account_autosel = checkbtn_forward_account_autosel;
265 prefs_writing->checkbtn_reedit_account_autosel = checkbtn_reedit_account_autosel;
267 prefs_writing->spinbtn_undolevel = spinbtn_undolevel;
269 prefs_writing->checkbtn_autosave = checkbtn_autosave;
270 prefs_writing->spinbtn_autosave_length = spinbtn_autosave_length;
272 prefs_writing->checkbtn_autosave_encrypted = checkbtn_autosave_encrypted;
274 prefs_writing->checkbtn_warn_large_insert = checkbtn_warn_large_insert;
275 prefs_writing->spinbtn_warn_large_insert_size = spinbtn_warn_large_insert_size;
277 prefs_writing->checkbtn_forward_as_attachment =
278 checkbtn_forward_as_attachment;
279 prefs_writing->checkbtn_redirect_keep_from = checkbtn_redirect_keep_from;
280 prefs_writing->checkbtn_reply_with_quote = checkbtn_reply_with_quote;
281 prefs_writing->checkbtn_default_reply_list = checkbtn_default_reply_list;
283 prefs_writing->optmenu_dnd_insert_or_attach = optmenu_dnd_insert_or_attach;
284 prefs_writing->checkbtn_warn_pasted_attachments = checkbtn_warn_pasted_attachments;
286 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autoextedit),
287 prefs_common.auto_exteditor);
288 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_forward_as_attachment),
289 prefs_common.forward_as_attachment);
290 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_redirect_keep_from),
291 prefs_common.redirect_keep_from);
292 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autosave),
293 prefs_common.autosave);
294 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autosave_encrypted),
295 prefs_common.autosave_encrypted);
296 gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_autosave_length),
297 prefs_common.autosave_length);
298 gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_undolevel),
299 prefs_common.undolevels);
300 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_warn_large_insert),
301 prefs_common.warn_large_insert);
302 gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_warn_large_insert_size),
303 prefs_common.warn_large_insert_size);
304 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reply_account_autosel),
305 prefs_common.reply_account_autosel);
306 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_forward_account_autosel),
307 prefs_common.forward_account_autosel);
308 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reedit_account_autosel),
309 prefs_common.reedit_account_autosel);
310 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reply_with_quote),
311 prefs_common.reply_with_quote);
312 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_warn_pasted_attachments),
313 prefs_common.notify_pasted_attachments);
314 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_default_reply_list),
315 prefs_common.default_reply_list);
316 combobox_select_by_data(GTK_COMBO_BOX(optmenu_dnd_insert_or_attach),
317 prefs_common.compose_dnd_mode);
319 prefs_writing->page.widget = vbox1;
322 static void prefs_compose_writing_save(PrefsPage *_page)
324 WritingPage *page = (WritingPage *) _page;
326 prefs_common.auto_exteditor =
327 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autoextedit));
328 prefs_common.forward_as_attachment =
329 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_as_attachment));
330 prefs_common.redirect_keep_from =
331 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_redirect_keep_from));
332 prefs_common.autosave =
333 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autosave));
334 prefs_common.autosave_encrypted =
335 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autosave_encrypted));
336 prefs_common.autosave_length =
337 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_autosave_length));
338 prefs_common.undolevels =
339 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_undolevel));
340 prefs_common.warn_large_insert =
341 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_warn_large_insert));
342 prefs_common.warn_large_insert_size =
343 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_warn_large_insert_size));
345 prefs_common.reply_account_autosel =
346 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_account_autosel));
347 prefs_common.forward_account_autosel =
348 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_account_autosel));
349 prefs_common.reedit_account_autosel =
350 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reedit_account_autosel));
351 prefs_common.reply_with_quote = gtk_toggle_button_get_active(
352 GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_quote));
353 prefs_common.default_reply_list =
354 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_list));
356 prefs_common.compose_dnd_mode = combobox_get_active_data(
357 GTK_COMBO_BOX(page->optmenu_dnd_insert_or_attach));
359 prefs_common.notify_pasted_attachments =
360 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_warn_pasted_attachments));
363 static void prefs_compose_writing_destroy_widget(PrefsPage *_page)
367 WritingPage *prefs_writing;
369 void prefs_compose_writing_init(void)
371 WritingPage *page;
372 static gchar *path[3];
374 path[0] = _("Compose");
375 path[1] = _("Writing");
376 path[2] = NULL;
378 page = g_new0(WritingPage, 1);
379 page->page.path = path;
380 page->page.create_widget = prefs_compose_writing_create_widget;
381 page->page.destroy_widget = prefs_compose_writing_destroy_widget;
382 page->page.save_page = prefs_compose_writing_save;
383 page->page.weight = 190.0;
384 prefs_gtk_register_page((PrefsPage *) page);
385 prefs_writing = page;
388 void prefs_compose_writing_done(void)
390 prefs_gtk_unregister_page((PrefsPage *) prefs_writing);
391 g_free(prefs_writing);