comparison libgui/src/resource-manager.cc @ 17930:ffdbb82a0c78

allow welcome wizard dialog to be canceled * resource-manager.h, resource-manager.cc (class resource_manager): Cache settings directory and file, but not first_run. (resource_manager::get_gui_translation_dir, resource_manager::do_update_network_settings): Only access settings if it is valid. (resource_manager::do_reload_settings): Don't set first_run. (resource_manager::do_get_home_path): Delete. * welcome-wizard.cc (welcome_wizard::welcome_wizard): Provide cancel button. * octave-gui.cc (octave_start_gui): Don't loop over welcome wizard. Run welcome wizard once if settings file is missing and exit Octave if welcome wizard returns a rejected status. Otherwise, load resources and start Octave.
author John W. Eaton <jwe@octave.org>
date Thu, 14 Nov 2013 16:52:21 -0500
parents 86c6ae5f969e
children cd97a7ef7355
comparison
equal deleted inserted replaced
17929:97bde75d4119 17930:ffdbb82a0c78
55 55
56 return QString::fromStdString (dsf); 56 return QString::fromStdString (dsf);
57 } 57 }
58 58
59 resource_manager::resource_manager (void) 59 resource_manager::resource_manager (void)
60 : settings (0), home_path (), first_run (false) 60 : settings_directory (), settings_file (), settings (0),
61 { 61 default_settings (0)
62 do_reload_settings (); 62 {
63 QDesktopServices desktopServices;
64
65 QString home_path
66 = desktopServices.storageLocation (QDesktopServices::HomeLocation);
67
68 settings_directory = home_path + "/.config/octave/";
69
70 settings_file = settings_directory + "/qt-settings";
63 71
64 default_settings = new QSettings (default_qt_settings_file (), 72 default_settings = new QSettings (default_qt_settings_file (),
65 QSettings::IniFormat); 73 QSettings::IniFormat);
66 } 74 }
67 75
68 resource_manager::~resource_manager (void) 76 resource_manager::~resource_manager (void)
69 { 77 {
70 delete settings; 78 delete settings;
71 delete default_settings; 79 delete default_settings;
72 } 80 }
73
74 81
75 QString 82 QString
76 resource_manager::get_gui_translation_dir (void) 83 resource_manager::get_gui_translation_dir (void)
77 { 84 {
78 // get environment variable for the locale dir (e.g. from run-octave) 85 // get environment variable for the locale dir (e.g. from run-octave)
89 { 96 {
90 bool loaded; 97 bool loaded;
91 98
92 QString qt_trans_dir 99 QString qt_trans_dir
93 = QLibraryInfo::location (QLibraryInfo::TranslationsPath); 100 = QLibraryInfo::location (QLibraryInfo::TranslationsPath);
101
94 QSettings *settings = resource_manager::get_settings (); 102 QSettings *settings = resource_manager::get_settings ();
95 // FIXME: what should happen if settings is 0? 103
96 104 if (settings)
97 // get the locale from the settings 105 {
98 QString language = settings->value ("language","SYSTEM").toString (); 106 // get the locale from the settings
99 if (language == "SYSTEM") 107 QString language = settings->value ("language","SYSTEM").toString ();
100 language = QLocale::system ().name (); // get system wide locale 108
101 109 if (language == "SYSTEM")
102 // load the translator file for qt strings 110 language = QLocale::system ().name (); // get system wide locale
103 loaded = qt_tr->load ("qt_" + language, qt_trans_dir); 111
104 if (!loaded) // try lower case 112 // load the translator file for qt strings
105 qt_tr->load ("qt_" + language.toLower (), qt_trans_dir); 113 loaded = qt_tr->load ("qt_" + language, qt_trans_dir);
106 114
107 // load the translator file for qscintilla settings 115 if (!loaded) // try lower case
108 loaded = qsci_tr->load ("qscintilla_" + language, qt_trans_dir); 116 qt_tr->load ("qt_" + language.toLower (), qt_trans_dir);
109 if (!loaded) // try lower case 117
110 qsci_tr->load ("qscintilla_" + language.toLower (), qt_trans_dir); 118 // load the translator file for qscintilla settings
111 119 loaded = qsci_tr->load ("qscintilla_" + language, qt_trans_dir);
112 // load the translator file for gui strings 120
113 gui_tr->load (language, get_gui_translation_dir ()); 121 if (!loaded) // try lower case
122 qsci_tr->load ("qscintilla_" + language.toLower (), qt_trans_dir);
123
124 // load the translator file for gui strings
125 gui_tr->load (language, get_gui_translation_dir ());
126 }
127 else
128 {
129 // FIXME: Is this an error? If so, what should we do?
130 }
114 } 131 }
115 132
116 bool 133 bool
117 resource_manager::instance_ok (void) 134 resource_manager::instance_ok (void)
118 { 135 {
147 { 164 {
148 return default_settings; 165 return default_settings;
149 } 166 }
150 167
151 QString 168 QString
152 resource_manager::do_get_home_path (void) const 169 resource_manager::do_get_settings_directory (void)
153 { 170 {
154 return home_path; 171 return settings_directory;
155 }
156
157 QString
158 resource_manager::do_get_settings_path (void)
159 {
160 QDesktopServices desktopServices;
161 home_path = desktopServices.storageLocation (QDesktopServices::HomeLocation);
162 QString settings_path = home_path + "/.config/octave/";
163 return settings_path;
164 } 172 }
165 173
166 QString 174 QString
167 resource_manager::do_get_settings_file (void) 175 resource_manager::do_get_settings_file (void)
168 { 176 {
169 return do_get_settings_path () + "qt-settings"; 177 return settings_file;
170 } 178 }
171 179
172 void 180 void
173 resource_manager::do_reload_settings (void) 181 resource_manager::do_reload_settings (void)
174 { 182 {
175 QDesktopServices desktopServices; 183 if (! QFile::exists (settings_file))
176 home_path = desktopServices.storageLocation (QDesktopServices::HomeLocation); 184 {
177 QString settings_path = do_get_settings_path (); 185 QDir ("/").mkpath (settings_directory);
178 QString settings_file = do_get_settings_file ();
179
180 if (!QFile::exists (settings_file))
181 {
182 QDir ("/").mkpath (settings_path);
183 QFile::copy (default_qt_settings_file (), settings_file); 186 QFile::copy (default_qt_settings_file (), settings_file);
184 first_run = true; 187 }
185 }
186 else
187 first_run = false;
188 188
189 do_set_settings (settings_file); 189 do_set_settings (settings_file);
190 } 190 }
191 191
192 void 192 void
197 } 197 }
198 198
199 bool 199 bool
200 resource_manager::do_is_first_run (void) const 200 resource_manager::do_is_first_run (void) const
201 { 201 {
202 return first_run; 202 return ! QFile::exists (settings_file);
203 } 203 }
204 204
205 void 205 void
206 resource_manager::do_update_network_settings (void) 206 resource_manager::do_update_network_settings (void)
207 { 207 {
208 QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy; 208 if (settings)
209 209 {
210 if (settings->value ("useProxyServer",false).toBool ()) 210 QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
211 { 211
212 QString proxyTypeString = settings->value ("proxyType").toString (); 212 if (settings->value ("useProxyServer",false).toBool ())
213 213 {
214 if (proxyTypeString == "Socks5Proxy") 214 QString proxyTypeString = settings->value ("proxyType").toString ();
215 proxyType = QNetworkProxy::Socks5Proxy; 215
216 else if (proxyTypeString == "HttpProxy") 216 if (proxyTypeString == "Socks5Proxy")
217 proxyType = QNetworkProxy::HttpProxy; 217 proxyType = QNetworkProxy::Socks5Proxy;
218 } 218 else if (proxyTypeString == "HttpProxy")
219 219 proxyType = QNetworkProxy::HttpProxy;
220 QNetworkProxy proxy; 220 }
221 221
222 proxy.setType (proxyType); 222 QNetworkProxy proxy;
223 proxy.setHostName (settings->value ("proxyHostName").toString ()); 223
224 proxy.setPort (settings->value ("proxyPort",80).toInt ()); 224 proxy.setType (proxyType);
225 proxy.setUser (settings->value ("proxyUserName").toString ()); 225 proxy.setHostName (settings->value ("proxyHostName").toString ());
226 proxy.setPassword (settings->value ("proxyPassword").toString ()); 226 proxy.setPort (settings->value ("proxyPort",80).toInt ());
227 227 proxy.setUser (settings->value ("proxyUserName").toString ());
228 QNetworkProxy::setApplicationProxy (proxy); 228 proxy.setPassword (settings->value ("proxyPassword").toString ());
229
230 QNetworkProxy::setApplicationProxy (proxy);
231 }
232 else
233 {
234 // FIXME: Is this an error? If so, what should we do?
235 }
229 } 236 }
230 237
231 QStringList 238 QStringList
232 resource_manager::storage_class_names (void) 239 resource_manager::storage_class_names (void)
233 { 240 {