Wrong initialization for nb_inserted in the deserialization.
[gliv.git] / src / options.c
blob1e48f93d2fd0bf5c89c246a504220c6d0293c68a
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * See the COPYING file for license information.
18 * Guillaume Chazarain <guichaz@yahoo.fr>
21 /*****************************
22 * User configurable options *
23 *****************************/
25 #include <string.h> /* memcmp() */
26 #include <gdk/gdkkeysyms.h> /* GDK_Escape, GDK_c, GDK_C, GDK_o, GDK_O */
28 #include "gliv.h"
29 #include "options.h"
30 #include "glade_options.h"
31 #include "gliv_image.h"
32 #include "gl_widget.h"
33 #include "history.h"
34 #include "windows.h"
35 #include "matrix.h"
36 #include "messages.h"
37 #include "rendering.h"
38 #include "scrollbars.h"
39 #include "next_image.h"
40 #include "rcfile.h"
41 #include "str_utils.h"
42 #include "tree.h"
44 extern rt_struct *rt;
45 extern options_struct *options;
46 extern gliv_image *current_image;
47 extern GtkWidget *gl_widget;
49 /* Filled by the dialog. */
50 static options_struct *new_options;
51 static GtkWidget *options_dialog = NULL;
53 static gboolean save_options = FALSE;
55 static void toggle_delay(void)
57 if (options->delay == 0)
58 /* Enable. */
59 gtk_widget_add_events(gl_widget, GDK_POINTER_MOTION_MASK);
61 options->delay = new_options->delay;
62 schedule_hide_cursor();
65 static void toggle_history(void)
67 options->history_size = new_options->history_size;
68 clean_history();
71 static void finish(gboolean apply)
73 gint what = 0;
74 gboolean bg_color_changed;
76 gtk_widget_hide(options_dialog);
78 if (apply) {
80 if (options->fullscreen != new_options->fullscreen)
81 toggle_fullscreen(new_options->fullscreen);
83 if ((options->maximize == FALSE && new_options->maximize) ||
84 (options->scaledown == FALSE && new_options->scaledown)) {
86 options->maximize = new_options->maximize;
87 options->scaledown = new_options->scaledown;
89 matrix_set_max_zoom(-1, -1, TRUE);
90 what |= REFRESH_IMAGE | REFRESH_STATUS | APPEND_HISTORY;
93 if (options->menu_bar != new_options->menu_bar)
94 toggle_menu_bar();
96 if (options->status_bar != new_options->status_bar)
97 toggle_status_bar();
99 if (options->scrollbars != new_options->scrollbars)
100 toggle_scrollbars();
102 if (options->dither != new_options->dither ||
103 options->mipmap != new_options->mipmap) {
105 options->dither = new_options->dither;
106 options->mipmap = new_options->mipmap;
108 reload_all_images();
109 what |= REFRESH_IMAGE;
112 if (options->one_image == FALSE && new_options->one_image)
113 unload_images();
115 if (options->delay != new_options->delay)
116 toggle_delay();
118 if (options->history_size != new_options->history_size)
119 toggle_history();
121 if (options->duration != new_options->duration)
122 if (slide_show_started()) {
123 options->duration = new_options->duration;
124 start_slide_show();
127 if (options->thumbnails != new_options->thumbnails ||
128 options->thumb_width != new_options->thumb_width ||
129 options->thumb_height != new_options->thumb_height)
130 invalidate_last_tree();
132 bg_color_changed = !gdk_color_equal(&options->bg_col,
133 &new_options->bg_col);
135 if (!gdk_color_equal(&options->alpha1, &new_options->alpha1) ||
136 !gdk_color_equal(&options->alpha2, &new_options->alpha2)) {
138 rt->alpha_checks_changed = TRUE;
140 if (current_image != NULL && current_image->has_alpha)
141 what |= REFRESH_IMAGE;
144 g_free(options);
145 options = new_options;
147 if (save_options)
148 save_rc(options);
150 if (bg_color_changed) {
151 update_bg_color();
152 what |= REFRESH_IMAGE;
154 } else
155 g_free(new_options);
157 gtk_widget_destroy(options_dialog);
158 options_dialog = NULL;
160 refresh(what);
163 static gboolean key_press_event(GtkWidget * unused, GdkEventKey * event)
165 if (event->keyval == GDK_Escape) {
166 finish(FALSE);
167 return TRUE;
170 return FALSE;
173 /* Cancel and OK buttons */
175 static void add_cancel_button(GtkWidget * button)
177 g_signal_connect_swapped(button, "clicked",
178 G_CALLBACK(finish), GINT_TO_POINTER(FALSE));
181 static void add_ok_button(GtkWidget * button)
183 GTK_WIDGET_SET_FLAGS(GTK_WIDGET(button), GTK_CAN_DEFAULT);
184 g_signal_connect_swapped(button, "clicked",
185 G_CALLBACK(finish), GINT_TO_POINTER(TRUE));
187 g_signal_connect(button, "realize",
188 G_CALLBACK(gtk_widget_grab_default), NULL);
191 /* GtkColorSelection */
193 static void add_color_selection(GtkWidget * color_sel, GdkColor * col)
195 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(color_sel), col);
197 g_signal_connect(color_sel, "color-changed",
198 G_CALLBACK(gtk_color_selection_get_current_color), col);
201 /* GtkSpinButton */
203 static gboolean value_changed(GtkAdjustment * adj, gint * val)
205 *val = (gint) gtk_adjustment_get_value(adj);
206 return TRUE;
209 static void add_spin_button(GtkWidget * button, gint * value)
211 GtkAdjustment *adj;
213 adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(button));
214 gtk_adjustment_set_value(adj, (gdouble) * value);
216 g_signal_connect(adj, "value-changed", G_CALLBACK(value_changed), value);
219 /* GtkCheckButton */
221 static gboolean toggled_button(GtkToggleButton * button, gboolean * bool)
223 *bool = gtk_toggle_button_get_active(button);
224 return TRUE;
227 static void add_check_button(GtkWidget * button, gboolean * value)
229 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), *value);
230 g_signal_connect(button, "toggled", G_CALLBACK(toggled_button), value);
233 #include "glade_options.c"
235 void show_options(void)
237 if (options_dialog != NULL)
238 return;
240 new_options = g_memdup(options, sizeof(options_struct));
241 options_dialog = create_options_dialog();
243 g_signal_connect_swapped(options_dialog, "delete-event",
244 G_CALLBACK(finish), GINT_TO_POINTER(FALSE));
246 g_signal_connect(options_dialog, "key-press-event",
247 G_CALLBACK(key_press_event), NULL);
249 show_dialog(GTK_WIDGET(options_dialog), _("Options"));