2011-10-22 [colin] 3.7.10cvs42
[claws.git] / src / prefs_image_viewer.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2011 Hiroyuki Yamamoto and 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 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29
30 #include "common/utils.h"
31 #include "prefs.h"
32 #include "prefs_gtk.h"
33 #include "prefswindow.h"
34
35 #include "prefs_common.h"
36 #include "prefs_gtk.h"
37
38 typedef struct _ImageViewerPage
39 {
40         PrefsPage page;
41         
42         GtkWidget *window;              /* do not modify */
43
44         GtkWidget *autoload_img;
45         GtkWidget *resize_img;
46         GtkWidget *inline_img;
47         GtkWidget *print_imgs;
48 }ImageViewerPage;
49
50 static void imageviewer_create_widget_func(PrefsPage * _page,
51                                            GtkWindow * window,
52                                            gpointer data)
53 {
54         ImageViewerPage *prefs_imageviewer = (ImageViewerPage *) _page;
55
56         GtkWidget *table;
57         GtkWidget *autoload_img;
58         GtkWidget *resize_img;
59         GtkWidget *inline_img;
60         GtkWidget *print_imgs;
61
62         table = gtk_table_new(4, 1, FALSE);
63         gtk_widget_show(table);
64         gtk_container_set_border_width(GTK_CONTAINER(table), VBOX_BORDER);
65         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
66         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
67
68         autoload_img = gtk_check_button_new_with_label(_("Automatically display attached images"));
69         gtk_widget_show(autoload_img);
70         gtk_table_attach(GTK_TABLE(table), autoload_img, 0, 1, 0, 1,
71                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
72                          (GtkAttachOptions) (0), 0, 0);
73
74         resize_img = gtk_check_button_new_with_label(_("Resize attached images by default"));
75         gtk_widget_show(resize_img);
76         CLAWS_SET_TIP(resize_img,
77                              _("Clicking image toggles scaling"));
78         gtk_table_attach(GTK_TABLE(table), resize_img, 0, 1, 1, 2,
79                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
80                          (GtkAttachOptions) (0), 0, 0);
81
82         inline_img = gtk_check_button_new_with_label(_("Display images inline"));
83         gtk_widget_show(inline_img);
84         gtk_table_attach(GTK_TABLE(table), inline_img, 0, 1, 2, 3,
85                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
86                          (GtkAttachOptions) (0), 0, 0);
87         
88         print_imgs = gtk_check_button_new_with_label(_("Print images"));
89         gtk_widget_show(print_imgs);
90         gtk_table_attach(GTK_TABLE(table), print_imgs, 0, 1, 3, 4,
91                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
92                          (GtkAttachOptions) (0), 0, 0);
93         
94         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(resize_img), prefs_common.resize_img);
95         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(autoload_img), prefs_common.display_img);
96         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(inline_img), prefs_common.inline_img);
97         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_imgs), prefs_common.print_imgs);
98
99         prefs_imageviewer->window       = GTK_WIDGET(window);
100         prefs_imageviewer->autoload_img = autoload_img;
101         prefs_imageviewer->resize_img   = resize_img;
102         prefs_imageviewer->inline_img   = inline_img;
103         prefs_imageviewer->print_imgs   = print_imgs;
104
105         prefs_imageviewer->page.widget = table;
106 }
107
108 static void imageviewer_destroy_widget_func(PrefsPage *_page)
109 {
110 }
111
112 static void imageviewer_save_func(PrefsPage * _page)
113 {
114         ImageViewerPage *imageviewer = (ImageViewerPage *) _page;
115         
116         prefs_common.display_img =
117             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
118                                          (imageviewer->autoload_img));
119         prefs_common.resize_img =
120             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
121                                          (imageviewer->resize_img));
122         prefs_common.inline_img =
123             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
124                                          (imageviewer->inline_img));
125         prefs_common.print_imgs =
126             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
127                                          (imageviewer->print_imgs));
128 }
129
130 ImageViewerPage *prefs_imageviewer;
131
132 void prefs_image_viewer_init(void)
133 {
134         ImageViewerPage *page;
135         static gchar *path[3];
136
137         path[0] = _("Message View");
138         path[1] = _("Image Viewer");
139         path[2] = NULL;
140
141         page = g_new0(ImageViewerPage, 1);
142         page->page.path = path;
143         page->page.create_widget = imageviewer_create_widget_func;
144         page->page.destroy_widget = imageviewer_destroy_widget_func;
145         page->page.save_page = imageviewer_save_func;
146         page->page.weight = 160.0;
147         prefs_gtk_register_page((PrefsPage *) page);
148         prefs_imageviewer = page;
149 }
150
151 void prefs_image_viewer_done(void)
152 {
153         prefs_gtk_unregister_page((PrefsPage *) prefs_imageviewer);
154         g_free(prefs_imageviewer);
155 }