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