From 2399843ceb70b45b2c1a47b680e11ba1e623ef45 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 25 Apr 2009 23:55:14 +0200 Subject: Another importing step. Need to fix cookies' classes and then (I think) we are near the goal.. --- src/CMakeLists.txt | 2 + src/lineedit.cpp | 84 +++++++++++++ src/lineedit.h | 48 ++++++++ src/mainview.cpp | 318 +++++++++++++++++++++++++------------------------- src/mainview.h | 74 +++++++----- src/mainwindow.cpp | 66 +++++++---- src/mainwindow.h | 1 - src/stackedurlbar.cpp | 151 ++++++++++++++++++++++++ src/stackedurlbar.h | 64 ++++++++++ src/urlbar.cpp | 243 ++++++++++++++++++++++++++------------ src/urlbar.h | 61 +++++++--- src/webview.cpp | 178 ++++++++++++++++++---------- src/webview.h | 5 +- 13 files changed, 922 insertions(+), 373 deletions(-) create mode 100644 src/lineedit.cpp create mode 100644 src/lineedit.h create mode 100644 src/stackedurlbar.cpp create mode 100644 src/stackedurlbar.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 486a3992..3e22ac5d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,6 +20,8 @@ SET( rekonq_SRCS main.cpp sidepanel.cpp panelhistory.cpp + lineedit.cpp + stackedurlbar.cpp ) KDE4_ADD_UI_FILES( rekonq_SRCS diff --git a/src/lineedit.cpp b/src/lineedit.cpp new file mode 100644 index 00000000..aa6a2755 --- /dev/null +++ b/src/lineedit.cpp @@ -0,0 +1,84 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Paweł Prażak +* +* +* This program is free software; you can redistribute it +* and/or modify it under the terms of the GNU General +* Public License as published by the Free Software Foundation; +* either version 2, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* ============================================================ */ + +// Self Includes +#include "lineedit.h" + +// Qt Includes +#include +#include +#include + +// KDE Includes +#include + +// Local Includes + +LineEdit::LineEdit(QWidget* parent) + : KLineEdit(parent) +{ + setMinimumWidth(180); + setFocusPolicy(Qt::WheelFocus); + + setHandleSignals(true); +} + + +LineEdit::~LineEdit() +{ +} + + +void LineEdit::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Escape) + { + clearFocus(); + event->accept(); + } + + KLineEdit::keyPressEvent(event); +} + + +void LineEdit::contextMenuEvent(QContextMenuEvent *event) +{ + KLineEdit::contextMenuEvent(event); +} + + +void LineEdit::focusInEvent(QFocusEvent *event) +{ + selectAll(); + + KLineEdit::focusInEvent(event); +} + + +void LineEdit::focusOutEvent(QFocusEvent *event) +{ + KLineEdit::focusOutEvent(event); + + // reset cursor state and deselect + setCursorPosition(0); + deselect(); +} + + + diff --git a/src/lineedit.h b/src/lineedit.h new file mode 100644 index 00000000..202f1aba --- /dev/null +++ b/src/lineedit.h @@ -0,0 +1,48 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Paweł Prażak +* +* +* This program is free software; you can redistribute it +* and/or modify it under the terms of the GNU General +* Public License as published by the Free Software Foundation; +* either version 2, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* ============================================================ */ + + +#ifndef LINEEDIT_H +#define LINEEDIT_H + +// Qt Includes + +// KDE Includes +#include + +// Local Includes + +class QContextMenuEvent; +class QFocusEvent; +class QKeyEvent; + +class LineEdit : public KLineEdit +{ +public: + explicit LineEdit(QWidget *parent = 0); + virtual ~LineEdit(); + +protected: + virtual void keyPressEvent (QKeyEvent*); + virtual void contextMenuEvent (QContextMenuEvent*); + virtual void focusInEvent (QFocusEvent*); + virtual void focusOutEvent (QFocusEvent*); +}; + +#endif // LINEEDIT_H diff --git a/src/mainview.cpp b/src/mainview.cpp index a4966e7b..95d3565a 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -32,6 +32,7 @@ #include "application.h" #include "mainwindow.h" #include "history.h" +#include "stackedurlbar.h" #include "urlbar.h" #include "webview.h" @@ -56,9 +57,8 @@ MainView::MainView(QWidget *parent) : KTabWidget(parent) , m_recentlyClosedTabsAction(0) - , m_recentlyClosedTabsMenu(0) - , m_lineEditCompleter(0) - , m_lineEdits(new QStackedWidget(this)) + , m_recentlyClosedTabsMenu(new KMenu(this)) + , m_urlBars(new StackedUrlBar(this)) , m_tabBar(new TabBar(this)) { setTabBar(m_tabBar); @@ -74,17 +74,24 @@ MainView::MainView(QWidget *parent) connect(m_tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(moveTab(int,int))); // Recently Closed Tab Action - m_recentlyClosedTabsMenu = new KMenu(this); connect(m_recentlyClosedTabsMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowRecentTabsMenu())); connect(m_recentlyClosedTabsMenu, SIGNAL(triggered(QAction *)), this, SLOT(aboutToShowRecentTriggeredAction(QAction *))); m_recentlyClosedTabsAction = new KAction(i18n("Recently Closed Tabs"), this); m_recentlyClosedTabsAction->setMenu(m_recentlyClosedTabsMenu); m_recentlyClosedTabsAction->setEnabled(false); - // add close button to tab bar.. - m_tabBar->setTabsClosable(true); + #if KDE_IS_VERSION(4,2,60) + setTabsClosable(true); // this causes #23 on KDE 4.2 + #else + setCloseButtonEnabled(oneCloseButton); // this is deprecated, remove + #endif + connect(m_tabBar, SIGNAL(tabCloseRequested(int)),this, SLOT(slotCloseTab(int))); + // -- + connect(this, SIGNAL(loadUrlPage(const KUrl &)), + this, SLOT(loadUrlInCurrentTab(const KUrl &))); + // -- connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int))); } @@ -92,16 +99,12 @@ MainView::MainView(QWidget *parent) MainView::~MainView() { - delete m_lineEditCompleter; - delete m_recentlyClosedTabsMenu; } void MainView::showTabBar() { - bool astb = ReKonfig::alwaysShowTabBar(); - - if (astb == true) + if ( ReKonfig::alwaysShowTabBar() ) { if (m_tabBar->isHidden()) { @@ -124,12 +127,6 @@ void MainView::showTabBar() } -KAction *MainView::recentlyClosedTabsAction() const -{ - return m_recentlyClosedTabsAction; -} - - void MainView::slotWebReload() { WebView *webView = currentWebView(); @@ -216,10 +213,11 @@ void MainView::clear() // clear the recently closed tabs m_recentlyClosedTabs.clear(); // clear the line edit history - for (int i = 0; i < m_lineEdits->count(); ++i) + for (int i = 0; i < m_urlBars->count(); ++i) { - QLineEdit *qLineEdit = lineEdit(i); - qLineEdit->setText(qLineEdit->text()); + /// TODO What exacly do we need to clear here? + urlBar(i)->clearHistory(); + urlBar(i)->clear(); } } @@ -244,15 +242,17 @@ void MainView::slotCurrentChanged(int index) if (!webView) return; - Q_ASSERT(m_lineEdits->count() == count()); + Q_ASSERT(m_urlBars->count() == count()); - WebView *oldWebView = this->webView(m_lineEdits->currentIndex()); + WebView *oldWebView = this->webView(m_urlBars->currentIndex()); if (oldWebView) { - disconnect(oldWebView, SIGNAL(statusBarMessage(const QString&)), this, SIGNAL(showStatusBarMessage(const QString&))); + disconnect(oldWebView, SIGNAL(statusBarMessage(const QString&)), + this, SIGNAL(showStatusBarMessage(const QString&))); disconnect(oldWebView->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)), this, SIGNAL(linkHovered(const QString&))); - disconnect(oldWebView, SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int))); + disconnect(oldWebView, SIGNAL(loadProgress(int)), + this, SIGNAL(loadProgress(int))); } connect(webView, SIGNAL(statusBarMessage(const QString&)), this, SIGNAL(showStatusBarMessage(const QString&))); @@ -260,7 +260,7 @@ void MainView::slotCurrentChanged(int index) connect(webView, SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int))); emit setCurrentTitle(webView->title()); - m_lineEdits->setCurrentIndex(index); + m_urlBars->setCurrentIndex(index); emit loadProgress(webView->progress()); emit showStatusBarMessage(webView->lastStatusBarText()); @@ -269,30 +269,19 @@ void MainView::slotCurrentChanged(int index) } -QWidget *MainView::lineEditStack() const -{ - return m_lineEdits; -} - - -QLineEdit *MainView::currentLineEdit() const +UrlBar *MainView::urlBar(int index) const { - return lineEdit(m_lineEdits->currentIndex()); -} - - -WebView *MainView::currentWebView() const -{ - return webView(currentIndex()); -} - - -QLineEdit *MainView::lineEdit(int index) const -{ - UrlBar *urlLineEdit = qobject_cast(m_lineEdits->widget(index)); - if (urlLineEdit) - return urlLineEdit->lineEdit(); - return 0; + if (index == -1) + { + index = m_urlBars->currentIndex(); + } + UrlBar *urlBar = m_urlBars->urlBar(index); + if (urlBar) + { + return urlBar; + } + kWarning() << "URL bar with index" << index << "not found. Returning NULL. (line:" << __LINE__ << ")"; + return NULL; } @@ -303,99 +292,59 @@ WebView *MainView::webView(int index) const { return webView; } - else - { - // optimization to delay creating the first webview - if (count() == 1) - { - MainView *that = const_cast(this); - that->setUpdatesEnabled(false); - that->newWebView(); - that->slotCloseTab(0); - that->setUpdatesEnabled(true); - return currentWebView(); - } - } - return 0; -} - -int MainView::webViewIndex(WebView *webView) const -{ - int index = indexOf(webView); - return index; + kWarning() << "WebView with index " << index << "not found. Returning NULL." ; + return 0; } -WebView *MainView::newWebView() +WebView *MainView::newWebView(bool makeCurrent) { // line edit - UrlBar *urlLineEdit = new UrlBar; - QLineEdit *lineEdit = urlLineEdit->lineEdit(); - if (!m_lineEditCompleter && count() > 0) - { - HistoryCompletionModel *completionModel = new HistoryCompletionModel(this); - completionModel->setSourceModel(Application::historyManager()->historyFilterModel()); - m_lineEditCompleter = new QCompleter(completionModel, this); - // Should this be in Qt by default? - QAbstractItemView *popup = m_lineEditCompleter->popup(); - QListView *listView = qobject_cast(popup); - if (listView) - { - listView->setUniformItemSizes(true); - } - } - lineEdit->setCompleter(m_lineEditCompleter); - connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(lineEditReturnPressed())); - m_lineEdits->addWidget(urlLineEdit); - m_lineEdits->setSizePolicy(lineEdit->sizePolicy()); - - // optimization to delay creating the more expensive WebView, history, etc - if (count() == 0) - { - QWidget *emptyWidget = new QWidget; - QPalette p = emptyWidget->palette(); - p.setColor(QPalette::Window, palette().color(QPalette::Base)); - emptyWidget->setPalette(p); - emptyWidget->setAutoFillBackground(true); - disconnect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int))); - addTab(emptyWidget, i18n("(Untitled)")); - connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int))); - return 0; - } - - // webview - WebView *webView = new WebView; - urlLineEdit->setWebView(webView); - + UrlBar *urlBar = new UrlBar; // Ownership of widget is passed on to the QStackedWidget (addWidget method). + connect(urlBar, SIGNAL(activated(const KUrl&)), this, SLOT(loadUrlInCurrentTab(const KUrl&))); + m_urlBars->addUrlBar(urlBar); + + WebView *webView = new WebView; // should be deleted on tab close + + // connecting webview with urlbar + connect(webView, SIGNAL(loadProgress(int)), urlBar, SLOT(slotUpdateProgress(int))); + connect(webView, SIGNAL(loadFinished(bool)), urlBar, SLOT(slotLoadFinished(bool))); + connect(webView, SIGNAL(urlChanged(const QUrl &)), urlBar, SLOT(setUrl(const QUrl &))); + connect(webView, SIGNAL(iconChanged()), urlBar, SLOT(slotUpdateUrl())); + + // connecting webview with mainview connect(webView, SIGNAL(loadStarted()), this, SLOT(webViewLoadStarted())); - connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(webViewIconChanged())); + connect(webView, SIGNAL(loadProgress(int)), this, SLOT(webViewLoadProgress(int))); + connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(webViewLoadFinished(bool))); connect(webView, SIGNAL(iconChanged()), this, SLOT(webViewIconChanged())); connect(webView, SIGNAL(titleChanged(const QString &)), this, SLOT(webViewTitleChanged(const QString &))); connect(webView, SIGNAL(urlChanged(const QUrl &)), this, SLOT(webViewUrlChanged(const QUrl &))); - connect(webView->page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested())); - connect(webView->page(), SIGNAL(geometryChangeRequested(const QRect &)), this, SIGNAL(geometryChangeRequested(const QRect &))); - connect(webView->page(), SIGNAL(printRequested(QWebFrame *)), this, SIGNAL(printRequested(QWebFrame *))); - 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))); connect(webView, SIGNAL(ctrlTabPressed()), this, SLOT(nextTab())); connect(webView, SIGNAL(shiftCtrlTabPressed()), this, SLOT(previousTab())); + // connecting webPage signals with mainview + connect(webView->page(), SIGNAL(windowCloseRequested()), + this, SLOT(windowCloseRequested())); + connect(webView->page(), SIGNAL(geometryChangeRequested(const QRect &)), + this, SIGNAL(geometryChangeRequested(const QRect &))); + connect(webView->page(), SIGNAL(printRequested(QWebFrame *)), + this, SIGNAL(printRequested(QWebFrame *))); + 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)")); - setCurrentWidget(webView); - // focus on currentLineEdit just for empty pages - if(webView->url().isEmpty()) + if (makeCurrent) { - currentLineEdit()->setFocus(Qt::ActiveWindowFocusReason); + setCurrentWidget(webView); // this method does NOT take owneship of webView } - if (count() == 1) - { - slotCurrentChanged(currentIndex()); - } emit tabsChanged(); showTabBar(); @@ -417,19 +366,6 @@ void MainView::slotReloadAllTabs() } -void MainView::lineEditReturnPressed() -{ - if (QLineEdit *lineEdit = qobject_cast(sender())) - { - emit loadUrlPage(KUrl(lineEdit->text())); - if (m_lineEdits->currentWidget() == lineEdit) - { - currentWebView()->setFocus(); - } - } -} - - void MainView::windowCloseRequested() { WebPage *webPage = qobject_cast(sender()); @@ -500,10 +436,10 @@ void MainView::slotCloseTab(int index) if (tab->isModified()) { int risp = KMessageBox::questionYesNo(this , - i18n("You have modified this page and when closing it you would lose the modification.\n" - "Do you really want to close this page?\n"), - i18n("Do you really want to close this page?") - ); + i18n("You have modified this page and when closing it you would lose the modification.\n" + "Do you really want to close this page?\n"), + i18n("Do you really want to close this page?") + ); if (risp == KMessageBox::No) return; } @@ -511,18 +447,33 @@ void MainView::slotCloseTab(int index) m_recentlyClosedTabsAction->setEnabled(true); m_recentlyClosedTabs.prepend(tab->url()); + + // don't add empty urls + if (tab->url().isValid()) + { + m_recentlyClosedTabs.prepend(tab->url()); + } + if (m_recentlyClosedTabs.size() >= MainView::m_recentlyClosedTabsSize) + { m_recentlyClosedTabs.removeLast(); + } } - QWidget *lineEdit = m_lineEdits->widget(index); - m_lineEdits->removeWidget(lineEdit); - lineEdit->deleteLater(); + + QWidget *urlBar = m_urlBars->urlBar(index); + m_urlBars->removeWidget(urlBar); + urlBar->deleteLater(); // urlBar is scheduled for deletion. + QWidget *webView = widget(index); removeTab(index); - webView->deleteLater(); + webView->deleteLater(); // webView is scheduled for deletion. + emit tabsChanged(); + if (hasFocus && count() > 0) + { currentWebView()->setFocus(); + } showTabBar(); } @@ -532,14 +483,64 @@ void MainView::webViewLoadStarted() { WebView *webView = qobject_cast(sender()); int index = webViewIndex(webView); + kWarning() << "Here.. index = " << index; if (-1 != index) { - QLabel *label = animatedLoading(index); + QLabel *label = animatedLoading(index, true); if (label->movie()) { label->movie()->start(); } } + + if (index != currentIndex()) + return; + + emit showStatusBarMessage(i18n("Loading...")); +} + + +void MainView::webViewLoadProgress(int progress) +{ + WebView *webView = qobject_cast(sender()); + int index = webViewIndex(webView); + if (index != currentIndex() || index < 0) + { + return; + } + + double totalBytes = static_cast(webView->webPage()->totalBytes() / 1024); + + QString message = i18n("Loading %1% (%2 %3)...", progress, totalBytes, QLatin1String("kB") ); + emit showStatusBarMessage(message); +} + + +void MainView::webViewLoadFinished(bool ok) +{ + WebView *webView = qobject_cast(sender()); + int index = webViewIndex(webView); + + if (-1 != index) + { + QLabel *label = animatedLoading(index, true); + QMovie *movie = label->movie(); + if(movie) + movie->stop(); + } + + webViewIconChanged(); + + // don't display messages for background tabs + if (index != currentIndex()) + { + return; + } + + if (ok) + emit showStatusBarMessage(i18n("Done")); + else + emit showStatusBarMessage(i18n("Failed to load")); } @@ -550,7 +551,7 @@ void MainView::webViewIconChanged() if (-1 != index) { QIcon icon = Application::instance()->icon(webView->url()); - QLabel *label = animatedLoading(index); + QLabel *label = animatedLoading(index, false); QMovie *movie = label->movie(); delete movie; label->setMovie(0); @@ -645,13 +646,13 @@ void MainView::previousTab() void MainView::moveTab(int fromIndex, int toIndex) { - QWidget *lineEdit = m_lineEdits->widget(fromIndex); - m_lineEdits->removeWidget(lineEdit); - m_lineEdits->insertWidget(toIndex, lineEdit); + QWidget *lineEdit = m_urlBars->widget(fromIndex); + m_urlBars->removeWidget(lineEdit); + m_urlBars->insertWidget(toIndex, lineEdit); } -QLabel *MainView::animatedLoading(int index) +QLabel *MainView::animatedLoading(int index, bool addMovie) { if (index == -1) return 0; @@ -660,15 +661,16 @@ QLabel *MainView::animatedLoading(int index) if (!label) { label = new QLabel(this); - if (!label->movie()) - { - QMovie *movie = new QMovie(m_loadingGitPath, QByteArray(), label); - movie->setSpeed(50); - label->setMovie(movie); - movie->start(); - } - m_tabBar->setTabButton(index, QTabBar::LeftSide, 0); - m_tabBar->setTabButton(index, QTabBar::LeftSide, label); } + if (addMovie && !label->movie()) + { + QMovie *movie = new QMovie(m_loadingGitPath, QByteArray(), label); + movie->setSpeed(50); + label->setMovie(movie); + movie->start(); + } + m_tabBar->setTabButton(index, QTabBar::LeftSide, 0); + m_tabBar->setTabButton(index, QTabBar::LeftSide, label); return label; } + diff --git a/src/mainview.h b/src/mainview.h index b3aa1f4b..bcefa165 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -24,23 +24,27 @@ #ifndef TABWIDGET_H #define TABWIDGET_H +// Local Includes +#include "webview.h" + // KDE Includes #include // Forward Declarations -class WebView; -class TabBar; +class QLineEdit; +class QUrl; +class QWebFrame; +class QLabel; -class KUrl; class KAction; +class KCompletion; class KMenu; +class KUrl; -class QWebFrame; -class QCompleter; -class QStackedWidget; -class QLineEdit; -class QUrl; -class QLabel; +class HistoryCompletionModel; +class StackedUrlBar; +class TabBar; +class UrlBar; /** @@ -62,12 +66,14 @@ signals: // tab widget signals void loadUrlPage(const KUrl &url); void tabsChanged(); + void lastTabClosed(); // current tab signals void setCurrentTitle(const QString &url); void showStatusBarMessage(const QString &message); void linkHovered(const QString &link); void loadProgress(int progress); + void geometryChangeRequested(const QRect &geometry); void menuBarVisibilityChangeRequested(bool visible); void statusBarVisibilityChangeRequested(bool visible); @@ -75,24 +81,27 @@ signals: void printRequested(QWebFrame *frame); public: - void clear(); - - KAction *recentlyClosedTabsAction() const; - - QWidget *lineEditStack() const; - QLineEdit *currentLineEdit() const; - WebView *currentWebView() const; +// void setupTabButtons(); + + UrlBar *urlBar(int index) const; + UrlBar *currentUrlBar() const { return urlBar(-1); } WebView *webView(int index) const; - QLineEdit *lineEdit(int index) const; - int webViewIndex(WebView *webView) const; - + QList tabs(); // ? + + // inlines + TabBar *tabBar() const { return m_tabBar; } + StackedUrlBar *urlBarStack() const { return m_urlBars; } + WebView *currentWebView() const { return webView(currentIndex()); } + int webViewIndex(WebView *webView) const { return indexOf(webView); } + KAction *recentlyClosedTabsAction() const { return m_recentlyClosedTabsAction; } + /** * show and hide TabBar if user doesn't choose * "Always Show TabBar" option * */ void showTabBar(); - + void clear(); public slots: /** @@ -101,8 +110,8 @@ public slots: * * @return a pointer to the new WebView */ - WebView *newWebView(); - void loadUrlInCurrentTab(const KUrl &url); + WebView *newWebView(bool makeCurrent = true); + void loadUrlInCurrentTab(const KUrl &url); // DEPRECATED void slotCloneTab(int index = -1); void slotCloseTab(int index = -1); void slotCloseOtherTabs(int index); @@ -126,43 +135,46 @@ private slots: void slotCurrentChanged(int index); void aboutToShowRecentTabsMenu(); void aboutToShowRecentTriggeredAction(QAction *action); // need QAction! + void webViewLoadStarted(); + void webViewLoadProgress(int progress); + void webViewLoadFinished(bool ok); void webViewIconChanged(); void webViewTitleChanged(const QString &title); void webViewUrlChanged(const QUrl &url); - void lineEditReturnPressed(); - void windowCloseRequested(); + void windowCloseRequested(); -private: /** * This functions move tab informations "from index to index" * * @param fromIndex the index from which we move * - * @param toIndex the index to wchich we move + * @param toIndex the index to which we move */ void moveTab(int fromIndex, int toIndex); +private: + /** * This function creates (if not exists) and returns a QLabel * with a loading QMovie. - * Inspired from Arora's code. + * Imported from Arora's code. * * @param index the tab index where inserting the animated label + * @param addMovie creates or not a loading movie * * @return animated label's pointer */ - QLabel *animatedLoading(int index); + QLabel *animatedLoading(int index, bool addMovie); + static const int m_recentlyClosedTabsSize = 10; KAction *m_recentlyClosedTabsAction; KMenu *m_recentlyClosedTabsMenu; - static const int m_recentlyClosedTabsSize = 10; QList m_recentlyClosedTabs; - QCompleter *m_lineEditCompleter; - QStackedWidget *m_lineEdits; + StackedUrlBar *m_urlBars; TabBar *m_tabBar; QString m_loadingGitPath; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 03a7b01a..80d18675 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -40,6 +40,8 @@ #include "download.h" #include "findbar.h" #include "sidepanel.h" +#include "urlbar.h" +#include "stackedurlbar.h" // KDE Includes #include @@ -169,7 +171,7 @@ void MainWindow::setupToolBars() // location bar a = new KAction(i18n("Location Bar"), this); a->setShortcut(KShortcut(Qt::Key_F6)); - a->setDefaultWidget(m_view->lineEditStack()); + a->setDefaultWidget(m_view->urlBarStack()); actionCollection()->addAction(QLatin1String("url_bar"), a); // search bar @@ -204,7 +206,8 @@ void MainWindow::setupActions() KStandardAction::showMenubar(this, SLOT(slotShowMenubar(bool)), actionCollection()); // WEB Actions (NO KStandardActions..) - KStandardAction::redisplay(m_view, SLOT(slotWebReload()), actionCollection()); + a = KStandardAction::redisplay(m_view, SLOT(slotWebReload()), actionCollection()); + a->setText( i18n("Reload") ); KStandardAction::back(m_view, SLOT(slotWebBack()), actionCollection()); KStandardAction::forward(m_view, SLOT(slotWebForward()), actionCollection()); KStandardAction::undo(m_view, SLOT(slotWebUndo()), actionCollection()); @@ -225,6 +228,7 @@ void MainWindow::setupActions() // ============== Custom Actions a = new KAction(KIcon("document-open-remote"), i18n("Open Location"), this); + a->setShortcut(Qt::CTRL+Qt::Key_L); actionCollection()->addAction(QLatin1String("open_location"), a); connect(a, SIGNAL(triggered(bool)) , this, SLOT(slotOpenLocation())); @@ -294,15 +298,6 @@ void MainWindow::setupActions() a->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() : KStandardShortcut::tabPrev()); actionCollection()->addAction(QLatin1String("show_prev_tab"), a); connect(a, SIGNAL(triggered(bool)), m_view, SLOT(previousTab())); - - // clear Location Bar action (Henry de Valance WISH) - a = new KAction(KIcon("edit-clear-locationbar-rtl"), i18n("Clear Location Bar"), this); - a->setShortcut(Qt::CTRL+Qt::Key_L); - actionCollection()->addAction(QLatin1String("clear_location"),a); - connect(a, SIGNAL(triggered(bool)), this, SLOT(slotClearLocationBar())); - a->setWhatsThis(i18n( "Clear Location bar

