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