Mercurial > projects > qtd
comparison demos/browser/settings.d @ 73:7bfd46c330dc
more porting
author | mandel |
---|---|
date | Fri, 22 May 2009 10:59:00 +0000 |
parents | 71b382c10ef6 |
children | 37caa90ce503 |
comparison
equal
deleted
inserted
replaced
72:b149ef2cb18b | 73:7bfd46c330dc |
---|---|
39 ** | 39 ** |
40 ****************************************************************************/ | 40 ****************************************************************************/ |
41 module settings; | 41 module settings; |
42 | 42 |
43 | 43 |
44 import QtGui.QDialog; | 44 import qt.core.QSettings; |
45 import ui_settings; | 45 |
46 | 46 import qt.gui.qt.gui; |
47 | 47 import qt.gui.QDialog; |
48 import settings; | 48 |
49 import QtWebKit.QtWebKit; | |
49 | 50 |
50 import browserapplication; | 51 import browserapplication; |
51 import browsermainwindow; | 52 import browsermainwindow; |
52 import cookiejar; | 53 import cookiejar; |
53 import history; | 54 import history; |
54 import networkaccessmanager; | 55 import networkaccessmanager; |
55 import webview; | 56 import webview; |
56 | 57 import ui_settings; |
57 import QtCore.QSettings; | |
58 import QtGui.QtGui; | |
59 import QtWebKit.QtWebKit; | |
60 | 58 |
61 | 59 |
62 class SettingsDialog : public QDialog, public Ui_Settings | 60 class SettingsDialog : public QDialog, public Ui_Settings |
63 { | 61 { |
64 Q_OBJECT | |
65 | |
66 public: | 62 public: |
67 SettingsDialog(QWidget *parent = null); | 63 |
68 : QDialog(parent) | 64 this(QWidget parent = null); |
69 { | 65 : QDialog(parent) |
70 setupUi(this); | 66 { |
71 connect(exceptionsButton, SIGNAL(clicked()), this, SLOT(showExceptions())); | 67 setupUi(this); |
72 connect(setHomeToCurrentPageButton, SIGNAL(clicked()), this, SLOT(setHomeToCurrentPage())); | 68 connect(exceptionsButton, SIGNAL(clicked()), this, SLOT(showExceptions())); |
73 connect(cookiesButton, SIGNAL(clicked()), this, SLOT(showCookies())); | 69 connect(setHomeToCurrentPageButton, SIGNAL(clicked()), this, SLOT(setHomeToCurrentPage())); |
74 connect(standardFontButton, SIGNAL(clicked()), this, SLOT(chooseFont())); | 70 connect(cookiesButton, SIGNAL(clicked()), this, SLOT(showCookies())); |
75 connect(fixedFontButton, SIGNAL(clicked()), this, SLOT(chooseFixedFont())); | 71 connect(standardFontButton, SIGNAL(clicked()), this, SLOT(chooseFont())); |
76 | 72 connect(fixedFontButton, SIGNAL(clicked()), this, SLOT(chooseFixedFont())); |
77 loadDefaults(); | 73 |
78 loadFromSettings(); | 74 loadDefaults(); |
75 loadFromSettings(); | |
76 } | |
77 | |
78 void accept(); | |
79 { | |
80 saveToSettings(); | |
81 QDialog.accept(); | |
82 } | |
83 | |
84 private: | |
85 | |
86 void loadDefaults() | |
87 { | |
88 QWebSettings defaultSettings = QWebSettings.globalSettings(); | |
89 QString standardFontFamily = defaultSettings.fontFamily(QWebSettings.StandardFont); | |
90 int standardFontSize = defaultSettings.fontSize(QWebSettings.DefaultFontSize); | |
91 standardFont = QFont(standardFontFamily, standardFontSize); | |
92 standardLabel.setText(QString(QLatin1String("%1 %2")).arg(standardFont.family()).arg(standardFont.pointSize())); | |
93 | |
94 QString fixedFontFamily = defaultSettings.fontFamily(QWebSettings.FixedFont); | |
95 int fixedFontSize = defaultSettings.fontSize(QWebSettings.DefaultFixedFontSize); | |
96 fixedFont = QFont(fixedFontFamily, fixedFontSize); | |
97 fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(fixedFont.family()).arg(fixedFont.pointSize())); | |
98 | |
99 downloadsLocation.setText(QDesktopServices.storageLocation(QDesktopServices.DesktopLocation)); | |
100 | |
101 enableJavascript.setChecked(defaultSettings.testAttribute(QWebSettings.JavascriptEnabled)); | |
102 enablePlugins.setChecked(defaultSettings.testAttribute(QWebSettings.PluginsEnabled)); | |
103 } | |
104 | |
105 void loadFromSettings() | |
106 { | |
107 QSettings settings; | |
108 settings.beginGroup(QLatin1String("MainWindow")); | |
109 QString defaultHome = QLatin1String("http://qtsoftware.com"); | |
110 homeLineEdit.setText(settings.value(QLatin1String("home"), defaultHome).toString()); | |
111 settings.endGroup(); | |
112 | |
113 settings.beginGroup(QLatin1String("history")); | |
114 int historyExpire = settings.value(QLatin1String("historyExpire")).toInt(); | |
115 int idx = 0; | |
116 switch (historyExpire) { | |
117 case 1: idx = 0; break; | |
118 case 7: idx = 1; break; | |
119 case 14: idx = 2; break; | |
120 case 30: idx = 3; break; | |
121 case 365: idx = 4; break; | |
122 case -1: idx = 5; break; | |
123 default: | |
124 idx = 5; | |
125 } | |
126 expireHistory.setCurrentIndex(idx); | |
127 settings.endGroup(); | |
128 | |
129 settings.beginGroup(QLatin1String("downloadmanager")); | |
130 QString downloadDirectory = settings.value(QLatin1String("downloadDirectory"), downloadsLocation.text()).toString(); | |
131 downloadsLocation.setText(downloadDirectory); | |
132 settings.endGroup(); | |
133 | |
134 settings.beginGroup(QLatin1String("general")); | |
135 openLinksIn.setCurrentIndex(settings.value(QLatin1String("openLinksIn"), openLinksIn.currentIndex()).toInt()); | |
136 | |
137 settings.endGroup(); | |
138 | |
139 // Appearance | |
140 settings.beginGroup(QLatin1String("websettings")); | |
141 fixedFont = qVariantValue<QFont>(settings.value(QLatin1String("fixedFont"), fixedFont)); | |
142 standardFont = qVariantValue<QFont>(settings.value(QLatin1String("standardFont"), standardFont)); | |
143 | |
144 standardLabel.setText(QString(QLatin1String("%1 %2")).arg(standardFont.family()).arg(standardFont.pointSize())); | |
145 fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(fixedFont.family()).arg(fixedFont.pointSize())); | |
146 | |
147 enableJavascript.setChecked(settings.value(QLatin1String("enableJavascript"), enableJavascript.isChecked()).toBool()); | |
148 enablePlugins.setChecked(settings.value(QLatin1String("enablePlugins"), enablePlugins.isChecked()).toBool()); | |
149 userStyleSheet.setText(settings.value(QLatin1String("userStyleSheet")).toUrl().toString()); | |
150 settings.endGroup(); | |
151 | |
152 // Privacy | |
153 settings.beginGroup(QLatin1String("cookies")); | |
154 | |
155 CookieJar jar = BrowserApplication.cookieJar(); | |
156 QByteArray value = settings.value(QLatin1String("acceptCookies"), QLatin1String("AcceptOnlyFromSitesNavigatedTo")).toByteArray(); | |
157 QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy")); | |
158 CookieJar.AcceptPolicy acceptCookies = acceptPolicyEnum.keyToValue(value) == -1 ? CookieJar.AcceptOnlyFromSitesNavigatedTo : | |
159 cast(CookieJar.AcceptPolicy) acceptPolicyEnum.keyToValue(value); | |
160 switch(acceptCookies) { | |
161 case CookieJar.AcceptAlways: | |
162 acceptCombo.setCurrentIndex(0); | |
163 break; | |
164 case CookieJar.AcceptNever: | |
165 acceptCombo.setCurrentIndex(1); | |
166 break; | |
167 case CookieJar.AcceptOnlyFromSitesNavigatedTo: | |
168 acceptCombo.setCurrentIndex(2); | |
169 break; | |
170 } | |
171 | |
172 value = settings.value(QLatin1String("keepCookiesUntil"), QLatin1String("Expire")).toByteArray(); | |
173 QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy")); | |
174 CookieJar.KeepPolicy keepCookies = keepPolicyEnum.keyToValue(value) == -1 ? CookieJar.KeepUntilExpire : | |
175 cast(CookieJar.KeepPolicy)(keepPolicyEnum.keyToValue(value)); | |
176 switch(keepCookies) { | |
177 case CookieJar.KeepUntilExpire: | |
178 keepUntilCombo.setCurrentIndex(0); | |
179 break; | |
180 case CookieJar.KeepUntilExit: | |
181 keepUntilCombo.setCurrentIndex(1); | |
182 break; | |
183 case CookieJar.KeepUntilTimeLimit: | |
184 keepUntilCombo.setCurrentIndex(2); | |
185 break; | |
186 } | |
187 settings.endGroup(); | |
188 | |
189 // Proxy | |
190 settings.beginGroup(QLatin1String("proxy")); | |
191 proxySupport.setChecked(settings.value(QLatin1String("enabled"), false).toBool()); | |
192 proxyType.setCurrentIndex(settings.value(QLatin1String("type"), 0).toInt()); | |
193 proxyHostName.setText(settings.value(QLatin1String("hostName")).toString()); | |
194 proxyPort.setValue(settings.value(QLatin1String("port"), 1080).toInt()); | |
195 proxyUserName.setText(settings.value(QLatin1String("userName")).toString()); | |
196 proxyPassword.setText(settings.value(QLatin1String("password")).toString()); | |
197 settings.endGroup(); | |
198 } | |
199 | |
200 void saveToSettings() | |
201 { | |
202 QSettings settings; | |
203 settings.beginGroup(QLatin1String("MainWindow")); | |
204 settings.setValue(QLatin1String("home"), homeLineEdit.text()); | |
205 settings.endGroup(); | |
206 | |
207 settings.beginGroup(QLatin1String("general")); | |
208 settings.setValue(QLatin1String("openLinksIn"), openLinksIn.currentIndex()); | |
209 settings.endGroup(); | |
210 | |
211 settings.beginGroup(QLatin1String("history")); | |
212 int historyExpire = expireHistory.currentIndex(); | |
213 int idx = -1; | |
214 switch (historyExpire) { | |
215 case 0: idx = 1; break; | |
216 case 1: idx = 7; break; | |
217 case 2: idx = 14; break; | |
218 case 3: idx = 30; break; | |
219 case 4: idx = 365; break; | |
220 case 5: idx = -1; break; | |
221 } | |
222 settings.setValue(QLatin1String("historyExpire"), idx); | |
223 settings.endGroup(); | |
224 | |
225 // Appearance | |
226 settings.beginGroup(QLatin1String("websettings")); | |
227 settings.setValue(QLatin1String("fixedFont"), fixedFont); | |
228 settings.setValue(QLatin1String("standardFont"), standardFont); | |
229 settings.setValue(QLatin1String("enableJavascript"), enableJavascript.isChecked()); | |
230 settings.setValue(QLatin1String("enablePlugins"), enablePlugins.isChecked()); | |
231 QString userStyleSheetString = userStyleSheet.text(); | |
232 if (QFile.exists(userStyleSheetString)) | |
233 settings.setValue(QLatin1String("userStyleSheet"), QUrl.fromLocalFile(userStyleSheetString)); | |
234 else | |
235 settings.setValue(QLatin1String("userStyleSheet"), QUrl(userStyleSheetString)); | |
236 settings.endGroup(); | |
237 | |
238 //Privacy | |
239 settings.beginGroup(QLatin1String("cookies")); | |
240 | |
241 CookieJar.KeepPolicy keepCookies; | |
242 switch(acceptCombo.currentIndex()) { | |
243 default: | |
244 case 0: | |
245 keepCookies = CookieJar.KeepUntilExpire; | |
246 break; | |
247 case 1: | |
248 keepCookies = CookieJar.KeepUntilExit; | |
249 break; | |
250 case 2: | |
251 keepCookies = CookieJar.KeepUntilTimeLimit; | |
252 break; | |
253 } | |
254 CookieJar jar = BrowserApplication.cookieJar(); | |
255 QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy")); | |
256 settings.setValue(QLatin1String("acceptCookies"), QLatin1String(acceptPolicyEnum.valueToKey(keepCookies))); | |
257 | |
258 CookieJar.KeepPolicy keepPolicy; | |
259 switch(keepUntilCombo.currentIndex()) { | |
260 default: | |
261 case 0: | |
262 keepPolicy = CookieJar.KeepUntilExpire; | |
263 break; | |
264 case 1: | |
265 keepPolicy = CookieJar.KeepUntilExit; | |
266 break; | |
267 case 2: | |
268 keepPolicy = CookieJar.KeepUntilTimeLimit; | |
269 break; | |
270 } | |
271 | |
272 QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy")); | |
273 settings.setValue(QLatin1String("keepCookiesUntil"), QLatin1String(keepPolicyEnum.valueToKey(keepPolicy))); | |
274 | |
275 settings.endGroup(); | |
276 | |
277 // proxy | |
278 settings.beginGroup(QLatin1String("proxy")); | |
279 settings.setValue(QLatin1String("enabled"), proxySupport.isChecked()); | |
280 settings.setValue(QLatin1String("type"), proxyType.currentIndex()); | |
281 settings.setValue(QLatin1String("hostName"), proxyHostName.text()); | |
282 settings.setValue(QLatin1String("port"), proxyPort.text()); | |
283 settings.setValue(QLatin1String("userName"), proxyUserName.text()); | |
284 settings.setValue(QLatin1String("password"), proxyPassword.text()); | |
285 settings.endGroup(); | |
286 | |
287 BrowserApplication.instance().loadSettings(); | |
288 BrowserApplication.networkAccessManager().loadSettings(); | |
289 BrowserApplication.cookieJar().loadSettings(); | |
290 BrowserApplication.historyManager().loadSettings(); | |
291 } | |
292 | |
293 void setHomeToCurrentPage() | |
294 { | |
295 BrowserMainWindow mw = cast(BrowserMainWindow) parent(); | |
296 WebView webView = mw.currentTab(); | |
297 if (webView) | |
298 homeLineEdit.setText(webView.url().toString()); | |
299 } | |
300 | |
301 void showCookies() | |
302 { | |
303 CookiesDialog dialog = new CookiesDialog(BrowserApplication.cookieJar(), this); | |
304 dialog.exec(); | |
305 } | |
306 | |
307 void showExceptions() | |
308 { | |
309 CookiesExceptionsDialog dialog = new CookiesExceptionsDialog(BrowserApplication.cookieJar(), this); | |
310 dialog.exec(); | |
311 } | |
312 | |
313 void chooseFont() | |
314 { | |
315 bool ok; | |
316 QFont font = QFontDialog.getFont(&ok, standardFont, this); | |
317 if ( ok ) { | |
318 standardFont = font; | |
319 standardLabel.setText(QString(QLatin1String("%1 %2")).arg(font.family()).arg(font.pointSize())); | |
320 } | |
321 } | |
322 | |
323 void chooseFixedFont() | |
324 { | |
325 bool ok; | |
326 QFont font = QFontDialog.getFont(&ok, fixedFont, this); | |
327 if ( ok ) { | |
328 fixedFont = font; | |
329 fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(font.family()).arg(font.pointSize())); | |
330 } | |
331 } | |
332 | |
333 private: | |
334 | |
335 QFont standardFont; | |
336 QFont fixedFont; | |
79 } | 337 } |
80 void accept(); | |
81 { | |
82 saveToSettings(); | |
83 QDialog::accept(); | |
84 } | |
85 | |
86 private slots: | |
87 void loadDefaults() | |
88 { | |
89 QWebSettings *defaultSettings = QWebSettings::globalSettings(); | |
90 QString standardFontFamily = defaultSettings.fontFamily(QWebSettings::StandardFont); | |
91 int standardFontSize = defaultSettings.fontSize(QWebSettings::DefaultFontSize); | |
92 standardFont = QFont(standardFontFamily, standardFontSize); | |
93 standardLabel.setText(QString(QLatin1String("%1 %2")).arg(standardFont.family()).arg(standardFont.pointSize())); | |
94 | |
95 QString fixedFontFamily = defaultSettings.fontFamily(QWebSettings::FixedFont); | |
96 int fixedFontSize = defaultSettings.fontSize(QWebSettings::DefaultFixedFontSize); | |
97 fixedFont = QFont(fixedFontFamily, fixedFontSize); | |
98 fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(fixedFont.family()).arg(fixedFont.pointSize())); | |
99 | |
100 downloadsLocation.setText(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)); | |
101 | |
102 enableJavascript.setChecked(defaultSettings.testAttribute(QWebSettings::JavascriptEnabled)); | |
103 enablePlugins.setChecked(defaultSettings.testAttribute(QWebSettings::PluginsEnabled)); | |
104 } | |
105 | |
106 void loadFromSettings() | |
107 { | |
108 QSettings settings; | |
109 settings.beginGroup(QLatin1String("MainWindow")); | |
110 QString defaultHome = QLatin1String("http://qtsoftware.com"); | |
111 homeLineEdit.setText(settings.value(QLatin1String("home"), defaultHome).toString()); | |
112 settings.endGroup(); | |
113 | |
114 settings.beginGroup(QLatin1String("history")); | |
115 int historyExpire = settings.value(QLatin1String("historyExpire")).toInt(); | |
116 int idx = 0; | |
117 switch (historyExpire) { | |
118 case 1: idx = 0; break; | |
119 case 7: idx = 1; break; | |
120 case 14: idx = 2; break; | |
121 case 30: idx = 3; break; | |
122 case 365: idx = 4; break; | |
123 case -1: idx = 5; break; | |
124 default: | |
125 idx = 5; | |
126 } | |
127 expireHistory.setCurrentIndex(idx); | |
128 settings.endGroup(); | |
129 | |
130 settings.beginGroup(QLatin1String("downloadmanager")); | |
131 QString downloadDirectory = settings.value(QLatin1String("downloadDirectory"), downloadsLocation.text()).toString(); | |
132 downloadsLocation.setText(downloadDirectory); | |
133 settings.endGroup(); | |
134 | |
135 settings.beginGroup(QLatin1String("general")); | |
136 openLinksIn.setCurrentIndex(settings.value(QLatin1String("openLinksIn"), openLinksIn.currentIndex()).toInt()); | |
137 | |
138 settings.endGroup(); | |
139 | |
140 // Appearance | |
141 settings.beginGroup(QLatin1String("websettings")); | |
142 fixedFont = qVariantValue<QFont>(settings.value(QLatin1String("fixedFont"), fixedFont)); | |
143 standardFont = qVariantValue<QFont>(settings.value(QLatin1String("standardFont"), standardFont)); | |
144 | |
145 standardLabel.setText(QString(QLatin1String("%1 %2")).arg(standardFont.family()).arg(standardFont.pointSize())); | |
146 fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(fixedFont.family()).arg(fixedFont.pointSize())); | |
147 | |
148 enableJavascript.setChecked(settings.value(QLatin1String("enableJavascript"), enableJavascript.isChecked()).toBool()); | |
149 enablePlugins.setChecked(settings.value(QLatin1String("enablePlugins"), enablePlugins.isChecked()).toBool()); | |
150 userStyleSheet.setText(settings.value(QLatin1String("userStyleSheet")).toUrl().toString()); | |
151 settings.endGroup(); | |
152 | |
153 // Privacy | |
154 settings.beginGroup(QLatin1String("cookies")); | |
155 | |
156 CookieJar *jar = BrowserApplication::cookieJar(); | |
157 QByteArray value = settings.value(QLatin1String("acceptCookies"), QLatin1String("AcceptOnlyFromSitesNavigatedTo")).toByteArray(); | |
158 QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy")); | |
159 CookieJar::AcceptPolicy acceptCookies = acceptPolicyEnum.keyToValue(value) == -1 ? | |
160 CookieJar::AcceptOnlyFromSitesNavigatedTo : | |
161 static_cast<CookieJar::AcceptPolicy>(acceptPolicyEnum.keyToValue(value)); | |
162 switch(acceptCookies) { | |
163 case CookieJar::AcceptAlways: | |
164 acceptCombo.setCurrentIndex(0); | |
165 break; | |
166 case CookieJar::AcceptNever: | |
167 acceptCombo.setCurrentIndex(1); | |
168 break; | |
169 case CookieJar::AcceptOnlyFromSitesNavigatedTo: | |
170 acceptCombo.setCurrentIndex(2); | |
171 break; | |
172 } | |
173 | |
174 value = settings.value(QLatin1String("keepCookiesUntil"), QLatin1String("Expire")).toByteArray(); | |
175 QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy")); | |
176 CookieJar::KeepPolicy keepCookies = keepPolicyEnum.keyToValue(value) == -1 ? | |
177 CookieJar::KeepUntilExpire : | |
178 static_cast<CookieJar::KeepPolicy>(keepPolicyEnum.keyToValue(value)); | |
179 switch(keepCookies) { | |
180 case CookieJar::KeepUntilExpire: | |
181 keepUntilCombo.setCurrentIndex(0); | |
182 break; | |
183 case CookieJar::KeepUntilExit: | |
184 keepUntilCombo.setCurrentIndex(1); | |
185 break; | |
186 case CookieJar::KeepUntilTimeLimit: | |
187 keepUntilCombo.setCurrentIndex(2); | |
188 break; | |
189 } | |
190 settings.endGroup(); | |
191 | |
192 | |
193 // Proxy | |
194 settings.beginGroup(QLatin1String("proxy")); | |
195 proxySupport.setChecked(settings.value(QLatin1String("enabled"), false).toBool()); | |
196 proxyType.setCurrentIndex(settings.value(QLatin1String("type"), 0).toInt()); | |
197 proxyHostName.setText(settings.value(QLatin1String("hostName")).toString()); | |
198 proxyPort.setValue(settings.value(QLatin1String("port"), 1080).toInt()); | |
199 proxyUserName.setText(settings.value(QLatin1String("userName")).toString()); | |
200 proxyPassword.setText(settings.value(QLatin1String("password")).toString()); | |
201 settings.endGroup(); | |
202 } | |
203 | |
204 void saveToSettings() | |
205 { | |
206 QSettings settings; | |
207 settings.beginGroup(QLatin1String("MainWindow")); | |
208 settings.setValue(QLatin1String("home"), homeLineEdit.text()); | |
209 settings.endGroup(); | |
210 | |
211 settings.beginGroup(QLatin1String("general")); | |
212 settings.setValue(QLatin1String("openLinksIn"), openLinksIn.currentIndex()); | |
213 settings.endGroup(); | |
214 | |
215 settings.beginGroup(QLatin1String("history")); | |
216 int historyExpire = expireHistory.currentIndex(); | |
217 int idx = -1; | |
218 switch (historyExpire) { | |
219 case 0: idx = 1; break; | |
220 case 1: idx = 7; break; | |
221 case 2: idx = 14; break; | |
222 case 3: idx = 30; break; | |
223 case 4: idx = 365; break; | |
224 case 5: idx = -1; break; | |
225 } | |
226 settings.setValue(QLatin1String("historyExpire"), idx); | |
227 settings.endGroup(); | |
228 | |
229 // Appearance | |
230 settings.beginGroup(QLatin1String("websettings")); | |
231 settings.setValue(QLatin1String("fixedFont"), fixedFont); | |
232 settings.setValue(QLatin1String("standardFont"), standardFont); | |
233 settings.setValue(QLatin1String("enableJavascript"), enableJavascript.isChecked()); | |
234 settings.setValue(QLatin1String("enablePlugins"), enablePlugins.isChecked()); | |
235 QString userStyleSheetString = userStyleSheet.text(); | |
236 if (QFile::exists(userStyleSheetString)) | |
237 settings.setValue(QLatin1String("userStyleSheet"), QUrl::fromLocalFile(userStyleSheetString)); | |
238 else | |
239 settings.setValue(QLatin1String("userStyleSheet"), QUrl(userStyleSheetString)); | |
240 settings.endGroup(); | |
241 | |
242 //Privacy | |
243 settings.beginGroup(QLatin1String("cookies")); | |
244 | |
245 CookieJar::KeepPolicy keepCookies; | |
246 switch(acceptCombo.currentIndex()) { | |
247 default: | |
248 case 0: | |
249 keepCookies = CookieJar::KeepUntilExpire; | |
250 break; | |
251 case 1: | |
252 keepCookies = CookieJar::KeepUntilExit; | |
253 break; | |
254 case 2: | |
255 keepCookies = CookieJar::KeepUntilTimeLimit; | |
256 break; | |
257 } | |
258 CookieJar *jar = BrowserApplication::cookieJar(); | |
259 QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy")); | |
260 settings.setValue(QLatin1String("acceptCookies"), QLatin1String(acceptPolicyEnum.valueToKey(keepCookies))); | |
261 | |
262 CookieJar::KeepPolicy keepPolicy; | |
263 switch(keepUntilCombo.currentIndex()) { | |
264 default: | |
265 case 0: | |
266 keepPolicy = CookieJar::KeepUntilExpire; | |
267 break; | |
268 case 1: | |
269 keepPolicy = CookieJar::KeepUntilExit; | |
270 break; | |
271 case 2: | |
272 keepPolicy = CookieJar::KeepUntilTimeLimit; | |
273 break; | |
274 } | |
275 | |
276 QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy")); | |
277 settings.setValue(QLatin1String("keepCookiesUntil"), QLatin1String(keepPolicyEnum.valueToKey(keepPolicy))); | |
278 | |
279 settings.endGroup(); | |
280 | |
281 // proxy | |
282 settings.beginGroup(QLatin1String("proxy")); | |
283 settings.setValue(QLatin1String("enabled"), proxySupport.isChecked()); | |
284 settings.setValue(QLatin1String("type"), proxyType.currentIndex()); | |
285 settings.setValue(QLatin1String("hostName"), proxyHostName.text()); | |
286 settings.setValue(QLatin1String("port"), proxyPort.text()); | |
287 settings.setValue(QLatin1String("userName"), proxyUserName.text()); | |
288 settings.setValue(QLatin1String("password"), proxyPassword.text()); | |
289 settings.endGroup(); | |
290 | |
291 BrowserApplication::instance().loadSettings(); | |
292 BrowserApplication::networkAccessManager().loadSettings(); | |
293 BrowserApplication::cookieJar().loadSettings(); | |
294 BrowserApplication::historyManager().loadSettings(); | |
295 } | |
296 | |
297 void setHomeToCurrentPage() | |
298 { | |
299 BrowserMainWindow *mw = static_cast<BrowserMainWindow*>(parent()); | |
300 WebView *webView = mw.currentTab(); | |
301 if (webView) | |
302 homeLineEdit.setText(webView.url().toString()); | |
303 } | |
304 | |
305 void showCookies() | |
306 { | |
307 CookiesDialog *dialog = new CookiesDialog(BrowserApplication::cookieJar(), this); | |
308 dialog.exec(); | |
309 } | |
310 void showExceptions() | |
311 { | |
312 CookiesExceptionsDialog *dialog = new CookiesExceptionsDialog(BrowserApplication::cookieJar(), this); | |
313 dialog.exec(); | |
314 } | |
315 | |
316 void chooseFont() | |
317 { | |
318 bool ok; | |
319 QFont font = QFontDialog::getFont(&ok, standardFont, this); | |
320 if ( ok ) { | |
321 standardFont = font; | |
322 standardLabel.setText(QString(QLatin1String("%1 %2")).arg(font.family()).arg(font.pointSize())); | |
323 } | |
324 } | |
325 | |
326 void chooseFixedFont() | |
327 { | |
328 bool ok; | |
329 QFont font = QFontDialog::getFont(&ok, fixedFont, this); | |
330 if ( ok ) { | |
331 fixedFont = font; | |
332 fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(font.family()).arg(font.pointSize())); | |
333 } | |
334 } | |
335 | |
336 private: | |
337 QFont standardFont; | |
338 QFont fixedFont; | |
339 } |