]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QPrefs.cpp
* src/frontends/qt4/ui/TextLayoutUi.ui:
[lyx.git] / src / frontends / qt4 / QPrefs.cpp
1 /**
2  * \file QPrefs.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  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QPrefs.h"
14
15 #include "Qt2BC.h"
16 #include "qt_helpers.h"
17 #include "GuiApplication.h"
18
19 #include "ConverterCache.h"
20 #include "Session.h"
21 #include "debug.h"
22 #include "Color.h"
23 #include "Font.h"
24 #include "PanelStack.h"
25 #include "QFontExample.h"
26 #include "gettext.h"
27
28 #include "support/lstrings.h"
29 #include "support/os.h"
30
31 #include "controllers/ControlPrefs.h"
32 #include "controllers/frontend_helpers.h"
33
34 #include "frontends/alert.h"
35 #include "frontends/Application.h"
36
37 #include <QCheckBox>
38 #include <QColorDialog>
39 #include <QFontDatabase>
40 #include <QLineEdit>
41 #include <QPushButton>
42 #include <QSpinBox>
43 #include <QString>
44 #include <QValidator>
45 #include <QCloseEvent>
46
47 #include <boost/tuple/tuple.hpp>
48 #include <iomanip>
49 #include <sstream>
50
51 using namespace Ui;
52
53 using lyx::support::compare_ascii_no_case;
54 using lyx::support::os::external_path;
55 using lyx::support::os::external_path_list;
56 using lyx::support::os::internal_path;
57 using lyx::support::os::internal_path_list;
58
59 using std::endl;
60 using std::string;
61 using std::pair;
62 using std::vector;
63
64
65 namespace lyx {
66 namespace frontend {
67
68 /////////////////////////////////////////////////////////////////////
69 //
70 // Helpers
71 //
72 /////////////////////////////////////////////////////////////////////
73
74 string const LookAndFeel = N_("Look and feel");
75 string const LanguageSettings = N_("Language settings");
76 string const Outputs = N_("Outputs");
77
78
79 // FIXME: move to frontend_helpers.h
80
81 template<class A>
82 static size_t findPos_helper(std::vector<A> const & vec, A const & val)
83 {
84         typedef typename std::vector<A>::const_iterator Cit;
85
86         Cit it = std::find(vec.begin(), vec.end(), val);
87         if (it == vec.end())
88                 return 0;
89         return std::distance(vec.begin(), it);
90 }
91
92
93 static void setComboxFont(QComboBox * cb, string const & family,
94         string const & foundry)
95 {
96         string const name = makeFontName(family, foundry);
97         for (int i = 0; i < cb->count(); ++i) {
98                 if (fromqstr(cb->itemText(i)) == name) {
99                         cb->setCurrentIndex(i);
100                         return;
101                 }
102         }
103
104         // Try matching without foundry name
105
106         // We count in reverse in order to prefer the Xft foundry
107         for (int i = cb->count() - 1; i >= 0; --i) {
108                 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
109                 if (compare_ascii_no_case(tmp.first, family) == 0) {
110                         cb->setCurrentIndex(i);
111                         return;
112                 }
113         }
114
115         // family alone can contain e.g. "Helvetica [Adobe]"
116         pair<string, string> tmpfam = parseFontName(family);
117
118         // We count in reverse in order to prefer the Xft foundry
119         for (int i = cb->count() - 1; i >= 0; --i) {
120                 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
121                 if (compare_ascii_no_case(tmp.first, tmpfam.first) == 0) {
122                         cb->setCurrentIndex(i);
123                         return;
124                 }
125         }
126
127         // Bleh, default fonts, and the names couldn't be found. Hack
128         // for bug 1063.
129
130         QFont font;
131         font.setKerning(false);
132
133         if (family == theApp()->romanFontName()) {
134                 font.setStyleHint(QFont::Serif);
135                 font.setFamily(family.c_str());
136         } else if (family == theApp()->sansFontName()) {
137                 font.setStyleHint(QFont::SansSerif);
138                 font.setFamily(family.c_str());
139         } else if (family == theApp()->typewriterFontName()) {
140                 font.setStyleHint(QFont::TypeWriter);
141                 font.setFamily(family.c_str());
142         } else {
143                 lyxerr << "FAILED to find the default font: '"
144                        << foundry << "', '" << family << '\''<< endl;
145                 return;
146         }
147
148         QFontInfo info(font);
149         pair<string, string> tmp = parseFontName(fromqstr(info.family()));
150         string const & default_font_name = tmp.first;
151         lyxerr << "Apparent font is " << default_font_name << endl;
152
153         for (int i = 0; i < cb->count(); ++i) {
154                 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
155                 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
156                                     default_font_name) == 0) {
157                         cb->setCurrentIndex(i);
158                         return;
159                 }
160         }
161
162         lyxerr << "FAILED to find the font: '"
163                << foundry << "', '" << family << '\'' <<endl;
164 }
165
166
167 /////////////////////////////////////////////////////////////////////
168 //
169 // PrefPlaintext
170 //
171 /////////////////////////////////////////////////////////////////////
172
173 PrefPlaintext::PrefPlaintext(QWidget * parent)
174         : PrefModule(_(Outputs), _("Plain text"), 0, parent)
175 {
176         setupUi(this);
177         connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
178                 this, SIGNAL(changed()));
179         connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
180                 this, SIGNAL(changed()));
181 }
182
183
184 void PrefPlaintext::apply(LyXRC & rc) const
185 {
186         rc.plaintext_linelen = plaintextLinelengthSB->value();
187         rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
188 }
189
190
191 void PrefPlaintext::update(LyXRC const & rc)
192 {
193         plaintextLinelengthSB->setValue(rc.plaintext_linelen);
194         plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
195 }
196
197
198 /////////////////////////////////////////////////////////////////////
199 //
200 // PrefDate
201 //
202 /////////////////////////////////////////////////////////////////////
203
204 PrefDate::PrefDate(QWidget * parent)
205         : PrefModule(_(Outputs), _("Date format"), 0, parent)
206 {
207         setupUi(this);
208         connect(DateED, SIGNAL(textChanged(const QString &)),
209                 this, SIGNAL(changed()));
210 }
211
212
213 void PrefDate::apply(LyXRC & rc) const
214 {
215         rc.date_insert_format = fromqstr(DateED->text());
216 }
217
218
219 void PrefDate::update(LyXRC const & rc)
220 {
221         DateED->setText(toqstr(rc.date_insert_format));
222 }
223
224
225 /////////////////////////////////////////////////////////////////////
226 //
227 // PrefKeyboard
228 //
229 /////////////////////////////////////////////////////////////////////
230
231 PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
232         : PrefModule(_(LookAndFeel), _("Keyboard"), form, parent)
233 {
234         setupUi(this);
235
236         connect(keymapCB, SIGNAL(clicked()),
237                 this, SIGNAL(changed()));
238         connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
239                 this, SIGNAL(changed()));
240         connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
241                 this, SIGNAL(changed()));
242 }
243
244
245 void PrefKeyboard::apply(LyXRC & rc) const
246 {
247         // FIXME: can derive CB from the two EDs
248         rc.use_kbmap = keymapCB->isChecked();
249         rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
250         rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
251 }
252
253
254 void PrefKeyboard::update(LyXRC const & rc)
255 {
256         // FIXME: can derive CB from the two EDs
257         keymapCB->setChecked(rc.use_kbmap);
258         firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
259         secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
260 }
261
262
263 QString PrefKeyboard::testKeymap(QString keymap)
264 {
265         return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
266 }
267
268
269 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
270 {
271         QString const file = testKeymap(firstKeymapED->text());
272         if (!file.isEmpty())
273                 firstKeymapED->setText(file);
274 }
275
276
277 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
278 {
279         QString const file = testKeymap(secondKeymapED->text());
280         if (!file.isEmpty())
281                 secondKeymapED->setText(file);
282 }
283
284
285 void PrefKeyboard::on_keymapCB_toggled(bool keymap)
286 {
287         firstKeymapLA->setEnabled(keymap);
288         secondKeymapLA->setEnabled(keymap);
289         firstKeymapED->setEnabled(keymap);
290         secondKeymapED->setEnabled(keymap);
291         firstKeymapPB->setEnabled(keymap);
292         secondKeymapPB->setEnabled(keymap);
293 }
294
295
296 /////////////////////////////////////////////////////////////////////
297 //
298 // PrefLatex
299 //
300 /////////////////////////////////////////////////////////////////////
301
302 PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
303         : PrefModule(_(Outputs), _("LaTeX"), form, parent)
304 {
305         setupUi(this);
306         connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
307                 this, SIGNAL(changed()));
308         connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
309                 this, SIGNAL(changed()));
310         connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
311                 this, SIGNAL(changed()));
312         connect(latexIndexED, SIGNAL(textChanged(const QString&)),
313                 this, SIGNAL(changed()));
314         connect(latexAutoresetCB, SIGNAL(clicked()),
315                 this, SIGNAL(changed()));
316         connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
317                 this, SIGNAL(changed()));
318         connect(latexPaperSizeCO, SIGNAL(activated(int)),
319                 this, SIGNAL(changed()));
320 }
321
322
323 void PrefLatex::apply(LyXRC & rc) const
324 {
325         rc.fontenc = fromqstr(latexEncodingED->text());
326         rc.chktex_command = fromqstr(latexChecktexED->text());
327         rc.bibtex_command = fromqstr(latexBibtexED->text());
328         rc.index_command = fromqstr(latexIndexED->text());
329         rc.auto_reset_options = latexAutoresetCB->isChecked();
330         rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
331         rc.default_papersize =
332                 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
333 }
334
335
336 void PrefLatex::update(LyXRC const & rc)
337 {
338         latexEncodingED->setText(toqstr(rc.fontenc));
339         latexChecktexED->setText(toqstr(rc.chktex_command));
340         latexBibtexED->setText(toqstr(rc.bibtex_command));
341         latexIndexED->setText(toqstr(rc.index_command));
342         latexAutoresetCB->setChecked(rc.auto_reset_options);
343         latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
344         latexPaperSizeCO->setCurrentIndex(
345                 form_->controller().fromPaperSize(rc.default_papersize));
346 }
347
348
349 /////////////////////////////////////////////////////////////////////
350 //
351 // PrefScreenFonts
352 //
353 /////////////////////////////////////////////////////////////////////
354
355 PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
356         : PrefModule(_(LookAndFeel), _("Screen fonts"), form, parent)
357 {
358         setupUi(this);
359
360         connect(screenRomanCO, SIGNAL(activated(const QString&)),
361                 this, SLOT(select_roman(const QString&)));
362         connect(screenSansCO, SIGNAL(activated(const QString&)),
363                 this, SLOT(select_sans(const QString&)));
364         connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
365                 this, SLOT(select_typewriter(const QString&)));
366
367         QFontDatabase fontdb;
368         QStringList families(fontdb.families());
369         for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
370                 screenRomanCO->addItem(*it);
371                 screenSansCO->addItem(*it);
372                 screenTypewriterCO->addItem(*it);
373         }
374         connect(screenRomanCO, SIGNAL(activated(const QString&)),
375                 this, SIGNAL(changed()));
376         connect(screenSansCO, SIGNAL(activated(const QString&)),
377                 this, SIGNAL(changed()));
378         connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
379                 this, SIGNAL(changed()));
380         connect(screenZoomSB, SIGNAL(valueChanged(int)),
381                 this, SIGNAL(changed()));
382         connect(screenDpiSB, SIGNAL(valueChanged(int)),
383                 this, SIGNAL(changed()));
384         connect(screenTinyED, SIGNAL(textChanged(const QString&)),
385                 this, SIGNAL(changed()));
386         connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
387                 this, SIGNAL(changed()));
388         connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
389                 this, SIGNAL(changed()));
390         connect(screenSmallED, SIGNAL(textChanged(const QString&)),
391                 this, SIGNAL(changed()));
392         connect(screenNormalED, SIGNAL(textChanged(const QString&)),
393                 this, SIGNAL(changed()));
394         connect(screenLargeED, SIGNAL(textChanged(const QString&)),
395                 this, SIGNAL(changed()));
396         connect(screenLargerED, SIGNAL(textChanged(const QString&)),
397                 this, SIGNAL(changed()));
398         connect(screenLargestED, SIGNAL(textChanged(const QString&)),
399                 this, SIGNAL(changed()));
400         connect(screenHugeED, SIGNAL(textChanged(const QString&)),
401                 this, SIGNAL(changed()));
402         connect(screenHugerED, SIGNAL(textChanged(const QString&)),
403                 this, SIGNAL(changed()));
404
405         screenTinyED->setValidator(new QDoubleValidator(
406                 screenTinyED));
407         screenSmallestED->setValidator(new QDoubleValidator(
408                 screenSmallestED));
409         screenSmallerED->setValidator(new QDoubleValidator(
410                 screenSmallerED));
411         screenSmallED->setValidator(new QDoubleValidator(
412                 screenSmallED));
413         screenNormalED->setValidator(new QDoubleValidator(
414                 screenNormalED));
415         screenLargeED->setValidator(new QDoubleValidator(
416                 screenLargeED));
417         screenLargerED->setValidator(new QDoubleValidator(
418                 screenLargerED));
419         screenLargestED->setValidator(new QDoubleValidator(
420                 screenLargestED));
421         screenHugeED->setValidator(new QDoubleValidator(
422                 screenHugeED));
423         screenHugerED->setValidator(new QDoubleValidator(
424                 screenHugerED));
425 }
426
427
428 void PrefScreenFonts::apply(LyXRC & rc) const
429 {
430         LyXRC const oldrc(rc);
431
432         boost::tie(rc.roman_font_name, rc.roman_font_foundry)
433                 = parseFontName(fromqstr(screenRomanCO->currentText()));
434         boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
435                 parseFontName(fromqstr(screenSansCO->currentText()));
436         boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
437                 parseFontName(fromqstr(screenTypewriterCO->currentText()));
438
439         rc.zoom = screenZoomSB->value();
440         rc.dpi = screenDpiSB->value();
441         rc.font_sizes[Font::SIZE_TINY] = fromqstr(screenTinyED->text());
442         rc.font_sizes[Font::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
443         rc.font_sizes[Font::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
444         rc.font_sizes[Font::SIZE_SMALL] = fromqstr(screenSmallED->text());
445         rc.font_sizes[Font::SIZE_NORMAL] = fromqstr(screenNormalED->text());
446         rc.font_sizes[Font::SIZE_LARGE] = fromqstr(screenLargeED->text());
447         rc.font_sizes[Font::SIZE_LARGER] = fromqstr(screenLargerED->text());
448         rc.font_sizes[Font::SIZE_LARGEST] = fromqstr(screenLargestED->text());
449         rc.font_sizes[Font::SIZE_HUGE] = fromqstr(screenHugeED->text());
450         rc.font_sizes[Font::SIZE_HUGER] = fromqstr(screenHugerED->text());
451
452         if (rc.font_sizes != oldrc.font_sizes
453                 || rc.roman_font_name != oldrc.roman_font_name
454                 || rc.sans_font_name != oldrc.sans_font_name
455                 || rc.typewriter_font_name != oldrc.typewriter_font_name
456                 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
457                 form_->controller().updateScreenFonts();
458         }
459 }
460
461
462 void PrefScreenFonts::update(LyXRC const & rc)
463 {
464         setComboxFont(screenRomanCO, rc.roman_font_name,
465                         rc.roman_font_foundry);
466         setComboxFont(screenSansCO, rc.sans_font_name,
467                         rc.sans_font_foundry);
468         setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
469                         rc.typewriter_font_foundry);
470
471         select_roman(screenRomanCO->currentText());
472         select_sans(screenSansCO->currentText());
473         select_typewriter(screenTypewriterCO->currentText());
474
475         screenZoomSB->setValue(rc.zoom);
476         screenDpiSB->setValue(rc.dpi);
477         screenTinyED->setText(toqstr(rc.font_sizes[Font::SIZE_TINY]));
478         screenSmallestED->setText(toqstr(rc.font_sizes[Font::SIZE_SCRIPT]));
479         screenSmallerED->setText(toqstr(rc.font_sizes[Font::SIZE_FOOTNOTE]));
480         screenSmallED->setText(toqstr(rc.font_sizes[Font::SIZE_SMALL]));
481         screenNormalED->setText(toqstr(rc.font_sizes[Font::SIZE_NORMAL]));
482         screenLargeED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGE]));
483         screenLargerED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGER]));
484         screenLargestED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGEST]));
485         screenHugeED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGE]));
486         screenHugerED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGER]));
487 }
488
489 void PrefScreenFonts::select_roman(const QString& name)
490 {
491         screenRomanFE->set(QFont(name), name);
492 }
493
494
495 void PrefScreenFonts::select_sans(const QString& name)
496 {
497         screenSansFE->set(QFont(name), name);
498 }
499
500
501 void PrefScreenFonts::select_typewriter(const QString& name)
502 {
503         screenTypewriterFE->set(QFont(name), name);
504 }
505
506
507 /////////////////////////////////////////////////////////////////////
508 //
509 // PrefColors
510 //
511 /////////////////////////////////////////////////////////////////////
512
513 PrefColors::PrefColors(QPrefs * form, QWidget * parent)
514         : PrefModule(_(LookAndFeel), _("Colors"), form, parent)
515 {
516         setupUi(this);
517
518         // FIXME: all of this initialization should be put into the controller.
519         // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
520         // for some discussion of why that is not trivial.
521         QPixmap icon(32, 32);
522         for (int i = 0; i < Color::ignore; ++i) {
523                 Color::color lc = static_cast<Color::color>(i);
524                 if (lc == Color::none
525                         || lc == Color::black
526                         || lc == Color::white
527                         || lc == Color::red
528                         || lc == Color::green
529                         || lc == Color::blue
530                         || lc == Color::cyan
531                         || lc == Color::magenta
532                         || lc == Color::yellow
533                         || lc == Color::inherit
534                         || lc == Color::ignore) continue;
535
536                 lcolors_.push_back(lc);
537                 // This is not a memory leak:
538                 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(icon),
539                         toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
540         }
541         curcolors_.resize(lcolors_.size());
542         newcolors_.resize(lcolors_.size());
543         // End initialization
544
545         connect(colorChangePB, SIGNAL(clicked()),
546                 this, SLOT(change_color()));
547         connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
548                 this, SLOT(change_lyxObjects_selection()));
549         connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
550                 this, SLOT(change_color()));
551 }
552
553
554 void PrefColors::apply(LyXRC & /*rc*/) const
555 {
556         for (unsigned int i = 0; i < lcolors_.size(); ++i) {
557                 if (curcolors_[i] != newcolors_[i]) {
558                         form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
559                 }
560         }
561 }
562
563
564 void PrefColors::update(LyXRC const & /*rc*/)
565 {
566         for (unsigned int i = 0; i < lcolors_.size(); ++i) {
567                 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
568                 QPixmap coloritem(32, 32);
569                 coloritem.fill(color);
570                 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
571                 newcolors_[i] = curcolors_[i] = color.name();
572         }
573         change_lyxObjects_selection();
574 }
575
576 void PrefColors::change_color()
577 {
578         int const row = lyxObjectsLW->currentRow();
579
580         // just to be sure
581         if (row < 0) return;
582
583         QString const color = newcolors_[row];
584         QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget()));
585
586         if (c.isValid() && c.name() != color) {
587                 newcolors_[row] = c.name();
588                 QPixmap coloritem(32, 32);
589                 coloritem.fill(c);
590                 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
591                 // emit signal
592                 changed();
593         }
594 }
595
596 void PrefColors::change_lyxObjects_selection()
597 {
598         colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
599 }
600
601
602 /////////////////////////////////////////////////////////////////////
603 //
604 // PrefCygwinPath
605 //
606 /////////////////////////////////////////////////////////////////////
607
608 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
609         : PrefModule(_(Outputs), _("Paths"), 0, parent)
610 {
611         setupUi(this);
612         connect(pathCB, SIGNAL(clicked()), this, SIGNAL(changed()));
613 }
614
615
616 void PrefCygwinPath::apply(LyXRC & rc) const
617 {
618         rc.windows_style_tex_paths = pathCB->isChecked();
619 }
620
621
622 void PrefCygwinPath::update(LyXRC const & rc)
623 {
624         pathCB->setChecked(rc.windows_style_tex_paths);
625 }
626
627
628 /////////////////////////////////////////////////////////////////////
629 //
630 // PrefDisplay
631 //
632 /////////////////////////////////////////////////////////////////////
633
634 PrefDisplay::PrefDisplay(QWidget * parent)
635         : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
636 {
637         setupUi(this);
638         connect(instantPreviewCO, SIGNAL(activated(int)),
639                 this, SIGNAL(changed()));
640         connect(displayGraphicsCO, SIGNAL(activated(int)),
641                 this, SIGNAL(changed()));
642 }
643
644
645 void PrefDisplay::apply(LyXRC & rc) const
646 {
647         switch (instantPreviewCO->currentIndex()) {
648         case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
649         case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
650         case 2: rc.preview = LyXRC::PREVIEW_ON; break;
651         }
652
653         lyx::graphics::DisplayType dtype;
654         switch (displayGraphicsCO->currentIndex()) {
655         case 3: dtype = lyx::graphics::NoDisplay; break;
656         case 2: dtype = lyx::graphics::ColorDisplay; break;
657         case 1: dtype = lyx::graphics::GrayscaleDisplay;        break;
658         case 0: dtype = lyx::graphics::MonochromeDisplay; break;
659         default: dtype = lyx::graphics::GrayscaleDisplay;
660         }
661         rc.display_graphics = dtype;
662
663 #ifdef WITH_WARNINGS
664 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
665 #endif
666 #if 0
667         if (old_value != rc.display_graphics) {
668                 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
669                 gc.changeDisplay();
670         }
671 #endif
672 }
673
674
675 void PrefDisplay::update(LyXRC const & rc)
676 {
677         switch (rc.preview) {
678         case LyXRC::PREVIEW_OFF:
679                 instantPreviewCO->setCurrentIndex(0);
680                 break;
681         case LyXRC::PREVIEW_NO_MATH :
682                 instantPreviewCO->setCurrentIndex(1);
683                 break;
684         case LyXRC::PREVIEW_ON :
685                 instantPreviewCO->setCurrentIndex(2);
686                 break;
687         }
688
689         int item = 2;
690         switch (rc.display_graphics) {
691                 case lyx::graphics::NoDisplay:          item = 3; break;
692                 case lyx::graphics::ColorDisplay:       item = 2; break;
693                 case lyx::graphics::GrayscaleDisplay:   item = 1; break;
694                 case lyx::graphics::MonochromeDisplay:  item = 0; break;
695                 default: break;
696         }
697         displayGraphicsCO->setCurrentIndex(item);
698 }
699
700
701 /////////////////////////////////////////////////////////////////////
702 //
703 // PrefPaths
704 //
705 /////////////////////////////////////////////////////////////////////
706
707 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
708         : PrefModule(docstring(), _("Paths"), form, parent)
709 {
710         setupUi(this);
711         connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
712         connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
713         connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
714         connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
715         connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
716         connect(workingDirED, SIGNAL(textChanged(const QString&)),
717                 this, SIGNAL(changed()));
718         connect(templateDirED, SIGNAL(textChanged(const QString&)),
719                 this, SIGNAL(changed()));
720         connect(backupDirED, SIGNAL(textChanged(const QString&)),
721                 this, SIGNAL(changed()));
722         connect(tempDirED, SIGNAL(textChanged(const QString&)),
723                 this, SIGNAL(changed()));
724         connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
725                 this, SIGNAL(changed()));
726         connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
727                 this, SIGNAL(changed()));
728 }
729
730
731 void PrefPaths::apply(LyXRC & rc) const
732 {
733         rc.document_path = internal_path(fromqstr(workingDirED->text()));
734         rc.template_path = internal_path(fromqstr(templateDirED->text()));
735         rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
736         rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
737         rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
738         // FIXME: should be a checkbox only
739         rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
740 }
741
742
743 void PrefPaths::update(LyXRC const & rc)
744 {
745         workingDirED->setText(toqstr(external_path(rc.document_path)));
746         templateDirED->setText(toqstr(external_path(rc.template_path)));
747         backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
748         tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
749         pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
750         // FIXME: should be a checkbox only
751         lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
752 }
753
754
755 void PrefPaths::select_templatedir()
756 {
757         docstring file(form_->controller().browsedir(
758                 from_utf8(internal_path(fromqstr(templateDirED->text()))),
759                 _("Select a document templates directory")));
760         if (!file.empty())
761                 templateDirED->setText(toqstr(file));
762 }
763
764
765 void PrefPaths::select_tempdir()
766 {
767         docstring file(form_->controller().browsedir(
768                 from_utf8(internal_path(fromqstr(tempDirED->text()))),
769                 _("Select a temporary directory")));
770         if (!file.empty())
771                 tempDirED->setText(toqstr(file));
772 }
773
774
775 void PrefPaths::select_backupdir()
776 {
777         docstring file(form_->controller().browsedir(
778                 from_utf8(internal_path(fromqstr(backupDirED->text()))),
779                 _("Select a backups directory")));
780         if (!file.empty())
781                 backupDirED->setText(toqstr(file));
782 }
783
784
785 void PrefPaths::select_workingdir()
786 {
787         docstring file(form_->controller().browsedir(
788                 from_utf8(internal_path(fromqstr(workingDirED->text()))),
789                 _("Select a document directory")));
790         if (!file.empty())
791                 workingDirED->setText(toqstr(file));
792 }
793
794
795 void PrefPaths::select_lyxpipe()
796 {
797         docstring file(form_->controller().browse(
798                 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
799                 _("Give a filename for the LyX server pipe")));
800         if (!file.empty())
801                 lyxserverDirED->setText(toqstr(file));
802 }
803
804
805 /////////////////////////////////////////////////////////////////////
806 //
807 // PrefSpellchecker
808 //
809 /////////////////////////////////////////////////////////////////////
810
811 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
812         : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
813 {
814         setupUi(this);
815
816         connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
817 #if defined (USE_ISPELL)
818         connect(spellCommandCO, SIGNAL(activated(int)),
819                 this, SIGNAL(changed()));
820 #else
821         spellCommandCO->setEnabled(false);
822 #endif
823         connect(altLanguageED, SIGNAL(textChanged(const QString&)),
824                 this, SIGNAL(changed()));
825         connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
826                 this, SIGNAL(changed()));
827         connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
828                 this, SIGNAL(changed()));
829         connect(compoundWordCB, SIGNAL(clicked()),
830                 this, SIGNAL(changed()));
831         connect(inputEncodingCB, SIGNAL(clicked()),
832                 this, SIGNAL(changed()));
833
834         spellCommandCO->addItem(qt_("ispell"));
835         spellCommandCO->addItem(qt_("aspell"));
836         spellCommandCO->addItem(qt_("hspell"));
837 #ifdef USE_PSPELL
838         spellCommandCO->addItem(qt_("pspell (library)"));
839 #else
840 #ifdef USE_ASPELL
841         spellCommandCO->addItem(qt_("aspell (library)"));
842 #endif
843 #endif
844 }
845
846
847 void PrefSpellchecker::apply(LyXRC & rc) const
848 {
849         switch (spellCommandCO->currentIndex()) {
850                 case 0:
851                 case 1:
852                 case 2:
853                         rc.use_spell_lib = false;
854                         rc.isp_command = fromqstr(spellCommandCO->currentText());
855                         break;
856                 case 3:
857                         rc.use_spell_lib = true;
858                         break;
859         }
860
861         // FIXME: remove isp_use_alt_lang
862         rc.isp_alt_lang = fromqstr(altLanguageED->text());
863         rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
864         // FIXME: remove isp_use_esc_chars
865         rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
866         rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
867         // FIXME: remove isp_use_pers_dict
868         rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
869         rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
870         rc.isp_accept_compound = compoundWordCB->isChecked();
871         rc.isp_use_input_encoding = inputEncodingCB->isChecked();
872 }
873
874
875 void PrefSpellchecker::update(LyXRC const & rc)
876 {
877         spellCommandCO->setCurrentIndex(0);
878
879         if (rc.isp_command == "ispell") {
880                 spellCommandCO->setCurrentIndex(0);
881         } else if (rc.isp_command == "aspell") {
882                 spellCommandCO->setCurrentIndex(1);
883         } else if (rc.isp_command == "hspell") {
884                 spellCommandCO->setCurrentIndex(2);
885         }
886
887         if (rc.use_spell_lib) {
888 #if defined(USE_ASPELL) || defined(USE_PSPELL)
889                 spellCommandCO->setCurrentIndex(3);
890 #endif
891         }
892
893         // FIXME: remove isp_use_alt_lang
894         altLanguageED->setText(toqstr(rc.isp_alt_lang));
895         // FIXME: remove isp_use_esc_chars
896         escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
897         // FIXME: remove isp_use_pers_dict
898         persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
899         compoundWordCB->setChecked(rc.isp_accept_compound);
900         inputEncodingCB->setChecked(rc.isp_use_input_encoding);
901 }
902
903
904 void PrefSpellchecker::select_dict()
905 {
906         docstring file(form_->controller().browsedict(
907                 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
908         if (!file.empty())
909                 persDictionaryED->setText(toqstr(file));
910 }
911
912
913
914 /////////////////////////////////////////////////////////////////////
915 //
916 // PrefConverters
917 //
918 /////////////////////////////////////////////////////////////////////
919
920
921 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
922         : PrefModule(docstring(), _("Converters"), form, parent)
923 {
924         setupUi(this);
925
926         connect(converterNewPB, SIGNAL(clicked()),
927                 this, SLOT(update_converter()));
928         connect(converterRemovePB, SIGNAL(clicked()),
929                 this, SLOT(remove_converter()));
930         connect(converterModifyPB, SIGNAL(clicked()),
931                 this, SLOT(update_converter()));
932         connect(convertersLW, SIGNAL(currentRowChanged(int)),
933                 this, SLOT(switch_converter()));
934         connect(converterFromCO, SIGNAL(activated(const QString&)),
935                 this, SLOT(converter_changed()));
936         connect(converterToCO, SIGNAL(activated(const QString&)),
937                 this, SLOT(converter_changed()));
938         connect(converterED, SIGNAL(textChanged(const QString&)),
939                 this, SLOT(converter_changed()));
940         connect(converterFlagED, SIGNAL(textChanged(const QString&)),
941                 this, SLOT(converter_changed()));
942         connect(converterNewPB, SIGNAL(clicked()),
943                 this, SIGNAL(changed()));
944         connect(converterRemovePB, SIGNAL(clicked()),
945                 this, SIGNAL(changed()));
946         connect(converterModifyPB, SIGNAL(clicked()),
947                 this, SIGNAL(changed()));
948         connect(maxAgeLE, SIGNAL(textChanged(const QString&)),
949                 this, SIGNAL(changed()));
950
951         maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
952         converterDefGB->setFocusProxy(convertersLW);
953 }
954
955
956 void PrefConverters::apply(LyXRC & rc) const
957 {
958         rc.use_converter_cache = cacheCB->isChecked();
959         rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
960 }
961
962
963 void PrefConverters::update(LyXRC const & rc)
964 {
965         cacheCB->setChecked(rc.use_converter_cache);
966         QString max_age;
967         max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
968         maxAgeLE->setText(max_age);
969         updateGui();
970 }
971
972
973 void PrefConverters::updateGui()
974 {
975         // save current selection
976         QString current = converterFromCO->currentText()
977                 + " -> " + converterToCO->currentText();
978
979         converterFromCO->clear();
980         converterToCO->clear();
981
982         Formats::const_iterator cit = form_->formats().begin();
983         Formats::const_iterator end = form_->formats().end();
984         for (; cit != end; ++cit) {
985                 converterFromCO->addItem(toqstr(cit->prettyname()));
986                 converterToCO->addItem(toqstr(cit->prettyname()));
987         }
988
989         // currentRowChanged(int) is also triggered when updating the listwidget
990         // block signals to avoid unnecessary calls to switch_converter()
991         convertersLW->blockSignals(true);
992         convertersLW->clear();
993
994         Converters::const_iterator ccit = form_->converters().begin();
995         Converters::const_iterator cend = form_->converters().end();
996         for (; ccit != cend; ++ccit) {
997                 std::string const name =
998                         ccit->From->prettyname() + " -> " + ccit->To->prettyname();
999                 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1000                 new QListWidgetItem(toqstr(name), convertersLW, type);
1001         }
1002         convertersLW->sortItems(Qt::AscendingOrder);
1003         convertersLW->blockSignals(false);
1004
1005         // restore selection
1006         if (!current.isEmpty()) {
1007                 QList<QListWidgetItem *> const item =
1008                         convertersLW->findItems(current, Qt::MatchExactly);
1009                 if (item.size()>0)
1010                         convertersLW->setCurrentItem(item.at(0));
1011         }
1012
1013         // select first element if restoring failed
1014         if (convertersLW->currentRow() == -1)
1015                 convertersLW->setCurrentRow(0);
1016
1017         updateButtons();
1018 }
1019
1020
1021 void PrefConverters::switch_converter()
1022 {
1023         int const cnr = convertersLW->currentItem()->type();
1024         Converter const & c(form_->converters().get(cnr));
1025         converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1026         converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1027         converterED->setText(toqstr(c.command));
1028         converterFlagED->setText(toqstr(c.flags));
1029
1030         updateButtons();
1031 }
1032
1033
1034 void PrefConverters::converter_changed()
1035 {
1036         updateButtons();
1037 }
1038
1039
1040 void PrefConverters::updateButtons()
1041 {
1042         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1043         Format const & to(form_->formats().get(converterToCO->currentIndex()));
1044         int const sel = form_->converters().getNumber(from.name(), to.name());
1045         bool const known = !(sel < 0);
1046         bool const valid = !(converterED->text().isEmpty()
1047                 || from.name() == to.name());
1048
1049         int const cnr = convertersLW->currentItem()->type();
1050         Converter const & c(form_->converters().get(cnr));
1051         string const old_command = c.command;
1052         string const old_flag = c.flags;
1053         string const new_command(fromqstr(converterED->text()));
1054         string const new_flag(fromqstr(converterFlagED->text()));
1055
1056         bool modified = ((old_command != new_command) || (old_flag != new_flag));
1057
1058         converterModifyPB->setEnabled(valid && known && modified);
1059         converterNewPB->setEnabled(valid && !known);
1060         converterRemovePB->setEnabled(known);
1061
1062         maxAgeLE->setEnabled(cacheCB->isChecked());
1063         maxAgeLA->setEnabled(cacheCB->isChecked());
1064 }
1065
1066
1067 // FIXME: user must
1068 // specify unique from/to or it doesn't appear. This is really bad UI
1069 // this is why we can use the same function for both new and modify
1070 void PrefConverters::update_converter()
1071 {
1072         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1073         Format const & to(form_->formats().get(converterToCO->currentIndex()));
1074         string const flags = fromqstr(converterFlagED->text());
1075         string const command = fromqstr(converterED->text());
1076
1077         Converter const * old = form_->converters().getConverter(from.name(), to.name());
1078         form_->converters().add(from.name(), to.name(), command, flags);
1079         if (!old) {
1080                 form_->converters().updateLast(form_->formats());
1081         }
1082
1083         updateGui();
1084
1085         // Remove all files created by this converter from the cache, since
1086         // the modified converter might create different files.
1087         ConverterCache::get().remove_all(from.name(), to.name());
1088 }
1089
1090
1091 void PrefConverters::remove_converter()
1092 {
1093         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1094         Format const & to(form_->formats().get(converterToCO->currentIndex()));
1095         form_->converters().erase(from.name(), to.name());
1096
1097         updateGui();
1098
1099         // Remove all files created by this converter from the cache, since
1100         // a possible new converter might create different files.
1101         ConverterCache::get().remove_all(from.name(), to.name());
1102 }
1103
1104
1105 void PrefConverters::on_cacheCB_stateChanged(int state)
1106 {
1107         maxAgeLE->setEnabled(state == Qt::Checked);
1108         maxAgeLA->setEnabled(state == Qt::Checked);
1109         changed();
1110 }
1111
1112
1113 /////////////////////////////////////////////////////////////////////
1114 //
1115 // PrefCopiers
1116 //
1117 /////////////////////////////////////////////////////////////////////
1118
1119 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1120         : PrefModule(docstring(), _("Copiers"), form, parent)
1121 {
1122         setupUi(this);
1123
1124         connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1125         connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1126         connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1127         connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1128                 this, SLOT(switch_copierLB(int)));
1129         connect(copierFormatCO, SIGNAL(activated(int)),
1130                 this, SLOT(switch_copierCO(int)));
1131         connect(copierNewPB, SIGNAL(clicked()),
1132                 this, SIGNAL(changed()));
1133         connect(copierRemovePB, SIGNAL(clicked()),
1134                 this, SIGNAL(changed()));
1135         connect(copierModifyPB, SIGNAL(clicked()),
1136                 this, SIGNAL(changed()));
1137         connect(copierFormatCO, SIGNAL(activated(const QString &)),
1138                 this, SLOT(copiers_changed()));
1139         connect(copierED, SIGNAL(textChanged(const QString &)),
1140                 this, SLOT(copiers_changed()));
1141 }
1142
1143
1144 void PrefCopiers::apply(LyXRC & /*rc*/) const
1145 {
1146 }
1147
1148
1149 void PrefCopiers::update(LyXRC const & /*rc*/)
1150 {
1151         update();
1152 }
1153
1154
1155 void PrefCopiers::update()
1156 {
1157         // The choice widget
1158         // save current selection
1159         QString current = copierFormatCO->currentText();
1160         copierFormatCO->clear();
1161
1162         for (Formats::const_iterator it = form_->formats().begin(),
1163                      end = form_->formats().end();
1164              it != end; ++it) {
1165                 copierFormatCO->addItem(toqstr(it->prettyname()));
1166         }
1167
1168         // The browser widget
1169         AllCopiersLW->clear();
1170
1171         for (Movers::const_iterator it = form_->movers().begin(),
1172                      end = form_->movers().end();
1173              it != end; ++it) {
1174                 std::string const & command = it->second.command();
1175                 if (command.empty())
1176                         continue;
1177                 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1178                 AllCopiersLW->addItem(pretty);
1179         }
1180         AllCopiersLW->sortItems(Qt::AscendingOrder);
1181
1182         // restore selection
1183         if (!current.isEmpty()) {
1184                 QList<QListWidgetItem *> item =
1185                         AllCopiersLW->findItems(current, Qt::MatchExactly);
1186                 if (item.size()>0)
1187                         AllCopiersLW->setCurrentItem(item.at(0));
1188         }
1189         // select first element if restoring failed
1190         if (AllCopiersLW->currentRow() == -1)
1191                 AllCopiersLW->setCurrentRow(0);
1192 }
1193
1194
1195 namespace {
1196
1197 class SamePrettyName {
1198 public:
1199         SamePrettyName(string const & n) : pretty_name_(n) {}
1200
1201         bool operator()(Format const & fmt) const {
1202                 return fmt.prettyname() == pretty_name_;
1203         }
1204
1205 private:
1206         string const pretty_name_;
1207 };
1208
1209
1210 Format const * getFormat(std::string const & prettyname)
1211 {
1212         Formats::const_iterator it = formats.begin();
1213         Formats::const_iterator const end = formats.end();
1214         it = std::find_if(it, end, SamePrettyName(prettyname));
1215         return it == end ? 0 : &*it;
1216 }
1217
1218 } // namespace anon
1219
1220
1221 void PrefCopiers::switch_copierLB(int row)
1222 {
1223         if (row < 0)
1224                 return;
1225
1226         // FIXME UNICODE?
1227         std::string const browser_text =
1228                 fromqstr(AllCopiersLW->currentItem()->text());
1229         Format const * fmt = getFormat(browser_text);
1230         if (fmt == 0)
1231                 return;
1232
1233         QString const gui_name = toqstr(fmt->prettyname());
1234         QString const command = toqstr(form_->movers().command(fmt->name()));
1235
1236         copierED->clear();
1237         int const combo_size = copierFormatCO->count();
1238         for (int i = 0; i < combo_size; ++i) {
1239                 QString const text = copierFormatCO->itemText(i);
1240                 if (text == gui_name) {
1241                         copierFormatCO->setCurrentIndex(i);
1242                         copierED->setText(command);
1243                         break;
1244                 }
1245         }
1246         updateButtons();
1247 }
1248
1249
1250 void PrefCopiers::switch_copierCO(int row)
1251 {
1252         if (row<0)
1253                 return;
1254
1255         std::string const combo_text =
1256                 fromqstr(copierFormatCO->currentText());
1257         Format const * fmt = getFormat(combo_text);
1258         if (fmt == 0)
1259                 return;
1260
1261         QString const command = toqstr(form_->movers().command(fmt->name()));
1262         copierED->setText(command);
1263
1264         QListWidgetItem * const index = AllCopiersLW->currentItem();
1265         if (index >= 0)
1266                 AllCopiersLW->setItemSelected(index, false);
1267
1268         QString const gui_name = toqstr(fmt->prettyname());
1269         int const browser_size = AllCopiersLW->count();
1270         for (int i = 0; i < browser_size; ++i) {
1271                 QString const text = AllCopiersLW->item(i)->text();
1272                 if (text == gui_name) {
1273                         QListWidgetItem * item = AllCopiersLW->item(i);
1274                         AllCopiersLW->setItemSelected(item, true);
1275                         break;
1276                 }
1277         }
1278 }
1279
1280
1281 void PrefCopiers::copiers_changed()
1282 {
1283         updateButtons();
1284 }
1285
1286
1287 void PrefCopiers::updateButtons()
1288 {
1289         QString selected = copierFormatCO->currentText();
1290
1291         bool known = false;
1292         for (int i = 0; i < AllCopiersLW->count(); ++i) {
1293                 if (AllCopiersLW->item(i)->text() == selected)
1294                         known = true;
1295         }
1296
1297         bool const valid = !copierED->text().isEmpty();
1298
1299         Format const * fmt = getFormat(fromqstr(selected));
1300         string const old_command = form_->movers().command(fmt->name());
1301         string const new_command(fromqstr(copierED->text()));
1302
1303         bool modified = (old_command != new_command);
1304
1305         copierModifyPB->setEnabled(valid && known && modified);
1306         copierNewPB->setEnabled(valid && !known);
1307         copierRemovePB->setEnabled(known);
1308 }
1309
1310
1311 void PrefCopiers::new_copier()
1312 {
1313         std::string const combo_text =
1314                 fromqstr(copierFormatCO->currentText());
1315         Format const * fmt = getFormat(combo_text);
1316         if (fmt == 0)
1317                 return;
1318
1319         string const command = fromqstr(copierED->text());
1320         if (command.empty())
1321                 return;
1322
1323         form_->movers().set(fmt->name(), command);
1324
1325         update();
1326         int const last = AllCopiersLW->count() - 1;
1327         AllCopiersLW->setCurrentRow(last);
1328
1329         updateButtons();
1330 }
1331
1332
1333 void PrefCopiers::modify_copier()
1334 {
1335         std::string const combo_text =
1336                 fromqstr(copierFormatCO->currentText());
1337         Format const * fmt = getFormat(combo_text);
1338         if (fmt == 0)
1339                 return;
1340
1341         string const command = fromqstr(copierED->text());
1342         form_->movers().set(fmt->name(), command);
1343
1344         update();
1345         updateButtons();
1346 }
1347
1348
1349 void PrefCopiers::remove_copier()
1350 {
1351         std::string const combo_text =
1352                 fromqstr(copierFormatCO->currentText());
1353         Format const * fmt = getFormat(combo_text);
1354         if (fmt == 0)
1355                 return;
1356
1357         string const & fmt_name = fmt->name();
1358         form_->movers().set(fmt_name, string());
1359
1360         update();
1361         updateButtons();
1362 }
1363
1364
1365
1366 /////////////////////////////////////////////////////////////////////
1367 //
1368 // PrefFileformats
1369 //
1370 /////////////////////////////////////////////////////////////////////
1371
1372 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1373         : PrefModule(docstring(), _("File formats"), form, parent)
1374 {
1375         setupUi(this);
1376
1377         connect(formatNewPB, SIGNAL(clicked()),
1378                 this, SLOT(new_format()));
1379         connect(formatRemovePB, SIGNAL(clicked()),
1380                 this, SLOT(remove_format()));
1381         connect(formatModifyPB, SIGNAL(clicked()),
1382                 this, SLOT(modify_format()));
1383         connect(formatsLW, SIGNAL(currentRowChanged(int)),
1384                 this, SLOT(switch_format(int)));
1385         connect(formatED, SIGNAL(textChanged(const QString&)),
1386                 this, SLOT(fileformat_changed()));
1387         connect(guiNameED, SIGNAL(textChanged(const QString&)),
1388                 this, SLOT(fileformat_changed()));
1389         connect(shortcutED, SIGNAL(textChanged(const QString&)),
1390                 this, SLOT(fileformat_changed()));
1391         connect(extensionED, SIGNAL(textChanged(const QString&)),
1392                 this, SLOT(fileformat_changed()));
1393         connect(viewerED, SIGNAL(textChanged(const QString&)),
1394                 this, SLOT(fileformat_changed()));
1395         connect(editorED, SIGNAL(textChanged(const QString&)),
1396                 this, SLOT(fileformat_changed()));
1397         connect(documentCB, SIGNAL(clicked()),
1398                 this, SLOT(fileformat_changed()));
1399         connect(vectorCB, SIGNAL(clicked()),
1400                 this, SLOT(fileformat_changed()));
1401         connect(formatNewPB, SIGNAL(clicked()),
1402                 this, SIGNAL(changed()));
1403         connect(formatRemovePB, SIGNAL(clicked()),
1404                 this, SIGNAL(changed()));
1405         connect(formatModifyPB, SIGNAL(clicked()),
1406                 this, SIGNAL(changed()));
1407 }
1408
1409
1410 void PrefFileformats::apply(LyXRC & /*rc*/) const
1411 {
1412 }
1413
1414
1415 void PrefFileformats::update(LyXRC const & /*rc*/)
1416 {
1417         update();
1418 }
1419
1420
1421 void PrefFileformats::update()
1422 {
1423         // save current selection
1424         QString current = guiNameED->text();
1425
1426         // update listwidget with formats
1427         formatsLW->blockSignals(true);
1428         formatsLW->clear();
1429         Formats::const_iterator cit = form_->formats().begin();
1430         Formats::const_iterator end = form_->formats().end();
1431         for (; cit != end; ++cit) {
1432                 new QListWidgetItem(toqstr(cit->prettyname()),
1433                                                         formatsLW,
1434                                                         form_->formats().getNumber(cit->name()) );
1435         }
1436         formatsLW->sortItems(Qt::AscendingOrder);
1437         formatsLW->blockSignals(false);
1438
1439         // restore selection
1440         if (!current.isEmpty()) {
1441                 QList<QListWidgetItem *>  item = formatsLW->findItems(current, Qt::MatchExactly);
1442                 if (item.size()>0)
1443                         formatsLW->setCurrentItem(item.at(0));
1444         }
1445         // select first element if restoring failed
1446         if (formatsLW->currentRow() == -1)
1447                 formatsLW->setCurrentRow(0);
1448 }
1449
1450
1451 void PrefFileformats::switch_format(int nr)
1452 {
1453         int const ftype = formatsLW->item(nr)->type();
1454         Format const f = form_->formats().get(ftype);
1455
1456         formatED->setText(toqstr(f.name()));
1457         guiNameED->setText(toqstr(f.prettyname()));
1458         extensionED->setText(toqstr(f.extension()));
1459         shortcutED->setText(toqstr(f.shortcut()));
1460         viewerED->setText(toqstr(f.viewer()));
1461         editorED->setText(toqstr(f.editor()));
1462         documentCB->setChecked((f.documentFormat()));
1463         vectorCB->setChecked((f.vectorFormat()));
1464
1465         updateButtons();
1466 }
1467
1468
1469 void PrefFileformats::fileformat_changed()
1470 {
1471         updateButtons();
1472 }
1473
1474
1475 void PrefFileformats::updateButtons()
1476 {
1477         QString const format = formatED->text();
1478         QString const gui_name = guiNameED->text();
1479         int const sel = form_->formats().getNumber(fromqstr(format));
1480         bool gui_name_known = false;
1481         int where = sel;
1482         for (int i = 0; i < formatsLW->count(); ++i) {
1483                 if (formatsLW->item(i)->text() == gui_name) {
1484                         gui_name_known = true;
1485                         where = formatsLW->item(i)->type();
1486                 }
1487         }
1488
1489         // assure that a gui name cannot be chosen twice
1490         bool const known_otherwise = gui_name_known && (where != sel);
1491
1492         bool const known = !(sel < 0);
1493         bool const valid = (!formatED->text().isEmpty()
1494                 && !guiNameED->text().isEmpty());
1495
1496         int const ftype = formatsLW->currentItem()->type();
1497         Format const & f(form_->formats().get(ftype));
1498         string const old_pretty(f.prettyname());
1499         string const old_shortcut(f.shortcut());
1500         string const old_extension(f.extension());
1501         string const old_viewer(f.viewer());
1502         string const old_editor(f.editor());
1503         bool const old_document(f.documentFormat());
1504         bool const old_vector(f.vectorFormat());
1505
1506         string const new_pretty(fromqstr(gui_name));
1507         string const new_shortcut(fromqstr(shortcutED->text()));
1508         string const new_extension(fromqstr(extensionED->text()));
1509         string const new_viewer(fromqstr(viewerED->text()));
1510         string const new_editor(fromqstr(editorED->text()));
1511         bool const new_document(documentCB->isChecked());
1512         bool const new_vector(vectorCB->isChecked());
1513
1514         bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1515                 || (old_extension != new_extension) || (old_viewer != new_viewer)
1516                 || old_editor != new_editor || old_document != new_document
1517                 || old_vector != new_vector);
1518
1519         formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1520         formatNewPB->setEnabled(valid && !known && !gui_name_known);
1521         formatRemovePB->setEnabled(known);
1522 }
1523
1524
1525 void PrefFileformats::new_format()
1526 {
1527         string const name = fromqstr(formatED->text());
1528         string const prettyname = fromqstr(guiNameED->text());
1529         string const extension = fromqstr(extensionED->text());
1530         string const shortcut = fromqstr(shortcutED->text());
1531         string const viewer = fromqstr(viewerED->text());
1532         string const editor = fromqstr(editorED->text());
1533         int flags = Format::none;
1534         if (documentCB->isChecked())
1535                 flags |= Format::document;
1536         if (vectorCB->isChecked())
1537                 flags |= Format::vector;
1538
1539         form_->formats().add(name, extension, prettyname, shortcut, viewer,
1540                              editor, flags);
1541         form_->formats().sort();
1542         form_->converters().update(form_->formats());
1543
1544         update();
1545         updateButtons();
1546         formatsChanged();
1547 }
1548
1549
1550 void PrefFileformats::modify_format()
1551 {
1552         int const current_item = formatsLW->currentItem()->type();
1553         Format const & oldformat = form_->formats().get(current_item);
1554         form_->formats().erase(oldformat.name());
1555
1556         new_format();
1557 }
1558
1559
1560 void PrefFileformats::remove_format()
1561 {
1562         int const nr = formatsLW->currentItem()->type();
1563         string const current_text = form_->formats().get(nr).name();
1564         if (form_->converters().formatIsUsed(current_text)) {
1565                 Alert::error(_("Format in use"),
1566                              _("Cannot remove a Format used by a Converter. "
1567                                             "Remove the converter first."));
1568                 return;
1569         }
1570
1571         form_->formats().erase(current_text);
1572         form_->converters().update(form_->formats());
1573
1574         update();
1575         updateButtons();
1576         formatsChanged();
1577 }
1578
1579
1580 /////////////////////////////////////////////////////////////////////
1581 //
1582 // PrefLanguage
1583 //
1584 /////////////////////////////////////////////////////////////////////
1585
1586 PrefLanguage::PrefLanguage(QWidget * parent)
1587         : PrefModule(_(LanguageSettings), _("Language"), 0, parent)
1588 {
1589         setupUi(this);
1590
1591         connect(rtlCB, SIGNAL(clicked()),
1592                 this, SIGNAL(changed()));
1593         connect(markForeignCB, SIGNAL(clicked()),
1594                 this, SIGNAL(changed()));
1595         connect(autoBeginCB, SIGNAL(clicked()),
1596                 this, SIGNAL(changed()));
1597         connect(autoEndCB, SIGNAL(clicked()),
1598                 this, SIGNAL(changed()));
1599         connect(useBabelCB, SIGNAL(clicked()),
1600                 this, SIGNAL(changed()));
1601         connect(globalCB, SIGNAL(clicked()),
1602                 this, SIGNAL(changed()));
1603         connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1604                 this, SIGNAL(changed()));
1605         connect(startCommandED, SIGNAL(textChanged(const QString&)),
1606                 this, SIGNAL(changed()));
1607         connect(endCommandED, SIGNAL(textChanged(const QString&)),
1608                 this, SIGNAL(changed()));
1609         connect(defaultLanguageCO, SIGNAL(activated(int)),
1610                 this, SIGNAL(changed()));
1611
1612         defaultLanguageCO->clear();
1613
1614         // store the lang identifiers for later
1615         std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
1616         lang_ = getSecond(langs);
1617
1618         std::vector<LanguagePair>::const_iterator lit  = langs.begin();
1619         std::vector<LanguagePair>::const_iterator lend = langs.end();
1620         for (; lit != lend; ++lit) {
1621                 defaultLanguageCO->addItem(toqstr(lit->first));
1622         }
1623 }
1624
1625
1626 void PrefLanguage::apply(LyXRC & rc) const
1627 {
1628         // FIXME: remove rtl_support bool
1629         rc.rtl_support = rtlCB->isChecked();
1630         rc.mark_foreign_language = markForeignCB->isChecked();
1631         rc.language_auto_begin = autoBeginCB->isChecked();
1632         rc.language_auto_end = autoEndCB->isChecked();
1633         rc.language_use_babel = useBabelCB->isChecked();
1634         rc.language_global_options = globalCB->isChecked();
1635         rc.language_package = fromqstr(languagePackageED->text());
1636         rc.language_command_begin = fromqstr(startCommandED->text());
1637         rc.language_command_end = fromqstr(endCommandED->text());
1638         rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1639 }
1640
1641
1642 void PrefLanguage::update(LyXRC const & rc)
1643 {
1644         // FIXME: remove rtl_support bool
1645         rtlCB->setChecked(rc.rtl_support);
1646         markForeignCB->setChecked(rc.mark_foreign_language);
1647         autoBeginCB->setChecked(rc.language_auto_begin);
1648         autoEndCB->setChecked(rc.language_auto_end);
1649         useBabelCB->setChecked(rc.language_use_babel);
1650         globalCB->setChecked(rc.language_global_options);
1651         languagePackageED->setText(toqstr(rc.language_package));
1652         startCommandED->setText(toqstr(rc.language_command_begin));
1653         endCommandED->setText(toqstr(rc.language_command_end));
1654
1655         int const pos = int(findPos_helper(lang_, rc.default_language));
1656         defaultLanguageCO->setCurrentIndex(pos);
1657 }
1658
1659
1660 /////////////////////////////////////////////////////////////////////
1661 //
1662 // PrefPrinter
1663 //
1664 /////////////////////////////////////////////////////////////////////
1665
1666 PrefPrinter::PrefPrinter(QWidget * parent)
1667         : PrefModule(_(Outputs), _("Printer"), 0, parent)
1668 {
1669         setupUi(this);
1670
1671         connect(printerAdaptCB, SIGNAL(clicked()),
1672                 this, SIGNAL(changed()));
1673         connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1674                 this, SIGNAL(changed()));
1675         connect(printerNameED, SIGNAL(textChanged(const QString&)),
1676                 this, SIGNAL(changed()));
1677         connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1678                 this, SIGNAL(changed()));
1679         connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1680                 this, SIGNAL(changed()));
1681         connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1682                 this, SIGNAL(changed()));
1683         connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1684                 this, SIGNAL(changed()));
1685         connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1686                 this, SIGNAL(changed()));
1687         connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1688                 this, SIGNAL(changed()));
1689         connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1690                 this, SIGNAL(changed()));
1691         connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1692                 this, SIGNAL(changed()));
1693         connect(printerOddED, SIGNAL(textChanged(const QString&)),
1694                 this, SIGNAL(changed()));
1695         connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1696                 this, SIGNAL(changed()));
1697         connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1698                 this, SIGNAL(changed()));
1699         connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1700                 this, SIGNAL(changed()));
1701         connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1702                 this, SIGNAL(changed()));
1703         connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1704                 this, SIGNAL(changed()));
1705         connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1706                 this, SIGNAL(changed()));
1707 }
1708
1709
1710 void PrefPrinter::apply(LyXRC & rc) const
1711 {
1712         rc.print_adapt_output = printerAdaptCB->isChecked();
1713         rc.print_command = fromqstr(printerCommandED->text());
1714         rc.printer = fromqstr(printerNameED->text());
1715
1716         rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1717         rc.print_copies_flag = fromqstr(printerCopiesED->text());
1718         rc.print_reverse_flag = fromqstr(printerReverseED->text());
1719         rc.print_to_printer = fromqstr(printerToPrinterED->text());
1720         rc.print_file_extension = fromqstr(printerExtensionED->text());
1721         rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1722         rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1723         rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1724         rc.print_oddpage_flag = fromqstr(printerOddED->text());
1725         rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1726         rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1727         rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1728         rc.print_extra_options = fromqstr(printerExtraED->text());
1729         rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1730         rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1731 }
1732
1733
1734 void PrefPrinter::update(LyXRC const & rc)
1735 {
1736         printerAdaptCB->setChecked(rc.print_adapt_output);
1737         printerCommandED->setText(toqstr(rc.print_command));
1738         printerNameED->setText(toqstr(rc.printer));
1739
1740         printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1741         printerCopiesED->setText(toqstr(rc.print_copies_flag));
1742         printerReverseED->setText(toqstr(rc.print_reverse_flag));
1743         printerToPrinterED->setText(toqstr(rc.print_to_printer));
1744         printerExtensionED->setText(toqstr(rc.print_file_extension));
1745         printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1746         printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1747         printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1748         printerOddED->setText(toqstr(rc.print_oddpage_flag));
1749         printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1750         printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1751         printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1752         printerExtraED->setText(toqstr(rc.print_extra_options));
1753         printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1754         printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1755 }
1756
1757
1758 /////////////////////////////////////////////////////////////////////
1759 //
1760 // PrefUserInterface
1761 //
1762 /////////////////////////////////////////////////////////////////////
1763
1764 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1765         : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1766 {
1767         setupUi(this);
1768
1769         connect(autoSaveCB, SIGNAL(toggled(bool)),
1770                 autoSaveLA, SLOT(setEnabled(bool)));
1771         connect(autoSaveCB, SIGNAL(toggled(bool)),
1772                 autoSaveSB, SLOT(setEnabled(bool)));
1773         connect(autoSaveCB, SIGNAL(toggled(bool)),
1774                 TextLabel1, SLOT(setEnabled(bool)));
1775         connect(uiFilePB, SIGNAL(clicked()),
1776                 this, SLOT(select_ui()));
1777         connect(bindFilePB, SIGNAL(clicked()),
1778                 this, SLOT(select_bind()));
1779         connect(uiFileED, SIGNAL(textChanged(const QString &)),
1780                 this, SIGNAL(changed()));
1781         connect(bindFileED, SIGNAL(textChanged(const QString &)),
1782                 this, SIGNAL(changed()));
1783         connect(restoreCursorCB, SIGNAL(clicked()),
1784                 this, SIGNAL(changed()));
1785         connect(loadSessionCB, SIGNAL(clicked()),
1786                 this, SIGNAL(changed()));
1787         connect(loadWindowSizeCB, SIGNAL(clicked()),
1788                 this, SIGNAL(changed()));
1789         connect(loadWindowLocationCB, SIGNAL(clicked()),
1790                 this, SIGNAL(changed()));
1791         connect(windowWidthSB, SIGNAL(valueChanged(int)),
1792                 this, SIGNAL(changed()));
1793         connect(windowHeightSB, SIGNAL(valueChanged(int)),
1794                 this, SIGNAL(changed()));
1795         connect(cursorFollowsCB, SIGNAL(clicked()),
1796                 this, SIGNAL(changed()));
1797         connect(autoSaveSB, SIGNAL(valueChanged(int)),
1798                 this, SIGNAL(changed()));
1799         connect(autoSaveCB, SIGNAL(clicked()),
1800                 this, SIGNAL(changed()));
1801         connect(lastfilesSB, SIGNAL(valueChanged(int)),
1802                 this, SIGNAL(changed()));
1803         lastfilesSB->setMaximum(maxlastfiles);
1804 }
1805
1806
1807 void PrefUserInterface::apply(LyXRC & rc) const
1808 {
1809         rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1810         rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1811         rc.use_lastfilepos = restoreCursorCB->isChecked();
1812         rc.load_session = loadSessionCB->isChecked();
1813         if (loadWindowSizeCB->isChecked()) {
1814                 rc.geometry_width = 0;
1815                 rc.geometry_height = 0;
1816         } else {
1817                 rc.geometry_width = windowWidthSB->value();
1818                 rc.geometry_height = windowHeightSB->value();
1819         }
1820         rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1821         rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1822         rc.autosave = autoSaveSB->value() * 60;
1823         rc.make_backup = autoSaveCB->isChecked();
1824         rc.num_lastfiles = lastfilesSB->value();
1825 }
1826
1827
1828 void PrefUserInterface::update(LyXRC const & rc)
1829 {
1830         uiFileED->setText(toqstr(external_path(rc.ui_file)));
1831         bindFileED->setText(toqstr(external_path(rc.bind_file)));
1832         restoreCursorCB->setChecked(rc.use_lastfilepos);
1833         loadSessionCB->setChecked(rc.load_session);
1834         bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1835         loadWindowSizeCB->setChecked(loadWindowSize);
1836         if (!loadWindowSize) {
1837                 windowWidthSB->setValue(rc.geometry_width);
1838                 windowHeightSB->setValue(rc.geometry_height);
1839         }
1840         loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1841         cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1842         // convert to minutes
1843         int mins(rc.autosave / 60);
1844         if (rc.autosave && !mins)
1845                 mins = 1;
1846         autoSaveSB->setValue(mins);
1847         autoSaveCB->setChecked(rc.make_backup);
1848         lastfilesSB->setValue(rc.num_lastfiles);
1849 }
1850
1851
1852
1853 void PrefUserInterface::select_ui()
1854 {
1855         docstring const name =
1856                 from_utf8(internal_path(fromqstr(uiFileED->text())));
1857         docstring file(form_->controller().browseUI(name));
1858         if (!file.empty())
1859                 uiFileED->setText(toqstr(file));
1860 }
1861
1862
1863 void PrefUserInterface::select_bind()
1864 {
1865         docstring const name =
1866                 from_utf8(internal_path(fromqstr(bindFileED->text())));
1867         docstring file(form_->controller().browsebind(name));
1868         if (!file.empty())
1869                 bindFileED->setText(toqstr(file));
1870 }
1871
1872
1873 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1874 {
1875         windowWidthLA->setDisabled(loadwindowsize);
1876         windowHeightLA->setDisabled(loadwindowsize);
1877         windowWidthSB->setDisabled(loadwindowsize);
1878         windowHeightSB->setDisabled(loadwindowsize);
1879 }
1880
1881
1882 PrefIdentity::PrefIdentity(QWidget * parent)
1883 : PrefModule(docstring(), _("Identity"), 0, parent)
1884 {
1885         setupUi(this);
1886
1887         connect(nameED, SIGNAL(textChanged(const QString&)),
1888                 this, SIGNAL(changed()));
1889         connect(emailED, SIGNAL(textChanged(const QString&)),
1890                 this, SIGNAL(changed()));
1891 }
1892
1893
1894 void PrefIdentity::apply(LyXRC & rc) const
1895 {
1896         rc.user_name = fromqstr(nameED->text());
1897         rc.user_email = fromqstr(emailED->text());
1898 }
1899
1900
1901 void PrefIdentity::update(LyXRC const & rc)
1902 {
1903         nameED->setText(toqstr(rc.user_name));
1904         emailED->setText(toqstr(rc.user_email));
1905 }
1906
1907
1908
1909 /////////////////////////////////////////////////////////////////////
1910 //
1911 // QPrefsDialog
1912 //
1913 /////////////////////////////////////////////////////////////////////
1914
1915 QPrefsDialog::QPrefsDialog(QPrefs * form)
1916         : form_(form)
1917 {
1918         setupUi(this);
1919         QDialog::setModal(false);
1920
1921         connect(savePB, SIGNAL(clicked()), form, SLOT(slotOK()));
1922         connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
1923         connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
1924         connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
1925
1926         add(new PrefUserInterface(form_));
1927         add(new PrefScreenFonts(form_));
1928         add(new PrefColors(form_));
1929         add(new PrefDisplay);
1930         add(new PrefKeyboard(form_));
1931
1932         add(new PrefPaths(form_));
1933
1934         add(new PrefIdentity);
1935
1936         add(new PrefLanguage);
1937         add(new PrefSpellchecker(form_));
1938
1939         add(new PrefPrinter);
1940         add(new PrefDate);
1941         add(new PrefPlaintext);
1942         add(new PrefLatex(form_));
1943
1944 #if defined(__CYGWIN__) || defined(_WIN32)
1945         add(new PrefCygwinPath);
1946 #endif
1947
1948
1949         PrefConverters * converters = new PrefConverters(form_);
1950         PrefFileformats * formats = new PrefFileformats(form_);
1951         connect(formats, SIGNAL(formatsChanged()),
1952                         converters, SLOT(updateGui()));
1953         add(converters);
1954         add(formats);
1955
1956         add(new PrefCopiers(form_));
1957
1958
1959         prefsPS->setCurrentPanel(_("User interface"));
1960 // FIXME: hack to work around resizing bug in Qt >= 4.2
1961 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1962 #if QT_VERSION >= 0x040200
1963         prefsPS->updateGeometry();
1964 #endif
1965
1966         form_->bcview().setOK(savePB);
1967         form_->bcview().setApply(applyPB);
1968         form_->bcview().setCancel(closePB);
1969         form_->bcview().setRestore(restorePB);
1970 }
1971
1972
1973 void QPrefsDialog::add(PrefModule * module)
1974 {
1975         BOOST_ASSERT(module);
1976
1977 //      if (module->category().empty())
1978 //              prefsPS->addPanel(module, module->title());
1979 //      else
1980                 prefsPS->addPanel(module, module->title(), module->category());
1981
1982         connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1983
1984         modules_.push_back(module);
1985 }
1986
1987 void QPrefsDialog::closeEvent(QCloseEvent * e)
1988 {
1989         form_->slotWMHide();
1990         e->accept();
1991 }
1992
1993
1994 void QPrefsDialog::change_adaptor()
1995 {
1996         form_->changed();
1997 }
1998
1999
2000 void QPrefsDialog::apply(LyXRC & rc) const
2001 {
2002         size_t end = modules_.size();
2003         for (size_t i = 0; i != end; ++i)
2004                 modules_[i]->apply(rc);
2005 }
2006
2007
2008 void QPrefsDialog::updateRc(LyXRC const & rc)
2009 {
2010         size_t const end = modules_.size();
2011         for (size_t i = 0; i != end; ++i)
2012                 modules_[i]->update(rc);
2013 }
2014
2015
2016 /////////////////////////////////////////////////////////////////////
2017 //
2018 // QPrefs
2019 //
2020 /////////////////////////////////////////////////////////////////////
2021
2022 typedef QController<ControlPrefs, QView<QPrefsDialog> > PrefsBase;
2023
2024 QPrefs::QPrefs(Dialog & parent)
2025         : PrefsBase(parent, _("Preferences"))
2026 {
2027 }
2028
2029 Converters & QPrefs::converters()
2030 {
2031         return controller().converters();
2032 }
2033
2034 Formats & QPrefs::formats()
2035 {
2036         return controller().formats();
2037 }
2038
2039 Movers & QPrefs::movers()
2040 {
2041         return controller().movers();
2042 }
2043
2044 void QPrefs::build_dialog()
2045 {
2046         dialog_.reset(new QPrefsDialog(this));
2047 }
2048
2049 void QPrefs::apply()
2050 {
2051         dialog_->apply(controller().rc());
2052 }
2053
2054 void QPrefs::update_contents()
2055 {
2056         dialog_->updateRc(controller().rc());
2057 }
2058
2059 } // namespace frontend
2060 } // namespace lyx
2061
2062 #include "QPrefs_moc.cpp"