]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrefs.cpp
Remove unused UI file.
[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 "ColorCache.h"
17 #include "FileDialog.h"
18 #include "GuiApplication.h"
19 #include "GuiFontExample.h"
20 #include "GuiFontLoader.h"
21 #include "GuiKeySymbol.h"
22 #include "qt_helpers.h"
23
24 #include "BufferList.h"
25 #include "Color.h"
26 #include "ColorSet.h"
27 #include "ConverterCache.h"
28 #include "FontEnums.h"
29 #include "FuncRequest.h"
30 #include "KeyMap.h"
31 #include "KeySequence.h"
32 #include "Language.h"
33 #include "LyXAction.h"
34 #include "PanelStack.h"
35 #include "paper.h"
36 #include "Session.h"
37 #include "SpellChecker.h"
38
39 #include "support/debug.h"
40 #include "support/FileName.h"
41 #include "support/filetools.h"
42 #include "support/foreach.h"
43 #include "support/gettext.h"
44 #include "support/lstrings.h"
45 #include "support/os.h"
46 #include "support/Package.h"
47
48 #include "graphics/GraphicsTypes.h"
49
50 #include "frontends/alert.h"
51 #include "frontends/Application.h"
52 #include "frontends/FontLoader.h"
53
54 #include <QAbstractItemModel>
55 #include <QCheckBox>
56 #include <QColorDialog>
57 #include <QFontDatabase>
58 #include <QHeaderView>
59 #include <QLineEdit>
60 #include <QMessageBox>
61 #include <QPixmapCache>
62 #include <QPushButton>
63 #include <QSpinBox>
64 #include <QString>
65 #include <QTreeWidget>
66 #include <QTreeWidgetItem>
67 #include <QValidator>
68
69 #include <iomanip>
70 #include <sstream>
71 #include <algorithm>
72
73 using namespace Ui;
74
75 using namespace std;
76 using namespace lyx::support;
77 using namespace lyx::support::os;
78
79 namespace lyx {
80 namespace frontend {
81
82 /////////////////////////////////////////////////////////////////////
83 //
84 // Browser Helpers
85 //
86 /////////////////////////////////////////////////////////////////////
87
88 /** Launch a file dialog and return the chosen file.
89         filename: a suggested filename.
90         title: the title of the dialog.
91         pattern: *.ps etc.
92         dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
93 */
94 QString browseFile(QString const & filename,
95         QString const & title,
96         QStringList const & filters,
97         bool save = false,
98         QString const & label1 = QString(),
99         QString const & dir1 = QString(),
100         QString const & label2 = QString(),
101         QString const & dir2 = QString(),
102         QString const & fallback_dir = QString())
103 {
104         QString lastPath = ".";
105         if (!filename.isEmpty())
106                 lastPath = onlyPath(filename);
107         else if(!fallback_dir.isEmpty())
108                 lastPath = fallback_dir;
109
110         FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
111         dlg.setButton2(label1, dir1);
112         dlg.setButton2(label2, dir2);
113
114         FileDialog::Result result;
115
116         if (save)
117                 result = dlg.save(lastPath, filters, onlyFilename(filename));
118         else
119                 result = dlg.open(lastPath, filters, onlyFilename(filename));
120
121         return result.second;
122 }
123
124
125 /** Wrapper around browseFile which tries to provide a filename
126 *  relative to the user or system directory. The dir, name and ext
127 *  parameters have the same meaning as in the
128 *  support::LibFileSearch function.
129 */
130 QString browseLibFile(QString const & dir,
131         QString const & name,
132         QString const & ext,
133         QString const & title,
134         QStringList const & filters)
135 {
136         // FIXME UNICODE
137         QString const label1 = qt_("System files|#S#s");
138         QString const dir1 =
139                 toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
140
141         QString const label2 = qt_("User files|#U#u");
142         QString const dir2 =
143                 toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
144
145         QString const result = browseFile(toqstr(
146                 libFileSearch(dir, name, ext).absFilename()),
147                 title, filters, false, dir1, dir2, QString(), QString(), dir1);
148
149         // remove the extension if it is the default one
150         QString noextresult;
151         if (getExtension(result) == ext)
152                 noextresult = removeExtension(result);
153         else
154                 noextresult = result;
155
156         // remove the directory, if it is the default one
157         QString const file = onlyFilename(noextresult);
158         if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
159                 return file;
160         else
161                 return noextresult;
162 }
163
164
165 /** Launch a file dialog and return the chosen directory.
166         pathname: a suggested pathname.
167         title: the title of the dialog.
168         dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
169 */
170 QString browseDir(QString const & pathname,
171         QString const & title,
172         QString const & label1 = QString(),
173         QString const & dir1 = QString(),
174         QString const & label2 = QString(),
175         QString const & dir2 = QString())
176 {
177         QString lastPath = ".";
178         if (!pathname.isEmpty())
179                 lastPath = onlyPath(pathname);
180
181         FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
182         dlg.setButton1(label1, dir1);
183         dlg.setButton2(label2, dir2);
184
185         FileDialog::Result const result =
186                 dlg.opendir(lastPath, onlyFilename(pathname));
187
188         return result.second;
189 }
190
191
192 } // namespace frontend
193
194
195 QString browseRelFile(QString const & filename, QString const & refpath,
196         QString const & title, QStringList const & filters, bool save,
197         QString const & label1, QString const & dir1,
198         QString const & label2, QString const & dir2)
199 {
200         QString const fname = makeAbsPath(filename, refpath);
201
202
203         QString const outname =
204                 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
205
206         QString const reloutname =
207                 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
208
209         if (reloutname.startsWith("../"))
210                 return outname;
211         else
212                 return reloutname;
213 }
214
215
216
217 /////////////////////////////////////////////////////////////////////
218 //
219 // Helpers
220 //
221 /////////////////////////////////////////////////////////////////////
222
223 namespace frontend {
224
225 string const catLookAndFeel = N_("Look & Feel");
226 string const catEditing = N_("Editing");
227 string const catLanguage = N_("Language Settings");
228 string const catOutput = N_("Output");
229 string const catFiles = N_("File Handling");
230
231 static void parseFontName(QString const & mangled0,
232         string & name, string & foundry)
233 {
234         string mangled = fromqstr(mangled0);
235         size_t const idx = mangled.find('[');
236         if (idx == string::npos || idx == 0) {
237                 name = mangled;
238                 foundry.clear();
239         } else {
240                 name = mangled.substr(0, idx - 1),
241                 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
242         }
243 }
244
245
246 static void setComboxFont(QComboBox * cb, string const & family,
247         string const & foundry)
248 {
249         QString fontname = toqstr(family);
250         if (!foundry.empty())
251                 fontname += " [" + toqstr(foundry) + ']';
252
253         for (int i = 0; i != cb->count(); ++i) {
254                 if (cb->itemText(i) == fontname) {
255                         cb->setCurrentIndex(i);
256                         return;
257                 }
258         }
259
260         // Try matching without foundry name
261
262         // We count in reverse in order to prefer the Xft foundry
263         for (int i = cb->count(); --i >= 0;) {
264                 string name, foundry;
265                 parseFontName(cb->itemText(i), name, foundry);
266                 if (compare_ascii_no_case(name, family) == 0) {
267                         cb->setCurrentIndex(i);
268                         return;
269                 }
270         }
271
272         // family alone can contain e.g. "Helvetica [Adobe]"
273         string tmpname, tmpfoundry;
274         parseFontName(toqstr(family), tmpname, tmpfoundry);
275
276         // We count in reverse in order to prefer the Xft foundry
277         for (int i = cb->count(); --i >= 0; ) {
278                 string name, foundry;
279                 parseFontName(cb->itemText(i), name, foundry);
280                 if (compare_ascii_no_case(name, foundry) == 0) {
281                         cb->setCurrentIndex(i);
282                         return;
283                 }
284         }
285
286         // Bleh, default fonts, and the names couldn't be found. Hack
287         // for bug 1063.
288
289         QFont font;
290         font.setKerning(false);
291
292         QString const font_family = toqstr(family);
293         if (font_family == guiApp->romanFontName()) {
294                 font.setStyleHint(QFont::Serif);
295                 font.setFamily(font_family);
296         } else if (font_family == guiApp->sansFontName()) {
297                 font.setStyleHint(QFont::SansSerif);
298                 font.setFamily(font_family);
299         } else if (font_family == guiApp->typewriterFontName()) {
300                 font.setStyleHint(QFont::TypeWriter);
301                 font.setFamily(font_family);
302         } else {
303                 LYXERR0("FAILED to find the default font: '"
304                        << foundry << "', '" << family << '\'');
305                 return;
306         }
307
308         QFontInfo info(font);
309         string default_font_name, dummyfoundry;
310         parseFontName(info.family(), default_font_name, dummyfoundry);
311         LYXERR0("Apparent font is " << default_font_name);
312
313         for (int i = 0; i < cb->count(); ++i) {
314                 LYXERR0("Looking at " << cb->itemText(i));
315                 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
316                                     default_font_name) == 0) {
317                         cb->setCurrentIndex(i);
318                         return;
319                 }
320         }
321
322         LYXERR0("FAILED to find the font: '"
323                << foundry << "', '" << family << '\'');
324 }
325
326
327
328 /////////////////////////////////////////////////////////////////////
329 //
330 // PrefPlaintext
331 //
332 /////////////////////////////////////////////////////////////////////
333
334 PrefPlaintext::PrefPlaintext(GuiPreferences * form)
335         : PrefModule(qt_(catOutput), qt_("Plain text"), form)
336 {
337         setupUi(this);
338         connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
339                 this, SIGNAL(changed()));
340 }
341
342
343 void PrefPlaintext::apply(LyXRC & rc) const
344 {
345         rc.plaintext_linelen = plaintextLinelengthSB->value();
346 }
347
348
349 void PrefPlaintext::update(LyXRC const & rc)
350 {
351         plaintextLinelengthSB->setValue(rc.plaintext_linelen);
352 }
353
354
355 /////////////////////////////////////////////////////////////////////
356 //
357 // StrftimeValidator
358 //
359 /////////////////////////////////////////////////////////////////////
360
361 class StrftimeValidator : public QValidator
362 {
363 public:
364         StrftimeValidator(QWidget *);
365         QValidator::State validate(QString & input, int & pos) const;
366 };
367
368
369 StrftimeValidator::StrftimeValidator(QWidget * parent)
370         : QValidator(parent)
371 {
372 }
373
374
375 QValidator::State StrftimeValidator::validate(QString & input, int & /*pos*/) const
376 {
377         if (is_valid_strftime(fromqstr(input)))
378                 return QValidator::Acceptable;
379         else
380                 return QValidator::Intermediate;
381 }
382
383
384 /////////////////////////////////////////////////////////////////////
385 //
386 // PrefDate
387 //
388 /////////////////////////////////////////////////////////////////////
389
390 PrefDate::PrefDate(GuiPreferences * form)
391         : PrefModule(qt_(catOutput), qt_("Date format"), form)
392 {
393         setupUi(this);
394         DateED->setValidator(new StrftimeValidator(DateED));
395         connect(DateED, SIGNAL(textChanged(QString)),
396                 this, SIGNAL(changed()));
397 }
398
399
400 void PrefDate::on_DateED_textChanged(const QString &)
401 {
402         QString t = DateED->text();
403         int p = 0;
404         bool valid = DateED->validator()->validate(t, p)
405                      == QValidator::Acceptable;
406         setValid(DateLA, valid);
407 }
408
409
410 void PrefDate::apply(LyXRC & rc) const
411 {
412         rc.date_insert_format = fromqstr(DateED->text());
413 }
414
415
416 void PrefDate::update(LyXRC const & rc)
417 {
418         DateED->setText(toqstr(rc.date_insert_format));
419 }
420
421
422 /////////////////////////////////////////////////////////////////////
423 //
424 // PrefInput
425 //
426 /////////////////////////////////////////////////////////////////////
427
428 PrefInput::PrefInput(GuiPreferences * form)
429         : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
430 {
431         setupUi(this);
432
433         connect(keymapCB, SIGNAL(clicked()),
434                 this, SIGNAL(changed()));
435         connect(firstKeymapED, SIGNAL(textChanged(QString)),
436                 this, SIGNAL(changed()));
437         connect(secondKeymapED, SIGNAL(textChanged(QString)),
438                 this, SIGNAL(changed()));
439         connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
440                 this, SIGNAL(changed()));
441 }
442
443
444 void PrefInput::apply(LyXRC & rc) const
445 {
446         // FIXME: can derive CB from the two EDs
447         rc.use_kbmap = keymapCB->isChecked();
448         rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
449         rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
450         rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
451 }
452
453
454 void PrefInput::update(LyXRC const & rc)
455 {
456         // FIXME: can derive CB from the two EDs
457         keymapCB->setChecked(rc.use_kbmap);
458         firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
459         secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
460         mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
461 }
462
463
464 QString PrefInput::testKeymap(QString const & keymap)
465 {
466         return form_->browsekbmap(internalPath(keymap));
467 }
468
469
470 void PrefInput::on_firstKeymapPB_clicked(bool)
471 {
472         QString const file = testKeymap(firstKeymapED->text());
473         if (!file.isEmpty())
474                 firstKeymapED->setText(file);
475 }
476
477
478 void PrefInput::on_secondKeymapPB_clicked(bool)
479 {
480         QString const file = testKeymap(secondKeymapED->text());
481         if (!file.isEmpty())
482                 secondKeymapED->setText(file);
483 }
484
485
486 void PrefInput::on_keymapCB_toggled(bool keymap)
487 {
488         firstKeymapLA->setEnabled(keymap);
489         secondKeymapLA->setEnabled(keymap);
490         firstKeymapED->setEnabled(keymap);
491         secondKeymapED->setEnabled(keymap);
492         firstKeymapPB->setEnabled(keymap);
493         secondKeymapPB->setEnabled(keymap);
494 }
495
496
497 /////////////////////////////////////////////////////////////////////
498 //
499 // PrefCompletion
500 //
501 /////////////////////////////////////////////////////////////////////
502
503 PrefCompletion::PrefCompletion(GuiPreferences * form)
504         : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
505 {
506         setupUi(this);
507
508         connect(inlineDelaySB, SIGNAL(valueChanged(double)),
509                 this, SIGNAL(changed()));
510         connect(inlineMathCB, SIGNAL(clicked()),
511                 this, SIGNAL(changed()));
512         connect(inlineTextCB, SIGNAL(clicked()),
513                 this, SIGNAL(changed()));
514         connect(inlineDotsCB, SIGNAL(clicked()),
515                 this, SIGNAL(changed()));
516         connect(popupDelaySB, SIGNAL(valueChanged(double)),
517                 this, SIGNAL(changed()));
518         connect(popupMathCB, SIGNAL(clicked()),
519                 this, SIGNAL(changed()));
520         connect(autocorrectionCB, SIGNAL(clicked()),
521                 this, SIGNAL(changed()));
522         connect(popupTextCB, SIGNAL(clicked()),
523                 this, SIGNAL(changed()));
524         connect(popupAfterCompleteCB, SIGNAL(clicked()),
525                 this, SIGNAL(changed()));
526         connect(cursorTextCB, SIGNAL(clicked()),
527                 this, SIGNAL(changed()));
528 }
529
530
531 void PrefCompletion::on_inlineTextCB_clicked()
532 {
533         enableCB();
534 }
535
536
537 void PrefCompletion::on_popupTextCB_clicked()
538 {
539         enableCB();
540 }
541
542
543 void PrefCompletion::enableCB()
544 {
545         cursorTextCB->setEnabled(
546                 popupTextCB->isChecked() || inlineTextCB->isChecked());
547 }
548
549
550 void PrefCompletion::apply(LyXRC & rc) const
551 {
552         rc.completion_inline_delay = inlineDelaySB->value();
553         rc.completion_inline_math = inlineMathCB->isChecked();
554         rc.completion_inline_text = inlineTextCB->isChecked();
555         rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
556         rc.completion_popup_delay = popupDelaySB->value();
557         rc.completion_popup_math = popupMathCB->isChecked();
558         rc.autocorrection_math = autocorrectionCB->isChecked();
559         rc.completion_popup_text = popupTextCB->isChecked();
560         rc.completion_cursor_text = cursorTextCB->isChecked();
561         rc.completion_popup_after_complete =
562                 popupAfterCompleteCB->isChecked();
563 }
564
565
566 void PrefCompletion::update(LyXRC const & rc)
567 {
568         inlineDelaySB->setValue(rc.completion_inline_delay);
569         inlineMathCB->setChecked(rc.completion_inline_math);
570         inlineTextCB->setChecked(rc.completion_inline_text);
571         inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
572         popupDelaySB->setValue(rc.completion_popup_delay);
573         popupMathCB->setChecked(rc.completion_popup_math);
574         autocorrectionCB->setChecked(rc.autocorrection_math);
575         popupTextCB->setChecked(rc.completion_popup_text);
576         cursorTextCB->setChecked(rc.completion_cursor_text);
577         popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
578         enableCB();
579 }
580
581
582
583 /////////////////////////////////////////////////////////////////////
584 //
585 // PrefLatex
586 //
587 /////////////////////////////////////////////////////////////////////
588
589 PrefLatex::PrefLatex(GuiPreferences * form)
590         : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
591 {
592         setupUi(this);
593         connect(latexEncodingCB, SIGNAL(clicked()),
594                 this, SIGNAL(changed()));
595         connect(latexEncodingED, SIGNAL(textChanged(QString)),
596                 this, SIGNAL(changed()));
597         connect(latexChecktexED, SIGNAL(textChanged(QString)),
598                 this, SIGNAL(changed()));
599         connect(latexBibtexCO, SIGNAL(activated(int)),
600                 this, SIGNAL(changed()));
601         connect(latexBibtexED, SIGNAL(textChanged(QString)),
602                 this, SIGNAL(changed()));
603         connect(latexJBibtexED, SIGNAL(textChanged(QString)),
604                 this, SIGNAL(changed()));
605         connect(latexIndexCO, SIGNAL(activated(int)),
606                 this, SIGNAL(changed()));
607         connect(latexIndexED, SIGNAL(textChanged(QString)),
608                 this, SIGNAL(changed()));
609         connect(latexJIndexED, SIGNAL(textChanged(QString)),
610                 this, SIGNAL(changed()));
611         connect(latexAutoresetCB, SIGNAL(clicked()),
612                 this, SIGNAL(changed()));
613         connect(latexDviPaperED, SIGNAL(textChanged(QString)),
614                 this, SIGNAL(changed()));
615         connect(latexPaperSizeCO, SIGNAL(activated(int)),
616                 this, SIGNAL(changed()));
617
618 #if defined(__CYGWIN__) || defined(_WIN32)
619         pathCB->setVisible(true);
620         connect(pathCB, SIGNAL(clicked()),
621                 this, SIGNAL(changed()));
622 #else
623         pathCB->setVisible(false);
624 #endif
625 }
626
627
628 void PrefLatex::on_latexEncodingCB_stateChanged(int state)
629 {
630         latexEncodingED->setEnabled(state == Qt::Checked);
631 }
632
633
634 void PrefLatex::on_latexBibtexCO_activated(int n)
635 {
636         QString const bibtex = latexBibtexCO->itemData(n).toString();
637         if (bibtex.isEmpty()) {
638                 latexBibtexED->clear();
639                 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
640                 return;
641         }
642         for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
643              it != bibtex_alternatives.end(); ++it) {
644                 QString const bib = toqstr(*it);
645                 int ind = bib.indexOf(" ");
646                 QString sel_command = bib.left(ind);
647                 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
648                 if (bibtex == sel_command) {
649                         if (ind < 0)
650                                 latexBibtexED->clear();
651                         else
652                                 latexBibtexED->setText(sel_options.trimmed());
653                 }
654         }
655         latexBibtexOptionsLA->setText(qt_("&Options:"));
656 }
657
658
659 void PrefLatex::on_latexIndexCO_activated(int n)
660 {
661         QString const index = latexIndexCO->itemData(n).toString();
662         if (index.isEmpty()) {
663                 latexIndexED->clear();
664                 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
665                 return;
666         }
667         for (LyXRC::CommandSet::const_iterator it = index_alternatives.begin();
668              it != index_alternatives.end(); ++it) {
669                 QString const idx = toqstr(*it);
670                 int ind = idx.indexOf(" ");
671                 QString sel_command = idx.left(ind);
672                 QString sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
673                 if (index == sel_command) {
674                         if (ind < 0)
675                                 latexIndexED->clear();
676                         else
677                                 latexIndexED->setText(sel_options.trimmed());
678                 }
679         }
680         latexIndexOptionsLA->setText(qt_("Op&tions:"));
681 }
682
683
684 void PrefLatex::apply(LyXRC & rc) const
685 {
686         // If bibtex is not empty, bibopt contains the options, otherwise
687         // it is a customized bibtex command with options.
688         QString const bibtex = latexBibtexCO->itemData(
689                 latexBibtexCO->currentIndex()).toString();
690         QString const bibopt = latexBibtexED->text();
691         if (bibtex.isEmpty())
692                 rc.bibtex_command = fromqstr(bibopt);
693         else if (bibopt.isEmpty())
694                 rc.bibtex_command = fromqstr(bibtex);
695         else
696                 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
697
698         // If index is not empty, idxopt contains the options, otherwise
699         // it is a customized index command with options.
700         QString const index = latexIndexCO->itemData(
701                 latexIndexCO->currentIndex()).toString();
702         QString const idxopt = latexIndexED->text();
703         if (index.isEmpty())
704                 rc.index_command = fromqstr(idxopt);
705         else if (idxopt.isEmpty())
706                 rc.index_command = fromqstr(index);
707         else
708                 rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
709
710         if (latexEncodingCB->isChecked())
711                 rc.fontenc = fromqstr(latexEncodingED->text());
712         else
713                 rc.fontenc = "default";
714         rc.chktex_command = fromqstr(latexChecktexED->text());
715         rc.jbibtex_command = fromqstr(latexJBibtexED->text());
716         rc.jindex_command = fromqstr(latexJIndexED->text());
717         rc.nomencl_command = fromqstr(latexNomenclED->text());
718         rc.auto_reset_options = latexAutoresetCB->isChecked();
719         rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
720         rc.default_papersize =
721                 form_->toPaperSize(latexPaperSizeCO->currentIndex());
722 #if defined(__CYGWIN__) || defined(_WIN32)
723         rc.windows_style_tex_paths = pathCB->isChecked();
724 #endif
725 }
726
727
728 void PrefLatex::update(LyXRC const & rc)
729 {
730         latexBibtexCO->clear();
731
732         latexBibtexCO->addItem(qt_("Custom"), QString());
733         for (LyXRC::CommandSet::const_iterator it = rc.bibtex_alternatives.begin();
734                              it != rc.bibtex_alternatives.end(); ++it) {
735                 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
736                 latexBibtexCO->addItem(command, command);
737         }
738
739         bibtex_alternatives = rc.bibtex_alternatives;
740
741         QString const bib = toqstr(rc.bibtex_command);
742         int ind = bib.indexOf(" ");
743         QString sel_command = bib.left(ind);
744         QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
745
746         int pos = latexBibtexCO->findData(sel_command);
747         if (pos != -1) {
748                 latexBibtexCO->setCurrentIndex(pos);
749                 latexBibtexED->setText(sel_options.trimmed());
750                 latexBibtexOptionsLA->setText(qt_("&Options:"));
751         } else {
752                 latexBibtexED->setText(toqstr(rc.bibtex_command));
753                 latexBibtexCO->setCurrentIndex(0);
754                 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
755         }
756
757         latexIndexCO->clear();
758
759         latexIndexCO->addItem(qt_("Custom"), QString());
760         for (LyXRC::CommandSet::const_iterator it = rc.index_alternatives.begin();
761                              it != rc.index_alternatives.end(); ++it) {
762                 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
763                 latexIndexCO->addItem(command, command);
764         }
765
766         index_alternatives = rc.index_alternatives;
767
768         QString const idx = toqstr(rc.index_command);
769         ind = idx.indexOf(" ");
770         sel_command = idx.left(ind);
771         sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
772
773         pos = latexIndexCO->findData(sel_command);
774         if (pos != -1) {
775                 latexIndexCO->setCurrentIndex(pos);
776                 latexIndexED->setText(sel_options.trimmed());
777                 latexIndexOptionsLA->setText(qt_("Op&tions:"));
778         } else {
779                 latexIndexED->setText(toqstr(rc.index_command));
780                 latexIndexCO->setCurrentIndex(0);
781                 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
782         }
783
784         if (rc.fontenc == "default") {
785                 latexEncodingCB->setChecked(false);
786                 latexEncodingED->setEnabled(false);
787         } else {
788                 latexEncodingCB->setChecked(true);
789                 latexEncodingED->setEnabled(true);
790                 latexEncodingED->setText(toqstr(rc.fontenc));
791         }
792         latexChecktexED->setText(toqstr(rc.chktex_command));
793         latexJBibtexED->setText(toqstr(rc.jbibtex_command));
794         latexJIndexED->setText(toqstr(rc.jindex_command));
795         latexNomenclED->setText(toqstr(rc.nomencl_command));
796         latexAutoresetCB->setChecked(rc.auto_reset_options);
797         latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
798         latexPaperSizeCO->setCurrentIndex(
799                 form_->fromPaperSize(rc.default_papersize));
800 #if defined(__CYGWIN__) || defined(_WIN32)
801         pathCB->setChecked(rc.windows_style_tex_paths);
802 #endif
803 }
804
805
806 /////////////////////////////////////////////////////////////////////
807 //
808 // PrefScreenFonts
809 //
810 /////////////////////////////////////////////////////////////////////
811
812 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
813         : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
814 {
815         setupUi(this);
816
817         connect(screenRomanCO, SIGNAL(activated(QString)),
818                 this, SLOT(selectRoman(QString)));
819         connect(screenSansCO, SIGNAL(activated(QString)),
820                 this, SLOT(selectSans(QString)));
821         connect(screenTypewriterCO, SIGNAL(activated(QString)),
822                 this, SLOT(selectTypewriter(QString)));
823
824         QFontDatabase fontdb;
825         QStringList families(fontdb.families());
826         for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
827                 screenRomanCO->addItem(*it);
828                 screenSansCO->addItem(*it);
829                 screenTypewriterCO->addItem(*it);
830         }
831         connect(screenRomanCO, SIGNAL(activated(QString)),
832                 this, SIGNAL(changed()));
833         connect(screenSansCO, SIGNAL(activated(QString)),
834                 this, SIGNAL(changed()));
835         connect(screenTypewriterCO, SIGNAL(activated(QString)),
836                 this, SIGNAL(changed()));
837         connect(screenZoomSB, SIGNAL(valueChanged(int)),
838                 this, SIGNAL(changed()));
839         connect(screenDpiSB, SIGNAL(valueChanged(int)),
840                 this, SIGNAL(changed()));
841         connect(screenTinyED, SIGNAL(textChanged(QString)),
842                 this, SIGNAL(changed()));
843         connect(screenSmallestED, SIGNAL(textChanged(QString)),
844                 this, SIGNAL(changed()));
845         connect(screenSmallerED, SIGNAL(textChanged(QString)),
846                 this, SIGNAL(changed()));
847         connect(screenSmallED, SIGNAL(textChanged(QString)),
848                 this, SIGNAL(changed()));
849         connect(screenNormalED, SIGNAL(textChanged(QString)),
850                 this, SIGNAL(changed()));
851         connect(screenLargeED, SIGNAL(textChanged(QString)),
852                 this, SIGNAL(changed()));
853         connect(screenLargerED, SIGNAL(textChanged(QString)),
854                 this, SIGNAL(changed()));
855         connect(screenLargestED, SIGNAL(textChanged(QString)),
856                 this, SIGNAL(changed()));
857         connect(screenHugeED, SIGNAL(textChanged(QString)),
858                 this, SIGNAL(changed()));
859         connect(screenHugerED, SIGNAL(textChanged(QString)),
860                 this, SIGNAL(changed()));
861         connect(pixmapCacheCB, SIGNAL(toggled(bool)),
862                 this, SIGNAL(changed()));
863
864         screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
865         screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
866         screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
867         screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
868         screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
869         screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
870         screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
871         screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
872         screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
873         screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
874 }
875
876
877 void PrefScreenFonts::apply(LyXRC & rc) const
878 {
879         LyXRC const oldrc = rc;
880
881         parseFontName(screenRomanCO->currentText(),
882                 rc.roman_font_name, rc.roman_font_foundry);
883         parseFontName(screenSansCO->currentText(),
884                 rc.sans_font_name, rc.sans_font_foundry);
885         parseFontName(screenTypewriterCO->currentText(),
886                 rc.typewriter_font_name, rc.typewriter_font_foundry);
887
888         rc.zoom = screenZoomSB->value();
889         rc.dpi = screenDpiSB->value();
890         rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
891         rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
892         rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
893         rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
894         rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
895         rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
896         rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
897         rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
898         rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
899         rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
900         rc.use_pixmap_cache = pixmapCacheCB->isChecked();
901
902         if (rc.font_sizes != oldrc.font_sizes
903                 || rc.roman_font_name != oldrc.roman_font_name
904                 || rc.sans_font_name != oldrc.sans_font_name
905                 || rc.typewriter_font_name != oldrc.typewriter_font_name
906                 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
907                 // The global QPixmapCache is used in GuiPainter to cache text
908                 // painting so we must reset it in case any of the above
909                 // parameter is changed.
910                 QPixmapCache::clear();
911                 guiApp->fontLoader().update();
912                 form_->updateScreenFonts();
913         }
914 }
915
916
917 void PrefScreenFonts::update(LyXRC const & rc)
918 {
919         setComboxFont(screenRomanCO, rc.roman_font_name,
920                         rc.roman_font_foundry);
921         setComboxFont(screenSansCO, rc.sans_font_name,
922                         rc.sans_font_foundry);
923         setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
924                         rc.typewriter_font_foundry);
925
926         selectRoman(screenRomanCO->currentText());
927         selectSans(screenSansCO->currentText());
928         selectTypewriter(screenTypewriterCO->currentText());
929
930         screenZoomSB->setValue(rc.zoom);
931         screenDpiSB->setValue(rc.dpi);
932         doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
933         doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
934         doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
935         doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
936         doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
937         doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
938         doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
939         doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
940         doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
941         doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
942
943         pixmapCacheCB->setChecked(rc.use_pixmap_cache);
944 #if defined(Q_WS_X11)
945         pixmapCacheCB->setEnabled(false);
946 #endif
947
948 }
949
950
951 void PrefScreenFonts::selectRoman(const QString & name)
952 {
953         screenRomanFE->set(QFont(name), name);
954 }
955
956
957 void PrefScreenFonts::selectSans(const QString & name)
958 {
959         screenSansFE->set(QFont(name), name);
960 }
961
962
963 void PrefScreenFonts::selectTypewriter(const QString & name)
964 {
965         screenTypewriterFE->set(QFont(name), name);
966 }
967
968
969 /////////////////////////////////////////////////////////////////////
970 //
971 // PrefColors
972 //
973 /////////////////////////////////////////////////////////////////////
974
975 namespace {
976
977 struct ColorSorter
978 {
979         bool operator()(ColorCode lhs, ColorCode rhs) const {
980                 return 
981                         compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
982         }
983 };
984
985 } // namespace anon
986
987 PrefColors::PrefColors(GuiPreferences * form)
988         : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
989 {
990         setupUi(this);
991
992         // FIXME: all of this initialization should be put into the controller.
993         // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
994         // for some discussion of why that is not trivial.
995         QPixmap icon(32, 32);
996         for (int i = 0; i < Color_ignore; ++i) {
997                 ColorCode lc = static_cast<ColorCode>(i);
998                 if (lc == Color_none
999                         || lc == Color_black
1000                         || lc == Color_white
1001                         || lc == Color_red
1002                         || lc == Color_green
1003                         || lc == Color_blue
1004                         || lc == Color_cyan
1005                         || lc == Color_magenta
1006                         || lc == Color_yellow
1007                         || lc == Color_inherit
1008                         || lc == Color_ignore) continue;
1009
1010                 lcolors_.push_back(lc);
1011         }
1012         sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
1013         vector<ColorCode>::const_iterator cit = lcolors_.begin();
1014         vector<ColorCode>::const_iterator const end = lcolors_.end();
1015         for (; cit != end; ++cit) {
1016                         (void) new QListWidgetItem(QIcon(icon),
1017                         toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
1018         }
1019         curcolors_.resize(lcolors_.size());
1020         newcolors_.resize(lcolors_.size());
1021         // End initialization
1022
1023         connect(colorChangePB, SIGNAL(clicked()),
1024                 this, SLOT(changeColor()));
1025         connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
1026                 this, SLOT(changeLyxObjectsSelection()));
1027         connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
1028                 this, SLOT(changeColor()));
1029 }
1030
1031
1032 void PrefColors::apply(LyXRC & /*rc*/) const
1033 {
1034         for (unsigned int i = 0; i < lcolors_.size(); ++i)
1035                 if (curcolors_[i] != newcolors_[i])
1036                         form_->setColor(lcolors_[i], newcolors_[i]);
1037 }
1038
1039
1040 void PrefColors::update(LyXRC const & /*rc*/)
1041 {
1042         for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1043                 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
1044                 QPixmap coloritem(32, 32);
1045                 coloritem.fill(color);
1046                 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1047                 newcolors_[i] = curcolors_[i] = color.name();
1048         }
1049         changeLyxObjectsSelection();
1050 }
1051
1052
1053 void PrefColors::changeColor()
1054 {
1055         int const row = lyxObjectsLW->currentRow();
1056
1057         // just to be sure
1058         if (row < 0)
1059                 return;
1060
1061         QString const color = newcolors_[row];
1062         QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1063
1064         if (c.isValid() && c.name() != color) {
1065                 newcolors_[row] = c.name();
1066                 QPixmap coloritem(32, 32);
1067                 coloritem.fill(c);
1068                 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1069                 // emit signal
1070                 changed();
1071         }
1072 }
1073
1074 void PrefColors::changeLyxObjectsSelection()
1075 {
1076         colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1077 }
1078
1079
1080 /////////////////////////////////////////////////////////////////////
1081 //
1082 // PrefDisplay
1083 //
1084 /////////////////////////////////////////////////////////////////////
1085
1086 PrefDisplay::PrefDisplay(GuiPreferences * form)
1087         : PrefModule(qt_(catLookAndFeel), qt_("Display"), form)
1088 {
1089         setupUi(this);
1090         connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1091         connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1092         connect(previewSizeSB, SIGNAL(valueChanged(double)), this, SIGNAL(changed()));
1093         connect(paragraphMarkerCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1094         if (instantPreviewCO->currentIndex() == 0)
1095                 previewSizeSB->setEnabled(false);
1096         else
1097                 previewSizeSB->setEnabled(true);
1098 }
1099
1100
1101 void PrefDisplay::on_instantPreviewCO_currentIndexChanged(int index)
1102 {
1103         if (index == 0)
1104                 previewSizeSB->setEnabled(false);
1105         else
1106                 previewSizeSB->setEnabled(true);
1107 }
1108
1109
1110 void PrefDisplay::apply(LyXRC & rc) const
1111 {
1112         switch (instantPreviewCO->currentIndex()) {
1113                 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
1114                 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
1115                 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
1116         }
1117
1118         rc.display_graphics = displayGraphicsCB->isChecked();
1119         rc.preview_scale_factor = previewSizeSB->value();
1120         rc.paragraph_markers = paragraphMarkerCB->isChecked();
1121
1122         // FIXME!! The graphics cache no longer has a changeDisplay method.
1123 #if 0
1124         if (old_value != rc.display_graphics) {
1125                 graphics::GCache & gc = graphics::GCache::get();
1126                 gc.changeDisplay();
1127         }
1128 #endif
1129 }
1130
1131
1132 void PrefDisplay::update(LyXRC const & rc)
1133 {
1134         switch (rc.preview) {
1135         case LyXRC::PREVIEW_OFF:
1136                 instantPreviewCO->setCurrentIndex(0);
1137                 break;
1138         case LyXRC::PREVIEW_NO_MATH :
1139                 instantPreviewCO->setCurrentIndex(1);
1140                 break;
1141         case LyXRC::PREVIEW_ON :
1142                 instantPreviewCO->setCurrentIndex(2);
1143                 break;
1144         }
1145
1146         displayGraphicsCB->setChecked(rc.display_graphics);
1147         instantPreviewCO->setEnabled(rc.display_graphics);
1148         previewSizeSB->setValue(rc.preview_scale_factor);
1149         paragraphMarkerCB->setChecked(rc.paragraph_markers);
1150 }
1151
1152
1153 /////////////////////////////////////////////////////////////////////
1154 //
1155 // PrefPaths
1156 //
1157 /////////////////////////////////////////////////////////////////////
1158
1159 PrefPaths::PrefPaths(GuiPreferences * form)
1160         : PrefModule(QString(), qt_("Paths"), form)
1161 {
1162         setupUi(this);
1163
1164         connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1165         connect(workingDirED, SIGNAL(textChanged(QString)),
1166                 this, SIGNAL(changed()));
1167
1168         connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1169         connect(templateDirED, SIGNAL(textChanged(QString)),
1170                 this, SIGNAL(changed()));
1171
1172         connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1173         connect(exampleDirED, SIGNAL(textChanged(QString)),
1174                 this, SIGNAL(changed()));
1175
1176         connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1177         connect(backupDirED, SIGNAL(textChanged(QString)),
1178                 this, SIGNAL(changed()));
1179
1180         connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1181         connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1182                 this, SIGNAL(changed()));
1183
1184         connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1185         connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1186                 this, SIGNAL(changed()));
1187
1188         connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1189         connect(tempDirED, SIGNAL(textChanged(QString)),
1190                 this, SIGNAL(changed()));
1191
1192         connect(hunspellDirPB, SIGNAL(clicked()), this, SLOT(selectHunspelldir()));
1193         connect(hunspellDirED, SIGNAL(textChanged(QString)),
1194                 this, SIGNAL(changed()));
1195
1196         connect(pathPrefixED, SIGNAL(textChanged(QString)),
1197                 this, SIGNAL(changed()));
1198 }
1199
1200
1201 void PrefPaths::apply(LyXRC & rc) const
1202 {
1203         rc.document_path = internal_path(fromqstr(workingDirED->text()));
1204         rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1205         rc.template_path = internal_path(fromqstr(templateDirED->text()));
1206         rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1207         rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1208         rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1209         rc.hunspelldir_path = internal_path(fromqstr(hunspellDirED->text()));
1210         rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1211         // FIXME: should be a checkbox only
1212         rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1213 }
1214
1215
1216 void PrefPaths::update(LyXRC const & rc)
1217 {
1218         workingDirED->setText(toqstr(external_path(rc.document_path)));
1219         exampleDirED->setText(toqstr(external_path(rc.example_path)));
1220         templateDirED->setText(toqstr(external_path(rc.template_path)));
1221         backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1222         tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1223         thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1224         hunspellDirED->setText(toqstr(external_path(rc.hunspelldir_path)));
1225         pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1226         // FIXME: should be a checkbox only
1227         lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1228 }
1229
1230
1231 void PrefPaths::selectExampledir()
1232 {
1233         QString file = browseDir(internalPath(exampleDirED->text()),
1234                 qt_("Select directory for example files"));
1235         if (!file.isEmpty())
1236                 exampleDirED->setText(file);
1237 }
1238
1239
1240 void PrefPaths::selectTemplatedir()
1241 {
1242         QString file = browseDir(internalPath(templateDirED->text()),
1243                 qt_("Select a document templates directory"));
1244         if (!file.isEmpty())
1245                 templateDirED->setText(file);
1246 }
1247
1248
1249 void PrefPaths::selectTempdir()
1250 {
1251         QString file = browseDir(internalPath(tempDirED->text()),
1252                 qt_("Select a temporary directory"));
1253         if (!file.isEmpty())
1254                 tempDirED->setText(file);
1255 }
1256
1257
1258 void PrefPaths::selectBackupdir()
1259 {
1260         QString file = browseDir(internalPath(backupDirED->text()),
1261                 qt_("Select a backups directory"));
1262         if (!file.isEmpty())
1263                 backupDirED->setText(file);
1264 }
1265
1266
1267 void PrefPaths::selectWorkingdir()
1268 {
1269         QString file = browseDir(internalPath(workingDirED->text()),
1270                 qt_("Select a document directory"));
1271         if (!file.isEmpty())
1272                 workingDirED->setText(file);
1273 }
1274
1275
1276 void PrefPaths::selectThesaurusdir()
1277 {
1278         QString file = browseDir(internalPath(thesaurusDirED->text()),
1279                 qt_("Set the path to the thesaurus dictionaries"));
1280         if (!file.isEmpty())
1281                 thesaurusDirED->setText(file);
1282 }
1283
1284
1285 void PrefPaths::selectHunspelldir()
1286 {
1287         QString file = browseDir(internalPath(hunspellDirED->text()),
1288                 qt_("Set the path to the Hunspell dictionaries"));
1289         if (!file.isEmpty())
1290                 hunspellDirED->setText(file);
1291 }
1292
1293
1294 void PrefPaths::selectLyxPipe()
1295 {
1296         QString file = form_->browse(internalPath(lyxserverDirED->text()),
1297                 qt_("Give a filename for the LyX server pipe"));
1298         if (!file.isEmpty())
1299                 lyxserverDirED->setText(file);
1300 }
1301
1302
1303 /////////////////////////////////////////////////////////////////////
1304 //
1305 // PrefSpellchecker
1306 //
1307 /////////////////////////////////////////////////////////////////////
1308
1309 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1310         : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1311 {
1312         setupUi(this);
1313
1314 #if defined(USE_ASPELL)
1315         spellcheckerCB->addItem("aspell");
1316 #endif
1317 #if defined(USE_HUNSPELL)
1318         spellcheckerCB->addItem("hunspell");
1319 #endif
1320
1321         if (theSpellChecker()) {
1322                 connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
1323                         this, SIGNAL(changed()));
1324                 connect(altLanguageED, SIGNAL(textChanged(QString)),
1325                         this, SIGNAL(changed()));
1326                 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1327                         this, SIGNAL(changed()));
1328                 connect(compoundWordCB, SIGNAL(clicked()),
1329                         this, SIGNAL(changed()));
1330                 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1331                         this, SIGNAL(changed()));
1332         } else {
1333                 spellcheckerCB->setEnabled(false);
1334                 altLanguageED->setEnabled(false);
1335                 escapeCharactersED->setEnabled(false);
1336                 compoundWordCB->setEnabled(false);
1337                 spellcheckContinuouslyCB->setEnabled(false);
1338         }
1339 }
1340
1341
1342 void PrefSpellchecker::apply(LyXRC & rc) const
1343 {
1344         rc.spellchecker = fromqstr(spellcheckerCB->currentText());
1345         rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1346         rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1347         rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1348         rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1349 }
1350
1351
1352 void PrefSpellchecker::update(LyXRC const & rc)
1353 {
1354         spellcheckerCB->setCurrentIndex(spellcheckerCB->findText(
1355                 toqstr(rc.spellchecker)));
1356         altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1357         escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1358         compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1359         spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1360 }
1361
1362
1363
1364 /////////////////////////////////////////////////////////////////////
1365 //
1366 // PrefConverters
1367 //
1368 /////////////////////////////////////////////////////////////////////
1369
1370
1371 PrefConverters::PrefConverters(GuiPreferences * form)
1372         : PrefModule(qt_(catFiles), qt_("Converters"), form)
1373 {
1374         setupUi(this);
1375
1376         connect(converterNewPB, SIGNAL(clicked()),
1377                 this, SLOT(updateConverter()));
1378         connect(converterRemovePB, SIGNAL(clicked()),
1379                 this, SLOT(removeConverter()));
1380         connect(converterModifyPB, SIGNAL(clicked()),
1381                 this, SLOT(updateConverter()));
1382         connect(convertersLW, SIGNAL(currentRowChanged(int)),
1383                 this, SLOT(switchConverter()));
1384         connect(converterFromCO, SIGNAL(activated(QString)),
1385                 this, SLOT(changeConverter()));
1386         connect(converterToCO, SIGNAL(activated(QString)),
1387                 this, SLOT(changeConverter()));
1388         connect(converterED, SIGNAL(textEdited(QString)),
1389                 this, SLOT(changeConverter()));
1390         connect(converterFlagED, SIGNAL(textEdited(QString)),
1391                 this, SLOT(changeConverter()));
1392         connect(converterNewPB, SIGNAL(clicked()),
1393                 this, SIGNAL(changed()));
1394         connect(converterRemovePB, SIGNAL(clicked()),
1395                 this, SIGNAL(changed()));
1396         connect(converterModifyPB, SIGNAL(clicked()),
1397                 this, SIGNAL(changed()));
1398         connect(maxAgeLE, SIGNAL(textEdited(QString)),
1399                 this, SIGNAL(changed()));
1400
1401         maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1402         //converterDefGB->setFocusProxy(convertersLW);
1403 }
1404
1405
1406 void PrefConverters::apply(LyXRC & rc) const
1407 {
1408         rc.use_converter_cache = cacheCB->isChecked();
1409         rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
1410 }
1411
1412
1413 void PrefConverters::update(LyXRC const & rc)
1414 {
1415         cacheCB->setChecked(rc.use_converter_cache);
1416         QString max_age;
1417         doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
1418         updateGui();
1419 }
1420
1421
1422 void PrefConverters::updateGui()
1423 {
1424         form_->formats().sort();
1425         form_->converters().update(form_->formats());
1426         // save current selection
1427         QString current = converterFromCO->currentText()
1428                 + " -> " + converterToCO->currentText();
1429
1430         converterFromCO->clear();
1431         converterToCO->clear();
1432
1433         Formats::const_iterator cit = form_->formats().begin();
1434         Formats::const_iterator end = form_->formats().end();
1435         for (; cit != end; ++cit) {
1436                 converterFromCO->addItem(qt_(cit->prettyname()));
1437                 converterToCO->addItem(qt_(cit->prettyname()));
1438         }
1439
1440         // currentRowChanged(int) is also triggered when updating the listwidget
1441         // block signals to avoid unnecessary calls to switchConverter()
1442         convertersLW->blockSignals(true);
1443         convertersLW->clear();
1444
1445         Converters::const_iterator ccit = form_->converters().begin();
1446         Converters::const_iterator cend = form_->converters().end();
1447         for (; ccit != cend; ++ccit) {
1448                 QString const name =
1449                         qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1450                 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1451                 new QListWidgetItem(name, convertersLW, type);
1452         }
1453         convertersLW->sortItems(Qt::AscendingOrder);
1454         convertersLW->blockSignals(false);
1455
1456         // restore selection
1457         if (!current.isEmpty()) {
1458                 QList<QListWidgetItem *> const item =
1459                         convertersLW->findItems(current, Qt::MatchExactly);
1460                 if (!item.isEmpty())
1461                         convertersLW->setCurrentItem(item.at(0));
1462         }
1463
1464         // select first element if restoring failed
1465         if (convertersLW->currentRow() == -1)
1466                 convertersLW->setCurrentRow(0);
1467
1468         updateButtons();
1469 }
1470
1471
1472 void PrefConverters::switchConverter()
1473 {
1474         int const cnr = convertersLW->currentItem()->type();
1475         Converter const & c(form_->converters().get(cnr));
1476         converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1477         converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1478         converterED->setText(toqstr(c.command));
1479         converterFlagED->setText(toqstr(c.flags));
1480
1481         updateButtons();
1482 }
1483
1484
1485 void PrefConverters::changeConverter()
1486 {
1487         updateButtons();
1488 }
1489
1490
1491 void PrefConverters::updateButtons()
1492 {
1493         Format const & from = form_->formats().get(converterFromCO->currentIndex());
1494         Format const & to = form_->formats().get(converterToCO->currentIndex());
1495         int const sel = form_->converters().getNumber(from.name(), to.name());
1496         bool const known = sel >= 0;
1497         bool const valid = !(converterED->text().isEmpty()
1498                 || from.name() == to.name());
1499
1500         int const cnr = convertersLW->currentItem()->type();
1501         Converter const & c = form_->converters().get(cnr);
1502         string const old_command = c.command;
1503         string const old_flag = c.flags;
1504         string const new_command = fromqstr(converterED->text());
1505         string const new_flag = fromqstr(converterFlagED->text());
1506
1507         bool modified = (old_command != new_command || old_flag != new_flag);
1508
1509         converterModifyPB->setEnabled(valid && known && modified);
1510         converterNewPB->setEnabled(valid && !known);
1511         converterRemovePB->setEnabled(known);
1512
1513         maxAgeLE->setEnabled(cacheCB->isChecked());
1514         maxAgeLA->setEnabled(cacheCB->isChecked());
1515 }
1516
1517
1518 // FIXME: user must
1519 // specify unique from/to or it doesn't appear. This is really bad UI
1520 // this is why we can use the same function for both new and modify
1521 void PrefConverters::updateConverter()
1522 {
1523         Format const & from = form_->formats().get(converterFromCO->currentIndex());
1524         Format const & to = form_->formats().get(converterToCO->currentIndex());
1525         string const flags = fromqstr(converterFlagED->text());
1526         string const command = fromqstr(converterED->text());
1527
1528         Converter const * old =
1529                 form_->converters().getConverter(from.name(), to.name());
1530         form_->converters().add(from.name(), to.name(), command, flags);
1531
1532         if (!old)
1533                 form_->converters().updateLast(form_->formats());
1534
1535         updateGui();
1536
1537         // Remove all files created by this converter from the cache, since
1538         // the modified converter might create different files.
1539         ConverterCache::get().remove_all(from.name(), to.name());
1540 }
1541
1542
1543 void PrefConverters::removeConverter()
1544 {
1545         Format const & from = form_->formats().get(converterFromCO->currentIndex());
1546         Format const & to = form_->formats().get(converterToCO->currentIndex());
1547         form_->converters().erase(from.name(), to.name());
1548
1549         updateGui();
1550
1551         // Remove all files created by this converter from the cache, since
1552         // a possible new converter might create different files.
1553         ConverterCache::get().remove_all(from.name(), to.name());
1554 }
1555
1556
1557 void PrefConverters::on_cacheCB_stateChanged(int state)
1558 {
1559         maxAgeLE->setEnabled(state == Qt::Checked);
1560         maxAgeLA->setEnabled(state == Qt::Checked);
1561         changed();
1562 }
1563
1564
1565 /////////////////////////////////////////////////////////////////////
1566 //
1567 // FormatValidator
1568 //
1569 /////////////////////////////////////////////////////////////////////
1570
1571 class FormatValidator : public QValidator
1572 {
1573 public:
1574         FormatValidator(QWidget *, Formats const & f);
1575         void fixup(QString & input) const;
1576         QValidator::State validate(QString & input, int & pos) const;
1577 private:
1578         virtual QString toString(Format const & format) const = 0;
1579         int nr() const;
1580         Formats const & formats_;
1581 };
1582
1583
1584 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1585         : QValidator(parent), formats_(f)
1586 {
1587 }
1588
1589
1590 void FormatValidator::fixup(QString & input) const
1591 {
1592         Formats::const_iterator cit = formats_.begin();
1593         Formats::const_iterator end = formats_.end();
1594         for (; cit != end; ++cit) {
1595                 QString const name = toString(*cit);
1596                 if (distance(formats_.begin(), cit) == nr()) {
1597                         input = name;
1598                         return;
1599                 }
1600         }
1601 }
1602
1603
1604 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1605 {
1606         Formats::const_iterator cit = formats_.begin();
1607         Formats::const_iterator end = formats_.end();
1608         bool unknown = true;
1609         for (; unknown && cit != end; ++cit) {
1610                 QString const name = toString(*cit);
1611                 if (distance(formats_.begin(), cit) != nr())
1612                         unknown = name != input;
1613         }
1614
1615         if (unknown && !input.isEmpty())
1616                 return QValidator::Acceptable;
1617         else
1618                 return QValidator::Intermediate;
1619 }
1620
1621
1622 int FormatValidator::nr() const
1623 {
1624         QComboBox * p = qobject_cast<QComboBox *>(parent());
1625         return p->itemData(p->currentIndex()).toInt();
1626 }
1627
1628
1629 /////////////////////////////////////////////////////////////////////
1630 //
1631 // FormatNameValidator
1632 //
1633 /////////////////////////////////////////////////////////////////////
1634
1635 class FormatNameValidator : public FormatValidator
1636 {
1637 public:
1638         FormatNameValidator(QWidget * parent, Formats const & f)
1639                 : FormatValidator(parent, f)
1640         {}
1641 private:
1642         QString toString(Format const & format) const
1643         {
1644                 return toqstr(format.name());
1645         }
1646 };
1647
1648
1649 /////////////////////////////////////////////////////////////////////
1650 //
1651 // FormatPrettynameValidator
1652 //
1653 /////////////////////////////////////////////////////////////////////
1654
1655 class FormatPrettynameValidator : public FormatValidator
1656 {
1657 public:
1658         FormatPrettynameValidator(QWidget * parent, Formats const & f)
1659                 : FormatValidator(parent, f)
1660         {}
1661 private:
1662         QString toString(Format const & format) const
1663         {
1664                 return qt_(format.prettyname());
1665         }
1666 };
1667
1668
1669 /////////////////////////////////////////////////////////////////////
1670 //
1671 // PrefFileformats
1672 //
1673 /////////////////////////////////////////////////////////////////////
1674
1675 PrefFileformats::PrefFileformats(GuiPreferences * form)
1676         : PrefModule(qt_(catFiles), qt_("File formats"), form)
1677 {
1678         setupUi(this);
1679         formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1680         formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1681
1682         connect(documentCB, SIGNAL(clicked()),
1683                 this, SLOT(setFlags()));
1684         connect(vectorCB, SIGNAL(clicked()),
1685                 this, SLOT(setFlags()));
1686         connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1687                 this, SLOT(updatePrettyname()));
1688         connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1689                 this, SIGNAL(changed()));
1690         connect(defaultFormatCB, SIGNAL(activated(QString)),
1691                 this, SIGNAL(changed()));
1692         connect(viewerCO, SIGNAL(activated(int)),
1693                 this, SIGNAL(changed()));
1694         connect(editorCO, SIGNAL(activated(int)),
1695                 this, SIGNAL(changed()));
1696 }
1697
1698
1699 namespace {
1700
1701 string const l10n_shortcut(string const prettyname, string const shortcut)
1702 {
1703         if (shortcut.empty())
1704                 return string();
1705
1706         string l10n_format =
1707                 to_utf8(_(prettyname + '|' + shortcut));
1708         return split(l10n_format, '|');
1709 }
1710
1711 }; // namespace anon
1712
1713
1714 void PrefFileformats::apply(LyXRC & rc) const
1715 {
1716         QString const default_format = defaultFormatCB->itemData(
1717                 defaultFormatCB->currentIndex()).toString();
1718         rc.default_view_format = fromqstr(default_format);
1719 }
1720
1721
1722 void PrefFileformats::update(LyXRC const & rc)
1723 {
1724         viewer_alternatives = rc.viewer_alternatives;
1725         editor_alternatives = rc.editor_alternatives;
1726         bool const init = defaultFormatCB->currentText().isEmpty();
1727         updateView();
1728         if (init) {
1729                 int const pos =
1730                         defaultFormatCB->findData(toqstr(rc.default_view_format));
1731                 defaultFormatCB->setCurrentIndex(pos);
1732         }
1733 }
1734
1735
1736 void PrefFileformats::updateView()
1737 {
1738         QString const current = formatsCB->currentText();
1739         QString const current_def = defaultFormatCB->currentText();
1740
1741         // update comboboxes with formats
1742         formatsCB->blockSignals(true);
1743         defaultFormatCB->blockSignals(true);
1744         formatsCB->clear();
1745         defaultFormatCB->clear();
1746         form_->formats().sort();
1747         Formats::const_iterator cit = form_->formats().begin();
1748         Formats::const_iterator end = form_->formats().end();
1749         for (; cit != end; ++cit) {
1750                 formatsCB->addItem(qt_(cit->prettyname()),
1751                                 QVariant(form_->formats().getNumber(cit->name())));
1752                 if (form_->converters().isReachable("latex", cit->name())
1753                     || form_->converters().isReachable("pdflatex", cit->name()))
1754                         defaultFormatCB->addItem(qt_(cit->prettyname()),
1755                                         QVariant(toqstr(cit->name())));
1756         }
1757
1758         // restore selection
1759         int item = formatsCB->findText(current, Qt::MatchExactly);
1760         formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1761         on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1762         item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1763         defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1764         formatsCB->blockSignals(false);
1765         defaultFormatCB->blockSignals(false);
1766 }
1767
1768
1769 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1770 {
1771         int const nr = formatsCB->itemData(i).toInt();
1772         Format const f = form_->formats().get(nr);
1773
1774         formatED->setText(toqstr(f.name()));
1775         copierED->setText(toqstr(form_->movers().command(f.name())));
1776         extensionED->setText(toqstr(f.extension()));
1777         shortcutED->setText(
1778                 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1779         documentCB->setChecked((f.documentFormat()));
1780         vectorCB->setChecked((f.vectorFormat()));
1781         updateViewers();
1782         updateEditors();
1783 }
1784
1785
1786 void PrefFileformats::setFlags()
1787 {
1788         int flags = Format::none;
1789         if (documentCB->isChecked())
1790                 flags |= Format::document;
1791         if (vectorCB->isChecked())
1792                 flags |= Format::vector;
1793         currentFormat().setFlags(flags);
1794         changed();
1795 }
1796
1797
1798 void PrefFileformats::on_copierED_textEdited(const QString & s)
1799 {
1800         string const fmt = fromqstr(formatED->text());
1801         form_->movers().set(fmt, fromqstr(s));
1802         changed();
1803 }
1804
1805
1806 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1807 {
1808         currentFormat().setExtension(fromqstr(s));
1809         changed();
1810 }
1811
1812 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1813 {
1814         currentFormat().setViewer(fromqstr(s));
1815         changed();
1816 }
1817
1818
1819 void PrefFileformats::on_editorED_textEdited(const QString & s)
1820 {
1821         currentFormat().setEditor(fromqstr(s));
1822         changed();
1823 }
1824
1825
1826 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1827 {
1828         string const new_shortcut = fromqstr(s);
1829         if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1830                                           currentFormat().shortcut()))
1831                 return;
1832         currentFormat().setShortcut(new_shortcut);
1833         changed();
1834 }
1835
1836
1837 void PrefFileformats::on_formatED_editingFinished()
1838 {
1839         string const newname = fromqstr(formatED->displayText());
1840         if (newname == currentFormat().name())
1841                 return;
1842
1843         currentFormat().setName(newname);
1844         changed();
1845 }
1846
1847
1848 void PrefFileformats::on_formatED_textChanged(const QString &)
1849 {
1850         QString t = formatED->text();
1851         int p = 0;
1852         bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1853         setValid(formatLA, valid);
1854 }
1855
1856
1857 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1858 {
1859         QString t = formatsCB->currentText();
1860         int p = 0;
1861         bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1862         setValid(formatsLA, valid);
1863 }
1864
1865
1866 void PrefFileformats::updatePrettyname()
1867 {
1868         QString const newname = formatsCB->currentText();
1869         if (newname == qt_(currentFormat().prettyname()))
1870                 return;
1871
1872         currentFormat().setPrettyname(fromqstr(newname));
1873         formatsChanged();
1874         updateView();
1875         changed();
1876 }
1877
1878
1879 namespace {
1880         void updateComboBox(LyXRC::Alternatives const & alts,
1881                             string const & fmt, QComboBox * combo)
1882         {
1883                 LyXRC::Alternatives::const_iterator it = 
1884                                 alts.find(fmt);
1885                 if (it != alts.end()) {
1886                         LyXRC::CommandSet const & cmds = it->second;
1887                         LyXRC::CommandSet::const_iterator sit = 
1888                                         cmds.begin();
1889                         LyXRC::CommandSet::const_iterator const sen = 
1890                                         cmds.end();
1891                         for (; sit != sen; ++sit) {
1892                                 QString const qcmd = toqstr(*sit);
1893                                 combo->addItem(qcmd, qcmd);
1894                         }
1895                 }
1896         }
1897 }
1898
1899
1900 void PrefFileformats::updateViewers()
1901 {
1902         Format const f = currentFormat();
1903         viewerCO->blockSignals(true);
1904         viewerCO->clear();
1905         viewerCO->addItem(qt_("None"), QString());
1906         updateComboBox(viewer_alternatives, f.name(), viewerCO);
1907         viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
1908         viewerCO->blockSignals(false);
1909
1910         int pos = viewerCO->findData(toqstr(f.viewer()));
1911         if (pos != -1) {
1912                 viewerED->clear();
1913                 viewerED->setEnabled(false);
1914                 viewerCO->setCurrentIndex(pos);
1915         } else {
1916                 viewerED->setEnabled(true);
1917                 viewerED->setText(toqstr(f.viewer()));
1918                 viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
1919         }
1920 }
1921
1922
1923 void PrefFileformats::updateEditors()
1924 {
1925         Format const f = currentFormat();
1926         editorCO->blockSignals(true);
1927         editorCO->clear();
1928         editorCO->addItem(qt_("None"), QString());
1929         updateComboBox(editor_alternatives, f.name(), editorCO);
1930         editorCO->addItem(qt_("Custom"), QString("custom editor"));
1931         editorCO->blockSignals(false);
1932
1933         int pos = editorCO->findData(toqstr(f.editor()));
1934         if (pos != -1) {
1935                 editorED->clear();
1936                 editorED->setEnabled(false);
1937                 editorCO->setCurrentIndex(pos);
1938         } else {
1939                 editorED->setEnabled(true);
1940                 editorED->setText(toqstr(f.editor()));
1941                 editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
1942         }
1943 }
1944
1945
1946 void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
1947 {
1948         bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
1949         viewerED->setEnabled(custom);
1950         if (!custom)
1951                 currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
1952 }
1953
1954
1955 void PrefFileformats::on_editorCO_currentIndexChanged(int i)
1956 {
1957         bool const custom = editorCO->itemData(i).toString() == "custom editor";
1958         editorED->setEnabled(custom);
1959         if (!custom)
1960                 currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
1961 }
1962
1963
1964 Format & PrefFileformats::currentFormat()
1965 {
1966         int const i = formatsCB->currentIndex();
1967         int const nr = formatsCB->itemData(i).toInt();
1968         return form_->formats().get(nr);
1969 }
1970
1971
1972 void PrefFileformats::on_formatNewPB_clicked()
1973 {
1974         form_->formats().add("", "", "", "", "", "", Format::none);
1975         updateView();
1976         formatsCB->setCurrentIndex(0);
1977         formatsCB->setFocus(Qt::OtherFocusReason);
1978 }
1979
1980
1981 void PrefFileformats::on_formatRemovePB_clicked()
1982 {
1983         int const i = formatsCB->currentIndex();
1984         int const nr = formatsCB->itemData(i).toInt();
1985         string const current_text = form_->formats().get(nr).name();
1986         if (form_->converters().formatIsUsed(current_text)) {
1987                 Alert::error(_("Format in use"),
1988                              _("Cannot remove a Format used by a Converter. "
1989                                             "Remove the converter first."));
1990                 return;
1991         }
1992
1993         form_->formats().erase(current_text);
1994         formatsChanged();
1995         updateView();
1996         on_formatsCB_editTextChanged(formatsCB->currentText());
1997         changed();
1998 }
1999
2000
2001 /////////////////////////////////////////////////////////////////////
2002 //
2003 // PrefLanguage
2004 //
2005 /////////////////////////////////////////////////////////////////////
2006
2007 PrefLanguage::PrefLanguage(GuiPreferences * form)
2008         : PrefModule(qt_(catLanguage), qt_("Language"), form)
2009 {
2010         setupUi(this);
2011
2012         connect(rtlGB, SIGNAL(clicked()),
2013                 this, SIGNAL(changed()));
2014         connect(visualCursorRB, SIGNAL(clicked()),
2015                 this, SIGNAL(changed()));
2016         connect(logicalCursorRB, SIGNAL(clicked()),
2017                 this, SIGNAL(changed()));
2018         connect(markForeignCB, SIGNAL(clicked()),
2019                 this, SIGNAL(changed()));
2020         connect(autoBeginCB, SIGNAL(clicked()),
2021                 this, SIGNAL(changed()));
2022         connect(autoEndCB, SIGNAL(clicked()),
2023                 this, SIGNAL(changed()));
2024         connect(useBabelCB, SIGNAL(clicked()),
2025                 this, SIGNAL(changed()));
2026         connect(globalCB, SIGNAL(clicked()),
2027                 this, SIGNAL(changed()));
2028         connect(languagePackageED, SIGNAL(textChanged(QString)),
2029                 this, SIGNAL(changed()));
2030         connect(startCommandED, SIGNAL(textChanged(QString)),
2031                 this, SIGNAL(changed()));
2032         connect(endCommandED, SIGNAL(textChanged(QString)),
2033                 this, SIGNAL(changed()));
2034         connect(uiLanguageCO, SIGNAL(activated(int)),
2035                 this, SIGNAL(changed()));
2036
2037         uiLanguageCO->clear();
2038
2039         QAbstractItemModel * language_model = guiApp->languageModel();
2040         // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
2041         language_model->sort(0);
2042
2043         // FIXME: This is wrong, we need filter this list based on the available
2044         // translation.
2045         uiLanguageCO->blockSignals(true);
2046         uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
2047         for (int i = 0; i != language_model->rowCount(); ++i) {
2048                 QModelIndex index = language_model->index(i, 0);
2049                 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
2050                         index.data(Qt::UserRole).toString());
2051         }
2052         uiLanguageCO->blockSignals(false);
2053 }
2054
2055
2056 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
2057 {
2058          QMessageBox::information(this, qt_("LyX needs to be restarted!"),
2059                  qt_("The change of user interface language will be fully "
2060                  "effective only after a restart."));
2061 }
2062
2063
2064 void PrefLanguage::apply(LyXRC & rc) const
2065 {
2066         // FIXME: remove rtl_support bool
2067         rc.rtl_support = rtlGB->isChecked();
2068         rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
2069         rc.mark_foreign_language = markForeignCB->isChecked();
2070         rc.language_auto_begin = autoBeginCB->isChecked();
2071         rc.language_auto_end = autoEndCB->isChecked();
2072         rc.language_use_babel = useBabelCB->isChecked();
2073         rc.language_global_options = globalCB->isChecked();
2074         rc.language_package = fromqstr(languagePackageED->text());
2075         rc.language_command_begin = fromqstr(startCommandED->text());
2076         rc.language_command_end = fromqstr(endCommandED->text());
2077         rc.gui_language = fromqstr(
2078                 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
2079 }
2080
2081
2082 void PrefLanguage::update(LyXRC const & rc)
2083 {
2084         // FIXME: remove rtl_support bool
2085         rtlGB->setChecked(rc.rtl_support);
2086         if (rc.visual_cursor)
2087                 visualCursorRB->setChecked(true);
2088         else
2089                 logicalCursorRB->setChecked(true);
2090         markForeignCB->setChecked(rc.mark_foreign_language);
2091         autoBeginCB->setChecked(rc.language_auto_begin);
2092         autoEndCB->setChecked(rc.language_auto_end);
2093         useBabelCB->setChecked(rc.language_use_babel);
2094         globalCB->setChecked(rc.language_global_options);
2095         languagePackageED->setText(toqstr(rc.language_package));
2096         startCommandED->setText(toqstr(rc.language_command_begin));
2097         endCommandED->setText(toqstr(rc.language_command_end));
2098
2099         int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
2100         uiLanguageCO->blockSignals(true);
2101         uiLanguageCO->setCurrentIndex(pos);
2102         uiLanguageCO->blockSignals(false);
2103 }
2104
2105
2106 /////////////////////////////////////////////////////////////////////
2107 //
2108 // PrefPrinter
2109 //
2110 /////////////////////////////////////////////////////////////////////
2111
2112 PrefPrinter::PrefPrinter(GuiPreferences * form)
2113         : PrefModule(qt_(catOutput), qt_("Printer"), form)
2114 {
2115         setupUi(this);
2116
2117         connect(printerAdaptCB, SIGNAL(clicked()),
2118                 this, SIGNAL(changed()));
2119         connect(printerCommandED, SIGNAL(textChanged(QString)),
2120                 this, SIGNAL(changed()));
2121         connect(printerNameED, SIGNAL(textChanged(QString)),
2122                 this, SIGNAL(changed()));
2123         connect(printerPageRangeED, SIGNAL(textChanged(QString)),
2124                 this, SIGNAL(changed()));
2125         connect(printerCopiesED, SIGNAL(textChanged(QString)),
2126                 this, SIGNAL(changed()));
2127         connect(printerReverseED, SIGNAL(textChanged(QString)),
2128                 this, SIGNAL(changed()));
2129         connect(printerToPrinterED, SIGNAL(textChanged(QString)),
2130                 this, SIGNAL(changed()));
2131         connect(printerExtensionED, SIGNAL(textChanged(QString)),
2132                 this, SIGNAL(changed()));
2133         connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
2134                 this, SIGNAL(changed()));
2135         connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
2136                 this, SIGNAL(changed()));
2137         connect(printerEvenED, SIGNAL(textChanged(QString)),
2138                 this, SIGNAL(changed()));
2139         connect(printerOddED, SIGNAL(textChanged(QString)),
2140                 this, SIGNAL(changed()));
2141         connect(printerCollatedED, SIGNAL(textChanged(QString)),
2142                 this, SIGNAL(changed()));
2143         connect(printerLandscapeED, SIGNAL(textChanged(QString)),
2144                 this, SIGNAL(changed()));
2145         connect(printerToFileED, SIGNAL(textChanged(QString)),
2146                 this, SIGNAL(changed()));
2147         connect(printerExtraED, SIGNAL(textChanged(QString)),
2148                 this, SIGNAL(changed()));
2149         connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2150                 this, SIGNAL(changed()));
2151         connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2152                 this, SIGNAL(changed()));
2153 }
2154
2155
2156 void PrefPrinter::apply(LyXRC & rc) const
2157 {
2158         rc.print_adapt_output = printerAdaptCB->isChecked();
2159         rc.print_command = fromqstr(printerCommandED->text());
2160         rc.printer = fromqstr(printerNameED->text());
2161
2162         rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2163         rc.print_copies_flag = fromqstr(printerCopiesED->text());
2164         rc.print_reverse_flag = fromqstr(printerReverseED->text());
2165         rc.print_to_printer = fromqstr(printerToPrinterED->text());
2166         rc.print_file_extension = fromqstr(printerExtensionED->text());
2167         rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2168         rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2169         rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2170         rc.print_oddpage_flag = fromqstr(printerOddED->text());
2171         rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2172         rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2173         rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2174         rc.print_extra_options = fromqstr(printerExtraED->text());
2175         rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2176         rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2177 }
2178
2179
2180 void PrefPrinter::update(LyXRC const & rc)
2181 {
2182         printerAdaptCB->setChecked(rc.print_adapt_output);
2183         printerCommandED->setText(toqstr(rc.print_command));
2184         printerNameED->setText(toqstr(rc.printer));
2185
2186         printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2187         printerCopiesED->setText(toqstr(rc.print_copies_flag));
2188         printerReverseED->setText(toqstr(rc.print_reverse_flag));
2189         printerToPrinterED->setText(toqstr(rc.print_to_printer));
2190         printerExtensionED->setText(toqstr(rc.print_file_extension));
2191         printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2192         printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2193         printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2194         printerOddED->setText(toqstr(rc.print_oddpage_flag));
2195         printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2196         printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2197         printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2198         printerExtraED->setText(toqstr(rc.print_extra_options));
2199         printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2200         printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2201 }
2202
2203
2204 /////////////////////////////////////////////////////////////////////
2205 //
2206 // PrefUserInterface
2207 //
2208 /////////////////////////////////////////////////////////////////////
2209
2210 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2211         : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
2212 {
2213         setupUi(this);
2214
2215         connect(autoSaveCB, SIGNAL(toggled(bool)),
2216                 autoSaveSB, SLOT(setEnabled(bool)));
2217         connect(autoSaveCB, SIGNAL(toggled(bool)),
2218                 TextLabel1, SLOT(setEnabled(bool)));
2219         connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2220                 this, SIGNAL(changed()));
2221 #if QT_VERSION < 0x040500
2222         singleCloseTabButtonCB->setEnabled(false);
2223 #endif
2224         connect(singleCloseTabButtonCB, SIGNAL(clicked()),
2225                 this, SIGNAL(changed()));
2226         connect(uiFilePB, SIGNAL(clicked()),
2227                 this, SLOT(selectUi()));
2228         connect(uiFileED, SIGNAL(textChanged(QString)),
2229                 this, SIGNAL(changed()));
2230         connect(restoreCursorCB, SIGNAL(clicked()),
2231                 this, SIGNAL(changed()));
2232         connect(loadSessionCB, SIGNAL(clicked()),
2233                 this, SIGNAL(changed()));
2234         connect(allowGeometrySessionCB, SIGNAL(clicked()),
2235                 this, SIGNAL(changed()));
2236         connect(autoSaveSB, SIGNAL(valueChanged(int)),
2237                 this, SIGNAL(changed()));
2238         connect(autoSaveCB, SIGNAL(clicked()),
2239                 this, SIGNAL(changed()));
2240         connect(backupCB, SIGNAL(clicked()),
2241                 this, SIGNAL(changed()));
2242         connect(lastfilesSB, SIGNAL(valueChanged(int)),
2243                 this, SIGNAL(changed()));
2244         connect(tooltipCB, SIGNAL(toggled(bool)),
2245                 this, SIGNAL(changed()));
2246         lastfilesSB->setMaximum(maxlastfiles);
2247 }
2248
2249
2250 void PrefUserInterface::apply(LyXRC & rc) const
2251 {
2252         rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2253         rc.use_lastfilepos = restoreCursorCB->isChecked();
2254         rc.load_session = loadSessionCB->isChecked();
2255         rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2256         rc.autosave = autoSaveCB->isChecked()?  autoSaveSB->value() * 60 : 0;
2257         rc.make_backup = backupCB->isChecked();
2258         rc.num_lastfiles = lastfilesSB->value();
2259         rc.use_tooltip = tooltipCB->isChecked();
2260         rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2261         rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
2262 #if QT_VERSION < 0x040500
2263         rc.single_close_tab_button = true;
2264 #endif
2265 }
2266
2267
2268 void PrefUserInterface::update(LyXRC const & rc)
2269 {
2270         uiFileED->setText(toqstr(external_path(rc.ui_file)));
2271         restoreCursorCB->setChecked(rc.use_lastfilepos);
2272         loadSessionCB->setChecked(rc.load_session);
2273         allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2274         // convert to minutes
2275         bool autosave = rc.autosave > 0;
2276         int mins = rc.autosave / 60;
2277         if (!mins)
2278                 mins = 5;
2279         autoSaveSB->setValue(mins);
2280         autoSaveCB->setChecked(autosave);
2281         autoSaveSB->setEnabled(autosave);
2282         backupCB->setChecked(rc.make_backup);
2283         lastfilesSB->setValue(rc.num_lastfiles);
2284         tooltipCB->setChecked(rc.use_tooltip);
2285         openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2286         singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
2287 }
2288
2289
2290 void PrefUserInterface::selectUi()
2291 {
2292         QString file = form_->browseUI(internalPath(uiFileED->text()));
2293         if (!file.isEmpty())
2294                 uiFileED->setText(file);
2295 }
2296
2297
2298 void PrefUserInterface::on_clearSessionPB_clicked()
2299 {
2300         guiApp->clearSession();
2301 }
2302
2303
2304
2305 /////////////////////////////////////////////////////////////////////
2306 //
2307 // PrefEdit
2308 //
2309 /////////////////////////////////////////////////////////////////////
2310
2311 PrefEdit::PrefEdit(GuiPreferences * form)
2312         : PrefModule(qt_(catEditing), qt_("Control"), form)
2313 {
2314         setupUi(this);
2315
2316         connect(cursorFollowsCB, SIGNAL(clicked()),
2317                 this, SIGNAL(changed()));
2318         connect(scrollBelowCB, SIGNAL(clicked()),
2319                 this, SIGNAL(changed()));
2320         connect(sortEnvironmentsCB, SIGNAL(clicked()),
2321                 this, SIGNAL(changed()));
2322         connect(groupEnvironmentsCB, SIGNAL(clicked()),
2323                 this, SIGNAL(changed()));
2324         connect(macroEditStyleCO, SIGNAL(activated(int)),
2325                 this, SIGNAL(changed()));
2326         connect(fullscreenLimitGB, SIGNAL(clicked()),
2327                 this, SIGNAL(changed()));
2328         connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2329                 this, SIGNAL(changed()));
2330         connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2331                 this, SIGNAL(changed()));
2332         connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2333                 this, SIGNAL(changed()));
2334         connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2335                 this, SIGNAL(changed()));
2336         connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2337                 this, SIGNAL(changed()));
2338 }
2339
2340
2341 void PrefEdit::apply(LyXRC & rc) const
2342 {
2343         rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2344         rc.scroll_below_document = scrollBelowCB->isChecked();
2345         rc.sort_layouts = sortEnvironmentsCB->isChecked();
2346         rc.group_layouts = groupEnvironmentsCB->isChecked();
2347         switch (macroEditStyleCO->currentIndex()) {
2348                 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2349                 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2350                 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST;   break;
2351         }
2352         rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2353         rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2354         rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2355         rc.full_screen_menubar = toggleMenubarCB->isChecked();
2356         rc.full_screen_width = fullscreenWidthSB->value();
2357         rc.full_screen_limit = fullscreenLimitGB->isChecked();
2358 }
2359
2360
2361 void PrefEdit::update(LyXRC const & rc)
2362 {
2363         cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2364         scrollBelowCB->setChecked(rc.scroll_below_document);
2365         sortEnvironmentsCB->setChecked(rc.sort_layouts);
2366         groupEnvironmentsCB->setChecked(rc.group_layouts);
2367         macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2368         toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2369         toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2370         toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2371         toggleMenubarCB->setChecked(rc.full_screen_menubar);
2372         fullscreenWidthSB->setValue(rc.full_screen_width);
2373         fullscreenLimitGB->setChecked(rc.full_screen_limit);
2374 }
2375
2376
2377 /////////////////////////////////////////////////////////////////////
2378 //
2379 // PrefShortcuts
2380 //
2381 /////////////////////////////////////////////////////////////////////
2382
2383
2384 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2385 {
2386         Ui::shortcutUi::setupUi(this);
2387         QDialog::setModal(true);
2388 }
2389
2390
2391 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2392         : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2393 {
2394         setupUi(this);
2395
2396         shortcutsTW->setColumnCount(2);
2397         shortcutsTW->headerItem()->setText(0, qt_("Function"));
2398         shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2399         shortcutsTW->setSortingEnabled(true);
2400         // Multi-selection can be annoying.
2401         // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2402
2403         connect(bindFilePB, SIGNAL(clicked()),
2404                 this, SLOT(selectBind()));
2405         connect(bindFileED, SIGNAL(textChanged(QString)),
2406                 this, SIGNAL(changed()));
2407         connect(removePB, SIGNAL(clicked()),
2408                 this, SIGNAL(changed()));
2409
2410         shortcut_ = new GuiShortcutDialog(this);
2411         shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2412         shortcut_bc_.setOK(shortcut_->okPB);
2413         shortcut_bc_.setCancel(shortcut_->cancelPB);
2414
2415         connect(shortcut_->okPB, SIGNAL(clicked()),
2416                 shortcut_, SLOT(accept()));
2417         connect(shortcut_->okPB, SIGNAL(clicked()),
2418                 this, SIGNAL(changed()));
2419         connect(shortcut_->cancelPB, SIGNAL(clicked()),
2420                 shortcut_, SLOT(reject()));
2421         connect(shortcut_->clearPB, SIGNAL(clicked()),
2422                 this, SLOT(shortcutClearPressed()));
2423         connect(shortcut_->removePB, SIGNAL(clicked()),
2424                 this, SLOT(shortcutRemovePressed()));
2425         connect(shortcut_->okPB, SIGNAL(clicked()),
2426                 this, SLOT(shortcutOkPressed()));
2427         connect(shortcut_->cancelPB, SIGNAL(clicked()),
2428                 this, SLOT(shortcutCancelPressed()));
2429 }
2430
2431
2432 void PrefShortcuts::apply(LyXRC & rc) const
2433 {
2434         rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2435         // write user_bind and user_unbind to .lyx/bind/user.bind
2436         FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2437         if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2438                 lyxerr << "LyX could not create the user bind directory '"
2439                        << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2440                 return;
2441         }
2442         if (!bind_dir.isDirWritable()) {
2443                 lyxerr << "LyX could not write to the user bind directory '"
2444                        << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2445                 return;
2446         }
2447         FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2448         user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2449         user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2450         // immediately apply the keybindings. Why this is not done before?
2451         // The good thing is that the menus are updated automatically.
2452         theTopLevelKeymap().clear();
2453         theTopLevelKeymap().read("site");
2454         theTopLevelKeymap().read(rc.bind_file, 0, KeyMap::Fallback);
2455         theTopLevelKeymap().read("user", 0, KeyMap::MissingOK);
2456 }
2457
2458
2459 void PrefShortcuts::update(LyXRC const & rc)
2460 {
2461         bindFileED->setText(toqstr(external_path(rc.bind_file)));
2462         //
2463         system_bind_.clear();
2464         user_bind_.clear();
2465         user_unbind_.clear();
2466         system_bind_.read("site");
2467         system_bind_.read(rc.bind_file);
2468         // \unbind in user.bind is added to user_unbind_
2469         user_bind_.read("user", &user_unbind_, KeyMap::MissingOK);
2470         updateShortcutsTW();
2471 }
2472
2473
2474 void PrefShortcuts::updateShortcutsTW()
2475 {
2476         shortcutsTW->clear();
2477
2478         editItem_ = new QTreeWidgetItem(shortcutsTW);
2479         editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2480         editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2481
2482         mathItem_ = new QTreeWidgetItem(shortcutsTW);
2483         mathItem_->setText(0, qt_("Mathematical Symbols"));
2484         mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2485
2486         bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2487         bufferItem_->setText(0, qt_("Document and Window"));
2488         bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2489
2490         layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2491         layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2492         layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2493
2494         systemItem_ = new QTreeWidgetItem(shortcutsTW);
2495         systemItem_->setText(0, qt_("System and Miscellaneous"));
2496         systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2497
2498         // listBindings(unbound=true) lists all bound and unbound lfuns
2499         // Items in this list is tagged by its source.
2500         KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2501                 KeyMap::System);
2502         KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2503                 KeyMap::UserBind);
2504         KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2505                 KeyMap::UserUnbind);
2506         bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2507                         user_bindinglist.end());
2508         bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2509                         user_unbindinglist.end());
2510
2511         KeyMap::BindingList::const_iterator it = bindinglist.begin();
2512         KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2513         for (; it != it_end; ++it)
2514                 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2515
2516         shortcutsTW->sortItems(0, Qt::AscendingOrder);
2517         QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2518         removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2519         modifyPB->setEnabled(!items.isEmpty());
2520
2521         shortcutsTW->resizeColumnToContents(0);
2522 }
2523
2524
2525 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2526 {
2527         item->setData(0, Qt::UserRole, QVariant(tag));
2528         QFont font;
2529
2530         switch (tag) {
2531         case KeyMap::System:
2532                 break;
2533         case KeyMap::UserBind:
2534                 font.setBold(true);
2535                 break;
2536         case KeyMap::UserUnbind:
2537                 font.setStrikeOut(true);
2538                 break;
2539         // this item is not displayed now.
2540         case KeyMap::UserExtraUnbind:
2541                 font.setStrikeOut(true);
2542                 break;
2543         }
2544
2545         item->setFont(1, font);
2546 }
2547
2548
2549 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2550                 KeySequence const & seq, KeyMap::ItemType tag)
2551 {
2552         FuncCode action = lfun.action;
2553         string const action_name = lyxaction.getActionName(action);
2554         QString const lfun_name = toqstr(from_utf8(action_name)
2555                         + ' ' + lfun.argument());
2556         QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2557         KeyMap::ItemType item_tag = tag;
2558
2559         QTreeWidgetItem * newItem = 0;
2560         // for unbind items, try to find an existing item in the system bind list
2561         if (tag == KeyMap::UserUnbind) {
2562                 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2563                         Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2564                 for (int i = 0; i < items.size(); ++i) {
2565                         if (items[i]->text(1) == shortcut)
2566                                 newItem = items[i];
2567                                 break;
2568                         }
2569                 // if not found, this unbind item is KeyMap::UserExtraUnbind
2570                 // Such an item is not displayed to avoid confusion (what is
2571                 // unmatched removed?).
2572                 if (!newItem) {
2573                         item_tag = KeyMap::UserExtraUnbind;
2574                         return 0;
2575                 }
2576         }
2577         if (!newItem) {
2578                 switch(lyxaction.getActionType(action)) {
2579                 case LyXAction::Hidden:
2580                         return 0;
2581                 case LyXAction::Edit:
2582                         newItem = new QTreeWidgetItem(editItem_);
2583                         break;
2584                 case LyXAction::Math:
2585                         newItem = new QTreeWidgetItem(mathItem_);
2586                         break;
2587                 case LyXAction::Buffer:
2588                         newItem = new QTreeWidgetItem(bufferItem_);
2589                         break;
2590                 case LyXAction::Layout:
2591                         newItem = new QTreeWidgetItem(layoutItem_);
2592                         break;
2593                 case LyXAction::System:
2594                         newItem = new QTreeWidgetItem(systemItem_);
2595                         break;
2596                 default:
2597                         // this should not happen
2598                         newItem = new QTreeWidgetItem(shortcutsTW);
2599                 }
2600         }
2601
2602         newItem->setText(0, lfun_name);
2603         newItem->setText(1, shortcut);
2604         // record BindFile representation to recover KeySequence when needed.
2605         newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2606         setItemType(newItem, item_tag);
2607         return newItem;
2608 }
2609
2610
2611 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2612 {
2613         QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2614         removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2615         modifyPB->setEnabled(!items.isEmpty());
2616         if (items.isEmpty())
2617                 return;
2618
2619         KeyMap::ItemType tag = 
2620                 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2621         if (tag == KeyMap::UserUnbind)
2622                 removePB->setText(qt_("Res&tore"));
2623         else
2624                 removePB->setText(qt_("Remo&ve"));
2625 }
2626
2627
2628 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2629 {
2630         modifyShortcut();
2631 }
2632
2633
2634 void PrefShortcuts::modifyShortcut()
2635 {
2636         QTreeWidgetItem * item = shortcutsTW->currentItem();
2637         if (item->flags() & Qt::ItemIsSelectable) {
2638                 shortcut_->lfunLE->setText(item->text(0));
2639                 save_lfun_ = item->text(0);
2640                 shortcut_->shortcutWG->setText(item->text(1));
2641                 KeySequence seq;
2642                 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2643                 shortcut_->shortcutWG->setKeySequence(seq);
2644                 shortcut_->shortcutWG->setFocus();
2645                 shortcut_->exec();
2646         }
2647 }
2648
2649
2650 void PrefShortcuts::removeShortcut()
2651 {
2652         // it seems that only one item can be selected, but I am
2653         // removing all selected items anyway.
2654         QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2655         for (int i = 0; i < items.size(); ++i) {
2656                 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2657                 string lfun = fromqstr(items[i]->text(0));
2658                 FuncRequest func = lyxaction.lookupFunc(lfun);
2659                 KeyMap::ItemType tag = 
2660                         static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2661
2662                 switch (tag) {
2663                 case KeyMap::System: {
2664                         // for system bind, we do not touch the item
2665                         // but add an user unbind item
2666                         user_unbind_.bind(shortcut, func);
2667                         setItemType(items[i], KeyMap::UserUnbind);
2668                         removePB->setText(qt_("Res&tore"));
2669                         break;
2670                 }
2671                 case KeyMap::UserBind: {
2672                         // for user_bind, we remove this bind
2673                         QTreeWidgetItem * parent = items[i]->parent();
2674                         int itemIdx = parent->indexOfChild(items[i]);
2675                         parent->takeChild(itemIdx);
2676                         if (itemIdx > 0)
2677                                 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2678                         else
2679                                 shortcutsTW->scrollToItem(parent);
2680                         user_bind_.unbind(shortcut, func);
2681                         break;
2682                 }
2683                 case KeyMap::UserUnbind: {
2684                         // for user_unbind, we remove the unbind, and the item
2685                         // become KeyMap::System again.
2686                         user_unbind_.unbind(shortcut, func);
2687                         setItemType(items[i], KeyMap::System);
2688                         removePB->setText(qt_("Remo&ve"));
2689                         break;
2690                 }
2691                 case KeyMap::UserExtraUnbind: {
2692                         // for user unbind that is not in system bind file,
2693                         // remove this unbind file
2694                         QTreeWidgetItem * parent = items[i]->parent();
2695                         parent->takeChild(parent->indexOfChild(items[i]));
2696                         user_unbind_.unbind(shortcut, func);
2697                 }
2698                 }
2699         }
2700 }
2701
2702
2703 void PrefShortcuts::selectBind()
2704 {
2705         QString file = form_->browsebind(internalPath(bindFileED->text()));
2706         if (!file.isEmpty()) {
2707                 bindFileED->setText(file);
2708                 system_bind_ = KeyMap();
2709                 system_bind_.read(fromqstr(file));
2710                 updateShortcutsTW();
2711         }
2712 }
2713
2714
2715 void PrefShortcuts::on_modifyPB_pressed()
2716 {
2717         modifyShortcut();
2718 }
2719
2720
2721 void PrefShortcuts::on_newPB_pressed()
2722 {
2723         shortcut_->lfunLE->clear();
2724         shortcut_->shortcutWG->reset();
2725         save_lfun_ = QString();
2726         shortcut_->exec();
2727 }
2728
2729
2730 void PrefShortcuts::on_removePB_pressed()
2731 {
2732         removeShortcut();
2733 }
2734
2735
2736 void PrefShortcuts::on_searchLE_textEdited()
2737 {
2738         if (searchLE->text().isEmpty()) {
2739                 // show all hidden items
2740                 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2741                 while (*it)
2742                         shortcutsTW->setItemHidden(*it++, false);
2743                 return;
2744         }
2745         // search both columns
2746         QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2747                 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2748         matched += shortcutsTW->findItems(searchLE->text(),
2749                 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2750
2751         // hide everyone (to avoid searching in matched QList repeatedly
2752         QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2753         while (*it)
2754                 shortcutsTW->setItemHidden(*it++, true);
2755         // show matched items
2756         for (int i = 0; i < matched.size(); ++i) {
2757                 shortcutsTW->setItemHidden(matched[i], false);
2758         shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2759         }
2760 }
2761
2762
2763 docstring makeCmdString(FuncRequest const & f)
2764 {
2765         docstring actionStr = from_ascii(lyxaction.getActionName(f.action));
2766         if (!f.argument().empty())
2767                 actionStr += " " + f.argument();
2768         return actionStr;
2769 }
2770
2771
2772 void PrefShortcuts::shortcutOkPressed()
2773 {
2774         QString const new_lfun = shortcut_->lfunLE->text();
2775         FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2776
2777         if (func.action == LFUN_UNKNOWN_ACTION) {
2778                 Alert::error(_("Failed to create shortcut"),
2779                         _("Unknown or invalid LyX function"));
2780                 return;
2781         }
2782
2783         KeySequence k = shortcut_->shortcutWG->getKeySequence();
2784         if (k.length() == 0) {
2785                 Alert::error(_("Failed to create shortcut"),
2786                         _("Invalid or empty key sequence"));
2787                 return;
2788         }
2789
2790         // check to see if there's been any change
2791         FuncRequest oldBinding = system_bind_.getBinding(k);
2792         if (oldBinding.action == LFUN_UNKNOWN_ACTION)
2793                 oldBinding = user_bind_.getBinding(k);
2794         if (oldBinding == func) {
2795                 docstring const actionStr = makeCmdString(func);
2796                 Alert::error(_("Failed to create shortcut"),
2797                         bformat(_("Shortcut `%1$s' is already bound to:\n%2$s"), 
2798                         k.print(KeySequence::ForGui), actionStr));
2799                 return;
2800         }
2801         
2802         // make sure this key isn't already bound---and, if so, not unbound
2803         FuncCode const unbind = user_unbind_.getBinding(k).action;
2804         if (oldBinding.action != LFUN_UNKNOWN_ACTION && unbind == LFUN_UNKNOWN_ACTION)
2805         {
2806                 // FIXME Perhaps we should offer to over-write the old shortcut?
2807                 // If so, we'll need to remove it from our list, etc.
2808                 docstring const actionStr = makeCmdString(oldBinding);
2809                 Alert::error(_("Failed to create shortcut"),
2810                         bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2811                           "You need to remove that binding before creating a new one."), 
2812                         k.print(KeySequence::ForGui), actionStr));
2813                 return;
2814         }
2815
2816         if (!save_lfun_.isEmpty() && new_lfun == save_lfun_)
2817                 // real modification of the lfun's shortcut,
2818                 // so remove the previous one
2819                 removeShortcut();
2820
2821         QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2822         if (item) {
2823                 user_bind_.bind(&k, func);
2824                 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2825                 shortcutsTW->setItemExpanded(item->parent(), true);
2826                 shortcutsTW->scrollToItem(item);
2827         } else {
2828                 Alert::error(_("Failed to create shortcut"),
2829                         _("Can not insert shortcut to the list"));
2830                 return;
2831         }
2832 }
2833
2834
2835 void PrefShortcuts::shortcutCancelPressed()
2836 {
2837         shortcut_->shortcutWG->reset();
2838 }
2839
2840
2841 void PrefShortcuts::shortcutClearPressed()
2842 {
2843         shortcut_->shortcutWG->reset();
2844 }
2845
2846
2847 void PrefShortcuts::shortcutRemovePressed()
2848 {
2849         shortcut_->shortcutWG->removeFromSequence();
2850 }
2851
2852
2853 /////////////////////////////////////////////////////////////////////
2854 //
2855 // PrefIdentity
2856 //
2857 /////////////////////////////////////////////////////////////////////
2858
2859 PrefIdentity::PrefIdentity(GuiPreferences * form)
2860         : PrefModule(QString(), qt_("Identity"), form)
2861 {
2862         setupUi(this);
2863
2864         connect(nameED, SIGNAL(textChanged(QString)),
2865                 this, SIGNAL(changed()));
2866         connect(emailED, SIGNAL(textChanged(QString)),
2867                 this, SIGNAL(changed()));
2868 }
2869
2870
2871 void PrefIdentity::apply(LyXRC & rc) const
2872 {
2873         rc.user_name = fromqstr(nameED->text());
2874         rc.user_email = fromqstr(emailED->text());
2875 }
2876
2877
2878 void PrefIdentity::update(LyXRC const & rc)
2879 {
2880         nameED->setText(toqstr(rc.user_name));
2881         emailED->setText(toqstr(rc.user_email));
2882 }
2883
2884
2885
2886 /////////////////////////////////////////////////////////////////////
2887 //
2888 // GuiPreferences
2889 //
2890 /////////////////////////////////////////////////////////////////////
2891
2892 GuiPreferences::GuiPreferences(GuiView & lv)
2893         : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2894 {
2895         setupUi(this);
2896
2897         QDialog::setModal(false);
2898
2899         connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2900         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2901         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2902         connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2903
2904         addModule(new PrefUserInterface(this));
2905         addModule(new PrefEdit(this));
2906         addModule(new PrefShortcuts(this));
2907         addModule(new PrefScreenFonts(this));
2908         addModule(new PrefColors(this));
2909         addModule(new PrefDisplay(this));
2910         addModule(new PrefInput(this));
2911         addModule(new PrefCompletion(this));
2912
2913         addModule(new PrefPaths(this));
2914
2915         addModule(new PrefIdentity(this));
2916
2917         addModule(new PrefLanguage(this));
2918         addModule(new PrefSpellchecker(this));
2919
2920         addModule(new PrefPrinter(this));
2921         PrefDate * dateFormat = new PrefDate(this);
2922         addModule(dateFormat);
2923         addModule(new PrefPlaintext(this));
2924         addModule(new PrefLatex(this));
2925
2926         PrefConverters * converters = new PrefConverters(this);
2927         PrefFileformats * formats = new PrefFileformats(this);
2928         connect(formats, SIGNAL(formatsChanged()),
2929                         converters, SLOT(updateGui()));
2930         addModule(converters);
2931         addModule(formats);
2932
2933         prefsPS->setCurrentPanel(qt_("User interface"));
2934 // FIXME: hack to work around resizing bug in Qt >= 4.2
2935 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2936 #if QT_VERSION >= 0x040200
2937         prefsPS->updateGeometry();
2938 #endif
2939
2940         bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2941         bc().setOK(savePB);
2942         bc().setApply(applyPB);
2943         bc().setCancel(closePB);
2944         bc().setRestore(restorePB);
2945
2946         // initialize the strftime validator
2947         bc().addCheckedLineEdit(dateFormat->DateED);
2948 }
2949
2950
2951 void GuiPreferences::addModule(PrefModule * module)
2952 {
2953         LASSERT(module, return);
2954         if (module->category().isEmpty())
2955                 prefsPS->addPanel(module, module->title());
2956         else
2957                 prefsPS->addPanel(module, module->title(), module->category());
2958         connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2959         modules_.push_back(module);
2960 }
2961
2962
2963 void GuiPreferences::change_adaptor()
2964 {
2965         changed();
2966 }
2967
2968
2969 void GuiPreferences::apply(LyXRC & rc) const
2970 {
2971         size_t end = modules_.size();
2972         for (size_t i = 0; i != end; ++i)
2973                 modules_[i]->apply(rc);
2974 }
2975
2976
2977 void GuiPreferences::updateRc(LyXRC const & rc)
2978 {
2979         size_t const end = modules_.size();
2980         for (size_t i = 0; i != end; ++i)
2981                 modules_[i]->update(rc);
2982 }
2983
2984
2985 void GuiPreferences::applyView()
2986 {
2987         apply(rc());
2988 }
2989
2990 bool GuiPreferences::initialiseParams(string const &)
2991 {
2992         rc_ = lyxrc;
2993         formats_ = lyx::formats;
2994         converters_ = theConverters();
2995         converters_.update(formats_);
2996         movers_ = theMovers();
2997         colors_.clear();
2998         update_screen_font_ = false;
2999         
3000         updateRc(rc_);
3001         // Make sure that the bc is in the INITIAL state  
3002         if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))  
3003                 bc().restore();  
3004
3005         return true;
3006 }
3007
3008
3009 void GuiPreferences::dispatchParams()
3010 {
3011         ostringstream ss;
3012         rc_.write(ss, true);
3013         dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
3014         // FIXME: these need lfuns
3015         // FIXME UNICODE
3016         theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
3017
3018         lyx::formats = formats_;
3019
3020         theConverters() = converters_;
3021         theConverters().update(lyx::formats);
3022         theConverters().buildGraph();
3023
3024         theMovers() = movers_;
3025
3026         vector<string>::const_iterator it = colors_.begin();
3027         vector<string>::const_iterator const end = colors_.end();
3028         for (; it != end; ++it)
3029                 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
3030         colors_.clear();
3031
3032         if (update_screen_font_) {
3033                 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3034                 update_screen_font_ = false;
3035         }
3036
3037         // The Save button has been pressed
3038         if (isClosing())
3039                 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
3040 }
3041
3042
3043 void GuiPreferences::setColor(ColorCode col, QString const & hex)
3044 {
3045         colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
3046 }
3047
3048
3049 void GuiPreferences::updateScreenFonts()
3050 {
3051         update_screen_font_ = true;
3052 }
3053
3054
3055 QString GuiPreferences::browsebind(QString const & file) const
3056 {
3057         return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
3058                              QStringList(qt_("LyX bind files (*.bind)")));
3059 }
3060
3061
3062 QString GuiPreferences::browseUI(QString const & file) const
3063 {
3064         return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
3065                              QStringList(qt_("LyX UI files (*.ui)")));
3066 }
3067
3068
3069 QString GuiPreferences::browsekbmap(QString const & file) const
3070 {
3071         return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
3072                              QStringList(qt_("LyX keyboard maps (*.kmap)")));
3073 }
3074
3075
3076 QString GuiPreferences::browse(QString const & file,
3077         QString const & title) const
3078 {
3079         return browseFile(file, title, QStringList(), true);
3080 }
3081
3082
3083 // We support less paper sizes than the document dialog
3084 // Therefore this adjustment is needed.
3085 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
3086 {
3087         switch (i) {
3088         case 0:
3089                 return PAPER_DEFAULT;
3090         case 1:
3091                 return PAPER_USLETTER;
3092         case 2:
3093                 return PAPER_USLEGAL;
3094         case 3:
3095                 return PAPER_USEXECUTIVE;
3096         case 4:
3097                 return PAPER_A3;
3098         case 5:
3099                 return PAPER_A4;
3100         case 6:
3101                 return PAPER_A5;
3102         case 7:
3103                 return PAPER_B5;
3104         default:
3105                 // should not happen
3106                 return PAPER_DEFAULT;
3107         }
3108 }
3109
3110
3111 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
3112 {
3113         switch (papersize) {
3114         case PAPER_DEFAULT:
3115                 return 0;
3116         case PAPER_USLETTER:
3117                 return 1;
3118         case PAPER_USLEGAL:
3119                 return 2;
3120         case PAPER_USEXECUTIVE:
3121                 return 3;
3122         case PAPER_A3:
3123                 return 4;
3124         case PAPER_A4:
3125                 return 5;
3126         case PAPER_A5:
3127                 return 6;
3128         case PAPER_B5:
3129                 return 7;
3130         default:
3131                 // should not happen
3132                 return 0;
3133         }
3134 }
3135
3136
3137 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
3138
3139
3140 } // namespace frontend
3141 } // namespace lyx
3142
3143 #include "moc_GuiPrefs.cpp"