]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrefs.C
replace global variable bufferlist with Application class member access.
[lyx.git] / src / frontends / controllers / ControlPrefs.C
1 /**
2  * \file ControlPrefs.C
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 "ControlPrefs.h"
14
15 #include "helper_funcs.h"
16 #include "Kernel.h"
17
18 #include "gettext.h"
19 #include "funcrequest.h"
20 #include "paper.h"
21 #include "LColor.h"
22
23 #include "frontends/Application.h"
24
25 #include "support/filefilterlist.h"
26
27 #include <sstream>
28
29 using std::ostringstream;
30 using std::pair;
31 using std::string;
32 using std::vector;
33
34
35 namespace lyx {
36
37 using support::FileFilterList;
38
39 namespace frontend {
40
41
42 ControlPrefs::ControlPrefs(Dialog & parent)
43         : Dialog::Controller(parent),
44           update_screen_font_(false)
45 {}
46
47
48 bool ControlPrefs::initialiseParams(std::string const &)
49 {
50         rc_ = lyxrc;
51         formats_ = ::formats;
52         converters_ = ::converters;
53         converters_.update(formats_);
54         movers_ = ::movers;
55         colors_.clear();
56         update_screen_font_ = false;
57
58         return true;
59 }
60
61
62 void ControlPrefs::dispatchParams()
63 {
64         ostringstream ss;
65         rc_.write(ss, true);
66         kernel().dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
67
68         // FIXME: these need lfuns
69         theApp->bufferList().setCurrentAuthor(rc_.user_name, rc_.user_email);
70
71         ::formats = formats_;
72
73         ::converters = converters_;
74         ::converters.update(::formats);
75         ::converters.buildGraph();
76
77         ::movers = movers_;
78
79         vector<string>::const_iterator it = colors_.begin();
80         vector<string>::const_iterator const end = colors_.end();
81         for (; it != end; ++it)
82                 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, *it));
83         colors_.clear();
84
85         if (update_screen_font_) {
86                 kernel().dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
87                 update_screen_font_ = false;
88         }
89
90         // The Save button has been pressed
91         if (dialog().isClosing()) {
92                 kernel().dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
93         }
94 }
95
96
97 void ControlPrefs::setColor(LColor_color col, string const & hex)
98 {
99         colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
100 }
101
102
103 void ControlPrefs::updateScreenFonts()
104 {
105         update_screen_font_ = true;
106 }
107
108
109 string const ControlPrefs::browsebind(string const & file) const
110 {
111         // FIXME UNICODE
112         return browseLibFile("bind", file, "bind",
113                              lyx::to_utf8(_("Choose bind file")),
114                              FileFilterList(lyx::to_utf8(_("LyX bind files (*.bind)"))));
115 }
116
117
118 string const ControlPrefs::browseUI(string const & file) const
119 {
120         // FIXME UNICODE
121         return browseLibFile("ui", file, "ui",
122                              lyx::to_utf8(_("Choose UI file")),
123                              FileFilterList(lyx::to_utf8(_("LyX UI files (*.ui)"))));
124 }
125
126
127 string const ControlPrefs::browsekbmap(string const & file) const
128 {
129         // FIXME UNICODE
130         return browseLibFile("kbd", file, "kmap",
131                              lyx::to_utf8(_("Choose keyboard map")),
132                              FileFilterList(lyx::to_utf8(_("LyX keyboard maps (*.kmap)"))));
133 }
134
135
136 string const ControlPrefs::browsedict(string const & file) const
137 {
138         // FIXME UNICODE
139         return browseFile(file,
140                           lyx::to_utf8(_("Choose personal dictionary")),
141                           FileFilterList(lyx::to_utf8(_("*.ispell"))));
142 }
143
144
145 string const ControlPrefs::browse(string const & file,
146                                   string const & title) const
147 {
148         return browseFile(file, title, FileFilterList(), true);
149 }
150
151
152 string const ControlPrefs::browsedir(string const & path,
153                                      string const & title) const
154 {
155         return browseDir(path, title);
156 }
157
158
159 // We support less paper sizes than the document dialog
160 // Therefore this adjustment is needed.
161 PAPER_SIZE const ControlPrefs::toPaperSize(int i) const
162 {
163         switch (i) {
164         case 0:
165                 return PAPER_DEFAULT;
166         case 1:
167                 return PAPER_USLETTER;
168         case 2:
169                 return PAPER_USLEGAL;
170         case 3:
171                 return PAPER_USEXECUTIVE;
172         case 4:
173                 return PAPER_A3;
174         case 5:
175                 return PAPER_A4;
176         case 6:
177                 return PAPER_A5;
178         case 7:
179                 return PAPER_B5;
180         default:
181                 // should not happen
182                 return PAPER_DEFAULT;
183         }
184 }
185
186
187 int const ControlPrefs::fromPaperSize(PAPER_SIZE papersize) const
188 {
189         switch (papersize) {
190         case PAPER_DEFAULT:
191                 return 0;
192         case PAPER_USLETTER:
193                 return 1;
194         case PAPER_USLEGAL:
195                 return 2;
196         case PAPER_USEXECUTIVE:
197                 return 3;
198         case PAPER_A3:
199                 return 4;
200         case PAPER_A4:
201                 return 5;
202         case PAPER_A5:
203                 return 6;
204         case PAPER_B5:
205                 return 7;
206         default:
207                 // should not happen
208                 return 0;
209         }
210 }
211
212 } // namespace frontend
213 } // namespace lyx