From b9f8ccd9099fa48406203ad5c5389266b3318d88 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 5 Dec 2008 00:27:23 +0100 Subject: QUrl --> KUrl! --- src/bookmarks.cpp | 4 +- src/bookmarks.h | 3 +- src/browserapplication.cpp | 27 ++++++---- src/browserapplication.h | 8 +-- src/browsermainwindow.cpp | 128 ++++++++++++++++++++++++++++++--------------- src/browsermainwindow.h | 9 ++-- src/history.cpp | 10 ++-- src/history.h | 27 +++++++--- src/searchbar.cpp | 2 +- src/searchbar.h | 4 +- src/settings.cpp | 25 ++++++--- src/tabwidget.cpp | 28 ++++++---- src/tabwidget.h | 12 +++-- src/urlbar.cpp | 33 +----------- src/urlbar.h | 4 -- src/webview.cpp | 112 ++++++++++++++++++++++----------------- src/webview.h | 16 ++++-- 17 files changed, 267 insertions(+), 185 deletions(-) (limited to 'src') diff --git a/src/bookmarks.cpp b/src/bookmarks.cpp index 6f9c3beb..e03bf3dc 100644 --- a/src/bookmarks.cpp +++ b/src/bookmarks.cpp @@ -32,13 +32,13 @@ OwnBookMarks::OwnBookMarks(KMainWindow *parent) , KBookmarkOwner() { m_parent = qobject_cast( parent ); - connect( this, SIGNAL( openUrl( const QUrl &) ) , parent , SLOT( loadUrl( const QUrl & ) ) ); + connect( this, SIGNAL( openUrl( const KUrl &) ) , parent , SLOT( loadUrl( const KUrl & ) ) ); } void OwnBookMarks::openBookmark (const KBookmark & b, Qt::MouseButtons , Qt::KeyboardModifiers ) { - emit openUrl( (QUrl)b.url() ); + emit openUrl( b.url() ); } QString OwnBookMarks::currentUrl() const diff --git a/src/bookmarks.h b/src/bookmarks.h index 80362e1c..950fc8a6 100644 --- a/src/bookmarks.h +++ b/src/bookmarks.h @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -43,7 +44,7 @@ public: virtual QString currentTitle() const; signals: - void openUrl(const QUrl &); // FIXME pass all to KUrl!! + void openUrl(const KUrl &); private: BrowserMainWindow *m_parent; diff --git a/src/browserapplication.cpp b/src/browserapplication.cpp index 3099dfc2..a79f28b2 100644 --- a/src/browserapplication.cpp +++ b/src/browserapplication.cpp @@ -19,6 +19,7 @@  * ============================================================ */ +// Local Includes #include "browserapplication.h" #include "browsermainwindow.h" @@ -29,9 +30,12 @@ #include "tabwidget.h" #include "webview.h" +// KDE Includes #include #include +#include +// Qt Includes #include #include #include @@ -259,18 +263,23 @@ void BrowserApplication::restoreLastSession() buffer.open(QIODevice::ReadOnly); int windowCount; stream >> windowCount; - for (int i = 0; i < windowCount; ++i) { + for (int i = 0; i < windowCount; ++i) + { QByteArray windowState; stream >> windowState; windows.append(windowState); } - for (int i = 0; i < windows.count(); ++i) { + for (int i = 0; i < windows.count(); ++i) + { BrowserMainWindow *newWindow = 0; if (m_mainWindows.count() == 1 && mainWindow()->tabWidget()->count() == 1 - && mainWindow()->currentTab()->url() == QUrl()) { + && mainWindow()->currentTab()->url() == QUrl()) + { newWindow = mainWindow(); - } else { + } + else + { newWindow = newMainWindow(); } newWindow->restoreState(windows.at(i)); @@ -295,9 +304,9 @@ void BrowserApplication::installTranslator(const QString &name) -void BrowserApplication::openUrl(const QUrl &url) +void BrowserApplication::openUrl(const KUrl &url) { - mainWindow()->loadPage(url.toString()); + mainWindow()->loadPage( url.url() ); } @@ -311,8 +320,6 @@ BrowserMainWindow *BrowserApplication::newMainWindow() } - - BrowserMainWindow *BrowserApplication::mainWindow() { clean(); @@ -322,8 +329,6 @@ BrowserMainWindow *BrowserApplication::mainWindow() } - - void BrowserApplication::newLocalSocketConnection() { QLocalSocket *socket = m_localServer->nextPendingConnection(); @@ -392,7 +397,7 @@ HistoryManager *BrowserApplication::historyManager() -KIcon BrowserApplication::icon(const QUrl &url) const +KIcon BrowserApplication::icon(const KUrl &url) const { KIcon icon = KIcon( QWebSettings::iconForUrl(url) ); if (!icon.isNull()) diff --git a/src/browserapplication.h b/src/browserapplication.h index 43d374d3..cee28895 100644 --- a/src/browserapplication.h +++ b/src/browserapplication.h @@ -22,11 +22,13 @@ #ifndef BROWSERAPPLICATION_H #define BROWSERAPPLICATION_H +// KDE Includes #include #include #include +#include -#include +// Qt Includes #include QT_BEGIN_NAMESPACE @@ -52,7 +54,7 @@ public: bool isTheOnlyBrowser() const; BrowserMainWindow *mainWindow(); QList mainWindows(); - KIcon icon(const QUrl &url) const; + KIcon icon(const KUrl &url) const; void saveSession(); bool canRestoreSession() const; @@ -68,7 +70,7 @@ public slots: private slots: void postLaunch(); - void openUrl(const QUrl &url); + void openUrl(const KUrl &url); void newLocalSocketConnection(); private: diff --git a/src/browsermainwindow.cpp b/src/browsermainwindow.cpp index 57c6e4bf..ada00b5c 100644 --- a/src/browsermainwindow.cpp +++ b/src/browsermainwindow.cpp @@ -308,7 +308,7 @@ void BrowserMainWindow::setupMenu() // ------------------------------------------------------------- HISTORY -------------------------------------------------------------------------------------------------- HistoryMenu *historyMenu = new HistoryMenu(this); - connect(historyMenu, SIGNAL(openUrl(const QUrl&)), m_tabWidget, SLOT(loadUrlInCurrentTab(const QUrl&))); + connect(historyMenu, SIGNAL(openUrl(const KUrl&)), m_tabWidget, SLOT(loadUrlInCurrentTab(const KUrl&))); connect(historyMenu, SIGNAL(hovered(const QString&)), this, SLOT(slotUpdateStatusbar(const QString&))); historyMenu->setTitle( i18n("Hi&story") ); menuBar()->addMenu(historyMenu); @@ -400,7 +400,7 @@ void BrowserMainWindow::setupToolBar() m_searchBar = new SearchBar(m_navigationBar); m_navigationBar->addWidget(m_searchBar); - connect(m_searchBar, SIGNAL(search(const QUrl&)), this, SLOT(loadUrl(const QUrl&))); + connect(m_searchBar, SIGNAL(search(const KUrl&)), this, SLOT(loadUrl(const KUrl&))); // UI settings m_navigationBar->setIconDimensions(16); @@ -443,52 +443,66 @@ void BrowserMainWindow::slotViewStatusbar() -QUrl BrowserMainWindow::guessUrlFromString(const QString &string) +KUrl BrowserMainWindow::guessUrlFromString(const QString &string) { QString urlStr = string.trimmed(); QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*")); // Check if it looks like a qualified URL. Try parsing it and see. bool hasSchema = test.exactMatch(urlStr); - if (hasSchema) { - QUrl url(urlStr, QUrl::TolerantMode); - if (url.isValid()) + if (hasSchema) + { + QUrl qurl(urlStr, QUrl::TolerantMode); + KUrl url(qurl); + if ( url.isValid() ) + { return url; + } } // Might be a file. - if (QFile::exists(urlStr)) { + if (QFile::exists(urlStr)) + { QFileInfo info(urlStr); - return QUrl::fromLocalFile(info.absoluteFilePath()); + return KUrl::fromPath( info.absoluteFilePath() ); } // Might be a shorturl - try to detect the schema. - if (!hasSchema) { + if (!hasSchema) + { int dotIndex = urlStr.indexOf(QLatin1Char('.')); - if (dotIndex != -1) { + if (dotIndex != -1) + { QString prefix = urlStr.left(dotIndex).toLower(); QString schema = (prefix == QLatin1String("ftp")) ? prefix : QLatin1String("http"); - QUrl url(schema + QLatin1String("://") + urlStr, QUrl::TolerantMode); - if (url.isValid()) + QUrl qurl(schema + QLatin1String("://") + urlStr, QUrl::TolerantMode); + KUrl url(qurl); + if ( url.isValid() ) + { return url; + } } } // Fall back to QUrl's own tolerant parser. - QUrl url = QUrl(string, QUrl::TolerantMode); + QUrl qurl = QUrl(string, QUrl::TolerantMode); + KUrl url(qurl); // finally for cases where the user just types in a hostname add http - if (url.scheme().isEmpty()) - url = QUrl(QLatin1String("http://") + string, QUrl::TolerantMode); + if ( qurl.scheme().isEmpty() ) + { + qurl = QUrl(QLatin1String("http://") + string, QUrl::TolerantMode); + url = KUrl(qurl); + } return url; } -void BrowserMainWindow::loadUrl(const QUrl &url) +void BrowserMainWindow::loadUrl(const KUrl &url) { - loadPage(url.toString()); + loadPage( url.url() ); } @@ -574,8 +588,7 @@ void BrowserMainWindow::slotFilePrintPreview() if (!currentTab()) return; QPrintPreviewDialog *dialog = new QPrintPreviewDialog(this); - connect(dialog, SIGNAL(paintRequested(QPrinter *)), - currentTab(), SLOT(print(QPrinter *))); + connect(dialog, SIGNAL(paintRequested(QPrinter *)), currentTab(), SLOT(print(QPrinter *))); dialog->exec(); } @@ -595,7 +608,7 @@ void BrowserMainWindow::printRequested(QWebFrame *frame) QPrinter printer; QPrintDialog *dialog = new QPrintDialog(&printer, this); dialog->setWindowTitle( i18n("Print Document") ); - if (dialog->exec() != QDialog::Accepted) + if (dialog->exec() != QDialog::Accepted ) return; frame->print(&printer); } @@ -606,7 +619,8 @@ void BrowserMainWindow::slotPrivateBrowsing() { QWebSettings *settings = QWebSettings::globalSettings(); bool pb = settings->testAttribute(QWebSettings::PrivateBrowsingEnabled); - if (!pb) { + if (!pb) + { QString title = i18n("Are you sure you want to turn on private browsing?"); QString text = "" + title + i18n("

