]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QPrefsDialog.C
enable Font cache only for MacOSX and inline width() for other platform.
[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 #include "qt_helpers.h"
15
16 #include "GuiApplication.h"
17 #include "Qt2BC.h"
18 #include "qt_helpers.h"
19
20 #include "debug.h"
21 #include "session.h"
22 #include "LColor.h"
23 #include "lyxfont.h"
24
25 #include "support/lstrings.h"
26 #include "support/os.h"
27
28 #include "controllers/ControlPrefs.h"
29 #include "controllers/frnt_lang.h"
30 #include "controllers/helper_funcs.h"
31
32 #include "frontends/Alert.h"
33 #include "frontends/lyx_gui.h"
34
35 #include "QPrefsDialog.h"
36 #include "QPrefs.h"
37
38 #include "panelstack.h"
39 #include "qfontexample.h"
40
41 #include "gettext.h"
42 #include "LColor.h"
43
44 #include "controllers/ControlPrefs.h"
45
46 #include <QCheckBox>
47 #include <QColorDialog>
48 #include <QFontDatabase>
49 #include <QLineEdit>
50 #include <QPushButton>
51 #include <QSpinBox>
52 #include <QString>
53 #include <QValidator>
54 #include <QCloseEvent>
55
56 #include <boost/tuple/tuple.hpp>
57 #include <iomanip>
58 #include <sstream>
59
60 using lyx::support::compare_no_case;
61
62 using std::distance;
63 using std::endl;
64 using std::setfill;
65 using std::setw;
66 using std::string;
67 using std::ostringstream;
68 using std::pair;
69 using std::vector;
70
71
72 namespace lyx {
73 namespace frontend {
74
75 string const LookAndFeel = "Look and feel";
76 string const LanguageSettings = "Language settings";
77 string const Outputs = "Outputs";
78
79
80 // FIXME: move to helper_funcs.h
81 namespace {
82
83 template<class A>
84 typename std::vector<A>::size_type
85 findPos(std::vector<A> const & vec, A const & val)
86 {
87         typedef typename std::vector<A>::const_iterator Cit;
88
89         Cit it = std::find(vec.begin(), vec.end(), val);
90         if (it == vec.end())
91                 return 0;
92         return distance(vec.begin(), it);
93 }
94
95 void setComboxFont(QComboBox * cb, string const & family, string const & foundry)
96 {
97         string const name = makeFontName(family, foundry);
98         for (int i = 0; i < cb->count(); ++i) {
99                 if (fromqstr(cb->itemText(i)) == name) {
100                         cb->setCurrentIndex(i);
101                         return;
102                 }
103         }
104
105         // Try matching without foundry name
106
107         // We count in reverse in order to prefer the Xft foundry
108         for (int i = cb->count() - 1; i >= 0; --i) {
109                 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
110                 if (compare_no_case(tmp.first, family) == 0) {
111                         cb->setCurrentIndex(i);
112                         return;
113                 }
114         }
115
116         // family alone can contain e.g. "Helvetica [Adobe]"
117         pair<string, string> tmpfam = parseFontName(family);
118
119         // We count in reverse in order to prefer the Xft foundry
120         for (int i = cb->count() - 1; i >= 0; --i) {
121                 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
122                 if (compare_no_case(tmp.first, tmpfam.first) == 0) {
123                         cb->setCurrentIndex(i);
124                         return;
125                 }
126         }
127
128         // Bleh, default fonts, and the names couldn't be found. Hack
129         // for bug 1063. Qt makes baby Jesus cry.
130
131         QFont font;
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(lyx::to_utf8(_(Outputs)), lyx::to_utf8(_("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(lyx::to_utf8(_(Outputs)), lyx::to_utf8(_("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(lyx::to_utf8(_(LookAndFeel)), lyx::to_utf8(_("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(fromqstr(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(lyx::to_utf8(_(Outputs)), lyx::to_utf8(_("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(lyx::to_utf8(_(LookAndFeel)), lyx::to_utf8(_("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(lyx::to_utf8(_(LookAndFeel)), lyx::to_utf8(_("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(lyx::to_utf8(_(Outputs)), lyx::to_utf8(_("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(lyx::to_utf8(_(LookAndFeel)), lyx::to_utf8(_("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(string(), lyx::to_utf8(_("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 // NB: the lyx::to_utf8(_() is OK here because it gets passed back and we toqstr()) them
705
706 void PrefPaths::select_templatedir()
707 {
708         string file(form_->controller().browsedir(fromqstr(templateDirED->text()), lyx::to_utf8(_("Select a document templates directory"))));
709         if (!file.empty())
710                 templateDirED->setText(toqstr(file));
711 }
712
713
714 void PrefPaths::select_tempdir()
715 {
716         string file(form_->controller().browsedir(fromqstr(tempDirED->text()), lyx::to_utf8(_("Select a temporary directory"))));
717         if (!file.empty())
718                 tempDirED->setText(toqstr(file));
719 }
720
721
722 void PrefPaths::select_backupdir()
723 {
724         string file(form_->controller().browsedir(fromqstr(backupDirED->text()), lyx::to_utf8(_("Select a backups directory"))));
725         if (!file.empty())
726                 backupDirED->setText(toqstr(file));
727 }
728
729
730 void PrefPaths::select_workingdir()
731 {
732         string file(form_->controller().browsedir(fromqstr(workingDirED->text()), lyx::to_utf8(_("Select a document directory"))));
733         if (!file.empty())
734                 workingDirED->setText(toqstr(file));
735 }
736
737
738 void PrefPaths::select_lyxpipe()
739 {
740         string file(form_->controller().browse(fromqstr(lyxserverDirED->text()), lyx::to_utf8(_("Give a filename for the LyX server pipe"))));
741         if (!file.empty())
742                 lyxserverDirED->setText(toqstr(file));
743 }
744
745
746 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
747 : PrefModule(lyx::to_utf8(_(LanguageSettings)), lyx::to_utf8(_("Spellchecker")), form, parent)
748 {
749         setupUi(this);
750
751         connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
752 #if defined (USE_ISPELL)
753         connect(spellCommandCO, SIGNAL(activated(int)),
754                 this, SIGNAL(changed()));
755 #else
756         spellCommandCO->setEnabled(false);
757 #endif
758         connect(altLanguageED, SIGNAL(textChanged(const QString&)),
759                 this, SIGNAL(changed()));
760         connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
761                 this, SIGNAL(changed()));
762         connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
763                 this, SIGNAL(changed()));
764         connect(compoundWordCB, SIGNAL(toggled(bool)),
765                 this, SIGNAL(changed()));
766         connect(inputEncodingCB, SIGNAL(toggled(bool)),
767                 this, SIGNAL(changed()));
768
769         spellCommandCO->addItem(qt_("ispell"));
770         spellCommandCO->addItem(qt_("aspell"));
771         spellCommandCO->addItem(qt_("hspell"));
772 #ifdef USE_PSPELL
773         spellCommandCO->addItem(qt_("pspell (library)"));
774 #else
775 #ifdef USE_ASPELL
776         spellCommandCO->addItem(qt_("aspell (library)"));
777 #endif
778 #endif
779 }
780
781
782 void PrefSpellchecker::apply(LyXRC & rc) const
783 {
784         switch (spellCommandCO->currentIndex()) {
785                 case 0:
786                 case 1:
787                 case 2:
788                         rc.use_spell_lib = false;
789                         rc.isp_command = fromqstr(spellCommandCO->currentText());
790                         break;
791                 case 3:
792                         rc.use_spell_lib = true;
793                         break;
794         }
795
796         // FIXME: remove isp_use_alt_lang
797         rc.isp_alt_lang = fromqstr(altLanguageED->text());
798         rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
799         // FIXME: remove isp_use_esc_chars
800         rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
801         rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
802         // FIXME: remove isp_use_pers_dict
803         rc.isp_pers_dict = internal_path(persDictionaryED->text());
804         rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
805         rc.isp_accept_compound = compoundWordCB->isChecked();
806         rc.isp_use_input_encoding = inputEncodingCB->isChecked();
807 }
808
809
810 void PrefSpellchecker::update(LyXRC const & rc)
811 {
812         spellCommandCO->setCurrentIndex(0);
813
814         if (rc.isp_command == "ispell") {
815                 spellCommandCO->setCurrentIndex(0);
816         } else if (rc.isp_command == "aspell") {
817                 spellCommandCO->setCurrentIndex(1);
818         } else if (rc.isp_command == "hspell") {
819                 spellCommandCO->setCurrentIndex(2);
820         }
821
822         if (rc.use_spell_lib) {
823 #if defined(USE_ASPELL) || defined(USE_PSPELL)
824                 spellCommandCO->setCurrentIndex(3);
825 #endif
826         }
827
828         // FIXME: remove isp_use_alt_lang
829         altLanguageED->setText(toqstr(rc.isp_alt_lang));
830         // FIXME: remove isp_use_esc_chars
831         escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
832         // FIXME: remove isp_use_pers_dict
833         persDictionaryED->setText(external_path(rc.isp_pers_dict));
834         compoundWordCB->setChecked(rc.isp_accept_compound);
835         inputEncodingCB->setChecked(rc.isp_use_input_encoding);
836 }
837
838
839 void PrefSpellchecker::select_dict()
840 {
841         string file(form_->controller().browsedict(fromqstr(persDictionaryED->text())));
842         if (!file.empty())
843                 persDictionaryED->setText(toqstr(file));
844 }
845
846
847 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
848 : PrefModule(string(), lyx::to_utf8(_("Converters")), form, parent)
849 {
850         setupUi(this);
851
852         connect(converterNewPB, SIGNAL(clicked()),
853                 this, SLOT(new_converter()));
854         connect(converterRemovePB, SIGNAL(clicked()),
855                 this, SLOT(remove_converter()));
856         connect(converterModifyPB, SIGNAL(clicked()),
857                 this, SLOT(modify_converter()));
858         connect(convertersLW, SIGNAL(currentRowChanged(int)),
859                 this, SLOT(switch_converter(int)));
860         connect(converterFromCO, SIGNAL(activated(const QString&)),
861                 this, SLOT(converter_changed()));
862         connect(converterToCO, SIGNAL(activated(const QString&)),
863                 this, SLOT(converter_changed()));
864         connect(converterED, SIGNAL(textChanged(const QString&)),
865                 this, SLOT(converter_changed()));
866         connect(converterFlagED, SIGNAL(textChanged(const QString&)),
867                 this, SLOT(converter_changed()));
868         connect(converterNewPB, SIGNAL(clicked()),
869                 this, SIGNAL(changed()));
870         connect(converterRemovePB, SIGNAL(clicked()),
871                 this, SIGNAL(changed()));
872         connect(converterModifyPB, SIGNAL(clicked()),
873                 this, SIGNAL(changed()));
874 }
875
876
877 void PrefConverters::apply(LyXRC & /*rc*/) const
878 {
879 }
880
881
882 void PrefConverters::update(LyXRC const & /*rc*/)
883 {
884         updateGui();
885 }
886
887
888 void PrefConverters::updateGui()
889 {
890         // save current selection
891         QString current = converterFromCO->currentText()
892                 + " -> " + converterToCO->currentText();
893
894         converterFromCO->clear();
895         converterToCO->clear();
896
897         Formats::const_iterator cit = form_->formats().begin();
898         Formats::const_iterator end = form_->formats().end();
899         for (; cit != end; ++cit) {
900                 converterFromCO->addItem(toqstr(cit->prettyname()));
901                 converterToCO->addItem(toqstr(cit->prettyname()));
902         }
903
904         convertersLW->clear();
905
906         Converters::const_iterator ccit = form_->converters().begin();
907         Converters::const_iterator cend = form_->converters().end();
908         for (; ccit != cend; ++ccit) {
909                 std::string const name = ccit->From->prettyname() + " -> "
910                                                                 + ccit->To->prettyname();
911                 new QListWidgetItem(toqstr(name), convertersLW,
912                                                         form_->converters().getNumber(ccit->From->name(), ccit->To->name()));
913         }
914         convertersLW->sortItems(Qt::AscendingOrder);
915
916         // restore selection
917         if (!current.isEmpty()) {
918                 QList<QListWidgetItem *> const item =
919                         convertersLW->findItems(current, Qt::MatchExactly);
920                 if (item.size()>0)
921                         convertersLW->setCurrentItem(item.at(0));
922         }
923         // select first element if restoring failed
924         if (convertersLW->currentRow() == -1)
925                 convertersLW->setCurrentRow(0);
926
927         updateButtons();
928 }
929
930
931 void PrefConverters::switch_converter(int nr)
932 {
933         if (nr<0)
934                 return;
935
936         int const cnr = convertersLW->currentItem()->type();
937         Converter const & c(form_->converters().get(cnr));
938         converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
939         converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
940         converterED->setText(toqstr(c.command));
941         converterFlagED->setText(toqstr(c.flags));
942
943         updateButtons();
944 }
945
946
947 void PrefConverters::converter_changed()
948 {
949         updateButtons();
950 }
951
952
953 void PrefConverters::updateButtons()
954 {
955         Format const & from(form_->formats().get(
956                 converterFromCO->currentIndex()));
957         Format const & to(form_->formats().get(
958                 converterToCO->currentIndex()));
959         int const sel = form_->converters().getNumber(from.name(), to.name());
960         bool const known = !(sel < 0);
961         bool const valid = !(converterED->text().isEmpty()
962                 || from.name() == to.name());
963
964         int const cnr = convertersLW->currentItem()->type();
965         Converter const & c(form_->converters().get(cnr));
966         string const old_command = c.command;
967         string const old_flag = c.flags;
968         string const new_command(fromqstr(converterED->text()));
969         string const new_flag(fromqstr(converterFlagED->text()));
970
971         bool modified = ((old_command != new_command) || (old_flag != new_flag));
972
973         converterModifyPB->setEnabled(valid && known && modified);
974         converterNewPB->setEnabled(valid && !known);
975         converterRemovePB->setEnabled(known);
976 }
977
978
979 // FIXME: user must
980 // specify unique from/to or it doesn't appear. This is really bad UI
981 void PrefConverters::new_converter()
982 {
983         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
984         Format const & to(form_->formats().get(converterToCO->currentIndex()));
985         string const command(fromqstr(converterED->text()));
986         string const flags(fromqstr(converterFlagED->text()));
987
988         Converter const * old = form_->converters().getConverter(from.name(), to.name());
989         form_->converters().add(from.name(), to.name(), command, flags);
990         if (!old) {
991                 form_->converters().updateLast(form_->formats());
992         }
993         updateGui();
994
995         QString const name = toqstr(from.name() + " -> " + to.name());
996         QList<QListWidgetItem *> const item =
997                 convertersLW->findItems(name, Qt::MatchExactly);
998         if (item.size()>0)
999                 convertersLW->setCurrentItem(item.at(0));
1000 }
1001
1002
1003 void PrefConverters::modify_converter()
1004 {
1005         QString const current_text =
1006                 convertersLW->currentItem()->text();
1007
1008         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1009         Format const & to(form_->formats().get(converterToCO->currentIndex()));
1010         string flags(fromqstr(converterFlagED->text()));
1011         string name(fromqstr(converterED->text()));
1012
1013         Converter const * old = form_->converters().getConverter(from.name(), to.name());
1014         form_->converters().add(from.name(), to.name(), name, flags);
1015         if (!old) {
1016                 form_->converters().updateLast(form_->formats());
1017         }
1018         updateGui();
1019
1020         QList<QListWidgetItem *> const item =
1021                 convertersLW->findItems(current_text, Qt::MatchExactly);
1022         if (item.size()>0)
1023                 convertersLW->setCurrentItem(item.at(0));
1024 }
1025
1026
1027 void PrefConverters::remove_converter()
1028 {
1029         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1030         Format const & to(form_->formats().get(converterToCO->currentIndex()));
1031         form_->converters().erase(from.name(), to.name());
1032         updateGui();
1033 }
1034
1035
1036 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1037 : PrefModule(string(), lyx::to_utf8(_("Copiers")), form, parent)
1038 {
1039         setupUi(this);
1040
1041         connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1042         connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1043         connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1044         connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1045                 this, SLOT(switch_copierLB(int)));
1046         connect(copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
1047         connect(copierNewPB, SIGNAL(clicked()),
1048                 this, SIGNAL(changed()));
1049         connect(copierRemovePB, SIGNAL(clicked()),
1050                 this, SIGNAL(changed()));
1051         connect(copierModifyPB, SIGNAL(clicked()),
1052                 this, SIGNAL(changed()));
1053         connect(copierFormatCO, SIGNAL(activated(const QString&)), this, SLOT(copiers_changed()));
1054         connect(copierED, SIGNAL(textChanged(const QString&)), this, SLOT(copiers_changed()));
1055 }
1056
1057
1058 void PrefCopiers::apply(LyXRC & /*rc*/) const
1059 {
1060 }
1061
1062
1063 void PrefCopiers::update(LyXRC const & /*rc*/)
1064 {
1065         update();
1066 }
1067
1068
1069 void PrefCopiers::update()
1070 {
1071         // The choice widget
1072         // save current selection
1073         QString current = copierFormatCO->currentText();
1074         copierFormatCO->clear();
1075
1076         for (Formats::const_iterator it = form_->formats().begin(),
1077                      end = form_->formats().end();
1078              it != end; ++it) {
1079                 copierFormatCO->addItem(toqstr(it->prettyname()));
1080         }
1081
1082         // The browser widget
1083         AllCopiersLW->clear();
1084
1085         for (Movers::iterator it = form_->movers().begin(),
1086                      end = form_->movers().end();
1087              it != end; ++it) {
1088                 std::string const & command = it->second.command();
1089                 if (command.empty())
1090                         continue;
1091                 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1092                 AllCopiersLW->addItem(pretty);
1093         }
1094         AllCopiersLW->sortItems(Qt::AscendingOrder);
1095
1096         // restore selection
1097         if (!current.isEmpty()) {
1098                 QList<QListWidgetItem *> item =
1099                         AllCopiersLW->findItems(current, Qt::MatchExactly);
1100                 if (item.size()>0)
1101                         AllCopiersLW->setCurrentItem(item.at(0));
1102         }
1103         // select first element if restoring failed
1104         if (AllCopiersLW->currentRow() == -1)
1105                 AllCopiersLW->setCurrentRow(0);
1106 }
1107
1108
1109 namespace {
1110
1111 class SamePrettyName {
1112 public:
1113         SamePrettyName(string const & n) : pretty_name_(n) {}
1114
1115         bool operator()(::Format const & fmt) const {
1116                 return fmt.prettyname() == pretty_name_;
1117         }
1118
1119 private:
1120         string const pretty_name_;
1121 };
1122
1123
1124 Format const * getFormat(std::string const & prettyname)
1125 {
1126         Formats::const_iterator it = ::formats.begin();
1127         Formats::const_iterator const end = ::formats.end();
1128         it = std::find_if(it, end, SamePrettyName(prettyname));
1129         return it == end ? 0 : &*it;
1130 }
1131
1132 } // namespace anon
1133
1134
1135 void PrefCopiers::switch_copierLB(int row)
1136 {
1137         if (row<0)
1138                 return;
1139
1140         std::string const browser_text =
1141                 fromqstr(AllCopiersLW->currentItem()->text());
1142         Format const * fmt = getFormat(browser_text);
1143         if (fmt == 0)
1144                 return;
1145
1146         QString const gui_name = toqstr(fmt->prettyname());
1147         QString const command = toqstr(form_->movers().command(fmt->name()));
1148
1149         copierED->clear();
1150         int const combo_size = copierFormatCO->count();
1151         for (int i = 0; i < combo_size; ++i) {
1152                 QString const text = copierFormatCO->itemText(i);
1153                 if (text == gui_name) {
1154                         copierFormatCO->setCurrentIndex(i);
1155                         copierED->setText(command);
1156                         break;
1157                 }
1158         }
1159         updateButtons();
1160 }
1161
1162
1163 void PrefCopiers::switch_copierCO(int row)
1164 {
1165         if (row<0)
1166                 return;
1167
1168         std::string const combo_text =
1169                 fromqstr(copierFormatCO->currentText());
1170         Format const * fmt = getFormat(combo_text);
1171         if (fmt == 0)
1172                 return;
1173
1174         QString const command = toqstr(form_->movers().command(fmt->name()));
1175         copierED->setText(command);
1176
1177         QListWidgetItem * const index = AllCopiersLW->currentItem();
1178         if (index >= 0)
1179                 AllCopiersLW->setItemSelected(index, false);
1180
1181         QString const gui_name = toqstr(fmt->prettyname());
1182         int const browser_size = AllCopiersLW->count();
1183         for (int i = 0; i < browser_size; ++i) {
1184                 QString const text = AllCopiersLW->item(i)->text();
1185                 if (text == gui_name) {
1186                         QListWidgetItem * item = AllCopiersLW->item(i);
1187                         AllCopiersLW->setItemSelected(item, true);
1188                         break;
1189                 }
1190         }
1191 }
1192
1193
1194 void PrefCopiers::copiers_changed()
1195 {
1196         updateButtons();
1197 }
1198
1199
1200 void PrefCopiers::updateButtons()
1201 {
1202         QString selected = copierFormatCO->currentText();
1203
1204         bool known = false;
1205         for (int i = 0; i < AllCopiersLW->count(); ++i) {
1206                 if (AllCopiersLW->item(i)->text() == selected)
1207                         known = true;
1208         }
1209
1210         bool const valid = !copierED->text().isEmpty();
1211
1212         Format const * fmt = getFormat(fromqstr(selected));
1213         string const old_command = form_->movers().command(fmt->name());
1214         string const new_command(fromqstr(copierED->text()));
1215
1216         bool modified = (old_command != new_command);
1217
1218         copierModifyPB->setEnabled(valid && known && modified);
1219         copierNewPB->setEnabled(valid && !known);
1220         copierRemovePB->setEnabled(known);
1221 }
1222
1223
1224 void PrefCopiers::new_copier()
1225 {
1226         std::string const combo_text =
1227                 fromqstr(copierFormatCO->currentText());
1228         Format const * fmt = getFormat(combo_text);
1229         if (fmt == 0)
1230                 return;
1231
1232         string const command = fromqstr(copierED->text());
1233         if (command.empty())
1234                 return;
1235
1236         form_->movers().set(fmt->name(), command);
1237
1238         update();
1239         int const last = AllCopiersLW->count() - 1;
1240         AllCopiersLW->setCurrentRow(last);
1241
1242         updateButtons();
1243 }
1244
1245
1246 void PrefCopiers::modify_copier()
1247 {
1248         std::string const combo_text =
1249                 fromqstr(copierFormatCO->currentText());
1250         Format const * fmt = getFormat(combo_text);
1251         if (fmt == 0)
1252                 return;
1253
1254         string const command = fromqstr(copierED->text());
1255         form_->movers().set(fmt->name(), command);
1256
1257         update();
1258         updateButtons();
1259 }
1260
1261
1262 void PrefCopiers::remove_copier()
1263 {
1264         std::string const combo_text =
1265                 fromqstr(copierFormatCO->currentText());
1266         Format const * fmt = getFormat(combo_text);
1267         if (fmt == 0)
1268                 return;
1269
1270         string const & fmt_name = fmt->name();
1271         form_->movers().set(fmt_name, string());
1272
1273         update();
1274         updateButtons();
1275 }
1276
1277
1278
1279 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1280 : PrefModule(string(), lyx::to_utf8(_("File formats")), form, parent)
1281 {
1282         setupUi(this);
1283
1284         connect(formatNewPB, SIGNAL(clicked()), this, SLOT(new_format()));
1285         connect(formatRemovePB, SIGNAL(clicked()), this, SLOT(remove_format()));
1286         connect(formatModifyPB, SIGNAL(clicked()), this, SLOT(modify_format()));
1287         connect(formatsLW, SIGNAL(currentRowChanged(int)),
1288                 this, SLOT(switch_format(int)));
1289         connect(formatED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1290         connect(guiNameED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1291         connect(shortcutED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1292         connect(extensionED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1293         connect(viewerED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1294         connect(editorED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1295         connect(documentCB, SIGNAL(toggled(bool)), this, SLOT(fileformat_changed()));
1296         connect(vectorCB, SIGNAL(toggled(bool)), this, SLOT(fileformat_changed()));
1297         connect(formatNewPB, SIGNAL(clicked()),
1298                 this, SIGNAL(changed()));
1299         connect(formatRemovePB, SIGNAL(clicked()),
1300                 this, SIGNAL(changed()));
1301         connect(formatModifyPB, SIGNAL(clicked()),
1302                 this, SIGNAL(changed()));
1303 }
1304
1305
1306 void PrefFileformats::apply(LyXRC & /*rc*/) const
1307 {
1308 }
1309
1310
1311 void PrefFileformats::update(LyXRC const & /*rc*/)
1312 {
1313         update();
1314 }
1315
1316
1317 void PrefFileformats::update()
1318 {
1319         // save current selection
1320         QString current = guiNameED->text();
1321
1322         formatsLW->clear();
1323
1324         Formats::const_iterator cit = form_->formats().begin();
1325         Formats::const_iterator end = form_->formats().end();
1326         for (; cit != end; ++cit) {
1327                 new QListWidgetItem(toqstr(cit->prettyname()),
1328                                                         formatsLW,
1329                                                         form_->formats().getNumber(cit->name()) );
1330         }
1331         formatsLW->sortItems(Qt::AscendingOrder);
1332
1333         // restore selection
1334         if (!current.isEmpty()) {
1335                 QList<QListWidgetItem *>  item = formatsLW->findItems(current, Qt::MatchExactly);
1336                 if (item.size()>0)
1337                         formatsLW->setCurrentItem(item.at(0));
1338         }
1339         // select first element if restoring failed
1340         if (formatsLW->currentRow() == -1)
1341                 formatsLW->setCurrentRow(0);
1342 }
1343
1344
1345 void PrefFileformats::switch_format(int nr)
1346 {
1347         if (nr<0)
1348                 return;
1349
1350         int const ftype = formatsLW->item(nr)->type();
1351         Format const f(form_->formats().get(ftype));
1352
1353         formatED->setText(toqstr(f.name()));
1354         guiNameED->setText(toqstr(f.prettyname()));
1355         extensionED->setText(toqstr(f.extension()));
1356         shortcutED->setText(toqstr(f.shortcut()));
1357         viewerED->setText(toqstr(f.viewer()));
1358         editorED->setText(toqstr(f.editor()));
1359         documentCB->setChecked((f.documentFormat()));
1360         vectorCB->setChecked((f.vectorFormat()));
1361         formatRemovePB->setEnabled(
1362                 !form_->converters().formatIsUsed(f.name()));
1363
1364         updateButtons();
1365 }
1366
1367
1368 void PrefFileformats::fileformat_changed()
1369 {
1370         updateButtons();
1371 }
1372
1373
1374 void PrefFileformats::updateButtons()
1375 {
1376         QString const format = formatED->text();
1377         QString const gui_name = guiNameED->text();
1378         int const sel = form_->formats().getNumber(fromqstr(format));
1379         bool gui_name_known = false;
1380         int where = sel;
1381         for (int i = 0; i < formatsLW->count(); ++i) {
1382                 if (formatsLW->item(i)->text() == gui_name) {
1383                         gui_name_known = true;
1384                         where = formatsLW->item(i)->type();
1385                 }
1386         }
1387
1388         // assure that a gui name cannot be chosen twice
1389         bool const known_otherwise = gui_name_known && (where != sel);
1390
1391         bool const known = !(sel < 0);
1392         bool const valid = (!formatED->text().isEmpty()
1393                 && !guiNameED->text().isEmpty());
1394
1395         int const ftype = formatsLW->currentItem()->type();
1396         Format const & f(form_->formats().get(ftype));
1397         string const old_pretty(f.prettyname());
1398         string const old_shortcut(f.shortcut());
1399         string const old_extension(f.extension());
1400         string const old_viewer(f.viewer());
1401         string const old_editor(f.editor());
1402         bool const old_document(f.documentFormat());
1403         bool const old_vector(f.vectorFormat());
1404
1405         string const new_pretty(fromqstr(gui_name));
1406         string const new_shortcut(fromqstr(shortcutED->text()));
1407         string const new_extension(fromqstr(extensionED->text()));
1408         string const new_viewer(fromqstr(viewerED->text()));
1409         string const new_editor(fromqstr(editorED->text()));
1410         bool const new_document(documentCB->isChecked());
1411         bool const new_vector(vectorCB->isChecked());
1412
1413         bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1414                 || (old_extension != new_extension) || (old_viewer != new_viewer)
1415                 || old_editor != new_editor || old_document != new_document
1416                 || old_vector != new_vector);
1417
1418         formatModifyPB->setEnabled(
1419                 valid && known && modified && !known_otherwise);
1420         formatNewPB->setEnabled(valid && !known && !gui_name_known);
1421         formatRemovePB->setEnabled(known);
1422 }
1423
1424 void PrefFileformats::setConverters(PrefConverters * converters)
1425 {
1426         converters_ = converters;
1427 }
1428
1429 void PrefFileformats::new_format()
1430 {
1431         string const name = fromqstr(formatED->text());
1432         string const prettyname = fromqstr(guiNameED->text());
1433         string const extension = fromqstr(extensionED->text());
1434         string const shortcut = fromqstr(shortcutED->text());
1435         string const viewer = fromqstr(viewerED->text());
1436         string const editor = fromqstr(editorED->text());
1437         int flags = Format::none;
1438         if (documentCB->isChecked())
1439                 flags |= Format::document;
1440         if (vectorCB->isChecked())
1441                 flags |= Format::vector;
1442
1443         form_->formats().add(name, extension, prettyname, shortcut, viewer,
1444                              editor, flags);
1445         form_->formats().sort();
1446         update();
1447
1448         QList<QListWidgetItem *>  const item =
1449                 formatsLW->findItems(toqstr(prettyname), Qt::MatchExactly);
1450         if (item.size()>0)
1451                 formatsLW->setCurrentItem(item.at(0));
1452
1453         form_->converters().update(form_->formats());
1454
1455         converters_->updateGui();
1456         updateButtons();
1457 }
1458
1459
1460 void PrefFileformats::modify_format()
1461 {
1462         int const current_item = formatsLW->currentItem()->type();
1463         QString const current_text =
1464                 formatsLW->currentItem()->text();
1465
1466         Format const & oldformat(form_->formats().get(current_item));
1467         string const oldpretty(oldformat.prettyname());
1468         string const name(fromqstr(formatED->text()));
1469         form_->formats().erase(oldformat.name());
1470
1471         string const prettyname = fromqstr(guiNameED->text());
1472         string const extension = fromqstr(extensionED->text());
1473         string const shortcut = fromqstr(shortcutED->text());
1474         string const viewer = fromqstr(viewerED->text());
1475         string const editor = fromqstr(editorED->text());
1476         int flags = Format::none;
1477         if (documentCB->isChecked())
1478                 flags |= Format::document;
1479         if (vectorCB->isChecked())
1480                 flags |= Format::vector;
1481
1482         form_->formats().add(name, extension, prettyname, shortcut, viewer,
1483                              editor, flags);
1484         form_->formats().sort();
1485
1486         formatsLW->setUpdatesEnabled(false);
1487         update();
1488         formatsLW->setUpdatesEnabled(true);
1489         formatsLW->update();
1490
1491         converters_->updateGui();
1492         updateButtons();
1493
1494         QList<QListWidgetItem *>  const item =
1495                 formatsLW->findItems(current_text, Qt::MatchExactly);
1496         if (item.size()>0)
1497                 formatsLW->setCurrentItem(item.at(0));
1498 }
1499
1500
1501 void PrefFileformats::remove_format()
1502 {
1503         int const nr = formatsLW->currentItem()->type();
1504         if (nr < 0)
1505                 return;
1506         string const current_text = form_->formats().get(nr).name();
1507         if (form_->converters().formatIsUsed(current_text)) {
1508                 Alert::error(_("Format in use"),
1509                              _("Cannot remove a Format used by a Converter. "
1510                                             "Remove the converter first."));
1511                 return;
1512         }
1513
1514         form_->formats().erase(current_text);
1515         update();
1516         form_->converters().update(form_->formats());
1517
1518         converters_->updateGui();
1519         updateButtons();
1520 }
1521
1522
1523
1524 PrefLanguage::PrefLanguage(QWidget * parent)
1525 : PrefModule(string(), lyx::to_utf8(_("Language")), 0, parent)
1526 {
1527         setupUi(this);
1528
1529         connect(rtlCB, SIGNAL(toggled(bool)),
1530                 this, SIGNAL(changed()));
1531         connect(markForeignCB, SIGNAL(toggled(bool)),
1532                 this, SIGNAL(changed()));
1533         connect(autoBeginCB, SIGNAL(toggled(bool)),
1534                 this, SIGNAL(changed()));
1535         connect(autoEndCB, SIGNAL(toggled(bool)),
1536                 this, SIGNAL(changed()));
1537         connect(useBabelCB, SIGNAL(toggled(bool)),
1538                 this, SIGNAL(changed()));
1539         connect(globalCB, SIGNAL(toggled(bool)),
1540                 this, SIGNAL(changed()));
1541         connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1542                 this, SIGNAL(changed()));
1543         connect(startCommandED, SIGNAL(textChanged(const QString&)),
1544                 this, SIGNAL(changed()));
1545         connect(endCommandED, SIGNAL(textChanged(const QString&)),
1546                 this, SIGNAL(changed()));
1547         connect(defaultLanguageCO, SIGNAL(activated(int)),
1548                 this, SIGNAL(changed()));
1549
1550         defaultLanguageCO->clear();
1551
1552         // store the lang identifiers for later
1553         using lyx::frontend::LanguagePair;
1554         std::vector<LanguagePair> const langs =
1555                 lyx::frontend::getLanguageData(false);
1556         lang_ = getSecond(langs);
1557
1558         std::vector<LanguagePair>::const_iterator lit  = langs.begin();
1559         std::vector<LanguagePair>::const_iterator lend = langs.end();
1560         for (; lit != lend; ++lit) {
1561                 defaultLanguageCO->addItem(toqstr(lit->first));
1562         }
1563 }
1564
1565
1566 void PrefLanguage::apply(LyXRC & rc) const
1567 {
1568         // FIXME: remove rtl_support bool
1569         rc.rtl_support = rtlCB->isChecked();
1570         rc.mark_foreign_language = markForeignCB->isChecked();
1571         rc.language_auto_begin = autoBeginCB->isChecked();
1572         rc.language_auto_end = autoEndCB->isChecked();
1573         rc.language_use_babel = useBabelCB->isChecked();
1574         rc.language_global_options = globalCB->isChecked();
1575         rc.language_package = fromqstr(languagePackageED->text());
1576         rc.language_command_begin = fromqstr(startCommandED->text());
1577         rc.language_command_end = fromqstr(endCommandED->text());
1578         rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1579 }
1580
1581
1582 void PrefLanguage::update(LyXRC const & rc)
1583 {
1584         // FIXME: remove rtl_support bool
1585         rtlCB->setChecked(rc.rtl_support);
1586         markForeignCB->setChecked(rc.mark_foreign_language);
1587         autoBeginCB->setChecked(rc.language_auto_begin);
1588         autoEndCB->setChecked(rc.language_auto_end);
1589         useBabelCB->setChecked(rc.language_use_babel);
1590         globalCB->setChecked(rc.language_global_options);
1591         languagePackageED->setText(toqstr(rc.language_package));
1592         startCommandED->setText(toqstr(rc.language_command_begin));
1593         endCommandED->setText(toqstr(rc.language_command_end));
1594
1595         int const pos = int(findPos(lang_, rc.default_language));
1596         defaultLanguageCO->setCurrentIndex(pos);
1597 }
1598
1599
1600 PrefPrinter::PrefPrinter(QWidget * parent)
1601 : PrefModule(lyx::to_utf8(_(Outputs)), lyx::to_utf8(_("Printer")), 0, parent)
1602 {
1603         setupUi(this);
1604
1605         connect(printerAdaptCB, SIGNAL(toggled(bool)),
1606                 this, SIGNAL(changed()));
1607         connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1608                 this, SIGNAL(changed()));
1609         connect(printerNameED, SIGNAL(textChanged(const QString&)),
1610                 this, SIGNAL(changed()));
1611         connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1612                 this, SIGNAL(changed()));
1613         connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1614                 this, SIGNAL(changed()));
1615         connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1616                 this, SIGNAL(changed()));
1617         connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1618                 this, SIGNAL(changed()));
1619         connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1620                 this, SIGNAL(changed()));
1621         connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1622                 this, SIGNAL(changed()));
1623         connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1624                 this, SIGNAL(changed()));
1625         connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1626                 this, SIGNAL(changed()));
1627         connect(printerOddED, SIGNAL(textChanged(const QString&)),
1628                 this, SIGNAL(changed()));
1629         connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1630                 this, SIGNAL(changed()));
1631         connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1632                 this, SIGNAL(changed()));
1633         connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1634                 this, SIGNAL(changed()));
1635         connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1636                 this, SIGNAL(changed()));
1637         connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1638                 this, SIGNAL(changed()));
1639         connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1640                 this, SIGNAL(changed()));
1641 }
1642
1643
1644 void PrefPrinter::apply(LyXRC & rc) const
1645 {
1646         rc.print_adapt_output = printerAdaptCB->isChecked();
1647         rc.print_command = fromqstr(printerCommandED->text());
1648         rc.printer = fromqstr(printerNameED->text());
1649
1650         rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1651         rc.print_copies_flag = fromqstr(printerCopiesED->text());
1652         rc.print_reverse_flag = fromqstr(printerReverseED->text());
1653         rc.print_to_printer = fromqstr(printerToPrinterED->text());
1654         rc.print_file_extension = fromqstr(printerExtensionED->text());
1655         rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1656         rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1657         rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1658         rc.print_oddpage_flag = fromqstr(printerOddED->text());
1659         rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1660         rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1661         rc.print_to_file = internal_path(printerToFileED->text());
1662         rc.print_extra_options = fromqstr(printerExtraED->text());
1663         rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1664         rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1665 }
1666
1667
1668 void PrefPrinter::update(LyXRC const & rc)
1669 {
1670         printerAdaptCB->setChecked(rc.print_adapt_output);
1671         printerCommandED->setText(toqstr(rc.print_command));
1672         printerNameED->setText(toqstr(rc.printer));
1673
1674         printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1675         printerCopiesED->setText(toqstr(rc.print_copies_flag));
1676         printerReverseED->setText(toqstr(rc.print_reverse_flag));
1677         printerToPrinterED->setText(toqstr(rc.print_to_printer));
1678         printerExtensionED->setText(toqstr(rc.print_file_extension));
1679         printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1680         printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1681         printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1682         printerOddED->setText(toqstr(rc.print_oddpage_flag));
1683         printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1684         printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1685         printerToFileED->setText(external_path(rc.print_to_file));
1686         printerExtraED->setText(toqstr(rc.print_extra_options));
1687         printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1688         printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1689 }
1690
1691
1692 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1693 : PrefModule(lyx::to_utf8(_(LookAndFeel)), lyx::to_utf8(_("User interface")), form, parent)
1694 {
1695         setupUi(this);
1696
1697         connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveLA, SLOT( setEnabled(bool) ) );
1698         connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveSB, SLOT( setEnabled(bool) ) );
1699         connect(autoSaveCB, SIGNAL( toggled(bool) ), TextLabel1, SLOT( setEnabled(bool) ) );
1700         connect(uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
1701         connect(bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
1702         connect(uiFileED, SIGNAL(textChanged(const QString&)),
1703                 this, SIGNAL(changed()));
1704         connect(bindFileED, SIGNAL(textChanged(const QString&)),
1705                 this, SIGNAL(changed()));
1706         connect(restoreCursorCB, SIGNAL(toggled(bool)),
1707                 this, SIGNAL(changed()));
1708         connect(loadSessionCB, SIGNAL(toggled(bool)),
1709                 this, SIGNAL(changed()));
1710         connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1711                 this, SIGNAL(changed()));
1712         connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1713                 windowWidthLA, SLOT(setDisabled(bool)));
1714         connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1715                 windowHeightLA, SLOT(setDisabled(bool)));
1716         connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1717                 windowWidthSB, SLOT(setDisabled(bool)));
1718         connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1719                 windowHeightSB, SLOT(setDisabled(bool)));
1720         connect(loadWindowLocationCB, SIGNAL(toggled(bool)),
1721                 this, SIGNAL(changed()));
1722         connect(windowWidthSB, SIGNAL(valueChanged(int)),
1723                 this, SIGNAL(changed()));
1724         connect(windowHeightSB, SIGNAL(valueChanged(int)),
1725                 this, SIGNAL(changed()));
1726         connect(cursorFollowsCB, SIGNAL(toggled(bool)),
1727                 this, SIGNAL(changed()));
1728         connect(autoSaveSB, SIGNAL(valueChanged(int)),
1729                 this, SIGNAL(changed()));
1730         connect(autoSaveCB, SIGNAL(toggled(bool)),
1731                 this, SIGNAL(changed()));
1732         connect(lastfilesSB, SIGNAL(valueChanged(int)),
1733                 this, SIGNAL(changed()));
1734         lastfilesSB->setMaximum(maxlastfiles);
1735 }
1736
1737
1738 void PrefUserInterface::apply(LyXRC & rc) const
1739 {
1740         rc.ui_file = internal_path(uiFileED->text());
1741         rc.bind_file = internal_path(bindFileED->text());
1742         rc.use_lastfilepos = restoreCursorCB->isChecked();
1743         rc.load_session = loadSessionCB->isChecked();
1744         if (loadWindowSizeCB->isChecked()) {
1745                 rc.geometry_width = 0;
1746                 rc.geometry_height = 0;
1747         } else {
1748                 rc.geometry_width = windowWidthSB->value();
1749                 rc.geometry_height = windowHeightSB->value();
1750         }
1751         rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1752         rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1753         rc.autosave = autoSaveSB->value() * 60;
1754         rc.make_backup = autoSaveCB->isChecked();
1755         rc.num_lastfiles = lastfilesSB->value();
1756 }
1757
1758
1759 void PrefUserInterface::update(LyXRC const & rc)
1760 {
1761         uiFileED->setText(external_path(rc.ui_file));
1762         bindFileED->setText(external_path(rc.bind_file));
1763         restoreCursorCB->setChecked(rc.use_lastfilepos);
1764         loadSessionCB->setChecked(rc.load_session);
1765         bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1766         loadWindowSizeCB->setChecked(loadWindowSize);
1767         windowWidthSB->setEnabled(!loadWindowSize);
1768         windowHeightSB->setEnabled(!loadWindowSize);
1769         windowWidthLA->setEnabled(!loadWindowSize);
1770         windowHeightLA->setEnabled(!loadWindowSize);
1771         if (!loadWindowSize) {
1772                 windowWidthSB->setValue(rc.geometry_width);
1773                 windowHeightSB->setValue(rc.geometry_height);
1774         }
1775         loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1776         cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1777         // convert to minutes
1778         int mins(rc.autosave / 60);
1779         if (rc.autosave && !mins)
1780                 mins = 1;
1781         autoSaveSB->setValue(mins);
1782         autoSaveCB->setChecked(rc.make_backup);
1783         lastfilesSB->setValue(rc.num_lastfiles);
1784 }
1785
1786
1787
1788 void PrefUserInterface::select_ui()
1789 {
1790         string file(form_->controller().browseUI(fromqstr(uiFileED->text())));
1791         if (!file.empty())
1792                 uiFileED->setText(toqstr(file));
1793 }
1794
1795
1796 void PrefUserInterface::select_bind()
1797 {
1798         string file(form_->controller().browsebind(fromqstr(bindFileED->text())));
1799         if (!file.empty())
1800                 bindFileED->setText(toqstr(file));
1801 }
1802
1803
1804 PrefIdentity::PrefIdentity(QWidget * parent)
1805 : PrefModule(string(), lyx::to_utf8(_("Identity")), 0, parent)
1806 {
1807         setupUi(this);
1808
1809         connect(nameED, SIGNAL(textChanged(const QString&)),
1810                 this, SIGNAL(changed()));
1811         connect(emailED, SIGNAL(textChanged(const QString&)),
1812                 this, SIGNAL(changed()));
1813 }
1814
1815
1816 void PrefIdentity::apply(LyXRC & rc) const
1817 {
1818         rc.user_name = fromqstr(nameED->text());
1819         rc.user_email = fromqstr(emailED->text());
1820 }
1821
1822
1823 void PrefIdentity::update(LyXRC const & rc)
1824 {
1825         nameED->setText(toqstr(rc.user_name));
1826         emailED->setText(toqstr(rc.user_email));
1827 }
1828
1829
1830
1831 QPrefsDialog::QPrefsDialog(QPrefs * form)
1832         : form_(form)
1833 {
1834         setupUi(this);
1835         QDialog::setModal(true);
1836
1837         connect(savePB, SIGNAL(clicked()),
1838                 form, SLOT(slotOK()));
1839         connect(applyPB, SIGNAL(clicked()),
1840                 form, SLOT(slotApply()));
1841         connect(closePB, SIGNAL(clicked()),
1842                 form, SLOT(slotClose()));
1843         connect(restorePB, SIGNAL(clicked()),
1844                 form, SLOT(slotRestore()));
1845
1846         add(new PrefAscii);
1847         add(new PrefDate);
1848         add(new PrefKeyboard(form_));
1849         add(new PrefLatex(form_));
1850         add(new PrefScreenFonts(form_));
1851         add(new PrefColors(form_));
1852
1853 #if defined(__CYGWIN__) || defined(_WIN32)
1854         add(new PrefCygwinPath);
1855 #endif
1856
1857         add(new PrefDisplay);
1858         add(new PrefPaths(form_));
1859         add(new PrefSpellchecker(form_));
1860
1861         PrefConverters * converters = new PrefConverters(form_);
1862         PrefFileformats * formats = new PrefFileformats(form_);
1863         formats->setConverters(converters);
1864         add(converters);
1865         add(formats);
1866
1867         add(new PrefCopiers(form_));
1868
1869         add(new PrefLanguage);
1870         add(new PrefPrinter);
1871         add(new PrefUserInterface(form_));
1872         add(new PrefIdentity);
1873
1874         prefsPS->setCurrentPanel(lyx::to_utf8(_("User interface")));
1875
1876         form_->bcview().setOK(savePB);
1877         form_->bcview().setApply(applyPB);
1878         form_->bcview().setCancel(closePB);
1879         form_->bcview().setRestore(restorePB);
1880 }
1881
1882
1883 QPrefsDialog::~QPrefsDialog()
1884 {
1885 }
1886
1887
1888 void QPrefsDialog::add(PrefModule * module)
1889 {
1890         BOOST_ASSERT(module);
1891
1892 //      if (module->category().empty())
1893 //              prefsPS->addPanel(module, module->title());
1894 //      else
1895                 prefsPS->addPanel(module, module->title(), module->category());
1896
1897         connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1898
1899         modules_.push_back(module);
1900 }
1901
1902 void QPrefsDialog::closeEvent(QCloseEvent * e)
1903 {
1904         form_->slotWMHide();
1905         e->accept();
1906 }
1907
1908
1909 void QPrefsDialog::change_adaptor()
1910 {
1911         form_->changed();
1912 }
1913
1914
1915 void QPrefsDialog::apply(LyXRC & rc) const
1916 {
1917         size_t end = modules_.size();
1918         for (size_t i = 0; i != end; ++i)
1919                 modules_[i]->apply(rc);
1920 }
1921
1922
1923 void QPrefsDialog::update(LyXRC const & rc)
1924 {
1925         size_t end = modules_.size();
1926         for (size_t i = 0; i != end; ++i)
1927                 modules_[i]->update(rc);
1928 }
1929
1930
1931 } // namespace frontend
1932 } // namespace lyx
1933
1934 #include "QPrefsDialog_moc.cpp"