1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /*
4 * GThumb
5 *
6 * Copyright (C) 2014 The Free Software Foundation, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <config.h>
23 #include <gtk/gtk.h>
24 #include "dlg-preferences-general.h"
25 #include "glib-utils.h"
26 #include "gth-browser.h"
27 #include "gth-file-source-vfs.h"
28 #include "gth-location-chooser.h"
29 #include "gth-main.h"
30 #include "gth-preferences.h"
31 #include "gtk-utils.h"
32 #include "main.h"
33
34
35 #define BROWSER_DATA_KEY "general-preference-data"
36 #define GET_WIDGET(name) _gtk_builder_get_widget (data->builder, (name))
37
38
39 typedef struct {
40 GthBrowser *browser;
41 GtkBuilder *builder;
42 GSettings *general_settings;
43 GSettings *browser_settings;
44 GSettings *messages_settings;
45 GtkWidget *dialog;
46 GtkWidget *startup_location_chooser;
47 } BrowserData;
48
49
50 static void
browser_data_free(BrowserData * data)51 browser_data_free (BrowserData *data)
52 {
53 g_object_unref (data->general_settings);
54 g_object_unref (data->browser_settings);
55 g_object_unref (data->messages_settings);
56 g_object_unref (data->builder);
57 g_object_unref (data->browser);
58 g_free (data);
59 }
60
61
62 static void
use_startup_toggled_cb(GtkWidget * widget,BrowserData * data)63 use_startup_toggled_cb (GtkWidget *widget,
64 BrowserData *data)
65 {
66 gtk_widget_set_sensitive (data->startup_location_chooser, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)));
67 gtk_widget_set_sensitive (GET_WIDGET ("set_to_current_button"), gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)));
68 }
69
70
71 static void
set_to_current_cb(GtkWidget * widget,BrowserData * data)72 set_to_current_cb (GtkWidget *widget,
73 BrowserData *data)
74 {
75 gth_location_chooser_set_current (GTH_LOCATION_CHOOSER (data->startup_location_chooser),
76 gth_browser_get_location (data->browser));
77 }
78
79
80 static void
thumbnails_pane_orientation_changed_cb(GtkWidget * widget,BrowserData * data)81 thumbnails_pane_orientation_changed_cb (GtkWidget *widget,
82 BrowserData *data)
83 {
84 g_settings_set_enum (data->browser_settings, PREF_BROWSER_VIEWER_THUMBNAILS_ORIENT, gtk_combo_box_get_active (GTK_COMBO_BOX (GET_WIDGET ("thumbnails_pane_orient_combobox"))));
85 }
86
87
88 static void
file_properties_position_combobox_changed_cb(GtkWidget * widget,BrowserData * data)89 file_properties_position_combobox_changed_cb (GtkWidget *widget,
90 BrowserData *data)
91 {
92 g_settings_set_boolean (data->browser_settings, PREF_BROWSER_PROPERTIES_ON_THE_RIGHT, gtk_combo_box_get_active (GTK_COMBO_BOX (GET_WIDGET ("file_properties_position_combobox"))) == 1);
93 }
94
95
96 static void
reuse_active_window_checkbutton_toggled_cb(GtkToggleButton * button,BrowserData * data)97 reuse_active_window_checkbutton_toggled_cb (GtkToggleButton *button,
98 BrowserData *data)
99 {
100 g_settings_set_boolean (data->browser_settings, PREF_BROWSER_REUSE_ACTIVE_WINDOW, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("reuse_active_window_checkbutton"))));
101 }
102
103
104 static void
confirm_deletion_toggled_cb(GtkToggleButton * button,BrowserData * data)105 confirm_deletion_toggled_cb (GtkToggleButton *button,
106 BrowserData *data)
107 {
108 g_settings_set_boolean (data->messages_settings, PREF_MSG_CONFIRM_DELETION, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("confirm_deletion_checkbutton"))));
109 }
110
111
112 static void
ask_to_save_toggled_cb(GtkToggleButton * button,BrowserData * data)113 ask_to_save_toggled_cb (GtkToggleButton *button,
114 BrowserData *data)
115 {
116 g_settings_set_boolean (data->messages_settings, PREF_MSG_SAVE_MODIFIED_IMAGE, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("ask_to_save_checkbutton"))));
117 }
118
119
120 void
general__dlg_preferences_construct_cb(GtkWidget * dialog,GthBrowser * browser,GtkBuilder * dialog_builder)121 general__dlg_preferences_construct_cb (GtkWidget *dialog,
122 GthBrowser *browser,
123 GtkBuilder *dialog_builder)
124 {
125 BrowserData *data;
126
127 data = g_new0 (BrowserData, 1);
128 data->browser = g_object_ref (browser);
129 data->builder = g_object_ref (dialog_builder);
130 data->general_settings = g_settings_new (GTHUMB_GENERAL_SCHEMA);
131 data->browser_settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
132 data->messages_settings = g_settings_new (GTHUMB_MESSAGES_SCHEMA);
133 data->dialog = dialog;
134
135 /* widgets */
136
137 gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("file_properties_position_combobox")),
138 g_settings_get_boolean (data->browser_settings, PREF_BROWSER_PROPERTIES_ON_THE_RIGHT) ? 1 : 0);
139
140 if (g_settings_get_boolean (data->browser_settings, PREF_BROWSER_USE_STARTUP_LOCATION))
141 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("use_startup_location_radiobutton")), TRUE);
142 else
143 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("go_to_last_location_radiobutton")), TRUE);
144
145 /* starup location */
146 {
147 char *uri;
148 GFile *location;
149
150 data->startup_location_chooser = g_object_new (
151 GTH_TYPE_LOCATION_CHOOSER,
152 "show-entry-points", FALSE,
153 "show-other", TRUE,
154 "relief", GTK_RELIEF_NORMAL,
155 NULL);
156 gtk_widget_show (data->startup_location_chooser);
157 gtk_box_pack_start (GTK_BOX (GET_WIDGET ("startup_location_chooser_box")),
158 data->startup_location_chooser,
159 TRUE,
160 TRUE,
161 0);
162
163 uri = _g_settings_get_uri (data->browser_settings, PREF_BROWSER_STARTUP_LOCATION);
164 if (uri == NULL)
165 uri = g_strdup (_g_uri_get_home ());
166 location = g_file_new_for_uri (uri);
167 gth_location_chooser_set_current (GTH_LOCATION_CHOOSER (data->startup_location_chooser), location);
168
169 g_object_unref (location);
170 g_free (uri);
171 }
172
173 if (! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("use_startup_location_radiobutton")))) {
174 gtk_widget_set_sensitive (data->startup_location_chooser, FALSE);
175 gtk_widget_set_sensitive (GET_WIDGET ("set_to_current_button"), FALSE);
176 }
177
178 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("reuse_active_window_checkbutton")),
179 g_settings_get_boolean (data->browser_settings, PREF_BROWSER_REUSE_ACTIVE_WINDOW));
180 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("confirm_deletion_checkbutton")),
181 g_settings_get_boolean (data->messages_settings, PREF_MSG_CONFIRM_DELETION));
182 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("ask_to_save_checkbutton")),
183 g_settings_get_boolean (data->messages_settings, PREF_MSG_SAVE_MODIFIED_IMAGE));
184 gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("thumbnails_pane_orient_combobox")),
185 g_settings_get_enum (data->browser_settings, PREF_BROWSER_VIEWER_THUMBNAILS_ORIENT));
186
187 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("embed_metadata_checkbutton")),
188 g_settings_get_boolean (data->general_settings, PREF_GENERAL_STORE_METADATA_IN_FILES));
189
190 /* signal handlers */
191
192 g_signal_connect (GET_WIDGET ("thumbnails_pane_orient_combobox"),
193 "changed",
194 G_CALLBACK (thumbnails_pane_orientation_changed_cb),
195 data);
196 g_signal_connect (GET_WIDGET ("file_properties_position_combobox"),
197 "changed",
198 G_CALLBACK (file_properties_position_combobox_changed_cb),
199 data);
200 g_signal_connect (G_OBJECT (GET_WIDGET ("use_startup_location_radiobutton")),
201 "toggled",
202 G_CALLBACK (use_startup_toggled_cb),
203 data);
204 g_signal_connect (G_OBJECT (GET_WIDGET ("set_to_current_button")),
205 "clicked",
206 G_CALLBACK (set_to_current_cb),
207 data);
208 g_signal_connect (G_OBJECT (GET_WIDGET ("reuse_active_window_checkbutton")),
209 "toggled",
210 G_CALLBACK (reuse_active_window_checkbutton_toggled_cb),
211 data);
212 g_signal_connect (G_OBJECT (GET_WIDGET ("confirm_deletion_checkbutton")),
213 "toggled",
214 G_CALLBACK (confirm_deletion_toggled_cb),
215 data);
216 g_signal_connect (G_OBJECT (GET_WIDGET ("ask_to_save_checkbutton")),
217 "toggled",
218 G_CALLBACK (ask_to_save_toggled_cb),
219 data);
220
221 g_object_set_data_full (G_OBJECT (dialog), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
222 }
223
224
225 void
general__dlg_preferences_apply(GtkWidget * dialog,GthBrowser * browser,GtkBuilder * dialog_builder)226 general__dlg_preferences_apply (GtkWidget *dialog,
227 GthBrowser *browser,
228 GtkBuilder *dialog_builder)
229 {
230 BrowserData *data;
231
232 data = g_object_get_data (G_OBJECT (dialog), BROWSER_DATA_KEY);
233 g_return_if_fail (data != NULL);
234
235 /* Startup dir. */
236
237 g_settings_set_boolean (data->browser_settings, PREF_BROWSER_GO_TO_LAST_LOCATION, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("go_to_last_location_radiobutton"))));
238 g_settings_set_boolean (data->browser_settings, PREF_BROWSER_USE_STARTUP_LOCATION, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("use_startup_location_radiobutton"))));
239 g_settings_set_boolean (data->general_settings, PREF_GENERAL_STORE_METADATA_IN_FILES, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("embed_metadata_checkbutton"))));
240
241 if (g_settings_get_boolean (data->browser_settings, PREF_BROWSER_USE_STARTUP_LOCATION)) {
242 GFile *location;
243
244 location = gth_location_chooser_get_current (GTH_LOCATION_CHOOSER (data->startup_location_chooser));
245 if (location != NULL) {
246 char *uri;
247
248 uri = g_file_get_uri (location);
249 _g_settings_set_uri (data->browser_settings, PREF_BROWSER_STARTUP_LOCATION, uri);
250 gth_pref_set_startup_location (uri);
251 g_free (uri);
252 }
253 }
254
255 }
256