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