Fix CID 1491093: attrib leaked if attvalue is null
[claws.git] / src / prefs_image_viewer.c
blobfbb064b95556328b5adb73eb55380e21bac478a2
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2020 the Claws Mail Team
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/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include "defs.h"
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
31 #include "common/utils.h"
32 #include "prefs.h"
33 #include "prefs_gtk.h"
34 #include "prefswindow.h"
36 #include "prefs_common.h"
38 typedef struct _ImageViewerPage
40 PrefsPage page;
42 GtkWidget *window; /* do not modify */
44 GtkWidget *autoload_img;
45 GtkWidget *resize_img;
46 GtkWidget *fit_img_height_radiobtn;
47 GtkWidget *fit_img_width_radiobtn;
48 GtkWidget *inline_img;
49 GtkWidget *print_imgs;
50 }ImageViewerPage;
52 static void imageviewer_create_widget_func(PrefsPage * _page,
53 GtkWindow * window,
54 gpointer data)
56 ImageViewerPage *prefs_imageviewer = (ImageViewerPage *) _page;
58 GtkWidget *table;
59 GtkWidget *autoload_img;
60 GtkWidget *resize_img;
61 GtkWidget *vbox;
62 GtkWidget *hbox;
63 GtkWidget *fit_img_label;
64 GtkWidget *fit_img_height_radiobtn;
65 GtkWidget *fit_img_width_radiobtn;
66 GtkWidget *inline_img;
67 GtkWidget *print_imgs;
69 table = gtk_grid_new();
70 gtk_grid_set_column_homogeneous(GTK_GRID(table), FALSE);
71 gtk_widget_show(table);
72 gtk_container_set_border_width(GTK_CONTAINER(table), VBOX_BORDER);
73 gtk_grid_set_row_spacing(GTK_GRID(table), 4);
74 gtk_grid_set_column_spacing(GTK_GRID(table), 8);
76 autoload_img = gtk_check_button_new_with_label(_("Automatically display attached images"));
77 gtk_widget_show(autoload_img);
78 gtk_grid_attach(GTK_GRID(table), autoload_img, 0, 0, 1, 1);
80 resize_img = gtk_check_button_new_with_label(_("Resize attached images by default"));
81 gtk_widget_show(resize_img);
82 CLAWS_SET_TIP(resize_img,
83 _("Clicking image toggles scaling"));
84 gtk_grid_attach(GTK_GRID(table), resize_img, 0, 1, 1, 1);
86 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
87 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
88 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
89 gtk_widget_show(vbox);
90 gtk_widget_show(hbox);
92 fit_img_label = gtk_label_new (_("Fit image"));
93 gtk_widget_set_halign(fit_img_label, GTK_ALIGN_END);
94 gtk_widget_show(fit_img_label);
95 CLAWS_SET_TIP(fit_img_label,
96 _("Right-clicking image toggles fitting height/width"));
97 gtk_box_pack_start(GTK_BOX(hbox), fit_img_label, FALSE, FALSE, 0);
99 fit_img_height_radiobtn = gtk_radio_button_new_with_label(NULL, _("Height"));
100 gtk_widget_set_halign(fit_img_height_radiobtn, GTK_ALIGN_START);
101 gtk_widget_show(fit_img_height_radiobtn);
102 gtk_box_pack_start(GTK_BOX(hbox), fit_img_height_radiobtn, FALSE, FALSE, 0);
104 fit_img_width_radiobtn = gtk_radio_button_new_with_label_from_widget(
105 GTK_RADIO_BUTTON(fit_img_height_radiobtn), _("Width"));
106 gtk_widget_show(fit_img_width_radiobtn);
107 gtk_box_pack_start(GTK_BOX(hbox), fit_img_width_radiobtn, FALSE, FALSE, 0);
108 gtk_grid_attach(GTK_GRID(table), vbox, 0, 2, 1, 1);
110 inline_img = gtk_check_button_new_with_label(_("Display images inline"));
111 gtk_widget_show(inline_img);
112 gtk_grid_attach(GTK_GRID(table), inline_img, 0, 3, 1, 1);
114 print_imgs = gtk_check_button_new_with_label(_("Print images"));
115 gtk_widget_show(print_imgs);
116 gtk_grid_attach(GTK_GRID(table), print_imgs, 0, 4, 1, 1);
118 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(resize_img), prefs_common.resize_img);
119 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(autoload_img), prefs_common.display_img);
120 if (prefs_common.fit_img_height)
121 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fit_img_height_radiobtn), TRUE);
122 else
123 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fit_img_width_radiobtn), TRUE);
124 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(inline_img), prefs_common.inline_img);
125 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_imgs), prefs_common.print_imgs);
127 SET_TOGGLE_SENSITIVITY(resize_img, vbox);
129 prefs_imageviewer->window = GTK_WIDGET(window);
130 prefs_imageviewer->autoload_img = autoload_img;
131 prefs_imageviewer->resize_img = resize_img;
132 prefs_imageviewer->fit_img_height_radiobtn = fit_img_height_radiobtn;
133 prefs_imageviewer->fit_img_width_radiobtn = fit_img_width_radiobtn;
134 prefs_imageviewer->inline_img = inline_img;
135 prefs_imageviewer->print_imgs = print_imgs;
137 prefs_imageviewer->page.widget = table;
140 static void imageviewer_destroy_widget_func(PrefsPage *_page)
144 static void imageviewer_save_func(PrefsPage * _page)
146 ImageViewerPage *imageviewer = (ImageViewerPage *) _page;
148 prefs_common.display_img =
149 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
150 (imageviewer->autoload_img));
151 prefs_common.resize_img =
152 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
153 (imageviewer->resize_img));
154 prefs_common.fit_img_height =
155 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
156 (imageviewer->fit_img_height_radiobtn));
157 prefs_common.inline_img =
158 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
159 (imageviewer->inline_img));
160 prefs_common.print_imgs =
161 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
162 (imageviewer->print_imgs));
165 ImageViewerPage *prefs_imageviewer;
167 void prefs_image_viewer_init(void)
169 ImageViewerPage *page;
170 static gchar *path[3];
172 path[0] = _("Message View");
173 path[1] = _("Image Viewer");
174 path[2] = NULL;
176 page = g_new0(ImageViewerPage, 1);
177 page->page.path = path;
178 page->page.create_widget = imageviewer_create_widget_func;
179 page->page.destroy_widget = imageviewer_destroy_widget_func;
180 page->page.save_page = imageviewer_save_func;
181 page->page.weight = 160.0;
182 prefs_gtk_register_page((PrefsPage *) page);
183 prefs_imageviewer = page;
186 void prefs_image_viewer_done(void)
188 prefs_gtk_unregister_page((PrefsPage *) prefs_imageviewer);
189 g_free(prefs_imageviewer);