]> git.lyx.org Git - features.git/blob - src/frontends/qt4/QPrefs.cpp
50879fdc83ab515bcbf06bb875484227bc1473ce
[features.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 "LColor.h"
22 #include "LyXFont.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[LyXFont::SIZE_TINY] = fromqstr(screenTinyED->text());
441         rc.font_sizes[LyXFont::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
442         rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
443         rc.font_sizes[LyXFont::SIZE_SMALL] = fromqstr(screenSmallED->text());
444         rc.font_sizes[LyXFont::SIZE_NORMAL] = fromqstr(screenNormalED->text());
445         rc.font_sizes[LyXFont::SIZE_LARGE] = fromqstr(screenLargeED->text());
446         rc.font_sizes[LyXFont::SIZE_LARGER] = fromqstr(screenLargerED->text());
447         rc.font_sizes[LyXFont::SIZE_LARGEST] = fromqstr(screenLargestED->text());
448         rc.font_sizes[LyXFont::SIZE_HUGE] = fromqstr(screenHugeED->text());
449         rc.font_sizes[LyXFont::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[LyXFont::SIZE_TINY]));
477         screenSmallestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SCRIPT]));
478         screenSmallerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]));
479         screenSmallED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SMALL]));
480         screenNormalED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_NORMAL]));
481         screenLargeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGE]));
482         screenLargerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGER]));
483         screenLargestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGEST]));
484         screenHugeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGE]));
485         screenHugerED->setText(toqstr(rc.font_sizes[LyXFont::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         for (int i = 0; i < LColor::ignore; ++i) {
521                 LColor::color lc = static_cast<LColor::color>(i);
522                 if (lc == LColor::none
523                         || lc == LColor::black
524                         || lc == LColor::white
525                         || lc == LColor::red
526                         || lc == LColor::green
527                         || lc == LColor::blue
528                         || lc == LColor::cyan
529                         || lc == LColor::magenta
530                         || lc == LColor::yellow
531                         || lc == LColor::inherit
532                         || lc == LColor::ignore) continue;
533
534                 lcolors_.push_back(lc);
535                 QColor color = QColor(guiApp->colorCache().get(lc));
536                 curcolors_.push_back(color.name());
537                 QPixmap coloritem(32, 32);
538                 coloritem.fill(color);
539                 // This is not a memory leak:
540                 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(coloritem),
541                         toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
542         }
543         newcolors_ = curcolors_;
544         // End initialization
545
546         connect(colorChangePB, SIGNAL(clicked()),
547                 this, SLOT(change_color()));
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         // HACK The following line is needed because the values are not 
560         // re-initialized in ControlPrefs::initialiseParams but are only 
561         // initialized in the constructor. But the constructor is only called 
562         // once, when the dialog if first created, and is not called again when 
563         // Tools > Preferences is selected a second time: It's just called up 
564         // from memory. [See QDialogView::show(): if (!form) { build(); }.]
565         curcolors_ = newcolors_;
566 }
567
568
569 // FIXME The fact that this method is empty is also a symptom of the
570 // problem here.
571 void PrefColors::update(LyXRC const & /*rc*/)
572 {
573 }
574
575 void PrefColors::change_color()
576 {
577         int const row = lyxObjectsLW->currentRow();
578         QString color = newcolors_[row];
579         QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget()));
580
581         if (c.name() != color) {
582                 newcolors_[row] = c.name();
583                 QPixmap coloritem(32, 32);
584                 coloritem.fill(c);
585                 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
586                 // emit signal
587                 changed();
588         }
589 }
590
591
592 /////////////////////////////////////////////////////////////////////
593 //
594 // PrefCygwinPath
595 //
596 /////////////////////////////////////////////////////////////////////
597
598 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
599         : PrefModule(_(Outputs), _("Paths"), 0, parent)
600 {
601         setupUi(this);
602         connect(pathCB, SIGNAL(clicked()), this, SIGNAL(changed()));
603 }
604
605
606 void PrefCygwinPath::apply(LyXRC & rc) const
607 {
608         rc.windows_style_tex_paths = pathCB->isChecked();
609 }
610
611
612 void PrefCygwinPath::update(LyXRC const & rc)
613 {
614         pathCB->setChecked(rc.windows_style_tex_paths);
615 }
616
617
618 /////////////////////////////////////////////////////////////////////
619 //
620 // PrefDisplay
621 //
622 /////////////////////////////////////////////////////////////////////
623
624 PrefDisplay::PrefDisplay(QWidget * parent)
625         : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
626 {
627         setupUi(this);
628         connect(instantPreviewCO, SIGNAL(activated(int)),
629                 this, SIGNAL(changed()));
630         connect(displayGraphicsCO, SIGNAL(activated(int)),
631                 this, SIGNAL(changed()));
632 }
633
634
635 void PrefDisplay::apply(LyXRC & rc) const
636 {
637         switch (instantPreviewCO->currentIndex()) {
638         case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
639         case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
640         case 2: rc.preview = LyXRC::PREVIEW_ON; break;
641         }
642
643         lyx::graphics::DisplayType dtype;
644         switch (displayGraphicsCO->currentIndex()) {
645         case 3: dtype = lyx::graphics::NoDisplay; break;
646         case 2: dtype = lyx::graphics::ColorDisplay; break;
647         case 1: dtype = lyx::graphics::GrayscaleDisplay;        break;
648         case 0: dtype = lyx::graphics::MonochromeDisplay; break;
649         default: dtype = lyx::graphics::GrayscaleDisplay;
650         }
651         rc.display_graphics = dtype;
652
653 #ifdef WITH_WARNINGS
654 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
655 #endif
656 #if 0
657         if (old_value != rc.display_graphics) {
658                 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
659                 gc.changeDisplay();
660         }
661 #endif
662 }
663
664
665 void PrefDisplay::update(LyXRC const & rc)
666 {
667         switch (rc.preview) {
668         case LyXRC::PREVIEW_OFF:
669                 instantPreviewCO->setCurrentIndex(0);
670                 break;
671         case LyXRC::PREVIEW_NO_MATH :
672                 instantPreviewCO->setCurrentIndex(1);
673                 break;
674         case LyXRC::PREVIEW_ON :
675                 instantPreviewCO->setCurrentIndex(2);
676                 break;
677         }
678
679         int item = 2;
680         switch (rc.display_graphics) {
681                 case lyx::graphics::NoDisplay:          item = 3; break;
682                 case lyx::graphics::ColorDisplay:       item = 2; break;
683                 case lyx::graphics::GrayscaleDisplay:   item = 1; break;
684                 case lyx::graphics::MonochromeDisplay:  item = 0; break;
685                 default: break;
686         }
687         displayGraphicsCO->setCurrentIndex(item);
688 }
689
690
691 /////////////////////////////////////////////////////////////////////
692 //
693 // PrefPaths
694 //
695 /////////////////////////////////////////////////////////////////////
696
697 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
698         : PrefModule(docstring(), _("Paths"), form, parent)
699 {
700         setupUi(this);
701         connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
702         connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
703         connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
704         connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
705         connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
706         connect(workingDirED, SIGNAL(textChanged(const QString&)),
707                 this, SIGNAL(changed()));
708         connect(templateDirED, SIGNAL(textChanged(const QString&)),
709                 this, SIGNAL(changed()));
710         connect(backupDirED, SIGNAL(textChanged(const QString&)),
711                 this, SIGNAL(changed()));
712         connect(tempDirED, SIGNAL(textChanged(const QString&)),
713                 this, SIGNAL(changed()));
714         connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
715                 this, SIGNAL(changed()));
716         connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
717                 this, SIGNAL(changed()));
718 }
719
720
721 void PrefPaths::apply(LyXRC & rc) const
722 {
723         rc.document_path = internal_path(fromqstr(workingDirED->text()));
724         rc.template_path = internal_path(fromqstr(templateDirED->text()));
725         rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
726         rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
727         rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
728         // FIXME: should be a checkbox only
729         rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
730 }
731
732
733 void PrefPaths::update(LyXRC const & rc)
734 {
735         workingDirED->setText(toqstr(external_path(rc.document_path)));
736         templateDirED->setText(toqstr(external_path(rc.template_path)));
737         backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
738         tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
739         pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
740         // FIXME: should be a checkbox only
741         lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
742 }
743
744
745 void PrefPaths::select_templatedir()
746 {
747         docstring file(form_->controller().browsedir(
748                 from_utf8(internal_path(fromqstr(templateDirED->text()))),
749                 _("Select a document templates directory")));
750         if (!file.empty())
751                 templateDirED->setText(toqstr(file));
752 }
753
754
755 void PrefPaths::select_tempdir()
756 {
757         docstring file(form_->controller().browsedir(
758                 from_utf8(internal_path(fromqstr(tempDirED->text()))),
759                 _("Select a temporary directory")));
760         if (!file.empty())
761                 tempDirED->setText(toqstr(file));
762 }
763
764
765 void PrefPaths::select_backupdir()
766 {
767         docstring file(form_->controller().browsedir(
768                 from_utf8(internal_path(fromqstr(backupDirED->text()))),
769                 _("Select a backups directory")));
770         if (!file.empty())
771                 backupDirED->setText(toqstr(file));
772 }
773
774
775 void PrefPaths::select_workingdir()
776 {
777         docstring file(form_->controller().browsedir(
778                 from_utf8(internal_path(fromqstr(workingDirED->text()))),
779                 _("Select a document directory")));
780         if (!file.empty())
781                 workingDirED->setText(toqstr(file));
782 }
783
784
785 void PrefPaths::select_lyxpipe()
786 {
787         docstring file(form_->controller().browse(
788                 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
789                 _("Give a filename for the LyX server pipe")));
790         if (!file.empty())
791                 lyxserverDirED->setText(toqstr(file));
792 }
793
794
795 /////////////////////////////////////////////////////////////////////
796 //
797 // PrefSpellchecker
798 //
799 /////////////////////////////////////////////////////////////////////
800
801 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
802         : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
803 {
804         setupUi(this);
805
806         connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
807 #if defined (USE_ISPELL)
808         connect(spellCommandCO, SIGNAL(activated(int)),
809                 this, SIGNAL(changed()));
810 #else
811         spellCommandCO->setEnabled(false);
812 #endif
813         connect(altLanguageED, SIGNAL(textChanged(const QString&)),
814                 this, SIGNAL(changed()));
815         connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
816                 this, SIGNAL(changed()));
817         connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
818                 this, SIGNAL(changed()));
819         connect(compoundWordCB, SIGNAL(clicked()),
820                 this, SIGNAL(changed()));
821         connect(inputEncodingCB, SIGNAL(clicked()),
822                 this, SIGNAL(changed()));
823
824         spellCommandCO->addItem(qt_("ispell"));
825         spellCommandCO->addItem(qt_("aspell"));
826         spellCommandCO->addItem(qt_("hspell"));
827 #ifdef USE_PSPELL
828         spellCommandCO->addItem(qt_("pspell (library)"));
829 #else
830 #ifdef USE_ASPELL
831         spellCommandCO->addItem(qt_("aspell (library)"));
832 #endif
833 #endif
834 }
835
836
837 void PrefSpellchecker::apply(LyXRC & rc) const
838 {
839         switch (spellCommandCO->currentIndex()) {
840                 case 0:
841                 case 1:
842                 case 2:
843                         rc.use_spell_lib = false;
844                         rc.isp_command = fromqstr(spellCommandCO->currentText());
845                         break;
846                 case 3:
847                         rc.use_spell_lib = true;
848                         break;
849         }
850
851         // FIXME: remove isp_use_alt_lang
852         rc.isp_alt_lang = fromqstr(altLanguageED->text());
853         rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
854         // FIXME: remove isp_use_esc_chars
855         rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
856         rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
857         // FIXME: remove isp_use_pers_dict
858         rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
859         rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
860         rc.isp_accept_compound = compoundWordCB->isChecked();
861         rc.isp_use_input_encoding = inputEncodingCB->isChecked();
862 }
863
864
865 void PrefSpellchecker::update(LyXRC const & rc)
866 {
867         spellCommandCO->setCurrentIndex(0);
868
869         if (rc.isp_command == "ispell") {
870                 spellCommandCO->setCurrentIndex(0);
871         } else if (rc.isp_command == "aspell") {
872                 spellCommandCO->setCurrentIndex(1);
873         } else if (rc.isp_command == "hspell") {
874                 spellCommandCO->setCurrentIndex(2);
875         }
876
877         if (rc.use_spell_lib) {
878 #if defined(USE_ASPELL) || defined(USE_PSPELL)
879                 spellCommandCO->setCurrentIndex(3);
880 #endif
881         }
882
883         // FIXME: remove isp_use_alt_lang
884         altLanguageED->setText(toqstr(rc.isp_alt_lang));
885         // FIXME: remove isp_use_esc_chars
886         escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
887         // FIXME: remove isp_use_pers_dict
888         persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
889         compoundWordCB->setChecked(rc.isp_accept_compound);
890         inputEncodingCB->setChecked(rc.isp_use_input_encoding);
891 }
892
893
894 void PrefSpellchecker::select_dict()
895 {
896         docstring file(form_->controller().browsedict(
897                 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
898         if (!file.empty())
899                 persDictionaryED->setText(toqstr(file));
900 }
901
902
903
904 /////////////////////////////////////////////////////////////////////
905 //
906 // PrefConverters
907 //
908 /////////////////////////////////////////////////////////////////////
909
910
911 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
912         : PrefModule(docstring(), _("Converters"), form, parent)
913 {
914         setupUi(this);
915
916         connect(converterNewPB, SIGNAL(clicked()),
917                 this, SLOT(update_converter()));
918         connect(converterRemovePB, SIGNAL(clicked()),
919                 this, SLOT(remove_converter()));
920         connect(converterModifyPB, SIGNAL(clicked()),
921                 this, SLOT(update_converter()));
922         connect(convertersLW, SIGNAL(currentRowChanged(int)),
923                 this, SLOT(switch_converter()));
924         connect(converterFromCO, SIGNAL(activated(const QString&)),
925                 this, SLOT(converter_changed()));
926         connect(converterToCO, SIGNAL(activated(const QString&)),
927                 this, SLOT(converter_changed()));
928         connect(converterED, SIGNAL(textChanged(const QString&)),
929                 this, SLOT(converter_changed()));
930         connect(converterFlagED, SIGNAL(textChanged(const QString&)),
931                 this, SLOT(converter_changed()));
932         connect(converterNewPB, SIGNAL(clicked()),
933                 this, SIGNAL(changed()));
934         connect(converterRemovePB, SIGNAL(clicked()),
935                 this, SIGNAL(changed()));
936         connect(converterModifyPB, SIGNAL(clicked()),
937                 this, SIGNAL(changed()));
938         connect(maxAgeLE, SIGNAL(textChanged(const QString&)),
939                 this, SIGNAL(changed()));
940
941         maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
942         converterDefGB->setFocusProxy(convertersLW);
943 }
944
945
946 void PrefConverters::apply(LyXRC & rc) const
947 {
948         rc.use_converter_cache = cacheCB->isChecked();
949         rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
950 }
951
952
953 void PrefConverters::update(LyXRC const & rc)
954 {
955         cacheCB->setChecked(rc.use_converter_cache);
956         QString max_age;
957         max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
958         maxAgeLE->setText(max_age);
959         updateGui();
960 }
961
962
963 void PrefConverters::updateGui()
964 {
965         // save current selection
966         QString current = converterFromCO->currentText()
967                 + " -> " + converterToCO->currentText();
968
969         converterFromCO->clear();
970         converterToCO->clear();
971
972         Formats::const_iterator cit = form_->formats().begin();
973         Formats::const_iterator end = form_->formats().end();
974         for (; cit != end; ++cit) {
975                 converterFromCO->addItem(toqstr(cit->prettyname()));
976                 converterToCO->addItem(toqstr(cit->prettyname()));
977         }
978
979         // currentRowChanged(int) is also triggered when updating the listwidget
980         // block signals to avoid unnecessary calls to switch_converter()
981         convertersLW->blockSignals(true);
982         convertersLW->clear();
983
984         Converters::const_iterator ccit = form_->converters().begin();
985         Converters::const_iterator cend = form_->converters().end();
986         for (; ccit != cend; ++ccit) {
987                 std::string const name =
988                         ccit->From->prettyname() + " -> " + ccit->To->prettyname();
989                 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
990                 new QListWidgetItem(toqstr(name), convertersLW, type);
991         }
992         convertersLW->sortItems(Qt::AscendingOrder);
993         convertersLW->blockSignals(false);
994
995         // restore selection
996         if (!current.isEmpty()) {
997                 QList<QListWidgetItem *> const item =
998                         convertersLW->findItems(current, Qt::MatchExactly);
999                 if (item.size()>0)
1000                         convertersLW->setCurrentItem(item.at(0));
1001         }
1002
1003         // select first element if restoring failed
1004         if (convertersLW->currentRow() == -1)
1005                 convertersLW->setCurrentRow(0);
1006
1007         updateButtons();
1008 }
1009
1010
1011 void PrefConverters::switch_converter()
1012 {
1013         int const cnr = convertersLW->currentItem()->type();
1014         Converter const & c(form_->converters().get(cnr));
1015         converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1016         converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1017         converterED->setText(toqstr(c.command));
1018         converterFlagED->setText(toqstr(c.flags));
1019
1020         updateButtons();
1021 }
1022
1023
1024 void PrefConverters::converter_changed()
1025 {
1026         updateButtons();
1027 }
1028
1029
1030 void PrefConverters::updateButtons()
1031 {
1032         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1033         Format const & to(form_->formats().get(converterToCO->currentIndex()));
1034         int const sel = form_->converters().getNumber(from.name(), to.name());
1035         bool const known = !(sel < 0);
1036         bool const valid = !(converterED->text().isEmpty()
1037                 || from.name() == to.name());
1038
1039         int const cnr = convertersLW->currentItem()->type();
1040         Converter const & c(form_->converters().get(cnr));
1041         string const old_command = c.command;
1042         string const old_flag = c.flags;
1043         string const new_command(fromqstr(converterED->text()));
1044         string const new_flag(fromqstr(converterFlagED->text()));
1045
1046         bool modified = ((old_command != new_command) || (old_flag != new_flag));
1047
1048         converterModifyPB->setEnabled(valid && known && modified);
1049         converterNewPB->setEnabled(valid && !known);
1050         converterRemovePB->setEnabled(known);
1051
1052         maxAgeLE->setEnabled(cacheCB->isChecked());
1053         maxAgeLA->setEnabled(cacheCB->isChecked());
1054 }
1055
1056
1057 // FIXME: user must
1058 // specify unique from/to or it doesn't appear. This is really bad UI
1059 // this is why we can use the same function for both new and modify
1060 void PrefConverters::update_converter()
1061 {
1062         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1063         Format const & to(form_->formats().get(converterToCO->currentIndex()));
1064         string const flags = fromqstr(converterFlagED->text());
1065         string const command = fromqstr(converterED->text());
1066
1067         Converter const * old = form_->converters().getConverter(from.name(), to.name());
1068         form_->converters().add(from.name(), to.name(), command, flags);
1069         if (!old) {
1070                 form_->converters().updateLast(form_->formats());
1071         }
1072
1073         updateGui();
1074 }
1075
1076
1077 void PrefConverters::remove_converter()
1078 {
1079         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1080         Format const & to(form_->formats().get(converterToCO->currentIndex()));
1081         form_->converters().erase(from.name(), to.name());
1082
1083         updateGui();
1084 }
1085
1086
1087 void PrefConverters::on_cacheCB_stateChanged(int state)
1088 {
1089         maxAgeLE->setEnabled(state == Qt::Checked);
1090         maxAgeLA->setEnabled(state == Qt::Checked);
1091         changed();
1092 }
1093
1094
1095 /////////////////////////////////////////////////////////////////////
1096 //
1097 // PrefCopiers
1098 //
1099 /////////////////////////////////////////////////////////////////////
1100
1101 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1102         : PrefModule(docstring(), _("Copiers"), form, parent)
1103 {
1104         setupUi(this);
1105
1106         connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1107         connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1108         connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1109         connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1110                 this, SLOT(switch_copierLB(int)));
1111         connect(copierFormatCO, SIGNAL(activated(int)),
1112                 this, SLOT(switch_copierCO(int)));
1113         connect(copierNewPB, SIGNAL(clicked()),
1114                 this, SIGNAL(changed()));
1115         connect(copierRemovePB, SIGNAL(clicked()),
1116                 this, SIGNAL(changed()));
1117         connect(copierModifyPB, SIGNAL(clicked()),
1118                 this, SIGNAL(changed()));
1119         connect(copierFormatCO, SIGNAL(activated(const QString &)),
1120                 this, SLOT(copiers_changed()));
1121         connect(copierED, SIGNAL(textChanged(const QString &)),
1122                 this, SLOT(copiers_changed()));
1123 }
1124
1125
1126 void PrefCopiers::apply(LyXRC & /*rc*/) const
1127 {
1128 }
1129
1130
1131 void PrefCopiers::update(LyXRC const & /*rc*/)
1132 {
1133         update();
1134 }
1135
1136
1137 void PrefCopiers::update()
1138 {
1139         // The choice widget
1140         // save current selection
1141         QString current = copierFormatCO->currentText();
1142         copierFormatCO->clear();
1143
1144         for (Formats::const_iterator it = form_->formats().begin(),
1145                      end = form_->formats().end();
1146              it != end; ++it) {
1147                 copierFormatCO->addItem(toqstr(it->prettyname()));
1148         }
1149
1150         // The browser widget
1151         AllCopiersLW->clear();
1152
1153         for (Movers::const_iterator it = form_->movers().begin(),
1154                      end = form_->movers().end();
1155              it != end; ++it) {
1156                 std::string const & command = it->second.command();
1157                 if (command.empty())
1158                         continue;
1159                 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1160                 AllCopiersLW->addItem(pretty);
1161         }
1162         AllCopiersLW->sortItems(Qt::AscendingOrder);
1163
1164         // restore selection
1165         if (!current.isEmpty()) {
1166                 QList<QListWidgetItem *> item =
1167                         AllCopiersLW->findItems(current, Qt::MatchExactly);
1168                 if (item.size()>0)
1169                         AllCopiersLW->setCurrentItem(item.at(0));
1170         }
1171         // select first element if restoring failed
1172         if (AllCopiersLW->currentRow() == -1)
1173                 AllCopiersLW->setCurrentRow(0);
1174 }
1175
1176
1177 namespace {
1178
1179 class SamePrettyName {
1180 public:
1181         SamePrettyName(string const & n) : pretty_name_(n) {}
1182
1183         bool operator()(Format const & fmt) const {
1184                 return fmt.prettyname() == pretty_name_;
1185         }
1186
1187 private:
1188         string const pretty_name_;
1189 };
1190
1191
1192 Format const * getFormat(std::string const & prettyname)
1193 {
1194         Formats::const_iterator it = formats.begin();
1195         Formats::const_iterator const end = formats.end();
1196         it = std::find_if(it, end, SamePrettyName(prettyname));
1197         return it == end ? 0 : &*it;
1198 }
1199
1200 } // namespace anon
1201
1202
1203 void PrefCopiers::switch_copierLB(int row)
1204 {
1205         if (row < 0)
1206                 return;
1207
1208         // FIXME UNICODE?
1209         std::string const browser_text =
1210                 fromqstr(AllCopiersLW->currentItem()->text());
1211         Format const * fmt = getFormat(browser_text);
1212         if (fmt == 0)
1213                 return;
1214
1215         QString const gui_name = toqstr(fmt->prettyname());
1216         QString const command = toqstr(form_->movers().command(fmt->name()));
1217
1218         copierED->clear();
1219         int const combo_size = copierFormatCO->count();
1220         for (int i = 0; i < combo_size; ++i) {
1221                 QString const text = copierFormatCO->itemText(i);
1222                 if (text == gui_name) {
1223                         copierFormatCO->setCurrentIndex(i);
1224                         copierED->setText(command);
1225                         break;
1226                 }
1227         }
1228         updateButtons();
1229 }
1230
1231
1232 void PrefCopiers::switch_copierCO(int row)
1233 {
1234         if (row<0)
1235                 return;
1236
1237         std::string const combo_text =
1238                 fromqstr(copierFormatCO->currentText());
1239         Format const * fmt = getFormat(combo_text);
1240         if (fmt == 0)
1241                 return;
1242
1243         QString const command = toqstr(form_->movers().command(fmt->name()));
1244         copierED->setText(command);
1245
1246         QListWidgetItem * const index = AllCopiersLW->currentItem();
1247         if (index >= 0)
1248                 AllCopiersLW->setItemSelected(index, false);
1249
1250         QString const gui_name = toqstr(fmt->prettyname());
1251         int const browser_size = AllCopiersLW->count();
1252         for (int i = 0; i < browser_size; ++i) {
1253                 QString const text = AllCopiersLW->item(i)->text();
1254                 if (text == gui_name) {
1255                         QListWidgetItem * item = AllCopiersLW->item(i);
1256                         AllCopiersLW->setItemSelected(item, true);
1257                         break;
1258                 }
1259         }
1260 }
1261
1262
1263 void PrefCopiers::copiers_changed()
1264 {
1265         updateButtons();
1266 }
1267
1268
1269 void PrefCopiers::updateButtons()
1270 {
1271         QString selected = copierFormatCO->currentText();
1272
1273         bool known = false;
1274         for (int i = 0; i < AllCopiersLW->count(); ++i) {
1275                 if (AllCopiersLW->item(i)->text() == selected)
1276                         known = true;
1277         }
1278
1279         bool const valid = !copierED->text().isEmpty();
1280
1281         Format const * fmt = getFormat(fromqstr(selected));
1282         string const old_command = form_->movers().command(fmt->name());
1283         string const new_command(fromqstr(copierED->text()));
1284
1285         bool modified = (old_command != new_command);
1286
1287         copierModifyPB->setEnabled(valid && known && modified);
1288         copierNewPB->setEnabled(valid && !known);
1289         copierRemovePB->setEnabled(known);
1290 }
1291
1292
1293 void PrefCopiers::new_copier()
1294 {
1295         std::string const combo_text =
1296                 fromqstr(copierFormatCO->currentText());
1297         Format const * fmt = getFormat(combo_text);
1298         if (fmt == 0)
1299                 return;
1300
1301         string const command = fromqstr(copierED->text());
1302         if (command.empty())
1303                 return;
1304
1305         form_->movers().set(fmt->name(), command);
1306
1307         update();
1308         int const last = AllCopiersLW->count() - 1;
1309         AllCopiersLW->setCurrentRow(last);
1310
1311         updateButtons();
1312 }
1313
1314
1315 void PrefCopiers::modify_copier()
1316 {
1317         std::string const combo_text =
1318                 fromqstr(copierFormatCO->currentText());
1319         Format const * fmt = getFormat(combo_text);
1320         if (fmt == 0)
1321                 return;
1322
1323         string const command = fromqstr(copierED->text());
1324         form_->movers().set(fmt->name(), command);
1325
1326         update();
1327         updateButtons();
1328 }
1329
1330
1331 void PrefCopiers::remove_copier()
1332 {
1333         std::string const combo_text =
1334                 fromqstr(copierFormatCO->currentText());
1335         Format const * fmt = getFormat(combo_text);
1336         if (fmt == 0)
1337                 return;
1338
1339         string const & fmt_name = fmt->name();
1340         form_->movers().set(fmt_name, string());
1341
1342         update();
1343         updateButtons();
1344 }
1345
1346
1347
1348 /////////////////////////////////////////////////////////////////////
1349 //
1350 // PrefFileformats
1351 //
1352 /////////////////////////////////////////////////////////////////////
1353
1354 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1355         : PrefModule(docstring(), _("File formats"), form, parent)
1356 {
1357         setupUi(this);
1358
1359         connect(formatNewPB, SIGNAL(clicked()),
1360                 this, SLOT(new_format()));
1361         connect(formatRemovePB, SIGNAL(clicked()),
1362                 this, SLOT(remove_format()));
1363         connect(formatModifyPB, SIGNAL(clicked()),
1364                 this, SLOT(modify_format()));
1365         connect(formatsLW, SIGNAL(currentRowChanged(int)),
1366                 this, SLOT(switch_format(int)));
1367         connect(formatED, SIGNAL(textChanged(const QString&)),
1368                 this, SLOT(fileformat_changed()));
1369         connect(guiNameED, SIGNAL(textChanged(const QString&)),
1370                 this, SLOT(fileformat_changed()));
1371         connect(shortcutED, SIGNAL(textChanged(const QString&)),
1372                 this, SLOT(fileformat_changed()));
1373         connect(extensionED, SIGNAL(textChanged(const QString&)),
1374                 this, SLOT(fileformat_changed()));
1375         connect(viewerED, SIGNAL(textChanged(const QString&)),
1376                 this, SLOT(fileformat_changed()));
1377         connect(editorED, SIGNAL(textChanged(const QString&)),
1378                 this, SLOT(fileformat_changed()));
1379         connect(documentCB, SIGNAL(clicked()),
1380                 this, SLOT(fileformat_changed()));
1381         connect(vectorCB, SIGNAL(clicked()),
1382                 this, SLOT(fileformat_changed()));
1383         connect(formatNewPB, SIGNAL(clicked()),
1384                 this, SIGNAL(changed()));
1385         connect(formatRemovePB, SIGNAL(clicked()),
1386                 this, SIGNAL(changed()));
1387         connect(formatModifyPB, SIGNAL(clicked()),
1388                 this, SIGNAL(changed()));
1389 }
1390
1391
1392 void PrefFileformats::apply(LyXRC & /*rc*/) const
1393 {
1394 }
1395
1396
1397 void PrefFileformats::update(LyXRC const & /*rc*/)
1398 {
1399         update();
1400 }
1401
1402
1403 void PrefFileformats::update()
1404 {
1405         // save current selection
1406         QString current = guiNameED->text();
1407
1408         // update listwidget with formats
1409         formatsLW->blockSignals(true);
1410         formatsLW->clear();
1411         Formats::const_iterator cit = form_->formats().begin();
1412         Formats::const_iterator end = form_->formats().end();
1413         for (; cit != end; ++cit) {
1414                 new QListWidgetItem(toqstr(cit->prettyname()),
1415                                                         formatsLW,
1416                                                         form_->formats().getNumber(cit->name()) );
1417         }
1418         formatsLW->sortItems(Qt::AscendingOrder);
1419         formatsLW->blockSignals(false);
1420
1421         // restore selection
1422         if (!current.isEmpty()) {
1423                 QList<QListWidgetItem *>  item = formatsLW->findItems(current, Qt::MatchExactly);
1424                 if (item.size()>0)
1425                         formatsLW->setCurrentItem(item.at(0));
1426         }
1427         // select first element if restoring failed
1428         if (formatsLW->currentRow() == -1)
1429                 formatsLW->setCurrentRow(0);
1430 }
1431
1432
1433 void PrefFileformats::switch_format(int nr)
1434 {
1435         int const ftype = formatsLW->item(nr)->type();
1436         Format const f = form_->formats().get(ftype);
1437
1438         formatED->setText(toqstr(f.name()));
1439         guiNameED->setText(toqstr(f.prettyname()));
1440         extensionED->setText(toqstr(f.extension()));
1441         shortcutED->setText(toqstr(f.shortcut()));
1442         viewerED->setText(toqstr(f.viewer()));
1443         editorED->setText(toqstr(f.editor()));
1444         documentCB->setChecked((f.documentFormat()));
1445         vectorCB->setChecked((f.vectorFormat()));
1446
1447         updateButtons();
1448 }
1449
1450
1451 void PrefFileformats::fileformat_changed()
1452 {
1453         updateButtons();
1454 }
1455
1456
1457 void PrefFileformats::updateButtons()
1458 {
1459         QString const format = formatED->text();
1460         QString const gui_name = guiNameED->text();
1461         int const sel = form_->formats().getNumber(fromqstr(format));
1462         bool gui_name_known = false;
1463         int where = sel;
1464         for (int i = 0; i < formatsLW->count(); ++i) {
1465                 if (formatsLW->item(i)->text() == gui_name) {
1466                         gui_name_known = true;
1467                         where = formatsLW->item(i)->type();
1468                 }
1469         }
1470
1471         // assure that a gui name cannot be chosen twice
1472         bool const known_otherwise = gui_name_known && (where != sel);
1473
1474         bool const known = !(sel < 0);
1475         bool const valid = (!formatED->text().isEmpty()
1476                 && !guiNameED->text().isEmpty());
1477
1478         int const ftype = formatsLW->currentItem()->type();
1479         Format const & f(form_->formats().get(ftype));
1480         string const old_pretty(f.prettyname());
1481         string const old_shortcut(f.shortcut());
1482         string const old_extension(f.extension());
1483         string const old_viewer(f.viewer());
1484         string const old_editor(f.editor());
1485         bool const old_document(f.documentFormat());
1486         bool const old_vector(f.vectorFormat());
1487
1488         string const new_pretty(fromqstr(gui_name));
1489         string const new_shortcut(fromqstr(shortcutED->text()));
1490         string const new_extension(fromqstr(extensionED->text()));
1491         string const new_viewer(fromqstr(viewerED->text()));
1492         string const new_editor(fromqstr(editorED->text()));
1493         bool const new_document(documentCB->isChecked());
1494         bool const new_vector(vectorCB->isChecked());
1495
1496         bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1497                 || (old_extension != new_extension) || (old_viewer != new_viewer)
1498                 || old_editor != new_editor || old_document != new_document
1499                 || old_vector != new_vector);
1500
1501         formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1502         formatNewPB->setEnabled(valid && !known && !gui_name_known);
1503         formatRemovePB->setEnabled(known);
1504 }
1505
1506
1507 void PrefFileformats::new_format()
1508 {
1509         string const name = fromqstr(formatED->text());
1510         string const prettyname = fromqstr(guiNameED->text());
1511         string const extension = fromqstr(extensionED->text());
1512         string const shortcut = fromqstr(shortcutED->text());
1513         string const viewer = fromqstr(viewerED->text());
1514         string const editor = fromqstr(editorED->text());
1515         int flags = Format::none;
1516         if (documentCB->isChecked())
1517                 flags |= Format::document;
1518         if (vectorCB->isChecked())
1519                 flags |= Format::vector;
1520
1521         form_->formats().add(name, extension, prettyname, shortcut, viewer,
1522                              editor, flags);
1523         form_->formats().sort();
1524         form_->converters().update(form_->formats());
1525
1526         update();
1527         updateButtons();
1528         formatsChanged();
1529 }
1530
1531
1532 void PrefFileformats::modify_format()
1533 {
1534         int const current_item = formatsLW->currentItem()->type();
1535         Format const & oldformat = form_->formats().get(current_item);
1536         form_->formats().erase(oldformat.name());
1537
1538         new_format();
1539 }
1540
1541
1542 void PrefFileformats::remove_format()
1543 {
1544         int const nr = formatsLW->currentItem()->type();
1545         string const current_text = form_->formats().get(nr).name();
1546         if (form_->converters().formatIsUsed(current_text)) {
1547                 Alert::error(_("Format in use"),
1548                              _("Cannot remove a Format used by a Converter. "
1549                                             "Remove the converter first."));
1550                 return;
1551         }
1552
1553         form_->formats().erase(current_text);
1554         form_->converters().update(form_->formats());
1555
1556         update();
1557         updateButtons();
1558         formatsChanged();
1559 }
1560
1561
1562 /////////////////////////////////////////////////////////////////////
1563 //
1564 // PrefLanguage
1565 //
1566 /////////////////////////////////////////////////////////////////////
1567
1568 PrefLanguage::PrefLanguage(QWidget * parent)
1569         : PrefModule(_(LanguageSettings), _("Language"), 0, parent)
1570 {
1571         setupUi(this);
1572
1573         connect(rtlCB, SIGNAL(clicked()),
1574                 this, SIGNAL(changed()));
1575         connect(markForeignCB, SIGNAL(clicked()),
1576                 this, SIGNAL(changed()));
1577         connect(autoBeginCB, SIGNAL(clicked()),
1578                 this, SIGNAL(changed()));
1579         connect(autoEndCB, SIGNAL(clicked()),
1580                 this, SIGNAL(changed()));
1581         connect(useBabelCB, SIGNAL(clicked()),
1582                 this, SIGNAL(changed()));
1583         connect(globalCB, SIGNAL(clicked()),
1584                 this, SIGNAL(changed()));
1585         connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1586                 this, SIGNAL(changed()));
1587         connect(startCommandED, SIGNAL(textChanged(const QString&)),
1588                 this, SIGNAL(changed()));
1589         connect(endCommandED, SIGNAL(textChanged(const QString&)),
1590                 this, SIGNAL(changed()));
1591         connect(defaultLanguageCO, SIGNAL(activated(int)),
1592                 this, SIGNAL(changed()));
1593
1594         defaultLanguageCO->clear();
1595
1596         // store the lang identifiers for later
1597         std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
1598         lang_ = getSecond(langs);
1599
1600         std::vector<LanguagePair>::const_iterator lit  = langs.begin();
1601         std::vector<LanguagePair>::const_iterator lend = langs.end();
1602         for (; lit != lend; ++lit) {
1603                 defaultLanguageCO->addItem(toqstr(lit->first));
1604         }
1605 }
1606
1607
1608 void PrefLanguage::apply(LyXRC & rc) const
1609 {
1610         // FIXME: remove rtl_support bool
1611         rc.rtl_support = rtlCB->isChecked();
1612         rc.mark_foreign_language = markForeignCB->isChecked();
1613         rc.language_auto_begin = autoBeginCB->isChecked();
1614         rc.language_auto_end = autoEndCB->isChecked();
1615         rc.language_use_babel = useBabelCB->isChecked();
1616         rc.language_global_options = globalCB->isChecked();
1617         rc.language_package = fromqstr(languagePackageED->text());
1618         rc.language_command_begin = fromqstr(startCommandED->text());
1619         rc.language_command_end = fromqstr(endCommandED->text());
1620         rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1621 }
1622
1623
1624 void PrefLanguage::update(LyXRC const & rc)
1625 {
1626         // FIXME: remove rtl_support bool
1627         rtlCB->setChecked(rc.rtl_support);
1628         markForeignCB->setChecked(rc.mark_foreign_language);
1629         autoBeginCB->setChecked(rc.language_auto_begin);
1630         autoEndCB->setChecked(rc.language_auto_end);
1631         useBabelCB->setChecked(rc.language_use_babel);
1632         globalCB->setChecked(rc.language_global_options);
1633         languagePackageED->setText(toqstr(rc.language_package));
1634         startCommandED->setText(toqstr(rc.language_command_begin));
1635         endCommandED->setText(toqstr(rc.language_command_end));
1636
1637         int const pos = int(findPos_helper(lang_, rc.default_language));
1638         defaultLanguageCO->setCurrentIndex(pos);
1639 }
1640
1641
1642 /////////////////////////////////////////////////////////////////////
1643 //
1644 // PrefPrinter
1645 //
1646 /////////////////////////////////////////////////////////////////////
1647
1648 PrefPrinter::PrefPrinter(QWidget * parent)
1649         : PrefModule(_(Outputs), _("Printer"), 0, parent)
1650 {
1651         setupUi(this);
1652
1653         connect(printerAdaptCB, SIGNAL(clicked()),
1654                 this, SIGNAL(changed()));
1655         connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1656                 this, SIGNAL(changed()));
1657         connect(printerNameED, SIGNAL(textChanged(const QString&)),
1658                 this, SIGNAL(changed()));
1659         connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1660                 this, SIGNAL(changed()));
1661         connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1662                 this, SIGNAL(changed()));
1663         connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1664                 this, SIGNAL(changed()));
1665         connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1666                 this, SIGNAL(changed()));
1667         connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1668                 this, SIGNAL(changed()));
1669         connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1670                 this, SIGNAL(changed()));
1671         connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1672                 this, SIGNAL(changed()));
1673         connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1674                 this, SIGNAL(changed()));
1675         connect(printerOddED, SIGNAL(textChanged(const QString&)),
1676                 this, SIGNAL(changed()));
1677         connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1678                 this, SIGNAL(changed()));
1679         connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1680                 this, SIGNAL(changed()));
1681         connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1682                 this, SIGNAL(changed()));
1683         connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1684                 this, SIGNAL(changed()));
1685         connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1686                 this, SIGNAL(changed()));
1687         connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1688                 this, SIGNAL(changed()));
1689 }
1690
1691
1692 void PrefPrinter::apply(LyXRC & rc) const
1693 {
1694         rc.print_adapt_output = printerAdaptCB->isChecked();
1695         rc.print_command = fromqstr(printerCommandED->text());
1696         rc.printer = fromqstr(printerNameED->text());
1697
1698         rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1699         rc.print_copies_flag = fromqstr(printerCopiesED->text());
1700         rc.print_reverse_flag = fromqstr(printerReverseED->text());
1701         rc.print_to_printer = fromqstr(printerToPrinterED->text());
1702         rc.print_file_extension = fromqstr(printerExtensionED->text());
1703         rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1704         rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1705         rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1706         rc.print_oddpage_flag = fromqstr(printerOddED->text());
1707         rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1708         rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1709         rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1710         rc.print_extra_options = fromqstr(printerExtraED->text());
1711         rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1712         rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1713 }
1714
1715
1716 void PrefPrinter::update(LyXRC const & rc)
1717 {
1718         printerAdaptCB->setChecked(rc.print_adapt_output);
1719         printerCommandED->setText(toqstr(rc.print_command));
1720         printerNameED->setText(toqstr(rc.printer));
1721
1722         printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1723         printerCopiesED->setText(toqstr(rc.print_copies_flag));
1724         printerReverseED->setText(toqstr(rc.print_reverse_flag));
1725         printerToPrinterED->setText(toqstr(rc.print_to_printer));
1726         printerExtensionED->setText(toqstr(rc.print_file_extension));
1727         printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1728         printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1729         printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1730         printerOddED->setText(toqstr(rc.print_oddpage_flag));
1731         printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1732         printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1733         printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1734         printerExtraED->setText(toqstr(rc.print_extra_options));
1735         printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1736         printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1737 }
1738
1739
1740 /////////////////////////////////////////////////////////////////////
1741 //
1742 // PrefUserInterface
1743 //
1744 /////////////////////////////////////////////////////////////////////
1745
1746 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1747         : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1748 {
1749         setupUi(this);
1750
1751         connect(autoSaveCB, SIGNAL(toggled(bool)),
1752                 autoSaveLA, SLOT(setEnabled(bool)));
1753         connect(autoSaveCB, SIGNAL(toggled(bool)),
1754                 autoSaveSB, SLOT(setEnabled(bool)));
1755         connect(autoSaveCB, SIGNAL(toggled(bool)),
1756                 TextLabel1, SLOT(setEnabled(bool)));
1757         connect(uiFilePB, SIGNAL(clicked()),
1758                 this, SLOT(select_ui()));
1759         connect(bindFilePB, SIGNAL(clicked()),
1760                 this, SLOT(select_bind()));
1761         connect(uiFileED, SIGNAL(textChanged(const QString &)),
1762                 this, SIGNAL(changed()));
1763         connect(bindFileED, SIGNAL(textChanged(const QString &)),
1764                 this, SIGNAL(changed()));
1765         connect(restoreCursorCB, SIGNAL(clicked()),
1766                 this, SIGNAL(changed()));
1767         connect(loadSessionCB, SIGNAL(clicked()),
1768                 this, SIGNAL(changed()));
1769         connect(loadWindowSizeCB, SIGNAL(clicked()),
1770                 this, SIGNAL(changed()));
1771         connect(loadWindowLocationCB, SIGNAL(clicked()),
1772                 this, SIGNAL(changed()));
1773         connect(windowWidthSB, SIGNAL(valueChanged(int)),
1774                 this, SIGNAL(changed()));
1775         connect(windowHeightSB, SIGNAL(valueChanged(int)),
1776                 this, SIGNAL(changed()));
1777         connect(cursorFollowsCB, SIGNAL(clicked()),
1778                 this, SIGNAL(changed()));
1779         connect(autoSaveSB, SIGNAL(valueChanged(int)),
1780                 this, SIGNAL(changed()));
1781         connect(autoSaveCB, SIGNAL(clicked()),
1782                 this, SIGNAL(changed()));
1783         connect(lastfilesSB, SIGNAL(valueChanged(int)),
1784                 this, SIGNAL(changed()));
1785         lastfilesSB->setMaximum(maxlastfiles);
1786 }
1787
1788
1789 void PrefUserInterface::apply(LyXRC & rc) const
1790 {
1791         rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1792         rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1793         rc.use_lastfilepos = restoreCursorCB->isChecked();
1794         rc.load_session = loadSessionCB->isChecked();
1795         if (loadWindowSizeCB->isChecked()) {
1796                 rc.geometry_width = 0;
1797                 rc.geometry_height = 0;
1798         } else {
1799                 rc.geometry_width = windowWidthSB->value();
1800                 rc.geometry_height = windowHeightSB->value();
1801         }
1802         rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1803         rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1804         rc.autosave = autoSaveSB->value() * 60;
1805         rc.make_backup = autoSaveCB->isChecked();
1806         rc.num_lastfiles = lastfilesSB->value();
1807 }
1808
1809
1810 void PrefUserInterface::update(LyXRC const & rc)
1811 {
1812         uiFileED->setText(toqstr(external_path(rc.ui_file)));
1813         bindFileED->setText(toqstr(external_path(rc.bind_file)));
1814         restoreCursorCB->setChecked(rc.use_lastfilepos);
1815         loadSessionCB->setChecked(rc.load_session);
1816         bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1817         loadWindowSizeCB->setChecked(loadWindowSize);
1818         if (!loadWindowSize) {
1819                 windowWidthSB->setValue(rc.geometry_width);
1820                 windowHeightSB->setValue(rc.geometry_height);
1821         }
1822         loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1823         cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1824         // convert to minutes
1825         int mins(rc.autosave / 60);
1826         if (rc.autosave && !mins)
1827                 mins = 1;
1828         autoSaveSB->setValue(mins);
1829         autoSaveCB->setChecked(rc.make_backup);
1830         lastfilesSB->setValue(rc.num_lastfiles);
1831 }
1832
1833
1834
1835 void PrefUserInterface::select_ui()
1836 {
1837         docstring const name =
1838                 from_utf8(internal_path(fromqstr(uiFileED->text())));
1839         docstring file(form_->controller().browseUI(name));
1840         if (!file.empty())
1841                 uiFileED->setText(toqstr(file));
1842 }
1843
1844
1845 void PrefUserInterface::select_bind()
1846 {
1847         docstring const name =
1848                 from_utf8(internal_path(fromqstr(bindFileED->text())));
1849         docstring file(form_->controller().browsebind(name));
1850         if (!file.empty())
1851                 bindFileED->setText(toqstr(file));
1852 }
1853
1854
1855 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1856 {
1857         windowWidthLA->setDisabled(loadwindowsize);
1858         windowHeightLA->setDisabled(loadwindowsize);
1859         windowWidthSB->setDisabled(loadwindowsize);
1860         windowHeightSB->setDisabled(loadwindowsize);
1861 }
1862
1863
1864 PrefIdentity::PrefIdentity(QWidget * parent)
1865 : PrefModule(docstring(), _("Identity"), 0, parent)
1866 {
1867         setupUi(this);
1868
1869         connect(nameED, SIGNAL(textChanged(const QString&)),
1870                 this, SIGNAL(changed()));
1871         connect(emailED, SIGNAL(textChanged(const QString&)),
1872                 this, SIGNAL(changed()));
1873 }
1874
1875
1876 void PrefIdentity::apply(LyXRC & rc) const
1877 {
1878         rc.user_name = fromqstr(nameED->text());
1879         rc.user_email = fromqstr(emailED->text());
1880 }
1881
1882
1883 void PrefIdentity::update(LyXRC const & rc)
1884 {
1885         nameED->setText(toqstr(rc.user_name));
1886         emailED->setText(toqstr(rc.user_email));
1887 }
1888
1889
1890
1891 /////////////////////////////////////////////////////////////////////
1892 //
1893 // QPrefsDialog
1894 //
1895 /////////////////////////////////////////////////////////////////////
1896
1897 QPrefsDialog::QPrefsDialog(QPrefs * form)
1898         : form_(form)
1899 {
1900         setupUi(this);
1901         QDialog::setModal(false);
1902
1903         connect(savePB, SIGNAL(clicked()), form, SLOT(slotOK()));
1904         connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
1905         connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
1906         connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
1907
1908         add(new PrefUserInterface(form_));
1909         add(new PrefScreenFonts(form_));
1910         add(new PrefColors(form_));
1911         add(new PrefDisplay);
1912         add(new PrefKeyboard(form_));
1913
1914         add(new PrefPaths(form_));
1915
1916         add(new PrefIdentity);
1917
1918         add(new PrefLanguage);
1919         add(new PrefSpellchecker(form_));
1920
1921         add(new PrefPrinter);
1922         add(new PrefDate);
1923         add(new PrefPlaintext);
1924         add(new PrefLatex(form_));
1925
1926 #if defined(__CYGWIN__) || defined(_WIN32)
1927         add(new PrefCygwinPath);
1928 #endif
1929
1930
1931         PrefConverters * converters = new PrefConverters(form_);
1932         PrefFileformats * formats = new PrefFileformats(form_);
1933         connect(formats, SIGNAL(formatsChanged()),
1934                         converters, SLOT(updateGui()));
1935         add(converters);
1936         add(formats);
1937
1938         add(new PrefCopiers(form_));
1939
1940
1941         prefsPS->setCurrentPanel(_("User interface"));
1942 // FIXME: hack to work around resizing bug in Qt >= 4.2
1943 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1944 #if QT_VERSION >= 0x040200
1945         prefsPS->updateGeometry();
1946 #endif
1947
1948         form_->bcview().setOK(savePB);
1949         form_->bcview().setApply(applyPB);
1950         form_->bcview().setCancel(closePB);
1951         form_->bcview().setRestore(restorePB);
1952 }
1953
1954
1955 void QPrefsDialog::add(PrefModule * module)
1956 {
1957         BOOST_ASSERT(module);
1958
1959 //      if (module->category().empty())
1960 //              prefsPS->addPanel(module, module->title());
1961 //      else
1962                 prefsPS->addPanel(module, module->title(), module->category());
1963
1964         connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1965
1966         modules_.push_back(module);
1967 }
1968
1969 void QPrefsDialog::closeEvent(QCloseEvent * e)
1970 {
1971         form_->slotWMHide();
1972         e->accept();
1973 }
1974
1975
1976 void QPrefsDialog::change_adaptor()
1977 {
1978         form_->changed();
1979 }
1980
1981
1982 void QPrefsDialog::apply(LyXRC & rc) const
1983 {
1984         size_t end = modules_.size();
1985         for (size_t i = 0; i != end; ++i)
1986                 modules_[i]->apply(rc);
1987 }
1988
1989
1990 void QPrefsDialog::updateRc(LyXRC const & rc)
1991 {
1992         size_t const end = modules_.size();
1993         for (size_t i = 0; i != end; ++i)
1994                 modules_[i]->update(rc);
1995 }
1996
1997
1998 /////////////////////////////////////////////////////////////////////
1999 //
2000 // QPrefs
2001 //
2002 /////////////////////////////////////////////////////////////////////
2003
2004 typedef QController<ControlPrefs, QView<QPrefsDialog> > PrefsBase;
2005
2006 QPrefs::QPrefs(Dialog & parent)
2007         : PrefsBase(parent, _("Preferences"))
2008 {
2009 }
2010
2011 Converters & QPrefs::converters()
2012 {
2013         return controller().converters();
2014 }
2015
2016 Formats & QPrefs::formats()
2017 {
2018         return controller().formats();
2019 }
2020
2021 Movers & QPrefs::movers()
2022 {
2023         return controller().movers();
2024 }
2025
2026 void QPrefs::build_dialog()
2027 {
2028         dialog_.reset(new QPrefsDialog(this));
2029 }
2030
2031 void QPrefs::apply()
2032 {
2033         dialog_->apply(controller().rc());
2034 }
2035
2036 void QPrefs::update_contents()
2037 {
2038         dialog_->updateRc(controller().rc());
2039 }
2040
2041 } // namespace frontend
2042 } // namespace lyx
2043
2044 #include "QPrefs_moc.cpp"