Mercurial > projects > qtd
comparison demos/browser/browserapplication.d @ 94:87bb4e622f9e
more porting
author | mandel |
---|---|
date | Thu, 28 May 2009 22:11:52 +0000 |
parents | 85c59c4e5f19 |
children | 8636c819ce4d |
comparison
equal
deleted
inserted
replaced
93:55fd7080c4b9 | 94:87bb4e622f9e |
---|---|
47 import qt.core.QLibraryInfo; | 47 import qt.core.QLibraryInfo; |
48 import qt.core.QSettings; | 48 import qt.core.QSettings; |
49 import qt.core.QTextStream; | 49 import qt.core.QTextStream; |
50 import qt.core.QTranslator; | 50 import qt.core.QTranslator; |
51 import qt.core.QUrl; | 51 import qt.core.QUrl; |
52 import qt.core.QPointer; | 52 //import qt.core.QPointer; |
53 | 53 |
54 import qt.gui.QApplication; | 54 import qt.gui.QApplication; |
55 import qt.gui.QIcon; | 55 import qt.gui.QIcon; |
56 import qt.gui.QDesktopServices; | 56 import qt.gui.QDesktopServices; |
57 import qt.gui.QFileOpenEvent; | 57 import qt.gui.QFileOpenEvent; |
60 import qt.network.QLocalServer; | 60 import qt.network.QLocalServer; |
61 import qt.network.QLocalSocket; | 61 import qt.network.QLocalSocket; |
62 import qt.network.QNetworkProxy; | 62 import qt.network.QNetworkProxy; |
63 import qt.network.QSslSocket; | 63 import qt.network.QSslSocket; |
64 | 64 |
65 import QtWebKit.QWebSettings; | 65 import qt.webkit.QWebSettings; |
66 | 66 |
67 import qt.core.QDebug; | 67 //import qt.core.QDebug; |
68 | 68 |
69 import bookmarks; | 69 import bookmarks; |
70 import browsermainwindow; | 70 import browsermainwindow; |
71 import cookiejar; | 71 import cookiejar; |
72 import downloadmanager; | 72 import downloadmanager; |
99 auto socket = new QLocalSocket; | 99 auto socket = new QLocalSocket; |
100 socket.connectToServer(serverName); | 100 socket.connectToServer(serverName); |
101 if (socket.waitForConnected(500)) { | 101 if (socket.waitForConnected(500)) { |
102 auto stream = new QTextStream(&socket); | 102 auto stream = new QTextStream(&socket); |
103 string[] args = QCoreApplication.arguments(); | 103 string[] args = QCoreApplication.arguments(); |
104 if (args.count() > 1) | 104 if (args.length > 1) |
105 stream << args.last(); | 105 stream << args[$-1]; |
106 else | 106 else |
107 stream << ""; | 107 stream << ""; |
108 stream.flush(); | 108 stream.flush(); |
109 socket.waitForBytesWritten(); | 109 socket.waitForBytesWritten(); |
110 return; | 110 return; |
201 } | 201 } |
202 | 202 |
203 BrowserMainWindow mainWindow() | 203 BrowserMainWindow mainWindow() |
204 { | 204 { |
205 clean(); | 205 clean(); |
206 if (m_mainWindows.isEmpty()) | 206 if (m_mainWindows.length == 0) |
207 newMainWindow(); | 207 newMainWindow(); |
208 return m_mainWindows[0]; | 208 return m_mainWindows[0]; |
209 } | 209 } |
210 | 210 |
211 BrowserMainWindow[] mainWindows() | 211 BrowserMainWindow[] mainWindows() |
301 bool event(QEvent event) | 301 bool event(QEvent event) |
302 { | 302 { |
303 switch (event.type()) { | 303 switch (event.type()) { |
304 case QEvent.ApplicationActivate: { | 304 case QEvent.ApplicationActivate: { |
305 clean(); | 305 clean(); |
306 if (!m_mainWindows.isEmpty()) { | 306 if (m_mainWindows.length) { |
307 BrowserMainWindow mw = mainWindow(); | 307 BrowserMainWindow mw = mainWindow(); |
308 if (mw && !mw.isMinimized()) { | 308 if (mw && !mw.isMinimized()) { |
309 mainWindow().show(); | 309 mainWindow().show(); |
310 } | 310 } |
311 return true; | 311 return true; |
312 } | 312 } |
313 } | 313 } |
314 case QEvent.FileOpen: | 314 case QEvent.FileOpen: |
315 if (!m_mainWindows.isEmpty()) { | 315 if (m_mainWindows.length) { |
316 mainWindow().loadPage(cast(QFileOpenEvent) event.file()); | 316 mainWindow().loadPage(cast(QFileOpenEvent) event.file()); |
317 return true; | 317 return true; |
318 } | 318 } |
319 default: | 319 default: |
320 break; | 320 break; |
326 public: | 326 public: |
327 | 327 |
328 BrowserMainWindow newMainWindow() | 328 BrowserMainWindow newMainWindow() |
329 { | 329 { |
330 BrowserMainWindow browser = new BrowserMainWindow(); | 330 BrowserMainWindow browser = new BrowserMainWindow(); |
331 m_mainWindows.prepend(browser); | 331 m_mainWindows = [browser] ~ m_mainWindows; |
332 browser.show(); | 332 browser.show(); |
333 return browser; | 333 return browser; |
334 } | 334 } |
335 | 335 |
336 void restoreLastSession() | 336 void restoreLastSession() |
346 stream >> windowState; | 346 stream >> windowState; |
347 windows ~= windowState; | 347 windows ~= windowState; |
348 } | 348 } |
349 for (int i = 0; i < windows.count(); ++i) { | 349 for (int i = 0; i < windows.count(); ++i) { |
350 BrowserMainWindow newWindow = 0; | 350 BrowserMainWindow newWindow = 0; |
351 if (m_mainWindows.count() == 1 && mainWindow().tabWidget().count() == 1 | 351 if (m_mainWindows.length == 1 && mainWindow().tabWidget().count() == 1 |
352 && mainWindow().currentTab().url() == QUrl()) { | 352 && mainWindow().currentTab().getUrl() is null) { |
353 newWindow = mainWindow(); | 353 newWindow = mainWindow(); |
354 } else { | 354 } else { |
355 newWindow = newMainWindow(); | 355 newWindow = newMainWindow(); |
356 } | 356 } |
357 newWindow.restoreState(windows[i]); | 357 newWindow.restoreState(windows[i]); |
371 tabCount =+ m_mainWindows[i].tabWidget().count(); | 371 tabCount =+ m_mainWindows[i].tabWidget().count(); |
372 } | 372 } |
373 | 373 |
374 if (tabCount > 1) { | 374 if (tabCount > 1) { |
375 int ret = QMessageBox.warning(mainWindow(), null, | 375 int ret = QMessageBox.warning(mainWindow(), null, |
376 tr("There are %1 windows and %2 tabs open\n" | 376 Format(tr("There are %1 windows and %2 tabs open\n" |
377 "Do you want to quit anyway?").arg(m_mainWindows.count()).arg(tabCount), | 377 "Do you want to quit anyway?"), m_mainWindows.length, tabCount), |
378 QMessageBox.Yes | QMessageBox.No, | 378 QMessageBox.Yes | QMessageBox.No, |
379 QMessageBox.No); | 379 QMessageBox.No); |
380 if (ret == QMessageBox.No) | 380 if (ret == QMessageBox.No) |
381 return; | 381 return; |
382 } | 382 } |
387 void lastWindowClosed() | 387 void lastWindowClosed() |
388 { | 388 { |
389 clean(); | 389 clean(); |
390 BrowserMainWindow mw = new BrowserMainWindow; | 390 BrowserMainWindow mw = new BrowserMainWindow; |
391 mw.slotHome(); | 391 mw.slotHome(); |
392 m_mainWindows.prepend(mw); | 392 m_mainWindows = [mw] ~ m_mainWindows; |
393 } | 393 } |
394 } | 394 } |
395 | |
396 | 395 |
397 private: | 396 private: |
398 | 397 |
399 /*! | 398 /*! |
400 Any actions that can be delayed until the window is visible | 399 Any actions that can be delayed until the window is visible |
409 setWindowIcon(new QIcon(":browser.svg")); | 408 setWindowIcon(new QIcon(":browser.svg")); |
410 | 409 |
411 loadSettings(); | 410 loadSettings(); |
412 | 411 |
413 // newMainWindow() needs to be called in main() for this to happen | 412 // newMainWindow() needs to be called in main() for this to happen |
414 if (m_mainWindows.count() > 0) { | 413 if (m_mainWindows.length > 0) { |
415 string[] args = QCoreApplication.arguments(); | 414 string[] args = QCoreApplication.arguments(); |
416 if (args.count() > 1) | 415 if (args.count() > 1) |
417 mainWindow().loadPage(args.last()); | 416 mainWindow().loadPage(args.last()); |
418 else | 417 else |
419 mainWindow().slotHome(); | 418 mainWindow().slotHome(); |
471 static HistoryManager s_historyManager; | 470 static HistoryManager s_historyManager; |
472 static DownloadManager s_downloadManager; | 471 static DownloadManager s_downloadManager; |
473 static NetworkAccessManager s_networkAccessManager; | 472 static NetworkAccessManager s_networkAccessManager; |
474 static BookmarksManager s_bookmarksManager; | 473 static BookmarksManager s_bookmarksManager; |
475 | 474 |
476 QPointer!(BrowserMainWindow)[] m_mainWindows; | 475 //QPointer!(BrowserMainWindow)[] m_mainWindows; |
476 BrowserMainWindow[] m_mainWindows; | |
477 QLocalServer m_localServer; | 477 QLocalServer m_localServer; |
478 QByteArray m_lastSession; | 478 QByteArray m_lastSession; |
479 QIcon m_defaultIcon; | 479 QIcon m_defaultIcon; |
480 } | 480 } |