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