Mercurial > projects > qtd
comparison demos/browser/browserapplication.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 |
---|---|
82 | 82 |
83 this(string[] args) | 83 this(string[] args) |
84 { | 84 { |
85 super(args); | 85 super(args); |
86 m_localServer = null; | 86 m_localServer = null; |
87 QCoreApplication.setOrganizationName(QLatin1String("Trolltech")); | 87 QCoreApplication.setOrganizationName("Trolltech"); |
88 QCoreApplication.setApplicationName(QLatin1String("demobrowser")); | 88 QCoreApplication.setApplicationName("demobrowser"); |
89 QCoreApplication.setApplicationVersion(QLatin1String("0.1")); | 89 QCoreApplication.setApplicationVersion("0.1"); |
90 version(Q_WS_QWS) | 90 version(Q_WS_QWS) |
91 { | 91 { |
92 // Use a different server name for QWS so we can run an X11 | 92 // Use a different server name for QWS so we can run an X11 |
93 // browser and a QWS browser in parallel on the same machine for | 93 // browser and a QWS browser in parallel on the same machine for |
94 // debugging | 94 // debugging |
95 string serverName = QCoreApplication.applicationName() + QLatin1String("_qws"); | 95 string serverName = QCoreApplication.applicationName() ~ "_qws"; |
96 } else { | 96 } else { |
97 string serverName = QCoreApplication.applicationName(); | 97 string serverName = QCoreApplication.applicationName(); |
98 } | 98 } |
99 auto socket = new QLocalSocket; | 99 auto socket = new QLocalSocket; |
100 socket.connectToServer(serverName); | 100 socket.connectToServer(serverName); |
131 QMessageBox.information(0, "Demo Browser", | 131 QMessageBox.information(0, "Demo Browser", |
132 "This system does not support OpenSSL. SSL websites will not be available."); | 132 "This system does not support OpenSSL. SSL websites will not be available."); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 QDesktopServices.setUrlHandler(QLatin1String("http"), this, "openUrl"); | 136 QDesktopServices.setUrlHandler("http", this, "openUrl"); |
137 string localSysName = QLocale.system().name(); | 137 string localSysName = QLocale.system().name(); |
138 | 138 |
139 installTranslator(QLatin1String("qt_") + localSysName); | 139 installTranslator("qt_" ~ localSysName); |
140 | 140 |
141 QSettings settings; | 141 QSettings settings; |
142 settings.beginGroup(QLatin1String("sessions")); | 142 settings.beginGroup("sessions"); |
143 m_lastSession = settings.value(QLatin1String("lastSession")).toByteArray(); | 143 m_lastSession = settings.value("lastSession").toByteArray(); |
144 settings.endGroup(); | 144 settings.endGroup(); |
145 | 145 |
146 version(Q_WS_MAC) { | 146 version(Q_WS_MAC) { |
147 this.lastWindowClosed.connect(&this.lastWindowClosed); | 147 this.lastWindowClosed.connect(&this.lastWindowClosed); |
148 } | 148 } |
167 } | 167 } |
168 | 168 |
169 void loadSettings() | 169 void loadSettings() |
170 { | 170 { |
171 QSettings settings; | 171 QSettings settings; |
172 settings.beginGroup(QLatin1String("websettings")); | 172 settings.beginGroup("websettings"); |
173 | 173 |
174 QWebSettings defaultSettings = QWebSettings.globalSettings(); | 174 QWebSettings defaultSettings = QWebSettings.globalSettings(); |
175 string standardFontFamily = defaultSettings.fontFamily(QWebSettings.StandardFont); | 175 string standardFontFamily = defaultSettings.fontFamily(QWebSettings.StandardFont); |
176 int standardFontSize = defaultSettings.fontSize(QWebSettings.DefaultFontSize); | 176 int standardFontSize = defaultSettings.fontSize(QWebSettings.DefaultFontSize); |
177 QFont standardFont = QFont(standardFontFamily, standardFontSize); | 177 QFont standardFont = QFont(standardFontFamily, standardFontSize); |
178 standardFont = qVariantValue!(QFont)(settings.value(QLatin1String("standardFont"), standardFont)); | 178 standardFont = qVariantValue!(QFont)(settings.value("standardFont", standardFont)); |
179 defaultSettings.setFontFamily(QWebSettings.StandardFont, standardFont.family()); | 179 defaultSettings.setFontFamily(QWebSettings.StandardFont, standardFont.family()); |
180 defaultSettings.setFontSize(QWebSettings.DefaultFontSize, standardFont.pointSize()); | 180 defaultSettings.setFontSize(QWebSettings.DefaultFontSize, standardFont.pointSize()); |
181 | 181 |
182 string fixedFontFamily = defaultSettings.fontFamily(QWebSettings.FixedFont); | 182 string fixedFontFamily = defaultSettings.fontFamily(QWebSettings.FixedFont); |
183 int fixedFontSize = defaultSettings.fontSize(QWebSettings.DefaultFixedFontSize); | 183 int fixedFontSize = defaultSettings.fontSize(QWebSettings.DefaultFixedFontSize); |
184 QFont fixedFont = QFont(fixedFontFamily, fixedFontSize); | 184 QFont fixedFont = QFont(fixedFontFamily, fixedFontSize); |
185 fixedFont = qVariantValue!(QFont)(settings.value(QLatin1String("fixedFont"), fixedFont)); | 185 fixedFont = qVariantValue!(QFont)(settings.value("fixedFont", fixedFont)); |
186 defaultSettings.setFontFamily(QWebSettings.FixedFont, fixedFont.family()); | 186 defaultSettings.setFontFamily(QWebSettings.FixedFont, fixedFont.family()); |
187 defaultSettings.setFontSize(QWebSettings.DefaultFixedFontSize, fixedFont.pointSize()); | 187 defaultSettings.setFontSize(QWebSettings.DefaultFixedFontSize, fixedFont.pointSize()); |
188 | 188 |
189 defaultSettings.setAttribute(QWebSettings.JavascriptEnabled, settings.value(QLatin1String("enableJavascript"), true).toBool()); | 189 defaultSettings.setAttribute(QWebSettings.JavascriptEnabled, settings.value("enableJavascript", true).toBool()); |
190 defaultSettings.setAttribute(QWebSettings.PluginsEnabled, settings.value(QLatin1String("enablePlugins"), true).toBool()); | 190 defaultSettings.setAttribute(QWebSettings.PluginsEnabled, settings.value("enablePlugins", true).toBool()); |
191 | 191 |
192 QUrl url = settings.value(QLatin1String("userStyleSheet")).toUrl(); | 192 QUrl url = settings.value("userStyleSheet").toUrl(); |
193 defaultSettings.setUserStyleSheetUrl(url); | 193 defaultSettings.setUserStyleSheetUrl(url); |
194 | 194 |
195 settings.endGroup(); | 195 settings.endGroup(); |
196 } | 196 } |
197 | 197 |
221 { | 221 { |
222 QIcon icon = QWebSettings.iconForUrl(url); | 222 QIcon icon = QWebSettings.iconForUrl(url); |
223 if (!icon.isNull()) | 223 if (!icon.isNull()) |
224 return icon.pixmap(16, 16); | 224 return icon.pixmap(16, 16); |
225 if (m_defaultIcon.isNull()) | 225 if (m_defaultIcon.isNull()) |
226 m_defaultIcon = QIcon(QLatin1String(":defaulticon.png")); | 226 m_defaultIcon = QIcon(":defaulticon.png"); |
227 return m_defaultIcon.pixmap(16, 16); | 227 return m_defaultIcon.pixmap(16, 16); |
228 } | 228 } |
229 | 229 |
230 void saveSession() | 230 void saveSession() |
231 { | 231 { |
234 return; | 234 return; |
235 | 235 |
236 clean(); | 236 clean(); |
237 | 237 |
238 QSettings settings; | 238 QSettings settings; |
239 settings.beginGroup(QLatin1String("sessions")); | 239 settings.beginGroup("sessions"); |
240 | 240 |
241 QByteArray data; | 241 QByteArray data; |
242 auto buffer = new QBuffer(&data); | 242 auto buffer = new QBuffer(&data); |
243 auto stream = new QDataStream(&buffer); | 243 auto stream = new QDataStream(&buffer); |
244 buffer.open(QIODevice.ReadWrite); | 244 buffer.open(QIODevice.ReadWrite); |
245 | 245 |
246 stream << m_mainWindows.length; | 246 stream << m_mainWindows.length; |
247 for (int i = 0; i < m_mainWindows.length; ++i) | 247 for (int i = 0; i < m_mainWindows.length; ++i) |
248 stream << m_mainWindows[i].saveState(); | 248 stream << m_mainWindows[i].saveState(); |
249 settings.setValue(QLatin1String("lastSession"), data); | 249 settings.setValue("lastSession", data); |
250 settings.endGroup(); | 250 settings.endGroup(); |
251 } | 251 } |
252 | 252 |
253 bool canRestoreSession() | 253 bool canRestoreSession() |
254 { | 254 { |
401 */ | 401 */ |
402 void postLaunch() | 402 void postLaunch() |
403 { | 403 { |
404 string directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation); | 404 string directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation); |
405 if (directory.isEmpty()) | 405 if (directory.isEmpty()) |
406 directory = QDir.homePath() ~ QLatin1String("/.") ~ QCoreApplication.applicationName(); | 406 directory = QDir.homePath() ~ "/." ~ QCoreApplication.applicationName(); |
407 QWebSettings.setIconDatabasePath(directory); | 407 QWebSettings.setIconDatabasePath(directory); |
408 | 408 |
409 setWindowIcon(QIcon(QLatin1String(":browser.svg"))); | 409 setWindowIcon(new QIcon(":browser.svg")); |
410 | 410 |
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.count() > 0) { | 414 if (m_mainWindows.count() > 0) { |
435 QTextStream stream(socket); | 435 QTextStream stream(socket); |
436 string url; | 436 string url; |
437 stream >> url; | 437 stream >> url; |
438 if (!url.isEmpty()) { | 438 if (!url.isEmpty()) { |
439 QSettings settings; | 439 QSettings settings; |
440 settings.beginGroup(QLatin1String("general")); | 440 settings.beginGroup("general"); |
441 int openLinksIn = settings.value(QLatin1String("openLinksIn"), 0).toInt(); | 441 int openLinksIn = settings.value("openLinksIn", 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(); |