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