]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.C
Small fix from Angus
[lyx.git] / src / frontends / xforms / FormPreferences.C
1 /* FormPreferences.C
2  * FormPreferences Interface Class Implementation
3  */
4
5 #include <config.h>
6
7 #include FORMS_H_LOCATION
8
9 #ifdef __GNUG_
10 #pragma implementation
11 #endif
12
13 #include "FormPreferences.h"
14 #include "form_preferences.h"
15 #include "input_validators.h"
16 #include "LyXView.h"
17 #include "lyxfunc.h"
18 #include "Dialogs.h"
19 #include "lyxrc.h"
20 #include "debug.h"
21 #include "support/FileInfo.h"
22 #include "support/filetools.h"
23 #include "lyx_gui_misc.h"
24
25 #ifdef SIGC_CXX_NAMESPACES
26 using SigC::slot;
27 #endif
28
29
30 FormPreferences::FormPreferences(LyXView * lv, Dialogs * d)
31         : FormBaseBI(lv, d, _("Preferences"), new PreferencesPolicy),
32           dialog_(0), outputs_tab_(0), look_n_feel_tab_(0), inputs_tab_(0),
33           lnf_general_(0), screen_fonts_(0), interface_(0),
34           printer_(0), paths_(0), outputs_general_(0), minw_(0), minh_(0)
35 {
36         // let the dialog be shown
37         // This is a permanent connection so we won't bother
38         // storing a copy because we won't be disconnecting.
39         d->showPreferences.connect(slot(this, &FormPreferences::show));
40 }
41
42
43 FormPreferences::~FormPreferences()
44 {
45         delete dialog_;
46         delete look_n_feel_tab_;
47         delete inputs_tab_;
48         delete outputs_tab_;
49         delete lnf_general_;
50         delete screen_fonts_;
51         delete interface_;
52         delete printer_;
53         delete paths_;
54         delete outputs_general_;
55 }
56
57
58 void FormPreferences::hide()
59 {
60         // We need to hide the active tabfolder otherwise we get a
61         // BadDrawable error from X windows and LyX crashes without saving.
62         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder_prefs);
63         if (outer_form
64             && outer_form->visible) {
65                 fl_hide_form(outer_form);
66         }
67         FormBase::hide();
68 }
69
70
71 void FormPreferences::build()
72 {
73         dialog_ = build_preferences();
74
75         // manage the restore, save, apply and cancel/close buttons
76         bc_.setOK(dialog_->button_ok);
77         bc_.setApply(dialog_->button_apply);
78         bc_.setCancel(dialog_->button_cancel);
79         bc_.setUndoAll(dialog_->button_restore);
80         bc_.refresh();
81
82         // Workaround dumb xforms sizing bug
83         minw_ = dialog_->form->w;
84         minh_ = dialog_->form->h;
85
86         // build the tab folders
87         outputs_tab_ = build_outer_tab();
88         look_n_feel_tab_ = build_outer_tab();
89         inputs_tab_  = build_outer_tab();
90
91         // build actual tabfolder contents
92         // these will become nested tabfolders
93         screen_fonts_ = build_screen_fonts();
94         interface_ = build_interface();
95         lnf_general_ = build_lnf_general();
96         printer_ = build_printer();
97         paths_ = build_paths();
98         outputs_general_ = build_outputs_general();
99
100         // setup the input returns
101         // Lnf_General tab
102         fl_set_counter_return(lnf_general_->counter_autosave, FL_RETURN_CHANGED);
103         fl_set_counter_return(lnf_general_->counter_wm_jump, FL_RETURN_CHANGED);
104         // Screen fonts
105         fl_set_input_return(screen_fonts_->input_roman, FL_RETURN_CHANGED);
106         fl_set_input_return(screen_fonts_->input_sans, FL_RETURN_CHANGED);
107         fl_set_input_return(screen_fonts_->input_typewriter,
108                             FL_RETURN_CHANGED);
109         fl_set_input_return(screen_fonts_->input_screen_encoding,
110                             FL_RETURN_CHANGED);
111         fl_set_counter_return(screen_fonts_->counter_zoom, FL_RETURN_CHANGED);
112         fl_set_input_return(screen_fonts_->input_tiny, FL_RETURN_CHANGED);
113         fl_set_input_return(screen_fonts_->input_script, FL_RETURN_CHANGED);
114         fl_set_input_return(screen_fonts_->input_footnote, FL_RETURN_CHANGED);
115         fl_set_input_return(screen_fonts_->input_small, FL_RETURN_CHANGED);
116         fl_set_input_return(screen_fonts_->input_normal, FL_RETURN_CHANGED);
117         fl_set_input_return(screen_fonts_->input_large, FL_RETURN_CHANGED);
118         fl_set_input_return(screen_fonts_->input_larger, FL_RETURN_CHANGED);
119         fl_set_input_return(screen_fonts_->input_largest, FL_RETURN_CHANGED);
120         fl_set_input_return(screen_fonts_->input_huge, FL_RETURN_CHANGED);
121         fl_set_input_return(screen_fonts_->input_huger, FL_RETURN_CHANGED);
122         // interface
123         fl_set_input_return(interface_->input_popup_font,
124                             FL_RETURN_CHANGED);
125         fl_set_input_return(interface_->input_menu_font,
126                             FL_RETURN_CHANGED);
127         fl_set_input_return(interface_->input_popup_encoding,
128                             FL_RETURN_CHANGED);
129         fl_set_input_return(interface_->input_bind_file,
130                             FL_RETURN_CHANGED);
131         fl_set_input_return(interface_->input_ui_file,
132                             FL_RETURN_CHANGED);
133         // printer
134         fl_set_input_return(printer_->input_command, FL_RETURN_CHANGED);
135         fl_set_input_return(printer_->input_page_range, FL_RETURN_CHANGED);
136         fl_set_input_return(printer_->input_copies, FL_RETURN_CHANGED);
137         fl_set_input_return(printer_->input_reverse, FL_RETURN_CHANGED);
138         fl_set_input_return(printer_->input_to_printer, FL_RETURN_CHANGED);
139         fl_set_input_return(printer_->input_file_extension, FL_RETURN_CHANGED);
140         fl_set_input_return(printer_->input_spool_command, FL_RETURN_CHANGED);
141         fl_set_input_return(printer_->input_paper_type, FL_RETURN_CHANGED);
142         fl_set_input_return(printer_->input_even_pages, FL_RETURN_CHANGED);
143         fl_set_input_return(printer_->input_odd_pages, FL_RETURN_CHANGED);
144         fl_set_input_return(printer_->input_collated, FL_RETURN_CHANGED);
145         fl_set_input_return(printer_->input_landscape, FL_RETURN_CHANGED);
146         fl_set_input_return(printer_->input_to_file, FL_RETURN_CHANGED);
147         fl_set_input_return(printer_->input_extra_options, FL_RETURN_CHANGED);
148         fl_set_input_return(printer_->input_spool_prefix, FL_RETURN_CHANGED);
149         fl_set_input_return(printer_->input_paper_size, FL_RETURN_CHANGED);
150         fl_set_input_return(printer_->input_name, FL_RETURN_CHANGED);
151         // paths
152         fl_set_input_return(paths_->input_default_path, FL_RETURN_CHANGED);
153         fl_set_input_return(paths_->input_template_path, FL_RETURN_CHANGED);
154         fl_set_input_return(paths_->input_temp_dir, FL_RETURN_CHANGED);
155         fl_set_input_return(paths_->input_lastfiles, FL_RETURN_CHANGED);
156         fl_set_input_return(paths_->input_backup_path, FL_RETURN_CHANGED);
157         fl_set_counter_return(paths_->counter_lastfiles, FL_RETURN_CHANGED);
158         fl_set_input_return(paths_->input_serverpipe, FL_RETURN_CHANGED);
159         // outputs general
160         fl_set_counter_return(outputs_general_->counter_line_len,
161                               FL_RETURN_CHANGED);
162
163         // Now add them to the tabfolder
164         fl_addto_tabfolder(dialog_->tabfolder_prefs,
165                            _("Look and Feel"),
166                            look_n_feel_tab_->form);
167         fl_addto_tabfolder(dialog_->tabfolder_prefs,
168                            _("Inputs"),
169                            inputs_tab_->form);
170         fl_addto_tabfolder(dialog_->tabfolder_prefs,
171                            _("Outputs"),
172                            outputs_tab_->form);
173
174         // now build the nested tabfolders
175         // Starting with look and feel
176         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
177                            _("Screen Fonts"),
178                            screen_fonts_->form);
179         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
180                            _("Interface"),
181                            interface_->form);
182         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
183                            _("General"),
184                            lnf_general_->form);
185
186         // then build inputs
187         // Paths should probably go in a few outer_tab called Files
188         fl_addto_tabfolder(inputs_tab_->tabfolder_outer,
189                            _("Paths"),
190                            paths_->form);
191
192         // then building outputs
193         fl_addto_tabfolder(outputs_tab_->tabfolder_outer,
194                            _("Printer"),
195                            printer_->form);
196         fl_addto_tabfolder(outputs_tab_->tabfolder_outer,
197                            _("General"),
198                            outputs_general_->form);
199
200         // deactivate the various browse buttons because they
201         // currently aren't implemented
202         fl_deactivate_object(interface_->button_bind_file_browse);
203         fl_deactivate_object(interface_->button_ui_file_browse);
204         fl_deactivate_object(paths_->button_document_browse);
205         fl_deactivate_object(paths_->button_template_browse);
206         fl_deactivate_object(paths_->button_temp_dir_browse);
207         fl_deactivate_object(paths_->button_lastfiles_browse);
208         fl_deactivate_object(paths_->button_backup_path_browse);
209         fl_deactivate_object(paths_->button_serverpipe_browse);
210         fl_set_object_lcol(interface_->button_bind_file_browse, FL_INACTIVE);
211         fl_set_object_lcol(interface_->button_ui_file_browse, FL_INACTIVE);
212         fl_set_object_lcol(paths_->button_document_browse, FL_INACTIVE);
213         fl_set_object_lcol(paths_->button_template_browse, FL_INACTIVE);
214         fl_set_object_lcol(paths_->button_temp_dir_browse, FL_INACTIVE);
215         fl_set_object_lcol(paths_->button_lastfiles_browse, FL_INACTIVE);
216         fl_set_object_lcol(paths_->button_backup_path_browse, FL_INACTIVE);
217         fl_set_object_lcol(paths_->button_serverpipe_browse, FL_INACTIVE);
218 }
219
220
221 FL_FORM * FormPreferences::form() const
222 {
223         if (dialog_) return dialog_->form;
224         return 0;
225 }
226
227
228 void FormPreferences::connect()
229 {
230         FormBaseBI::connect();
231         fl_set_form_minsize(dialog_->form,
232                             minw_,
233                             minh_);
234 }
235
236
237 void FormPreferences::apply()
238 {
239         // set the new lyxrc entries
240         // many of these need to trigger other functions when the assignment
241         // is made.  For example, screen zoom and font types.  These could be
242         // handled either by signals/slots in lyxrc or just directly call the
243         // associated functions here.
244         // There are other problems with this scheme.  We really should check
245         // what we copy to make sure that it really is necessary to do things
246         // like update the screen fonts because that flushes the textcache
247         // and other stuff which may cost us a lot on slower/high-load machines.
248         
249         // Look 'n Feel General tab
250         lyxrc.show_banner = fl_get_button(lnf_general_->check_banner);
251         lyxrc.auto_region_delete = fl_get_button(lnf_general_->
252                                                  check_auto_region_delete);
253         lyxrc.exit_confirmation = fl_get_button(lnf_general_->check_exit_confirm);
254         lyxrc.display_shortcuts =
255                 fl_get_button(lnf_general_->check_display_shortcuts);
256         lyxrc.new_ask_filename = fl_get_button(lnf_general_->check_ask_new_file);
257         lyxrc.cursor_follows_scrollbar =
258                 fl_get_button(lnf_general_->check_cursor_follows_scrollbar);
259         lyxrc.autosave = static_cast<unsigned int>
260                 (fl_get_counter_value(lnf_general_->counter_autosave));
261         lyxrc.wheel_jump = static_cast<unsigned int>
262                 (fl_get_counter_value(lnf_general_->counter_wm_jump));
263         // Interface
264         lyxrc.popup_font_name =
265                 fl_get_input(interface_->input_popup_font);
266         lyxrc.menu_font_name = fl_get_input(interface_->input_menu_font);
267         lyxrc.font_norm_menu =
268                 fl_get_input(interface_->input_popup_encoding);
269         lyxrc.bind_file = fl_get_input(interface_->input_bind_file);
270         lyxrc.ui_file = fl_get_input(interface_->input_ui_file);
271         lyxrc.override_x_deadkeys =
272                 fl_get_button(interface_->check_override_x_dead_keys);
273         // Screen fonts
274         if (lyxrc.roman_font_name !=
275             fl_get_input(screen_fonts_->input_roman) ||
276             lyxrc.sans_font_name !=
277             fl_get_input(screen_fonts_->input_sans) ||
278             lyxrc.typewriter_font_name !=
279             fl_get_input(screen_fonts_->input_typewriter) ||
280             lyxrc.font_norm !=
281             fl_get_input(screen_fonts_->input_screen_encoding) ||
282             lyxrc.use_scalable_fonts !=
283             fl_get_button(screen_fonts_->check_scalable) ||
284             lyxrc.zoom != static_cast<unsigned int>
285             (fl_get_counter_value(screen_fonts_->counter_zoom)) ||
286             lyxrc.font_sizes[LyXFont::SIZE_TINY] !=
287             strToDbl(fl_get_input(screen_fonts_->input_tiny)) ||
288             lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] !=
289             strToDbl(fl_get_input(screen_fonts_->input_script)) ||
290             lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] !=
291             strToDbl(fl_get_input(screen_fonts_->input_footnote)) ||
292             lyxrc.font_sizes[LyXFont::SIZE_SMALL] !=
293             strToDbl(fl_get_input(screen_fonts_->input_small)) ||
294             lyxrc.font_sizes[LyXFont::SIZE_NORMAL] !=
295             strToDbl(fl_get_input(screen_fonts_->input_normal)) ||
296             lyxrc.font_sizes[LyXFont::SIZE_LARGE] !=
297             strToDbl(fl_get_input(screen_fonts_->input_large)) ||
298             lyxrc.font_sizes[LyXFont::SIZE_LARGER] !=
299             strToDbl(fl_get_input(screen_fonts_->input_larger)) ||
300             lyxrc.font_sizes[LyXFont::SIZE_LARGEST] !=
301             strToDbl(fl_get_input(screen_fonts_->input_largest)) ||
302             lyxrc.font_sizes[LyXFont::SIZE_HUGE] !=
303             strToDbl(fl_get_input(screen_fonts_->input_huge)) ||
304             lyxrc.font_sizes[LyXFont::SIZE_HUGER] !=
305             strToDbl(fl_get_input(screen_fonts_->input_huger))) {
306                 // Something has changed so copy all of them and then force
307                 // an update of the screen fonts (ie. redraw every buffer)
308                 lyxrc.roman_font_name = fl_get_input(screen_fonts_->input_roman);
309                 lyxrc.sans_font_name = fl_get_input(screen_fonts_->input_sans);
310                 lyxrc.typewriter_font_name = fl_get_input(screen_fonts_->
311                                                           input_typewriter);
312                 lyxrc.font_norm = fl_get_input(screen_fonts_->
313                                                input_screen_encoding);
314                 lyxrc.use_scalable_fonts =
315                         fl_get_button(screen_fonts_->check_scalable);
316                 lyxrc.zoom = static_cast<unsigned int>
317                         (fl_get_counter_value(screen_fonts_->counter_zoom));
318                 lyxrc.font_sizes[LyXFont::SIZE_TINY] = 
319                         strToDbl(fl_get_input(screen_fonts_->input_tiny));
320                 lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] =
321                         strToDbl(fl_get_input(screen_fonts_->input_script));
322                 lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] =
323                         strToDbl(fl_get_input(screen_fonts_->input_footnote));
324                 lyxrc.font_sizes[LyXFont::SIZE_SMALL] =
325                         strToDbl(fl_get_input(screen_fonts_->input_small));
326                 lyxrc.font_sizes[LyXFont::SIZE_NORMAL] =
327                         strToDbl(fl_get_input(screen_fonts_->input_normal));
328                 lyxrc.font_sizes[LyXFont::SIZE_LARGE] =
329                         strToDbl(fl_get_input(screen_fonts_->input_large));
330                 lyxrc.font_sizes[LyXFont::SIZE_LARGER] =
331                 strToDbl(fl_get_input(screen_fonts_->input_larger));
332                 lyxrc.font_sizes[LyXFont::SIZE_LARGEST] =
333                         strToDbl(fl_get_input(screen_fonts_->input_largest));
334                 lyxrc.font_sizes[LyXFont::SIZE_HUGE] =
335                         strToDbl(fl_get_input(screen_fonts_->input_huge));
336                 lyxrc.font_sizes[LyXFont::SIZE_HUGER] =
337                         strToDbl(fl_get_input(screen_fonts_->input_huger));
338                 // Now update the buffers
339                 // Can anything below here affect the redraw process?
340                 lv_->getLyXFunc()->Dispatch(LFUN_SCREEN_FONT_UPDATE);
341         }
342         // printer
343         lyxrc.print_adapt_output = fl_get_button(printer_->check_adapt_output);
344         lyxrc.print_command = fl_get_input(printer_->input_command);
345         lyxrc.print_pagerange_flag = fl_get_input(printer_->input_page_range);
346         lyxrc.print_copies_flag = fl_get_input(printer_->input_copies);
347         lyxrc.print_reverse_flag = fl_get_input(printer_->input_reverse);
348         lyxrc.print_to_printer = fl_get_input(printer_->input_to_printer);
349         lyxrc.print_file_extension =
350                 fl_get_input(printer_->input_file_extension);
351         lyxrc.print_spool_command =
352                 fl_get_input(printer_->input_spool_command);
353         lyxrc.print_paper_flag = fl_get_input(printer_->input_paper_type);
354         lyxrc.print_evenpage_flag = fl_get_input(printer_->input_even_pages);
355         lyxrc.print_oddpage_flag = fl_get_input(printer_->input_odd_pages);
356         lyxrc.print_collcopies_flag = fl_get_input(printer_->input_collated);
357         lyxrc.print_landscape_flag = fl_get_input(printer_->input_landscape);
358         lyxrc.print_to_file = fl_get_input(printer_->input_to_file);
359         lyxrc.print_extra_options =
360                 fl_get_input(printer_->input_extra_options);
361         lyxrc.print_spool_printerprefix =
362                 fl_get_input(printer_->input_spool_prefix);
363         lyxrc.print_paper_dimension_flag =
364                 fl_get_input(printer_->input_paper_size);
365         lyxrc.printer = fl_get_input(printer_->input_name);
366         // paths
367         lyxrc.document_path = fl_get_input(paths_->input_default_path);
368         lyxrc.template_path = fl_get_input(paths_->input_template_path);
369         lyxrc.tempdir_path = fl_get_input(paths_->input_temp_dir);
370         lyxrc.lastfiles = fl_get_input(paths_->input_lastfiles);
371         lyxrc.backupdir_path = fl_get_input(paths_->input_backup_path);
372         lyxrc.use_tempdir = fl_get_button(paths_->check_use_temp_dir);
373         lyxrc.check_lastfiles = fl_get_button(paths_->check_last_files);
374         lyxrc.make_backup = fl_get_button(paths_->check_make_backups);
375         lyxrc.num_lastfiles = static_cast<unsigned int>
376                 (fl_get_counter_value(paths_->counter_lastfiles));
377         lyxrc.lyxpipes = fl_get_input(paths_->input_serverpipe);
378         // outputs general
379         lyxrc.ascii_linelen = static_cast<unsigned int>
380                 (fl_get_counter_value(outputs_general_->counter_line_len));
381 }
382
383
384 // we can safely ignore the parameter because we can always update
385 void FormPreferences::update(bool)
386 {
387         if (dialog_) {
388                 // read lyxrc entries
389                 // Lnf_General tab
390                 fl_set_button(lnf_general_->check_banner,
391                               lyxrc.show_banner);
392                 fl_set_button(lnf_general_->check_auto_region_delete,
393                               lyxrc.auto_region_delete);
394                 fl_set_button(lnf_general_->check_exit_confirm,
395                               lyxrc.exit_confirmation);
396                 fl_set_button(lnf_general_->check_display_shortcuts,
397                               lyxrc.display_shortcuts);
398                 fl_set_button(lnf_general_->check_ask_new_file,
399                               lyxrc.new_ask_filename);
400                 fl_set_button(lnf_general_->check_cursor_follows_scrollbar,
401                               lyxrc.cursor_follows_scrollbar);
402                 fl_set_counter_value(lnf_general_->counter_autosave,
403                                      lyxrc.autosave);
404                 fl_set_counter_value(lnf_general_->counter_wm_jump,
405                                      lyxrc.wheel_jump);
406                 // Screen fonts
407                 fl_set_input(screen_fonts_->input_roman,
408                              lyxrc.roman_font_name.c_str());
409                 fl_set_input(screen_fonts_->input_sans,
410                              lyxrc.sans_font_name.c_str());
411                 fl_set_input(screen_fonts_->input_typewriter,
412                              lyxrc.typewriter_font_name.c_str());
413                 fl_set_input(screen_fonts_->input_screen_encoding,
414                              lyxrc.font_norm.c_str());
415                 fl_set_button(screen_fonts_->check_scalable,
416                              lyxrc.use_scalable_fonts);
417                 fl_set_counter_value(screen_fonts_->counter_zoom,
418                              lyxrc.zoom);
419                 fl_set_input(screen_fonts_->input_tiny,
420                              tostr(lyxrc.font_sizes[LyXFont::SIZE_TINY]).c_str());
421                 fl_set_input(screen_fonts_->input_script,
422                              tostr(lyxrc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
423                 fl_set_input(screen_fonts_->input_footnote,
424                              tostr(lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
425                 fl_set_input(screen_fonts_->input_small,
426                              tostr(lyxrc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
427                 fl_set_input(screen_fonts_->input_normal,
428                              tostr(lyxrc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
429                 fl_set_input(screen_fonts_->input_large,
430                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
431                 fl_set_input(screen_fonts_->input_larger,
432                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
433                 fl_set_input(screen_fonts_->input_largest,
434                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
435                 fl_set_input(screen_fonts_->input_huge,
436                              tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
437                 fl_set_input(screen_fonts_->input_huger,
438                              tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
439                 // interface
440                 fl_set_input(interface_->input_popup_font,
441                              lyxrc.popup_font_name.c_str());
442                 fl_set_input(interface_->input_menu_font,
443                              lyxrc.menu_font_name.c_str());
444                 fl_set_input(interface_->input_popup_encoding,
445                              lyxrc.font_norm_menu.c_str());
446                 fl_set_input(interface_->input_bind_file,
447                              lyxrc.bind_file.c_str());
448                 fl_set_input(interface_->input_ui_file,
449                              lyxrc.ui_file.c_str());
450                 fl_set_button(interface_->check_override_x_dead_keys,
451                               lyxrc.override_x_deadkeys);
452                 // printer
453                 fl_set_button(printer_->check_adapt_output,
454                               lyxrc.print_adapt_output);
455                 fl_set_input(printer_->input_command,
456                              lyxrc.print_command.c_str());
457                 fl_set_input(printer_->input_page_range,
458                              lyxrc.print_pagerange_flag.c_str());
459                 fl_set_input(printer_->input_copies,
460                              lyxrc.print_copies_flag.c_str());
461                 fl_set_input(printer_->input_reverse,
462                               lyxrc.print_reverse_flag.c_str());
463                 fl_set_input(printer_->input_to_printer,
464                              lyxrc.print_to_printer.c_str());
465                 fl_set_input(printer_->input_file_extension,
466                              lyxrc.print_file_extension.c_str());
467                 fl_set_input(printer_->input_spool_command,
468                              lyxrc.print_spool_command.c_str());
469                 fl_set_input(printer_->input_paper_type,
470                              lyxrc.print_paper_flag.c_str());
471                 fl_set_input(printer_->input_even_pages,
472                              lyxrc.print_evenpage_flag.c_str());
473                 fl_set_input(printer_->input_odd_pages,
474                              lyxrc.print_oddpage_flag.c_str());
475                 fl_set_input(printer_->input_collated,
476                              lyxrc.print_collcopies_flag.c_str());
477                 fl_set_input(printer_->input_landscape,
478                              lyxrc.print_landscape_flag.c_str());
479                 fl_set_input(printer_->input_to_file,
480                              lyxrc.print_to_file.c_str());
481                 fl_set_input(printer_->input_extra_options,
482                              lyxrc.print_extra_options.c_str());
483                 fl_set_input(printer_->input_spool_prefix,
484                              lyxrc.print_spool_printerprefix.c_str());
485                 fl_set_input(printer_->input_paper_size,
486                              lyxrc.print_paper_dimension_flag.c_str());
487                 fl_set_input(printer_->input_name,
488                              lyxrc.printer.c_str());
489                 // paths
490                 fl_set_input(paths_->input_default_path,
491                              lyxrc.document_path.c_str());
492                 fl_set_input(paths_->input_template_path,
493                              lyxrc.template_path.c_str());
494                 fl_set_input(paths_->input_temp_dir,
495                              lyxrc.tempdir_path.c_str());
496                 fl_set_input(paths_->input_lastfiles,
497                              lyxrc.lastfiles.c_str());
498                 fl_set_input(paths_->input_backup_path,
499                              lyxrc.backupdir_path.c_str());
500                 fl_set_button(paths_->check_use_temp_dir,
501                               lyxrc.use_tempdir);
502                 fl_set_button(paths_->check_last_files,
503                               lyxrc.check_lastfiles);           
504                 fl_set_button(paths_->check_make_backups,
505                               lyxrc.make_backup);
506                 fl_set_counter_value(paths_->counter_lastfiles,
507                                      lyxrc.num_lastfiles);
508                 fl_set_input(paths_->input_serverpipe, lyxrc.lyxpipes.c_str());
509                 // outputs general
510                 fl_set_counter_value(outputs_general_->counter_line_len,
511                                      lyxrc.ascii_linelen);
512
513         }
514 }
515
516
517 bool FormPreferences::input(FL_OBJECT *, long)
518 {
519         bool activate = true;
520         //
521         // whatever checks you need to ensure the user hasn't entered
522         // some totally ridiculous value somewhere.  Change activate to suit.
523         // comments before each test describe what is _valid_
524
525         // input path -- dir should exist, be writable & absolute
526         if (!AbsolutePath(fl_get_input(paths_->input_default_path))
527             || 1 != IsDirWriteable(fl_get_input(paths_->input_default_path))) {
528                 activate = false;
529                 lyxerr[Debug::GUI] << "Preferences: input path is wrong\n";
530         }
531
532         {
533                 // template_path should be a readable directory
534                 string temp(fl_get_input(paths_->input_template_path));
535                 FileInfo tp(temp);
536                 if (!AbsolutePath(temp)
537                     || !tp.isDir()
538                     || !tp.readable()) {
539                         activate = false;
540                         lyxerr[Debug::GUI] << "Preferences: template path is wrong\n";
541                 }
542         }
543
544         // tmpdir:  not used
545         //          || writable directory
546         if (fl_get_button(paths_->check_use_temp_dir)
547             && (1 != IsDirWriteable(fl_get_input(paths_->input_temp_dir))
548                 || !AbsolutePath(fl_get_input(paths_->input_temp_dir)))) {
549                 activate = false;
550                 lyxerr[Debug::GUI] << "Preferences: tmpdir is wrong\n";
551         }
552
553         // backupdir: not used
554         //            || empty
555         //            || writable dir
556         if (fl_get_button(paths_->check_make_backups)
557             && (!string(fl_get_input(paths_->input_backup_path)).empty()
558                 && (1 != IsDirWriteable(fl_get_input(paths_->
559                                                      input_backup_path))
560                     || !AbsolutePath(fl_get_input(paths_->
561                                                   input_backup_path))))) {
562                 activate = false;
563                 lyxerr[Debug::GUI] << "Preferences: backupdir is wrong\n";
564         }
565
566         // lastfiles: exists && writeable
567         //            || non-existent && isn't a dir
568 #ifdef WITH_WARNINGS
569 #warning incorrectly allows files in /, other tests might also do this
570 #endif
571         {
572                 string lastfiles(fl_get_input(paths_->input_lastfiles));
573                 FileInfo lf(lastfiles);
574                 if (!AbsolutePath(lastfiles)
575                     || 1 != IsDirWriteable(OnlyPath(lastfiles))
576                     || (lf.exist()
577                         && (lf.isDir()
578                             || !lf.writable()))) {
579                         activate = false;
580                         lyxerr[Debug::GUI] << "Preferences: lastfiles is wrong\n";
581                 }
582         }
583
584         // serverpipe:  empty
585         //              || non-existent && isn't a dir
586         //              || exists && writeable
587         // remember we append .in and .out later
588         if (!string(fl_get_input(paths_->input_serverpipe)).empty()) {
589                 string pipe(fl_get_input(paths_->input_serverpipe));
590                 FileInfo sp_in(pipe + ".in");
591                 FileInfo sp_out(pipe + ".out");
592                 if (!AbsolutePath(pipe)
593                     || 1 != IsDirWriteable(OnlyPath(pipe))
594                     || (sp_in.exist()
595                         && (!sp_in.writable()
596                             || sp_in.isDir()))
597                     || (sp_out.exist()
598                         && (!sp_out.writable()
599                             || sp_out.isDir()))) {
600                         activate = false;
601                         lyxerr[Debug::GUI] << "Preferences: Serverpipe is wrong\n";
602                 }
603         }
604
605         //  fontsizes -- tiny < script < footnote etc.
606         if (0.0 >= strToDbl(fl_get_input(screen_fonts_->input_tiny))
607             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_script))
608             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_footnote))
609             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_small))
610             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_normal))
611             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_large))
612             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_larger))
613             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_largest))
614             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huge))
615             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huger))) {
616                 // make sure they all have positive entries
617                 // Also note that an empty entry is returned as 0.0 by strToDbl
618                 activate = false;
619                 lyxerr[Debug::GUI] << "Preferences: Sizes are wrong\n";
620         } else if (strToDbl(fl_get_input(screen_fonts_->input_tiny)) >
621                    strToDbl(fl_get_input(screen_fonts_->input_script)) ||
622                    strToDbl(fl_get_input(screen_fonts_->input_script)) >
623                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) ||
624                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) >
625                    strToDbl(fl_get_input(screen_fonts_->input_small)) ||
626                    strToDbl(fl_get_input(screen_fonts_->input_small)) >
627                    strToDbl(fl_get_input(screen_fonts_->input_normal)) ||
628                    strToDbl(fl_get_input(screen_fonts_->input_normal)) >
629                    strToDbl(fl_get_input(screen_fonts_->input_large)) ||
630                    strToDbl(fl_get_input(screen_fonts_->input_large)) >
631                    strToDbl(fl_get_input(screen_fonts_->input_larger)) ||
632                    strToDbl(fl_get_input(screen_fonts_->input_larger)) >
633                    strToDbl(fl_get_input(screen_fonts_->input_largest)) ||
634                    strToDbl(fl_get_input(screen_fonts_->input_largest)) >
635                    strToDbl(fl_get_input(screen_fonts_->input_huge)) ||
636                    strToDbl(fl_get_input(screen_fonts_->input_huge)) >
637                    strToDbl(fl_get_input(screen_fonts_->input_huger))) {
638                 activate = false;
639                 lyxerr[Debug::GUI] << "Preferences: Sizes are wrong\n";
640         }
641
642         return activate;
643 }
644
645
646 void FormPreferences::ok()
647 {
648         FormBase::ok();
649         lv_->getLyXFunc()->Dispatch(LFUN_SAVEPREFERENCES);
650 }
651
652
653 void FormPreferences::restore()
654 {
655         update();
656 // if I add an error message line to the dialog it'll have to be controlled
657 // within input().  I don't need it yet so I'll leave it commented out.
658 //      bc_.valid(input(0));
659 }