4
* Copyright 2009 PCMan <pcman.tw@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
31
#include "app-config.h"
34
#define INIT_BOOL(b, st, name, changed_notify) init_bool(b, #name, G_STRUCT_OFFSET(st, name), changed_notify)
35
#define INIT_COMBO(b, st, name, changed_notify) init_combo(b, #name, G_STRUCT_OFFSET(st, name), changed_notify)
36
#define INIT_ICON_SIZES(b, name) init_icon_sizes(b, #name, G_STRUCT_OFFSET(FmConfig, name))
37
#define INIT_COLOR(b, st, name, changed_notify) init_color(b, #name, G_STRUCT_OFFSET(st, name), changed_notify)
38
#define INIT_SPIN(b, st, name, changed_notify) init_spin(b, #name, G_STRUCT_OFFSET(st, name), changed_notify)
39
#define INIT_ENTRY(b, st, name, changed_notify) init_entry(b, #name, G_STRUCT_OFFSET(st, name), changed_notify)
41
static GtkWidget* pref_dlg = NULL;
42
static GtkWidget* notebook = NULL;
44
static GtkWidget* icon_size_combo[3] = {0};
45
static GtkWidget* bookmark_combo = NULL
46
static GtkWidget* use_trash;
49
static GtkWidget* desktop_pref_dlg = NULL;
51
static void on_response(GtkDialog* dlg, int res, GtkWidget** pdlg)
53
gtk_widget_destroy(dlg);
55
pcmanfm_save_config();
58
static void on_icon_size_changed(GtkComboBox* combo, gpointer _off)
61
if(gtk_combo_box_get_active_iter(combo, &it))
63
gsize off = GPOINTER_TO_SIZE(_off);
64
int* val = (int*)G_STRUCT_MEMBER_P(fm_config, off);
66
GtkTreeModel* model = gtk_combo_box_get_model(combo);
67
gtk_tree_model_get(model, &it, 1, &size, -1);
70
const char* name = gtk_buildable_get_name((GtkBuildable*)combo);
72
fm_config_emit_changed(fm_config, name);
77
static void init_icon_sizes(GtkBuilder* builder, const char* name, gsize off)
79
GtkComboBox* combo = (GtkComboBox*)gtk_builder_get_object(builder, name);
80
GtkTreeModel* model = gtk_combo_box_get_model(combo);
82
int* val = (int*)G_STRUCT_MEMBER_P(fm_config, off);
83
gtk_tree_model_get_iter_first(model, &it);
84
gtk_combo_box_set_active_iter(combo, &it);
87
gtk_tree_model_get(model, &it, 1, &size, -1);
90
gtk_combo_box_set_active_iter(combo, &it);
93
}while(gtk_tree_model_iter_next(model, &it));
94
g_signal_connect(combo, "changed", G_CALLBACK(on_icon_size_changed), GSIZE_TO_POINTER(off));
97
static void on_combo_changed(GtkComboBox* combo, gpointer _off)
99
gsize off = GPOINTER_TO_SIZE(_off);
100
int* val = (int*)G_STRUCT_MEMBER_P(fm_config, off);
101
int sel = gtk_combo_box_get_active(combo);
104
const char* name = g_object_get_data((GObject*)combo, "changed");
106
name = gtk_buildable_get_name((GtkBuildable*)combo);
108
fm_config_emit_changed(fm_config, name);
112
static void init_combo(GtkBuilder* builder, const char* name, gsize off, const char* changed_notify)
114
GtkComboBox* combo = (GtkComboBox*)gtk_builder_get_object(builder, name);
115
int* val = (int*)G_STRUCT_MEMBER_P(fm_config, off);
117
g_object_set_data_full(combo, "changed", g_strdup(changed_notify), g_free);
118
gtk_combo_box_set_active(combo, *val);
119
g_signal_connect(combo, "changed", G_CALLBACK(on_combo_changed), GSIZE_TO_POINTER(off));
122
static void on_archiver_combo_changed(GtkComboBox* combo, gpointer user_data)
124
GtkTreeModel* model = gtk_combo_box_get_model(combo);
126
if(gtk_combo_box_get_active_iter(combo, &it))
128
FmArchiver* archiver;
129
gtk_tree_model_get(model, &it, 1, &archiver, -1);
132
g_free(fm_config->archiver);
133
fm_config->archiver = g_strdup(archiver->program);
134
fm_archiver_set_default(archiver);
135
fm_config_emit_changed(fm_config, "archiver");
140
/* archiver integration */
141
static void init_archiver_combo(GtkBuilder* builder)
143
GtkListStore* model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
144
GtkComboBox* combo = (GtkComboBox*)gtk_builder_get_object(builder, "archiver");
146
GList* archivers = fm_archiver_get_all();
147
FmArchiver* default_archiver = fm_archiver_get_default();
150
gtk_combo_box_set_model(combo, GTK_TREE_MODEL(model));
152
for(l = archivers; l; l=l->next)
154
FmArchiver* archiver = (FmArchiver*)l->data;
155
gtk_list_store_insert_with_values(model, &it, -1,
156
0, archiver->program,
158
if(archiver == default_archiver)
159
gtk_combo_box_set_active_iter(combo, &it);
161
g_object_unref(model);
162
g_signal_connect(combo, "changed", G_CALLBACK(on_archiver_combo_changed), NULL);
165
static void on_toggled(GtkToggleButton* btn, gpointer _off)
167
gsize off = GPOINTER_TO_SIZE(_off);
168
gboolean* val = (gboolean*)G_STRUCT_MEMBER_P(fm_config, off);
169
gboolean new_val = gtk_toggle_button_get_active(btn);
172
const char* name = g_object_get_data((GObject*)btn, "changed");
174
name = gtk_buildable_get_name((GtkBuildable*)btn);
176
fm_config_emit_changed(fm_config, name);
180
static void init_bool(GtkBuilder* b, const char* name, gsize off, const char* changed_notify)
182
GtkToggleButton* btn = GTK_TOGGLE_BUTTON(gtk_builder_get_object(b, name));
183
gboolean* val = (gboolean*)G_STRUCT_MEMBER_P(fm_config, off);
185
g_object_set_data_full(btn, "changed", g_strdup(changed_notify), g_free);
186
gtk_toggle_button_set_active(btn, *val);
187
g_signal_connect(btn, "toggled", G_CALLBACK(on_toggled), GSIZE_TO_POINTER(off));
190
static void on_color_set(GtkColorButton* btn, gpointer _off)
192
gsize off = GPOINTER_TO_SIZE(_off);
193
GdkColor* val = (GdkColor*)G_STRUCT_MEMBER_P(fm_config, off);
195
gtk_color_button_get_color(btn, &new_val);
196
if( !gdk_color_equal(val, &new_val) )
198
const char* name = g_object_get_data((GObject*)btn, "changed");
200
name = gtk_buildable_get_name((GtkBuildable*)btn);
202
fm_config_emit_changed(fm_config, name);
206
static void init_color(GtkBuilder* b, const char* name, gsize off, const char* changed_notify)
208
GtkFontButton* btn = GTK_FONT_BUTTON(gtk_builder_get_object(b, name));
209
GdkColor* val = (GdkColor*)G_STRUCT_MEMBER_P(fm_config, off);
211
g_object_set_data_full(btn, "changed", g_strdup(changed_notify), g_free);
212
gtk_color_button_set_color(btn, val);
213
g_signal_connect(btn, "color-set", G_CALLBACK(on_color_set), GSIZE_TO_POINTER(off));
216
static void on_spin_changed(GtkSpinButton* btn, gpointer _off)
218
gsize off = GPOINTER_TO_SIZE(_off);
219
guint* val = (guint*)G_STRUCT_MEMBER_P(fm_config, off);
220
gboolean new_val = gtk_spin_button_get_value(btn);
223
const char* name = g_object_get_data((GObject*)btn, "changed");
225
name = gtk_buildable_get_name((GtkBuildable*)btn);
227
fm_config_emit_changed(fm_config, name);
231
static void init_spin(GtkBuilder* b, const char* name, gsize off, const char* changed_notify)
233
GtkSpinButton* btn = GTK_SPIN_BUTTON(gtk_builder_get_object(b, name));
234
guint* val = (guint*)G_STRUCT_MEMBER_P(fm_config, off);
236
g_object_set_data_full(btn, "changed", g_strdup(changed_notify), g_free);
237
gtk_spin_button_set_value(btn, *val);
238
g_signal_connect(btn, "value-changed", G_CALLBACK(on_spin_changed), GSIZE_TO_POINTER(off));
241
static void on_entry_changed(GtkEntry* entry, gpointer _off)
243
gsize off = GPOINTER_TO_SIZE(_off);
244
gchar** val = (guint*)G_STRUCT_MEMBER_P(fm_config, off);
245
const char* new_val = gtk_entry_get_text(entry);
246
if(g_strcmp0(*val, new_val))
248
const char* name = g_object_get_data((GObject*)entry, "changed");
250
name = gtk_buildable_get_name((GtkBuildable*)entry);
252
*val = *new_val ? g_strdup(new_val) : NULL;
253
fm_config_emit_changed(fm_config, name);
257
static void init_entry(GtkBuilder* b, const char* name, gsize off, const char* changed_notify)
259
GtkSpinButton* btn = GTK_SPIN_BUTTON(gtk_builder_get_object(b, name));
260
gchar** val = (guint*)G_STRUCT_MEMBER_P(fm_config, off);
262
g_object_set_data_full(btn, "changed", g_strdup(changed_notify), g_free);
264
gtk_entry_set_text(btn, *val);
265
g_signal_connect(btn, "changed", G_CALLBACK(on_entry_changed), GSIZE_TO_POINTER(off));
268
void fm_edit_preference( GtkWindow* parent, int page )
272
GtkBuilder* builder = gtk_builder_new();
274
gtk_builder_add_from_file(builder, PACKAGE_UI_DIR "/pref.ui", NULL);
275
pref_dlg = gtk_builder_get_object(builder, "dlg");
276
notebook = gtk_builder_get_object(builder, "notebook");
278
INIT_BOOL(builder, FmConfig, single_click, NULL);
279
INIT_BOOL(builder, FmConfig, confirm_del, NULL);
280
INIT_BOOL(builder, FmConfig, use_trash, NULL);
282
INIT_BOOL(builder, FmConfig, show_thumbnail, NULL);
283
INIT_BOOL(builder, FmConfig, thumbnail_local, NULL);
284
INIT_SPIN(builder, FmConfig, thumbnail_max, NULL);
286
INIT_BOOL(builder, FmAppConfig, mount_on_startup, NULL);
287
INIT_BOOL(builder, FmAppConfig, mount_removable, NULL);
288
INIT_BOOL(builder, FmAppConfig, autorun, NULL);
290
INIT_BOOL(builder, FmAppConfig, always_show_tabs, NULL);
291
INIT_BOOL(builder, FmAppConfig, hide_close_btn, NULL);
292
INIT_BOOL(builder, FmConfig, si_unit, NULL);
294
INIT_COMBO(builder, FmAppConfig, bm_open_method, NULL);
295
INIT_COMBO(builder, FmAppConfig, view_mode, NULL);
297
INIT_ICON_SIZES(builder, big_icon_size);
298
INIT_ICON_SIZES(builder, small_icon_size);
299
INIT_ICON_SIZES(builder, thumbnail_size);
300
INIT_ICON_SIZES(builder, pane_icon_size);
302
INIT_ENTRY(builder, FmConfig, terminal, NULL);
303
INIT_ENTRY(builder, FmAppConfig, su_cmd, NULL);
305
/* archiver integration */
306
init_archiver_combo(builder);
308
g_signal_connect(pref_dlg, "response", G_CALLBACK(on_response), &pref_dlg);
309
g_object_unref(builder);
312
g_signal_connect(pref_dlg, "destroy", G_CALLBACK(pcmanfm_unref), NULL);
314
gtk_notebook_set_current_page(notebook, page);
315
gtk_window_present(pref_dlg);
318
static void on_wallpaper_set(GtkFileChooserButton* btn, gpointer user_data)
320
char* file = gtk_file_chooser_get_filename(btn);
321
g_free(app_config->wallpaper);
322
app_config->wallpaper = file;
323
fm_config_emit_changed(fm_config, "wallpaper");
326
static void on_update_img_preview( GtkFileChooser *chooser, GtkImage* img )
328
char* file = gtk_file_chooser_get_preview_filename( chooser );
329
GdkPixbuf* pix = NULL;
332
pix = gdk_pixbuf_new_from_file_at_scale( file, 128, 128, TRUE, NULL );
337
gtk_file_chooser_set_preview_widget_active(chooser, TRUE);
338
gtk_image_set_from_pixbuf( img, pix );
339
g_object_unref( pix );
343
gtk_image_clear( img );
344
gtk_file_chooser_set_preview_widget_active(chooser, FALSE);
348
static void on_desktop_font_set(GtkFontButton* btn, gpointer user_data)
350
const char* font = gtk_font_button_get_font_name(btn);
353
g_free(app_config->desktop_font);
354
app_config->desktop_font = g_strdup(font);
355
fm_config_emit_changed(fm_config, "desktop_font");
359
void fm_desktop_preference()
361
if(!desktop_pref_dlg)
363
GtkBuilder* builder = gtk_builder_new();
364
GtkWidget* item, *img_preview;
365
gtk_builder_add_from_file(builder, PACKAGE_UI_DIR "/desktop-pref.ui", NULL);
366
desktop_pref_dlg = gtk_builder_get_object(builder, "dlg");
368
item = gtk_builder_get_object(builder, "wallpaper");
369
g_signal_connect(item, "file-set", G_CALLBACK(on_wallpaper_set), NULL);
370
img_preview = gtk_image_new();
371
gtk_misc_set_alignment(img_preview, 0.5, 0.0);
372
gtk_widget_set_size_request( img_preview, 128, 128 );
373
gtk_file_chooser_set_preview_widget( (GtkFileChooser*)item, img_preview );
374
g_signal_connect( item, "update-preview", G_CALLBACK(on_update_img_preview), img_preview );
375
if(app_config->wallpaper)
376
gtk_file_chooser_set_filename(item, app_config->wallpaper);
378
INIT_COMBO(builder, FmAppConfig, wallpaper_mode, "wallpaper");
379
INIT_COLOR(builder, FmAppConfig, desktop_bg, "wallpaper");
381
INIT_COLOR(builder, FmAppConfig, desktop_fg, "desktop_text");
382
INIT_COLOR(builder, FmAppConfig, desktop_shadow, "desktop_text");
384
INIT_BOOL(builder, FmAppConfig, show_wm_menu, NULL);
386
item = gtk_builder_get_object(builder, "desktop_font");
387
if(app_config->desktop_font)
388
gtk_font_button_set_font_name(item, app_config->desktop_font);
389
g_signal_connect(item, "font-set", G_CALLBACK(on_desktop_font_set), NULL);
391
g_signal_connect(desktop_pref_dlg, "response", G_CALLBACK(on_response), &desktop_pref_dlg);
392
g_object_unref(builder);
395
g_signal_connect(desktop_pref_dlg, "destroy", G_CALLBACK(pcmanfm_unref), NULL);
397
gtk_window_present(desktop_pref_dlg);