diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2010-11-19 01:32:04 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2010-11-19 01:32:04 +0100 |
commit | fe21365ffafb922a6b24959f3d1096e4c6171427 (patch) | |
tree | 7380e1486a65ab57e39a663442876ff1912715d3 | |
parent | API clean up (diff) | |
download | rekonq-fe21365ffafb922a6b24959f3d1096e4c6171427.tar.xz |
Print && Find actions for the parts :)
- handle print & find with different signals in mainwindow
- show right tab title (moving titleChanged signal from view to tab)
-rw-r--r-- | src/findbar.cpp | 9 | ||||
-rw-r--r-- | src/mainview.cpp | 8 | ||||
-rw-r--r-- | src/mainwindow.cpp | 34 | ||||
-rw-r--r-- | src/mainwindow.h | 13 | ||||
-rw-r--r-- | src/webpage.cpp | 35 | ||||
-rw-r--r-- | src/webtab.cpp | 32 | ||||
-rw-r--r-- | src/webtab.h | 15 |
7 files changed, 111 insertions, 35 deletions
diff --git a/src/findbar.cpp b/src/findbar.cpp index 3f7825da..158849f9 100644 --- a/src/findbar.cpp +++ b/src/findbar.cpp @@ -31,6 +31,8 @@ // Local Includes #include "mainwindow.h" +#include "webtab.h" +#include "webpage.h" // KDE Includes #include <KApplication> @@ -154,6 +156,13 @@ bool FindBar::highlightAllState() const void FindBar::setVisible(bool visible) { + if (visible && m_mainWindow->currentTab()->page()->isOnRekonqPage() && m_mainWindow->currentTab()->part() != 0) + { + // findNext is the slot containing part integration code + m_mainWindow->findNext(); + return; + } + QWidget::setVisible(visible); if (visible) diff --git a/src/mainview.cpp b/src/mainview.cpp index 26248da5..903ec12b 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -314,7 +314,7 @@ WebTab *MainView::newWebTab(bool focused) // connecting webview with mainview connect(tab->view(), SIGNAL(loadStarted()), this, SLOT(webViewLoadStarted())); connect(tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(webViewLoadFinished(bool))); - connect(tab->view(), SIGNAL(titleChanged(const QString &)), this, SLOT(webViewTitleChanged(const QString &))); + connect(tab, SIGNAL(titleChanged(const QString &)), this, SLOT(webViewTitleChanged(const QString &))); connect(tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(webViewUrlChanged(const QUrl &))); connect(tab->view(), SIGNAL(iconChanged()), this, SLOT(webViewIconChanged())); @@ -584,8 +584,8 @@ void MainView::webViewTitleChanged(const QString &title) QString tabTitle = viewTitle; tabTitle.replace('&', "&&"); - WebView *view = qobject_cast<WebView *>(sender()); - int index = indexOf(view->parentWidget()); + WebTab *tab = qobject_cast<WebTab *>(sender()); + int index = indexOf(tab); if (-1 != index) { setTabText(index, tabTitle); @@ -594,7 +594,7 @@ void MainView::webViewTitleChanged(const QString &title) { emit currentTitle(viewTitle); } - Application::historyManager()->updateHistoryEntry(view->url(), tabTitle); + Application::historyManager()->updateHistoryEntry(tab->url(), tabTitle); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5f508506..f662d7aa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -72,6 +72,9 @@ #include <KStandardDirs> #include <KToggleFullScreenAction> +#include <KParts/Part> +#include <KParts/BrowserExtension> + // Qt Includes #include <QtCore/QTimer> @@ -707,6 +710,25 @@ void MainWindow::printRequested(QWebFrame *frame) if (!currentTab()) return; + if(currentTab()->page()->isOnRekonqPage()) + { + // trigger print part action instead of ours.. + KParts::ReadOnlyPart *p = currentTab()->part(); + if(p) + { + KParts::BrowserExtension *ext = p->browserExtension(); + if(ext) + { + KParts::BrowserExtension::ActionSlotMap *actionSlotMap = KParts::BrowserExtension::actionSlotMapPtr(); + + connect(this, SIGNAL(triggerPartPrint()), ext, actionSlotMap->value("print")); + emit triggerPartPrint(); + + return; + } + } + } + QWebFrame *printFrame = 0; if (frame == 0) { @@ -753,6 +775,18 @@ void MainWindow::findNext() if (!currentTab()) return; + if(currentTab()->page()->isOnRekonqPage()) + { + // trigger part find action + KParts::ReadOnlyPart *p = currentTab()->part(); + if(p) + { + connect(this, SIGNAL(triggerPartFind()), p, SLOT(slotFind())); + emit triggerPartFind(); + return; + } + } + if (m_findBar->isHidden()) { QPoint previous_position = currentTab()->view()->page()->currentFrame()->scrollPosition(); diff --git a/src/mainwindow.h b/src/mainwindow.h index 0395db4d..33fd2021 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -84,7 +84,7 @@ private: void setupToolbars(); void setupPanels(); -public slots: +public Q_SLOTS: void homePage(Qt::MouseButtons = Qt::LeftButton, Qt::KeyboardModifiers = Qt::NoModifier); /** @@ -108,12 +108,15 @@ public slots: void findPrevious(); void updateHighlight(); -signals: +Q_SIGNALS: // switching tabs void ctrlTabPressed(); void shiftCtrlTabPressed(); - -protected slots: + + void triggerPartPrint(); + void triggerPartFind(); + +protected Q_SLOTS: void saveNewToolbarConfig(); protected: @@ -126,7 +129,7 @@ protected: bool queryClose(); -private slots: +private Q_SLOTS: void postLaunch(); void browserLoading(bool); void updateWindowTitle(const QString &title = QString()); diff --git a/src/webpage.cpp b/src/webpage.cpp index f08aebd6..67a33047 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -229,7 +229,13 @@ WebPage::~WebPage() bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) { - _isOnRekonqPage = false; + if(_isOnRekonqPage) + { + WebView *view = qobject_cast<WebView *>(parent()); + WebTab *tab = qobject_cast<WebTab *>(view->parent()); + _isOnRekonqPage = false; + tab->setPart(0, KUrl()); // re-enable the view page + } _loadingUrl = request.url(); KIO::AccessManager *manager = qobject_cast<KIO::AccessManager*>(networkAccessManager()); @@ -439,32 +445,15 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) } // case KParts::BrowserRun::Embed - KService::List partServices = KMimeTypeTrader::self()->query(mimeType, QL1S("KParts/ReadOnlyPart")); - if (partServices.count() > 0) + KParts::ReadOnlyPart *pa = KMimeTypeTrader::createPartInstanceFromQuery<KParts::ReadOnlyPart>(mimeType, view(), this, QString()); + if (pa) { - QString p = replyUrl.pathOrUrl(); - - // A part can handle this. Embed it! - QString html; - html += "<html>"; - html += "<head>"; - html += "<title>"; - html += p; - html += "</title>"; - html += "<style type=\"text/css\">"; - html += "* { border: 0; padding: 0; margin: 0; }"; - html += "</style>"; - html += "</head>"; - html += "<body>"; - html += "<object type=\"" + mimeType + "\" data=\"" + p + "\" width=\"100%\" height=\"100%\" />"; - html += "</body>"; - html += "</html>"; - - mainFrame()->setHtml(html); _isOnRekonqPage = true; - + WebView *view = qobject_cast<WebView *>(parent()); WebTab *tab = qobject_cast<WebTab *>(view->parent()); + tab->setPart(pa,replyUrl); + UrlBar *bar = tab->urlBar(); bar->setQUrl(replyUrl); diff --git a/src/webtab.cpp b/src/webtab.cpp index 0a55060b..b4f070a9 100644 --- a/src/webtab.cpp +++ b/src/webtab.cpp @@ -51,6 +51,7 @@ WebTab::WebTab(QWidget *parent) , _view(new WebView(this)) , _bar(new UrlBar(this)) , _progress(0) + , _part(0) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -74,6 +75,7 @@ WebTab::WebTab(QWidget *parent) connect(_view, SIGNAL(loadProgress(int)), this, SLOT(updateProgress(int))); connect(_view, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool))); + connect(_view, SIGNAL(titleChanged(const QString &)), this, SIGNAL(titleChanged(const QString &))); } @@ -81,13 +83,18 @@ WebTab::~WebTab() { _walletBar.clear(); _previewSelectorBar.clear(); + + delete _part; } KUrl WebTab::url() { if(page() && page()->isOnRekonqPage()) + { + kDebug() << "REKONQ PAGE. URL = " << page()->loadingUrl(); return page()->loadingUrl(); + } return view()->url(); } @@ -203,3 +210,28 @@ void WebTab::showRSSInfo(QPoint pos) RSSWidget *widget = new RSSWidget(map, window()); widget->showAt(pos); } + + +void WebTab::setPart(KParts::ReadOnlyPart *p, const KUrl &u) +{ + if(p) + { + // Ok, part exists. Insert & show it.. + _part = p; + qobject_cast<QVBoxLayout *>(layout())->insertWidget(1, p->widget()); + p->openUrl(u); + _view->hide(); + + emit titleChanged(u.url()); + return; + } + + if(!_part) + return; + + // Part NO more exists. Let's clean up from webtab + _view->show(); + qobject_cast<QVBoxLayout *>(layout())->removeWidget(_part->widget()); + delete _part; + _part = 0; +} diff --git a/src/webtab.h b/src/webtab.h index 3fd4f793..abab5d73 100644 --- a/src/webtab.h +++ b/src/webtab.h @@ -35,6 +35,9 @@ // Local Includes #include "webview.h" +// KDE Includes +#include <KParts/Part> + // Qt Includes #include <QtGui/QWidget> @@ -65,16 +68,20 @@ public: bool hasRSSInfo(); bool isPageLoading(); -private slots: + KParts::ReadOnlyPart *part() { return _part; } + void setPart(KParts::ReadOnlyPart *p, const KUrl &u); + +private Q_SLOTS: void updateProgress(int progress); void loadFinished(bool); void createWalletBar(const QString &, const QUrl &); void showRSSInfo(QPoint pos); -signals: +Q_SIGNALS: void loadProgressing(); - + void titleChanged(const QString &); + private: WebView *_view; UrlBar *_bar; @@ -83,6 +90,8 @@ private: QWeakPointer<WalletBar> _walletBar; QWeakPointer<PreviewSelectorBar> _previewSelectorBar; + + KParts::ReadOnlyPart *_part; }; #endif |