]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QPrefs.cpp
Bug fix: the type combo was not cleared at each update.
[lyx.git] / src / frontends / qt4 / QPrefs.cpp
1 /**
2  * \file QPrefs.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QPrefs.h"
14
15 #include "Qt2BC.h"
16 #include "qt_helpers.h"
17 #include "GuiApplication.h"
18
19 #include "Session.h"
20 #include "debug.h"
21 #include "Color.h"
22 #include "Font.h"
23 #include "PanelStack.h"
24 #include "QFontExample.h"
25 #include "gettext.h"
26
27 #include "support/lstrings.h"
28 #include "support/os.h"
29
30 #include "controllers/ControlPrefs.h"
31 #include "controllers/frontend_helpers.h"
32
33 #include "frontends/alert.h"
34 #include "frontends/Application.h"
35
36 #include <QCheckBox>
37 #include <QColorDialog>
38 #include <QFontDatabase>
39 #include <QLineEdit>
40 #include <QPushButton>
41 #include <QSpinBox>
42 #include <QString>
43 #include <QValidator>
44 #include <QCloseEvent>
45
46 #include <boost/tuple/tuple.hpp>
47 #include <iomanip>
48 #include <sstream>
49
50 using namespace Ui;
51
52 using lyx::support::compare_ascii_no_case;
53 using lyx::support::os::external_path;
54 using lyx::support::os::external_path_list;
55 using lyx::support::os::internal_path;
56 using lyx::support::os::internal_path_list;
57
58 using std::endl;
59 using std::string;
60 using std::pair;
61 using std::vector;
62
63
64 namespace lyx {
65 namespace frontend {
66
67 /////////////////////////////////////////////////////////////////////
68 //
69 // Helpers
70 //
71 /////////////////////////////////////////////////////////////////////
72
73 string const LookAndFeel = N_("Look and feel");
74 string const LanguageSettings = N_("Language settings");
75 string const Outputs = N_("Outputs");
76
77
78 // FIXME: move to frontend_helpers.h
79
80 template<class A>
81 static size_t findPos_helper(std::vector<A> const & vec, A const & val)
82 {
83         typedef typename std::vector<A>::const_iterator Cit;
84
85         Cit it = std::find(vec.begin(), vec.end(), val);
86         if (it == vec.end())
87                 return 0;
88         return std::distance(vec.begin(), it);
89 }
90
91
92 static void setComboxFont(QComboBox * cb, string const & family,
93         string const & foundry)
94 {
95         string const name = makeFontName(family, foundry);
96         for (int i = 0; i < cb->count(); ++i) {
97                 if (fromqstr(cb->itemText(i)) == name) {
98                         cb->setCurrentIndex(i);
99                         return;
100                 }
101         }
102
103         // Try matching without foundry name
104
105         // We count in reverse in order to prefer the Xft foundry
106         for (int i = cb->count() - 1; i >= 0; --i) {
107                 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
108                 if (compare_ascii_no_case(tmp.first, family) == 0) {
109                         cb->setCurrentIndex(i);
110                         return;
111                 }
112         }
113
114         // family alone can contain e.g. "Helvetica [Adobe]"
115         pair<string, string> tmpfam = parseFontName(family);
116
117         // We count in reverse in order to prefer the Xft foundry
118         for (int i = cb->count() - 1; i >= 0; --i) {
119                 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
120                 if (compare_ascii_no_case(tmp.first, tmpfam.first) == 0) {
121                         cb->setCurrentIndex(i);
122                         return;
123                 }
124         }
125
126         // Bleh, default fonts, and the names couldn't be found. Hack
127         // for bug 1063.
128
129         QFont font;
130         font.setKerning(false);
131
132         if (family == theApp()->romanFontName()) {
133                 font.setStyleHint(QFont::Serif);
134                 font.setFamily(family.c_str());
135         } else if (family == theApp()->sansFontName()) {
136                 font.setStyleHint(QFont::SansSerif);
137                 font.setFamily(family.c_str());
138         } else if (family == theApp()->typewriterFontName()) {
139                 font.setStyleHint(QFont::TypeWriter);
140                 font.setFamily(family.c_str());
141         } else {
142                 lyxerr << "FAILED to find the default font: '"
143                        << foundry << "', '" << family << '\''<< endl;
144                 return;
145         }
146
147         QFontInfo info(font);
148         pair<string, string> tmp = parseFontName(fromqstr(info.family()));
149         string const & default_font_name = tmp.first;
150         lyxerr << "Apparent font is " << default_font_name << endl;
151
152         for (int i = 0; i < cb->count(); ++i) {
153                 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
154                 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
155                                     default_font_name) == 0) {
156                         cb->setCurrentIndex(i);
157                         return;
158                 }
159         }
160
161         lyxerr << "FAILED to find the font: '"
162                << foundry << "', '" << family << '\'' <<endl;
163 }
164
165
166 /////////////////////////////////////////////////////////////////////
167 //
168 // PrefPlaintext
169 //
170 /////////////////////////////////////////////////////////////////////
171
172 PrefPlaintext::PrefPlaintext(QWidget * parent)
173         : PrefModule(_(Outputs), _("Plain text"), 0, parent)
174 {
175         setupUi(this);
176         connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
177                 this, SIGNAL(changed()));
178         connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
179                 this, SIGNAL(changed()));
180 }
181
182
183 void PrefPlaintext::apply(LyXRC & rc) const
184 {
185         rc.plaintext_linelen = plaintextLinelengthSB->value();
186         rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
187 }
188
189
190 void PrefPlaintext::update(LyXRC const & rc)
191 {
192         plaintextLinelengthSB->setValue(rc.plaintext_linelen);
193         plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
194 }
195
196
197 /////////////////////////////////////////////////////////////////////
198 //
199 // PrefDate
200 //
201 /////////////////////////////////////////////////////////////////////
202
203 PrefDate::PrefDate(QWidget * parent)
204         : PrefModule(_(Outputs), _("Date format"), 0, parent)
205 {
206         setupUi(this);
207         connect(DateED, SIGNAL(textChanged(const QString &)),
208                 this, SIGNAL(changed()));
209 }
210
211
212 void PrefDate::apply(LyXRC & rc) const
213 {
214         rc.date_insert_format = fromqstr(DateED->text());
215 }
216
217
218 void PrefDate::update(LyXRC const & rc)
219 {
220         DateED->setText(toqstr(rc.date_insert_format));
221 }
222
223
224 /////////////////////////////////////////////////////////////////////
225 //
226 // PrefKeyboard
227 //
228 /////////////////////////////////////////////////////////////////////
229
230 PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
231         : PrefModule(_(LookAndFeel), _("Keyboard"), form, parent)
232 {
233         setupUi(this);
234
235         connect(keymapCB, SIGNAL(clicked()),
236                 this, SIGNAL(changed()));
237         connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
238                 this, SIGNAL(changed()));
239         connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
240                 this, SIGNAL(changed()));
241 }
242
243
244 void PrefKeyboard::apply(LyXRC & rc) const
245 {
246         // FIXME: can derive CB from the two EDs
247         rc.use_kbmap = keymapCB->isChecked();
248         rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
249         rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
250 }
251
252
253 void PrefKeyboard::update(LyXRC const & rc)
254 {
255         // FIXME: can derive CB from the two EDs
256         keymapCB->setChecked(rc.use_kbmap);
257         firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
258         secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
259 }
260
261
262 QString PrefKeyboard::testKeymap(QString keymap)
263 {
264         return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
265 }
266
267
268 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
269 {
270         QString const file = testKeymap(firstKeymapED->text());
271         if (!file.isEmpty())
272                 firstKeymapED->setText(file);
273 }
274
275
276 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
277 {
278         QString const file = testKeymap(secondKeymapED->text());
279         if (!file.isEmpty())
280                 secondKeymapED->setText(file);
281 }
282
283
284 void PrefKeyboard::on_keymapCB_toggled(bool keymap)
285 {
286         firstKeymapLA->setEnabled(keymap);
287         secondKeymapLA->setEnabled(keymap);
288         firstKeymapED->setEnabled(keymap);
289         secondKeymapED->setEnabled(keymap);
290         firstKeymapPB->setEnabled(keymap);
291         secondKeymapPB->setEnabled(keymap);
292 }
293
294
295 /////////////////////////////////////////////////////////////////////
296 //
297 // PrefLatex
298 //
299 /////////////////////////////////////////////////////////////////////
300
301 PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
302         : PrefModule(_(Outputs), _("LaTeX"), form, parent)
303 {
304         setupUi(this);
305         connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
306                 this, SIGNAL(changed()));
307         connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
308                 this, SIGNAL(changed()));
309         connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
310                 this, SIGNAL(changed()));
311         connect(latexIndexED, SIGNAL(textChanged(const QString&)),
312                 this, SIGNAL(changed()));
313         connect(latexAutoresetCB, SIGNAL(clicked()),
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 /////////////////////////////////////////////////////////////////////
349 //
350 // PrefScreenFonts
351 //
352 /////////////////////////////////////////////////////////////////////
353
354 PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
355         : PrefModule(_(LookAndFeel), _("Screen fonts"), form, parent)
356 {
357         setupUi(this);
358
359         connect(screenRomanCO, SIGNAL(activated(const QString&)),
360                 this, SLOT(select_roman(const QString&)));
361         connect(screenSansCO, SIGNAL(activated(const QString&)),
362                 this, SLOT(select_sans(const QString&)));
363         connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
364                 this, SLOT(select_typewriter(const QString&)));
365
366         QFontDatabase fontdb;
367         QStringList families(fontdb.families());
368         for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
369                 screenRomanCO->addItem(*it);
370                 screenSansCO->addItem(*it);
371                 screenTypewriterCO->addItem(*it);
372         }
373         connect(screenRomanCO, SIGNAL(activated(const QString&)),
374                 this, SIGNAL(changed()));
375         connect(screenSansCO, SIGNAL(activated(const QString&)),
376                 this, SIGNAL(changed()));
377         connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
378                 this, SIGNAL(changed()));
379         connect(screenZoomSB, SIGNAL(valueChanged(int)),
380                 this, SIGNAL(changed()));
381         connect(screenDpiSB, SIGNAL(valueChanged(int)),
382                 this, SIGNAL(changed()));
383         connect(screenTinyED, SIGNAL(textChanged(const QString&)),
384                 this, SIGNAL(changed()));
385         connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
386                 this, SIGNAL(changed()));
387         connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
388                 this, SIGNAL(changed()));
389         connect(screenSmallED, SIGNAL(textChanged(const QString&)),
390                 this, SIGNAL(changed()));
391         connect(screenNormalED, SIGNAL(textChanged(const QString&)),
392                 this, SIGNAL(changed()));
393         connect(screenLargeED, SIGNAL(textChanged(const QString&)),
394                 this, SIGNAL(changed()));
395         connect(screenLargerED, SIGNAL(textChanged(const QString&)),
396                 this, SIGNAL(changed()));
397         connect(screenLargestED, SIGNAL(textChanged(const QString&)),
398                 this, SIGNAL(changed()));
399         connect(screenHugeED, SIGNAL(textChanged(const QString&)),
400                 this, SIGNAL(changed()));
401         connect(screenHugerED, SIGNAL(textChanged(const QString&)),
402                 this, SIGNAL(changed()));
403
404         screenTinyED->setValidator(new QDoubleValidator(
405                 screenTinyED));
406         screenSmallestED->setValidator(new QDoubleValidator(
407                 screenSmallestED));
408         screenSmallerED->setValidator(new QDoubleValidator(
409                 screenSmallerED));
410         screenSmallED->setValidator(new QDoubleValidator(
411                 screenSmallED));
412         screenNormalED->setValidator(new QDoubleValidator(
413                 screenNormalED));
414         screenLargeED->setValidator(new QDoubleValidator(
415                 screenLargeED));
416         screenLargerED->setValidator(new QDoubleValidator(
417                 screenLargerED));
418         screenLargestED->setValidator(new QDoubleValidator(
419                 screenLargestED));
420         screenHugeED->setValidator(new QDoubleValidator(
421                 screenHugeED));
422         screenHugerED->setValidator(new QDoubleValidator(
423                 screenHugerED));
424 }
425
426
427 void PrefScreenFonts::apply(LyXRC & rc) const
428 {
429         LyXRC const oldrc(rc);
430
431         boost::tie(rc.roman_font_name, rc.roman_font_foundry)
432                 = parseFontName(fromqstr(screenRomanCO->currentText()));
433         boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
434                 parseFontName(fromqstr(screenSansCO->currentText()));
435         boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
436                 parseFontName(fromqstr(screenTypewriterCO->currentText()));
437
438         rc.zoom = screenZoomSB->value();
439         rc.dpi = screenDpiSB->value();
440         rc.font_sizes[Font::SIZE_TINY] = fromqstr(screenTinyED->text());
441         rc.font_sizes[Font::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
442         rc.font_sizes[Font::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
443         rc.font_sizes[Font::SIZE_SMALL] = fromqstr(screenSmallED->text());
444         rc.font_sizes[Font::SIZE_NORMAL] = fromqstr(screenNormalED->text());
445         rc.font_sizes[Font::SIZE_LARGE] = fromqstr(screenLargeED->text());
446         rc.font_sizes[Font::SIZE_LARGER] = fromqstr(screenLargerED->text());
447         rc.font_sizes[Font::SIZE_LARGEST] = fromqstr(screenLargestED->text());
448         rc.font_sizes[Font::SIZE_HUGE] = fromqstr(screenHugeED->text());
449         rc.font_sizes[Font::SIZE_HUGER] = fromqstr(screenHugerED->text());
450
451         if (rc.font_sizes != oldrc.font_sizes
452                 || rc.roman_font_name != oldrc.roman_font_name
453                 || rc.sans_font_name != oldrc.sans_font_name
454                 || rc.typewriter_font_name != oldrc.typewriter_font_name
455                 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
456                 form_->controller().updateScreenFonts();
457         }
458 }
459
460
461 void PrefScreenFonts::update(LyXRC const & rc)
462 {
463         setComboxFont(screenRomanCO, rc.roman_font_name,
464                         rc.roman_font_foundry);
465         setComboxFont(screenSansCO, rc.sans_font_name,
466                         rc.sans_font_foundry);
467         setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
468                         rc.typewriter_font_foundry);
469
470         select_roman(screenRomanCO->currentText());
471         select_sans(screenSansCO->currentText());
472         select_typewriter(screenTypewriterCO->currentText());
473
474         screenZoomSB->setValue(rc.zoom);
475         screenDpiSB->setValue(rc.dpi);
476         screenTinyED->setText(toqstr(rc.font_sizes[Font::SIZE_TINY]));
477         screenSmallestED->setText(toqstr(rc.font_sizes[Font::SIZE_SCRIPT]));
478         screenSmallerED->setText(toqstr(rc.font_sizes[Font::SIZE_FOOTNOTE]));
479         screenSmallED->setText(toqstr(rc.font_sizes[Font::SIZE_SMALL]));
480         screenNormalED->setText(toqstr(rc.font_sizes[Font::SIZE_NORMAL]));
481         screenLargeED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGE]));
482         screenLargerED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGER]));
483         screenLargestED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGEST]));
484         screenHugeED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGE]));
485         screenHugerED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGER]));
486 }
487
488 void PrefScreenFonts::select_roman(const QString& name)
489 {
490         screenRomanFE->set(QFont(name), name);
491 }
492
493
494 void PrefScreenFonts::select_sans(const QString& name)
495 {
496         screenSansFE->set(QFont(name), name);
497 }
498
499
500 void PrefScreenFonts::select_typewriter(const QString& name)
501 {
502         screenTypewriterFE->set(QFont(name), name);
503 }
504
505
506 /////////////////////////////////////////////////////////////////////
507 //
508 // PrefColors
509 //
510 /////////////////////////////////////////////////////////////////////
511
512 PrefColors::PrefColors(QPrefs * form, QWidget * parent)
513         : PrefModule(_(LookAndFeel), _("Colors"), form, parent)
514 {
515         setupUi(this);
516
517         // FIXME: all of this initialization should be put into the controller.
518         // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
519         // for some discussion of why that is not trivial.
520         QPixmap icon(32, 32);
521         for (int i = 0; i < Color::ignore; ++i) {
522                 Color::color lc = static_cast<Color::color>(i);
523                 if (lc == Color::none
524                         || lc == Color::black
525                         || lc == Color::white
526                         || lc == Color::red
527                         || lc == Color::green
528                         || lc == Color::blue
529                         || lc == Color::cyan
530                         || lc == Color::magenta
531                         || lc == Color::yellow
532                         || lc == Color::inherit
533                         || lc == Color::ignore) continue;
534
535                 lcolors_.push_back(lc);
536                 // This is not a memory leak:
537                 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(icon),
538                         toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
539         }
540         curcolors_.resize(lcolors_.size());
541         newcolors_.resize(lcolors_.size());
542         // End initialization
543
544         connect(colorChangePB, SIGNAL(clicked()),
545                 this, SLOT(change_color()));
546         connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
547                 this, SLOT(change_lyxObjects_selection()));
548         connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
549                 this, SLOT(change_color()));
550 }
551
552
553 void PrefColors::apply(LyXRC & /*rc*/) const
554 {
555         for (unsigned int i = 0; i < lcolors_.size(); ++i) {
556                 if (curcolors_[i] != newcolors_[i]) {
557                         form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
558                 }
559         }
560 }
561
562
563 void PrefColors::update(LyXRC const & /*rc*/)
564 {
565         for (unsigned int i = 0; i < lcolors_.size(); ++i) {
566                 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
567                 QPixmap coloritem(32, 32);
568                 coloritem.fill(color);
569                 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
570                 newcolors_[i] = curcolors_[i] = color.name();
571         }
572         change_lyxObjects_selection();
573 }
574
575 void PrefColors::change_color()
576 {
577         int const row = lyxObjectsLW->currentRow();
578
579         // just to be sure
580         if (row < 0) return;
581
582         QString const color = newcolors_[row];
583         QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget()));
584
585         if (c.isValid() && c.name() != color) {
586                 newcolors_[row] = c.name();
587                 QPixmap coloritem(32, 32);
588                 coloritem.fill(c);
589                 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
590                 // emit signal
591                 changed();
592         }
593 }
594
595 void PrefColors::change_lyxObjects_selection()
596 {
597         colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
598 }
599
600
601 /////////////////////////////////////////////////////////////////////
602 //
603 // PrefCygwinPath
604 //
605 /////////////////////////////////////////////////////////////////////
606
607 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
608         : PrefModule(_(Outputs), _("Paths"), 0, parent)
609 {
610         setupUi(this);
611         connect(pathCB, SIGNAL(clicked()), this, SIGNAL(changed()));
612 }
613
614
615 void PrefCygwinPath::apply(LyXRC & rc) const
616 {
617         rc.windows_style_tex_paths = pathCB->isChecked();
618 }
619
620
621 void PrefCygwinPath::update(LyXRC const & rc)
622 {
623         pathCB->setChecked(rc.windows_style_tex_paths);
624 }
625
626
627 /////////////////////////////////////////////////////////////////////
628 //
629 // PrefDisplay
630 //
631 /////////////////////////////////////////////////////////////////////
632
633 PrefDisplay::PrefDisplay(QWidget * parent)
634         : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
635 {
636         setupUi(this);
637         connect(instantPreviewCO, SIGNAL(activated(int)),
638                 this, SIGNAL(changed()));
639         connect(displayGraphicsCO, SIGNAL(activated(int)),
640                 this, SIGNAL(changed()));
641 }
642
643
644 void PrefDisplay::apply(LyXRC & rc) const
645 {
646         switch (instantPreviewCO->currentIndex()) {
647         case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
648         case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
649         case 2: rc.preview = LyXRC::PREVIEW_ON; break;
650         }
651
652         lyx::graphics::DisplayType dtype;
653         switch (displayGraphicsCO->currentIndex()) {
654         case 3: dtype = lyx::graphics::NoDisplay; break;
655         case 2: dtype = lyx::graphics::ColorDisplay; break;
656         case 1: dtype = lyx::graphics::GrayscaleDisplay;        break;
657         case 0: dtype = lyx::graphics::MonochromeDisplay; break;
658         default: dtype = lyx::graphics::GrayscaleDisplay;
659         }
660         rc.display_graphics = dtype;
661
662 #ifdef WITH_WARNINGS
663 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
664 #endif
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(QPrefs * form, QWidget * parent)
707         : PrefModule(docstring(), _("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(QPrefs * form, QWidget * parent)
811         : PrefModule(_(LanguageSettings), _("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(QPrefs * form, QWidget * parent)
921         : PrefModule(docstring(), _("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
1085
1086 void PrefConverters::remove_converter()
1087 {
1088         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1089         Format const & to(form_->formats().get(converterToCO->currentIndex()));
1090         form_->converters().erase(from.name(), to.name());
1091
1092         updateGui();
1093 }
1094
1095
1096 void PrefConverters::on_cacheCB_stateChanged(int state)
1097 {
1098         maxAgeLE->setEnabled(state == Qt::Checked);
1099         maxAgeLA->setEnabled(state == Qt::Checked);
1100         changed();
1101 }
1102
1103
1104 /////////////////////////////////////////////////////////////////////
1105 //
1106 // PrefCopiers
1107 //
1108 /////////////////////////////////////////////////////////////////////
1109
1110 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1111         : PrefModule(docstring(), _("Copiers"), form, parent)
1112 {
1113         setupUi(this);
1114
1115         connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1116         connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1117         connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1118         connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1119                 this, SLOT(switch_copierLB(int)));
1120         connect(copierFormatCO, SIGNAL(activated(int)),
1121                 this, SLOT(switch_copierCO(int)));
1122         connect(copierNewPB, SIGNAL(clicked()),
1123                 this, SIGNAL(changed()));
1124         connect(copierRemovePB, SIGNAL(clicked()),
1125                 this, SIGNAL(changed()));
1126         connect(copierModifyPB, SIGNAL(clicked()),
1127                 this, SIGNAL(changed()));
1128         connect(copierFormatCO, SIGNAL(activated(const QString &)),
1129                 this, SLOT(copiers_changed()));
1130         connect(copierED, SIGNAL(textChanged(const QString &)),
1131                 this, SLOT(copiers_changed()));
1132 }
1133
1134
1135 void PrefCopiers::apply(LyXRC & /*rc*/) const
1136 {
1137 }
1138
1139
1140 void PrefCopiers::update(LyXRC const & /*rc*/)
1141 {
1142         update();
1143 }
1144
1145
1146 void PrefCopiers::update()
1147 {
1148         // The choice widget
1149         // save current selection
1150         QString current = copierFormatCO->currentText();
1151         copierFormatCO->clear();
1152
1153         for (Formats::const_iterator it = form_->formats().begin(),
1154                      end = form_->formats().end();
1155              it != end; ++it) {
1156                 copierFormatCO->addItem(toqstr(it->prettyname()));
1157         }
1158
1159         // The browser widget
1160         AllCopiersLW->clear();
1161
1162         for (Movers::const_iterator it = form_->movers().begin(),
1163                      end = form_->movers().end();
1164              it != end; ++it) {
1165                 std::string const & command = it->second.command();
1166                 if (command.empty())
1167                         continue;
1168                 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1169                 AllCopiersLW->addItem(pretty);
1170         }
1171         AllCopiersLW->sortItems(Qt::AscendingOrder);
1172
1173         // restore selection
1174         if (!current.isEmpty()) {
1175                 QList<QListWidgetItem *> item =
1176                         AllCopiersLW->findItems(current, Qt::MatchExactly);
1177                 if (item.size()>0)
1178                         AllCopiersLW->setCurrentItem(item.at(0));
1179         }
1180         // select first element if restoring failed
1181         if (AllCopiersLW->currentRow() == -1)
1182                 AllCopiersLW->setCurrentRow(0);
1183 }
1184
1185
1186 namespace {
1187
1188 class SamePrettyName {
1189 public:
1190         SamePrettyName(string const & n) : pretty_name_(n) {}
1191
1192         bool operator()(Format const & fmt) const {
1193                 return fmt.prettyname() == pretty_name_;
1194         }
1195
1196 private:
1197         string const pretty_name_;
1198 };
1199
1200
1201 Format const * getFormat(std::string const & prettyname)
1202 {
1203         Formats::const_iterator it = formats.begin();
1204         Formats::const_iterator const end = formats.end();
1205         it = std::find_if(it, end, SamePrettyName(prettyname));
1206         return it == end ? 0 : &*it;
1207 }
1208
1209 } // namespace anon
1210
1211
1212 void PrefCopiers::switch_copierLB(int row)
1213 {
1214         if (row < 0)
1215                 return;
1216
1217         // FIXME UNICODE?
1218         std::string const browser_text =
1219                 fromqstr(AllCopiersLW->currentItem()->text());
1220         Format const * fmt = getFormat(browser_text);
1221         if (fmt == 0)
1222                 return;
1223
1224         QString const gui_name = toqstr(fmt->prettyname());
1225         QString const command = toqstr(form_->movers().command(fmt->name()));
1226
1227         copierED->clear();
1228         int const combo_size = copierFormatCO->count();
1229         for (int i = 0; i < combo_size; ++i) {
1230                 QString const text = copierFormatCO->itemText(i);
1231                 if (text == gui_name) {
1232                         copierFormatCO->setCurrentIndex(i);
1233                         copierED->setText(command);
1234                         break;
1235                 }
1236         }
1237         updateButtons();
1238 }
1239
1240
1241 void PrefCopiers::switch_copierCO(int row)
1242 {
1243         if (row<0)
1244                 return;
1245
1246         std::string const combo_text =
1247                 fromqstr(copierFormatCO->currentText());
1248         Format const * fmt = getFormat(combo_text);
1249         if (fmt == 0)
1250                 return;
1251
1252         QString const command = toqstr(form_->movers().command(fmt->name()));
1253         copierED->setText(command);
1254
1255         QListWidgetItem * const index = AllCopiersLW->currentItem();
1256         if (index >= 0)
1257                 AllCopiersLW->setItemSelected(index, false);
1258
1259         QString const gui_name = toqstr(fmt->prettyname());
1260         int const browser_size = AllCopiersLW->count();
1261         for (int i = 0; i < browser_size; ++i) {
1262                 QString const text = AllCopiersLW->item(i)->text();
1263                 if (text == gui_name) {
1264                         QListWidgetItem * item = AllCopiersLW->item(i);
1265                         AllCopiersLW->setItemSelected(item, true);
1266                         break;
1267                 }
1268         }
1269 }
1270
1271
1272 void PrefCopiers::copiers_changed()
1273 {
1274         updateButtons();
1275 }
1276
1277
1278 void PrefCopiers::updateButtons()
1279 {
1280         QString selected = copierFormatCO->currentText();
1281
1282         bool known = false;
1283         for (int i = 0; i < AllCopiersLW->count(); ++i) {
1284                 if (AllCopiersLW->item(i)->text() == selected)
1285                         known = true;
1286         }
1287
1288         bool const valid = !copierED->text().isEmpty();
1289
1290         Format const * fmt = getFormat(fromqstr(selected));
1291         string const old_command = form_->movers().command(fmt->name());
1292         string const new_command(fromqstr(copierED->text()));
1293
1294         bool modified = (old_command != new_command);
1295
1296         copierModifyPB->setEnabled(valid && known && modified);
1297         copierNewPB->setEnabled(valid && !known);
1298         copierRemovePB->setEnabled(known);
1299 }
1300
1301
1302 void PrefCopiers::new_copier()
1303 {
1304         std::string const combo_text =
1305                 fromqstr(copierFormatCO->currentText());
1306         Format const * fmt = getFormat(combo_text);
1307         if (fmt == 0)
1308                 return;
1309
1310         string const command = fromqstr(copierED->text());
1311         if (command.empty())
1312                 return;
1313
1314         form_->movers().set(fmt->name(), command);
1315
1316         update();
1317         int const last = AllCopiersLW->count() - 1;
1318         AllCopiersLW->setCurrentRow(last);
1319
1320         updateButtons();
1321 }
1322
1323
1324 void PrefCopiers::modify_copier()
1325 {
1326         std::string const combo_text =
1327                 fromqstr(copierFormatCO->currentText());
1328         Format const * fmt = getFormat(combo_text);
1329         if (fmt == 0)
1330                 return;
1331
1332         string const command = fromqstr(copierED->text());
1333         form_->movers().set(fmt->name(), command);
1334
1335         update();
1336         updateButtons();
1337 }
1338
1339
1340 void PrefCopiers::remove_copier()
1341 {
1342         std::string const combo_text =
1343                 fromqstr(copierFormatCO->currentText());
1344         Format const * fmt = getFormat(combo_text);
1345         if (fmt == 0)
1346                 return;
1347
1348         string const & fmt_name = fmt->name();
1349         form_->movers().set(fmt_name, string());
1350
1351         update();
1352         updateButtons();
1353 }
1354
1355
1356
1357 /////////////////////////////////////////////////////////////////////
1358 //
1359 // PrefFileformats
1360 //
1361 /////////////////////////////////////////////////////////////////////
1362
1363 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1364         : PrefModule(docstring(), _("File formats"), form, parent)
1365 {
1366         setupUi(this);
1367
1368         connect(formatNewPB, SIGNAL(clicked()),
1369                 this, SLOT(new_format()));
1370         connect(formatRemovePB, SIGNAL(clicked()),
1371                 this, SLOT(remove_format()));
1372         connect(formatModifyPB, SIGNAL(clicked()),
1373                 this, SLOT(modify_format()));
1374         connect(formatsLW, SIGNAL(currentRowChanged(int)),
1375                 this, SLOT(switch_format(int)));
1376         connect(formatED, SIGNAL(textChanged(const QString&)),
1377                 this, SLOT(fileformat_changed()));
1378         connect(guiNameED, SIGNAL(textChanged(const QString&)),
1379                 this, SLOT(fileformat_changed()));
1380         connect(shortcutED, SIGNAL(textChanged(const QString&)),
1381                 this, SLOT(fileformat_changed()));
1382         connect(extensionED, SIGNAL(textChanged(const QString&)),
1383                 this, SLOT(fileformat_changed()));
1384         connect(viewerED, SIGNAL(textChanged(const QString&)),
1385                 this, SLOT(fileformat_changed()));
1386         connect(editorED, SIGNAL(textChanged(const QString&)),
1387                 this, SLOT(fileformat_changed()));
1388         connect(documentCB, SIGNAL(clicked()),
1389                 this, SLOT(fileformat_changed()));
1390         connect(vectorCB, SIGNAL(clicked()),
1391                 this, SLOT(fileformat_changed()));
1392         connect(formatNewPB, SIGNAL(clicked()),
1393                 this, SIGNAL(changed()));
1394         connect(formatRemovePB, SIGNAL(clicked()),
1395                 this, SIGNAL(changed()));
1396         connect(formatModifyPB, SIGNAL(clicked()),
1397                 this, SIGNAL(changed()));
1398 }
1399
1400
1401 void PrefFileformats::apply(LyXRC & /*rc*/) const
1402 {
1403 }
1404
1405
1406 void PrefFileformats::update(LyXRC const & /*rc*/)
1407 {
1408         update();
1409 }
1410
1411
1412 void PrefFileformats::update()
1413 {
1414         // save current selection
1415         QString current = guiNameED->text();
1416
1417         // update listwidget with formats
1418         formatsLW->blockSignals(true);
1419         formatsLW->clear();
1420         Formats::const_iterator cit = form_->formats().begin();
1421         Formats::const_iterator end = form_->formats().end();
1422         for (; cit != end; ++cit) {
1423                 new QListWidgetItem(toqstr(cit->prettyname()),
1424                                                         formatsLW,
1425                                                         form_->formats().getNumber(cit->name()) );
1426         }
1427         formatsLW->sortItems(Qt::AscendingOrder);
1428         formatsLW->blockSignals(false);
1429
1430         // restore selection
1431         if (!current.isEmpty()) {
1432                 QList<QListWidgetItem *>  item = formatsLW->findItems(current, Qt::MatchExactly);
1433                 if (item.size()>0)
1434                         formatsLW->setCurrentItem(item.at(0));
1435         }
1436         // select first element if restoring failed
1437         if (formatsLW->currentRow() == -1)
1438                 formatsLW->setCurrentRow(0);
1439 }
1440
1441
1442 void PrefFileformats::switch_format(int nr)
1443 {
1444         int const ftype = formatsLW->item(nr)->type();
1445         Format const f = form_->formats().get(ftype);
1446
1447         formatED->setText(toqstr(f.name()));
1448         guiNameED->setText(toqstr(f.prettyname()));
1449         extensionED->setText(toqstr(f.extension()));
1450         shortcutED->setText(toqstr(f.shortcut()));
1451         viewerED->setText(toqstr(f.viewer()));
1452         editorED->setText(toqstr(f.editor()));
1453         documentCB->setChecked((f.documentFormat()));
1454         vectorCB->setChecked((f.vectorFormat()));
1455
1456         updateButtons();
1457 }
1458
1459
1460 void PrefFileformats::fileformat_changed()
1461 {
1462         updateButtons();
1463 }
1464
1465
1466 void PrefFileformats::updateButtons()
1467 {
1468         QString const format = formatED->text();
1469         QString const gui_name = guiNameED->text();
1470         int const sel = form_->formats().getNumber(fromqstr(format));
1471         bool gui_name_known = false;
1472         int where = sel;
1473         for (int i = 0; i < formatsLW->count(); ++i) {
1474                 if (formatsLW->item(i)->text() == gui_name) {
1475                         gui_name_known = true;
1476                         where = formatsLW->item(i)->type();
1477                 }
1478         }
1479
1480         // assure that a gui name cannot be chosen twice
1481         bool const known_otherwise = gui_name_known && (where != sel);
1482
1483         bool const known = !(sel < 0);
1484         bool const valid = (!formatED->text().isEmpty()
1485                 && !guiNameED->text().isEmpty());
1486
1487         int const ftype = formatsLW->currentItem()->type();
1488         Format const & f(form_->formats().get(ftype));
1489         string const old_pretty(f.prettyname());
1490         string const old_shortcut(f.shortcut());
1491         string const old_extension(f.extension());
1492         string const old_viewer(f.viewer());
1493         string const old_editor(f.editor());
1494         bool const old_document(f.documentFormat());
1495         bool const old_vector(f.vectorFormat());
1496
1497         string const new_pretty(fromqstr(gui_name));
1498         string const new_shortcut(fromqstr(shortcutED->text()));
1499         string const new_extension(fromqstr(extensionED->text()));
1500         string const new_viewer(fromqstr(viewerED->text()));
1501         string const new_editor(fromqstr(editorED->text()));
1502         bool const new_document(documentCB->isChecked());
1503         bool const new_vector(vectorCB->isChecked());
1504
1505         bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1506                 || (old_extension != new_extension) || (old_viewer != new_viewer)
1507                 || old_editor != new_editor || old_document != new_document
1508                 || old_vector != new_vector);
1509
1510         formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1511         formatNewPB->setEnabled(valid && !known && !gui_name_known);
1512         formatRemovePB->setEnabled(known);
1513 }
1514
1515
1516 void PrefFileformats::new_format()
1517 {
1518         string const name = fromqstr(formatED->text());
1519         string const prettyname = fromqstr(guiNameED->text());
1520         string const extension = fromqstr(extensionED->text());
1521         string const shortcut = fromqstr(shortcutED->text());
1522         string const viewer = fromqstr(viewerED->text());
1523         string const editor = fromqstr(editorED->text());
1524         int flags = Format::none;
1525         if (documentCB->isChecked())
1526                 flags |= Format::document;
1527         if (vectorCB->isChecked())
1528                 flags |= Format::vector;
1529
1530         form_->formats().add(name, extension, prettyname, shortcut, viewer,
1531                              editor, flags);
1532         form_->formats().sort();
1533         form_->converters().update(form_->formats());
1534
1535         update();
1536         updateButtons();
1537         formatsChanged();
1538 }
1539
1540
1541 void PrefFileformats::modify_format()
1542 {
1543         int const current_item = formatsLW->currentItem()->type();
1544         Format const & oldformat = form_->formats().get(current_item);
1545         form_->formats().erase(oldformat.name());
1546
1547         new_format();
1548 }
1549
1550
1551 void PrefFileformats::remove_format()
1552 {
1553         int const nr = formatsLW->currentItem()->type();
1554         string const current_text = form_->formats().get(nr).name();
1555         if (form_->converters().formatIsUsed(current_text)) {
1556                 Alert::error(_("Format in use"),
1557                              _("Cannot remove a Format used by a Converter. "
1558                                             "Remove the converter first."));
1559                 return;
1560         }
1561
1562         form_->formats().erase(current_text);
1563         form_->converters().update(form_->formats());
1564
1565         update();
1566         updateButtons();
1567         formatsChanged();
1568 }
1569
1570
1571 /////////////////////////////////////////////////////////////////////
1572 //
1573 // PrefLanguage
1574 //
1575 /////////////////////////////////////////////////////////////////////
1576
1577 PrefLanguage::PrefLanguage(QWidget * parent)
1578         : PrefModule(_(LanguageSettings), _("Language"), 0, parent)
1579 {
1580         setupUi(this);
1581
1582         connect(rtlCB, SIGNAL(clicked()),
1583                 this, SIGNAL(changed()));
1584         connect(markForeignCB, SIGNAL(clicked()),
1585                 this, SIGNAL(changed()));
1586         connect(autoBeginCB, SIGNAL(clicked()),
1587                 this, SIGNAL(changed()));
1588         connect(autoEndCB, SIGNAL(clicked()),
1589                 this, SIGNAL(changed()));
1590         connect(useBabelCB, SIGNAL(clicked()),
1591                 this, SIGNAL(changed()));
1592         connect(globalCB, SIGNAL(clicked()),
1593                 this, SIGNAL(changed()));
1594         connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1595                 this, SIGNAL(changed()));
1596         connect(startCommandED, SIGNAL(textChanged(const QString&)),
1597                 this, SIGNAL(changed()));
1598         connect(endCommandED, SIGNAL(textChanged(const QString&)),
1599                 this, SIGNAL(changed()));
1600         connect(defaultLanguageCO, SIGNAL(activated(int)),
1601                 this, SIGNAL(changed()));
1602
1603         defaultLanguageCO->clear();
1604
1605         // store the lang identifiers for later
1606         std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
1607         lang_ = getSecond(langs);
1608
1609         std::vector<LanguagePair>::const_iterator lit  = langs.begin();
1610         std::vector<LanguagePair>::const_iterator lend = langs.end();
1611         for (; lit != lend; ++lit) {
1612                 defaultLanguageCO->addItem(toqstr(lit->first));
1613         }
1614 }
1615
1616
1617 void PrefLanguage::apply(LyXRC & rc) const
1618 {
1619         // FIXME: remove rtl_support bool
1620         rc.rtl_support = rtlCB->isChecked();
1621         rc.mark_foreign_language = markForeignCB->isChecked();
1622         rc.language_auto_begin = autoBeginCB->isChecked();
1623         rc.language_auto_end = autoEndCB->isChecked();
1624         rc.language_use_babel = useBabelCB->isChecked();
1625         rc.language_global_options = globalCB->isChecked();
1626         rc.language_package = fromqstr(languagePackageED->text());
1627         rc.language_command_begin = fromqstr(startCommandED->text());
1628         rc.language_command_end = fromqstr(endCommandED->text());
1629         rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1630 }
1631
1632
1633 void PrefLanguage::update(LyXRC const & rc)
1634 {
1635         // FIXME: remove rtl_support bool
1636         rtlCB->setChecked(rc.rtl_support);
1637         markForeignCB->setChecked(rc.mark_foreign_language);
1638         autoBeginCB->setChecked(rc.language_auto_begin);
1639         autoEndCB->setChecked(rc.language_auto_end);
1640         useBabelCB->setChecked(rc.language_use_babel);
1641         globalCB->setChecked(rc.language_global_options);
1642         languagePackageED->setText(toqstr(rc.language_package));
1643         startCommandED->setText(toqstr(rc.language_command_begin));
1644         endCommandED->setText(toqstr(rc.language_command_end));
1645
1646         int const pos = int(findPos_helper(lang_, rc.default_language));
1647         defaultLanguageCO->setCurrentIndex(pos);
1648 }
1649
1650
1651 /////////////////////////////////////////////////////////////////////
1652 //
1653 // PrefPrinter
1654 //
1655 /////////////////////////////////////////////////////////////////////
1656
1657 PrefPrinter::PrefPrinter(QWidget * parent)
1658         : PrefModule(_(Outputs), _("Printer"), 0, parent)
1659 {
1660         setupUi(this);
1661
1662         connect(printerAdaptCB, SIGNAL(clicked()),
1663                 this, SIGNAL(changed()));
1664         connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1665                 this, SIGNAL(changed()));
1666         connect(printerNameED, SIGNAL(textChanged(const QString&)),
1667                 this, SIGNAL(changed()));
1668         connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1669                 this, SIGNAL(changed()));
1670         connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1671                 this, SIGNAL(changed()));
1672         connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1673                 this, SIGNAL(changed()));
1674         connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1675                 this, SIGNAL(changed()));
1676         connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1677                 this, SIGNAL(changed()));
1678         connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1679                 this, SIGNAL(changed()));
1680         connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1681                 this, SIGNAL(changed()));
1682         connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1683                 this, SIGNAL(changed()));
1684         connect(printerOddED, SIGNAL(textChanged(const QString&)),
1685                 this, SIGNAL(changed()));
1686         connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1687                 this, SIGNAL(changed()));
1688         connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1689                 this, SIGNAL(changed()));
1690         connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1691                 this, SIGNAL(changed()));
1692         connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1693                 this, SIGNAL(changed()));
1694         connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1695                 this, SIGNAL(changed()));
1696         connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1697                 this, SIGNAL(changed()));
1698 }
1699
1700
1701 void PrefPrinter::apply(LyXRC & rc) const
1702 {
1703         rc.print_adapt_output = printerAdaptCB->isChecked();
1704         rc.print_command = fromqstr(printerCommandED->text());
1705         rc.printer = fromqstr(printerNameED->text());
1706
1707         rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1708         rc.print_copies_flag = fromqstr(printerCopiesED->text());
1709         rc.print_reverse_flag = fromqstr(printerReverseED->text());
1710         rc.print_to_printer = fromqstr(printerToPrinterED->text());
1711         rc.print_file_extension = fromqstr(printerExtensionED->text());
1712         rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1713         rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1714         rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1715         rc.print_oddpage_flag = fromqstr(printerOddED->text());
1716         rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1717         rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1718         rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1719         rc.print_extra_options = fromqstr(printerExtraED->text());
1720         rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1721         rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1722 }
1723
1724
1725 void PrefPrinter::update(LyXRC const & rc)
1726 {
1727         printerAdaptCB->setChecked(rc.print_adapt_output);
1728         printerCommandED->setText(toqstr(rc.print_command));
1729         printerNameED->setText(toqstr(rc.printer));
1730
1731         printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1732         printerCopiesED->setText(toqstr(rc.print_copies_flag));
1733         printerReverseED->setText(toqstr(rc.print_reverse_flag));
1734         printerToPrinterED->setText(toqstr(rc.print_to_printer));
1735         printerExtensionED->setText(toqstr(rc.print_file_extension));
1736         printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1737         printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1738         printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1739         printerOddED->setText(toqstr(rc.print_oddpage_flag));
1740         printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1741         printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1742         printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1743         printerExtraED->setText(toqstr(rc.print_extra_options));
1744         printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1745         printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1746 }
1747
1748
1749 /////////////////////////////////////////////////////////////////////
1750 //
1751 // PrefUserInterface
1752 //
1753 /////////////////////////////////////////////////////////////////////
1754
1755 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1756         : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1757 {
1758         setupUi(this);
1759
1760         connect(autoSaveCB, SIGNAL(toggled(bool)),
1761                 autoSaveLA, SLOT(setEnabled(bool)));
1762         connect(autoSaveCB, SIGNAL(toggled(bool)),
1763                 autoSaveSB, SLOT(setEnabled(bool)));
1764         connect(autoSaveCB, SIGNAL(toggled(bool)),
1765                 TextLabel1, SLOT(setEnabled(bool)));
1766         connect(uiFilePB, SIGNAL(clicked()),
1767                 this, SLOT(select_ui()));
1768         connect(bindFilePB, SIGNAL(clicked()),
1769                 this, SLOT(select_bind()));
1770         connect(uiFileED, SIGNAL(textChanged(const QString &)),
1771                 this, SIGNAL(changed()));
1772         connect(bindFileED, SIGNAL(textChanged(const QString &)),
1773                 this, SIGNAL(changed()));
1774         connect(restoreCursorCB, SIGNAL(clicked()),
1775                 this, SIGNAL(changed()));
1776         connect(loadSessionCB, SIGNAL(clicked()),
1777                 this, SIGNAL(changed()));
1778         connect(loadWindowSizeCB, SIGNAL(clicked()),
1779                 this, SIGNAL(changed()));
1780         connect(loadWindowLocationCB, SIGNAL(clicked()),
1781                 this, SIGNAL(changed()));
1782         connect(windowWidthSB, SIGNAL(valueChanged(int)),
1783                 this, SIGNAL(changed()));
1784         connect(windowHeightSB, SIGNAL(valueChanged(int)),
1785                 this, SIGNAL(changed()));
1786         connect(cursorFollowsCB, SIGNAL(clicked()),
1787                 this, SIGNAL(changed()));
1788         connect(autoSaveSB, SIGNAL(valueChanged(int)),
1789                 this, SIGNAL(changed()));
1790         connect(autoSaveCB, SIGNAL(clicked()),
1791                 this, SIGNAL(changed()));
1792         connect(lastfilesSB, SIGNAL(valueChanged(int)),
1793                 this, SIGNAL(changed()));
1794         lastfilesSB->setMaximum(maxlastfiles);
1795 }
1796
1797
1798 void PrefUserInterface::apply(LyXRC & rc) const
1799 {
1800         rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1801         rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1802         rc.use_lastfilepos = restoreCursorCB->isChecked();
1803         rc.load_session = loadSessionCB->isChecked();
1804         if (loadWindowSizeCB->isChecked()) {
1805                 rc.geometry_width = 0;
1806                 rc.geometry_height = 0;
1807         } else {
1808                 rc.geometry_width = windowWidthSB->value();
1809                 rc.geometry_height = windowHeightSB->value();
1810         }
1811         rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1812         rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1813         rc.autosave = autoSaveSB->value() * 60;
1814         rc.make_backup = autoSaveCB->isChecked();
1815         rc.num_lastfiles = lastfilesSB->value();
1816 }
1817
1818
1819 void PrefUserInterface::update(LyXRC const & rc)
1820 {
1821         uiFileED->setText(toqstr(external_path(rc.ui_file)));
1822         bindFileED->setText(toqstr(external_path(rc.bind_file)));
1823         restoreCursorCB->setChecked(rc.use_lastfilepos);
1824         loadSessionCB->setChecked(rc.load_session);
1825         bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1826         loadWindowSizeCB->setChecked(loadWindowSize);
1827         if (!loadWindowSize) {
1828                 windowWidthSB->setValue(rc.geometry_width);
1829                 windowHeightSB->setValue(rc.geometry_height);
1830         }
1831         loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1832         cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1833         // convert to minutes
1834         int mins(rc.autosave / 60);
1835         if (rc.autosave && !mins)
1836                 mins = 1;
1837         autoSaveSB->setValue(mins);
1838         autoSaveCB->setChecked(rc.make_backup);
1839         lastfilesSB->setValue(rc.num_lastfiles);
1840 }
1841
1842
1843
1844 void PrefUserInterface::select_ui()
1845 {
1846         docstring const name =
1847                 from_utf8(internal_path(fromqstr(uiFileED->text())));
1848         docstring file(form_->controller().browseUI(name));
1849         if (!file.empty())
1850                 uiFileED->setText(toqstr(file));
1851 }
1852
1853
1854 void PrefUserInterface::select_bind()
1855 {
1856         docstring const name =
1857                 from_utf8(internal_path(fromqstr(bindFileED->text())));
1858         docstring file(form_->controller().browsebind(name));
1859         if (!file.empty())
1860                 bindFileED->setText(toqstr(file));
1861 }
1862
1863
1864 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1865 {
1866         windowWidthLA->setDisabled(loadwindowsize);
1867         windowHeightLA->setDisabled(loadwindowsize);
1868         windowWidthSB->setDisabled(loadwindowsize);
1869         windowHeightSB->setDisabled(loadwindowsize);
1870 }
1871
1872
1873 PrefIdentity::PrefIdentity(QWidget * parent)
1874 : PrefModule(docstring(), _("Identity"), 0, parent)
1875 {
1876         setupUi(this);
1877
1878         connect(nameED, SIGNAL(textChanged(const QString&)),
1879                 this, SIGNAL(changed()));
1880         connect(emailED, SIGNAL(textChanged(const QString&)),
1881                 this, SIGNAL(changed()));
1882 }
1883
1884
1885 void PrefIdentity::apply(LyXRC & rc) const
1886 {
1887         rc.user_name = fromqstr(nameED->text());
1888         rc.user_email = fromqstr(emailED->text());
1889 }
1890
1891
1892 void PrefIdentity::update(LyXRC const & rc)
1893 {
1894         nameED->setText(toqstr(rc.user_name));
1895         emailED->setText(toqstr(rc.user_email));
1896 }
1897
1898
1899
1900 /////////////////////////////////////////////////////////////////////
1901 //
1902 // QPrefsDialog
1903 //
1904 /////////////////////////////////////////////////////////////////////
1905
1906 QPrefsDialog::QPrefsDialog(QPrefs * form)
1907         : form_(form)
1908 {
1909         setupUi(this);
1910         QDialog::setModal(false);
1911
1912         connect(savePB, SIGNAL(clicked()), form, SLOT(slotOK()));
1913         connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
1914         connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
1915         connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
1916
1917         add(new PrefUserInterface(form_));
1918         add(new PrefScreenFonts(form_));
1919         add(new PrefColors(form_));
1920         add(new PrefDisplay);
1921         add(new PrefKeyboard(form_));
1922
1923         add(new PrefPaths(form_));
1924
1925         add(new PrefIdentity);
1926
1927         add(new PrefLanguage);
1928         add(new PrefSpellchecker(form_));
1929
1930         add(new PrefPrinter);
1931         add(new PrefDate);
1932         add(new PrefPlaintext);
1933         add(new PrefLatex(form_));
1934
1935 #if defined(__CYGWIN__) || defined(_WIN32)
1936         add(new PrefCygwinPath);
1937 #endif
1938
1939
1940         PrefConverters * converters = new PrefConverters(form_);
1941         PrefFileformats * formats = new PrefFileformats(form_);
1942         connect(formats, SIGNAL(formatsChanged()),
1943                         converters, SLOT(updateGui()));
1944         add(converters);
1945         add(formats);
1946
1947         add(new PrefCopiers(form_));
1948
1949
1950         prefsPS->setCurrentPanel(_("User interface"));
1951 // FIXME: hack to work around resizing bug in Qt >= 4.2
1952 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1953 #if QT_VERSION >= 0x040200
1954         prefsPS->updateGeometry();
1955 #endif
1956
1957         form_->bcview().setOK(savePB);
1958         form_->bcview().setApply(applyPB);
1959         form_->bcview().setCancel(closePB);
1960         form_->bcview().setRestore(restorePB);
1961 }
1962
1963
1964 void QPrefsDialog::add(PrefModule * module)
1965 {
1966         BOOST_ASSERT(module);
1967
1968 //      if (module->category().empty())
1969 //              prefsPS->addPanel(module, module->title());
1970 //      else
1971                 prefsPS->addPanel(module, module->title(), module->category());
1972
1973         connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1974
1975         modules_.push_back(module);
1976 }
1977
1978 void QPrefsDialog::closeEvent(QCloseEvent * e)
1979 {
1980         form_->slotWMHide();
1981         e->accept();
1982 }
1983
1984
1985 void QPrefsDialog::change_adaptor()
1986 {
1987         form_->changed();
1988 }
1989
1990
1991 void QPrefsDialog::apply(LyXRC & rc) const
1992 {
1993         size_t end = modules_.size();
1994         for (size_t i = 0; i != end; ++i)
1995                 modules_[i]->apply(rc);
1996 }
1997
1998
1999 void QPrefsDialog::updateRc(LyXRC const & rc)
2000 {
2001         size_t const end = modules_.size();
2002         for (size_t i = 0; i != end; ++i)
2003                 modules_[i]->update(rc);
2004 }
2005
2006
2007 /////////////////////////////////////////////////////////////////////
2008 //
2009 // QPrefs
2010 //
2011 /////////////////////////////////////////////////////////////////////
2012
2013 typedef QController<ControlPrefs, QView<QPrefsDialog> > PrefsBase;
2014
2015 QPrefs::QPrefs(Dialog & parent)
2016         : PrefsBase(parent, _("Preferences"))
2017 {
2018 }
2019
2020 Converters & QPrefs::converters()
2021 {
2022         return controller().converters();
2023 }
2024
2025 Formats & QPrefs::formats()
2026 {
2027         return controller().formats();
2028 }
2029
2030 Movers & QPrefs::movers()
2031 {
2032         return controller().movers();
2033 }
2034
2035 void QPrefs::build_dialog()
2036 {
2037         dialog_.reset(new QPrefsDialog(this));
2038 }
2039
2040 void QPrefs::apply()
2041 {
2042         dialog_->apply(controller().rc());
2043 }
2044
2045 void QPrefs::update_contents()
2046 {
2047         dialog_->updateRc(controller().rc());
2048 }
2049
2050 } // namespace frontend
2051 } // namespace lyx
2052
2053 #include "QPrefs_moc.cpp"