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