Changeset 561 for trunk/demos/browser/browsermainwindow.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/demos/browser/browsermainwindow.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 82 82 , m_reload(0) 83 83 { 84 setToolButtonStyle(Qt::ToolButtonFollowStyle); 84 85 setAttribute(Qt::WA_DeleteOnClose, true); 85 86 statusBar()->setSizeGripEnabled(true); … … 90 91 BookmarksModel *boomarksModel = BrowserApplication::bookmarksManager()->bookmarksModel(); 91 92 m_bookmarksToolbar = new BookmarksToolBar(boomarksModel, this); 92 connect(m_bookmarksToolbar, SIGNAL(openUrl( const QUrl&)),93 m_tabWidget, SLOT(loadUrlInCurrentTab( const QUrl&)));93 connect(m_bookmarksToolbar, SIGNAL(openUrl(QUrl)), 94 m_tabWidget, SLOT(loadUrlInCurrentTab(QUrl))); 94 95 connect(m_bookmarksToolbar->toggleViewAction(), SIGNAL(toggled(bool)), 95 96 this, SLOT(updateBookmarksToolbarActionText(bool))); … … 109 110 setCentralWidget(centralWidget); 110 111 111 connect(m_tabWidget, SIGNAL(loadPage( const QString &)),112 this, SLOT(loadPage( const QString &)));113 connect(m_tabWidget, SIGNAL(setCurrentTitle( const QString &)),114 this, SLOT(slotUpdateWindowTitle( const QString &)));115 connect(m_tabWidget, SIGNAL(showStatusBarMessage( const QString&)),116 statusBar(), SLOT(showMessage( const QString&)));117 connect(m_tabWidget, SIGNAL(linkHovered( const QString&)),118 statusBar(), SLOT(showMessage( const QString&)));112 connect(m_tabWidget, SIGNAL(loadPage(QString)), 113 this, SLOT(loadPage(QString))); 114 connect(m_tabWidget, SIGNAL(setCurrentTitle(QString)), 115 this, SLOT(slotUpdateWindowTitle(QString))); 116 connect(m_tabWidget, SIGNAL(showStatusBarMessage(QString)), 117 statusBar(), SLOT(showMessage(QString))); 118 connect(m_tabWidget, SIGNAL(linkHovered(QString)), 119 statusBar(), SLOT(showMessage(QString))); 119 120 connect(m_tabWidget, SIGNAL(loadProgress(int)), 120 121 this, SLOT(slotLoadProgress(int))); 121 122 connect(m_tabWidget, SIGNAL(tabsChanged()), 122 123 m_autoSaver, SLOT(changeOccurred())); 123 connect(m_tabWidget, SIGNAL(geometryChangeRequested( const QRect &)),124 this, SLOT(geometryChangeRequested( const QRect &)));125 connect(m_tabWidget, SIGNAL(printRequested(QWebFrame 126 this, SLOT(printRequested(QWebFrame 124 connect(m_tabWidget, SIGNAL(geometryChangeRequested(QRect)), 125 this, SLOT(geometryChangeRequested(QRect))); 126 connect(m_tabWidget, SIGNAL(printRequested(QWebFrame*)), 127 this, SLOT(printRequested(QWebFrame*))); 127 128 connect(m_tabWidget, SIGNAL(menuBarVisibilityChangeRequested(bool)), 128 129 menuBar(), SLOT(setVisible(bool))); … … 369 370 // History 370 371 HistoryMenu *historyMenu = new HistoryMenu(this); 371 connect(historyMenu, SIGNAL(openUrl( const QUrl&)),372 m_tabWidget, SLOT(loadUrlInCurrentTab( const QUrl&)));373 connect(historyMenu, SIGNAL(hovered( const QString&)), this,374 SLOT(slotUpdateStatusbar( const QString&)));372 connect(historyMenu, SIGNAL(openUrl(QUrl)), 373 m_tabWidget, SLOT(loadUrlInCurrentTab(QUrl))); 374 connect(historyMenu, SIGNAL(hovered(QString)), this, 375 SLOT(slotUpdateStatusbar(QString))); 375 376 historyMenu->setTitle(tr("Hi&story")); 376 377 menuBar()->addMenu(historyMenu); … … 404 405 // Bookmarks 405 406 BookmarksMenu *bookmarksMenu = new BookmarksMenu(this); 406 connect(bookmarksMenu, SIGNAL(openUrl( const QUrl&)),407 m_tabWidget, SLOT(loadUrlInCurrentTab( const QUrl&)));408 connect(bookmarksMenu, SIGNAL(hovered( const QString&)),409 this, SLOT(slotUpdateStatusbar( const QString&)));407 connect(bookmarksMenu, SIGNAL(openUrl(QUrl)), 408 m_tabWidget, SLOT(loadUrlInCurrentTab(QUrl))); 409 connect(bookmarksMenu, SIGNAL(hovered(QString)), 410 this, SLOT(slotUpdateStatusbar(QString))); 410 411 bookmarksMenu->setTitle(tr("&Bookmarks")); 411 412 menuBar()->addMenu(bookmarksMenu); … … 455 456 connect(m_historyBackMenu, SIGNAL(aboutToShow()), 456 457 this, SLOT(slotAboutToShowBackMenu())); 457 connect(m_historyBackMenu, SIGNAL(triggered(QAction 458 this, SLOT(slotOpenActionUrl(QAction 458 connect(m_historyBackMenu, SIGNAL(triggered(QAction*)), 459 this, SLOT(slotOpenActionUrl(QAction*))); 459 460 m_navigationBar->addAction(m_historyBack); 460 461 … … 463 464 connect(m_historyForwardMenu, SIGNAL(aboutToShow()), 464 465 this, SLOT(slotAboutToShowForwardMenu())); 465 connect(m_historyForwardMenu, SIGNAL(triggered(QAction 466 this, SLOT(slotOpenActionUrl(QAction 466 connect(m_historyForwardMenu, SIGNAL(triggered(QAction*)), 467 this, SLOT(slotOpenActionUrl(QAction*))); 467 468 m_historyForward->setMenu(m_historyForwardMenu); 468 469 m_navigationBar->addAction(m_historyForward); … … 478 479 m_toolbarSearch = new ToolbarSearch(m_navigationBar); 479 480 m_navigationBar->addWidget(m_toolbarSearch); 480 connect(m_toolbarSearch, SIGNAL(search( const QUrl&)), SLOT(loadUrl(const QUrl&)));481 connect(m_toolbarSearch, SIGNAL(search(QUrl)), SLOT(loadUrl(QUrl))); 481 482 482 483 m_chaseWidget = new ChaseWidget(this); … … 487 488 { 488 489 BookmarksDialog *dialog = new BookmarksDialog(this); 489 connect(dialog, SIGNAL(openUrl( const QUrl&)),490 m_tabWidget, SLOT(loadUrlInCurrentTab( const QUrl&)));490 connect(dialog, SIGNAL(openUrl(QUrl)), 491 m_tabWidget, SLOT(loadUrlInCurrentTab(QUrl))); 491 492 dialog->show(); 492 493 } … … 550 551 } 551 552 m_autoSaver->changeOccurred(); 552 }553 554 QUrl BrowserMainWindow::guessUrlFromString(const QString &string)555 {556 QString urlStr = string.trimmed();557 QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*"));558 559 // Check if it looks like a qualified URL. Try parsing it and see.560 bool hasSchema = test.exactMatch(urlStr);561 if (hasSchema) {562 QUrl url = QUrl::fromEncoded(urlStr.toUtf8(), QUrl::TolerantMode);563 if (url.isValid())564 return url;565 }566 567 // Might be a file.568 if (QFile::exists(urlStr)) {569 QFileInfo info(urlStr);570 return QUrl::fromLocalFile(info.absoluteFilePath());571 }572 573 // Might be a shorturl - try to detect the schema.574 if (!hasSchema) {575 int dotIndex = urlStr.indexOf(QLatin1Char('.'));576 if (dotIndex != -1) {577 QString prefix = urlStr.left(dotIndex).toLower();578 QByteArray schema = (prefix == QLatin1String("ftp")) ? prefix.toLatin1() : "http";579 QUrl url =580 QUrl::fromEncoded(schema + "://" + urlStr.toUtf8(), QUrl::TolerantMode);581 if (url.isValid())582 return url;583 }584 }585 586 // Fall back to QUrl's own tolerant parser.587 QUrl url = QUrl::fromEncoded(string.toUtf8(), QUrl::TolerantMode);588 589 // finally for cases where the user just types in a hostname add http590 if (url.scheme().isEmpty())591 url = QUrl::fromEncoded("http://" + string.toUtf8(), QUrl::TolerantMode);592 return url;593 553 } 594 554 … … 677 637 return; 678 638 QPrintPreviewDialog *dialog = new QPrintPreviewDialog(this); 679 connect(dialog, SIGNAL(paintRequested(QPrinter 680 currentTab(), SLOT(print(QPrinter 639 connect(dialog, SIGNAL(paintRequested(QPrinter*)), 640 currentTab(), SLOT(print(QPrinter*))); 681 641 dialog->exec(); 682 642 #endif … … 740 700 int ret = QMessageBox::warning(this, QString(), 741 701 tr("Are you sure you want to close the window?" 742 " There are %1 tab open").arg(m_tabWidget->count()),702 " There are %1 tabs open").arg(m_tabWidget->count()), 743 703 QMessageBox::Yes | QMessageBox::No, 744 704 QMessageBox::No); … … 839 799 QSettings settings; 840 800 settings.beginGroup(QLatin1String("MainWindow")); 841 QString home = settings.value(QLatin1String("home"), QLatin1String("http://qt software.com/")).toString();801 QString home = settings.value(QLatin1String("home"), QLatin1String("http://qt.nokia.com/")).toString(); 842 802 loadPage(home); 843 803 } … … 873 833 void BrowserMainWindow::loadPage(const QString &page) 874 834 { 875 QUrl url = guessUrlFromString(page);835 QUrl url = QUrl::fromUserInput(page); 876 836 loadUrl(url); 877 837 }
Note:
See TracChangeset
for help on using the changeset viewer.