diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2009-04-21 23:47:31 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2009-04-21 23:47:31 +0200 |
commit | 22e3699db8ce3395495eecd90c4f3ad4d235b090 (patch) | |
tree | ca7e8a23335aacf8cf049362a99c84dbec5798a0 | |
parent | Fixing (and updating) MainView code (diff) | |
download | rekonq-22e3699db8ce3395495eecd90c4f3ad4d235b090.tar.xz |
Merged quite all patches in Web{View,Page} class
...
Also updated rekonqui.rc
-rw-r--r-- | src/rekonqui.rc | 3 | ||||
-rw-r--r-- | src/webview.cpp | 183 | ||||
-rw-r--r-- | src/webview.h | 45 |
3 files changed, 151 insertions, 80 deletions
diff --git a/src/rekonqui.rc b/src/rekonqui.rc index 37890393..6de55eb5 100644 --- a/src/rekonqui.rc +++ b/src/rekonqui.rc @@ -51,7 +51,8 @@ </Menu> <!-- ============ BOOKMARKS menu =========== --> -<Action name="bookmarks" /> +<Action name="bookmarks" ><text>&Bookmarks</text> +</Action> <!-- ============ TOOLS menu =========== --> <Menu name="tools" noMerge="1"><text>&Tools</text> diff --git a/src/webview.cpp b/src/webview.cpp index 91a5b988..8d5c5b45 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -32,10 +32,14 @@ #include "mainview.h" #include "cookiejar.h" #include "networkaccessmanager.h" +#include "download.h" +#include "history.h" + // KDE Includes #include <KStandardDirs> #include <KUrl> +#include <KActionCollection> #include <KDebug> // Qt Includes @@ -61,19 +65,6 @@ WebPage::~WebPage() } -MainWindow *WebPage::mainWindow() -{ - QObject *w = this->parent(); - while (w) - { - if (MainWindow *mw = qobject_cast<MainWindow*>(w)) - return mw; - w = w->parent(); - } - return Application::instance()->mainWindow(); -} - - bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) { QString scheme = request.url().scheme(); @@ -153,8 +144,9 @@ QWebPage *WebPage::createWindow(QWebPage::WebWindowType type) // added to manage web modal dialogs if (type == QWebPage::WebModalDialog) { + // FIXME kWarning() << "trying QWebView here ---------------------------------------"; - QWebView *w = new QWebView; + QWebView *w = new QWebView(); return w->page(); } @@ -166,7 +158,7 @@ QWebPage *WebPage::createWindow(QWebPage::WebWindowType type) if (m_openInNewTab) { m_openInNewTab = false; - return mainWindow()->mainView()->newWebView()->page(); + return Application::instance()->mainWindow()->mainView()->newWebView()->page(); } MainWindow *mainWindow = Application::instance()->mainWindow(); @@ -198,11 +190,15 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) return; } - QString myfilestr = KStandardDirs::locate("data", "rekonq/htmls/notfound.html"); - QFile file(myfilestr); + // display "not found" page + QString notfoundFilePath = KStandardDirs::locate("data", "rekonq/htmls/notfound.html"); + QFile file(notfoundFilePath); bool isOpened = file.open(QIODevice::ReadOnly); - Q_ASSERT(isOpened); - + if (!isOpened) + { + kWarning() << "Couldn't open the notfound.html file"; + return; + } QString title = i18n("Error loading page: ") + reply->url().toString(); QString imagePath = KIconLoader::global()->iconPath("rekonq", KIconLoader::NoGroup, false); @@ -217,19 +213,21 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) frames.append(mainFrame()); while (!frames.isEmpty()) { - QWebFrame *frame = frames.takeFirst(); - if (frame->url() == reply->url()) + QWebFrame *firstFrame = frames.takeFirst(); + if (firstFrame->url() == reply->url()) { - frame->setHtml(html, reply->url()); + firstFrame->setHtml(html, reply->url()); return; } - QList<QWebFrame *> children = frame->childFrames(); + QList<QWebFrame *> children = firstFrame->childFrames(); foreach(QWebFrame *frame, children) frames.append(frame); } if (m_loadingUrl == reply->url()) { mainFrame()->setHtml(html, reply->url()); + // Don't put error pages to the history. + Application::historyManager()->removeHistoryEntry(reply->url(), mainFrame()->title()); } } @@ -239,8 +237,9 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) WebView::WebView(QWidget* parent) : QWebView(parent) - , m_progress(0) + , m_webActionCollection(new KActionCollection(this)) , m_page(new WebPage(this)) + , m_progress(0) { setPage(m_page); connect(page(), SIGNAL(statusBarMessage(const QString&)), this, SLOT(setStatusBarText(const QString&))); @@ -249,34 +248,116 @@ 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() +{ + + 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); } -// TODO : improve and KDE-ize this menu -// 1. Add link to bookmarks -// 2. Add "save link as" action void WebView::contextMenuEvent(QContextMenuEvent *event) { - QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); - if (!r.linkUrl().isEmpty()) + QWebHitTestResult result = page()->mainFrame()->hitTestContent(event->pos()); + MainWindow *mainwindow = Application::instance()->mainWindow(); + + QAction *addBookmarkAction = Application::bookmarkProvider()->actionByName("add_bookmark_payload"); + addBookmarkAction->setText(i18n("Bookmark This Page")); + addBookmarkAction->setData(QVariant()); + KMenu menu(this); + + bool linkIsEmpty = result.linkUrl().isEmpty(); + if (!linkIsEmpty) + { + menu.addAction( m_webActionCollection->action("open_link_in_new_tab") ); + } + else + { + menu.addAction(mainwindow->actionByName("new_tab")); + } + + menu.addAction(mainwindow->actionByName("view_redisplay")); + 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") ); + } + + if (result.isContentSelected()) + { + menu.addAction( m_webActionCollection->action("edit_copy") ); + } + + if (result.isContentEditable()) + { + menu.addAction( m_webActionCollection->action("edit_paste") ); + } + + if (!linkIsEmpty) { - KMenu menu(this); - KAction *a = new KAction(KIcon("tab-new"), i18n("Open in New Tab"), this); - connect(a, SIGNAL(triggered()), this , SLOT(openLinkInNewTab())); - menu.addAction(a); - menu.addSeparator(); - menu.addAction(pageAction(QWebPage::DownloadLinkToDisk)); - // Add link to bookmarks... menu.addSeparator(); - menu.addAction(pageAction(QWebPage::CopyLinkToClipboard)); - if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) + if (!result.pixmap().isNull()) { - menu.addAction(pageAction(QWebPage::InspectElement)); + // TODO Add "View Image" + menu.addAction( m_webActionCollection->action("save_image_as") ); + menu.addAction( m_webActionCollection->action("copy_this_image") ); } - menu.exec(mapToGlobal(event->pos())); - return; + menu.addAction( m_webActionCollection->action("save_link_as") ); + menu.addAction( m_webActionCollection->action("copy_link_location") ); + addBookmarkAction->setData(result.linkUrl()); + addBookmarkAction->setText(i18n("&Bookmark This Link")); } - QWebView::contextMenuEvent(event); + menu.addSeparator(); + + menu.addAction(addBookmarkAction); + menu.exec(mapToGlobal(event->pos())); } @@ -301,12 +382,6 @@ void WebView::openLinkInNewTab() } -void WebView::setProgress(int progress) -{ - m_progress = progress; -} - - void WebView::loadFinished() { if (m_progress != 100) @@ -337,12 +412,6 @@ void WebView::loadUrl(const KUrl &url) } -QString WebView::lastStatusBarText() const -{ - return m_statusBarText; -} - - KUrl WebView::url() const { KUrl url = QWebView::url(); @@ -376,12 +445,6 @@ void WebView::mouseReleaseEvent(QMouseEvent *event) } -void WebView::setStatusBarText(const QString &string) -{ - m_statusBarText = string; -} - - void WebView::downloadRequested(const QNetworkRequest &request) { KUrl srcUrl = request.url(); diff --git a/src/webview.h b/src/webview.h index de2822b9..4e51d5e0 100644 --- a/src/webview.h +++ b/src/webview.h @@ -30,6 +30,9 @@ // Forward Declarations class MainWindow; +class Application; + +class KActionCollection; class QWebFrame; class QAuthenticator; @@ -50,12 +53,16 @@ public: WebPage(QObject *parent = 0); ~WebPage(); - MainWindow *mainWindow(); - protected: - bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type); + bool acceptNavigationRequest(QWebFrame *frame, + const QNetworkRequest &request, + NavigationType type); + QWebPage *createWindow(QWebPage::WebWindowType type); - QObject *createPlugin(const QString &classId, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); + QObject *createPlugin(const QString &classId, + const QUrl &url, + const QStringList ¶mNames, + const QStringList ¶mValues); private slots: void handleUnsupportedContent(QNetworkReply *reply); @@ -71,7 +78,7 @@ private: }; -// --------------------------------------------------------------------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------------------- // Qt Includes #include <QWebView> @@ -83,19 +90,15 @@ class WebView : public QWebView public: WebView(QWidget *parent = 0); - WebPage *webPage() const - { - return m_page; - } - + WebPage *webPage() const { return m_page; } + + KActionCollection* actionCollection() const { return m_webActionCollection; } + void loadUrl(const KUrl &url); KUrl url() const; - QString lastStatusBarText() const; - inline int progress() const - { - return m_progress; - } + QString lastStatusBarText() const { return m_statusBarText; } + int progress() const { return m_progress; } signals: // switching tabs @@ -115,17 +118,21 @@ protected: void keyPressEvent(QKeyEvent *event); private slots: - void setProgress(int progress); + void setProgress(int progress) { m_progress = progress; } void loadFinished(); - void setStatusBarText(const QString &string); + void setStatusBarText(const QString &string) { m_statusBarText = string; } void downloadRequested(const QNetworkRequest &request); void openLinkInNewTab(); private: + KActionCollection *m_webActionCollection; + void fillWebActions(); + + WebPage *m_page; + + int m_progress; QString m_statusBarText; KUrl m_initialUrl; - int m_progress; - WebPage *m_page; }; #endif |