2 * Preferences configuration page for the GNU Midnight Commander
5 * Jonathan Blandford (jrb@redhat.com)
23 #include "gcustom-layout.h"
24 #include "gdesktop-prefs.h"
25 #include "../vfs/vfs.h"
28 /* Orphan confirmation options */
30 /* use internal edit */ /* maybe have a mime-type capplet for these */
31 /* use internal view */
32 /* complete: show all */
35 /* cd follows links */
38 extern int vfs_timeout
;
39 extern int ftpfs_always_use_proxy
;
40 extern char* ftpfs_anonymous_passwd
;
41 extern int file_op_compute_totals
;
42 extern int we_can_afford_the_speed
;
56 gpointer property_variable
;
73 PrefsPage
*prefs_pages
;
75 GDesktopPrefs
*desktop_prefs
;
76 gint desktop_prefs_page
;
78 GCustomLayout
*custom_layout
;
79 gint custom_layout_page
;
83 #define PROPERTIES_DONE { NULL, PROPERTY_NONE, NULL, NULL, NULL, NULL }
84 #define PREFSPAGES_DONE { NULL, NULL }
86 typedef GtkWidget
* (*CustomCreateFunc
) (PrefsDlg
*dlg
, Property
*prop
);
87 typedef void (*CustomApplyFunc
) (PrefsDlg
*dlg
, Property
*prop
);
89 static Property file_display_props
[] =
92 N_("Show backup files"), PROPERTY_BOOL
,
93 &show_backups
, NULL
, NULL
, NULL
96 N_("Show hidden files"), PROPERTY_BOOL
,
97 &show_dot_files
, NULL
, NULL
, NULL
100 N_("Mix files and directories"), PROPERTY_BOOL
,
101 &mix_all_files
, NULL
, NULL
, NULL
104 N_("Use shell patterns instead of regular expressions"), PROPERTY_BOOL
,
105 &easy_patterns
, NULL
, NULL
, NULL
108 N_("Determine file types from file content instead of extensions"), PROPERTY_BOOL
,
109 &use_magic
, NULL
, NULL
, NULL
114 static Property confirmation_props
[] =
117 N_("Confirm when deleting file"), PROPERTY_BOOL
,
118 &confirm_delete
, NULL
, NULL
, NULL
121 N_("Confirm when overwriting files"), PROPERTY_BOOL
,
122 &confirm_overwrite
, NULL
, NULL
, NULL
125 N_("Confirm when executing files"), PROPERTY_BOOL
,
126 &confirm_execute
, NULL
, NULL
, NULL
129 N_("Show progress while operations are being performed"), PROPERTY_BOOL
,
130 &verbose
, NULL
, NULL
, NULL
136 static Property vfs_props
[] =
139 N_("VFS Timeout:"), PROPERTY_INT
,
140 &vfs_timeout
, N_("Seconds"), NULL
, NULL
143 N_("Anonymous FTP password:"), PROPERTY_STRING
,
144 &ftpfs_anonymous_passwd
, NULL
, NULL
, NULL
147 N_("Always use FTP proxy"), PROPERTY_BOOL
,
148 &ftpfs_always_use_proxy
, NULL
, NULL
, NULL
152 #endif /* !USE_VFS */
154 static Property caching_and_optimization_props
[] =
157 N_("Fast directory reload"), PROPERTY_BOOL
,
158 &fast_reload
, NULL
, NULL
, NULL
161 N_("Compute totals before copying files"), PROPERTY_BOOL
,
162 &file_op_compute_totals
, NULL
, NULL
, NULL
166 N_("FTP directory cache timeout :"), PROPERTY_INT
,
167 &ftpfs_directory_timeout
, N_("Seconds"), NULL
, NULL
169 #endif /* !USE_VFS */
171 N_("Allow customization of icons in icon view"), PROPERTY_BOOL
,
172 &we_can_afford_the_speed
, NULL
, NULL
, NULL
177 static PrefsPage prefs_pages
[] =
192 #endif /* !USE_VFS */
195 caching_and_optimization_props
201 apply_changes_bool (PrefsDlg
*dlg
, Property
*cur_prop
)
205 checkbox
= cur_prop
->widget
;
207 if (GTK_TOGGLE_BUTTON (checkbox
)->active
)
208 *( (int*) cur_prop
->property_variable
) = TRUE
;
210 *( (int*) cur_prop
->property_variable
) = FALSE
;
214 apply_changes_string (PrefsDlg
*dlg
, Property
*cur_prop
)
219 entry
= cur_prop
->widget
;
221 text
= gtk_entry_get_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (entry
))));
223 *( (char**) cur_prop
->property_variable
) = g_strdup (text
);
227 apply_changes_int (PrefsDlg
*dlg
, Property
*cur_prop
)
233 entry
= cur_prop
->widget
;
234 num
= gtk_entry_get_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (entry
))));
235 sscanf(num
,"%lg",&val
);
237 *( (int*) cur_prop
->property_variable
) = (gint
) val
;
241 apply_changes_custom (PrefsDlg
*dlg
, Property
*cur_prop
)
243 CustomApplyFunc apply
= (CustomApplyFunc
) cur_prop
->extra_data2
;
245 apply (dlg
, cur_prop
);
249 apply_page_changes (PrefsDlg
*dlg
, gint pagenum
)
255 props
= dlg
->prefs_pages
[pagenum
].props
;
257 cur_prop
= props
[i
];
258 while (cur_prop
.label
!= NULL
) {
259 switch (cur_prop
.type
) {
261 g_warning ("Invalid case in gprefs.c: apply_page_changes");
264 apply_changes_bool (dlg
, &cur_prop
);
266 case PROPERTY_STRING
:
267 apply_changes_string (dlg
, &cur_prop
);
270 apply_changes_int (dlg
, &cur_prop
);
272 case PROPERTY_CUSTOM
:
273 apply_changes_custom (dlg
, &cur_prop
);
276 cur_prop
= props
[++i
];
281 apply_callback (GtkWidget
*prop_box
, gint pagenum
, PrefsDlg
*dlg
)
283 if (pagenum
== dlg
->desktop_prefs_page
)
284 desktop_prefs_apply (dlg
->desktop_prefs
);
285 else if (pagenum
== dlg
->custom_layout_page
)
286 custom_layout_apply (dlg
->custom_layout
);
287 else if (pagenum
!= -1)
288 apply_page_changes (dlg
, pagenum
);
290 update_panels (UP_RELOAD
, UP_KEEPSEL
);
296 changed_callback (GtkWidget
*widget
, PrefsDlg
*dlg
)
299 gnome_property_box_changed (GNOME_PROPERTY_BOX (dlg
->prop_box
));
303 create_prop_bool (PrefsDlg
*dlg
, Property
*prop
)
307 checkbox
= gtk_check_button_new_with_label (_(prop
->label
));
309 if (*((int*) prop
->property_variable
)) {
310 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox
),
313 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox
),
317 gtk_signal_connect (GTK_OBJECT (checkbox
), "clicked",
318 changed_callback
, (gpointer
) dlg
);
320 prop
->widget
= checkbox
;
321 gtk_widget_show_all (checkbox
);
326 create_prop_string (PrefsDlg
*dlg
, Property
*prop
)
329 GtkWidget
*gtk_entry
;
334 hbox
= gtk_hbox_new (FALSE
, GNOME_PAD_SMALL
);
336 label
= gtk_label_new (_(prop
->label
));
337 gtk_box_pack_start (GTK_BOX (hbox
), label
,
340 entry
= gnome_entry_new (_(prop
->label
));
341 gtk_entry
= gnome_entry_gtk_entry (GNOME_ENTRY (entry
));
343 max_length
= (int)prop
->extra_data1
;
344 if (max_length
!= 0) {
345 gtk_entry_set_max_length (GTK_ENTRY (gtk_entry
),
349 gtk_entry_set_text (GTK_ENTRY (gtk_entry
),
350 (gchar
*) *( (gchar
**) prop
->property_variable
));
351 gtk_signal_connect_while_alive (GTK_OBJECT (gtk_entry
),
353 GTK_SIGNAL_FUNC (changed_callback
),
355 GTK_OBJECT (dlg
->prop_box
));
357 gtk_box_pack_start (GTK_BOX (hbox
), entry
,
360 prop
->widget
= entry
;
361 gtk_widget_show_all (hbox
);
366 create_prop_int (PrefsDlg
*dlg
, Property
*prop
)
373 hbox
= gtk_hbox_new (FALSE
, GNOME_PAD_SMALL
);
375 label
= gtk_label_new (_(prop
->label
));
376 gtk_box_pack_start (GTK_BOX (hbox
), label
,
379 entry
= gnome_entry_new (_(prop
->label
));
381 g_snprintf (buffer
, 9, "%d", *( (int*) prop
->property_variable
));
383 gtk_entry_set_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (entry
))),
386 gtk_signal_connect_while_alive (GTK_OBJECT (gnome_entry_gtk_entry (GNOME_ENTRY (entry
))),
388 GTK_SIGNAL_FUNC (changed_callback
),
390 GTK_OBJECT (dlg
->prop_box
));
392 gtk_box_pack_start (GTK_BOX (hbox
), entry
,
394 if (prop
->extra_data1
) {
395 label
= gtk_label_new (_((gchar
*)prop
->extra_data1
));
396 gtk_box_pack_start (GTK_BOX (hbox
), label
,
400 prop
->widget
= entry
;
401 gtk_widget_show_all (hbox
);
406 create_prop_custom (PrefsDlg
*dlg
, Property
*prop
)
408 CustomCreateFunc create
= (CustomCreateFunc
) prop
->extra_data1
;
411 return create_prop_bool (dlg
, prop
);
413 return create (dlg
, prop
);
417 create_prop_widget (PrefsDlg
*dlg
, Property
*prop
)
419 switch (prop
->type
) {
421 g_warning ("Invalid case in gprefs.c: create_prop_widget");
424 return create_prop_bool (dlg
, prop
);
425 case PROPERTY_STRING
:
426 return create_prop_string (dlg
, prop
);
428 return create_prop_int (dlg
, prop
);
429 case PROPERTY_CUSTOM
:
430 return create_prop_custom (dlg
, prop
);
437 create_page (PrefsDlg
*dlg
, PrefsPage
*page
)
440 GtkWidget
*prop_widget
;
444 vbox
= gtk_vbox_new (FALSE
, GNOME_PAD_SMALL
);
445 gtk_container_set_border_width (GTK_CONTAINER (vbox
), GNOME_PAD_SMALL
);
446 gtk_widget_show (vbox
);
448 cur_prop
= &(page
->props
[i
]);
449 while (cur_prop
->label
!= NULL
) {
450 cur_prop
= &(page
->props
[i
]);
451 prop_widget
= create_prop_widget (dlg
, cur_prop
);
452 gtk_box_pack_start (GTK_BOX (vbox
), prop_widget
,
455 cur_prop
= &(page
->props
[i
]);
458 gnome_property_box_append_page (GNOME_PROPERTY_BOX (dlg
->prop_box
),
460 gtk_label_new (_(page
->title
)));
463 /* Help callback for the preferences dialog */
465 help_callback (GnomePropertyBox
*pb
, gint page_num
, gpointer data
)
467 static GnomeHelpMenuEntry entry
= {
472 gnome_help_display (NULL
, &entry
);
476 create_prop_box (PrefsDlg
*dlg
)
481 dlg
->prop_box
= gnome_property_box_new ();
483 gnome_dialog_set_parent (GNOME_DIALOG (dlg
->prop_box
),
484 GTK_WINDOW (dlg
->panel
->xwindow
));
485 gtk_window_set_modal (GTK_WINDOW (dlg
->prop_box
), TRUE
);
486 gtk_window_set_title (GTK_WINDOW (dlg
->prop_box
), _("Preferences"));
489 cur_page
= &(dlg
->prefs_pages
[i
]);
490 while (cur_page
->title
!= NULL
) {
491 create_page (dlg
, cur_page
);
493 cur_page
= &(dlg
->prefs_pages
[i
]);
496 dlg
->desktop_prefs
= desktop_prefs_new (GNOME_PROPERTY_BOX (dlg
->prop_box
));
497 dlg
->desktop_prefs_page
= i
++;
500 dlg
->custom_layout
= custom_layout_create_page (
501 GNOME_PROPERTY_BOX (dlg
->prop_box
), dlg
->panel
);
503 dlg
->custom_layout_page
= i
;
505 gtk_signal_connect (GTK_OBJECT (dlg
->prop_box
), "apply",
506 GTK_SIGNAL_FUNC (apply_callback
), dlg
);
507 gtk_signal_connect (GTK_OBJECT (dlg
->prop_box
), "help",
508 GTK_SIGNAL_FUNC (help_callback
), dlg
);
512 gnome_configure_box_with_desktop (GtkWidget
*widget
, WPanel
*panel
,
518 dlg
.prefs_pages
= prefs_pages
;
520 create_prop_box (&dlg
);
523 gtk_notebook_set_page (
524 GTK_NOTEBOOK (GNOME_PROPERTY_BOX (
525 dlg
.prop_box
)->notebook
),
526 dlg
.desktop_prefs_page
);
527 gtk_widget_show (dlg
.prop_box
);
531 gnome_configure_box (GtkWidget
*widget
, WPanel
*panel
)
533 gnome_configure_box_with_desktop (widget
, panel
, FALSE
);