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
|
|
44 import QtGui.QDialog;
|
|
45 import ui_settings;
|
|
46
|
|
47
|
|
48 import settings;
|
|
49
|
|
50 import browserapplication;
|
|
51 import browsermainwindow;
|
|
52 import cookiejar;
|
|
53 import history;
|
|
54 import networkaccessmanager;
|
|
55 import webview;
|
|
56
|
|
57 import QtCore.QSettings;
|
|
58 import QtGui.QtGui;
|
|
59 import QtWebKit.QtWebKit;
|
|
60
|
|
61
|
|
62 class SettingsDialog : public QDialog, public Ui_Settings
|
|
63 {
|
|
64 Q_OBJECT
|
|
65
|
|
66 public:
|
|
67 SettingsDialog(QWidget *parent = null);
|
|
68 : QDialog(parent)
|
|
69 {
|
|
70 setupUi(this);
|
|
71 connect(exceptionsButton, SIGNAL(clicked()), this, SLOT(showExceptions()));
|
|
72 connect(setHomeToCurrentPageButton, SIGNAL(clicked()), this, SLOT(setHomeToCurrentPage()));
|
|
73 connect(cookiesButton, SIGNAL(clicked()), this, SLOT(showCookies()));
|
|
74 connect(standardFontButton, SIGNAL(clicked()), this, SLOT(chooseFont()));
|
|
75 connect(fixedFontButton, SIGNAL(clicked()), this, SLOT(chooseFixedFont()));
|
|
76
|
|
77 loadDefaults();
|
|
78 loadFromSettings();
|
|
79 }
|
|
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 }
|