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