rework image viewer
[claws.git] / src / prefs_image_viewer.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2020 the Claws Mail Team
4  *
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.
9  *
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.
14  *
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/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30
31 #include "common/utils.h"
32 #include "prefs.h"
33 #include "prefs_gtk.h"
34 #include "prefswindow.h"
35
36 #include "prefs_common.h"
37 #include "prefs_gtk.h"
38
39 typedef struct _ImageViewerPage
40 {
41         PrefsPage page;
42         
43         GtkWidget *window;              /* do not modify */
44
45         GtkWidget *autoload_img;
46         GtkWidget *resize_img;
47         GtkWidget *fit_img_height_radiobtn;
48         GtkWidget *fit_img_width_radiobtn;
49         GtkWidget *inline_img;
50         GtkWidget *print_imgs;
51 }ImageViewerPage;
52
53 static void imageviewer_create_widget_func(PrefsPage * _page,
54                                            GtkWindow * window,
55                                            gpointer data)
56 {
57         ImageViewerPage *prefs_imageviewer = (ImageViewerPage *) _page;
58
59         GtkWidget *table;
60         GtkWidget *autoload_img;
61         GtkWidget *resize_img;
62         GtkWidget *vbox;
63         GtkWidget *hbox;
64         GtkWidget *fit_img_label;
65         GtkWidget *fit_img_height_radiobtn;
66         GtkWidget *fit_img_width_radiobtn;
67         GtkWidget *inline_img;
68         GtkWidget *print_imgs;
69
70         table = gtk_table_new(4, 1, FALSE);
71         gtk_widget_show(table);
72         gtk_container_set_border_width(GTK_CONTAINER(table), VBOX_BORDER);
73         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
74         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
75
76         autoload_img = gtk_check_button_new_with_label(_("Automatically display attached images"));
77         gtk_widget_show(autoload_img);
78         gtk_table_attach(GTK_TABLE(table), autoload_img, 0, 1, 0, 1,
79                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
80                          (GtkAttachOptions) (0), 0, 0);
81
82         resize_img = gtk_check_button_new_with_label(_("Resize attached images by default"));
83         gtk_widget_show(resize_img);
84         CLAWS_SET_TIP(resize_img,
85                              _("Clicking image toggles scaling"));
86         gtk_table_attach(GTK_TABLE(table), resize_img, 0, 1, 1, 2,
87                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
88                          (GtkAttachOptions) (0), 0, 0);
89
90         vbox = gtk_vbox_new(FALSE, VSPACING);
91         hbox = gtk_hbox_new(FALSE, 8);
92         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
93         gtk_widget_show(vbox);
94         gtk_widget_show(hbox);
95
96         fit_img_label = gtk_label_new (_("Fit image"));
97         gtk_widget_show(fit_img_label);
98         CLAWS_SET_TIP(fit_img_label,
99                              _("Right-clicking image toggles fitting height/width"));
100         gtk_box_pack_start(GTK_BOX(hbox), fit_img_label, FALSE, FALSE, 0);
101
102         fit_img_height_radiobtn = gtk_radio_button_new_with_label(NULL, _("Height"));
103         gtk_widget_show(fit_img_height_radiobtn);
104         gtk_box_pack_start(GTK_BOX(hbox), fit_img_height_radiobtn, FALSE, FALSE, 0);
105
106         fit_img_width_radiobtn = gtk_radio_button_new_with_label_from_widget(
107                                            GTK_RADIO_BUTTON(fit_img_height_radiobtn), _("Width"));
108         gtk_widget_show(fit_img_width_radiobtn);
109         gtk_box_pack_start(GTK_BOX(hbox), fit_img_width_radiobtn, FALSE, FALSE, 0);
110         gtk_table_attach(GTK_TABLE(table), vbox, 0, 1, 2, 3,
111                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
112                          (GtkAttachOptions) (0), 0, 0);
113
114         inline_img = gtk_check_button_new_with_label(_("Display images inline"));
115         gtk_widget_show(inline_img);
116         gtk_table_attach(GTK_TABLE(table), inline_img, 0, 1, 3, 4,
117                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
118                          (GtkAttachOptions) (0), 0, 0);
119         
120         print_imgs = gtk_check_button_new_with_label(_("Print images"));
121         gtk_widget_show(print_imgs);
122         gtk_table_attach(GTK_TABLE(table), print_imgs, 0, 1, 4, 5,
123                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
124                          (GtkAttachOptions) (0), 0, 0);
125         
126         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(resize_img), prefs_common.resize_img);
127         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(autoload_img), prefs_common.display_img);
128         if (prefs_common.fit_img_height)
129                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fit_img_height_radiobtn), TRUE);
130         else
131                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fit_img_width_radiobtn), TRUE);
132         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(inline_img), prefs_common.inline_img);
133         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_imgs), prefs_common.print_imgs);
134         
135         SET_TOGGLE_SENSITIVITY(resize_img, vbox);
136
137         prefs_imageviewer->window       = GTK_WIDGET(window);
138         prefs_imageviewer->autoload_img = autoload_img;
139         prefs_imageviewer->resize_img   = resize_img;
140         prefs_imageviewer->fit_img_height_radiobtn      = fit_img_height_radiobtn;
141         prefs_imageviewer->fit_img_width_radiobtn       = fit_img_width_radiobtn;
142         prefs_imageviewer->inline_img   = inline_img;
143         prefs_imageviewer->print_imgs   = print_imgs;
144
145         prefs_imageviewer->page.widget = table;
146 }
147
148 static void imageviewer_destroy_widget_func(PrefsPage *_page)
149 {
150 }
151
152 static void imageviewer_save_func(PrefsPage * _page)
153 {
154         ImageViewerPage *imageviewer = (ImageViewerPage *) _page;
155         
156         prefs_common.display_img =
157             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
158                                          (imageviewer->autoload_img));
159         prefs_common.resize_img =
160             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
161                                          (imageviewer->resize_img));
162         prefs_common.fit_img_height =
163             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
164                                         (imageviewer->fit_img_height_radiobtn));
165         prefs_common.inline_img =
166             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
167                                          (imageviewer->inline_img));
168         prefs_common.print_imgs =
169             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
170                                          (imageviewer->print_imgs));
171 }
172
173 ImageViewerPage *prefs_imageviewer;
174
175 void prefs_image_viewer_init(void)
176 {
177         ImageViewerPage *page;
178         static gchar *path[3];
179
180         path[0] = _("Message View");
181         path[1] = _("Image Viewer");
182         path[2] = NULL;
183
184         page = g_new0(ImageViewerPage, 1);
185         page->page.path = path;
186         page->page.create_widget = imageviewer_create_widget_func;
187         page->page.destroy_widget = imageviewer_destroy_widget_func;
188         page->page.save_page = imageviewer_save_func;
189         page->page.weight = 160.0;
190         prefs_gtk_register_page((PrefsPage *) page);
191         prefs_imageviewer = page;
192 }
193
194 void prefs_image_viewer_done(void)
195 {
196         prefs_gtk_unregister_page((PrefsPage *) prefs_imageviewer);
197         g_free(prefs_imageviewer);
198 }