comparison demos/browser/settings.d @ 80:85c59c4e5f19

remove QLatin1String and other fixes
author mandel
date Sun, 24 May 2009 15:25:41 +0000
parents 0654fc9bac95
children 87bb4e622f9e
comparison
equal deleted inserted replaced
79:957f549cfc65 80:85c59c4e5f19
87 { 87 {
88 QWebSettings defaultSettings = QWebSettings.globalSettings(); 88 QWebSettings defaultSettings = QWebSettings.globalSettings();
89 string standardFontFamily = defaultSettings.fontFamily(QWebSettings.StandardFont); 89 string standardFontFamily = defaultSettings.fontFamily(QWebSettings.StandardFont);
90 int standardFontSize = defaultSettings.fontSize(QWebSettings.DefaultFontSize); 90 int standardFontSize = defaultSettings.fontSize(QWebSettings.DefaultFontSize);
91 standardFont = QFont(standardFontFamily, standardFontSize); 91 standardFont = QFont(standardFontFamily, standardFontSize);
92 standardLabel.setText(Format(QLatin1String("{} {}"), standardFont.family(), standardFont.pointSize())); 92 standardLabel.setText(Format("{} {}", standardFont.family(), standardFont.pointSize()));
93 93
94 string fixedFontFamily = defaultSettings.fontFamily(QWebSettings.FixedFont); 94 string fixedFontFamily = defaultSettings.fontFamily(QWebSettings.FixedFont);
95 int fixedFontSize = defaultSettings.fontSize(QWebSettings.DefaultFixedFontSize); 95 int fixedFontSize = defaultSettings.fontSize(QWebSettings.DefaultFixedFontSize);
96 fixedFont = QFont(fixedFontFamily, fixedFontSize); 96 fixedFont = QFont(fixedFontFamily, fixedFontSize);
97 fixedLabel.setText(Format(QLatin1String("{} {}"), fixedFont.family(), fixedFont.pointSize())); 97 fixedLabel.setText(Format("{} {}", fixedFont.family(), fixedFont.pointSize()));
98 98
99 downloadsLocation.setText(QDesktopServices.storageLocation(QDesktopServices.DesktopLocation)); 99 downloadsLocation.setText(QDesktopServices.storageLocation(QDesktopServices.DesktopLocation));
100 100
101 enableJavascript.setChecked(defaultSettings.testAttribute(QWebSettings.JavascriptEnabled)); 101 enableJavascript.setChecked(defaultSettings.testAttribute(QWebSettings.JavascriptEnabled));
102 enablePlugins.setChecked(defaultSettings.testAttribute(QWebSettings.PluginsEnabled)); 102 enablePlugins.setChecked(defaultSettings.testAttribute(QWebSettings.PluginsEnabled));
103 } 103 }
104 104
105 void loadFromSettings() 105 void loadFromSettings()
106 { 106 {
107 auto settings = new QSettings; 107 auto settings = new QSettings;
108 settings.beginGroup(QLatin1String("MainWindow")); 108 settings.beginGroup("MainWindow");
109 string defaultHome = QLatin1String("http://qtsoftware.com"); 109 string defaultHome = "http://qtsoftware.com";
110 homeLineEdit.setText(settings.value(QLatin1String("home"), defaultHome).toString()); 110 homeLineEdit.setText(settings.value("home", defaultHome).toString());
111 settings.endGroup(); 111 settings.endGroup();
112 112
113 settings.beginGroup(QLatin1String("history")); 113 settings.beginGroup("history");
114 int historyExpire = settings.value(QLatin1String("historyExpire")).toInt(); 114 int historyExpire = settings.value("historyExpire").toInt();
115 int idx = 0; 115 int idx = 0;
116 switch (historyExpire) { 116 switch (historyExpire) {
117 case 1: idx = 0; break; 117 case 1: idx = 0; break;
118 case 7: idx = 1; break; 118 case 7: idx = 1; break;
119 case 14: idx = 2; break; 119 case 14: idx = 2; break;
124 idx = 5; 124 idx = 5;
125 } 125 }
126 expireHistory.setCurrentIndex(idx); 126 expireHistory.setCurrentIndex(idx);
127 settings.endGroup(); 127 settings.endGroup();
128 128
129 settings.beginGroup(QLatin1String("downloadmanager")); 129 settings.beginGroup("downloadmanager");
130 string downloadDirectory = settings.value(QLatin1String("downloadDirectory"), downloadsLocation.text()).toString(); 130 string downloadDirectory = settings.value("downloadDirectory", downloadsLocation.text()).toString();
131 downloadsLocation.setText(downloadDirectory); 131 downloadsLocation.setText(downloadDirectory);
132 settings.endGroup(); 132 settings.endGroup();
133 133
134 settings.beginGroup(QLatin1String("general")); 134 settings.beginGroup("general");
135 openLinksIn.setCurrentIndex(settings.value(QLatin1String("openLinksIn"), openLinksIn.currentIndex()).toInt()); 135 openLinksIn.setCurrentIndex(settings.value("openLinksIn", openLinksIn.currentIndex()).toInt());
136 136
137 settings.endGroup(); 137 settings.endGroup();
138 138
139 // Appearance 139 // Appearance
140 settings.beginGroup(QLatin1String("websettings")); 140 settings.beginGroup("websettings");
141 fixedFont = qVariantValue<QFont>(settings.value(QLatin1String("fixedFont"), fixedFont)); 141 fixedFont = new QFont(settings.value("fixedFont", fixedFont));
142 standardFont = qVariantValue<QFont>(settings.value(QLatin1String("standardFont"), standardFont)); 142 standardFont = new QFont(settings.value("standardFont", standardFont));
143 143
144 standardLabel.setText(Format(QLatin1String("{} {}"), standardFont.family(), standardFont.pointSize())); 144 standardLabel.setText(Format("{} {}", standardFont.family(), standardFont.pointSize()));
145 fixedLabel.setText(Format(QLatin1String("{} {}"), fixedFont.family(), fixedFont.pointSize())); 145 fixedLabel.setText(Format("{} {}", fixedFont.family(), fixedFont.pointSize()));
146 146
147 enableJavascript.setChecked(settings.value(QLatin1String("enableJavascript"), enableJavascript.isChecked()).toBool()); 147 enableJavascript.setChecked(settings.value("enableJavascript", enableJavascript.isChecked()).toBool());
148 enablePlugins.setChecked(settings.value(QLatin1String("enablePlugins"), enablePlugins.isChecked()).toBool()); 148 enablePlugins.setChecked(settings.value("enablePlugins", enablePlugins.isChecked()).toBool());
149 userStyleSheet.setText(settings.value(QLatin1String("userStyleSheet")).toUrl().toString()); 149 userStyleSheet.setText(settings.value("userStyleSheet").toUrl().toString());
150 settings.endGroup(); 150 settings.endGroup();
151 151
152 // Privacy 152 // Privacy
153 settings.beginGroup(QLatin1String("cookies")); 153 settings.beginGroup("cookies");
154 154
155 CookieJar jar = BrowserApplication.cookieJar(); 155 CookieJar jar = BrowserApplication.cookieJar();
156 QByteArray value = settings.value(QLatin1String("acceptCookies"), QLatin1String("AcceptOnlyFromSitesNavigatedTo")).toByteArray(); 156 QByteArray value = settings.value("acceptCookies", "AcceptOnlyFromSitesNavigatedTo").toByteArray();
157 QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy")); 157 QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy"));
158 CookieJar.AcceptPolicy acceptCookies = acceptPolicyEnum.keyToValue(value) == -1 ? CookieJar.AcceptOnlyFromSitesNavigatedTo : 158 CookieJar.AcceptPolicy acceptCookies = acceptPolicyEnum.keyToValue(value) == -1 ? CookieJar.AcceptOnlyFromSitesNavigatedTo :
159 cast(CookieJar.AcceptPolicy) acceptPolicyEnum.keyToValue(value); 159 cast(CookieJar.AcceptPolicy) acceptPolicyEnum.keyToValue(value);
160 switch(acceptCookies) { 160 switch(acceptCookies) {
161 case CookieJar.AcceptAlways: 161 case CookieJar.AcceptAlways:
167 case CookieJar.AcceptOnlyFromSitesNavigatedTo: 167 case CookieJar.AcceptOnlyFromSitesNavigatedTo:
168 acceptCombo.setCurrentIndex(2); 168 acceptCombo.setCurrentIndex(2);
169 break; 169 break;
170 } 170 }
171 171
172 value = settings.value(QLatin1String("keepCookiesUntil"), QLatin1String("Expire")).toByteArray(); 172 value = settings.value("keepCookiesUntil", "Expire").toByteArray();
173 QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy")); 173 QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy"));
174 CookieJar.KeepPolicy keepCookies = keepPolicyEnum.keyToValue(value) == -1 ? CookieJar.KeepUntilExpire : 174 CookieJar.KeepPolicy keepCookies = keepPolicyEnum.keyToValue(value) == -1 ? CookieJar.KeepUntilExpire :
175 cast(CookieJar.KeepPolicy)(keepPolicyEnum.keyToValue(value)); 175 cast(CookieJar.KeepPolicy)(keepPolicyEnum.keyToValue(value));
176 switch(keepCookies) { 176 switch(keepCookies) {
177 case CookieJar.KeepUntilExpire: 177 case CookieJar.KeepUntilExpire:
185 break; 185 break;
186 } 186 }
187 settings.endGroup(); 187 settings.endGroup();
188 188
189 // Proxy 189 // Proxy
190 settings.beginGroup(QLatin1String("proxy")); 190 settings.beginGroup("proxy");
191 proxySupport.setChecked(settings.value(QLatin1String("enabled"), false).toBool()); 191 proxySupport.setChecked(settings.value("enabled", false).toBool());
192 proxyType.setCurrentIndex(settings.value(QLatin1String("type"), 0).toInt()); 192 proxyType.setCurrentIndex(settings.value("type", 0).toInt());
193 proxyHostName.setText(settings.value(QLatin1String("hostName")).toString()); 193 proxyHostName.setText(settings.value("hostName").toString());
194 proxyPort.setValue(settings.value(QLatin1String("port"), 1080).toInt()); 194 proxyPort.setValue(settings.value("port", 1080).toInt());
195 proxyUserName.setText(settings.value(QLatin1String("userName")).toString()); 195 proxyUserName.setText(settings.value("userName").toString());
196 proxyPassword.setText(settings.value(QLatin1String("password")).toString()); 196 proxyPassword.setText(settings.value("password").toString());
197 settings.endGroup(); 197 settings.endGroup();
198 } 198 }
199 199
200 void saveToSettings() 200 void saveToSettings()
201 { 201 {
202 QSettings settings; 202 QSettings settings;
203 settings.beginGroup(QLatin1String("MainWindow")); 203 settings.beginGroup("MainWindow");
204 settings.setValue(QLatin1String("home"), homeLineEdit.text()); 204 settings.setValue("home", homeLineEdit.text());
205 settings.endGroup(); 205 settings.endGroup();
206 206
207 settings.beginGroup(QLatin1String("general")); 207 settings.beginGroup("general");
208 settings.setValue(QLatin1String("openLinksIn"), openLinksIn.currentIndex()); 208 settings.setValue("openLinksIn", openLinksIn.currentIndex());
209 settings.endGroup(); 209 settings.endGroup();
210 210
211 settings.beginGroup(QLatin1String("history")); 211 settings.beginGroup("history");
212 int historyExpire = expireHistory.currentIndex(); 212 int historyExpire = expireHistory.currentIndex();
213 int idx = -1; 213 int idx = -1;
214 switch (historyExpire) { 214 switch (historyExpire) {
215 case 0: idx = 1; break; 215 case 0: idx = 1; break;
216 case 1: idx = 7; break; 216 case 1: idx = 7; break;
217 case 2: idx = 14; break; 217 case 2: idx = 14; break;
218 case 3: idx = 30; break; 218 case 3: idx = 30; break;
219 case 4: idx = 365; break; 219 case 4: idx = 365; break;
220 case 5: idx = -1; break; 220 case 5: idx = -1; break;
221 } 221 }
222 settings.setValue(QLatin1String("historyExpire"), idx); 222 settings.setValue("historyExpire", idx);
223 settings.endGroup(); 223 settings.endGroup();
224 224
225 // Appearance 225 // Appearance
226 settings.beginGroup(QLatin1String("websettings")); 226 settings.beginGroup("websettings");
227 settings.setValue(QLatin1String("fixedFont"), fixedFont); 227 settings.setValue("fixedFont", fixedFont);
228 settings.setValue(QLatin1String("standardFont"), standardFont); 228 settings.setValue("standardFont", standardFont);
229 settings.setValue(QLatin1String("enableJavascript"), enableJavascript.isChecked()); 229 settings.setValue("enableJavascript", enableJavascript.isChecked());
230 settings.setValue(QLatin1String("enablePlugins"), enablePlugins.isChecked()); 230 settings.setValue("enablePlugins", enablePlugins.isChecked());
231 string userStyleSheetString = userStyleSheet.text(); 231 string userStyleSheetString = userStyleSheet.text();
232 if (QFile.exists(userStyleSheetString)) 232 if (QFile.exists(userStyleSheetString))
233 settings.setValue(QLatin1String("userStyleSheet"), QUrl.fromLocalFile(userStyleSheetString)); 233 settings.setValue("userStyleSheet", QUrl.fromLocalFile(userStyleSheetString));
234 else 234 else
235 settings.setValue(QLatin1String("userStyleSheet"), QUrl(userStyleSheetString)); 235 settings.setValue("userStyleSheet", QUrl(userStyleSheetString));
236 settings.endGroup(); 236 settings.endGroup();
237 237
238 //Privacy 238 //Privacy
239 settings.beginGroup(QLatin1String("cookies")); 239 settings.beginGroup("cookies");
240 240
241 CookieJar.KeepPolicy keepCookies; 241 CookieJar.KeepPolicy keepCookies;
242 switch(acceptCombo.currentIndex()) { 242 switch(acceptCombo.currentIndex()) {
243 default: 243 default:
244 case 0: 244 case 0:
251 keepCookies = CookieJar.KeepUntilTimeLimit; 251 keepCookies = CookieJar.KeepUntilTimeLimit;
252 break; 252 break;
253 } 253 }
254 CookieJar jar = BrowserApplication.cookieJar(); 254 CookieJar jar = BrowserApplication.cookieJar();
255 QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy")); 255 QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy"));
256 settings.setValue(QLatin1String("acceptCookies"), QLatin1String(acceptPolicyEnum.valueToKey(keepCookies))); 256 settings.setValue("acceptCookies", acceptPolicyEnum.valueToKey(keepCookies));
257 257
258 CookieJar.KeepPolicy keepPolicy; 258 CookieJar.KeepPolicy keepPolicy;
259 switch(keepUntilCombo.currentIndex()) { 259 switch(keepUntilCombo.currentIndex()) {
260 default: 260 default:
261 case 0: 261 case 0:
268 keepPolicy = CookieJar.KeepUntilTimeLimit; 268 keepPolicy = CookieJar.KeepUntilTimeLimit;
269 break; 269 break;
270 } 270 }
271 271
272 QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy")); 272 QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy"));
273 settings.setValue(QLatin1String("keepCookiesUntil"), QLatin1String(keepPolicyEnum.valueToKey(keepPolicy))); 273 settings.setValue("keepCookiesUntil", keepPolicyEnum.valueToKey(keepPolicy));
274 274
275 settings.endGroup(); 275 settings.endGroup();
276 276
277 // proxy 277 // proxy
278 settings.beginGroup(QLatin1String("proxy")); 278 settings.beginGroup("proxy");
279 settings.setValue(QLatin1String("enabled"), proxySupport.isChecked()); 279 settings.setValue("enabled", proxySupport.isChecked());
280 settings.setValue(QLatin1String("type"), proxyType.currentIndex()); 280 settings.setValue("type", proxyType.currentIndex());
281 settings.setValue(QLatin1String("hostName"), proxyHostName.text()); 281 settings.setValue("hostName", proxyHostName.text());
282 settings.setValue(QLatin1String("port"), proxyPort.text()); 282 settings.setValue("port", proxyPort.text());
283 settings.setValue(QLatin1String("userName"), proxyUserName.text()); 283 settings.setValue("userName", proxyUserName.text());
284 settings.setValue(QLatin1String("password"), proxyPassword.text()); 284 settings.setValue("password", proxyPassword.text());
285 settings.endGroup(); 285 settings.endGroup();
286 286
287 BrowserApplication.instance().loadSettings(); 287 BrowserApplication.instance().loadSettings();
288 BrowserApplication.networkAccessManager().loadSettings(); 288 BrowserApplication.networkAccessManager().loadSettings();
289 BrowserApplication.cookieJar().loadSettings(); 289 BrowserApplication.cookieJar().loadSettings();
314 { 314 {
315 bool ok; 315 bool ok;
316 QFont font = QFontDialog.getFont(&ok, standardFont, this); 316 QFont font = QFontDialog.getFont(&ok, standardFont, this);
317 if ( ok ) { 317 if ( ok ) {
318 standardFont = font; 318 standardFont = font;
319 standardLabel.setText(Format(QLatin1String("{} {}"), font.family(), font.pointSize())); 319 standardLabel.setText(Format("{} {}", font.family(), font.pointSize()));
320 } 320 }
321 } 321 }
322 322
323 void chooseFixedFont() 323 void chooseFixedFont()
324 { 324 {
325 bool ok; 325 bool ok;
326 QFont font = QFontDialog.getFont(&ok, fixedFont, this); 326 QFont font = QFontDialog.getFont(&ok, fixedFont, this);
327 if ( ok ) { 327 if ( ok ) {
328 fixedFont = font; 328 fixedFont = font;
329 fixedLabel.setText(Format(QLatin1String("{} {}"), font.family(), font.pointSize())); 329 fixedLabel.setText(Format("{} {}", font.family(), font.pointSize()));
330 } 330 }
331 } 331 }
332 332
333 private: 333 private:
334 334