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_ref(table2);
73 gtk_widget_show(table2);
74 gtk_container_set_border_width(GTK_CONTAINER(table2), 8);
75 gtk_table_set_row_spacings(GTK_TABLE(table2), 4);
76 gtk_table_set_col_spacings(GTK_TABLE(table2), 8);
79 gtk_label_new(_("Automatically display attached images"));
80 gtk_widget_ref(label14);
81 gtk_widget_show(label14);
82 gtk_table_attach(GTK_TABLE(table2), label14, 0, 1, 0, 1,
83 (GtkAttachOptions) (GTK_FILL),
84 (GtkAttachOptions) (0), 0, 0);
85 gtk_misc_set_alignment(GTK_MISC(label14), 0, 0.5);
87 label15 = gtk_label_new(_("Resize attached images"));
88 gtk_widget_ref(label15);
89 gtk_widget_show(label15);
90 gtk_table_attach(GTK_TABLE(table2), label15, 0, 1, 1, 2,
91 (GtkAttachOptions) (GTK_FILL),
92 (GtkAttachOptions) (0), 0, 0);
93 gtk_misc_set_alignment(GTK_MISC(label15), 0, 0.5);
95 autoload = gtk_check_button_new_with_label("");
96 gtk_widget_ref(autoload);
97 gtk_widget_show(autoload);
98 gtk_table_attach(GTK_TABLE(table2), autoload, 1, 2, 0, 1,
99 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
100 (GtkAttachOptions) (0), 0, 0);
102 resize = gtk_check_button_new_with_label("");
103 gtk_widget_ref(resize);
104 gtk_widget_show(resize);
105 gtk_table_attach(GTK_TABLE(table2), resize, 1, 2, 1, 2,
106 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
107 (GtkAttachOptions) (0), 0, 0);
108 /* --------------------------------------------------------- */
109 gtk_widget_set_sensitive(GTK_WIDGET(autoload), FALSE);
111 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(resize), imageviewerprefs.resize_img);
113 page->autoload = autoload;
114 page->resize = resize;
116 page->page.widget = table2;
119 static void imageviewer_destroy_widget_func(PrefsPage *_page)
123 static void imageviewer_save_func(PrefsPage * _page)
125 struct ImageViewerPage *page = (struct ImageViewerPage *) _page;
129 imageviewerprefs.display_img =
130 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
132 imageviewerprefs.resize_img =
133 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->resize));
135 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
136 pfile = prefs_write_open(rcpath);
138 if (!pfile || (prefs_set_block_label(pfile, PREFS_BLOCK_NAME) < 0))
141 if (prefs_write_param(param, pfile->fp) < 0) {
142 g_warning("failed to write ImageViewer configuration to file\n");
143 prefs_file_close_revert(pfile);
146 fprintf(pfile->fp, "\n");
148 prefs_file_close(pfile);
151 static struct ImageViewerPage imageviewer_page;
153 void image_viewer_prefs_init()
155 prefs_set_default(param);
156 prefs_read_config(param, PREFS_BLOCK_NAME, COMMON_RC);
158 imageviewer_page.page.path = "Message View/Image Viewer";
159 imageviewer_page.page.create_widget = imageviewer_create_widget_func;
160 imageviewer_page.page.destroy_widget = imageviewer_destroy_widget_func;
161 imageviewer_page.page.save_page = imageviewer_save_func;
163 prefs_gtk_register_page((PrefsPage *) &imageviewer_page);
166 void image_viewer_prefs_done()
168 prefs_gtk_unregister_page((PrefsPage *) &imageviewer_page);