]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrefs.cpp
less string conversions as long as we stay in the frontend
[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 void PrefColors::change_color()
797 {
798         int const row = lyxObjectsLW->currentRow();
799
800         // just to be sure
801         if (row < 0)
802                 return;
803
804         QString const color = newcolors_[row];
805         QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
806
807         if (c.isValid() && c.name() != color) {
808                 newcolors_[row] = c.name();
809                 QPixmap coloritem(32, 32);
810                 coloritem.fill(c);
811                 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
812                 // emit signal
813                 changed();
814         }
815 }
816
817 void PrefColors::change_lyxObjects_selection()
818 {
819         colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
820 }
821
822
823 /////////////////////////////////////////////////////////////////////
824 //
825 // PrefDisplay
826 //
827 /////////////////////////////////////////////////////////////////////
828
829 PrefDisplay::PrefDisplay(QWidget * parent)
830         : PrefModule(qt_("Graphics"), 0, parent)
831 {
832         setupUi(this);
833         connect(instantPreviewCO, SIGNAL(activated(int)),
834                 this, SIGNAL(changed()));
835         connect(displayGraphicsCO, SIGNAL(activated(int)),
836                 this, SIGNAL(changed()));
837 }
838
839
840 void PrefDisplay::apply(LyXRC & rc) const
841 {
842         switch (instantPreviewCO->currentIndex()) {
843                 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
844                 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
845                 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
846         }
847
848         graphics::DisplayType dtype;
849         switch (displayGraphicsCO->currentIndex()) {
850                 case 3: dtype = graphics::NoDisplay; break;
851                 case 2: dtype = graphics::ColorDisplay; break;
852                 case 1: dtype = graphics::GrayscaleDisplay;     break;
853                 case 0: dtype = graphics::MonochromeDisplay; break;
854                 default: dtype = graphics::GrayscaleDisplay;
855         }
856         rc.display_graphics = dtype;
857
858         // FIXME!! The graphics cache no longer has a changeDisplay method.
859 #if 0
860         if (old_value != rc.display_graphics) {
861                 graphics::GCache & gc = graphics::GCache::get();
862                 gc.changeDisplay();
863         }
864 #endif
865 }
866
867
868 void PrefDisplay::update(LyXRC const & rc)
869 {
870         switch (rc.preview) {
871         case LyXRC::PREVIEW_OFF:
872                 instantPreviewCO->setCurrentIndex(0);
873                 break;
874         case LyXRC::PREVIEW_NO_MATH :
875                 instantPreviewCO->setCurrentIndex(1);
876                 break;
877         case LyXRC::PREVIEW_ON :
878                 instantPreviewCO->setCurrentIndex(2);
879                 break;
880         }
881
882         int item = 2;
883         switch (rc.display_graphics) {
884                 case graphics::NoDisplay:               item = 3; break;
885                 case graphics::ColorDisplay:    item = 2; break;
886                 case graphics::GrayscaleDisplay:        item = 1; break;
887                 case graphics::MonochromeDisplay:       item = 0; break;
888                 default: break;
889         }
890         displayGraphicsCO->setCurrentIndex(item);
891 }
892
893
894 /////////////////////////////////////////////////////////////////////
895 //
896 // PrefPaths
897 //
898 /////////////////////////////////////////////////////////////////////
899
900 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
901         : PrefModule(qt_("Paths"), form, parent)
902 {
903         setupUi(this);
904         connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
905         connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
906         connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
907         connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
908         connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
909         connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
910         connect(workingDirED, SIGNAL(textChanged(QString)),
911                 this, SIGNAL(changed()));
912         connect(exampleDirED, SIGNAL(textChanged(QString)),
913                 this, SIGNAL(changed()));
914         connect(templateDirED, SIGNAL(textChanged(QString)),
915                 this, SIGNAL(changed()));
916         connect(backupDirED, SIGNAL(textChanged(QString)),
917                 this, SIGNAL(changed()));
918         connect(tempDirED, SIGNAL(textChanged(QString)),
919                 this, SIGNAL(changed()));
920         connect(lyxserverDirED, SIGNAL(textChanged(QString)),
921                 this, SIGNAL(changed()));
922         connect(pathPrefixED, SIGNAL(textChanged(QString)),
923                 this, SIGNAL(changed()));
924 }
925
926
927 void PrefPaths::apply(LyXRC & rc) const
928 {
929         rc.document_path = internal_path(fromqstr(workingDirED->text()));
930         rc.example_path = internal_path(fromqstr(exampleDirED->text()));
931         rc.template_path = internal_path(fromqstr(templateDirED->text()));
932         rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
933         rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
934         rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
935         // FIXME: should be a checkbox only
936         rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
937 }
938
939
940 void PrefPaths::update(LyXRC const & rc)
941 {
942         workingDirED->setText(toqstr(external_path(rc.document_path)));
943         exampleDirED->setText(toqstr(external_path(rc.example_path)));
944         templateDirED->setText(toqstr(external_path(rc.template_path)));
945         backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
946         tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
947         pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
948         // FIXME: should be a checkbox only
949         lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
950 }
951
952
953 void PrefPaths::select_exampledir()
954 {
955         QString file = form_->browsedir(internalPath(exampleDirED->text()),
956                 qt_("Select directory for example files"));
957         if (!file.isEmpty())
958                 exampleDirED->setText(file);
959 }
960
961
962 void PrefPaths::select_templatedir()
963 {
964         QString file = form_->browsedir(internalPath(templateDirED->text()),
965                 qt_("Select a document templates directory"));
966         if (!file.isEmpty())
967                 templateDirED->setText(file);
968 }
969
970
971 void PrefPaths::select_tempdir()
972 {
973         QString file = form_->browsedir(internalPath(tempDirED->text()),
974                 qt_("Select a temporary directory"));
975         if (!file.isEmpty())
976                 tempDirED->setText(file);
977 }
978
979
980 void PrefPaths::select_backupdir()
981 {
982         QString file = form_->browsedir(internalPath(backupDirED->text()),
983                 qt_("Select a backups directory"));
984         if (!file.isEmpty())
985                 backupDirED->setText(file);
986 }
987
988
989 void PrefPaths::select_workingdir()
990 {
991         QString file = form_->browsedir(internalPath(workingDirED->text()),
992                 qt_("Select a document directory"));
993         if (!file.isEmpty())
994                 workingDirED->setText(file);
995 }
996
997
998 void PrefPaths::select_lyxpipe()
999 {
1000         QString file = form_->browse(internalPath(lyxserverDirED->text()),
1001                 qt_("Give a filename for the LyX server pipe"));
1002         if (!file.isEmpty())
1003                 lyxserverDirED->setText(file);
1004 }
1005
1006
1007 /////////////////////////////////////////////////////////////////////
1008 //
1009 // PrefSpellchecker
1010 //
1011 /////////////////////////////////////////////////////////////////////
1012
1013 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
1014         : PrefModule(qt_("Spellchecker"), form, parent)
1015 {
1016         setupUi(this);
1017
1018         connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1019 #if defined (USE_ISPELL)
1020         connect(spellCommandCO, SIGNAL(activated(int)),
1021                 this, SIGNAL(changed()));
1022 #else
1023         spellCommandCO->setEnabled(false);
1024 #endif
1025         connect(altLanguageED, SIGNAL(textChanged(QString)),
1026                 this, SIGNAL(changed()));
1027         connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1028                 this, SIGNAL(changed()));
1029         connect(persDictionaryED, SIGNAL(textChanged(QString)),
1030                 this, SIGNAL(changed()));
1031         connect(compoundWordCB, SIGNAL(clicked()),
1032                 this, SIGNAL(changed()));
1033         connect(inputEncodingCB, SIGNAL(clicked()),
1034                 this, SIGNAL(changed()));
1035
1036         spellCommandCO->addItem(qt_("ispell"));
1037         spellCommandCO->addItem(qt_("aspell"));
1038         spellCommandCO->addItem(qt_("hspell"));
1039 #ifdef USE_PSPELL
1040         spellCommandCO->addItem(qt_("pspell (library)"));
1041 #else
1042 #ifdef USE_ASPELL
1043         spellCommandCO->addItem(qt_("aspell (library)"));
1044 #endif
1045 #endif
1046 }
1047
1048
1049 void PrefSpellchecker::apply(LyXRC & rc) const
1050 {
1051         switch (spellCommandCO->currentIndex()) {
1052                 case 0:
1053                 case 1:
1054                 case 2:
1055                         rc.use_spell_lib = false;
1056                         rc.isp_command = fromqstr(spellCommandCO->currentText());
1057                         break;
1058                 case 3:
1059                         rc.use_spell_lib = true;
1060                         break;
1061         }
1062
1063         // FIXME: remove isp_use_alt_lang
1064         rc.isp_alt_lang = fromqstr(altLanguageED->text());
1065         rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1066         // FIXME: remove isp_use_esc_chars
1067         rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
1068         rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1069         // FIXME: remove isp_use_pers_dict
1070         rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1071         rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1072         rc.isp_accept_compound = compoundWordCB->isChecked();
1073         rc.isp_use_input_encoding = inputEncodingCB->isChecked();
1074 }
1075
1076
1077 void PrefSpellchecker::update(LyXRC const & rc)
1078 {
1079         spellCommandCO->setCurrentIndex(0);
1080
1081         if (rc.isp_command == "ispell") {
1082                 spellCommandCO->setCurrentIndex(0);
1083         } else if (rc.isp_command == "aspell") {
1084                 spellCommandCO->setCurrentIndex(1);
1085         } else if (rc.isp_command == "hspell") {
1086                 spellCommandCO->setCurrentIndex(2);
1087         }
1088
1089         if (rc.use_spell_lib) {
1090 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1091                 spellCommandCO->setCurrentIndex(3);
1092 #endif
1093         }
1094
1095         // FIXME: remove isp_use_alt_lang
1096         altLanguageED->setText(toqstr(rc.isp_alt_lang));
1097         // FIXME: remove isp_use_esc_chars
1098         escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1099         // FIXME: remove isp_use_pers_dict
1100         persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
1101         compoundWordCB->setChecked(rc.isp_accept_compound);
1102         inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1103 }
1104
1105
1106 void PrefSpellchecker::select_dict()
1107 {
1108         QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1109         if (!file.isEmpty())
1110                 persDictionaryED->setText(file);
1111 }
1112
1113
1114
1115 /////////////////////////////////////////////////////////////////////
1116 //
1117 // PrefConverters
1118 //
1119 /////////////////////////////////////////////////////////////////////
1120
1121
1122 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
1123         : PrefModule(qt_("Converters"), form, parent)
1124 {
1125         setupUi(this);
1126
1127         connect(converterNewPB, SIGNAL(clicked()),
1128                 this, SLOT(update_converter()));
1129         connect(converterRemovePB, SIGNAL(clicked()),
1130                 this, SLOT(remove_converter()));
1131         connect(converterModifyPB, SIGNAL(clicked()),
1132                 this, SLOT(update_converter()));
1133         connect(convertersLW, SIGNAL(currentRowChanged(int)),
1134                 this, SLOT(switch_converter()));
1135         connect(converterFromCO, SIGNAL(activated(QString)),
1136                 this, SLOT(converter_changed()));
1137         connect(converterToCO, SIGNAL(activated(QString)),
1138                 this, SLOT(converter_changed()));
1139         connect(converterED, SIGNAL(textEdited(QString)),
1140                 this, SLOT(converter_changed()));
1141         connect(converterFlagED, SIGNAL(textEdited(QString)),
1142                 this, SLOT(converter_changed()));
1143         connect(converterNewPB, SIGNAL(clicked()),
1144                 this, SIGNAL(changed()));
1145         connect(converterRemovePB, SIGNAL(clicked()),
1146                 this, SIGNAL(changed()));
1147         connect(converterModifyPB, SIGNAL(clicked()),
1148                 this, SIGNAL(changed()));
1149         connect(maxAgeLE, SIGNAL(textEdited(QString)),
1150                 this, SIGNAL(changed()));
1151
1152         maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1153         //converterDefGB->setFocusProxy(convertersLW);
1154 }
1155
1156
1157 void PrefConverters::apply(LyXRC & rc) const
1158 {
1159         rc.use_converter_cache = cacheCB->isChecked();
1160         rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1161 }
1162
1163
1164 void PrefConverters::update(LyXRC const & rc)
1165 {
1166         cacheCB->setChecked(rc.use_converter_cache);
1167         QString max_age;
1168         max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1169         maxAgeLE->setText(max_age);
1170         updateGui();
1171 }
1172
1173
1174 void PrefConverters::updateGui()
1175 {
1176         form_->formats().sort();
1177         form_->converters().update(form_->formats());
1178         // save current selection
1179         QString current = converterFromCO->currentText()
1180                 + " -> " + converterToCO->currentText();
1181
1182         converterFromCO->clear();
1183         converterToCO->clear();
1184
1185         Formats::const_iterator cit = form_->formats().begin();
1186         Formats::const_iterator end = form_->formats().end();
1187         for (; cit != end; ++cit) {
1188                 converterFromCO->addItem(toqstr(cit->prettyname()));
1189                 converterToCO->addItem(toqstr(cit->prettyname()));
1190         }
1191
1192         // currentRowChanged(int) is also triggered when updating the listwidget
1193         // block signals to avoid unnecessary calls to switch_converter()
1194         convertersLW->blockSignals(true);
1195         convertersLW->clear();
1196
1197         Converters::const_iterator ccit = form_->converters().begin();
1198         Converters::const_iterator cend = form_->converters().end();
1199         for (; ccit != cend; ++ccit) {
1200                 string const name =
1201                         ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1202                 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1203                 new QListWidgetItem(toqstr(name), convertersLW, type);
1204         }
1205         convertersLW->sortItems(Qt::AscendingOrder);
1206         convertersLW->blockSignals(false);
1207
1208         // restore selection
1209         if (!current.isEmpty()) {
1210                 QList<QListWidgetItem *> const item =
1211                         convertersLW->findItems(current, Qt::MatchExactly);
1212                 if (!item.isEmpty())
1213                         convertersLW->setCurrentItem(item.at(0));
1214         }
1215
1216         // select first element if restoring failed
1217         if (convertersLW->currentRow() == -1)
1218                 convertersLW->setCurrentRow(0);
1219
1220         updateButtons();
1221 }
1222
1223
1224 void PrefConverters::switch_converter()
1225 {
1226         int const cnr = convertersLW->currentItem()->type();
1227         Converter const & c(form_->converters().get(cnr));
1228         converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1229         converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1230         converterED->setText(toqstr(c.command));
1231         converterFlagED->setText(toqstr(c.flags));
1232
1233         updateButtons();
1234 }
1235
1236
1237 void PrefConverters::converter_changed()
1238 {
1239         updateButtons();
1240 }
1241
1242
1243 void PrefConverters::updateButtons()
1244 {
1245         Format const & from = form_->formats().get(converterFromCO->currentIndex());
1246         Format const & to = form_->formats().get(converterToCO->currentIndex());
1247         int const sel = form_->converters().getNumber(from.name(), to.name());
1248         bool const known = sel >= 0;
1249         bool const valid = !(converterED->text().isEmpty()
1250                 || from.name() == to.name());
1251
1252         int const cnr = convertersLW->currentItem()->type();
1253         Converter const & c(form_->converters().get(cnr));
1254         string const old_command = c.command;
1255         string const old_flag = c.flags;
1256         string const new_command(fromqstr(converterED->text()));
1257         string const new_flag(fromqstr(converterFlagED->text()));
1258
1259         bool modified = (old_command != new_command) || (old_flag != new_flag);
1260
1261         converterModifyPB->setEnabled(valid && known && modified);
1262         converterNewPB->setEnabled(valid && !known);
1263         converterRemovePB->setEnabled(known);
1264
1265         maxAgeLE->setEnabled(cacheCB->isChecked());
1266         maxAgeLA->setEnabled(cacheCB->isChecked());
1267 }
1268
1269
1270 // FIXME: user must
1271 // specify unique from/to or it doesn't appear. This is really bad UI
1272 // this is why we can use the same function for both new and modify
1273 void PrefConverters::update_converter()
1274 {
1275         Format const & from = form_->formats().get(converterFromCO->currentIndex());
1276         Format const & to = form_->formats().get(converterToCO->currentIndex());
1277         string const flags = fromqstr(converterFlagED->text());
1278         string const command = fromqstr(converterED->text());
1279
1280         Converter const * old =
1281                 form_->converters().getConverter(from.name(), to.name());
1282         form_->converters().add(from.name(), to.name(), command, flags);
1283
1284         if (!old)
1285                 form_->converters().updateLast(form_->formats());
1286
1287         updateGui();
1288
1289         // Remove all files created by this converter from the cache, since
1290         // the modified converter might create different files.
1291         ConverterCache::get().remove_all(from.name(), to.name());
1292 }
1293
1294
1295 void PrefConverters::remove_converter()
1296 {
1297         Format const & from = form_->formats().get(converterFromCO->currentIndex());
1298         Format const & to = form_->formats().get(converterToCO->currentIndex());
1299         form_->converters().erase(from.name(), to.name());
1300
1301         updateGui();
1302
1303         // Remove all files created by this converter from the cache, since
1304         // a possible new converter might create different files.
1305         ConverterCache::get().remove_all(from.name(), to.name());
1306 }
1307
1308
1309 void PrefConverters::on_cacheCB_stateChanged(int state)
1310 {
1311         maxAgeLE->setEnabled(state == Qt::Checked);
1312         maxAgeLA->setEnabled(state == Qt::Checked);
1313         changed();
1314 }
1315
1316
1317 /////////////////////////////////////////////////////////////////////
1318 //
1319 // PrefFileformats
1320 //
1321 /////////////////////////////////////////////////////////////////////
1322 //
1323 FormatValidator::FormatValidator(QWidget * parent, Formats const & f) 
1324         : QValidator(parent), formats_(f)
1325 {
1326 }
1327
1328
1329 void FormatValidator::fixup(QString & input) const
1330 {
1331         Formats::const_iterator cit = formats_.begin();
1332         Formats::const_iterator end = formats_.end();
1333         for (; cit != end; ++cit) {
1334                 string const name = str(cit);
1335                 if (distance(formats_.begin(), cit) == nr()) {
1336                         input = toqstr(name);
1337                         return;
1338
1339                 }
1340         }
1341 }
1342
1343
1344 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1345 {
1346         Formats::const_iterator cit = formats_.begin();
1347         Formats::const_iterator end = formats_.end();
1348         bool unknown = true;
1349         for (; unknown && cit != end; ++cit) {
1350                 string const name = str(cit);
1351                 if (distance(formats_.begin(), cit) != nr())
1352                         unknown = toqstr(name) != input;
1353         }
1354
1355         if (unknown && !input.isEmpty()) 
1356                 return QValidator::Acceptable;
1357         else
1358                 return QValidator::Intermediate;
1359 }
1360
1361
1362 int FormatValidator::nr() const
1363 {
1364         QComboBox * p = qobject_cast<QComboBox *>(parent());
1365         return p->itemData(p->currentIndex()).toInt();
1366 }
1367
1368
1369 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f) 
1370         : FormatValidator(parent, f)
1371 {
1372 }
1373
1374 string FormatNameValidator::str(Formats::const_iterator it) const
1375 {
1376         return it->name();
1377 }
1378
1379
1380 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f) 
1381         : FormatValidator(parent, f)
1382 {
1383 }
1384
1385
1386 string FormatPrettynameValidator::str(Formats::const_iterator it) const
1387 {
1388         return it->prettyname();
1389 }
1390
1391
1392 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1393         : PrefModule(qt_("File formats"), form, parent)
1394 {
1395         setupUi(this);
1396         formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1397         formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1398
1399         connect(documentCB, SIGNAL(clicked()),
1400                 this, SLOT(setFlags()));
1401         connect(vectorCB, SIGNAL(clicked()),
1402                 this, SLOT(setFlags()));
1403         connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1404                 this, SLOT(updatePrettyname()));
1405         connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1406                 this, SIGNAL(changed()));
1407 }
1408
1409
1410 void PrefFileformats::apply(LyXRC & /*rc*/) const
1411 {
1412 }
1413
1414
1415 void PrefFileformats::update(LyXRC const & /*rc*/)
1416 {
1417         updateView();
1418 }
1419
1420
1421 void PrefFileformats::updateView()
1422 {
1423         QString const current = formatsCB->currentText();
1424
1425         // update combobox with formats
1426         formatsCB->blockSignals(true);
1427         formatsCB->clear();
1428         form_->formats().sort();
1429         Formats::const_iterator cit = form_->formats().begin();
1430         Formats::const_iterator end = form_->formats().end();
1431         for (; cit != end; ++cit)
1432                 formatsCB->addItem(toqstr(cit->prettyname()),
1433                                                         QVariant(form_->formats().getNumber(cit->name())) );
1434
1435         // restore selection
1436         int const item = formatsCB->findText(current, Qt::MatchExactly);
1437         formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1438         on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1439         formatsCB->blockSignals(false);
1440 }
1441
1442
1443 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1444 {
1445         int const nr = formatsCB->itemData(i).toInt();
1446         Format const f = form_->formats().get(nr);
1447
1448         formatED->setText(toqstr(f.name()));
1449         copierED->setText(toqstr(form_->movers().command(f.name())));
1450         extensionED->setText(toqstr(f.extension()));
1451         shortcutED->setText(toqstr(f.shortcut()));
1452         viewerED->setText(toqstr(f.viewer()));
1453         editorED->setText(toqstr(f.editor()));
1454         documentCB->setChecked((f.documentFormat()));
1455         vectorCB->setChecked((f.vectorFormat()));
1456 }
1457
1458
1459 void PrefFileformats::setFlags()
1460 {
1461         int flags = Format::none;
1462         if (documentCB->isChecked())
1463                 flags |= Format::document;
1464         if (vectorCB->isChecked())
1465                 flags |= Format::vector;
1466         currentFormat().setFlags(flags);
1467         changed();
1468 }
1469
1470
1471 void PrefFileformats::on_copierED_textEdited(const QString & s)
1472 {
1473         string const fmt = fromqstr(formatED->text());
1474         form_->movers().set(fmt, fromqstr(s));
1475         changed();
1476 }
1477
1478
1479 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1480 {
1481         currentFormat().setExtension(fromqstr(s));
1482         changed();
1483 }
1484
1485 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1486 {
1487         currentFormat().setViewer(fromqstr(s));
1488         changed();
1489 }
1490
1491
1492 void PrefFileformats::on_editorED_textEdited(const QString & s)
1493 {
1494         currentFormat().setEditor(fromqstr(s));
1495         changed();
1496 }
1497
1498
1499 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1500 {
1501         currentFormat().setShortcut(fromqstr(s));
1502         changed();
1503 }
1504
1505
1506 void PrefFileformats::on_formatED_editingFinished()
1507 {
1508         string const newname = fromqstr(formatED->displayText());
1509         if (newname == currentFormat().name())
1510                 return;
1511
1512         currentFormat().setName(newname);
1513         changed();
1514 }
1515
1516
1517 void PrefFileformats::on_formatED_textChanged(const QString &)
1518 {
1519         QString t = formatED->text();
1520         int p = 0;
1521         bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1522         setValid(formatLA, valid);
1523 }
1524
1525
1526 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1527 {
1528         QString t = formatsCB->currentText();
1529         int p = 0;
1530         bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1531         setValid(formatsLA, valid);
1532 }
1533
1534
1535 void PrefFileformats::updatePrettyname()
1536 {
1537         string const newname = fromqstr(formatsCB->currentText());
1538         if (newname == currentFormat().prettyname())
1539                 return;
1540
1541         currentFormat().setPrettyname(newname);
1542         formatsChanged();
1543         updateView();
1544         changed();
1545 }
1546
1547
1548 Format & PrefFileformats::currentFormat()
1549 {
1550         int const i = formatsCB->currentIndex();
1551         int const nr = formatsCB->itemData(i).toInt();
1552         return form_->formats().get(nr);
1553 }
1554
1555
1556 void PrefFileformats::on_formatNewPB_clicked()
1557 {
1558         form_->formats().add("", "", "", "", "", "", Format::none);
1559         updateView();
1560         formatsCB->setCurrentIndex(0);
1561         formatsCB->setFocus(Qt::OtherFocusReason);
1562 }
1563
1564
1565 void PrefFileformats::on_formatRemovePB_clicked()
1566 {
1567         int const i = formatsCB->currentIndex();
1568         int const nr = formatsCB->itemData(i).toInt();
1569         string const current_text = form_->formats().get(nr).name();
1570         if (form_->converters().formatIsUsed(current_text)) {
1571                 Alert::error(_("Format in use"),
1572                              _("Cannot remove a Format used by a Converter. "
1573                                             "Remove the converter first."));
1574                 return;
1575         }
1576
1577         form_->formats().erase(current_text);
1578         formatsChanged();
1579         updateView();
1580         on_formatsCB_editTextChanged(formatsCB->currentText());
1581         changed();
1582 }
1583
1584
1585 /////////////////////////////////////////////////////////////////////
1586 //
1587 // PrefLanguage
1588 //
1589 /////////////////////////////////////////////////////////////////////
1590
1591 PrefLanguage::PrefLanguage(QWidget * parent)
1592         : PrefModule(qt_("Language"), 0, parent)
1593 {
1594         setupUi(this);
1595
1596         connect(rtlGB, SIGNAL(clicked()),
1597                 this, SIGNAL(changed()));
1598         connect(visualCursorRB, SIGNAL(clicked()),
1599                 this, SIGNAL(changed()));
1600         connect(logicalCursorRB, SIGNAL(clicked()),
1601                 this, SIGNAL(changed()));
1602         connect(markForeignCB, SIGNAL(clicked()),
1603                 this, SIGNAL(changed()));
1604         connect(autoBeginCB, SIGNAL(clicked()),
1605                 this, SIGNAL(changed()));
1606         connect(autoEndCB, SIGNAL(clicked()),
1607                 this, SIGNAL(changed()));
1608         connect(useBabelCB, SIGNAL(clicked()),
1609                 this, SIGNAL(changed()));
1610         connect(globalCB, SIGNAL(clicked()),
1611                 this, SIGNAL(changed()));
1612         connect(languagePackageED, SIGNAL(textChanged(QString)),
1613                 this, SIGNAL(changed()));
1614         connect(startCommandED, SIGNAL(textChanged(QString)),
1615                 this, SIGNAL(changed()));
1616         connect(endCommandED, SIGNAL(textChanged(QString)),
1617                 this, SIGNAL(changed()));
1618         connect(defaultLanguageCO, SIGNAL(activated(int)),
1619                 this, SIGNAL(changed()));
1620
1621         defaultLanguageCO->clear();
1622
1623         // store the lang identifiers for later
1624         foreach (LanguagePair const & lpair, languageData(false)) {
1625                 defaultLanguageCO->addItem(lpair.first);
1626                 lang_.append(lpair.second);
1627         }
1628 }
1629
1630
1631 void PrefLanguage::apply(LyXRC & rc) const
1632 {
1633         // FIXME: remove rtl_support bool
1634         rc.rtl_support = rtlGB->isChecked();
1635         rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1636         rc.mark_foreign_language = markForeignCB->isChecked();
1637         rc.language_auto_begin = autoBeginCB->isChecked();
1638         rc.language_auto_end = autoEndCB->isChecked();
1639         rc.language_use_babel = useBabelCB->isChecked();
1640         rc.language_global_options = globalCB->isChecked();
1641         rc.language_package = fromqstr(languagePackageED->text());
1642         rc.language_command_begin = fromqstr(startCommandED->text());
1643         rc.language_command_end = fromqstr(endCommandED->text());
1644         rc.default_language = fromqstr(lang_[defaultLanguageCO->currentIndex()]);
1645 }
1646
1647
1648 void PrefLanguage::update(LyXRC const & rc)
1649 {
1650         // FIXME: remove rtl_support bool
1651         rtlGB->setChecked(rc.rtl_support);
1652         if (rc.visual_cursor)
1653                 visualCursorRB->setChecked(true);
1654         else
1655                 logicalCursorRB->setChecked(true);
1656         markForeignCB->setChecked(rc.mark_foreign_language);
1657         autoBeginCB->setChecked(rc.language_auto_begin);
1658         autoEndCB->setChecked(rc.language_auto_end);
1659         useBabelCB->setChecked(rc.language_use_babel);
1660         globalCB->setChecked(rc.language_global_options);
1661         languagePackageED->setText(toqstr(rc.language_package));
1662         startCommandED->setText(toqstr(rc.language_command_begin));
1663         endCommandED->setText(toqstr(rc.language_command_end));
1664
1665         int const pos = findPos_helper(lang_, toqstr(rc.default_language));
1666         defaultLanguageCO->setCurrentIndex(pos);
1667 }
1668
1669
1670 /////////////////////////////////////////////////////////////////////
1671 //
1672 // PrefPrinter
1673 //
1674 /////////////////////////////////////////////////////////////////////
1675
1676 PrefPrinter::PrefPrinter(QWidget * parent)
1677         : PrefModule(qt_("Printer"), 0, parent)
1678 {
1679         setupUi(this);
1680
1681         connect(printerAdaptCB, SIGNAL(clicked()),
1682                 this, SIGNAL(changed()));
1683         connect(printerCommandED, SIGNAL(textChanged(QString)),
1684                 this, SIGNAL(changed()));
1685         connect(printerNameED, SIGNAL(textChanged(QString)),
1686                 this, SIGNAL(changed()));
1687         connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1688                 this, SIGNAL(changed()));
1689         connect(printerCopiesED, SIGNAL(textChanged(QString)),
1690                 this, SIGNAL(changed()));
1691         connect(printerReverseED, SIGNAL(textChanged(QString)),
1692                 this, SIGNAL(changed()));
1693         connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1694                 this, SIGNAL(changed()));
1695         connect(printerExtensionED, SIGNAL(textChanged(QString)),
1696                 this, SIGNAL(changed()));
1697         connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1698                 this, SIGNAL(changed()));
1699         connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1700                 this, SIGNAL(changed()));
1701         connect(printerEvenED, SIGNAL(textChanged(QString)),
1702                 this, SIGNAL(changed()));
1703         connect(printerOddED, SIGNAL(textChanged(QString)),
1704                 this, SIGNAL(changed()));
1705         connect(printerCollatedED, SIGNAL(textChanged(QString)),
1706                 this, SIGNAL(changed()));
1707         connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1708                 this, SIGNAL(changed()));
1709         connect(printerToFileED, SIGNAL(textChanged(QString)),
1710                 this, SIGNAL(changed()));
1711         connect(printerExtraED, SIGNAL(textChanged(QString)),
1712                 this, SIGNAL(changed()));
1713         connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1714                 this, SIGNAL(changed()));
1715         connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1716                 this, SIGNAL(changed()));
1717 }
1718
1719
1720 void PrefPrinter::apply(LyXRC & rc) const
1721 {
1722         rc.print_adapt_output = printerAdaptCB->isChecked();
1723         rc.print_command = fromqstr(printerCommandED->text());
1724         rc.printer = fromqstr(printerNameED->text());
1725
1726         rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1727         rc.print_copies_flag = fromqstr(printerCopiesED->text());
1728         rc.print_reverse_flag = fromqstr(printerReverseED->text());
1729         rc.print_to_printer = fromqstr(printerToPrinterED->text());
1730         rc.print_file_extension = fromqstr(printerExtensionED->text());
1731         rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1732         rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1733         rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1734         rc.print_oddpage_flag = fromqstr(printerOddED->text());
1735         rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1736         rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1737         rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1738         rc.print_extra_options = fromqstr(printerExtraED->text());
1739         rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1740         rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1741 }
1742
1743
1744 void PrefPrinter::update(LyXRC const & rc)
1745 {
1746         printerAdaptCB->setChecked(rc.print_adapt_output);
1747         printerCommandED->setText(toqstr(rc.print_command));
1748         printerNameED->setText(toqstr(rc.printer));
1749
1750         printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1751         printerCopiesED->setText(toqstr(rc.print_copies_flag));
1752         printerReverseED->setText(toqstr(rc.print_reverse_flag));
1753         printerToPrinterED->setText(toqstr(rc.print_to_printer));
1754         printerExtensionED->setText(toqstr(rc.print_file_extension));
1755         printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1756         printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1757         printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1758         printerOddED->setText(toqstr(rc.print_oddpage_flag));
1759         printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1760         printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1761         printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1762         printerExtraED->setText(toqstr(rc.print_extra_options));
1763         printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1764         printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1765 }
1766
1767
1768 /////////////////////////////////////////////////////////////////////
1769 //
1770 // PrefUserInterface
1771 //
1772 /////////////////////////////////////////////////////////////////////
1773
1774 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1775         : PrefModule(qt_("User interface"), form, parent)
1776 {
1777         setupUi(this);
1778
1779         connect(autoSaveCB, SIGNAL(toggled(bool)),
1780                 autoSaveSB, SLOT(setEnabled(bool)));
1781         connect(autoSaveCB, SIGNAL(toggled(bool)),
1782                 TextLabel1, SLOT(setEnabled(bool)));
1783         connect(uiFilePB, SIGNAL(clicked()),
1784                 this, SLOT(select_ui()));
1785         connect(uiFileED, SIGNAL(textChanged(QString)),
1786                 this, SIGNAL(changed()));
1787         connect(restoreCursorCB, SIGNAL(clicked()),
1788                 this, SIGNAL(changed()));
1789         connect(loadSessionCB, SIGNAL(clicked()),
1790                 this, SIGNAL(changed()));
1791         connect(allowGeometrySessionCB, SIGNAL(clicked()),
1792                 this, SIGNAL(changed()));
1793         connect(cursorFollowsCB, SIGNAL(clicked()),
1794                 this, SIGNAL(changed()));
1795         connect(sortEnvironmentsCB, SIGNAL(clicked()),
1796                 this, SIGNAL(changed()));
1797         connect(macroEditStyleCO, SIGNAL(activated(int)),
1798                 this, SIGNAL(changed()));
1799         connect(autoSaveSB, SIGNAL(valueChanged(int)),
1800                 this, SIGNAL(changed()));
1801         connect(autoSaveCB, SIGNAL(clicked()),
1802                 this, SIGNAL(changed()));
1803         connect(lastfilesSB, SIGNAL(valueChanged(int)),
1804                 this, SIGNAL(changed()));
1805         connect(tooltipCB, SIGNAL(toggled(bool)),
1806                 this, SIGNAL(changed()));
1807         connect(fullscreenLimitGB, SIGNAL(clicked()),
1808                 this, SIGNAL(changed()));
1809         connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1810                 this, SIGNAL(changed()));
1811         connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1812                 this, SIGNAL(changed()));
1813         connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1814                 this, SIGNAL(changed()));
1815         connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1816                 this, SIGNAL(changed()));
1817         lastfilesSB->setMaximum(maxlastfiles);
1818 }
1819
1820
1821 void PrefUserInterface::apply(LyXRC & rc) const
1822 {
1823         rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1824         rc.use_lastfilepos = restoreCursorCB->isChecked();
1825         rc.load_session = loadSessionCB->isChecked();
1826         rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1827         rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1828         rc.sort_layouts = sortEnvironmentsCB->isChecked();
1829         switch (macroEditStyleCO->currentIndex()) {
1830                 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1831                 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1832                 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST;   break;
1833         }
1834         rc.autosave = autoSaveSB->value() * 60;
1835         rc.make_backup = autoSaveCB->isChecked();
1836         rc.num_lastfiles = lastfilesSB->value();
1837         rc.use_tooltip = tooltipCB->isChecked();
1838         rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1839         rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1840         rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1841         rc.full_screen_width = fullscreenWidthSB->value();
1842         rc.full_screen_limit = fullscreenLimitGB->isChecked();
1843 }
1844
1845
1846 void PrefUserInterface::update(LyXRC const & rc)
1847 {
1848         uiFileED->setText(toqstr(external_path(rc.ui_file)));
1849         restoreCursorCB->setChecked(rc.use_lastfilepos);
1850         loadSessionCB->setChecked(rc.load_session);
1851         allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1852         cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1853         sortEnvironmentsCB->setChecked(rc.sort_layouts);
1854         macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1855         // convert to minutes
1856         int mins(rc.autosave / 60);
1857         if (rc.autosave && !mins)
1858                 mins = 1;
1859         autoSaveSB->setValue(mins);
1860         autoSaveCB->setChecked(rc.make_backup);
1861         lastfilesSB->setValue(rc.num_lastfiles);
1862         tooltipCB->setChecked(rc.use_tooltip);
1863         toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
1864         toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
1865         toggleTabbarCB->setChecked(rc.full_screen_tabbar);
1866         fullscreenWidthSB->setValue(rc.full_screen_width);
1867         fullscreenLimitGB->setChecked(rc.full_screen_limit);
1868
1869 }
1870
1871
1872 void PrefUserInterface::select_ui()
1873 {
1874         QString file = form_->browseUI(internalPath(uiFileED->text()));
1875         if (!file.isEmpty())
1876                 uiFileED->setText(file);
1877 }
1878
1879
1880 /////////////////////////////////////////////////////////////////////
1881 //
1882 // PrefShortcuts
1883 //
1884 /////////////////////////////////////////////////////////////////////
1885
1886
1887 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1888 {
1889         Ui::shortcutUi::setupUi(this);
1890         QDialog::setModal(true);
1891 }
1892
1893
1894 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1895         : PrefModule(qt_("Shortcuts"), form, parent)
1896 {
1897         setupUi(this);
1898
1899         shortcutsTW->setColumnCount(2);
1900         shortcutsTW->headerItem()->setText(0, qt_("Function"));
1901         shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1902         shortcutsTW->setSortingEnabled(true);
1903         // Multi-selection can be annoying.
1904         // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1905         shortcutsTW->header()->resizeSection(0, 200);
1906
1907         connect(bindFilePB, SIGNAL(clicked()),
1908                 this, SLOT(select_bind()));
1909         connect(bindFileED, SIGNAL(textChanged(QString)),
1910                 this, SIGNAL(changed()));
1911         connect(removePB, SIGNAL(clicked()), 
1912                 this, SIGNAL(changed()));
1913         
1914         shortcut_ = new GuiShortcutDialog(this);
1915         shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1916         shortcut_bc_.setOK(shortcut_->okPB);
1917         shortcut_bc_.setCancel(shortcut_->cancelPB);
1918
1919         connect(shortcut_->okPB, SIGNAL(clicked()),
1920                 shortcut_, SLOT(accept()));
1921         connect(shortcut_->okPB, SIGNAL(clicked()), 
1922                 this, SIGNAL(changed()));
1923         connect(shortcut_->cancelPB, SIGNAL(clicked()), 
1924                 shortcut_, SLOT(reject()));
1925         connect(shortcut_->clearPB, SIGNAL(clicked()),
1926                 this, SLOT(shortcut_clearPB_pressed()));
1927         connect(shortcut_->okPB, SIGNAL(clicked()), 
1928                 this, SLOT(shortcut_okPB_pressed()));
1929 }
1930
1931
1932 void PrefShortcuts::apply(LyXRC & rc) const
1933 {
1934         rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1935         // write user_bind and user_unbind to .lyx/bind/user.bind
1936         FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
1937         if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
1938                 lyxerr << "LyX could not create the user bind directory '"
1939                        << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1940                 return;
1941         }
1942         if (!bind_dir.isDirWritable()) {
1943                 lyxerr << "LyX could not write to the user bind directory '"
1944                        << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1945                 return;
1946         }
1947         FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
1948         user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
1949         user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
1950         // immediately apply the keybindings. Why this is not done before?
1951         // The good thing is that the menus are updated automatically.
1952         theTopLevelKeymap().clear();
1953         theTopLevelKeymap().read("site");
1954         theTopLevelKeymap().read(rc.bind_file);
1955         theTopLevelKeymap().read("user");
1956 }
1957
1958
1959 void PrefShortcuts::update(LyXRC const & rc)
1960 {
1961         bindFileED->setText(toqstr(external_path(rc.bind_file)));
1962         //
1963         system_bind_.clear();
1964         user_bind_.clear();
1965         user_unbind_.clear();
1966         system_bind_.read(rc.bind_file);
1967         // \unbind in user.bind is added to user_unbind_
1968         user_bind_.read("user", &user_unbind_);
1969         updateShortcutsTW();
1970 }
1971
1972
1973 void PrefShortcuts::updateShortcutsTW()
1974 {
1975         shortcutsTW->clear();
1976
1977         editItem_ = new QTreeWidgetItem(shortcutsTW);
1978         editItem_->setText(0, toqstr("Cursor, Mouse and Editing functions"));
1979         editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
1980
1981         mathItem_ = new QTreeWidgetItem(shortcutsTW);
1982         mathItem_->setText(0, toqstr("Mathematical Symbols"));
1983         mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
1984         
1985         bufferItem_ = new QTreeWidgetItem(shortcutsTW);
1986         bufferItem_->setText(0, toqstr("Buffer and Window"));
1987         bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
1988         
1989         layoutItem_ = new QTreeWidgetItem(shortcutsTW);
1990         layoutItem_->setText(0, toqstr("Font, Layouts and Textclasses"));
1991         layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
1992
1993         systemItem_ = new QTreeWidgetItem(shortcutsTW);
1994         systemItem_->setText(0, toqstr("System and Miscellaneous"));
1995         systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
1996
1997         // listBindings(unbound=true) lists all bound and unbound lfuns
1998         // Items in this list is tagged by its source.
1999         KeyMap::BindingList bindinglist = system_bind_.listBindings(true, 
2000                 static_cast<int>(System));
2001         KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2002                 static_cast<int>(UserBind));
2003         KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2004                 static_cast<int>(UserUnbind));
2005         bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2006                         user_bindinglist.end());
2007         bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2008                         user_unbindinglist.end());
2009
2010         KeyMap::BindingList::const_iterator it = bindinglist.begin();
2011         KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2012         for (; it != it_end; ++it)
2013                 insertShortcutItem(it->request, it->sequence, item_type(it->tag));
2014
2015         shortcutsTW->sortItems(0, Qt::AscendingOrder);
2016         QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2017         removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2018 }
2019
2020
2021 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
2022 {
2023         item->setData(0, Qt::UserRole, QVariant(tag));
2024         QFont font;
2025
2026         switch (tag) {
2027         case System:
2028                 break;
2029         case UserBind:
2030                 font.setBold(true);
2031                 break;
2032         case UserUnbind:
2033                 font.setStrikeOut(true);
2034                 break;
2035         // this item is not displayed now.
2036         case UserExtraUnbind:
2037                 font.setStrikeOut(true);
2038                 break;
2039         }
2040
2041         item->setFont(1, font);
2042 }
2043
2044
2045 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2046                 KeySequence const & seq, item_type tag)
2047 {
2048         kb_action action = lfun.action;
2049         string const action_name = lyxaction.getActionName(action);
2050         QString const lfun_name = toqstr(from_utf8(action_name) 
2051                         + " " + lfun.argument());
2052         QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2053         item_type item_tag = tag;
2054
2055         QTreeWidgetItem * newItem = NULL;
2056         // for unbind items, try to find an existing item in the system bind list
2057         if (tag == UserUnbind) {
2058                 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name, 
2059                         Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2060                 for (int i = 0; i < items.size(); ++i) {
2061                         if (items[i]->text(1) == shortcut)
2062                                 newItem = items[i];
2063                                 break;
2064                         }
2065                 // if not found, this unbind item is UserExtraUnbind
2066                 // Such an item is not displayed to avoid confusion (what is 
2067                 // unmatched removed?).
2068                 if (!newItem) {
2069                         item_tag = UserExtraUnbind;
2070                         return NULL;
2071                 }
2072         }
2073         if (!newItem) {
2074                 switch(lyxaction.getActionType(action)) {
2075                 case LyXAction::Hidden:
2076                         return NULL;
2077                 case LyXAction::Edit:
2078                         newItem = new QTreeWidgetItem(editItem_);
2079                         break;
2080                 case LyXAction::Math:
2081                         newItem = new QTreeWidgetItem(mathItem_);
2082                         break;
2083                 case LyXAction::Buffer:
2084                         newItem = new QTreeWidgetItem(bufferItem_);
2085                         break;
2086                 case LyXAction::Layout:
2087                         newItem = new QTreeWidgetItem(layoutItem_);
2088                         break;
2089                 case LyXAction::System:
2090                         newItem = new QTreeWidgetItem(systemItem_);
2091                         break;
2092                 default:
2093                         // this should not happen
2094                         newItem = new QTreeWidgetItem(shortcutsTW);
2095                 }
2096         }
2097
2098         newItem->setText(0, lfun_name);
2099         newItem->setText(1, shortcut);
2100         // record BindFile representation to recover KeySequence when needed.
2101         newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2102         setItemType(newItem, item_tag);
2103         return newItem;
2104 }
2105
2106
2107 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2108 {
2109         QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2110         removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2111         if (items.isEmpty())
2112                 return;
2113         
2114         item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
2115         if (tag == UserUnbind)
2116                 removePB->setText(toqstr("Restore"));
2117         else
2118                 removePB->setText(toqstr("Remove"));
2119 }
2120
2121
2122 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2123 {
2124         QTreeWidgetItem * item = shortcutsTW->currentItem();
2125         if (item->flags() & Qt::ItemIsSelectable) {
2126                 shortcut_->lfunLE->setText(item->text(0));
2127                 // clear the shortcut because I assume that a user will enter
2128                 // a new shortcut.
2129                 shortcut_->shortcutLE->reset();
2130                 shortcut_->shortcutLE->setFocus();
2131                 shortcut_->exec();
2132         }
2133 }
2134
2135
2136 void PrefShortcuts::select_bind()
2137 {
2138         QString file = form_->browsebind(internalPath(bindFileED->text()));
2139         if (!file.isEmpty()) {
2140                 bindFileED->setText(file);
2141                 system_bind_ = KeyMap();
2142                 system_bind_.read(fromqstr(file));
2143                 updateShortcutsTW();
2144         }
2145 }
2146
2147
2148 void PrefShortcuts::on_newPB_pressed()
2149 {
2150         shortcut_->lfunLE->clear();
2151         shortcut_->shortcutLE->reset();
2152         shortcut_->exec();
2153 }
2154
2155
2156 void PrefShortcuts::on_removePB_pressed()
2157 {
2158         // it seems that only one item can be selected, but I am
2159         // removing all selected items anyway.
2160         QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2161         for (int i = 0; i < items.size(); ++i) {
2162                 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2163                 string lfun = fromqstr(items[i]->text(0));
2164                 FuncRequest func = lyxaction.lookupFunc(lfun);
2165                 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2166                 
2167                 switch (tag) {
2168                 case System: {
2169                         // for system bind, we do not touch the item
2170                         // but add an user unbind item
2171                         user_unbind_.bind(shortcut, func);
2172                         setItemType(items[i], UserUnbind);
2173                         removePB->setText(toqstr("Restore"));
2174                         break;
2175                 }
2176                 case UserBind: {
2177                         // for user_bind, we remove this bind
2178                         QTreeWidgetItem * parent = items[i]->parent();
2179                         int itemIdx = parent->indexOfChild(items[i]);
2180                         parent->takeChild(itemIdx);
2181                         if (itemIdx > 0)
2182                                 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2183                         else
2184                                 shortcutsTW->scrollToItem(parent);
2185                         user_bind_.unbind(shortcut, func);
2186                         break;
2187                 }
2188                 case UserUnbind: {
2189                         // for user_unbind, we remove the unbind, and the item
2190                         // become System again.
2191                         user_unbind_.unbind(shortcut, func);
2192                         setItemType(items[i], System);
2193                         removePB->setText(toqstr("Remove"));
2194                         break;
2195                 }
2196                 case UserExtraUnbind: {
2197                         // for user unbind that is not in system bind file,
2198                         // remove this unbind file
2199                         QTreeWidgetItem * parent = items[i]->parent();
2200                         parent->takeChild(parent->indexOfChild(items[i]));
2201                         user_unbind_.unbind(shortcut, func);
2202                 }
2203                 }
2204         }
2205 }
2206
2207
2208 void PrefShortcuts::on_searchLE_textEdited()
2209 {
2210         if (searchLE->text().isEmpty()) {
2211                 // show all hidden items
2212                 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2213                 while (*it)
2214                         shortcutsTW->setItemHidden(*it++, false);
2215                 return;
2216         }
2217         // search both columns
2218         QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2219                 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2220         matched += shortcutsTW->findItems(searchLE->text(),
2221                 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2222         
2223         // hide everyone (to avoid searching in matched QList repeatedly
2224         QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2225         while (*it)
2226                 shortcutsTW->setItemHidden(*it++, true);
2227         // show matched items
2228         for (int i = 0; i < matched.size(); ++i) {
2229                 shortcutsTW->setItemHidden(matched[i], false);
2230         shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2231         }
2232 }
2233
2234
2235 void PrefShortcuts::shortcut_okPB_pressed()
2236 {
2237         string lfun = fromqstr(shortcut_->lfunLE->text());
2238         FuncRequest func = lyxaction.lookupFunc(lfun);
2239
2240         if (func.action == LFUN_UNKNOWN_ACTION) {
2241                 Alert::error(_("Failed to create shortcut"),
2242                         _("Unknown or invalid LyX function"));
2243                 return;
2244         }
2245
2246         KeySequence k = shortcut_->shortcutLE->getKeySequence();
2247         if (k.length() == 0) {
2248                 Alert::error(_("Failed to create shortcut"),
2249                         _("Invalid or empty key sequence"));
2250                 return;
2251         }
2252
2253         // if both lfun and shortcut is valid
2254         if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2255                 Alert::error(_("Failed to create shortcut"),
2256                         _("Shortcut is already defined"));
2257                 return;
2258         }
2259                 
2260         QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2261         if (item) {
2262                 user_bind_.bind(&k, func);
2263                 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2264                 shortcutsTW->setItemExpanded(item->parent(), true);
2265                 shortcutsTW->scrollToItem(item);
2266         } else {
2267                 Alert::error(_("Failed to create shortcut"),
2268                         _("Can not insert shortcut to the list"));
2269                 return;
2270         }
2271 }
2272
2273
2274 void PrefShortcuts::shortcut_clearPB_pressed()
2275 {
2276         shortcut_->shortcutLE->reset();
2277         shortcut_->shortcutLE->setFocus();
2278 }
2279
2280
2281 /////////////////////////////////////////////////////////////////////
2282 //
2283 // PrefIdentity
2284 //
2285 /////////////////////////////////////////////////////////////////////
2286
2287 PrefIdentity::PrefIdentity(QWidget * parent)
2288         : PrefModule(qt_("Identity"), 0, parent)
2289 {
2290         setupUi(this);
2291
2292         connect(nameED, SIGNAL(textChanged(QString)),
2293                 this, SIGNAL(changed()));
2294         connect(emailED, SIGNAL(textChanged(QString)),
2295                 this, SIGNAL(changed()));
2296 }
2297
2298
2299 void PrefIdentity::apply(LyXRC & rc) const
2300 {
2301         rc.user_name = fromqstr(nameED->text());
2302         rc.user_email = fromqstr(emailED->text());
2303 }
2304
2305
2306 void PrefIdentity::update(LyXRC const & rc)
2307 {
2308         nameED->setText(toqstr(rc.user_name));
2309         emailED->setText(toqstr(rc.user_email));
2310 }
2311
2312
2313
2314 /////////////////////////////////////////////////////////////////////
2315 //
2316 // GuiPreferences
2317 //
2318 /////////////////////////////////////////////////////////////////////
2319
2320 GuiPreferences::GuiPreferences(GuiView & lv)
2321         : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2322 {
2323         setupUi(this);
2324
2325         QDialog::setModal(false);
2326
2327         connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2328         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2329         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2330         connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2331
2332         add(new PrefUserInterface(this));
2333         add(new PrefShortcuts(this));
2334         add(new PrefScreenFonts(this));
2335         add(new PrefColors(this));
2336         add(new PrefDisplay);
2337         add(new PrefInput(this));
2338
2339         add(new PrefPaths(this));
2340
2341         add(new PrefIdentity);
2342
2343         add(new PrefLanguage);
2344         add(new PrefSpellchecker(this));
2345
2346         add(new PrefPrinter);
2347         add(new PrefDate);
2348         add(new PrefPlaintext);
2349         add(new PrefLatex(this));
2350
2351         PrefConverters * converters = new PrefConverters(this);
2352         PrefFileformats * formats = new PrefFileformats(this);
2353         connect(formats, SIGNAL(formatsChanged()),
2354                         converters, SLOT(updateGui()));
2355         add(converters);
2356         add(formats);
2357
2358         prefsPS->setCurrentPanel(qt_("User interface"));
2359 // FIXME: hack to work around resizing bug in Qt >= 4.2
2360 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2361 #if QT_VERSION >= 0x040200
2362         prefsPS->updateGeometry();
2363 #endif
2364
2365         bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2366         bc().setOK(savePB);
2367         bc().setApply(applyPB);
2368         bc().setCancel(closePB);
2369         bc().setRestore(restorePB);
2370 }
2371
2372
2373 void GuiPreferences::add(PrefModule * module)
2374 {
2375         BOOST_ASSERT(module);
2376         prefsPS->addPanel(module, module->title());
2377         connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2378         modules_.push_back(module);
2379 }
2380
2381
2382 void GuiPreferences::change_adaptor()
2383 {
2384         changed();
2385 }
2386
2387
2388 void GuiPreferences::apply(LyXRC & rc) const
2389 {
2390         size_t end = modules_.size();
2391         for (size_t i = 0; i != end; ++i)
2392                 modules_[i]->apply(rc);
2393 }
2394
2395
2396 void GuiPreferences::updateRc(LyXRC const & rc)
2397 {
2398         size_t const end = modules_.size();
2399         for (size_t i = 0; i != end; ++i)
2400                 modules_[i]->update(rc);
2401 }
2402
2403
2404 void GuiPreferences::applyView()
2405 {
2406         apply(rc());
2407 }
2408
2409
2410 void GuiPreferences::updateContents()
2411 {
2412         updateRc(rc());
2413 }
2414
2415
2416 bool GuiPreferences::initialiseParams(string const &)
2417 {
2418         rc_ = lyxrc;
2419         formats_ = lyx::formats;
2420         converters_ = theConverters();
2421         converters_.update(formats_);
2422         movers_ = theMovers();
2423         colors_.clear();
2424         update_screen_font_ = false;
2425
2426         return true;
2427 }
2428
2429
2430 void GuiPreferences::dispatchParams()
2431 {
2432         ostringstream ss;
2433         rc_.write(ss, true);
2434         dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str())); 
2435         // FIXME: these need lfuns
2436         // FIXME UNICODE
2437         theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2438
2439         lyx::formats = formats_;
2440
2441         theConverters() = converters_;
2442         theConverters().update(lyx::formats);
2443         theConverters().buildGraph();
2444
2445         theMovers() = movers_;
2446
2447         vector<string>::const_iterator it = colors_.begin();
2448         vector<string>::const_iterator const end = colors_.end();
2449         for (; it != end; ++it)
2450                 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2451         colors_.clear();
2452
2453         if (update_screen_font_) {
2454                 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2455                 update_screen_font_ = false;
2456         }
2457
2458         // The Save button has been pressed
2459         if (isClosing())
2460                 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2461 }
2462
2463
2464 void GuiPreferences::setColor(ColorCode col, string const & hex)
2465 {
2466         colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2467 }
2468
2469
2470 void GuiPreferences::updateScreenFonts()
2471 {
2472         update_screen_font_ = true;
2473 }
2474
2475
2476 QString GuiPreferences::browsebind(QString const & file) const
2477 {
2478         return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2479                              FileFilterList(_("LyX bind files (*.bind)")));
2480 }
2481
2482
2483 QString GuiPreferences::browseUI(QString const & file) const
2484 {
2485         return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2486                              FileFilterList(_("LyX UI files (*.ui)")));
2487 }
2488
2489
2490 QString GuiPreferences::browsekbmap(QString const & file) const
2491 {
2492         return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2493                              FileFilterList(_("LyX keyboard maps (*.kmap)")));
2494 }
2495
2496
2497 QString GuiPreferences::browsedict(QString const & file) const
2498 {
2499         return browseFile(file, qt_("Choose personal dictionary"),
2500                 FileFilterList(lyxrc.use_spell_lib ? _("*.pws") : _("*.ispell")));
2501 }
2502
2503
2504 QString GuiPreferences::browse(QString const & file,
2505                                   QString const & title) const
2506 {
2507         return browseFile(file, title, FileFilterList(), true);
2508 }
2509
2510
2511 QString GuiPreferences::browsedir(QString const & path,
2512                                      QString const & title) const
2513 {
2514         return browseDir(path, title);
2515 }
2516
2517
2518 // We support less paper sizes than the document dialog
2519 // Therefore this adjustment is needed.
2520 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2521 {
2522         switch (i) {
2523         case 0:
2524                 return PAPER_DEFAULT;
2525         case 1:
2526                 return PAPER_USLETTER;
2527         case 2:
2528                 return PAPER_USLEGAL;
2529         case 3:
2530                 return PAPER_USEXECUTIVE;
2531         case 4:
2532                 return PAPER_A3;
2533         case 5:
2534                 return PAPER_A4;
2535         case 6:
2536                 return PAPER_A5;
2537         case 7:
2538                 return PAPER_B5;
2539         default:
2540                 // should not happen
2541                 return PAPER_DEFAULT;
2542         }
2543 }
2544
2545
2546 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2547 {
2548         switch (papersize) {
2549         case PAPER_DEFAULT:
2550                 return 0;
2551         case PAPER_USLETTER:
2552                 return 1;
2553         case PAPER_USLEGAL:
2554                 return 2;
2555         case PAPER_USEXECUTIVE:
2556                 return 3;
2557         case PAPER_A3:
2558                 return 4;
2559         case PAPER_A4:
2560                 return 5;
2561         case PAPER_A5:
2562                 return 6;
2563         case PAPER_B5:
2564                 return 7;
2565         default:
2566                 // should not happen
2567                 return 0;
2568         }
2569 }
2570
2571
2572 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2573
2574
2575 } // namespace frontend
2576 } // namespace lyx
2577
2578 #include "GuiPrefs_moc.cpp"