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