" - "Clears the contents of the location bar." )); - } @@ -454,15 +449,15 @@ void MainWindow::loadUrl(const KUrl &url) if (!currentTab() || url.isEmpty()) return; - m_view->currentLineEdit()->setText(url.prettyUrl()); + m_view->currentUrlBar()->setUrl(url.prettyUrl()); m_view->loadUrlInCurrentTab(url); } void MainWindow::slotOpenLocation() { - m_view->currentLineEdit()->selectAll(); - m_view->currentLineEdit()->setFocus(); + m_view->currentUrlBar()->selectAll(); + m_view->currentUrlBar()->setFocus(); } @@ -681,18 +676,47 @@ void MainWindow::slotViewTextSmaller() void MainWindow::slotViewFullScreen(bool makeFullScreen) { + // state flags + static bool menubarFlag; + static bool mainToolBarFlag; + static bool locationBarFlag; + static bool bookmarksToolBarFlag; + static bool statusBarFlag; + static bool sidePanelFlag; + if (makeFullScreen == true) { + // save current state + menubarFlag = menuBar()->isHidden(); + mainToolBarFlag = toolBar("mainToolBar")->isHidden(); + locationBarFlag = toolBar("locationToolBar")->isHidden(); + bookmarksToolBarFlag = toolBar("bookmarksToolBar")->isHidden(); + statusBarFlag = statusBar()->isHidden(); + sidePanelFlag = sidePanel()->isHidden(); + menuBar()->hide(); toolBar("mainToolBar")->hide(); toolBar("locationToolBar")->hide(); + toolBar("bookmarksToolBar")->hide(); + statusBar()->hide(); + sidePanel()->hide(); } else { - menuBar()->show(); - toolBar("mainToolBar")->show(); - toolBar("locationToolBar")->show(); + if (!menubarFlag) + menuBar()->show(); + if (!mainToolBarFlag) + toolBar("mainToolBar")->show(); + if (!locationBarFlag) + toolBar("locationToolBar")->show(); + if (!bookmarksToolBarFlag) + toolBar("bookmarksToolBar")->show(); + if (!statusBarFlag) + statusBar()->show(); + if (!sidePanelFlag) + sidePanel()->show(); } + KToggleFullScreenAction::setFullScreen(this, makeFullScreen); } @@ -890,14 +914,6 @@ bool MainWindow::queryClose() } -void MainWindow::slotClearLocationBar() -{ - QLineEdit *lineEdit = m_view->currentLineEdit(); - lineEdit->clear(); - lineEdit->setFocus(); -} - - QAction *MainWindow::actionByName(const QString name) { QAction *ret = actionCollection()->action(name); diff --git a/src/mainwindow.h b/src/mainwindow.h index c22da43f..a02fcee7 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -92,7 +92,6 @@ private slots: void slotOpenLocation(); void slotAboutToShowBackMenu(); void geometryChangeRequested(const QRect &geometry); - void slotClearLocationBar(); // history related void slotOpenActionUrl(QAction *action); diff --git a/src/stackedurlbar.cpp b/src/stackedurlbar.cpp new file mode 100644 index 00000000..41867b9c --- /dev/null +++ b/src/stackedurlbar.cpp @@ -0,0 +1,151 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Paweł Prażak +* +* +* This program is free software; you can redistribute it +* and/or modify it under the terms of the GNU General +* Public License as published by the Free Software Foundation; +* either version 2, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* ============================================================ */ + + +// Self Includes +#include "stackedurlbar.h" + +// KDE Includes +#include "kdebug.h" + +// Local Includes +#include "application.h" +#include "history.h" +#include "urlbar.h" + + +StackedUrlBar::StackedUrlBar(QWidget *parent) + : QStackedWidget(parent) + , m_completion(0) + , m_completionModel(0) +{ +} + + +StackedUrlBar::~StackedUrlBar() +{ + delete m_completion; + delete m_completionModel; +} + + +UrlBar *StackedUrlBar::currentUrlBar() +{ + return urlBar(currentIndex()); +} + + +UrlBar *StackedUrlBar::urlBar(int index) +{ + UrlBar *urlBar = qobject_cast(QStackedWidget::widget(index)); + if (!urlBar) + { + kWarning() << "URL bar with index" << index << "not found. Returning NULL. line:" << __LINE__; + } + + return urlBar; +} + + +void StackedUrlBar::addUrlBar(UrlBar* urlBar) +{ + QStackedWidget::addWidget(urlBar); + + // setup completion objects + urlBar->setCompletionObject(completion()); +} + + +void StackedUrlBar::setCurrentUrlBar(UrlBar* urlBar) +{ + QStackedWidget::setCurrentWidget(urlBar); +} + + +void StackedUrlBar::removeUrlBar(UrlBar* urlBar) +{ + QStackedWidget::removeWidget(urlBar); +} + + +void StackedUrlBar::clear() +{ + currentUrlBar()->clearHistory(); + + for (int i = 0; i < count(); ++i) + { + urlBar(i)->clear(); + } +} + + +QList StackedUrlBar::urlBars() +{ + QList list; + for (int i = 0; i < count(); ++i) + { + const UrlBar* u = urlBar(i); + list.append(u); + } + return list; +} + + +KCompletion *StackedUrlBar::completion() +{ + // make sure completion was created + if (!m_completion) + { + m_completion = new KCompletion(); + m_completion->setCompletionMode(KGlobalSettings::CompletionPopupAuto); + m_completion->setOrder(KCompletion::Weighted); + m_completion->setIgnoreCase(true); + + kDebug() << "Initialize completion list..."; + + HistoryCompletionModel *model = completionModel(); + int count = model->rowCount(); + + kDebug() << "...initialize history items" << count; + + // change order to insertion to avoid confusion of the addItem method + // in weighted it expects format string:number and it thinks http it the whole string + m_completion->setOrder(KCompletion::Insertion); + for(int i = 0; i < count; ++i) + { + QString item = model->data(model->index(i,0)).toString(); + item.remove(QRegExp("^http://|/$")); + m_completion->addItem(item); + } + m_completion->setOrder(KCompletion::Weighted); + } + + return m_completion; +} + + +HistoryCompletionModel *StackedUrlBar::completionModel() +{ + if (!m_completionModel) + { + m_completionModel = new HistoryCompletionModel(this); + m_completionModel->setSourceModel(Application::historyManager()->historyFilterModel()); + } + return m_completionModel; +} diff --git a/src/stackedurlbar.h b/src/stackedurlbar.h new file mode 100644 index 00000000..35b97656 --- /dev/null +++ b/src/stackedurlbar.h @@ -0,0 +1,64 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2008 by Andrea Diamantini +* Copyright (C) 2009 by Paweł Prażak +* +* +* This program is free software; you can redistribute it +* and/or modify it under the terms of the GNU General +* Public License as published by the Free Software Foundation; +* either version 2, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* ============================================================ */ + + + +#ifndef STACKEDURLBAR_H +#define STACKEDURLBAR_H + +// Qt Includes +#include + +class KCompletion; +class HistoryCompletionModel; +class UrlBar; + +class StackedUrlBar : public QStackedWidget +{ + Q_OBJECT + +public: + StackedUrlBar(QWidget *parent = 0); + ~StackedUrlBar(); + +public: + UrlBar *currentUrlBar(); + UrlBar *urlBar(int index); + void addUrlBar(UrlBar *urlBar); + void setCurrentUrlBar(UrlBar *urlBar); + void removeUrlBar(UrlBar *urlBar); + + QList urlBars(); + + KCompletion *completion(); + HistoryCompletionModel *completionModel(); + +public slots: + void clear(); + +private: + Q_DISABLE_COPY(StackedUrlBar) + + KCompletion *m_completion; + HistoryCompletionModel *m_completionModel; +}; + +#endif // STACKEDURLBAR_H + diff --git a/src/urlbar.cpp b/src/urlbar.cpp index d6b1beca..1987ff8c 100644 --- a/src/urlbar.cpp +++ b/src/urlbar.cpp @@ -3,7 +3,8 @@ * This file is a part of the rekonq project * * Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 rekonq team. Please, see AUTHORS file for details +* Copyright (C) 2009 by Domrachev Alexandr +* Copyright (C) 2009 by Paweł Prażak * * * This program is free software; you can redistribute it @@ -23,123 +24,215 @@ #include "urlbar.h" #include "urlbar.moc" +// Qt Includes +#include +#include + +// KDE Includes +#include +#include +#include + // Local Includes #include "application.h" +#include "history.h" +#include "lineedit.h" #include "mainwindow.h" #include "webview.h" -// Qt Includes -#include -#include +QColor UrlBar::s_defaultBaseColor; UrlBar::UrlBar(QWidget *parent) : KHistoryComboBox(true, parent) - , m_webView(0) - , m_lineEdit(new QLineEdit) + , m_lineEdit(new LineEdit) + , m_progress(0) { - setLineEdit(m_lineEdit); - - QSizePolicy policy = sizePolicy(); - setSizePolicy(QSizePolicy::Preferred, policy.verticalPolicy()); - - m_defaultBaseColor = palette().color(QPalette::Base); - + setUrlDropsEnabled(true); + setAutoDeleteCompletionObject(true); + setMinimumWidth(180); + + setTrapReturnKey(true); + + setupLineEdit(); + // add every item to history - connect(this, SIGNAL(activated(const QString&)), this, SLOT(addToHistory(const QString&))); - - webViewIconChanged(); + connect(this, SIGNAL(returnPressed(const QString&)), SLOT(slotActivated(const QString&))); + connect(completionBox(), SIGNAL(activated(const QString&)), SLOT(slotActivated(const QString&))); + + connect(this, SIGNAL(cleared()), SLOT(slotCleared())); + + // setup completion box + completionBox()->setTabHandling(true); // Konqueror bug #167135 + + // set dropdown list background + QPalette p = view()->palette(); + p.setColor(QPalette::Base, palette().color(QPalette::Base)); + view()->setPalette(p); + + // set empty item with default icon + slotUpdateUrl(); } - UrlBar::~UrlBar() { } +void UrlBar::setupLineEdit() +{ + // Make m_lineEdit background transparent + QPalette p = m_lineEdit->palette(); + p.setColor(QPalette::Base, Qt::transparent); + m_lineEdit->setPalette(p); + + if (!s_defaultBaseColor.isValid()) + { + s_defaultBaseColor = palette().color(QPalette::Base); + } + + setLineEdit(m_lineEdit); + + // Make the lineedit consume the Qt::Key_Enter event... + lineEdit()->setTrapReturnKey(true); + + lineEdit()->setHandleSignals(true); + + // clear the URL bar + lineEdit()->clear(); +} + -QLineEdit *UrlBar::lineEdit() +void UrlBar::setUrl(const QUrl& url) { - return m_lineEdit; + if (url.isEmpty()) + return; + + m_currentUrl = url; + slotUpdateUrl(); } +void UrlBar::slotUpdateUrl() +{ + if (count()) + { + changeUrl(0, Application::instance()->icon(m_currentUrl), m_currentUrl); + } + else + { + insertUrl(0, Application::instance()->icon(m_currentUrl), m_currentUrl); + } + + setCurrentIndex(0); + + // important security consideration: always display the beginning + // of the url rather than its end to prevent spoofing attempts. + // Must be AFTER setCurrentIndex + if (!hasFocus()) + { + lineEdit()->setCursorPosition(0); + } +} -void UrlBar::setWebView(WebView *webView) + +inline void UrlBar::slotActivated(const QString& url) { - Q_ASSERT(!m_webView); - m_webView = webView; - connect(webView, SIGNAL(urlChanged(const QUrl &)), this, SLOT(webViewUrlChanged(const QUrl &))); - connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(webViewIconChanged())); - connect(webView, SIGNAL(iconChanged()), this, SLOT(webViewIconChanged())); - connect(webView, SIGNAL(loadProgress(int)), this, SLOT(update())); + if (url.isEmpty()) + return; + + setUrl(url); + + Application::historyManager()->addHistoryEntry(url); + + emit activated(m_currentUrl); } +inline void UrlBar::slotCleared() +{ + // clear the history on user's request from context menu + clear(); + Application::historyManager()->clear(); +} + -void UrlBar::webViewUrlChanged(const QUrl &url) +inline void UrlBar::slotLoadFinished(bool) { - m_lineEdit->setText(url.toString()); - m_lineEdit->setCursorPosition(0); + // reset progress bar after small delay + m_progress = 0; + QTimer::singleShot(200, this, SLOT(repaint())); } +inline void UrlBar::slotUpdateProgress(int progress) +{ + m_progress = progress; + repaint(); +} + -void UrlBar::webViewIconChanged() +void UrlBar::paintEvent(QPaintEvent *event) { - KUrl url = (m_webView) ? m_webView->url() : KUrl(); - QIcon icon = Application::instance()->icon(url); - QPixmap pixmap(icon.pixmap(16, 16)); - QIcon urlIcon = QIcon(pixmap); - - // FIXME simple hack to show Icon in the urlbar, as calling changeUrl() doesn't affect it - insertUrl(0, urlIcon, url); - if (count() > 1) + QColor baseColor = s_defaultBaseColor; + if (m_currentUrl.scheme() == QLatin1String("https")) { - removeItem(1); + baseColor = QColor(248, 248, 100); + } + // set background color of UrlBar + QPalette p = palette(); + p.setColor(QPalette::Base, baseColor); + setPalette(p); + + KHistoryComboBox::paintEvent(event); + + if (!hasFocus()) + { + QPainter painter(this); + + QColor loadingColor = QColor(116, 192, 250); + + painter.setBrush(generateGradient(loadingColor, height())); + painter.setPen(Qt::transparent); + + QRect backgroundRect = lineEdit()->frameGeometry(); + int mid = backgroundRect.width() / 100 * m_progress; + QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height()); + painter.drawRect(progressRect); + painter.end(); } } -QLinearGradient UrlBar::generateGradient(const QColor &color) const +void UrlBar::focusOutEvent(QFocusEvent *event) { - QLinearGradient gradient(0, 0, 0, height()); - gradient.setColorAt(0, m_defaultBaseColor); - gradient.setColorAt(0.15, color.lighter(120)); - gradient.setColorAt(0.5, color); - gradient.setColorAt(0.85, color.lighter(120)); - gradient.setColorAt(1, m_defaultBaseColor); - return gradient; + // set back last loaded url in case user cleared it + setUrl(m_currentUrl); + + KHistoryComboBox::focusOutEvent(event); } -// 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); -// KHistoryComboBox::paintEvent(event); -// -// QPainter painter( this ); -// QRect backgroundRect = m_lineEdit->frameGeometry(); // contentsRect(); // FIXME perhaps better working with contentsRect -// if ( m_webView && !hasFocus() ) // and modifying colours.. -// { -// 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); -// } -// } +QSize UrlBar::sizeHint() const +{ + QSize size(lineEdit()->sizeHint()); + // make it (more or less) the same height with search bar (at least on oxygen) +// size.setHeight(size.height() + 2); + return size; +} +QLinearGradient UrlBar::generateGradient(const QColor &color, int height) +{ + QColor base = s_defaultBaseColor; + base.setAlpha(0); + QColor barColor = color; + barColor.setAlpha(200); + QLinearGradient gradient(0, 0, 0, height); + gradient.setColorAt(0, base); + gradient.setColorAt(0.25, barColor.lighter(120)); + gradient.setColorAt(0.5, barColor); + gradient.setColorAt(0.75, barColor.lighter(120)); + gradient.setColorAt(1, base); + return gradient; +} diff --git a/src/urlbar.h b/src/urlbar.h index 2b8f89a5..4cef5157 100644 --- a/src/urlbar.h +++ b/src/urlbar.h @@ -3,7 +3,8 @@ * This file is a part of the rekonq project * * Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 rekonq team. Please, see AUTHORS file for details +* Copyright (C) 2009 by Domrachev Alexandr +* Copyright (C) 2009 by Paweł Prażak * * * This program is free software; you can redistribute it @@ -22,18 +23,22 @@ #ifndef URLBAR_H #define URLBAR_H +// Qt Includes +#include +#include +#include // KDE Includes +#include #include -// Forward Declarations -class WebView; +// Local Includes +#include "lineedit.h" -class QWidget; -class QLineEdit; -class QUrl; + +// Forward Declarations class QLinearGradient; -class QColor; +class QWidget; class UrlBar : public KHistoryComboBox @@ -41,25 +46,45 @@ class UrlBar : public KHistoryComboBox Q_OBJECT public: - UrlBar(QWidget *parent = 0); + UrlBar(QWidget *parent=0); ~UrlBar(); - QLineEdit *lineEdit(); - void setWebView(WebView *webView); + void selectAll() const { lineEdit()->selectAll(); } + KUrl url() const { return m_currentUrl; } -private slots: - void webViewUrlChanged(const QUrl &url); - void webViewIconChanged(); + QSize sizeHint() const; + +signals: + void activated(const KUrl&); +public slots: + void setUrl(const QUrl &url); + void slotUpdateProgress(int progress); + +private slots: + void slotActivated(const QString&); + void slotLoadFinished(bool); + void slotCleared(); + void slotUpdateUrl(); + protected: -// void paintEvent( QPaintEvent * ); + virtual void paintEvent(QPaintEvent *event); + virtual void focusOutEvent(QFocusEvent *event); private: - QLinearGradient generateGradient(const QColor &color) const; + void setupLineEdit(); + + KLineEdit *lineEdit() const { return m_lineEdit; } + + static QLinearGradient generateGradient(const QColor &color, int height); + + static QColor s_defaultBaseColor; - WebView* m_webView; - QLineEdit* m_lineEdit; - QColor m_defaultBaseColor; + LineEdit *m_lineEdit; + + QIcon m_currentIcon; + KUrl m_currentUrl; + int m_progress; }; #endif diff --git a/src/webview.cpp b/src/webview.cpp index cfea6ca6..04ce9c9b 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -57,6 +57,8 @@ WebPage::WebPage(QObject *parent) , m_openInNewTab(false) { setNetworkAccessManager(Application::networkAccessManager()); + + setForwardUnsupportedContent(true); connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *))); } @@ -121,6 +123,22 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r // user activated the reload action. case QWebPage::NavigationTypeReload: + + #if QT_VERSION <= 040500 + // HACK Ported from Arora + // A short term hack until QtWebKit can get a reload without cache QAction + // *FYI* currently type is never NavigationTypeReload + // See: https://bugs.webkit.org/show_bug.cgi?id=24283 + if (qApp->keyboardModifiers() & Qt::ShiftModifier) + { + QNetworkRequest newRequest(request); + newRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, + QNetworkRequest::AlwaysNetwork); + mainFrame()->load(request); + return false; + } + #endif + break; // An HTML form was submitted a second time. @@ -182,12 +200,33 @@ QObject *WebPage::createPlugin(const QString &classId, const QUrl &url, const QS void WebPage::handleUnsupportedContent(QNetworkReply *reply) { + // create convenience fake api:// protocol for KDE apidox search and Qt docs + if (reply->url().scheme() == "api") + { + QString path; + QString className = reply->url().host().toLower(); + if (className[0] == 'k') + { + path = QString("http://api.kde.org/new.classmapper.php?class=%1").arg(className); + } + else if (className[0] == 'q') + { + path = QString("http://doc.trolltech.com/4.5/%1.html").arg(className); + } + QUrl url(path); + + Application::instance()->mainWindow()->loadUrl(url); + return; + } + if (reply->error() == QNetworkReply::NoError) { - KUrl srcUrl = reply->url(); - QString path = ReKonfig::downloadDir() + QString("/") + srcUrl.fileName(); - KUrl destUrl = KUrl(path); - Application::downloadManager()->newDownload(srcUrl); + // st iframe unwanted download fix + if (reply->header(QNetworkRequest::ContentTypeHeader).isValid()) + { + KUrl srcUrl = reply->url(); + Application::downloadManager()->newDownload(srcUrl); + } return; } @@ -222,7 +261,9 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) } QList children = firstFrame->childFrames(); foreach(QWebFrame *frame, children) - frames.append(frame); + { + frames.append(frame); + } } if (m_loadingUrl == reply->url()) { @@ -236,9 +277,11 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) // ----------------------------------------------------------------------------------------------------------------- +KActionCollection* WebView::s_webActionCollection; + + WebView::WebView(QWidget* parent) : QWebView(parent) - , m_webActionCollection(new KActionCollection(this)) , m_page(new WebPage(this)) , m_progress(0) { @@ -249,54 +292,63 @@ WebView::WebView(QWidget* parent) 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); - - fillWebActions(); } -void WebView::fillWebActions() +KActionCollection* WebView::webActions() { + if(!s_webActionCollection) + { + s_webActionCollection = new KActionCollection(this); + + QAction *a; + + a = new KAction(KIcon("tab-new"), i18n("Open Link in New &Tab"), this); + connect(a, SIGNAL(triggered()), this, SLOT(openLinkInNewTab()) ); + s_webActionCollection->addAction( QLatin1String("open_link_in_new_tab"), a); + + a = pageAction(QWebPage::Cut); + a->setIcon(KIcon("edit-cut")); + a->setText(i18n("Cu&t")); + s_webActionCollection->addAction( QLatin1String("edit_cut"), a); + + a = pageAction(QWebPage::Copy); + a->setIcon(KIcon("edit-copy")); + a->setText(i18n("&Copy")); + s_webActionCollection->addAction( QLatin1String("edit_copy"), a ); + + a = pageAction(QWebPage::Paste); + a->setIcon(KIcon("edit-paste")); + a->setText(i18n("&Paste")); + s_webActionCollection->addAction( QLatin1String("edit_paste"), a ); + + a = pageAction(QWebPage::DownloadImageToDisk); + a->setIcon(KIcon("folder-image")); + a->setText(i18n("&Save Image As...")); + s_webActionCollection->addAction( QLatin1String("save_image_as"), a ); + + a = pageAction(QWebPage::CopyImageToClipboard); + a->setIcon(KIcon("insert-image")); + a->setText(i18n("&Copy This Image")); + s_webActionCollection->addAction( QLatin1String("copy_this_image"), a); + + a = pageAction(QWebPage::DownloadLinkToDisk); + a->setIcon(KIcon("folder-downloads")); + a->setText(i18n("&Save Link As...")); + s_webActionCollection->addAction( QLatin1String("save_link_as"), a); + + a = pageAction(QWebPage::CopyLinkToClipboard); + a->setIcon(KIcon("insert-link")); + a->setText(i18n("&Copy Link Location")); + s_webActionCollection->addAction( QLatin1String("copy_link_location"), a); + + a = pageAction(QWebPage::InspectElement); + a->setIcon(KIcon("tools-report-bug")); + a->setText(i18n("&Inspect Element")); + s_webActionCollection->addAction( QLatin1String("inspect_element"), a); + } - QAction *a; - - a = new KAction(KIcon("tab-new"), i18n("Open Link in New &Tab"), this); - connect(a, SIGNAL(triggered()), this, SLOT(openLinkInNewTab()) ); - m_webActionCollection->addAction( QLatin1String("open_link_in_new_tab"), a); - - a = pageAction(QWebPage::Cut); - a->setIcon(KIcon("edit-cut")); - a->setText(i18n("Cu&t")); - m_webActionCollection->addAction( QLatin1String("edit_cut"), a); - - a = pageAction(QWebPage::Copy); - a->setIcon(KIcon("edit-copy")); - a->setText(i18n("&Copy")); - m_webActionCollection->addAction( QLatin1String("edit_copy"), a ); - - a = pageAction(QWebPage::Paste); - a->setIcon(KIcon("edit-paste")); - a->setText(i18n("&Paste")); - m_webActionCollection->addAction( QLatin1String("edit_paste"), a ); - - a = pageAction(QWebPage::DownloadImageToDisk); - a->setIcon(KIcon("folder-image")); - a->setText(i18n("&Save Image As...")); - m_webActionCollection->addAction( QLatin1String("save_image_as"), a ); - - a = pageAction(QWebPage::CopyImageToClipboard); - a->setIcon(KIcon("insert-image")); - a->setText(i18n("&Copy This Image")); - m_webActionCollection->addAction( QLatin1String("copy_this_image"), a); - - a = pageAction(QWebPage::DownloadLinkToDisk); - a->setIcon(KIcon("folder-downloads")); - a->setText(i18n("&Save Link As...")); - m_webActionCollection->addAction( QLatin1String("save_link_as"), a); - - a = pageAction(QWebPage::CopyLinkToClipboard); - a->setIcon(KIcon("insert-link")); - a->setText(i18n("&Copy Link Location")); - m_webActionCollection->addAction( QLatin1String("copy_link_location"), a); + return s_webActionCollection; } @@ -313,32 +365,38 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) bool linkIsEmpty = result.linkUrl().isEmpty(); if (!linkIsEmpty) { - menu.addAction( m_webActionCollection->action("open_link_in_new_tab") ); + menu.addAction( webActions()->action("open_link_in_new_tab") ); } else { menu.addAction(mainwindow->actionByName("new_tab")); } - menu.addAction(mainwindow->actionByName("view_redisplay")); menu.addSeparator(); + + if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) + { + menu.addAction( webActions()->action("inspect_element") ); + menu.addSeparator(); + } + menu.addAction(mainwindow->actionByName("history_back")); menu.addAction(mainwindow->actionByName("history_forward")); menu.addSeparator(); if (result.isContentSelected() && result.isContentEditable()) { - menu.addAction( m_webActionCollection->action("edit_cut") ); + menu.addAction( webActions()->action("edit_cut") ); } if (result.isContentSelected()) { - menu.addAction( m_webActionCollection->action("edit_copy") ); + menu.addAction( webActions()->action("edit_copy") ); } if (result.isContentEditable()) { - menu.addAction( m_webActionCollection->action("edit_paste") ); + menu.addAction( webActions()->action("edit_paste") ); } if (!linkIsEmpty) @@ -347,11 +405,11 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) if (!result.pixmap().isNull()) { // TODO Add "View Image" - menu.addAction( m_webActionCollection->action("save_image_as") ); - menu.addAction( m_webActionCollection->action("copy_this_image") ); + menu.addAction( webActions()->action("save_image_as") ); + menu.addAction( webActions()->action("copy_this_image") ); } - menu.addAction( m_webActionCollection->action("save_link_as") ); - menu.addAction( m_webActionCollection->action("copy_link_location") ); + menu.addAction( webActions()->action("save_link_as") ); + menu.addAction( webActions()->action("copy_link_location") ); addBookmarkAction->setData(result.linkUrl()); addBookmarkAction->setText(i18n("&Bookmark This Link")); } @@ -394,19 +452,15 @@ void WebView::loadFinished() } -// FIXME: load http by default!! void WebView::loadUrl(const KUrl &url) { m_initialUrl = url; if (m_initialUrl.isRelative()) { - kWarning() << "1: " << m_initialUrl.url(); QString fn = m_initialUrl.url(KUrl::RemoveTrailingSlash); - kWarning() << "2: " << fn; m_initialUrl.setUrl("//" + fn); m_initialUrl.setScheme("http"); - kWarning() << "3: " << m_initialUrl.url(); } load(m_initialUrl); diff --git a/src/webview.h b/src/webview.h index ab4d0a68..64994f83 100644 --- a/src/webview.h +++ b/src/webview.h @@ -93,7 +93,7 @@ public: WebView(QWidget *parent = 0); WebPage *webPage() const { return m_page; } - KActionCollection* actionCollection() const { return m_webActionCollection; } + KActionCollection* webActions(); void loadUrl(const KUrl &url); KUrl url() const; @@ -126,8 +126,7 @@ private slots: void openLinkInNewTab(); private: - KActionCollection *m_webActionCollection; - void fillWebActions(); + static KActionCollection* s_webActionCollection; WebPage *m_page; -- cgit v1.2.1