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