]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrefs.cpp
more of that
[lyx.git] / src / frontends / qt4 / GuiPrefs.cpp
1 /**
2  * \file GuiPrefs.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Bo Peng
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiPrefs.h"
15
16 #include "qt_helpers.h"
17 #include "GuiApplication.h"
18 #include "GuiFontLoader.h"
19
20 #include "BufferList.h"
21 #include "Color.h"
22 #include "ConverterCache.h"
23 #include "FileDialog.h"
24 #include "FuncRequest.h"
25 #include "GuiFontExample.h"
26 #include "GuiKeySymbol.h"
27 #include "KeyMap.h"
28 #include "KeySequence.h"
29 #include "LyXAction.h"
30 #include "PanelStack.h"
31 #include "paper.h"
32 #include "Session.h"
33
34 #include "support/debug.h"
35 #include "support/FileFilterList.h"
36 #include "support/FileName.h"
37 #include "support/filetools.h"
38 #include "support/gettext.h"
39 #include "support/lstrings.h"
40 #include "support/os.h"
41 #include "support/Package.h"
42
43 #include "graphics/GraphicsTypes.h"
44
45 #include "frontends/alert.h"
46 #include "frontends/Application.h"
47
48 #include <QCheckBox>
49 #include <QColorDialog>
50 #include <QFontDatabase>
51 #include <QHeaderView>
52 #include <QLineEdit>
53 #include <QPixmapCache>
54 #include <QPushButton>
55 #include <QSpinBox>
56 #include <QString>
57 #include <QTreeWidget>
58 #include <QTreeWidgetItem>
59 #include <QValidator>
60
61 #include <iomanip>
62 #include <sstream>
63 #include <algorithm>
64
65 using namespace Ui;
66
67 using namespace std;
68 using namespace lyx::support;
69 using namespace lyx::support::os;
70
71 namespace lyx {
72 namespace frontend {
73
74 /////////////////////////////////////////////////////////////////////
75 //
76 // Browser Helpers
77 //
78 /////////////////////////////////////////////////////////////////////
79
80 FileName libFileSearch(QString const & dir, QString const & name,
81                                 QString const & ext = QString())
82 {
83         return support::libFileSearch(fromqstr(dir), fromqstr(name), fromqstr(ext));
84 }
85
86
87 /** Launch a file dialog and return the chosen file.
88         filename: a suggested filename.
89         title: the title of the dialog.
90         pattern: *.ps etc.
91         dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
92 */
93 QString browseFile(QString const & filename,
94         QString const & title,
95         support::FileFilterList const & filters,
96         bool save = false,
97         QString const & label1 = QString(),
98         QString const & dir1 = QString(),
99         QString const & label2 = QString(),
100         QString const & dir2 = QString())
101 {
102         QString lastPath = ".";
103         if (!filename.isEmpty())
104                 lastPath = onlyPath(filename);
105
106         FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
107         dlg.setButton2(label1, dir1);
108         dlg.setButton2(label2, dir2);
109
110         FileDialog::Result result;
111
112         if (save)
113                 result = dlg.save(lastPath, filters, onlyFilename(filename));
114         else
115                 result = dlg.open(lastPath, filters, onlyFilename(filename));
116
117         return result.second;
118 }
119
120
121 /** Wrapper around browseFile which tries to provide a filename
122 *  relative to the user or system directory. The dir, name and ext
123 *  parameters have the same meaning as in the
124 *  support::LibFileSearch function.
125 */
126 QString browseLibFile(QString const & dir,
127         QString const & name,
128         QString const & ext,
129         QString const & title,
130         support::FileFilterList const & filters)
131 {
132         // FIXME UNICODE
133         QString const label1 = qt_("System files|#S#s");
134         QString const dir1 =
135                 toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
136
137         QString const label2 = qt_("User files|#U#u");
138         QString const dir2 =
139                 toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
140
141         QString const result = browseFile(toqstr(
142                 libFileSearch(dir, name, ext).absFilename()),
143                 title, filters, false, dir1, dir2);
144
145         // remove the extension if it is the default one
146         QString noextresult;
147         if (toqstr(getExtension(fromqstr(result))) == ext)
148                 noextresult = toqstr(removeExtension(fromqstr(result)));
149         else
150                 noextresult = result;
151
152         // remove the directory, if it is the default one
153         QString const file = onlyFilename(noextresult);
154         if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
155                 return file;
156         else
157                 return noextresult;
158 }
159
160
161 /** Launch a file dialog and return the chosen directory.
162         pathname: a suggested pathname.
163         title: the title of the dialog.
164         dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
165 */
166 QString browseDir(QString const & pathname,
167         QString const & title,
168         QString const & label1 = QString(),
169         QString const & dir1 = QString(),
170         QString const & label2 = QString(),
171         QString const & dir2 = QString())
172 {
173         QString lastPath = ".";
174         if (!pathname.isEmpty())
175                 lastPath = onlyPath(pathname);
176
177         FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
178         dlg.setButton1(label1, dir1);
179         dlg.setButton2(label2, dir2);
180
181         FileDialog::Result const result =
182                 dlg.opendir(lastPath, onlyFilename(pathname));
183
184         return result.second;
185 }
186
187
188 } // namespace frontend
189
190 QString browseRelFile(QString const & filename, QString const & refpath,
191         QString const & title, FileFilterList const & filters, bool save,
192         QString const & label1, QString const & dir1,
193         QString const & label2, QString const & dir2)
194 {
195         QString const fname = toqstr(makeAbsPath(
196                 fromqstr(filename), fromqstr(refpath)).absFilename());
197
198         QString const outname =
199                 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
200
201         QString const reloutname =
202                 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
203
204         if (reloutname.startsWith("../"))
205                 return outname;
206         else
207                 return reloutname;
208 }
209
210
211 /////////////////////////////////////////////////////////////////////
212 //
213 // Helpers
214 //
215 /////////////////////////////////////////////////////////////////////
216
217 namespace frontend {
218
219 template<class A>
220 static size_t findPos_helper(vector<A> const & vec, A const & val)
221 {
222         typedef typename vector<A>::const_iterator Cit;
223
224         Cit it = find(vec.begin(), vec.end(), val);
225         if (it == vec.end())
226                 return 0;
227         return distance(vec.begin(), it);
228 }
229
230
231 static void parseFontName(QString const & mangled0,
232         string & name, string & foundry)
233 {
234         string mangled = fromqstr(mangled0);
235         size_t const idx = mangled.find('[');
236         if (idx == string::npos || idx == 0) {
237                 name = mangled;
238                 foundry.clear();
239         } else {
240                 name = mangled.substr(0, idx - 1),
241                 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
242         }
243 }
244
245
246 static void setComboxFont(QComboBox * cb, string const & family,
247         string const & foundry)
248 {
249         QString fontname = toqstr(family);
250         if (!foundry.empty())
251                 fontname += " [" + toqstr(foundry) + ']';
252
253         for (int i = 0; i != cb->count(); ++i) {
254                 if (cb->itemText(i) == fontname) {
255                         cb->setCurrentIndex(i);
256                         return;
257                 }
258         }
259
260         // Try matching without foundry name
261
262         // We count in reverse in order to prefer the Xft foundry
263         for (int i = cb->count(); --i >= 0;) {
264                 string name, foundry;
265                 parseFontName(cb->itemText(i), name, foundry);
266                 if (compare_ascii_no_case(name, family) == 0) {
267                         cb->setCurrentIndex(i);
268                         return;
269                 }
270         }
271
272         // family alone can contain e.g. "Helvetica [Adobe]"
273         string tmpname, tmpfoundry;
274         parseFontName(toqstr(family), tmpname, tmpfoundry);
275
276         // We count in reverse in order to prefer the Xft foundry
277         for (int i = cb->count(); --i >= 0; ) {
278                 string name, foundry;
279                 parseFontName(cb->itemText(i), name, foundry);
280                 if (compare_ascii_no_case(name, foundry) == 0) {
281                         cb->setCurrentIndex(i);
282                         return;
283                 }
284         }
285
286         // Bleh, default fonts, and the names couldn't be found. Hack
287         // for bug 1063.
288
289         QFont font;
290         font.setKerning(false);
291
292         QString const font_family = toqstr(family);
293         if (font_family == guiApp->romanFontName()) {
294                 font.setStyleHint(QFont::Serif);
295                 font.setFamily(font_family);
296         } else if (font_family == guiApp->sansFontName()) {
297                 font.setStyleHint(QFont::SansSerif);
298                 font.setFamily(font_family);
299         } else if (font_family == guiApp->typewriterFontName()) {
300                 font.setStyleHint(QFont::TypeWriter);
301                 font.setFamily(font_family);
302         } else {
303                 lyxerr << "FAILED to find the default font: '"
304                        << foundry << "', '" << family << '\''<< endl;
305                 return;
306         }
307
308         QFontInfo info(font);
309         string default_font_name, dummyfoundry;
310         parseFontName(info.family(), default_font_name, dummyfoundry);
311         lyxerr << "Apparent font is " << default_font_name << endl;
312
313         for (int i = 0; i < cb->count(); ++i) {
314                 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
315                 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
316                                     default_font_name) == 0) {
317                         cb->setCurrentIndex(i);
318                         return;
319                 }
320         }
321
322         lyxerr << "FAILED to find the font: '"
323                << foundry << "', '" << family << '\'' <<endl;
324 }
325
326
327 /////////////////////////////////////////////////////////////////////
328 //
329 // PrefPlaintext
330 //
331 /////////////////////////////////////////////////////////////////////
332
333 PrefPlaintext::PrefPlaintext(QWidget * parent)
334         : PrefModule(qt_("Plain text"), 0, parent)
335 {
336         setupUi(this);
337         connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
338                 this, SIGNAL(changed()));
339         connect(plaintextRoffED, SIGNAL(textChanged(QString)),
340                 this, SIGNAL(changed()));
341 }
342
343
344 void PrefPlaintext::apply(LyXRC & rc) const
345 {
346         rc.plaintext_linelen = plaintextLinelengthSB->value();
347         rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
348 }
349
350
351 void PrefPlaintext::update(LyXRC const & rc)
352 {
353         plaintextLinelengthSB->setValue(rc.plaintext_linelen);
354         plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
355 }
356
357
358 /////////////////////////////////////////////////////////////////////
359 //
360 // PrefDate
361 //
362 /////////////////////////////////////////////////////////////////////
363
364 PrefDate::PrefDate(QWidget * parent)
365         : PrefModule(qt_("Date format"), 0, parent)
366 {
367         setupUi(this);
368         connect(DateED, SIGNAL(textChanged(QString)),
369                 this, SIGNAL(changed()));
370 }
371
372
373 void PrefDate::apply(LyXRC & rc) const
374 {
375         rc.date_insert_format = fromqstr(DateED->text());
376 }
377
378
379 void PrefDate::update(LyXRC const & rc)
380 {
381         DateED->setText(toqstr(rc.date_insert_format));
382 }
383
384
385 /////////////////////////////////////////////////////////////////////
386 //
387 // PrefInput
388 //
389 /////////////////////////////////////////////////////////////////////
390
391 PrefInput::PrefInput(GuiPreferences * form, QWidget * parent)
392         : PrefModule(qt_("Keyboard/Mouse"), form, parent)
393 {
394         setupUi(this);
395
396         connect(keymapCB, SIGNAL(clicked()),
397                 this, SIGNAL(changed()));
398         connect(firstKeymapED, SIGNAL(textChanged(QString)),
399                 this, SIGNAL(changed()));
400         connect(secondKeymapED, SIGNAL(textChanged(QString)),
401                 this, SIGNAL(changed()));
402         connect(inlineDelaySB, SIGNAL(valueChanged(double)),
403                 this, SIGNAL(changed()));
404         connect(inlineMathCB, SIGNAL(clicked()),
405                 this, SIGNAL(changed()));
406         connect(inlineTextCB, SIGNAL(clicked()),
407                 this, SIGNAL(changed()));
408         connect(inlineDotsCB, SIGNAL(clicked()),
409                 this, SIGNAL(changed()));
410         connect(popupDelaySB, SIGNAL(valueChanged(double)),
411                 this, SIGNAL(changed()));
412         connect(popupMathCB, SIGNAL(clicked()),
413                 this, SIGNAL(changed()));
414         connect(popupTextCB, SIGNAL(clicked()),
415                 this, SIGNAL(changed()));
416         connect(popupAfterCompleteCB, SIGNAL(clicked()),
417                 this, SIGNAL(changed()));
418         connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
419                 this, SIGNAL(changed()));
420 }
421
422
423 void PrefInput::apply(LyXRC & rc) const
424 {
425         // FIXME: can derive CB from the two EDs
426         rc.use_kbmap = keymapCB->isChecked();
427         rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
428         rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
429         rc.completion_inline_delay = inlineDelaySB->value();
430         rc.completion_inline_math = inlineMathCB->isChecked();
431         rc.completion_inline_text = inlineTextCB->isChecked();
432         rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
433         rc.completion_popup_delay = popupDelaySB->value();
434         rc.completion_popup_math = popupMathCB->isChecked();
435         rc.completion_popup_text = popupTextCB->isChecked();
436         rc.completion_popup_after_complete
437         = popupAfterCompleteCB->isChecked();
438         rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
439 }
440
441
442 void PrefInput::update(LyXRC const & rc)
443 {
444         // FIXME: can derive CB from the two EDs
445         keymapCB->setChecked(rc.use_kbmap);
446         firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
447         secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
448         inlineDelaySB->setValue(rc.completion_inline_delay);
449         inlineMathCB->setChecked(rc.completion_inline_math);
450         inlineTextCB->setChecked(rc.completion_inline_text);
451         inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
452         popupDelaySB->setValue(rc.completion_popup_delay);
453         popupMathCB->setChecked(rc.completion_popup_math);
454         popupTextCB->setChecked(rc.completion_popup_text);
455         popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
456         mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
457 }
458
459
460 QString PrefInput::testKeymap(QString keymap)
461 {
462         return form_->browsekbmap(toqstr(internal_path(fromqstr(keymap))));
463 }
464
465
466 void PrefInput::on_firstKeymapPB_clicked(bool)
467 {
468         QString const file = testKeymap(firstKeymapED->text());
469         if (!file.isEmpty())
470                 firstKeymapED->setText(file);
471 }
472
473
474 void PrefInput::on_secondKeymapPB_clicked(bool)
475 {
476         QString const file = testKeymap(secondKeymapED->text());
477         if (!file.isEmpty())
478                 secondKeymapED->setText(file);
479 }
480
481
482 void PrefInput::on_keymapCB_toggled(bool keymap)
483 {
484         firstKeymapLA->setEnabled(keymap);
485         secondKeymapLA->setEnabled(keymap);
486         firstKeymapED->setEnabled(keymap);
487         secondKeymapED->setEnabled(keymap);
488         firstKeymapPB->setEnabled(keymap);
489         secondKeymapPB->setEnabled(keymap);
490 }
491
492
493 /////////////////////////////////////////////////////////////////////
494 //
495 // PrefLatex
496 //
497 /////////////////////////////////////////////////////////////////////
498
499 PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
500         : PrefModule(qt_("LaTeX"), form, parent)
501 {
502         setupUi(this);
503         connect(latexEncodingED, SIGNAL(textChanged(QString)),
504                 this, SIGNAL(changed()));
505         connect(latexChecktexED, SIGNAL(textChanged(QString)),
506                 this, SIGNAL(changed()));
507         connect(latexBibtexED, SIGNAL(textChanged(QString)),
508                 this, SIGNAL(changed()));
509         connect(latexIndexED, SIGNAL(textChanged(QString)),
510                 this, SIGNAL(changed()));
511         connect(latexAutoresetCB, SIGNAL(clicked()),
512                 this, SIGNAL(changed()));
513         connect(latexDviPaperED, SIGNAL(textChanged(QString)),
514                 this, SIGNAL(changed()));
515         connect(latexPaperSizeCO, SIGNAL(activated(int)),
516                 this, SIGNAL(changed()));
517
518 #if defined(__CYGWIN__) || defined(_WIN32)
519         pathCB->setVisible(true);
520         connect(pathCB, SIGNAL(clicked()), 
521                 this, SIGNAL(changed()));
522 #else
523         pathCB->setVisible(false);
524 #endif
525 }
526
527
528 void PrefLatex::apply(LyXRC & rc) const
529 {
530         rc.fontenc = fromqstr(latexEncodingED->text());
531         rc.chktex_command = fromqstr(latexChecktexED->text());
532         rc.bibtex_command = fromqstr(latexBibtexED->text());
533         rc.index_command = fromqstr(latexIndexED->text());
534         rc.auto_reset_options = latexAutoresetCB->isChecked();
535         rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
536         rc.default_papersize =
537                 form_->toPaperSize(latexPaperSizeCO->currentIndex());
538 #if defined(__CYGWIN__) || defined(_WIN32)
539         rc.windows_style_tex_paths = pathCB->isChecked();
540 #endif
541 }
542
543
544 void PrefLatex::update(LyXRC const & rc)
545 {
546         latexEncodingED->setText(toqstr(rc.fontenc));
547         latexChecktexED->setText(toqstr(rc.chktex_command));
548         latexBibtexED->setText(toqstr(rc.bibtex_command));
549         latexIndexED->setText(toqstr(rc.index_command));
550         latexAutoresetCB->setChecked(rc.auto_reset_options);
551         latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
552         latexPaperSizeCO->setCurrentIndex(
553                 form_->fromPaperSize(rc.default_papersize));
554 #if defined(__CYGWIN__) || defined(_WIN32)
555         pathCB->setChecked(rc.windows_style_tex_paths);
556 #endif
557 }
558
559
560 /////////////////////////////////////////////////////////////////////
561 //
562 // PrefScreenFonts
563 //
564 /////////////////////////////////////////////////////////////////////
565
566 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
567         : PrefModule(qt_("Screen fonts"), form, parent)
568 {
569         setupUi(this);
570
571         connect(screenRomanCO, SIGNAL(activated(QString)),
572                 this, SLOT(select_roman(QString)));
573         connect(screenSansCO, SIGNAL(activated(QString)),
574                 this, SLOT(select_sans(QString)));
575         connect(screenTypewriterCO, SIGNAL(activated(QString)),
576                 this, SLOT(select_typewriter(QString)));
577
578         QFontDatabase fontdb;
579         QStringList families(fontdb.families());
580         for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
581                 screenRomanCO->addItem(*it);
582                 screenSansCO->addItem(*it);
583                 screenTypewriterCO->addItem(*it);
584         }
585         connect(screenRomanCO, SIGNAL(activated(QString)),
586                 this, SIGNAL(changed()));
587         connect(screenSansCO, SIGNAL(activated(QString)),
588                 this, SIGNAL(changed()));
589         connect(screenTypewriterCO, SIGNAL(activated(QString)),
590                 this, SIGNAL(changed()));
591         connect(screenZoomSB, SIGNAL(valueChanged(int)),
592                 this, SIGNAL(changed()));
593         connect(screenDpiSB, SIGNAL(valueChanged(int)),
594                 this, SIGNAL(changed()));
595         connect(screenTinyED, SIGNAL(textChanged(QString)),
596                 this, SIGNAL(changed()));
597         connect(screenSmallestED, SIGNAL(textChanged(QString)),
598                 this, SIGNAL(changed()));
599         connect(screenSmallerED, SIGNAL(textChanged(QString)),
600                 this, SIGNAL(changed()));
601         connect(screenSmallED, SIGNAL(textChanged(QString)),
602                 this, SIGNAL(changed()));
603         connect(screenNormalED, SIGNAL(textChanged(QString)),
604                 this, SIGNAL(changed()));
605         connect(screenLargeED, SIGNAL(textChanged(QString)),
606                 this, SIGNAL(changed()));
607         connect(screenLargerED, SIGNAL(textChanged(QString)),
608                 this, SIGNAL(changed()));
609         connect(screenLargestED, SIGNAL(textChanged(QString)),
610                 this, SIGNAL(changed()));
611         connect(screenHugeED, SIGNAL(textChanged(QString)),
612                 this, SIGNAL(changed()));
613         connect(screenHugerED, SIGNAL(textChanged(QString)),
614                 this, SIGNAL(changed()));
615         connect(pixmapCacheCB, SIGNAL(toggled(bool)),
616                 this, SIGNAL(changed()));
617
618         screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
619         screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
620         screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
621         screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
622         screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
623         screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
624         screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
625         screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
626         screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
627         screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
628 }
629
630
631 void PrefScreenFonts::apply(LyXRC & rc) const
632 {
633         LyXRC const oldrc = rc;
634
635         parseFontName(screenRomanCO->currentText(),
636                 rc.roman_font_name, rc.roman_font_foundry);
637         parseFontName(screenSansCO->currentText(),
638                 rc.sans_font_name, rc.sans_font_foundry);
639         parseFontName(screenTypewriterCO->currentText(),
640                 rc.typewriter_font_name, rc.typewriter_font_foundry);
641
642         rc.zoom = screenZoomSB->value();
643         rc.dpi = screenDpiSB->value();
644         rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
645         rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
646         rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
647         rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
648         rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
649         rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
650         rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
651         rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
652         rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
653         rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
654         rc.use_pixmap_cache = pixmapCacheCB->isChecked();
655
656         if (rc.font_sizes != oldrc.font_sizes
657                 || rc.roman_font_name != oldrc.roman_font_name
658                 || rc.sans_font_name != oldrc.sans_font_name
659                 || rc.typewriter_font_name != oldrc.typewriter_font_name
660                 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
661                 // The global QPixmapCache is used in GuiPainter to cache text
662                 // painting so we must reset it in case any of the above
663                 // parameter is changed.
664                 QPixmapCache::clear();
665                 guiApp->fontLoader().update();
666                 form_->updateScreenFonts();
667         }
668 }
669
670
671 void PrefScreenFonts::update(LyXRC const & rc)
672 {
673         setComboxFont(screenRomanCO, rc.roman_font_name,
674                         rc.roman_font_foundry);
675         setComboxFont(screenSansCO, rc.sans_font_name,
676                         rc.sans_font_foundry);
677         setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
678                         rc.typewriter_font_foundry);
679
680         select_roman(screenRomanCO->currentText());
681         select_sans(screenSansCO->currentText());
682         select_typewriter(screenTypewriterCO->currentText());
683
684         screenZoomSB->setValue(rc.zoom);
685         screenDpiSB->setValue(rc.dpi);
686         screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
687         screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
688         screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
689         screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
690         screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
691         screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
692         screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
693         screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
694         screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
695         screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
696
697         pixmapCacheCB->setChecked(rc.use_pixmap_cache);
698 #if defined(Q_WS_X11)
699         pixmapCacheCB->setEnabled(false);
700 #endif
701         
702 }
703
704
705 void PrefScreenFonts::select_roman(const QString & name)
706 {
707         screenRomanFE->set(QFont(name), name);
708 }
709
710
711 void PrefScreenFonts::select_sans(const QString & name)
712 {
713         screenSansFE->set(QFont(name), name);
714 }
715
716
717 void PrefScreenFonts::select_typewriter(const QString & name)
718 {
719         screenTypewriterFE->set(QFont(name), name);
720 }
721
722
723 /////////////////////////////////////////////////////////////////////
724 //
725 // PrefColors
726 //
727 /////////////////////////////////////////////////////////////////////
728
729 namespace {
730
731 struct ColorSorter
732 {
733         bool operator()(ColorCode lhs, ColorCode rhs) const {
734                 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
735         }
736 };
737
738 } // namespace anon
739
740 PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
741         : PrefModule(qt_("Colors"), form, parent)
742 {
743         setupUi(this);
744
745         // FIXME: all of this initialization should be put into the controller.
746         // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
747         // for some discussion of why that is not trivial.
748         QPixmap icon(32, 32);
749         for (int i = 0; i < Color_ignore; ++i) {
750                 ColorCode lc = static_cast<ColorCode>(i);
751                 if (lc == Color_none
752                         || lc == Color_black
753                         || lc == Color_white
754                         || lc == Color_red
755                         || lc == Color_green
756                         || lc == Color_blue
757                         || lc == Color_cyan
758                         || lc == Color_magenta
759                         || lc == Color_yellow
760                         || lc == Color_inherit
761                         || lc == Color_ignore) continue;
762
763                 lcolors_.push_back(lc);
764         }
765         sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
766         vector<ColorCode>::const_iterator cit = lcolors_.begin();
767         vector<ColorCode>::const_iterator const end = lcolors_.end();
768         for (; cit != end; ++cit) {
769                         (void) new QListWidgetItem(QIcon(icon),
770                         toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
771         }
772         curcolors_.resize(lcolors_.size());
773         newcolors_.resize(lcolors_.size());
774         // End initialization
775
776         connect(colorChangePB, SIGNAL(clicked()),
777                 this, SLOT(change_color()));
778         connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
779                 this, SLOT(change_lyxObjects_selection()));
780         connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
781                 this, SLOT(change_color()));
782 }
783
784
785 void PrefColors::apply(LyXRC & /*rc*/) const
786 {
787         for (unsigned int i = 0; i < lcolors_.size(); ++i)
788                 if (curcolors_[i] != newcolors_[i])
789                         form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
790 }
791
792
793 void PrefColors::update(LyXRC const & /*rc*/)
794 {
795         for (unsigned int i = 0; i < lcolors_.size(); ++i) {
796                 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
797                 QPixmap coloritem(32, 32);
798                 coloritem.fill(color);
799                 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
800                 newcolors_[i] = curcolors_[i] = color.name();
801         }
802         change_lyxObjects_selection();
803 }
804
805 void PrefColors::change_color()
806 {
807         int const row = lyxObjectsLW->currentRow();
808
809         // just to be sure
810         if (row < 0)
811                 return;
812
813         QString const color = newcolors_[row];
814         QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
815
816         if (c.isValid() && c.name() != color) {
817                 newcolors_[row] = c.name();
818                 QPixmap coloritem(32, 32);
819                 coloritem.fill(c);
820                 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
821                 // emit signal
822                 changed();
823         }
824 }
825
826 void PrefColors::change_lyxObjects_selection()
827 {
828         colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
829 }
830
831
832 /////////////////////////////////////////////////////////////////////
833 //
834 // PrefDisplay
835 //
836 /////////////////////////////////////////////////////////////////////
837
838 PrefDisplay::PrefDisplay(QWidget * parent)
839         : PrefModule(qt_("Graphics"), 0, parent)
840 {
841         setupUi(this);
842         connect(instantPreviewCO, SIGNAL(activated(int)),
843                 this, SIGNAL(changed()));
844         connect(displayGraphicsCO, SIGNAL(activated(int)),
845                 this, SIGNAL(changed()));
846 }
847
848
849 void PrefDisplay::apply(LyXRC & rc) const
850 {
851         switch (instantPreviewCO->currentIndex()) {
852                 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
853                 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
854                 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
855         }
856
857         graphics::DisplayType dtype;
858         switch (displayGraphicsCO->currentIndex()) {
859                 case 3: dtype = graphics::NoDisplay; break;
860                 case 2: dtype = graphics::ColorDisplay; break;
861                 case 1: dtype = graphics::GrayscaleDisplay;     break;
862                 case 0: dtype = graphics::MonochromeDisplay; break;
863                 default: dtype = graphics::GrayscaleDisplay;
864         }
865         rc.display_graphics = dtype;
866
867         // FIXME!! The graphics cache no longer has a changeDisplay method.
868 #if 0
869         if (old_value != rc.display_graphics) {
870                 graphics::GCache & gc = graphics::GCache::get();
871                 gc.changeDisplay();
872         }
873 #endif
874 }
875
876
877 void PrefDisplay::update(LyXRC const & rc)
878 {
879         switch (rc.preview) {
880         case LyXRC::PREVIEW_OFF:
881                 instantPreviewCO->setCurrentIndex(0);
882                 break;
883         case LyXRC::PREVIEW_NO_MATH :
884                 instantPreviewCO->setCurrentIndex(1);
885                 break;
886         case LyXRC::PREVIEW_ON :
887                 instantPreviewCO->setCurrentIndex(2);
888                 break;
889         }
890
891         int item = 2;
892         switch (rc.display_graphics) {
893                 case graphics::NoDisplay:               item = 3; break;
894                 case graphics::ColorDisplay:    item = 2; break;
895                 case graphics::GrayscaleDisplay:        item = 1; break;
896                 case graphics::MonochromeDisplay:       item = 0; break;
897                 default: break;
898         }
899         displayGraphicsCO->setCurrentIndex(item);
900 }
901
902
903 /////////////////////////////////////////////////////////////////////
904 //
905 // PrefPaths
906 //
907 /////////////////////////////////////////////////////////////////////
908
909 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
910         : PrefModule(qt_("Paths"), form, parent)
911 {
912         setupUi(this);
913         connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
914         connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
915         connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
916         connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
917         connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
918         connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
919         connect(workingDirED, SIGNAL(textChanged(QString)),
920                 this, SIGNAL(changed()));
921         connect(exampleDirED, SIGNAL(textChanged(QString)),
922                 this, SIGNAL(changed()));
923         connect(templateDirED, SIGNAL(textChanged(QString)),
924                 this, SIGNAL(changed()));
925         connect(backupDirED, SIGNAL(textChanged(QString)),
926                 this, SIGNAL(changed()));
927         connect(tempDirED, SIGNAL(textChanged(QString)),
928                 this, SIGNAL(changed()));
929         connect(lyxserverDirED, SIGNAL(textChanged(QString)),
930                 this, SIGNAL(changed()));
931         connect(pathPrefixED, SIGNAL(textChanged(QString)),
932                 this, SIGNAL(changed()));
933 }
934
935
936 void PrefPaths::apply(LyXRC & rc) const
937 {
938         rc.document_path = internal_path(fromqstr(workingDirED->text()));
939         rc.example_path = internal_path(fromqstr(exampleDirED->text()));
940         rc.template_path = internal_path(fromqstr(templateDirED->text()));
941         rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
942         rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
943         rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
944         // FIXME: should be a checkbox only
945         rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
946 }
947
948
949 void PrefPaths::update(LyXRC const & rc)
950 {
951         workingDirED->setText(toqstr(external_path(rc.document_path)));
952         exampleDirED->setText(toqstr(external_path(rc.example_path)));
953         templateDirED->setText(toqstr(external_path(rc.template_path)));
954         backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
955         tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
956         pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
957         // FIXME: should be a checkbox only
958         lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
959 }
960
961
962 void PrefPaths::select_exampledir()
963 {
964         QString file = form_->browsedir(internalPath(exampleDirED->text()),
965                 qt_("Select directory for example files"));
966         if (!file.isEmpty())
967                 exampleDirED->setText(file);
968 }
969
970
971 void PrefPaths::select_templatedir()
972 {
973         QString file = form_->browsedir(internalPath(templateDirED->text()),
974                 qt_("Select a document templates directory"));
975         if (!file.isEmpty())
976                 templateDirED->setText(file);
977 }
978
979
980 void PrefPaths::select_tempdir()
981 {
982         QString file = form_->browsedir(internalPath(tempDirED->text()),
983                 qt_("Select a temporary directory"));
984         if (!file.isEmpty())
985                 tempDirED->setText(file);
986 }
987
988
989 void PrefPaths::select_backupdir()
990 {
991         QString file = form_->browsedir(internalPath(backupDirED->text()),
992                 qt_("Select a backups directory"));
993         if (!file.isEmpty())
994                 backupDirED->setText(file);
995 }
996
997
998 void PrefPaths::select_workingdir()
999 {
1000         QString file = form_->browsedir(internalPath(workingDirED->text()),
1001                 qt_("Select a document directory"));
1002         if (!file.isEmpty())
1003                 workingDirED->setText(file);
1004 }
1005
1006
1007 void PrefPaths::select_lyxpipe()
1008 {
1009         QString file = form_->browse(internalPath(lyxserverDirED->text()),
1010                 qt_("Give a filename for the LyX server pipe"));
1011         if (!file.isEmpty())
1012                 lyxserverDirED->setText(file);
1013 }
1014
1015
1016 /////////////////////////////////////////////////////////////////////
1017 //
1018 // PrefSpellchecker
1019 //
1020 /////////////////////////////////////////////////////////////////////
1021
1022 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
1023         : PrefModule(qt_("Spellchecker"), form, parent)
1024 {
1025         setupUi(this);
1026
1027         connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1028 #if defined (USE_ISPELL)
1029         connect(spellCommandCO, SIGNAL(activated(int)),
1030                 this, SIGNAL(changed()));
1031 #else
1032         spellCommandCO->setEnabled(false);
1033 #endif
1034         connect(altLanguageED, SIGNAL(textChanged(QString)),
1035                 this, SIGNAL(changed()));
1036         connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1037                 this, SIGNAL(changed()));
1038         connect(persDictionaryED, SIGNAL(textChanged(QString)),
1039                 this, SIGNAL(changed()));
1040         connect(compoundWordCB, SIGNAL(clicked()),
1041                 this, SIGNAL(changed()));
1042         connect(inputEncodingCB, SIGNAL(clicked()),
1043                 this, SIGNAL(changed()));
1044
1045         spellCommandCO->addItem(qt_("ispell"));
1046         spellCommandCO->addItem(qt_("aspell"));
1047         spellCommandCO->addItem(qt_("hspell"));
1048 #ifdef USE_PSPELL
1049         spellCommandCO->addItem(qt_("pspell (library)"));
1050 #else
1051 #ifdef USE_ASPELL
1052         spellCommandCO->addItem(qt_("aspell (library)"));
1053 #endif
1054 #endif
1055 }
1056
1057
1058 void PrefSpellchecker::apply(LyXRC & rc) const
1059 {
1060         switch (spellCommandCO->currentIndex()) {
1061                 case 0:
1062                 case 1:
1063                 case 2:
1064                         rc.use_spell_lib = false;
1065                         rc.isp_command = fromqstr(spellCommandCO->currentText());
1066                         break;
1067                 case 3:
1068                         rc.use_spell_lib = true;
1069                         break;
1070         }
1071
1072         // FIXME: remove isp_use_alt_lang
1073         rc.isp_alt_lang = fromqstr(altLanguageED->text());
1074         rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1075         // FIXME: remove isp_use_esc_chars
1076         rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
1077         rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1078         // FIXME: remove isp_use_pers_dict
1079         rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1080         rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1081         rc.isp_accept_compound = compoundWordCB->isChecked();
1082         rc.isp_use_input_encoding = inputEncodingCB->isChecked();
1083 }
1084
1085
1086 void PrefSpellchecker::update(LyXRC const & rc)
1087 {
1088         spellCommandCO->setCurrentIndex(0);
1089
1090         if (rc.isp_command == "ispell") {
1091                 spellCommandCO->setCurrentIndex(0);
1092         } else if (rc.isp_command == "aspell") {
1093                 spellCommandCO->setCurrentIndex(1);
1094         } else if (rc.isp_command == "hspell") {
1095                 spellCommandCO->setCurrentIndex(2);
1096         }
1097
1098         if (rc.use_spell_lib) {
1099 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1100                 spellCommandCO->setCurrentIndex(3);
1101 #endif
1102         }
1103
1104         // FIXME: remove isp_use_alt_lang
1105         altLanguageED->setText(toqstr(rc.isp_alt_lang));
1106         // FIXME: remove isp_use_esc_chars
1107         escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1108         // FIXME: remove isp_use_pers_dict
1109         persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
1110         compoundWordCB->setChecked(rc.isp_accept_compound);
1111         inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1112 }
1113
1114
1115 void PrefSpellchecker::select_dict()
1116 {
1117         QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1118         if (!file.isEmpty())
1119                 persDictionaryED->setText(file);
1120 }
1121
1122
1123
1124 /////////////////////////////////////////////////////////////////////
1125 //
1126 // PrefConverters
1127 //
1128 /////////////////////////////////////////////////////////////////////
1129
1130
1131 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
1132         : PrefModule(qt_("Converters"), form, parent)
1133 {
1134         setupUi(this);
1135
1136         connect(converterNewPB, SIGNAL(clicked()),
1137                 this, SLOT(update_converter()));
1138         connect(converterRemovePB, SIGNAL(clicked()),
1139                 this, SLOT(remove_converter()));
1140         connect(converterModifyPB, SIGNAL(clicked()),
1141                 this, SLOT(update_converter()));
1142         connect(convertersLW, SIGNAL(currentRowChanged(int)),
1143                 this, SLOT(switch_converter()));
1144         connect(converterFromCO, SIGNAL(activated(QString)),
1145                 this, SLOT(converter_changed()));
1146         connect(converterToCO, SIGNAL(activated(QString)),
1147                 this, SLOT(converter_changed()));
1148         connect(converterED, SIGNAL(textEdited(QString)),
1149                 this, SLOT(converter_changed()));
1150         connect(converterFlagED, SIGNAL(textEdited(QString)),
1151                 this, SLOT(converter_changed()));
1152         connect(converterNewPB, SIGNAL(clicked()),
1153                 this, SIGNAL(changed()));
1154         connect(converterRemovePB, SIGNAL(clicked()),
1155                 this, SIGNAL(changed()));
1156         connect(converterModifyPB, SIGNAL(clicked()),
1157                 this, SIGNAL(changed()));
1158         connect(maxAgeLE, SIGNAL(textEdited(QString)),
1159                 this, SIGNAL(changed()));
1160
1161         maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1162         //converterDefGB->setFocusProxy(convertersLW);
1163 }
1164
1165
1166 void PrefConverters::apply(LyXRC & rc) const
1167 {
1168         rc.use_converter_cache = cacheCB->isChecked();
1169         rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1170 }
1171
1172
1173 void PrefConverters::update(LyXRC const & rc)
1174 {
1175         cacheCB->setChecked(rc.use_converter_cache);
1176         QString max_age;
1177         max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1178         maxAgeLE->setText(max_age);
1179         updateGui();
1180 }
1181
1182
1183 void PrefConverters::updateGui()
1184 {
1185         form_->formats().sort();
1186         form_->converters().update(form_->formats());
1187         // save current selection
1188         QString current = converterFromCO->currentText()
1189                 + " -> " + converterToCO->currentText();
1190
1191         converterFromCO->clear();
1192         converterToCO->clear();
1193
1194         Formats::const_iterator cit = form_->formats().begin();
1195         Formats::const_iterator end = form_->formats().end();
1196         for (; cit != end; ++cit) {
1197                 converterFromCO->addItem(toqstr(cit->prettyname()));
1198                 converterToCO->addItem(toqstr(cit->prettyname()));
1199         }
1200
1201         // currentRowChanged(int) is also triggered when updating the listwidget
1202         // block signals to avoid unnecessary calls to switch_converter()
1203         convertersLW->blockSignals(true);
1204         convertersLW->clear();
1205
1206         Converters::const_iterator ccit = form_->converters().begin();
1207         Converters::const_iterator cend = form_->converters().end();
1208         for (; ccit != cend; ++ccit) {
1209                 string const name =
1210                         ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1211                 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1212                 new QListWidgetItem(toqstr(name), convertersLW, type);
1213         }
1214         convertersLW->sortItems(Qt::AscendingOrder);
1215         convertersLW->blockSignals(false);
1216
1217         // restore selection
1218         if (!current.isEmpty()) {
1219                 QList<QListWidgetItem *> const item =
1220                         convertersLW->findItems(current, Qt::MatchExactly);
1221                 if (!item.isEmpty())
1222                         convertersLW->setCurrentItem(item.at(0));
1223         }
1224
1225         // select first element if restoring failed
1226         if (convertersLW->currentRow() == -1)
1227                 convertersLW->setCurrentRow(0);
1228
1229         updateButtons();
1230 }
1231
1232
1233 void PrefConverters::switch_converter()
1234 {
1235         int const cnr = convertersLW->currentItem()->type();
1236         Converter const & c(form_->converters().get(cnr));
1237         converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1238         converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1239         converterED->setText(toqstr(c.command));
1240         converterFlagED->setText(toqstr(c.flags));
1241
1242         updateButtons();
1243 }
1244
1245
1246 void PrefConverters::converter_changed()
1247 {
1248         updateButtons();
1249 }
1250
1251
1252 void PrefConverters::updateButtons()
1253 {
1254         Format const & from = form_->formats().get(converterFromCO->currentIndex());
1255         Format const & to = form_->formats().get(converterToCO->currentIndex());
1256         int const sel = form_->converters().getNumber(from.name(), to.name());
1257         bool const known = sel >= 0;
1258         bool const valid = !(converterED->text().isEmpty()
1259                 || from.name() == to.name());
1260
1261         int const cnr = convertersLW->currentItem()->type();
1262         Converter const & c(form_->converters().get(cnr));
1263         string const old_command = c.command;
1264         string const old_flag = c.flags;
1265         string const new_command(fromqstr(converterED->text()));
1266         string const new_flag(fromqstr(converterFlagED->text()));
1267
1268         bool modified = (old_command != new_command) || (old_flag != new_flag);
1269
1270         converterModifyPB->setEnabled(valid && known && modified);
1271         converterNewPB->setEnabled(valid && !known);
1272         converterRemovePB->setEnabled(known);
1273
1274         maxAgeLE->setEnabled(cacheCB->isChecked());
1275         maxAgeLA->setEnabled(cacheCB->isChecked());
1276 }
1277
1278
1279 // FIXME: user must
1280 // specify unique from/to or it doesn't appear. This is really bad UI
1281 // this is why we can use the same function for both new and modify
1282 void PrefConverters::update_converter()
1283 {
1284         Format const & from = form_->formats().get(converterFromCO->currentIndex());
1285         Format const & to = form_->formats().get(converterToCO->currentIndex());
1286         string const flags = fromqstr(converterFlagED->text());
1287         string const command = fromqstr(converterED->text());
1288
1289         Converter const * old =
1290                 form_->converters().getConverter(from.name(), to.name());
1291         form_->converters().add(from.name(), to.name(), command, flags);
1292
1293         if (!old)
1294                 form_->converters().updateLast(form_->formats());
1295
1296         updateGui();
1297
1298         // Remove all files created by this converter from the cache, since
1299         // the modified converter might create different files.
1300         ConverterCache::get().remove_all(from.name(), to.name());
1301 }
1302
1303
1304 void PrefConverters::remove_converter()
1305 {
1306         Format const & from = form_->formats().get(converterFromCO->currentIndex());
1307         Format const & to = form_->formats().get(converterToCO->currentIndex());
1308         form_->converters().erase(from.name(), to.name());
1309
1310         updateGui();
1311
1312         // Remove all files created by this converter from the cache, since
1313         // a possible new converter might create different files.
1314         ConverterCache::get().remove_all(from.name(), to.name());
1315 }
1316
1317
1318 void PrefConverters::on_cacheCB_stateChanged(int state)
1319 {
1320         maxAgeLE->setEnabled(state == Qt::Checked);
1321         maxAgeLA->setEnabled(state == Qt::Checked);
1322         changed();
1323 }
1324
1325
1326 /////////////////////////////////////////////////////////////////////
1327 //
1328 // PrefFileformats
1329 //
1330 /////////////////////////////////////////////////////////////////////
1331 //
1332 FormatValidator::FormatValidator(QWidget * parent, Formats const & f) 
1333         : QValidator(parent), formats_(f)
1334 {
1335 }
1336
1337
1338 void FormatValidator::fixup(QString & input) const
1339 {
1340         Formats::const_iterator cit = formats_.begin();
1341         Formats::const_iterator end = formats_.end();
1342         for (; cit != end; ++cit) {
1343                 string const name = str(cit);
1344                 if (distance(formats_.begin(), cit) == nr()) {
1345                         input = toqstr(name);
1346                         return;
1347
1348                 }
1349         }
1350 }
1351
1352
1353 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1354 {
1355         Formats::const_iterator cit = formats_.begin();
1356         Formats::const_iterator end = formats_.end();
1357         bool unknown = true;
1358         for (; unknown && cit != end; ++cit) {
1359                 string const name = str(cit);
1360                 if (distance(formats_.begin(), cit) != nr())
1361                         unknown = toqstr(name) != input;
1362         }
1363
1364         if (unknown && !input.isEmpty()) 
1365                 return QValidator::Acceptable;
1366         else
1367                 return QValidator::Intermediate;
1368 }
1369
1370
1371 int FormatValidator::nr() const
1372 {
1373         QComboBox * p = qobject_cast<QComboBox *>(parent());
1374         return p->itemData(p->currentIndex()).toInt();
1375 }
1376
1377
1378 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f) 
1379         : FormatValidator(parent, f)
1380 {
1381 }
1382
1383 string FormatNameValidator::str(Formats::const_iterator it) const
1384 {
1385         return it->name();
1386 }
1387
1388
1389 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f) 
1390         : FormatValidator(parent, f)
1391 {
1392 }
1393
1394
1395 string FormatPrettynameValidator::str(Formats::const_iterator it) const
1396 {
1397         return it->prettyname();
1398 }
1399
1400
1401 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1402         : PrefModule(qt_("File formats"), form, parent)
1403 {
1404         setupUi(this);
1405         formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1406         formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1407
1408         connect(documentCB, SIGNAL(clicked()),
1409                 this, SLOT(setFlags()));
1410         connect(vectorCB, SIGNAL(clicked()),
1411                 this, SLOT(setFlags()));
1412         connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1413                 this, SLOT(updatePrettyname()));
1414         connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1415                 this, SIGNAL(changed()));
1416 }
1417
1418
1419 void PrefFileformats::apply(LyXRC & /*rc*/) const
1420 {
1421 }
1422
1423
1424 void PrefFileformats::update(LyXRC const & /*rc*/)
1425 {
1426         updateView();
1427 }
1428
1429
1430 void PrefFileformats::updateView()
1431 {
1432         QString const current = formatsCB->currentText();
1433
1434         // update combobox with formats
1435         formatsCB->blockSignals(true);
1436         formatsCB->clear();
1437         form_->formats().sort();
1438         Formats::const_iterator cit = form_->formats().begin();
1439         Formats::const_iterator end = form_->formats().end();
1440         for (; cit != end; ++cit)
1441                 formatsCB->addItem(toqstr(cit->prettyname()),
1442                                                         QVariant(form_->formats().getNumber(cit->name())) );
1443
1444         // restore selection
1445         int const item = formatsCB->findText(current, Qt::MatchExactly);
1446         formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1447         on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1448         formatsCB->blockSignals(false);
1449 }
1450
1451
1452 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1453 {
1454         int const nr = formatsCB->itemData(i).toInt();
1455         Format const f = form_->formats().get(nr);
1456
1457         formatED->setText(toqstr(f.name()));
1458         copierED->setText(toqstr(form_->movers().command(f.name())));
1459         extensionED->setText(toqstr(f.extension()));
1460         shortcutED->setText(toqstr(f.shortcut()));
1461         viewerED->setText(toqstr(f.viewer()));
1462         editorED->setText(toqstr(f.editor()));
1463         documentCB->setChecked((f.documentFormat()));
1464         vectorCB->setChecked((f.vectorFormat()));
1465 }
1466
1467
1468 void PrefFileformats::setFlags()
1469 {
1470         int flags = Format::none;
1471         if (documentCB->isChecked())
1472                 flags |= Format::document;
1473         if (vectorCB->isChecked())
1474                 flags |= Format::vector;
1475         currentFormat().setFlags(flags);
1476         changed();
1477 }
1478
1479
1480 void PrefFileformats::on_copierED_textEdited(const QString & s)
1481 {
1482         string const fmt = fromqstr(formatED->text());
1483         form_->movers().set(fmt, fromqstr(s));
1484         changed();
1485 }
1486
1487
1488 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1489 {
1490         currentFormat().setExtension(fromqstr(s));
1491         changed();
1492 }
1493
1494 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1495 {
1496         currentFormat().setViewer(fromqstr(s));
1497         changed();
1498 }
1499
1500
1501 void PrefFileformats::on_editorED_textEdited(const QString & s)
1502 {
1503         currentFormat().setEditor(fromqstr(s));
1504         changed();
1505 }
1506
1507
1508 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1509 {
1510         currentFormat().setShortcut(fromqstr(s));
1511         changed();
1512 }
1513
1514
1515 void PrefFileformats::on_formatED_editingFinished()
1516 {
1517         string const newname = fromqstr(formatED->displayText());
1518         if (newname == currentFormat().name())
1519                 return;
1520
1521         currentFormat().setName(newname);
1522         changed();
1523 }
1524
1525
1526 void PrefFileformats::on_formatED_textChanged(const QString &)
1527 {
1528         QString t = formatED->text();
1529         int p = 0;
1530         bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1531         setValid(formatLA, valid);
1532 }
1533
1534
1535 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1536 {
1537         QString t = formatsCB->currentText();
1538         int p = 0;
1539         bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1540         setValid(formatsLA, valid);
1541 }
1542
1543
1544 void PrefFileformats::updatePrettyname()
1545 {
1546         string const newname = fromqstr(formatsCB->currentText());
1547         if (newname == currentFormat().prettyname())
1548                 return;
1549
1550         currentFormat().setPrettyname(newname);
1551         formatsChanged();
1552         updateView();
1553         changed();
1554 }
1555
1556
1557 Format & PrefFileformats::currentFormat()
1558 {
1559         int const i = formatsCB->currentIndex();
1560         int const nr = formatsCB->itemData(i).toInt();
1561         return form_->formats().get(nr);
1562 }
1563
1564
1565 void PrefFileformats::on_formatNewPB_clicked()
1566 {
1567         form_->formats().add("", "", "", "", "", "", Format::none);
1568         updateView();
1569         formatsCB->setCurrentIndex(0);
1570         formatsCB->setFocus(Qt::OtherFocusReason);
1571 }
1572
1573
1574 void PrefFileformats::on_formatRemovePB_clicked()
1575 {
1576         int const i = formatsCB->currentIndex();
1577         int const nr = formatsCB->itemData(i).toInt();
1578         string const current_text = form_->formats().get(nr).name();
1579         if (form_->converters().formatIsUsed(current_text)) {
1580                 Alert::error(_("Format in use"),
1581                              _("Cannot remove a Format used by a Converter. "
1582                                             "Remove the converter first."));
1583                 return;
1584         }
1585
1586         form_->formats().erase(current_text);
1587         formatsChanged();
1588         updateView();
1589         on_formatsCB_editTextChanged(formatsCB->currentText());
1590         changed();
1591 }
1592
1593
1594 /////////////////////////////////////////////////////////////////////
1595 //
1596 // PrefLanguage
1597 //
1598 /////////////////////////////////////////////////////////////////////
1599
1600 PrefLanguage::PrefLanguage(QWidget * parent)
1601         : PrefModule(qt_("Language"), 0, parent)
1602 {
1603         setupUi(this);
1604
1605         connect(rtlGB, SIGNAL(clicked()),
1606                 this, SIGNAL(changed()));
1607         connect(visualCursorRB, SIGNAL(clicked()),
1608                 this, SIGNAL(changed()));
1609         connect(logicalCursorRB, SIGNAL(clicked()),
1610                 this, SIGNAL(changed()));
1611         connect(markForeignCB, SIGNAL(clicked()),
1612                 this, SIGNAL(changed()));
1613         connect(autoBeginCB, SIGNAL(clicked()),
1614                 this, SIGNAL(changed()));
1615         connect(autoEndCB, SIGNAL(clicked()),
1616                 this, SIGNAL(changed()));
1617         connect(useBabelCB, SIGNAL(clicked()),
1618                 this, SIGNAL(changed()));
1619         connect(globalCB, SIGNAL(clicked()),
1620                 this, SIGNAL(changed()));
1621         connect(languagePackageED, SIGNAL(textChanged(QString)),
1622                 this, SIGNAL(changed()));
1623         connect(startCommandED, SIGNAL(textChanged(QString)),
1624                 this, SIGNAL(changed()));
1625         connect(endCommandED, SIGNAL(textChanged(QString)),
1626                 this, SIGNAL(changed()));
1627         connect(defaultLanguageCO, SIGNAL(activated(int)),
1628                 this, SIGNAL(changed()));
1629
1630         defaultLanguageCO->clear();
1631
1632         // store the lang identifiers for later
1633         vector<LanguagePair> const langs = getLanguageData(false);
1634         vector<LanguagePair>::const_iterator lit  = langs.begin();
1635         vector<LanguagePair>::const_iterator lend = langs.end();
1636         lang_.clear();
1637         for (; lit != lend; ++lit) {
1638                 defaultLanguageCO->addItem(toqstr(lit->first));
1639                 lang_.push_back(lit->second);
1640         }
1641 }
1642
1643
1644 void PrefLanguage::apply(LyXRC & rc) const
1645 {
1646         // FIXME: remove rtl_support bool
1647         rc.rtl_support = rtlGB->isChecked();
1648         rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1649         rc.mark_foreign_language = markForeignCB->isChecked();
1650         rc.language_auto_begin = autoBeginCB->isChecked();
1651         rc.language_auto_end = autoEndCB->isChecked();
1652         rc.language_use_babel = useBabelCB->isChecked();
1653         rc.language_global_options = globalCB->isChecked();
1654         rc.language_package = fromqstr(languagePackageED->text());
1655         rc.language_command_begin = fromqstr(startCommandED->text());
1656         rc.language_command_end = fromqstr(endCommandED->text());
1657         rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1658 }
1659
1660
1661 void PrefLanguage::update(LyXRC const & rc)
1662 {
1663         // FIXME: remove rtl_support bool
1664         rtlGB->setChecked(rc.rtl_support);
1665         if (rc.visual_cursor)
1666                 visualCursorRB->setChecked(true);
1667         else
1668                 logicalCursorRB->setChecked(true);
1669         markForeignCB->setChecked(rc.mark_foreign_language);
1670         autoBeginCB->setChecked(rc.language_auto_begin);
1671         autoEndCB->setChecked(rc.language_auto_end);
1672         useBabelCB->setChecked(rc.language_use_babel);
1673         globalCB->setChecked(rc.language_global_options);
1674         languagePackageED->setText(toqstr(rc.language_package));
1675         startCommandED->setText(toqstr(rc.language_command_begin));
1676         endCommandED->setText(toqstr(rc.language_command_end));
1677
1678         int const pos = int(findPos_helper(lang_, rc.default_language));
1679         defaultLanguageCO->setCurrentIndex(pos);
1680 }
1681
1682
1683 /////////////////////////////////////////////////////////////////////
1684 //
1685 // PrefPrinter
1686 //
1687 /////////////////////////////////////////////////////////////////////
1688
1689 PrefPrinter::PrefPrinter(QWidget * parent)
1690         : PrefModule(qt_("Printer"), 0, parent)
1691 {
1692         setupUi(this);
1693
1694         connect(printerAdaptCB, SIGNAL(clicked()),
1695                 this, SIGNAL(changed()));
1696         connect(printerCommandED, SIGNAL(textChanged(QString)),
1697                 this, SIGNAL(changed()));
1698         connect(printerNameED, SIGNAL(textChanged(QString)),
1699                 this, SIGNAL(changed()));
1700         connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1701                 this, SIGNAL(changed()));
1702         connect(printerCopiesED, SIGNAL(textChanged(QString)),
1703                 this, SIGNAL(changed()));
1704         connect(printerReverseED, SIGNAL(textChanged(QString)),
1705                 this, SIGNAL(changed()));
1706         connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1707                 this, SIGNAL(changed()));
1708         connect(printerExtensionED, SIGNAL(textChanged(QString)),
1709                 this, SIGNAL(changed()));
1710         connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1711                 this, SIGNAL(changed()));
1712         connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1713                 this, SIGNAL(changed()));
1714         connect(printerEvenED, SIGNAL(textChanged(QString)),
1715                 this, SIGNAL(changed()));
1716         connect(printerOddED, SIGNAL(textChanged(QString)),
1717                 this, SIGNAL(changed()));
1718         connect(printerCollatedED, SIGNAL(textChanged(QString)),
1719                 this, SIGNAL(changed()));
1720         connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1721                 this, SIGNAL(changed()));
1722         connect(printerToFileED, SIGNAL(textChanged(QString)),
1723                 this, SIGNAL(changed()));
1724         connect(printerExtraED, SIGNAL(textChanged(QString)),
1725                 this, SIGNAL(changed()));
1726         connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1727                 this, SIGNAL(changed()));
1728         connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1729                 this, SIGNAL(changed()));
1730 }
1731
1732
1733 void PrefPrinter::apply(LyXRC & rc) const
1734 {
1735         rc.print_adapt_output = printerAdaptCB->isChecked();
1736         rc.print_command = fromqstr(printerCommandED->text());
1737         rc.printer = fromqstr(printerNameED->text());
1738
1739         rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1740         rc.print_copies_flag = fromqstr(printerCopiesED->text());
1741         rc.print_reverse_flag = fromqstr(printerReverseED->text());
1742         rc.print_to_printer = fromqstr(printerToPrinterED->text());
1743         rc.print_file_extension = fromqstr(printerExtensionED->text());
1744         rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1745         rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1746         rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1747         rc.print_oddpage_flag = fromqstr(printerOddED->text());
1748         rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1749         rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1750         rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1751         rc.print_extra_options = fromqstr(printerExtraED->text());
1752         rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1753         rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1754 }
1755
1756
1757 void PrefPrinter::update(LyXRC const & rc)
1758 {
1759         printerAdaptCB->setChecked(rc.print_adapt_output);
1760         printerCommandED->setText(toqstr(rc.print_command));
1761         printerNameED->setText(toqstr(rc.printer));
1762
1763         printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1764         printerCopiesED->setText(toqstr(rc.print_copies_flag));
1765         printerReverseED->setText(toqstr(rc.print_reverse_flag));
1766         printerToPrinterED->setText(toqstr(rc.print_to_printer));
1767         printerExtensionED->setText(toqstr(rc.print_file_extension));
1768         printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1769         printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1770         printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1771         printerOddED->setText(toqstr(rc.print_oddpage_flag));
1772         printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1773         printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1774         printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1775         printerExtraED->setText(toqstr(rc.print_extra_options));
1776         printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1777         printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1778 }
1779
1780
1781 /////////////////////////////////////////////////////////////////////
1782 //
1783 // PrefUserInterface
1784 //
1785 /////////////////////////////////////////////////////////////////////
1786
1787 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1788         : PrefModule(qt_("User interface"), form, parent)
1789 {
1790         setupUi(this);
1791
1792         connect(autoSaveCB, SIGNAL(toggled(bool)),
1793                 autoSaveSB, SLOT(setEnabled(bool)));
1794         connect(autoSaveCB, SIGNAL(toggled(bool)),
1795                 TextLabel1, SLOT(setEnabled(bool)));
1796         connect(uiFilePB, SIGNAL(clicked()),
1797                 this, SLOT(select_ui()));
1798         connect(uiFileED, SIGNAL(textChanged(QString)),
1799                 this, SIGNAL(changed()));
1800         connect(restoreCursorCB, SIGNAL(clicked()),
1801                 this, SIGNAL(changed()));
1802         connect(loadSessionCB, SIGNAL(clicked()),
1803                 this, SIGNAL(changed()));
1804         connect(allowGeometrySessionCB, SIGNAL(clicked()),
1805                 this, SIGNAL(changed()));
1806         connect(cursorFollowsCB, SIGNAL(clicked()),
1807                 this, SIGNAL(changed()));
1808         connect(sortEnvironmentsCB, SIGNAL(clicked()),
1809                 this, SIGNAL(changed()));
1810         connect(macroEditStyleCO, SIGNAL(activated(int)),
1811                 this, SIGNAL(changed()));
1812         connect(autoSaveSB, SIGNAL(valueChanged(int)),
1813                 this, SIGNAL(changed()));
1814         connect(autoSaveCB, SIGNAL(clicked()),
1815                 this, SIGNAL(changed()));
1816         connect(lastfilesSB, SIGNAL(valueChanged(int)),
1817                 this, SIGNAL(changed()));
1818         connect(tooltipCB, SIGNAL(toggled(bool)),
1819                 this, SIGNAL(changed()));
1820         connect(fullscreenLimitGB, SIGNAL(clicked()),
1821                 this, SIGNAL(changed()));
1822         connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1823                 this, SIGNAL(changed()));
1824         connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1825                 this, SIGNAL(changed()));
1826         connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1827                 this, SIGNAL(changed()));
1828         connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1829                 this, SIGNAL(changed()));
1830         lastfilesSB->setMaximum(maxlastfiles);
1831 }
1832
1833
1834 void PrefUserInterface::apply(LyXRC & rc) const
1835 {
1836         rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1837         rc.use_lastfilepos = restoreCursorCB->isChecked();
1838         rc.load_session = loadSessionCB->isChecked();
1839         rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1840         rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1841         rc.sort_layouts = sortEnvironmentsCB->isChecked();
1842         switch (macroEditStyleCO->currentIndex()) {
1843                 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1844                 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1845                 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST;   break;
1846         }
1847         rc.autosave = autoSaveSB->value() * 60;
1848         rc.make_backup = autoSaveCB->isChecked();
1849         rc.num_lastfiles = lastfilesSB->value();
1850         rc.use_tooltip = tooltipCB->isChecked();
1851         rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1852         rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1853         rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1854         rc.full_screen_width = fullscreenWidthSB->value();
1855         rc.full_screen_limit = fullscreenLimitGB->isChecked();
1856 }
1857
1858
1859 void PrefUserInterface::update(LyXRC const & rc)
1860 {
1861         uiFileED->setText(toqstr(external_path(rc.ui_file)));
1862         restoreCursorCB->setChecked(rc.use_lastfilepos);
1863         loadSessionCB->setChecked(rc.load_session);
1864         allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1865         cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1866         sortEnvironmentsCB->setChecked(rc.sort_layouts);
1867         macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1868         // convert to minutes
1869         int mins(rc.autosave / 60);
1870         if (rc.autosave && !mins)
1871                 mins = 1;
1872         autoSaveSB->setValue(mins);
1873         autoSaveCB->setChecked(rc.make_backup);
1874         lastfilesSB->setValue(rc.num_lastfiles);
1875         tooltipCB->setChecked(rc.use_tooltip);
1876         toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
1877         toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
1878         toggleTabbarCB->setChecked(rc.full_screen_tabbar);
1879         fullscreenWidthSB->setValue(rc.full_screen_width);
1880         fullscreenLimitGB->setChecked(rc.full_screen_limit);
1881
1882 }
1883
1884
1885 void PrefUserInterface::select_ui()
1886 {
1887         QString file = form_->browseUI(internalPath(uiFileED->text()));
1888         if (!file.isEmpty())
1889                 uiFileED->setText(file);
1890 }
1891
1892
1893 /////////////////////////////////////////////////////////////////////
1894 //
1895 // PrefShortcuts
1896 //
1897 /////////////////////////////////////////////////////////////////////
1898
1899
1900 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1901 {
1902         Ui::shortcutUi::setupUi(this);
1903         QDialog::setModal(true);
1904 }
1905
1906
1907 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1908         : PrefModule(qt_("Shortcuts"), form, parent)
1909 {
1910         setupUi(this);
1911
1912         shortcutsTW->setColumnCount(2);
1913         shortcutsTW->headerItem()->setText(0, qt_("Function"));
1914         shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1915         shortcutsTW->setSortingEnabled(true);
1916         // Multi-selection can be annoying.
1917         // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1918         shortcutsTW->header()->resizeSection(0, 200);
1919
1920         connect(bindFilePB, SIGNAL(clicked()),
1921                 this, SLOT(select_bind()));
1922         connect(bindFileED, SIGNAL(textChanged(QString)),
1923                 this, SIGNAL(changed()));
1924         connect(removePB, SIGNAL(clicked()), 
1925                 this, SIGNAL(changed()));
1926         
1927         shortcut_ = new GuiShortcutDialog(this);
1928         shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1929         shortcut_bc_.setOK(shortcut_->okPB);
1930         shortcut_bc_.setCancel(shortcut_->cancelPB);
1931
1932         connect(shortcut_->okPB, SIGNAL(clicked()),
1933                 shortcut_, SLOT(accept()));
1934         connect(shortcut_->okPB, SIGNAL(clicked()), 
1935                 this, SIGNAL(changed()));
1936         connect(shortcut_->cancelPB, SIGNAL(clicked()), 
1937                 shortcut_, SLOT(reject()));
1938         connect(shortcut_->clearPB, SIGNAL(clicked()),
1939                 this, SLOT(shortcut_clearPB_pressed()));
1940         connect(shortcut_->okPB, SIGNAL(clicked()), 
1941                 this, SLOT(shortcut_okPB_pressed()));
1942 }
1943
1944
1945 void PrefShortcuts::apply(LyXRC & rc) const
1946 {
1947         rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1948         // write user_bind and user_unbind to .lyx/bind/user.bind
1949         FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
1950         if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
1951                 lyxerr << "LyX could not create the user bind directory '"
1952                        << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1953                 return;
1954         }
1955         if (!bind_dir.isDirWritable()) {
1956                 lyxerr << "LyX could not write to the user bind directory '"
1957                        << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1958                 return;
1959         }
1960         FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
1961         user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
1962         user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
1963         // immediately apply the keybindings. Why this is not done before?
1964         // The good thing is that the menus are updated automatically.
1965         theTopLevelKeymap().clear();
1966         theTopLevelKeymap().read("site");
1967         theTopLevelKeymap().read(rc.bind_file);
1968         theTopLevelKeymap().read("user");
1969 }
1970
1971
1972 void PrefShortcuts::update(LyXRC const & rc)
1973 {
1974         bindFileED->setText(toqstr(external_path(rc.bind_file)));
1975         //
1976         system_bind_.clear();
1977         user_bind_.clear();
1978         user_unbind_.clear();
1979         system_bind_.read(rc.bind_file);
1980         // \unbind in user.bind is added to user_unbind_
1981         user_bind_.read("user", &user_unbind_);
1982         updateShortcutsTW();
1983 }
1984
1985
1986 void PrefShortcuts::updateShortcutsTW()
1987 {
1988         shortcutsTW->clear();
1989
1990         editItem_ = new QTreeWidgetItem(shortcutsTW);
1991         editItem_->setText(0, toqstr("Cursor, Mouse and Editing functions"));
1992         editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
1993
1994         mathItem_ = new QTreeWidgetItem(shortcutsTW);
1995         mathItem_->setText(0, toqstr("Mathematical Symbols"));
1996         mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
1997         
1998         bufferItem_ = new QTreeWidgetItem(shortcutsTW);
1999         bufferItem_->setText(0, toqstr("Buffer and Window"));
2000         bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2001         
2002         layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2003         layoutItem_->setText(0, toqstr("Font, Layouts and Textclasses"));
2004         layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2005
2006         systemItem_ = new QTreeWidgetItem(shortcutsTW);
2007         systemItem_->setText(0, toqstr("System and Miscellaneous"));
2008         systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2009
2010         // listBindings(unbound=true) lists all bound and unbound lfuns
2011         // Items in this list is tagged by its source.
2012         KeyMap::BindingList bindinglist = system_bind_.listBindings(true, 
2013                 static_cast<int>(System));
2014         KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2015                 static_cast<int>(UserBind));
2016         KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2017                 static_cast<int>(UserUnbind));
2018         bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2019                         user_bindinglist.end());
2020         bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2021                         user_unbindinglist.end());
2022
2023         KeyMap::BindingList::const_iterator it = bindinglist.begin();
2024         KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2025         for (; it != it_end; ++it)
2026                 insertShortcutItem(it->request, it->sequence, item_type(it->tag));
2027
2028         shortcutsTW->sortItems(0, Qt::AscendingOrder);
2029         QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2030         removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2031 }
2032
2033
2034 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
2035 {
2036         item->setData(0, Qt::UserRole, QVariant(tag));
2037         QFont font;
2038
2039         switch (tag) {
2040         case System:
2041                 break;
2042         case UserBind:
2043                 font.setBold(true);
2044                 break;
2045         case UserUnbind:
2046                 font.setStrikeOut(true);
2047                 break;
2048         // this item is not displayed now.
2049         case UserExtraUnbind:
2050                 font.setStrikeOut(true);
2051                 break;
2052         }
2053
2054         item->setFont(1, font);
2055 }
2056
2057
2058 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2059                 KeySequence const & seq, item_type tag)
2060 {
2061         kb_action action = lfun.action;
2062         string const action_name = lyxaction.getActionName(action);
2063         QString const lfun_name = toqstr(from_utf8(action_name) 
2064                         + " " + lfun.argument());
2065         QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2066         item_type item_tag = tag;
2067
2068         QTreeWidgetItem * newItem = NULL;
2069         // for unbind items, try to find an existing item in the system bind list
2070         if (tag == UserUnbind) {
2071                 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name, 
2072                         Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2073                 for (int i = 0; i < items.size(); ++i) {
2074                         if (items[i]->text(1) == shortcut)
2075                                 newItem = items[i];
2076                                 break;
2077                         }
2078                 // if not found, this unbind item is UserExtraUnbind
2079                 // Such an item is not displayed to avoid confusion (what is 
2080                 // unmatched removed?).
2081                 if (!newItem) {
2082                         item_tag = UserExtraUnbind;
2083                         return NULL;
2084                 }
2085         }
2086         if (!newItem) {
2087                 switch(lyxaction.getActionType(action)) {
2088                 case LyXAction::Hidden:
2089                         return NULL;
2090                 case LyXAction::Edit:
2091                         newItem = new QTreeWidgetItem(editItem_);
2092                         break;
2093                 case LyXAction::Math:
2094                         newItem = new QTreeWidgetItem(mathItem_);
2095                         break;
2096                 case LyXAction::Buffer:
2097                         newItem = new QTreeWidgetItem(bufferItem_);
2098                         break;
2099                 case LyXAction::Layout:
2100                         newItem = new QTreeWidgetItem(layoutItem_);
2101                         break;
2102                 case LyXAction::System:
2103                         newItem = new QTreeWidgetItem(systemItem_);
2104                         break;
2105                 default:
2106                         // this should not happen
2107                         newItem = new QTreeWidgetItem(shortcutsTW);
2108                 }
2109         }
2110
2111         newItem->setText(0, lfun_name);
2112         newItem->setText(1, shortcut);
2113         // record BindFile representation to recover KeySequence when needed.
2114         newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2115         setItemType(newItem, item_tag);
2116         return newItem;
2117 }
2118
2119
2120 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2121 {
2122         QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2123         removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2124         if (items.isEmpty())
2125                 return;
2126         
2127         item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
2128         if (tag == UserUnbind)
2129                 removePB->setText(toqstr("Restore"));
2130         else
2131                 removePB->setText(toqstr("Remove"));
2132 }
2133
2134
2135 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2136 {
2137         QTreeWidgetItem * item = shortcutsTW->currentItem();
2138         if (item->flags() & Qt::ItemIsSelectable) {
2139                 shortcut_->lfunLE->setText(item->text(0));
2140                 // clear the shortcut because I assume that a user will enter
2141                 // a new shortcut.
2142                 shortcut_->shortcutLE->reset();
2143                 shortcut_->shortcutLE->setFocus();
2144                 shortcut_->exec();
2145         }
2146 }
2147
2148
2149 void PrefShortcuts::select_bind()
2150 {
2151         QString file = form_->browsebind(internalPath(bindFileED->text()));
2152         if (!file.isEmpty()) {
2153                 bindFileED->setText(file);
2154                 system_bind_ = KeyMap();
2155                 system_bind_.read(fromqstr(file));
2156                 updateShortcutsTW();
2157         }
2158 }
2159
2160
2161 void PrefShortcuts::on_newPB_pressed()
2162 {
2163         shortcut_->lfunLE->clear();
2164         shortcut_->shortcutLE->reset();
2165         shortcut_->exec();
2166 }
2167
2168
2169 void PrefShortcuts::on_removePB_pressed()
2170 {
2171         // it seems that only one item can be selected, but I am
2172         // removing all selected items anyway.
2173         QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2174         for (int i = 0; i < items.size(); ++i) {
2175                 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2176                 string lfun = fromqstr(items[i]->text(0));
2177                 FuncRequest func = lyxaction.lookupFunc(lfun);
2178                 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2179                 
2180                 switch (tag) {
2181                 case System: {
2182                         // for system bind, we do not touch the item
2183                         // but add an user unbind item
2184                         user_unbind_.bind(shortcut, func);
2185                         setItemType(items[i], UserUnbind);
2186                         removePB->setText(toqstr("Restore"));
2187                         break;
2188                 }
2189                 case UserBind: {
2190                         // for user_bind, we remove this bind
2191                         QTreeWidgetItem * parent = items[i]->parent();
2192                         int itemIdx = parent->indexOfChild(items[i]);
2193                         parent->takeChild(itemIdx);
2194                         if (itemIdx > 0)
2195                                 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2196                         else
2197                                 shortcutsTW->scrollToItem(parent);
2198                         user_bind_.unbind(shortcut, func);
2199                         break;
2200                 }
2201                 case UserUnbind: {
2202                         // for user_unbind, we remove the unbind, and the item
2203                         // become System again.
2204                         user_unbind_.unbind(shortcut, func);
2205                         setItemType(items[i], System);
2206                         removePB->setText(toqstr("Remove"));
2207                         break;
2208                 }
2209                 case UserExtraUnbind: {
2210                         // for user unbind that is not in system bind file,
2211                         // remove this unbind file
2212                         QTreeWidgetItem * parent = items[i]->parent();
2213                         parent->takeChild(parent->indexOfChild(items[i]));
2214                         user_unbind_.unbind(shortcut, func);
2215                 }
2216                 }
2217         }
2218 }
2219
2220
2221 void PrefShortcuts::on_searchLE_textEdited()
2222 {
2223         if (searchLE->text().isEmpty()) {
2224                 // show all hidden items
2225                 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2226                 while (*it)
2227                         shortcutsTW->setItemHidden(*it++, false);
2228                 return;
2229         }
2230         // search both columns
2231         QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2232                 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2233         matched += shortcutsTW->findItems(searchLE->text(),
2234                 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2235         
2236         // hide everyone (to avoid searching in matched QList repeatedly
2237         QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2238         while (*it)
2239                 shortcutsTW->setItemHidden(*it++, true);
2240         // show matched items
2241         for (int i = 0; i < matched.size(); ++i) {
2242                 shortcutsTW->setItemHidden(matched[i], false);
2243         shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2244         }
2245 }
2246
2247
2248 void PrefShortcuts::shortcut_okPB_pressed()
2249 {
2250         string lfun = fromqstr(shortcut_->lfunLE->text());
2251         FuncRequest func = lyxaction.lookupFunc(lfun);
2252
2253         if (func.action == LFUN_UNKNOWN_ACTION) {
2254                 Alert::error(_("Failed to create shortcut"),
2255                         _("Unknown or invalid LyX function"));
2256                 return;
2257         }
2258
2259         KeySequence k = shortcut_->shortcutLE->getKeySequence();
2260         if (k.length() == 0) {
2261                 Alert::error(_("Failed to create shortcut"),
2262                         _("Invalid or empty key sequence"));
2263                 return;
2264         }
2265
2266         // if both lfun and shortcut is valid
2267         if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2268                 Alert::error(_("Failed to create shortcut"),
2269                         _("Shortcut is already defined"));
2270                 return;
2271         }
2272                 
2273         QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2274         if (item) {
2275                 user_bind_.bind(&k, func);
2276                 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2277                 shortcutsTW->setItemExpanded(item->parent(), true);
2278                 shortcutsTW->scrollToItem(item);
2279         } else {
2280                 Alert::error(_("Failed to create shortcut"),
2281                         _("Can not insert shortcut to the list"));
2282                 return;
2283         }
2284 }
2285
2286
2287 void PrefShortcuts::shortcut_clearPB_pressed()
2288 {
2289         shortcut_->shortcutLE->reset();
2290         shortcut_->shortcutLE->setFocus();
2291 }
2292
2293
2294 /////////////////////////////////////////////////////////////////////
2295 //
2296 // PrefIdentity
2297 //
2298 /////////////////////////////////////////////////////////////////////
2299
2300 PrefIdentity::PrefIdentity(QWidget * parent)
2301         : PrefModule(qt_("Identity"), 0, parent)
2302 {
2303         setupUi(this);
2304
2305         connect(nameED, SIGNAL(textChanged(QString)),
2306                 this, SIGNAL(changed()));
2307         connect(emailED, SIGNAL(textChanged(QString)),
2308                 this, SIGNAL(changed()));
2309 }
2310
2311
2312 void PrefIdentity::apply(LyXRC & rc) const
2313 {
2314         rc.user_name = fromqstr(nameED->text());
2315         rc.user_email = fromqstr(emailED->text());
2316 }
2317
2318
2319 void PrefIdentity::update(LyXRC const & rc)
2320 {
2321         nameED->setText(toqstr(rc.user_name));
2322         emailED->setText(toqstr(rc.user_email));
2323 }
2324
2325
2326
2327 /////////////////////////////////////////////////////////////////////
2328 //
2329 // GuiPreferences
2330 //
2331 /////////////////////////////////////////////////////////////////////
2332
2333 GuiPreferences::GuiPreferences(GuiView & lv)
2334         : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2335 {
2336         setupUi(this);
2337
2338         QDialog::setModal(false);
2339
2340         connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2341         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2342         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2343         connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2344
2345         add(new PrefUserInterface(this));
2346         add(new PrefShortcuts(this));
2347         add(new PrefScreenFonts(this));
2348         add(new PrefColors(this));
2349         add(new PrefDisplay);
2350         add(new PrefInput(this));
2351
2352         add(new PrefPaths(this));
2353
2354         add(new PrefIdentity);
2355
2356         add(new PrefLanguage);
2357         add(new PrefSpellchecker(this));
2358
2359         add(new PrefPrinter);
2360         add(new PrefDate);
2361         add(new PrefPlaintext);
2362         add(new PrefLatex(this));
2363
2364         PrefConverters * converters = new PrefConverters(this);
2365         PrefFileformats * formats = new PrefFileformats(this);
2366         connect(formats, SIGNAL(formatsChanged()),
2367                         converters, SLOT(updateGui()));
2368         add(converters);
2369         add(formats);
2370
2371         prefsPS->setCurrentPanel(qt_("User interface"));
2372 // FIXME: hack to work around resizing bug in Qt >= 4.2
2373 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2374 #if QT_VERSION >= 0x040200
2375         prefsPS->updateGeometry();
2376 #endif
2377
2378         bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2379         bc().setOK(savePB);
2380         bc().setApply(applyPB);
2381         bc().setCancel(closePB);
2382         bc().setRestore(restorePB);
2383 }
2384
2385
2386 void GuiPreferences::add(PrefModule * module)
2387 {
2388         BOOST_ASSERT(module);
2389         prefsPS->addPanel(module, module->title());
2390         connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2391         modules_.push_back(module);
2392 }
2393
2394
2395 void GuiPreferences::change_adaptor()
2396 {
2397         changed();
2398 }
2399
2400
2401 void GuiPreferences::apply(LyXRC & rc) const
2402 {
2403         size_t end = modules_.size();
2404         for (size_t i = 0; i != end; ++i)
2405                 modules_[i]->apply(rc);
2406 }
2407
2408
2409 void GuiPreferences::updateRc(LyXRC const & rc)
2410 {
2411         size_t const end = modules_.size();
2412         for (size_t i = 0; i != end; ++i)
2413                 modules_[i]->update(rc);
2414 }
2415
2416
2417 void GuiPreferences::applyView()
2418 {
2419         apply(rc());
2420 }
2421
2422
2423 void GuiPreferences::updateContents()
2424 {
2425         updateRc(rc());
2426 }
2427
2428
2429 bool GuiPreferences::initialiseParams(string const &)
2430 {
2431         rc_ = lyxrc;
2432         formats_ = lyx::formats;
2433         converters_ = theConverters();
2434         converters_.update(formats_);
2435         movers_ = theMovers();
2436         colors_.clear();
2437         update_screen_font_ = false;
2438
2439         return true;
2440 }
2441
2442
2443 void GuiPreferences::dispatchParams()
2444 {
2445         ostringstream ss;
2446         rc_.write(ss, true);
2447         dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str())); 
2448         // FIXME: these need lfuns
2449         // FIXME UNICODE
2450         theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2451
2452         lyx::formats = formats_;
2453
2454         theConverters() = converters_;
2455         theConverters().update(lyx::formats);
2456         theConverters().buildGraph();
2457
2458         theMovers() = movers_;
2459
2460         vector<string>::const_iterator it = colors_.begin();
2461         vector<string>::const_iterator const end = colors_.end();
2462         for (; it != end; ++it)
2463                 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2464         colors_.clear();
2465
2466         if (update_screen_font_) {
2467                 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2468                 update_screen_font_ = false;
2469         }
2470
2471         // The Save button has been pressed
2472         if (isClosing())
2473                 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2474 }
2475
2476
2477 void GuiPreferences::setColor(ColorCode col, string const & hex)
2478 {
2479         colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2480 }
2481
2482
2483 void GuiPreferences::updateScreenFonts()
2484 {
2485         update_screen_font_ = true;
2486 }
2487
2488
2489 QString GuiPreferences::browsebind(QString const & file) const
2490 {
2491         return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2492                              FileFilterList(_("LyX bind files (*.bind)")));
2493 }
2494
2495
2496 QString GuiPreferences::browseUI(QString const & file) const
2497 {
2498         return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2499                              FileFilterList(_("LyX UI files (*.ui)")));
2500 }
2501
2502
2503 QString GuiPreferences::browsekbmap(QString const & file) const
2504 {
2505         return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2506                              FileFilterList(_("LyX keyboard maps (*.kmap)")));
2507 }
2508
2509
2510 QString GuiPreferences::browsedict(QString const & file) const
2511 {
2512         return browseFile(file, qt_("Choose personal dictionary"),
2513                 FileFilterList(lyxrc.use_spell_lib ? _("*.pws") : _("*.ispell")));
2514 }
2515
2516
2517 QString GuiPreferences::browse(QString const & file,
2518                                   QString const & title) const
2519 {
2520         return browseFile(file, title, FileFilterList(), true);
2521 }
2522
2523
2524 QString GuiPreferences::browsedir(QString const & path,
2525                                      QString const & title) const
2526 {
2527         return browseDir(path, title);
2528 }
2529
2530
2531 // We support less paper sizes than the document dialog
2532 // Therefore this adjustment is needed.
2533 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2534 {
2535         switch (i) {
2536         case 0:
2537                 return PAPER_DEFAULT;
2538         case 1:
2539                 return PAPER_USLETTER;
2540         case 2:
2541                 return PAPER_USLEGAL;
2542         case 3:
2543                 return PAPER_USEXECUTIVE;
2544         case 4:
2545                 return PAPER_A3;
2546         case 5:
2547                 return PAPER_A4;
2548         case 6:
2549                 return PAPER_A5;
2550         case 7:
2551                 return PAPER_B5;
2552         default:
2553                 // should not happen
2554                 return PAPER_DEFAULT;
2555         }
2556 }
2557
2558
2559 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2560 {
2561         switch (papersize) {
2562         case PAPER_DEFAULT:
2563                 return 0;
2564         case PAPER_USLETTER:
2565                 return 1;
2566         case PAPER_USLEGAL:
2567                 return 2;
2568         case PAPER_USEXECUTIVE:
2569                 return 3;
2570         case PAPER_A3:
2571                 return 4;
2572         case PAPER_A4:
2573                 return 5;
2574         case PAPER_A5:
2575                 return 6;
2576         case PAPER_B5:
2577                 return 7;
2578         default:
2579                 // should not happen
2580                 return 0;
2581         }
2582 }
2583
2584
2585 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2586
2587
2588 } // namespace frontend
2589 } // namespace lyx
2590
2591 #include "GuiPrefs_moc.cpp"