diff options
-rw-r--r-- | INSTALL | 4 | ||||
-rw-r--r-- | src/bookmarks/bookmarkcontextmenu.cpp | 10 | ||||
-rw-r--r-- | src/bookmarks/bookmarksmanager.cpp | 4 | ||||
-rw-r--r-- | src/data/home.html | 44 | ||||
-rw-r--r-- | src/data/rekonq.desktop | 3 | ||||
-rw-r--r-- | src/mainview.cpp | 24 | ||||
-rw-r--r-- | src/mainview.h | 1 | ||||
-rw-r--r-- | src/mainwindow.cpp | 36 | ||||
-rw-r--r-- | src/settings/generalwidget.cpp | 2 | ||||
-rw-r--r-- | src/urlbar/listitem.cpp | 11 | ||||
-rw-r--r-- | src/urlbar/rsswidget.cpp | 5 | ||||
-rw-r--r-- | src/urlbar/urlresolver.cpp | 40 | ||||
-rw-r--r-- | src/urlbar/urlresolver.h | 13 | ||||
-rw-r--r-- | src/webpage.cpp | 380 | ||||
-rw-r--r-- | src/webpage.h | 13 | ||||
-rw-r--r-- | src/webview.cpp | 2 |
16 files changed, 337 insertions, 255 deletions
@@ -30,4 +30,6 @@ then be found in build/src and is executed with ./rekonq. === Getting Help === -If you need help with rekonq, you can find it in the irc-channel #rekonq on freenode.
\ No newline at end of file +If you need help with rekonq, you can find it in the irc-channel #rekonq on irc.freenode.net or by viewing the Handbook that comes with rekonq. +You can view the rekonq Handbook by pressing F1 after starting rekonq. +Techbase page : http://techbase.kde.org/Projects/rekonq diff --git a/src/bookmarks/bookmarkcontextmenu.cpp b/src/bookmarks/bookmarkcontextmenu.cpp index 47608710..c96fa7bf 100644 --- a/src/bookmarks/bookmarkcontextmenu.cpp +++ b/src/bookmarks/bookmarkcontextmenu.cpp @@ -213,11 +213,12 @@ void BookmarkContextMenu::deleteBookmark() { KBookmark bm = bookmark(); bool folder = bm.isGroup(); + QString name = QString(bm.text()).replace("&&", "&"); if (KMessageBox::warningContinueCancel( QApplication::activeWindow(), - folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?", bm.text()) - : i18n("Are you sure you wish to remove the bookmark\n\"%1\"?", bm.text()), + folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?", name) + : i18n("Are you sure you wish to remove the bookmark\n\"%1\"?", name), folder ? i18n("Bookmark Folder Deletion") : i18n("Bookmark Deletion"), KStandardGuiItem::del()) @@ -233,9 +234,10 @@ void BookmarkContextMenu::deleteBookmark() void BookmarkContextMenu::editBookmark() { KBookmark selected = bookmark(); - + selected.setFullText(selected.text().replace("&&", "&")); KBookmarkDialog *dialog = owner()->bookmarkDialog(manager(), QApplication::activeWindow()); dialog->editBookmark(selected); + selected.setFullText(selected.text().replace("&", "&&")); delete dialog; } @@ -317,7 +319,7 @@ void BookmarkContextMenu::bookmarkCurrentPage() if (selected.isGroup()) parent = selected.toGroup(); - KBookmark newBk = parent.addBookmark(owner()->currentTitle(), KUrl(owner()->currentUrl()), "text-html"); + KBookmark newBk = parent.addBookmark(owner()->currentTitle().replace("&", "&&"), KUrl(owner()->currentUrl()), "text-html"); parent.moveBookmark(newBk, selected.parentGroup().previous(selected)); } diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp index 0c437934..503e1df8 100644 --- a/src/bookmarks/bookmarksmanager.cpp +++ b/src/bookmarks/bookmarksmanager.cpp @@ -409,7 +409,9 @@ void BookmarkProvider::fillBookmarkBar(KToolBar *toolBar) else { - toolBar->addAction(new KBookmarkAction(bookmark, m_owner, this)); + KBookmarkAction* a = new KBookmarkAction(bookmark, m_owner, this); + a->setIconText(a->iconText().replace("&", "&&")); + toolBar->addAction(a); } } } diff --git a/src/data/home.html b/src/data/home.html index 25236743..cedd8855 100644 --- a/src/data/home.html +++ b/src/data/home.html @@ -40,9 +40,7 @@ font: normal bold 1em; a { color: #3F7AB7; text-decoration: none; --webkit-transition-property: color; --webkit-transition-duration: 0.5s; --webkit-transition-timing-function: ease; +-webkit-transition: color 0.5s ease; } a:hover { color: black; @@ -81,7 +79,12 @@ height: 16px; .link { display: inline-block; +-webkit-transition: opacity 0.5s ease; } +.link:not(.current):hover { +opacity: 0.6; +} + .link img, .link span { vertical-align: middle; display: inline-block; } @@ -89,15 +92,6 @@ vertical-align: middle; display: inline-block; color: black; } -#actions .link { --webkit-transition-property: opacity; --webkit-transition-duration: 0.8s; --webkit-transition-timing-function: ease; -opacity: 0.2; -} -#actions .link:hover { -opacity: 1; -} #actions .link img { margin-right: 3px; width: 16px; } @@ -141,22 +135,13 @@ background: url(%2/bg.png) no-repeat; padding: 0 12px; } -.thumbnail:hover .preview , -.thumbnail:hover .button img { -opacity: 0.8; -} -.button img, .preview { --webkit-transition-property: opacity; --webkit-transition-duration: 0.8s; --webkit-transition-timing-function: ease-in-out; -} - .button img { display: inline-block; width: 16px; height: 16px; opacity: 0; } + .remove { float: right; } @@ -164,7 +149,20 @@ float: right; float: left; } -.thumbnail a:hover, .thumbnail span { +.button img, .preview { +-webkit-transition: opacity 0.8s ease-in-out; +} +.thumb-inner:hover .preview { +opacity: 0.6; +} +.thumb-inner:hover .button img { +opacity: 0.4; +-webkit-transition: opacity 0.8s ease-out; +} +.thumb-inner .button img:hover { +opacity: 1; +} +.thumbnail a:hover { color:#3F7AB7; } diff --git a/src/data/rekonq.desktop b/src/data/rekonq.desktop index 5f4291b7..1aca0333 100644 --- a/src/data/rekonq.desktop +++ b/src/data/rekonq.desktop @@ -5,6 +5,7 @@ Name[da]=rekonq Name[de]=rekonq Name[en_GB]=rekonq Name[es]=rekonq +Name[et]=rekonq Name[fr]=rekonq Name[ga]=rekonq Name[it]=rekonq @@ -22,6 +23,8 @@ Name[zh_TW]=rekonq GenericName=WebKit KDE Browser GenericName[da]=KDE-browser baseret på WebKit GenericName[de]=WebKit-basierter Webbrowser für KDE +GenericName[et]=KDE WebKiti veebibrauser +GenericName[fr]=Navigateur Webkit pour KDE GenericName[pt]=Navegador do KDE Usando o WebKit GenericName[pt_BR]=Navegador WebKit do KDE GenericName[sv]=Webkit webbläsare för KDE diff --git a/src/mainview.cpp b/src/mainview.cpp index 1c36adcf..0bc6fbde 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -512,6 +512,8 @@ void MainView::closeTab(int index, bool del) UrlBar *urlbar = _widgetBar->urlBar(index); _widgetBar->removeWidget(urlbar); + _widgetBar->setCurrentIndex(m_currentTabIndex); + if (del) { tab->deleteLater(); // tab is scheduled for deletion. @@ -592,11 +594,10 @@ void MainView::webViewIconChanged() void MainView::webViewTitleChanged(const QString &title) { - QString tabTitle = title; - if (title.isEmpty()) - { - tabTitle = i18n("(Untitled)"); - } + QString viewTitle = title.isEmpty()? i18n("(Untitled)") : title; + QString tabTitle = viewTitle; + tabTitle.replace("&", "&&"); + WebView *view = qobject_cast<WebView *>(sender()); int index = indexOf(view->parentWidget()); if (-1 != index) @@ -605,7 +606,7 @@ void MainView::webViewTitleChanged(const QString &title) } if (currentIndex() == index) { - emit currentTitle(tabTitle); + emit currentTitle(viewTitle); } Application::historyManager()->updateHistoryEntry(view->url(), tabTitle); } @@ -657,6 +658,17 @@ void MainView::openClosedTab() } } +void MainView::switchToTab() +{ + // uses the sender to determine the tab index + QAction *sender = static_cast<QAction*>(QObject::sender()); + int index = sender->data().toInt(); + index -= 1; // to compensate for off by 1 presented to the user + if( index < 0 || index >= count() ) + return; + setCurrentIndex( index ); +} + QLabel *MainView::animatedLoading(int index, bool addMovie) { if (index == -1) diff --git a/src/mainview.h b/src/mainview.h index 0cff4c81..636d37ac 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -135,6 +135,7 @@ public slots: void detachTab(int index = -1); void openClosedTabs(); void openClosedTab(); + void switchToTab(); // WEB slot actions void webReload(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 54e64ab6..43418ed3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -320,7 +320,9 @@ void MainWindow::setupActions() browserLoading(false); //first init for blank start page a = new KAction(i18n("Open Location"), this); - a->setShortcut(Qt::CTRL + Qt::Key_L); + KShortcut openLocationShortcut(Qt::CTRL + Qt::Key_L); + openLocationShortcut.setAlternate(Qt::Key_F6); + a->setShortcut(openLocationShortcut); actionCollection()->addAction(QL1S("open_location"), a); connect(a, SIGNAL(triggered(bool)) , this, SLOT(openLocation())); @@ -398,6 +400,16 @@ void MainWindow::setupActions() closedTabsMenu->setDelayed(false); actionCollection()->addAction(QL1S("closed_tab_menu"), closedTabsMenu); + // shortcuts for quickly switching to a tab + for( int i = 1; i <= 9; i++ ) { + a = new KAction(i18n("Switch to Tab %1", i), this); + a->setShortcut(KShortcut( QString("Alt+%1").arg(i) )); + a->setData( QVariant(i) ); + actionCollection()->addAction(QL1S(("switch_tab_" + QString::number(i)).toAscii()), a); + connect(a, SIGNAL(triggered(bool)), m_view, SLOT(switchToTab())); + } + + // ============================== Indexed Tab Actions ==================================== a = new KAction(KIcon("tab-close"), i18n("&Close Tab"), this); actionCollection()->addAction(QL1S("close_tab"), a); @@ -941,26 +953,8 @@ void MainWindow::viewPageSource() if (!currentTab()) return; - KUrl url(currentTab()->url()); - bool isTempFile = false; - if (!url.isLocalFile()) - { - KTemporaryFile sourceFile; - - /// TODO: autochoose tempfile suffix - sourceFile.setSuffix(QString(".html")); - sourceFile.setAutoRemove(false); - - if (sourceFile.open()) - { - sourceFile.write(currentTab()->page()->mainFrame()->toHtml().toUtf8()); - - url = KUrl(); - url.setPath(sourceFile.fileName()); - isTempFile = true; - } - } - KRun::runUrl(url, QL1S("text/plain"), this, isTempFile); + KUrl url = currentTab()->url(); + KRun::runUrl(url, QL1S("text/plain"), this, false); } diff --git a/src/settings/generalwidget.cpp b/src/settings/generalwidget.cpp index fc2d4d5d..09c9e5c7 100644 --- a/src/settings/generalwidget.cpp +++ b/src/settings/generalwidget.cpp @@ -69,7 +69,7 @@ void GeneralWidget::hasChanged() void GeneralWidget::setHomeToCurrentPage() { - MainWindow *mw = qobject_cast<MainWindow*>(parent()); + MainWindow *mw = Application::instance()->mainWindow(); WebTab *webTab = mw->currentTab(); if (webTab) { diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index f91840d2..5254c7dc 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -220,7 +220,16 @@ PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text, QVBoxLayout *vLayout = new QVBoxLayout; vLayout->setMargin(0); - vLayout->addWidget(new TextLabel(item.title, text, this)); + + QString title = item.title; + if (title.isEmpty()) + { + title = item.url.url(); + title = title.remove("http://"); + title.truncate(title.indexOf("/")); + } + + vLayout->addWidget(new TextLabel(title, text, this)); vLayout->addWidget(new TextLabel("<i>" + item.url.url() + "</i>", text, this)); hLayout->addLayout(vLayout); diff --git a/src/urlbar/rsswidget.cpp b/src/urlbar/rsswidget.cpp index 07b45853..6cd63b95 100644 --- a/src/urlbar/rsswidget.cpp +++ b/src/urlbar/rsswidget.cpp @@ -115,9 +115,12 @@ RSSWidget::~RSSWidget() void RSSWidget::showAt(const QPoint &pos) { + adjustSize(); + QPoint p; - p.setX(pos.x() - 200); + p.setX(pos.x() - width()); p.setY(pos.y() + 10); + move(p); show(); } diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 21e3fe9c..07b40bac 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -141,12 +141,23 @@ UrlSearchList UrlResolver::orderedSearchItems() int checkPoint = 9 - firstResults; UrlSearchList historyList = historyResolution(); + UrlSearchItem privileged = privilegedItem(&historyList); int historyResults = historyList.count(); + + UrlSearchList bookmarksList = bookmarksResolution(); + if (privileged.type == UrlSearchItem::Undefined) + { + privileged = privilegedItem(&bookmarksList); + } + + if (privileged.type != UrlSearchItem::Undefined) + { + list.insert(0,privileged); + } - UrlSearchList bookmarksList = bookmarksResolution(); - int bookmarkResults = bookmarksList.count(); + int bookmarksResults = bookmarksList.count(); - if (historyResults + bookmarkResults > checkPoint) + if (historyResults + bookmarksResults > checkPoint) { historyList = historyList.mid(0, 3); bookmarksList = bookmarksList.mid(0, 3); @@ -178,8 +189,6 @@ UrlSearchList UrlResolver::orderedSearchItems() list << i; } - list = placeTypedDomaineNameOnTop(list); - return list; } @@ -246,22 +255,19 @@ UrlSearchList UrlResolver::bookmarksResolution() } -UrlSearchList UrlResolver::placeTypedDomaineNameOnTop(UrlSearchList list) +UrlSearchItem UrlResolver::privilegedItem(UrlSearchList* list) { - int i = 0; - bool found = false; - - while(i<list.count() && !found) + int i=0; + while(i<list->count()) { - UrlSearchItem item = list.at(i); - if (item.url.url().contains("."+_typedString+".") || item.url.url().contains("/"+_typedString+".")) + UrlSearchItem item = list->at(i); + kDebug() << item.url.host(); + if (item.url.host().contains( _typedString + QL1C('.') ) ) { - list.removeAt(i); - list.insert(0,item); - found = true; + list->removeAt(i); + return item; } i++; } - - return list; + return UrlSearchItem(); } diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 0c7df8c8..2249ea32 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -45,6 +45,7 @@ public: enum types { + Undefined = 0x00000000, Search = 0x00000001, Browse = 0x00000010, History = 0x00000100, @@ -54,7 +55,15 @@ public: int type; KUrl url; QString title; - + + UrlSearchItem(const UrlSearchItem &item) + : type(item.type), url(item.url), title(item.title) + {}; + + UrlSearchItem() + : type(UrlSearchItem::Undefined), url(KUrl()), title("") + {}; + UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString()) : type(_type), url(_url), title(_title) {}; @@ -82,7 +91,7 @@ private: UrlSearchList historyResolution(); UrlSearchList qurlFromUserInputResolution(); UrlSearchList bookmarksResolution(); - UrlSearchList placeTypedDomaineNameOnTop(UrlSearchList list); + UrlSearchItem privilegedItem(UrlSearchList* list); static QRegExp _browseRegexp; }; diff --git a/src/webpage.cpp b/src/webpage.cpp index 507263cc..00745445 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -97,6 +97,72 @@ static bool domainSchemeMatch(const QUrl& u1, const QUrl& u2) } +// NOTE +// This is heavily based on the one from KdeWebKit and +// extended to provide the extra functionality we need: +// 1. KGet Integration +// 2. Save downloads history +static bool downloadResource (const KUrl& srcUrl, const KIO::MetaData& metaData = KIO::MetaData(), + QWidget* parent = 0, const QString& suggestedName = QString()) +{ + KUrl destUrl; + + int result = KIO::R_OVERWRITE; + const QUrl fileName ((suggestedName.isEmpty() ? srcUrl.fileName() : suggestedName)); + + do + { + destUrl = KFileDialog::getSaveFileName(fileName, QString(), parent); + + if (destUrl.isLocalFile()) + { + QFileInfo finfo (destUrl.toLocalFile()); + if (finfo.exists()) + { + QDateTime now = QDateTime::currentDateTime(); + KIO::RenameDialog dlg (parent, i18n("Overwrite File?"), srcUrl, destUrl, + KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP), + -1, finfo.size(), + now.toTime_t(), finfo.created().toTime_t(), + now.toTime_t(), finfo.lastModified().toTime_t()); + result = dlg.exec(); + } + } + } + while (result == KIO::R_CANCEL && destUrl.isValid()); + + // Save download on history manager + Application::historyManager()->addDownload(srcUrl.pathOrUrl() , destUrl.pathOrUrl()); + + if (ReKonfig::kgetDownload()) + { + //KGet integration: + if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) + { + KToolInvocation::kdeinitExecWait("kget"); + } + QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main"); + if (kget.isValid()) + { + kget.call("addTransfer", srcUrl.prettyUrl(), destUrl.prettyUrl(), true); + return true; + } + return false; + } + + KIO::Job *job = KIO::file_copy(srcUrl, destUrl, -1, KIO::Overwrite); + + if (!metaData.isEmpty()) + job->setMetaData(metaData); + + job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache. + job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available. + job->uiDelegate()->setAutoErrorHandlingEnabled(true); + return true; + +} + + // --------------------------------------------------------------------------------- @@ -246,111 +312,151 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) if (_protHandler.postHandling(reply->request(), mainFrame())) return; - if (reply->error() == QNetworkReply::NoError) - { - KUrl replyUrl = reply->url(); + if (reply->error() != QNetworkReply::NoError) + return; + + KUrl replyUrl = reply->url(); - // HACK ------------------------------------------- - QString mimeType; - QString suggestedFileName; - - QString app = reply->header(QNetworkRequest::ContentTypeHeader).toString(); - QStringList headerList = app.split( ';' ); - - if(headerList.count() > 0) + // HACK ------------------------------------------- + // This is done to fix #231204 && #212808 + + QString mimeType; + QString suggestedFileName; + + QString app = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + QStringList headerList = app.split( ';' ); + + if(headerList.count() > 0) + { + mimeType = headerList.takeFirst().trimmed(); + Q_FOREACH(const QString &head, headerList) { - mimeType = headerList.takeFirst().trimmed(); - Q_FOREACH(const QString &head, headerList) + if( head.contains( QL1S("name") ) ) { - if( head.contains( QL1S("name") ) ) - { - // this is not so sure.. :) - suggestedFileName = head; - suggestedFileName = suggestedFileName.remove( QL1S("name=") ); - suggestedFileName = suggestedFileName.remove( '"' ); - suggestedFileName = suggestedFileName.trimmed(); - break; - } + // this is not so sure.. :) + suggestedFileName = head; + suggestedFileName = suggestedFileName.remove( QL1S("name=") ); + suggestedFileName = suggestedFileName.remove( '"' ); + suggestedFileName = suggestedFileName.trimmed(); + break; } } - else + } + else + { + mimeType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + } + + // NOTE + // This part has been copied from KWebPage::downloadResponse code + if (reply->hasRawHeader("Content-Disposition")) + { + KIO::MetaData metaData = reply->attribute(static_cast<QNetworkRequest::Attribute>(KIO::AccessManager::MetaData)).toMap(); + if (metaData.value(QL1S("content-disposition-type")).compare(QL1S("attachment"), Qt::CaseInsensitive) == 0) + { + suggestedFileName = metaData.value(QL1S("content-disposition-filename")); + } + else { - mimeType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + const QString value = QL1S(reply->rawHeader("Content-Disposition").simplified()); + if (value.startsWith(QL1S("attachment"), Qt::CaseInsensitive)) + { + const int length = value.size(); + int pos = value.indexOf(QL1S("filename"), 0, Qt::CaseInsensitive); + if (pos > -1) + { + pos += 9; + while (pos < length && (value.at(pos) == QL1C(' ') || value.at(pos) == QL1C('=') || value.at(pos) == QL1C('"'))) + pos++; + + int endPos = pos; + while (endPos < length && value.at(endPos) != QL1C('"') && value.at(endPos) != QL1C(';')) + endPos++; + + if (endPos > pos) + { + suggestedFileName = value.mid(pos, (endPos-pos)).trimmed(); + } + } + } } - // ------------------------------------------------ - - KService::Ptr appService = KMimeTypeTrader::self()->preferredService(mimeType); - - bool isLocal = replyUrl.isLocalFile(); + } + + kDebug() << "Detected MimeType = " << mimeType; + kDebug() << "Suggested File Name = " << suggestedFileName; + // ------------------------------------------------ + + KService::Ptr appService = KMimeTypeTrader::self()->preferredService(mimeType); - if (appService.isNull()) // no service can handle this. We can just download it.. - { - kDebug() << "no service can handle this. We can just download it.."; + bool isLocal = replyUrl.isLocalFile(); - isLocal - ? KMessageBox::sorry(view(), i18n("No service can handle this :(")) - : downloadThings(reply->request(), suggestedFileName); + if (appService.isNull()) // no service can handle this. We can just download it.. + { + kDebug() << "no service can handle this. We can just download it.."; - return; - } + isLocal + ? KMessageBox::sorry(view(), i18n("No service can handle this :(")) + : downloadReply(reply, suggestedFileName); - if (!isLocal) - { + return; + } - KParts::BrowserOpenOrSaveQuestion dlg(Application::instance()->mainWindow(), replyUrl, mimeType); - if(!suggestedFileName.isEmpty()) - dlg.setSuggestedFileName(suggestedFileName); - - switch (dlg.askEmbedOrSave()) - { - case KParts::BrowserOpenOrSaveQuestion::Save: - kDebug() << "user choice: no services, just download!"; - downloadThings(reply->request(), suggestedFileName); - return; + if (!isLocal) + { - case KParts::BrowserOpenOrSaveQuestion::Cancel: - return; + KParts::BrowserOpenOrSaveQuestion dlg(Application::instance()->mainWindow(), replyUrl, mimeType); + if(!suggestedFileName.isEmpty()) + dlg.setSuggestedFileName(suggestedFileName); + + switch (dlg.askEmbedOrSave()) + { + case KParts::BrowserOpenOrSaveQuestion::Save: + kDebug() << "user choice: no services, just download!"; + downloadReply(reply, suggestedFileName); + return; - default: // non extant case - break; - } - } + case KParts::BrowserOpenOrSaveQuestion::Cancel: + return; - // case KParts::BrowserRun::Embed - KService::List partServices = KMimeTypeTrader::self()->query(mimeType, QL1S("KParts/ReadOnlyPart")); - if (partServices.count() > 0) - { - 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; - Application::instance()->mainWindow()->mainView()->urlBar()->setQUrl(replyUrl); - Application::instance()->mainWindow()->updateActions(); - } - else - { - // No parts, just app services. Load it! - KRun::run(*appService, replyUrl, 0); + default: // non extant case + break; } + } - return; + // case KParts::BrowserRun::Embed + KService::List partServices = KMimeTypeTrader::self()->query(mimeType, QL1S("KParts/ReadOnlyPart")); + if (partServices.count() > 0) + { + 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; + Application::instance()->mainWindow()->mainView()->urlBar()->setQUrl(replyUrl); + Application::instance()->mainWindow()->updateActions(); } + else + { + // No parts, just app services. Load it! + KRun::run(*appService, replyUrl, 0); + } + + return; } @@ -402,24 +508,28 @@ void WebPage::manageNetworkErrors(QNetworkReply *reply) } break; + case QNetworkReply::OperationCanceledError: // operation canceled via abort() or close() calls + // ignore this.. + return; + case QNetworkReply::ContentAccessDenied: // access to remote content denied (similar to HTTP error 401) kDebug() << "We (hopefully) are managing this through the adblock :)"; break; case QNetworkReply::UnknownNetworkError: // unknown network-related error detected - if (_protHandler.postHandling(reply->request(), mainFrame())) - break; + _protHandler.postHandling(reply->request(), mainFrame()); + return; case QNetworkReply::ConnectionRefusedError: // remote server refused connection case QNetworkReply::HostNotFoundError: // invalid hostname case QNetworkReply::TimeoutError: // connection time out - case QNetworkReply::OperationCanceledError: // operation canceled via abort() or close() calls case QNetworkReply::ProxyNotFoundError: // invalid proxy hostname case QNetworkReply::ContentOperationNotPermittedError: // operation requested on remote content not permitted case QNetworkReply::ContentNotFoundError: // remote content not found on server (similar to HTTP error 404) case QNetworkReply::ProtocolUnknownError: // Unknown protocol case QNetworkReply::ProtocolInvalidOperationError: // requested operation is invalid for this protocol + kDebug() << "ERROR " << reply->error() << ": " << reply->errorString(); if (reply->url() == _loadingUrl) { mainFrame()->setHtml(errorPage(reply)); @@ -478,89 +588,23 @@ QString WebPage::errorPage(QNetworkReply *reply) } -// WARNING -// this code is actually copied from KWebPage::downloadRequest to save -// downloads data before. If you have some better ideas about, -// feel free to let us know about :) -void WebPage::downloadThings(const QNetworkRequest &request, const QString &suggestedFileName) +void WebPage::downloadReply(const QNetworkReply *reply, const QString &suggestedFileName) { - KUrl destUrl; - KUrl srcUrl(request.url()); - - if( !ReKonfig::kgetDownload() && suggestedFileName.isEmpty() ) - { - kDebug() << "Using KWebPage downloadRequest.."; - Application::historyManager()->addDownload(srcUrl.pathOrUrl() , destUrl.pathOrUrl()); - KWebPage::downloadRequest(request); - return; - } - - int result = KIO::R_OVERWRITE; - - do - { - QString fName = suggestedFileName.isEmpty() - ? srcUrl.fileName() - : suggestedFileName; - - destUrl = KFileDialog::getSaveFileName(fName, QString(), view()); - - if (destUrl.isLocalFile()) - { - QFileInfo finfo(destUrl.toLocalFile()); - if (finfo.exists()) - { - QDateTime now = QDateTime::currentDateTime(); - QPointer<KIO::RenameDialog> dlg = new KIO::RenameDialog(view(), - i18n("Overwrite File?"), - srcUrl, - destUrl, - KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP), - -1, - finfo.size(), - now.toTime_t(), - finfo.created().toTime_t(), - now.toTime_t(), - finfo.lastModified().toTime_t() - ); - result = dlg->exec(); - delete dlg; - } - } - } - while (result == KIO::R_CANCEL && destUrl.isValid()); + downloadResource( reply->url(), KIO::MetaData(), view(), suggestedFileName); +} - if (result == KIO::R_OVERWRITE && destUrl.isValid()) - { - // now store data - // now, destUrl, srcUrl - Application::historyManager()->addDownload(srcUrl.pathOrUrl() , destUrl.pathOrUrl()); - if (ReKonfig::kgetDownload()) - { - //KGet integration: - if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) - { - KToolInvocation::kdeinitExecWait("kget"); - } - QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main"); - if (kget.isValid()) - { - kget.call("addTransfer", srcUrl.prettyUrl(), destUrl.prettyUrl(), true); - return; - } - } +void WebPage::downloadRequest(const QNetworkRequest &request) +{ + downloadResource(request.url(), + request.attribute(static_cast<QNetworkRequest::Attribute>(KIO::AccessManager::MetaData)).toMap(), + view()); +} - // else, use KIO or fallback to it - KIO::Job *job = KIO::file_copy(srcUrl, destUrl, -1, KIO::Overwrite); - QVariant attr = request.attribute(static_cast<QNetworkRequest::Attribute>(KIO::AccessManager::MetaData)); - if (attr.isValid() && attr.type() == QVariant::Map) - job->setMetaData(KIO::MetaData(attr.toMap())); - job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache. - job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available. - job->uiDelegate()->setAutoErrorHandlingEnabled(true); - } +void WebPage::downloadUrl(const KUrl &url) +{ + downloadResource( url, KIO::MetaData(), view() ); } diff --git a/src/webpage.h b/src/webpage.h index eff4c3fc..f3d201c2 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -68,7 +68,10 @@ public: public slots: void downloadAllContentsWithKGet(QPoint); - + + virtual void downloadRequest(const QNetworkRequest &request); + virtual void downloadUrl(const KUrl &url); + protected: WebPage *createWindow(WebWindowType type); @@ -83,13 +86,7 @@ private slots: void showSSLInfo(QPoint); void updateImage(bool ok); - /** - * This new slot is needed to provide integration between rekonq & KGet, - * to better manage file names and to not overwrite KWebPage default behavior on need - * - * @see KWebPage::downloadRequest. - */ - void downloadThings(const QNetworkRequest &request, const QString &suggestedFileName = QString()); + void downloadReply(const QNetworkReply *reply, const QString &suggestedFileName = QString()); private: QString errorPage(QNetworkReply *reply); diff --git a/src/webview.cpp b/src/webview.cpp index 99c48f0b..878a7403 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -77,7 +77,7 @@ WebView::WebView(QWidget* parent) // download system connect(this, SIGNAL(linkShiftClicked(const KUrl &)), page, SLOT(downloadUrl(const KUrl &))); - connect(page, SIGNAL(downloadRequested(const QNetworkRequest &)), page, SLOT(downloadThings(const QNetworkRequest &))); + connect(page, SIGNAL(downloadRequested(const QNetworkRequest &)), page, SLOT(downloadRequest(const QNetworkRequest &))); // middle click || ctrl + click signal connect(this, SIGNAL(linkMiddleOrCtrlClicked(const KUrl &)), this, SLOT(loadUrlInNewTab(const KUrl &))); |