2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 Hiroyuki Yamamoto and the Sylpheed-Claws 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 2 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include "common/utils.h"
32 #include "prefs_gtk.h"
33 #include "prefswindow.h"
35 #include "viewerprefs.h"
37 #define PREFS_BLOCK_NAME "ImageViewer"
39 struct ImageViewerPage
47 ImageViewerPrefs imageviewerprefs;
49 static PrefParam param[] = {
50 {"display_img", "TRUE", &imageviewerprefs.display_img, P_BOOL,
52 {"resize_image", "TRUE", &imageviewerprefs.resize_img, P_BOOL,
55 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
58 static void imageviewer_create_widget_func(PrefsPage * _page,
62 struct ImageViewerPage *page = (struct ImageViewerPage *) _page;
64 /* ------------------ code made by glade -------------------- */
71 table2 = gtk_table_new(2, 2, FALSE);
72 gtk_widget_show(table2);
73 gtk_container_set_border_width(GTK_CONTAINER(table2), 8);
74 gtk_table_set_row_spacings(GTK_TABLE(table2), 4);
75 gtk_table_set_col_spacings(GTK_TABLE(table2), 8);
78 gtk_label_new(_("Automatically display attached images"));
79 gtk_widget_show(label14);
80 gtk_table_attach(GTK_TABLE(table2), label14, 0, 1, 0, 1,
81 (GtkAttachOptions) (GTK_FILL),
82 (GtkAttachOptions) (0), 0, 0);
83 gtk_misc_set_alignment(GTK_MISC(label14), 0, 0.5);
85 label15 = gtk_label_new(_("Resize attached images by default\n(Clicking image toggles scaling)"));
86 gtk_widget_show(label15);
87 gtk_table_attach(GTK_TABLE(table2), label15, 0, 1, 1, 2,
88 (GtkAttachOptions) (GTK_FILL),
89 (GtkAttachOptions) (0), 0, 0);
90 gtk_misc_set_alignment(GTK_MISC(label15), 0, 0.5);
92 autoload = gtk_check_button_new_with_label("");
93 gtk_widget_show(autoload);
94 gtk_table_attach(GTK_TABLE(table2), autoload, 1, 2, 0, 1,
95 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
96 (GtkAttachOptions) (0), 0, 0);
98 resize = gtk_check_button_new_with_label("");
99 gtk_widget_show(resize);
100 gtk_table_attach(GTK_TABLE(table2), resize, 1, 2, 1, 2,
101 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
102 (GtkAttachOptions) (0), 0, 0);
103 /* --------------------------------------------------------- */
105 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(resize), imageviewerprefs.resize_img);
106 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(autoload), imageviewerprefs.display_img);
108 page->autoload = autoload;
109 page->resize = resize;
111 page->page.widget = table2;
114 static void imageviewer_destroy_widget_func(PrefsPage *_page)
118 static void imageviewer_save_func(PrefsPage * _page)
120 struct ImageViewerPage *page = (struct ImageViewerPage *) _page;
124 imageviewerprefs.display_img =
125 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
127 imageviewerprefs.resize_img =
128 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->resize));
130 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
131 pfile = prefs_write_open(rcpath);
133 if (!pfile || (prefs_set_block_label(pfile, PREFS_BLOCK_NAME) < 0))
136 if (prefs_write_param(param, pfile->fp) < 0) {
137 g_warning("failed to write ImageViewer configuration to file\n");
138 prefs_file_close_revert(pfile);
141 fprintf(pfile->fp, "\n");
143 prefs_file_close(pfile);
146 static struct ImageViewerPage imageviewer_page;
148 void image_viewer_prefs_init(void)
150 prefs_set_default(param);
151 prefs_read_config(param, PREFS_BLOCK_NAME, COMMON_RC);
153 imageviewer_page.page.path = "Message View/Image Viewer";
154 imageviewer_page.page.create_widget = imageviewer_create_widget_func;
155 imageviewer_page.page.destroy_widget = imageviewer_destroy_widget_func;
156 imageviewer_page.page.save_page = imageviewer_save_func;
158 prefs_gtk_register_page((PrefsPage *) &imageviewer_page);
161 void image_viewer_prefs_done(void)
163 prefs_gtk_unregister_page((PrefsPage *) &imageviewer_page);