When private browsing in turned on," " webpages are not added to the history," @@ -620,14 +634,18 @@ void BrowserMainWindow::slotPrivateBrowsing() QMessageBox::StandardButton button = QMessageBox::question(this, QString(), text, QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok); - if (button == QMessageBox::Ok) { + if (button == QMessageBox::Ok) + { settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, true); } - } else { + } + else + { settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, false); QList windows = BrowserApplication::instance()->mainWindows(); - for (int i = 0; i < windows.count(); ++i) { + for (int i = 0; i < windows.count(); ++i) + { BrowserMainWindow *window = windows.at(i); window->m_lastSearch = QString::null; window->tabWidget()->clear(); @@ -639,13 +657,15 @@ void BrowserMainWindow::slotPrivateBrowsing() void BrowserMainWindow::closeEvent(QCloseEvent *event) { - if (m_tabWidget->count() > 1) { + if (m_tabWidget->count() > 1) + { int ret = QMessageBox::warning(this, QString(), i18n("Are you sure you want to close the window?" " There are %1 tab open" , m_tabWidget->count() ) , QMessageBox::Yes | QMessageBox::No, QMessageBox::No); - if (ret == QMessageBox::No) { + if (ret == QMessageBox::No) + { event->ignore(); return; } @@ -721,14 +741,27 @@ void BrowserMainWindow::slotViewTextSmaller() void BrowserMainWindow::slotViewFullScreen(bool makeFullScreen) { - if (makeFullScreen) { + if (makeFullScreen) + { showFullScreen(); - } else { - if (isMinimized()) + } + else + { + if ( isMinimized() ) + { showMinimized(); - else if (isMaximized()) - showMaximized(); - else showNormal(); + } + else + { + if (isMaximized()) + { + showMaximized(); + } + else + { + showNormal(); + } + } } } @@ -773,12 +806,14 @@ void BrowserMainWindow::slotWebSearch() void BrowserMainWindow::slotToggleInspector(bool enable) { QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, enable); - if (enable) { + if (enable) + { int result = QMessageBox::question(this, i18n("Web Inspector"), i18n("The web inspector will only work correctly for pages that were loaded after enabling.\n" "Do you want to reload all pages?"), QMessageBox::Yes | QMessageBox::No); - if (result == QMessageBox::Yes) { + if (result == QMessageBox::Yes) + { m_tabWidget->reloadAllTabs(); } } @@ -854,7 +889,8 @@ void BrowserMainWindow::slotAboutToShowBackMenu() return; QWebHistory *history = currentTab()->history(); int historyCount = history->count(); - for (int i = history->backItems(historyCount).count() - 1; i >= 0; --i) { + for (int i = history->backItems(historyCount).count() - 1; i >= 0; --i) + { QWebHistoryItem item = history->backItems(history->count()).at(i); KAction *action = new KAction(this); action->setData(-1*(historyCount-i-1)); @@ -877,7 +913,8 @@ void BrowserMainWindow::slotAboutToShowWindowMenu() m_windowMenu->addSeparator(); QList windows = BrowserApplication::instance()->mainWindows(); - for (int i = 0; i < windows.count(); ++i) { + for (int i = 0; i < windows.count(); ++i) + { BrowserMainWindow *window = windows.at(i); QAction *action = m_windowMenu->addAction(window->windowTitle(), this, SLOT(slotShowWindow())); action->setData(i); @@ -892,9 +929,11 @@ void BrowserMainWindow::slotAboutToShowWindowMenu() void BrowserMainWindow::slotShowWindow() { - if (KAction *action = qobject_cast(sender())) { + if (KAction *action = qobject_cast(sender())) + { QVariant v = action->data(); - if (v.canConvert()) { + if (v.canConvert()) + { int offset = qvariant_cast(v); QList windows = BrowserApplication::instance()->mainWindows(); windows.at(offset)->activateWindow(); @@ -911,10 +950,17 @@ void BrowserMainWindow::slotOpenActionUrl(QAction *action) int offset = action->data().toInt(); QWebHistory *history = currentTab()->history(); if (offset < 0) + { history->goToItem(history->backItems(-1*offset).first()); // back - else if (offset > 0) - history->goToItem(history->forwardItems(history->count() - offset + 1).back()); // forward - } + } + else + { + if (offset > 0) + { + history->goToItem(history->forwardItems(history->count() - offset + 1).back()); // forward + } + } +} void BrowserMainWindow::slotOpenPrevious() diff --git a/src/browsermainwindow.h b/src/browsermainwindow.h index 3c459d18..237f872d 100644 --- a/src/browsermainwindow.h +++ b/src/browsermainwindow.h @@ -27,14 +27,15 @@ #include "searchbar.h" // KDE Includes +#include #include #include #include #include #include -// Qt Includes -#include +// // Qt Includes +// #include class AutoSaver; @@ -57,7 +58,7 @@ public: QSize sizeHint() const; public: - static QUrl guessUrlFromString(const QString &url); + static KUrl guessUrlFromString(const QString &url); TabWidget *tabWidget() const; WebView *currentTab() const; QByteArray saveState(bool withTabs = true) const; @@ -80,7 +81,7 @@ private slots: void slotUpdateStatusbar(const QString &string); void slotUpdateWindowTitle(const QString &title = QString()); - void loadUrl(const QUrl &url); + void loadUrl(const KUrl &url); void slotPreferences(); void slotFileNew(); diff --git a/src/history.cpp b/src/history.cpp index cb6e80b0..43714166 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -181,10 +181,12 @@ void HistoryManager::addHistoryItem(const HistoryItem &item) -void HistoryManager::updateHistoryItem(const QUrl &url, const QString &title) +void HistoryManager::updateHistoryItem(const KUrl &url, const QString &title) { - for (int i = 0; i < m_history.count(); ++i) { - if (url == m_history.at(i).url) { + for (int i = 0; i < m_history.count(); ++i) + { + if (url == m_history.at(i).url) + { m_history[i].title = title; m_saveTimer->changeOccurred(); if (m_lastSavedUrl.isEmpty()) @@ -654,7 +656,7 @@ void HistoryMenu::postPopulated() void HistoryMenu::showHistoryDialog() { HistoryDialog *dialog = new HistoryDialog(this); - connect(dialog, SIGNAL(openUrl(const QUrl&)), this, SIGNAL(openUrl(const QUrl&))); + connect(dialog, SIGNAL(openUrl(const KUrl&)), this, SIGNAL(openUrl(const KUrl&))); dialog->show(); } diff --git a/src/history.h b/src/history.h index 97d7f34e..41763b69 100644 --- a/src/history.h +++ b/src/history.h @@ -25,18 +25,18 @@ // Local Includes #include "modelmenu.h" +// KDE Includes +#include +#include + // Qt Includes #include #include #include #include -#include #include #include -// KDE Includes -#include - class HistoryItem { @@ -61,13 +61,15 @@ public: +// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + class AutoSaver; class HistoryModel; class HistoryFilterModel; class HistoryTreeModel; -// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + class HistoryManager : public QWebHistoryInterface { Q_OBJECT @@ -86,7 +88,7 @@ public: bool historyContains(const QString &url) const; void addHistoryEntry(const QString &url); - void updateHistoryItem(const QUrl &url, const QString &title); + void updateHistoryItem(const KUrl &url, const QString &title); int historyLimit() const; void setHistoryLimit(int limit); @@ -126,6 +128,8 @@ private: // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + + class HistoryModel : public QAbstractTableModel { Q_OBJECT @@ -234,7 +238,7 @@ class HistoryMenu : public ModelMenu Q_OBJECT signals: - void openUrl(const QUrl &url); + void openUrl(const KUrl &url); public: HistoryMenu(QWidget *parent = 0); @@ -278,6 +282,8 @@ private slots: }; + +// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ // proxy model for the history model that converts the list // into a tree, one top level node per day. // Used in the HistoryDialog. @@ -312,6 +318,8 @@ private: }; + +// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ // A modified QSortFilterProxyModel that always accepts the root nodes in the tree // so filtering is only done on the children. // Used in the HistoryDialog @@ -326,6 +334,9 @@ protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; }; + +// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + #include "ui_history.h" class HistoryDialog : public QDialog, public Ui_HistoryDialog @@ -333,7 +344,7 @@ class HistoryDialog : public QDialog, public Ui_HistoryDialog Q_OBJECT signals: - void openUrl(const QUrl &url); + void openUrl(const KUrl &url); public: HistoryDialog(QWidget *parent = 0, HistoryManager *history = 0); diff --git a/src/searchbar.cpp b/src/searchbar.cpp index deb8d631..a2f1217f 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -46,7 +46,7 @@ void SearchBar::searchNow() { QString searchText = m_lineEdit->text(); - QUrl url(QLatin1String("http://www.google.com/search")); + KUrl url(QLatin1String("http://www.google.com/search")); url.addQueryItem(QLatin1String("q"), searchText); url.addQueryItem(QLatin1String("ie"), QLatin1String("UTF-8")); url.addQueryItem(QLatin1String("oe"), QLatin1String("UTF-8")); diff --git a/src/searchbar.h b/src/searchbar.h index 40235891..92f20f8e 100644 --- a/src/searchbar.h +++ b/src/searchbar.h @@ -23,10 +23,10 @@ // KDE Includes #include +#include // Qt Includes #include -#include class SearchBar : public QWidget { @@ -45,7 +45,7 @@ private: KLineEdit *m_lineEdit; signals: - void search(const QUrl &url); + void search(const KUrl &url); }; diff --git a/src/settings.cpp b/src/settings.cpp index d23e7def..2a440c19 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -23,8 +23,6 @@ #include "settings.h" #include "settings.moc" -// #include "ui_settings.h" - #include "browserapplication.h" #include "browsermainwindow.h" #include "cookiejar.h" @@ -68,6 +66,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) loadFromSettings(); } + void SettingsDialog::loadDefaults() { QWebSettings *defaultSettings = QWebSettings::globalSettings(); @@ -87,6 +86,7 @@ void SettingsDialog::loadDefaults() enablePlugins->setChecked(defaultSettings->testAttribute(QWebSettings::PluginsEnabled)); } + void SettingsDialog::loadFromSettings() { KConfig config("rekonqrc"); @@ -136,7 +136,8 @@ void SettingsDialog::loadFromSettings() CookieJar::AcceptPolicy acceptCookies = acceptPolicyEnum.keyToValue( value.toLocal8Bit() ) == -1 ? CookieJar::AcceptOnlyFromSitesNavigatedTo : static_cast(acceptPolicyEnum.keyToValue( value.toLocal8Bit() ) ); - switch(acceptCookies) { + switch(acceptCookies) + { case CookieJar::AcceptAlways: acceptCombo->setCurrentIndex(0); break; @@ -177,6 +178,7 @@ void SettingsDialog::loadFromSettings() } + void SettingsDialog::saveToSettings() { KConfig config("rekonqrc"); @@ -188,7 +190,8 @@ void SettingsDialog::saveToSettings() int historyExpire = expireHistory->currentIndex(); int idx = -1; - switch (historyExpire) { + switch (historyExpire) + { case 0: idx = 1; break; case 1: idx = 7; break; case 2: idx = 14; break; @@ -207,7 +210,8 @@ void SettingsDialog::saveToSettings() group3.writeEntry(QString("enablePlugins"), enablePlugins->isChecked() ); CookieJar::KeepPolicy keepCookies; - switch(acceptCombo->currentIndex()) { + switch(acceptCombo->currentIndex()) + { default: case 0: keepCookies = CookieJar::KeepUntilExpire; @@ -224,7 +228,8 @@ void SettingsDialog::saveToSettings() group3.writeEntry(QString("acceptCookies"), QString(acceptPolicyEnum.valueToKey(keepCookies) ) ); CookieJar::KeepPolicy keepPolicy; - switch(keepUntilCombo->currentIndex()) { + switch(keepUntilCombo->currentIndex()) + { default: case 0: keepPolicy = CookieJar::KeepUntilExpire; @@ -265,12 +270,14 @@ void SettingsDialog::showCookies() dialog->exec(); } + void SettingsDialog::showExceptions() { CookiesExceptionsDialog *dialog = new CookiesExceptionsDialog(BrowserApplication::cookieJar(), this); dialog->exec(); } + void SettingsDialog::chooseFont() { QFont myFont; @@ -282,6 +289,7 @@ void SettingsDialog::chooseFont() } } + void SettingsDialog::chooseFixedFont() { @@ -294,12 +302,15 @@ void SettingsDialog::chooseFixedFont() } } + void SettingsDialog::setHomeToCurrentPage() { BrowserMainWindow *mw = static_cast(parent()); WebView *webView = mw->currentTab(); if (webView) - homeLineEdit->setText(webView->url().toString()); + { + homeLineEdit->setText( webView->url().prettyUrl() ); + } } diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp index efa77a95..32d43d65 100644 --- a/src/tabwidget.cpp +++ b/src/tabwidget.cpp @@ -52,6 +52,7 @@ TabBar::TabBar(QWidget *parent) } } + void TabBar::selectTabAction() { if (QShortcut *shortCut = qobject_cast(sender())) @@ -63,6 +64,7 @@ void TabBar::selectTabAction() } } + void TabBar::contextMenuRequested(const QPoint &position) { QMenu menu; @@ -94,14 +96,17 @@ void TabBar::contextMenuRequested(const QPoint &position) menu.exec(QCursor::pos()); } + void TabBar::cloneTab() { - if (QAction *action = qobject_cast(sender())) { + if (QAction *action = qobject_cast(sender())) + { int index = action->data().toInt(); emit cloneTab(index); } } + void TabBar::closeTab() { if (QAction *action = qobject_cast(sender())) @@ -111,6 +116,7 @@ void TabBar::closeTab() } } + void TabBar::closeOtherTabs() { if (QAction *action = qobject_cast(sender())) @@ -120,6 +126,7 @@ void TabBar::closeOtherTabs() } } + void TabBar::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) @@ -127,6 +134,7 @@ void TabBar::mousePressEvent(QMouseEvent *event) QTabBar::mousePressEvent(event); } + void TabBar::mouseMoveEvent(QMouseEvent *event) { if (event->buttons() == Qt::LeftButton && (event->pos() - m_dragStartPos).manhattanLength() > QApplication::startDragDistance()) @@ -146,6 +154,7 @@ void TabBar::mouseMoveEvent(QMouseEvent *event) QTabBar::mouseMoveEvent(event); } + void TabBar::dragEnterEvent(QDragEnterEvent *event) { const QMimeData *mimeData = event->mimeData(); @@ -158,6 +167,7 @@ void TabBar::dragEnterEvent(QDragEnterEvent *event) QTabBar::dragEnterEvent(event); } + void TabBar::dropEvent(QDropEvent *event) { int fromIndex = tabAt(m_dragStartPos); @@ -319,7 +329,7 @@ void TabWidget::currentChanged(int index) if (!webView) return; - Q_ASSERT(m_lineEdits->count() == count()); + Q_ASSERT( m_lineEdits->count() == count() ); WebView *oldWebView = this->webView(m_lineEdits->currentIndex()); if (oldWebView) @@ -493,7 +503,7 @@ WebView *TabWidget::newTab(bool makeCurrent) connect(webView->page(), SIGNAL(menuBarVisibilityChangeRequested(bool)), this, SIGNAL(menuBarVisibilityChangeRequested(bool))); connect(webView->page(), SIGNAL(statusBarVisibilityChangeRequested(bool)), this, SIGNAL(statusBarVisibilityChangeRequested(bool))); connect(webView->page(), SIGNAL(toolBarVisibilityChangeRequested(bool)), this, SIGNAL(toolBarVisibilityChangeRequested(bool))); - addTab(webView, i18n("(Untitled)")); + addTab(webView, i18n("(Untitled)") ); if (makeCurrent) setCurrentWidget(webView); @@ -569,7 +579,7 @@ void TabWidget::cloneTab(int index) if (index < 0 || index >= count()) return; WebView *tab = newTab(false); - tab->setUrl(webView(index)->url()); + tab->setUrl( webView(index)->url() ); } @@ -673,7 +683,7 @@ void TabWidget::aboutToShowRecentTabsMenu() action->setData(m_recentlyClosedTabs.at(i)); QIcon icon = BrowserApplication::instance()->icon(m_recentlyClosedTabs.at(i)); action->setIcon(icon); - action->setText(m_recentlyClosedTabs.at(i).toString()); + action->setText( m_recentlyClosedTabs.at(i).prettyUrl() ); m_recentlyClosedTabsMenu->addAction(action); } } @@ -681,7 +691,7 @@ void TabWidget::aboutToShowRecentTabsMenu() void TabWidget::aboutToShowRecentTriggeredAction(QAction *action) { - QUrl url = action->data().toUrl(); + KUrl url = action->data().toUrl(); loadUrlInCurrentTab(url); } @@ -715,7 +725,7 @@ void TabWidget::mouseReleaseEvent(QMouseEvent *event) // Remove the line below when QTabWidget does not have a one pixel frame && event->pos().y() < (tabBar()->y() + tabBar()->height())) { - QUrl url(QApplication::clipboard()->text(QClipboard::Selection)); + KUrl url( QApplication::clipboard()->text(QClipboard::Selection) ); if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) { WebView *webView = newTab(); @@ -725,7 +735,7 @@ void TabWidget::mouseReleaseEvent(QMouseEvent *event) } -void TabWidget::loadUrlInCurrentTab(const QUrl &url) +void TabWidget::loadUrlInCurrentTab(const KUrl &url) { WebView *webView = currentWebView(); if (webView) @@ -771,7 +781,7 @@ QByteArray TabWidget::saveState() const { if (WebView *tab = qobject_cast(widget(i))) { - tabs.append(tab->url().toString()); + tabs.append(tab->url().prettyUrl()); } else { diff --git a/src/tabwidget.h b/src/tabwidget.h index 8e6d16b4..5a48072f 100644 --- a/src/tabwidget.h +++ b/src/tabwidget.h @@ -108,12 +108,14 @@ private: // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -#include -#include - +// KDE Includes +#include #include #include +// Qt Includes +#include + QT_BEGIN_NAMESPACE class QCompleter; class QMenu; @@ -173,7 +175,7 @@ protected: void mouseReleaseEvent(QMouseEvent *event); public slots: - void loadUrlInCurrentTab(const QUrl &url); + void loadUrlInCurrentTab(const KUrl &url); WebView *newTab(bool makeCurrent = true); void cloneTab(int index = -1); void closeTab(int index = -1); @@ -204,7 +206,7 @@ private: KMenu *m_recentlyClosedTabsMenu; static const int m_recentlyClosedTabsSize = 10; - QList m_recentlyClosedTabs; + QList m_recentlyClosedTabs; QList m_actions; QCompleter *m_lineEditCompleter; diff --git a/src/urlbar.cpp b/src/urlbar.cpp index cde55cb3..1ee02dc3 100644 --- a/src/urlbar.cpp +++ b/src/urlbar.cpp @@ -54,7 +54,7 @@ UrlBar::UrlBar(QWidget *parent) UrlBar::~UrlBar() { -// delete m_webView; + delete m_webView; delete m_iconLabel; delete m_lineEdit; } @@ -87,7 +87,7 @@ void UrlBar::webViewUrlChanged(const QUrl &url) void UrlBar::webViewIconChanged() { - QUrl url = (m_webView) ? m_webView->url() : QUrl(); + KUrl url = (m_webView) ? m_webView->url() : KUrl(); QIcon icon = BrowserApplication::instance()->icon(url); QPixmap pixmap(icon.pixmap(16, 16)); m_iconLabel->setPixmap(pixmap); @@ -104,32 +104,3 @@ QLinearGradient UrlBar::generateGradient(const QColor &color) const gradient.setColorAt(1, m_defaultBaseColor); return gradient; } - -// FIXME -// void UrlBar::paintEvent(QPaintEvent *event) -// { -// QPalette p = palette(); -// if (m_webView && m_webView->url().scheme() == QLatin1String("https")) { -// QColor lightYellow(248, 248, 210); -// p.setBrush(QPalette::Base, generateGradient(lightYellow)); -// } else { -// p.setBrush(QPalette::Base, m_defaultBaseColor); -// } -// setPalette(p); -// -// QPainter painter(this); -// QStyleOptionFrameV2 panel; -// // initStyleOption(&panel); -// QRect backgroundRect = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); -// if (m_webView && !hasFocus()) -// { -// int progress = m_webView->progress(); -// QColor loadingColor = QColor(116, 192, 250); -// painter.setBrush(generateGradient(loadingColor)); -// painter.setPen(Qt::transparent); -// int mid = backgroundRect.width() / 100 * progress; -// QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height()); -// painter.drawRect(progressRect); -// } -// } - diff --git a/src/urlbar.h b/src/urlbar.h index 72b64654..5d766a92 100644 --- a/src/urlbar.h +++ b/src/urlbar.h @@ -43,10 +43,6 @@ public: KLineEdit *lineEdit(); void setWebView(WebView *webView); -// FIXME needed to color urlbar while loading urls -// protected: -// void paintEvent(QPaintEvent *event); - private slots: void webViewUrlChanged(const QUrl &url); void webViewIconChanged(); diff --git a/src/webview.cpp b/src/webview.cpp index 7cae61cf..2e97c486 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +//#include #include @@ -45,11 +45,11 @@ WebPage::WebPage(QObject *parent) , m_pressedButtons(Qt::NoButton) , m_openInNewTab(false) { - setNetworkAccessManager(BrowserApplication::networkAccessManager()); - connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), - this, SLOT(handleUnsupportedContent(QNetworkReply *))); + setNetworkAccessManager( BrowserApplication::networkAccessManager() ); + connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *))); } + BrowserMainWindow *WebPage::mainWindow() { QObject *w = this->parent(); @@ -61,24 +61,28 @@ BrowserMainWindow *WebPage::mainWindow() return BrowserApplication::instance()->mainWindow(); } + bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) { // ctrl open in new tab // ctrl-shift open in new tab and select // ctrl-alt open in new window - if (type == QWebPage::NavigationTypeLinkClicked - && (m_keyboardModifiers & Qt::ControlModifier - || m_pressedButtons == Qt::MidButton)) { + if ( type == QWebPage::NavigationTypeLinkClicked && (m_keyboardModifiers & Qt::ControlModifier + || m_pressedButtons == Qt::MidButton) ) + { bool newWindow = (m_keyboardModifiers & Qt::AltModifier); WebView *webView; - if (newWindow) { + if (newWindow) + { BrowserApplication::instance()->newMainWindow(); BrowserMainWindow *newMainWindow = BrowserApplication::instance()->mainWindow(); webView = newMainWindow->currentTab(); newMainWindow->raise(); newMainWindow->activateWindow(); webView->setFocus(); - } else { + } + else + { bool selectNewTab = (m_keyboardModifiers & Qt::ShiftModifier); webView = mainWindow()->tabWidget()->newTab(selectNewTab); } @@ -87,19 +91,22 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r m_pressedButtons = Qt::NoButton; return false; } - if (frame == mainFrame()) { + if ( frame == mainFrame() ) + { m_loadingUrl = request.url(); emit loadingUrl(m_loadingUrl); } return QWebPage::acceptNavigationRequest(frame, request, type); } + QWebPage *WebPage::createWindow(QWebPage::WebWindowType type) { Q_UNUSED(type); if (m_keyboardModifiers & Qt::ControlModifier || m_pressedButtons == Qt::MidButton) m_openInNewTab = true; - if (m_openInNewTab) { + if (m_openInNewTab) + { m_openInNewTab = false; return mainWindow()->tabWidget()->newTab()->page(); } @@ -108,20 +115,11 @@ QWebPage *WebPage::createWindow(QWebPage::WebWindowType type) return mainWindow->currentTab()->page(); } -// #if !defined(QT_NO_UITOOLS) -// QObject *WebPage::createPlugin(const QString &classId, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) -// { -// Q_UNUSED(url); -// Q_UNUSED(paramNames); -// Q_UNUSED(paramValues); -// QUiLoader loader; -// return loader.createWidget(classId, view()); -// } -// #endif // !defined(QT_NO_UITOOLS) void WebPage::handleUnsupportedContent(QNetworkReply *reply) { - if (reply->error() == QNetworkReply::NoError) { + if (reply->error() == QNetworkReply::NoError) + { BrowserApplication::downloadManager()->handleUnsupportedContent(reply); return; } @@ -140,16 +138,19 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) imageBuffer.open(QBuffer::ReadWrite); QIcon icon = view()->style()->standardIcon(QStyle::SP_MessageBoxWarning, 0, view()); QPixmap pixmap = icon.pixmap(QSize(32,32)); - if (pixmap.save(&imageBuffer, "PNG")) { + if (pixmap.save(&imageBuffer, "PNG")) + { html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"), QString(QLatin1String(imageBuffer.buffer().toBase64()))); } QList frames; frames.append(mainFrame()); - while (!frames.isEmpty()) { + while (!frames.isEmpty()) + { QWebFrame *frame = frames.takeFirst(); - if (frame->url() == reply->url()) { + if (frame->url() == reply->url()) + { frame->setHtml(html, reply->url()); return; } @@ -157,36 +158,37 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) foreach(QWebFrame *frame, children) frames.append(frame); } - if (m_loadingUrl == reply->url()) { + if (m_loadingUrl == reply->url()) + { mainFrame()->setHtml(html, reply->url()); } } +// ------------------------------------------------------------------------------------------------------------------------------------------------------ + + WebView::WebView(QWidget* parent) : QWebView(parent) , m_progress(0) , m_page(new WebPage(this)) { setPage(m_page); - connect(page(), SIGNAL(statusBarMessage(const QString&)), - SLOT(setStatusBarText(const QString&))); - connect(this, SIGNAL(loadProgress(int)), - this, SLOT(setProgress(int))); - connect(this, SIGNAL(loadFinished(bool)), - this, SLOT(loadFinished())); - connect(page(), SIGNAL(loadingUrl(const QUrl&)), - this, SIGNAL(urlChanged(const QUrl &))); - connect(page(), SIGNAL(downloadRequested(const QNetworkRequest &)), - this, SLOT(downloadRequested(const QNetworkRequest &))); + connect(page(), SIGNAL(statusBarMessage(const QString&)), this, SLOT(setStatusBarText(const QString&))); + connect(this, SIGNAL(loadProgress(int)), this, SLOT(setProgress(int))); + connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); + connect(page(), SIGNAL(loadingUrl(const QUrl&)), this, SIGNAL(urlChanged(const QUrl &))); + connect(page(), SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(downloadRequested(const QNetworkRequest &))); page()->setForwardUnsupportedContent(true); } + void WebView::contextMenuEvent(QContextMenuEvent *event) { QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); - if (!r.linkUrl().isEmpty()) { + if (!r.linkUrl().isEmpty()) + { QMenu menu(this); menu.addAction(pageAction(QWebPage::OpenLinkInNewWindow)); menu.addAction(i18n("Open in New Tab"), this, SLOT(openLinkInNewTab())); @@ -203,9 +205,11 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) QWebView::contextMenuEvent(event); } + void WebView::wheelEvent(QWheelEvent *event) { - if (QApplication::keyboardModifiers() & Qt::ControlModifier) { + if (QApplication::keyboardModifiers() & Qt::ControlModifier) + { int numDegrees = event->delta() / 8; int numSteps = numDegrees / 15; setTextSizeMultiplier(textSizeMultiplier() + numSteps * 0.1); @@ -215,46 +219,55 @@ void WebView::wheelEvent(QWheelEvent *event) QWebView::wheelEvent(event); } + void WebView::openLinkInNewTab() { m_page->m_openInNewTab = true; pageAction(QWebPage::OpenLinkInNewWindow)->trigger(); } + void WebView::setProgress(int progress) { m_progress = progress; } + void WebView::loadFinished() { - if (100 != m_progress) { + if (m_progress != 100) + { qWarning() << "Recieved finished signal while progress is still:" << progress() << "Url:" << url(); } m_progress = 0; } -void WebView::loadUrl(const QUrl &url) + +void WebView::loadUrl(const KUrl &url) { m_initialUrl = url; load(url); } + QString WebView::lastStatusBarText() const { return m_statusBarText; } -QUrl WebView::url() const + +KUrl WebView::url() const { - QUrl url = QWebView::url(); - if (!url.isEmpty()) + KUrl url = QWebView::url(); + if ( !url.isEmpty() ) + { return url; - + } return m_initialUrl; } + void WebView::mousePressEvent(QMouseEvent *event) { m_page->m_pressedButtons = event->buttons(); @@ -262,22 +275,27 @@ void WebView::mousePressEvent(QMouseEvent *event) QWebView::mousePressEvent(event); } + void WebView::mouseReleaseEvent(QMouseEvent *event) { QWebView::mouseReleaseEvent(event); - if (!event->isAccepted() && (m_page->m_pressedButtons & Qt::MidButton)) { - QUrl url(QApplication::clipboard()->text(QClipboard::Selection)); - if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) { + if (!event->isAccepted() && (m_page->m_pressedButtons & Qt::MidButton)) + { + KUrl url( QApplication::clipboard()->text(QClipboard::Selection) ); + if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) + { setUrl(url); } } } + void WebView::setStatusBarText(const QString &string) { m_statusBarText = string; } + void WebView::downloadRequested(const QNetworkRequest &request) { BrowserApplication::downloadManager()->download(request); diff --git a/src/webview.h b/src/webview.h index f81544a0..b2e97efb 100644 --- a/src/webview.h +++ b/src/webview.h @@ -21,6 +21,8 @@ #ifndef WEBVIEW_H #define WEBVIEW_H +#include + #include QT_BEGIN_NAMESPACE @@ -33,12 +35,13 @@ QT_END_NAMESPACE class BrowserMainWindow; + class WebPage : public QWebPage { Q_OBJECT signals: - void loadingUrl(const QUrl &url); + void loadingUrl(const QUrl &url); // WARNING has to be QUrl!! public: WebPage(QObject *parent = 0); @@ -58,9 +61,12 @@ private: Qt::KeyboardModifiers m_keyboardModifiers; Qt::MouseButtons m_pressedButtons; bool m_openInNewTab; - QUrl m_loadingUrl; + KUrl m_loadingUrl; }; + +// --------------------------------------------------------------------------------------------------------------------------------------- + class WebView : public QWebView { Q_OBJECT @@ -69,8 +75,8 @@ public: WebView(QWidget *parent = 0); WebPage *webPage() const { return m_page; } - void loadUrl(const QUrl &url); - QUrl url() const; + void loadUrl(const KUrl &url); + KUrl url() const; QString lastStatusBarText() const; inline int progress() const { return m_progress; } @@ -90,7 +96,7 @@ private slots: private: QString m_statusBarText; - QUrl m_initialUrl; + KUrl m_initialUrl; int m_progress; WebPage *m_page; }; -- cgit v1.2.1