45
|
1 /****************************************************************************
|
|
2 **
|
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 ** Contact: Qt Software Information (qt-info@nokia.com)
|
|
5 **
|
|
6 ** This file is part of the demonstration applications of the Qt Toolkit.
|
|
7 **
|
|
8 ** $QT_BEGIN_LICENSE:LGPL$
|
|
9 ** Commercial Usage
|
|
10 ** Licensees holding valid Qt Commercial licenses may use this file in
|
|
11 ** accordance with the Qt Commercial License Agreement provided with the
|
|
12 ** Software or, alternatively, in accordance with the terms contained in
|
|
13 ** a written agreement between you and Nokia.
|
|
14 **
|
|
15 ** GNU Lesser General Public License Usage
|
|
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
17 ** General Public License version 2.1 as published by the Free Software
|
|
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
19 ** packaging of this file. Please review the following information to
|
|
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
22 **
|
|
23 ** In addition, as a special exception, Nokia gives you certain
|
|
24 ** additional rights. These rights are described in the Nokia Qt LGPL
|
|
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|
26 ** package.
|
|
27 **
|
|
28 ** GNU General Public License Usage
|
|
29 ** Alternatively, this file may be used under the terms of the GNU
|
|
30 ** General Public License version 3.0 as published by the Free Software
|
|
31 ** Foundation and appearing in the file LICENSE.GPL included in the
|
|
32 ** packaging of this file. Please review the following information to
|
|
33 ** ensure the GNU General Public License version 3.0 requirements will be
|
|
34 ** met: http://www.gnu.org/copyleft/gpl.html.
|
|
35 **
|
|
36 ** If you are unsure which license is appropriate for your use, please
|
|
37 ** contact the sales department at qt-sales@nokia.com.
|
|
38 ** $QT_END_LICENSE$
|
|
39 **
|
|
40 ****************************************************************************/
|
|
41 module settings;
|
|
42
|
|
43
|
73
|
44 import qt.core.QSettings;
|
45
|
45
|
73
|
46 import qt.gui.qt.gui;
|
|
47 import qt.gui.QDialog;
|
45
|
48
|
74
|
49 import qt.webkit.QtWebKit;
|
45
|
50
|
|
51 import browserapplication;
|
|
52 import browsermainwindow;
|
|
53 import cookiejar;
|
|
54 import history;
|
|
55 import networkaccessmanager;
|
|
56 import webview;
|
73
|
57 import ui_settings;
|
45
|
58
|
|
59
|
|
60 class SettingsDialog : public QDialog, public Ui_Settings
|
|
61 {
|
|
62 public:
|
73
|
63
|
74
|
64 this(QWidget parent = null)
|
|
65 //: QDialog(parent)
|
73
|
66 {
|
|
67 setupUi(this);
|
74
|
68 exceptionsButton.clicked.connect(&this.showExceptions);
|
|
69 setHomeToCurrentPageButton.clicked.connect(&this.setHomeToCurrentPage);
|
|
70 cookiesButton.clicked.connect(&this.showCookies()));
|
|
71 standardFontButton.clicked.connect(this.chooseFont);
|
|
72 fixedFontButton.clicked.connect(&this.chooseFixedFont);
|
45
|
73
|
73
|
74 loadDefaults();
|
|
75 loadFromSettings();
|
|
76 }
|
|
77
|
|
78 void accept();
|
|
79 {
|
|
80 saveToSettings();
|
|
81 QDialog.accept();
|
|
82 }
|
45
|
83
|
|
84 private:
|
73
|
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;
|
45
|
337 }
|