Mercurial > projects > qtd
comparison demos/browser/browserapplication.d @ 150:a8d76a9a85aa
more porting
author | mandel |
---|---|
date | Sun, 14 Jun 2009 14:27:44 +0000 |
parents | 8636c819ce4d |
children |
comparison
equal
deleted
inserted
replaced
149:7bc921c7100a | 150:a8d76a9a85aa |
---|---|
128 } | 128 } |
129 | 129 |
130 version(QT_NO_OPENSSL) {} else { | 130 version(QT_NO_OPENSSL) {} else { |
131 if (!QSslSocket.supportsSsl()) { | 131 if (!QSslSocket.supportsSsl()) { |
132 QMessageBox.information(null, "Demo Browser", | 132 QMessageBox.information(null, "Demo Browser", |
133 "This system does not support OpenSSL. SSL websites will not be available."); | 133 "This system does not support OpenSSL. SSL websites will not be available."); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 QDesktopServices.setUrlHandler("http", this, "openUrl"); | 137 QDesktopServices.setUrlHandler("http", &this.openUrl); |
138 string localSysName = QLocale.system().name(); | 138 string localSysName = QLocale.system().name(); |
139 | 139 |
140 installTranslator("qt_" ~ localSysName); | 140 installTranslator("qt_" ~ localSysName); |
141 | 141 |
142 auto settings = new QSettings; | 142 auto settings = new QSettings; |
167 return cast(BrowserApplication) QCoreApplication.instance(); | 167 return cast(BrowserApplication) QCoreApplication.instance(); |
168 } | 168 } |
169 | 169 |
170 void loadSettings() | 170 void loadSettings() |
171 { | 171 { |
172 QSettings settings; | 172 QSettings settings = new QSettings; |
173 settings.beginGroup("websettings"); | 173 settings.beginGroup("websettings"); |
174 | 174 |
175 QWebSettings defaultSettings = QWebSettings.globalSettings(); | 175 QWebSettings defaultSettings = QWebSettings.globalSettings(); |
176 string standardFontFamily = defaultSettings.fontFamily(QWebSettings.StandardFont); | 176 string standardFontFamily = defaultSettings.fontFamily(QWebSettings.StandardFont); |
177 int standardFontSize = defaultSettings.fontSize(QWebSettings.DefaultFontSize); | 177 int standardFontSize = defaultSettings.fontSize(QWebSettings.DefaultFontSize); |
178 QFont standardFont = new QFont(standardFontFamily, standardFontSize); | 178 QFont standardFont = new QFont(standardFontFamily, standardFontSize); |
179 standardFont = qVariantValue!(QFont)(settings.value("standardFont", standardFont)); | 179 standardFont = QVariant.fromValue!(QFont)(settings.value("standardFont", standardFont)); |
180 defaultSettings.setFontFamily(QWebSettings.StandardFont, standardFont.family()); | 180 defaultSettings.setFontFamily(QWebSettings.StandardFont, standardFont.family()); |
181 defaultSettings.setFontSize(QWebSettings.DefaultFontSize, standardFont.pointSize()); | 181 defaultSettings.setFontSize(QWebSettings.DefaultFontSize, standardFont.pointSize()); |
182 | 182 |
183 string fixedFontFamily = defaultSettings.fontFamily(QWebSettings.FixedFont); | 183 string fixedFontFamily = defaultSettings.fontFamily(QWebSettings.FixedFont); |
184 int fixedFontSize = defaultSettings.fontSize(QWebSettings.DefaultFixedFontSize); | 184 int fixedFontSize = defaultSettings.fontSize(QWebSettings.DefaultFixedFontSize); |
185 QFont fixedFont = QFont(fixedFontFamily, fixedFontSize); | 185 QFont fixedFont = new QFont(fixedFontFamily, fixedFontSize); |
186 fixedFont = qVariantValue!(QFont)(settings.value("fixedFont", fixedFont)); | 186 fixedFont = QVariant.fromValue!(QFont)(settings.value("fixedFont", fixedFont)); |
187 defaultSettings.setFontFamily(QWebSettings.FixedFont, fixedFont.family()); | 187 defaultSettings.setFontFamily(QWebSettings.FixedFont, fixedFont.family()); |
188 defaultSettings.setFontSize(QWebSettings.DefaultFixedFontSize, fixedFont.pointSize()); | 188 defaultSettings.setFontSize(QWebSettings.DefaultFixedFontSize, fixedFont.pointSize()); |
189 | 189 |
190 defaultSettings.setAttribute(QWebSettings.JavascriptEnabled, settings.value("enableJavascript", true).toBool()); | 190 defaultSettings.setAttribute(QWebSettings.JavascriptEnabled, settings.value("enableJavascript", new QVariant(true)).toBool()); |
191 defaultSettings.setAttribute(QWebSettings.PluginsEnabled, settings.value("enablePlugins", true).toBool()); | 191 defaultSettings.setAttribute(QWebSettings.PluginsEnabled, settings.value("enablePlugins", new QVariant(true)).toBool()); |
192 | 192 |
193 QUrl url = settings.value("userStyleSheet").toUrl(); | 193 QUrl url = settings.value("userStyleSheet").toUrl(); |
194 defaultSettings.setUserStyleSheetUrl(url); | 194 defaultSettings.setUserStyleSheetUrl(url); |
195 | 195 |
196 settings.endGroup(); | 196 settings.endGroup(); |
197 } | 197 } |
198 | 198 |
199 bool isTheOnlyBrowser() | 199 bool isTheOnlyBrowser() |
200 { | 200 { |
201 return (m_localServer != null); | 201 return (m_localServer !is null); |
202 } | 202 } |
203 | 203 |
204 BrowserMainWindow mainWindow() | 204 BrowserMainWindow mainWindow() |
205 { | 205 { |
206 clean(); | 206 clean(); |
234 if (globalSettings.testAttribute(QWebSettings.PrivateBrowsingEnabled)) | 234 if (globalSettings.testAttribute(QWebSettings.PrivateBrowsingEnabled)) |
235 return; | 235 return; |
236 | 236 |
237 clean(); | 237 clean(); |
238 | 238 |
239 QSettings settings; | 239 QSettings settings = new QSettings; |
240 settings.beginGroup("sessions"); | 240 settings.beginGroup("sessions"); |
241 | 241 |
242 QByteArray data; | 242 QByteArray data = new QByteArray; |
243 auto buffer = new QBuffer(&data); | 243 auto buffer = new QBuffer(&data); |
244 auto stream = new QDataStream(&buffer); | 244 auto stream = new QDataStream(&buffer); |
245 buffer.open(QIODevice.ReadWrite); | 245 buffer.open(QIODevice.ReadWrite); |
246 | 246 |
247 stream << m_mainWindows.length; | 247 stream.writeLong(m_mainWindows.length); |
248 for (int i = 0; i < m_mainWindows.length; ++i) | 248 for (int i = 0; i < m_mainWindows.length; ++i) |
249 stream << m_mainWindows[i].saveState(); | 249 stream << m_mainWindows[i].saveState(); |
250 settings.setValue("lastSession", data); | 250 settings.setValue("lastSession", data); |
251 settings.endGroup(); | 251 settings.endGroup(); |
252 } | 252 } |
345 for (int i = 0; i < windowCount; ++i) { | 345 for (int i = 0; i < windowCount; ++i) { |
346 QByteArray windowState; | 346 QByteArray windowState; |
347 stream >> windowState; | 347 stream >> windowState; |
348 windows ~= windowState; | 348 windows ~= windowState; |
349 } | 349 } |
350 for (int i = 0; i < windows.count(); ++i) { | 350 for (int i = 0; i < windows.length; ++i) { |
351 BrowserMainWindow newWindow = 0; | 351 BrowserMainWindow newWindow = 0; |
352 if (m_mainWindows.length == 1 && mainWindow().tabWidget().count() == 1 | 352 if (m_mainWindows.length == 1 && mainWindow().tabWidget().count() == 1 |
353 && mainWindow().currentTab().getUrl() is null) { | 353 && mainWindow().currentTab().getUrl() is null) { |
354 newWindow = mainWindow(); | 354 newWindow = mainWindow(); |
355 } else { | 355 } else { |
411 loadSettings(); | 411 loadSettings(); |
412 | 412 |
413 // newMainWindow() needs to be called in main() for this to happen | 413 // newMainWindow() needs to be called in main() for this to happen |
414 if (m_mainWindows.length > 0) { | 414 if (m_mainWindows.length > 0) { |
415 string[] args = QCoreApplication.arguments(); | 415 string[] args = QCoreApplication.arguments(); |
416 if (args.count() > 1) | 416 if (args.length > 1) |
417 mainWindow().loadPage(args.last()); | 417 mainWindow().loadPage(args.last()); |
418 else | 418 else |
419 mainWindow().slotHome(); | 419 mainWindow().slotHome(); |
420 } | 420 } |
421 BrowserApplication.historyManager(); | 421 BrowserApplication.historyManager(); |
422 } | 422 } |
423 | 423 |
424 void openUrl( QUrl url) | 424 void openUrl(QUrl url) |
425 { | 425 { |
426 mainWindow().loadPage(url.toString()); | 426 mainWindow().loadPage(url.toString()); |
427 } | 427 } |
428 | 428 |
429 void newLocalSocketConnection() | 429 void newLocalSocketConnection() |
430 { | 430 { |
431 QLocalSocket socket = m_localServer.nextPendingConnection(); | 431 QLocalSocket socket = m_localServer.nextPendingConnection(); |
432 if (!socket) | 432 if (!socket) |
433 return; | 433 return; |
434 socket.waitForReadyRead(1000); | 434 socket.waitForReadyRead(1000); |
435 QTextStream stream(socket); | 435 auto stream = new QTextStream(socket); |
436 string url; | 436 string url; |
437 stream >> url; | 437 stream >> url; |
438 if (!url.isEmpty()) { | 438 if (url.length) { |
439 QSettings settings; | 439 QSettings settings; |
440 settings.beginGroup("general"); | 440 settings.beginGroup("general"); |
441 int openLinksIn = settings.value("openLinksIn", 0).toInt(); | 441 int openLinksIn = settings.value("openLinksIn", new QVariant(0)).toInt(); |
442 settings.endGroup(); | 442 settings.endGroup(); |
443 if (openLinksIn == 1) | 443 if (openLinksIn == 1) |
444 newMainWindow(); | 444 newMainWindow(); |
445 else | 445 else |
446 mainWindow().tabWidget().newTab(); | 446 mainWindow().tabWidget().newTab(); |
455 | 455 |
456 void clean() | 456 void clean() |
457 { | 457 { |
458 // cleanup any deleted main windows first | 458 // cleanup any deleted main windows first |
459 for (int i = m_mainWindows.length - 1; i >= 0; --i) | 459 for (int i = m_mainWindows.length - 1; i >= 0; --i) |
460 if (m_mainWindows[i].isNull()) | 460 if (m_mainWindows[i] is null) |
461 m_mainWindows.removeAt(i); | 461 m_mainWindows.removeAt(i); |
462 } | 462 } |
463 | 463 |
464 void installTranslator(string name) | 464 void installTranslator(string name) |
465 { | 465 { |