mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Make use of "error:" urls as much as possible, to display errors inline in the page rather than popping up message boxes.
The message boxes were especially annoying on session restore, when a konq on another desktop can block the konq on your current desktop, which drove my wife crazy. Don't want that. svn path=/trunk/KDE/kdebase/apps/; revision=1169903
This commit is contained in:
parent
8d7fc50afb
commit
662298c166
8 changed files with 92 additions and 122 deletions
|
@ -482,11 +482,9 @@ void KonqMainWindow::openFilteredUrl(const QString & url, const KonqOpenURLReque
|
|||
|
||||
// #4070: Give focus to view after URL was entered manually
|
||||
// Note: we do it here if the view mode (i.e. part) wasn't changed
|
||||
// If it is changed, then it's done in KonqView::changePart
|
||||
if ( m_currentView && m_currentView->part() ) {
|
||||
m_currentView->part()->widget()->setFocus();
|
||||
}
|
||||
|
||||
// If it is changed, then it's done in KonqViewManager::doSetActivePart
|
||||
if (m_currentView)
|
||||
m_currentView->setFocus();
|
||||
}
|
||||
|
||||
void KonqMainWindow::openFilteredUrl(const QString & _url, bool inNewTab, bool tempFile)
|
||||
|
@ -513,20 +511,18 @@ void KonqMainWindow::openUrl(KonqView *_view, const KUrl &_url,
|
|||
QString mimeType(_mimeType);
|
||||
KonqOpenURLRequest req(_req);
|
||||
|
||||
if ( url.url() == "about:blank" )
|
||||
{
|
||||
mimeType = "text/html";
|
||||
}
|
||||
else if ( !url.isValid() )
|
||||
{
|
||||
KMessageBox::error(0, i18n("Malformed URL\n%1", url.url()));
|
||||
return;
|
||||
}
|
||||
else if ( !KProtocolInfo::isKnownProtocol( url ) && url.protocol() != "about" )
|
||||
{
|
||||
KMessageBox::error(0, i18n("Protocol not supported\n%1", url.protocol()));
|
||||
return;
|
||||
}
|
||||
if (!url.isValid()) {
|
||||
// I think we can't really get here anymore; I tried and didn't succeed.
|
||||
// URL filtering catches this case before hand, and in cases without filtering
|
||||
// (e.g. HTML link), the url is empty here, not invalid.
|
||||
// But just to be safe, let's keep this code path, even if it can't show the typed string.
|
||||
url = KParts::BrowserRun::makeErrorUrl(KIO::ERR_MALFORMED_URL, url.url(), url.url());
|
||||
} else if (!KProtocolInfo::isKnownProtocol(url)) {
|
||||
url = KParts::BrowserRun::makeErrorUrl(KIO::ERR_UNSUPPORTED_PROTOCOL, url.protocol(), url.url());
|
||||
}
|
||||
if (url.url() == "about:blank" || url.protocol() == "error") {
|
||||
mimeType = "text/html";
|
||||
}
|
||||
|
||||
QString nameFilter = detectNameFilter( url );
|
||||
if ( !nameFilter.isEmpty() )
|
||||
|
@ -1450,74 +1446,6 @@ void KonqMainWindow::slotOpenFile()
|
|||
openFilteredUrl( url.url().trimmed() );
|
||||
}
|
||||
|
||||
#if 0
|
||||
void KonqMainWindow::slotToolFind()
|
||||
{
|
||||
if ( m_currentView && ::qobject_cast<KonqDirPart*>( m_currentView->part() ) )
|
||||
{
|
||||
KonqDirPart* dirPart = static_cast<KonqDirPart *>(m_currentView->part());
|
||||
|
||||
if (!m_paFindFiles->isChecked())
|
||||
{
|
||||
dirPart->slotFindClosed();
|
||||
return;
|
||||
}
|
||||
|
||||
KonqFactory konqFactory;
|
||||
KonqViewFactory factory = konqFactory.createView( "Konqueror/FindPart" );
|
||||
if ( factory.isNull() )
|
||||
{
|
||||
KMessageBox::error( this, i18n("Cannot create the find part, check your installation.") );
|
||||
m_paFindFiles->setChecked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
KParts::ReadOnlyPart* findPart = factory.create( m_currentView->frame(), dirPart );
|
||||
dirPart->setFindPart( findPart );
|
||||
|
||||
m_currentView->frame()->insertTopWidget( findPart->widget() );
|
||||
findPart->widget()->show();
|
||||
findPart->widget()->setFocus();
|
||||
|
||||
connect( dirPart, SIGNAL( findClosed(KonqDirPart *) ),
|
||||
this, SLOT( slotFindClosed(KonqDirPart *) ) );
|
||||
}
|
||||
else if ( ::qobject_cast<KAction*>(sender()) ) // don't go there if called by the singleShot below
|
||||
{
|
||||
KUrl url;
|
||||
if ( m_currentView && m_currentView->url().isLocalFile() )
|
||||
url = m_currentView->locationBarURL();
|
||||
else
|
||||
url.setPath( QDir::homePath() );
|
||||
KonqMainWindow * mw = KonqMisc::createBrowserWindowFromProfile(
|
||||
KStandardDirs::locate( "data", QLatin1String("konqueror/profiles/filemanagement") ),
|
||||
"filemanagement", url, KParts::URLArgs(), true /* forbid "use html"*/ );
|
||||
mw->m_paFindFiles->setChecked(true);
|
||||
// Delay it after the openUrl call (hacky!)
|
||||
QTimer::singleShot( 1, mw, SLOT(slotToolFind()));
|
||||
m_paFindFiles->setChecked(false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void KonqMainWindow::slotFindOpen( KonqDirPart * dirPart )
|
||||
{
|
||||
Q_ASSERT( m_currentView );
|
||||
Q_ASSERT( m_currentView->part() == dirPart );
|
||||
slotToolFind(); // lazy me
|
||||
}
|
||||
|
||||
void KonqMainWindow::slotFindClosed( KonqDirPart * dirPart )
|
||||
{
|
||||
KonqView * dirView = m_mapViews.value( dirPart );
|
||||
Q_ASSERT(dirView);
|
||||
if ( dirView && dirView == m_currentView )
|
||||
m_paFindFiles->setEnabled( true );
|
||||
m_paFindFiles->setChecked(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
void KonqMainWindow::slotIconsChanged()
|
||||
{
|
||||
kDebug();
|
||||
|
@ -1968,8 +1896,8 @@ void KonqMainWindow::slotViewCompleted( KonqView * view )
|
|||
|
||||
void KonqMainWindow::slotPartActivated(KParts::Part *part)
|
||||
{
|
||||
//kDebug() << part
|
||||
// << (part && part->componentData().isValid() && part->componentData().aboutData() ? part->componentData().aboutData()->appName() : "");
|
||||
kDebug() << part
|
||||
<< (part && part->componentData().isValid() && part->componentData().aboutData() ? part->componentData().aboutData()->appName() : "");
|
||||
|
||||
KonqView *newView = 0;
|
||||
KonqView *oldView = m_currentView;
|
||||
|
@ -1995,7 +1923,7 @@ void KonqMainWindow::slotPartActivated(KParts::Part *part)
|
|||
}
|
||||
}
|
||||
|
||||
//kDebug() << "New current view" << newView;
|
||||
kDebug() << "New current view" << newView;
|
||||
m_currentView = newView;
|
||||
if (!part) {
|
||||
//kDebug() << "No part activated - returning";
|
||||
|
@ -2332,6 +2260,7 @@ void KonqMainWindow::slotAddTab()
|
|||
//HACK!! QTabBar likes to steal focus when changing widgets. This can result
|
||||
//in a flicker since we don't want it to get focus we want the combo to get
|
||||
//or keep focus...
|
||||
// TODO: retest, and replace with the smaller hack from KTabWidget::moveTab
|
||||
QWidget *widget = newView->frame() && newView->frame()->part() ?
|
||||
newView->frame()->part()->widget() : 0;
|
||||
QWidget* origFocusProxy = widget ? widget->focusProxy() : 0;
|
||||
|
|
|
@ -498,12 +498,6 @@ private Q_SLOTS:
|
|||
|
||||
void slotOpenURL( const KUrl& );
|
||||
|
||||
#if 0
|
||||
void slotToolFind();
|
||||
void slotFindOpen( KonqDirPart * dirPart );
|
||||
void slotFindClosed( KonqDirPart * dirPart );
|
||||
#endif
|
||||
|
||||
void slotIconsChanged();
|
||||
|
||||
virtual bool event( QEvent* );
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* This file is part of the KDE project
|
||||
Copyright (C) 1998, 1999 David Faure <faure@kde.org>
|
||||
Copyright (C) 1998, 1999, 2010 David Faure <faure@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
|
@ -17,6 +17,7 @@
|
|||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include "konqmisc.h"
|
||||
#include <kparts/browserrun.h>
|
||||
#include <QDir>
|
||||
#include "konqsessionmanager.h"
|
||||
#include "konqsettingsxt.h"
|
||||
|
@ -26,7 +27,6 @@
|
|||
|
||||
#include <kapplication.h>
|
||||
#include <kdebug.h>
|
||||
#include <kmessagebox.h>
|
||||
#include <kurifilter.h>
|
||||
#include <klocale.h>
|
||||
#include <kstandarddirs.h>
|
||||
|
@ -196,9 +196,10 @@ KonqMainWindow * KonqMisc::newWindowFromHistory( KonqView* view, int steps )
|
|||
return mainwindow;
|
||||
}
|
||||
|
||||
QString KonqMisc::konqFilteredURL( QWidget* parent, const QString& _url, const QString& _path )
|
||||
KUrl KonqMisc::konqFilteredURL(KonqMainWindow* parent, const QString& _url, const QString& _path)
|
||||
{
|
||||
if ( !_url.startsWith( "about:" ) ) // Don't filter "about:" URLs
|
||||
Q_UNUSED(parent); // Useful if we want to change the error handling again
|
||||
if (!_url.startsWith( "about:" )) // Don't filter "about:" URLs
|
||||
{
|
||||
KUriFilterData data(_url);
|
||||
|
||||
|
@ -211,19 +212,23 @@ QString KonqMisc::konqFilteredURL( QWidget* parent, const QString& _url, const Q
|
|||
|
||||
if( KUriFilter::self()->filterUri( data ) )
|
||||
{
|
||||
if( data.uriType() == KUriFilterData::Error && !data.errorMsg().isEmpty() )
|
||||
{
|
||||
KMessageBox::sorry( parent, i18n( data.errorMsg().toUtf8() ) );
|
||||
return QString();
|
||||
if( data.uriType() == KUriFilterData::Error && !data.errorMsg().isEmpty() ) {
|
||||
return KParts::BrowserRun::makeErrorUrl(KIO::ERR_SLAVE_DEFINED, data.errorMsg(), _url);
|
||||
} else {
|
||||
return data.uri();
|
||||
}
|
||||
else
|
||||
return data.uri().url();
|
||||
}
|
||||
}
|
||||
else if (_url != "about:blank" && _url != "about:plugins" && !_url.startsWith("about:konqueror")) {
|
||||
return "about:";
|
||||
return KUrl("about:");
|
||||
}
|
||||
return _url; // return the original url if it cannot be filtered.
|
||||
|
||||
// return the original url if it cannot be filtered. But only if it gives a valid KUrl.
|
||||
KUrl url(_url);
|
||||
if (!url.isValid()) {
|
||||
return KParts::BrowserRun::makeErrorUrl(KIO::ERR_MALFORMED_URL, _url, _url);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
QString KonqMisc::defaultProfileName()
|
||||
|
|
|
@ -85,13 +85,13 @@ namespace KonqMisc // TODO split into something like KonqWindowFactory or KonqWi
|
|||
KonqMainWindow * newWindowFromHistory( KonqView* view, int steps );
|
||||
|
||||
/**
|
||||
* Applies the URI filters to @p url.
|
||||
* Applies the URI filters to @p url, and convert it to a KUrl.
|
||||
*
|
||||
* @p parent is used in case of a message box.
|
||||
* @p _url to be filtered.
|
||||
* @p _path the absolute path to append to the url before filtering it.
|
||||
* @p url to be filtered.
|
||||
* @p path the absolute path to use, in case the url is relative.
|
||||
*/
|
||||
QString konqFilteredURL( QWidget* /*parent*/, const QString& /*_url*/, const QString& _path = QString() );
|
||||
KUrl konqFilteredURL(KonqMainWindow* parent, const QString& url, const QString& path = QString());
|
||||
|
||||
/**
|
||||
* Name of the default profile
|
||||
|
|
|
@ -365,13 +365,14 @@ void KonqFrameTabs::slotSubPopupMenuTabActivated( QAction *action )
|
|||
|
||||
void KonqFrameTabs::slotMouseMiddleClick()
|
||||
{
|
||||
KUrl filteredURL ( KonqMisc::konqFilteredURL( this, QApplication::clipboard()->text(QClipboard::Selection) ) );
|
||||
KonqMainWindow* mainWindow = m_pViewManager->mainWindow();
|
||||
KUrl filteredURL ( KonqMisc::konqFilteredURL( mainWindow, QApplication::clipboard()->text(QClipboard::Selection) ) );
|
||||
if ( !filteredURL.isEmpty() ) {
|
||||
KonqView* newView = m_pViewManager->addTab("text/html", QString(), false, false);
|
||||
if (newView == 0L) return;
|
||||
m_pViewManager->mainWindow()->openUrl( newView, filteredURL, QString() );
|
||||
mainWindow->openUrl( newView, filteredURL, QString() );
|
||||
m_pViewManager->showTab( newView );
|
||||
m_pViewManager->mainWindow()->focusLocationBar();
|
||||
mainWindow->focusLocationBar();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -380,7 +381,7 @@ void KonqFrameTabs::slotMouseMiddleClick(QWidget *w)
|
|||
if (KonqSettings::mouseMiddleClickClosesTab()) {
|
||||
slotCloseRequest(w);
|
||||
} else {
|
||||
KUrl filteredURL(KonqMisc::konqFilteredURL(this, QApplication::clipboard()->text(QClipboard::Selection)));
|
||||
KUrl filteredURL(KonqMisc::konqFilteredURL(m_pViewManager->mainWindow(), QApplication::clipboard()->text(QClipboard::Selection)));
|
||||
if (!filteredURL.isEmpty()) {
|
||||
KonqFrameBase* frame = dynamic_cast<KonqFrameBase*>(w);
|
||||
if (frame) {
|
||||
|
|
|
@ -101,6 +101,7 @@ KonqView::KonqView( KonqViewFactory &viewFactory,
|
|||
m_bFollowActive = false;
|
||||
m_bBuiltinView = false;
|
||||
m_bURLDropHandling = false;
|
||||
m_bErrorURL = false;
|
||||
|
||||
switchView( viewFactory );
|
||||
}
|
||||
|
@ -133,6 +134,7 @@ void KonqView::openUrl( const KUrl &url, const QString & locationBarURL,
|
|||
const QString & nameFilter, bool tempFile )
|
||||
{
|
||||
kDebug() << "url=" << url << "locationBarURL=" << locationBarURL;
|
||||
|
||||
setPartMimeType();
|
||||
|
||||
KParts::OpenUrlArguments args;
|
||||
|
@ -172,7 +174,11 @@ void KonqView::openUrl( const KUrl &url, const QString & locationBarURL,
|
|||
if ( m_bDisableScrolling )
|
||||
callExtensionMethod( "disableScrolling" );
|
||||
|
||||
setLocationBarURL( locationBarURL );
|
||||
// Set location-bar URL, except for error urls, where we know the browser component
|
||||
// will set back the url with the error anyway.
|
||||
if (url.protocol() != "error")
|
||||
setLocationBarURL(locationBarURL);
|
||||
|
||||
setPageSecurity(KonqMainWindow::NotCrypted);
|
||||
|
||||
if ( !args.reload() )
|
||||
|
@ -576,10 +582,10 @@ void KonqView::slotCompleted( bool hasPending )
|
|||
void KonqView::slotCanceled( const QString & errorMsg )
|
||||
{
|
||||
//kDebug();
|
||||
// The errorMsg comes from the ReadOnlyPart's job.
|
||||
// The errorMsg comes from the ReadOnlyPart (usually from its kio job, but not necessarily).
|
||||
// It should probably be used in a KMessageBox
|
||||
// Let's use the statusbar for now
|
||||
m_pKonqFrame->statusbar()->message( errorMsg );
|
||||
m_pKonqFrame->statusbar()->setMessage(errorMsg, KonqStatusBarMessageLabel::Error);
|
||||
m_bAborted = true;
|
||||
slotCompleted();
|
||||
}
|
||||
|
@ -963,6 +969,8 @@ void KonqView::setLockedLocation( bool b )
|
|||
|
||||
void KonqView::aboutToOpenURL( const KUrl &url, const KParts::OpenUrlArguments &args )
|
||||
{
|
||||
m_bErrorURL = url.protocol() == "error";
|
||||
|
||||
KParts::OpenUrlEvent ev( m_pPart, url, args );
|
||||
QApplication::sendEvent( m_pMainWindow, &ev );
|
||||
|
||||
|
@ -1385,4 +1393,15 @@ bool KonqView::isModified() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void KonqView::setFocus()
|
||||
{
|
||||
if (m_pPart && m_pPart->widget() && !isErrorUrl())
|
||||
m_pPart->widget()->setFocus();
|
||||
}
|
||||
|
||||
bool KonqView::isErrorUrl() const
|
||||
{
|
||||
return m_bErrorURL;
|
||||
}
|
||||
|
||||
#include "konqview.moc"
|
||||
|
|
|
@ -371,6 +371,18 @@ public:
|
|||
// overload for the QString version
|
||||
void setLocationBarURL( const KUrl& locationBarURL );
|
||||
|
||||
/**
|
||||
* Gives focus to the part's widget, after we just opened a URL in this part.
|
||||
* Does nothing on error:/ urls, so that the user can fix the wrong URL more easily.
|
||||
*/
|
||||
void setFocus();
|
||||
|
||||
/**
|
||||
* Returns true if this page is showing an error page, from an error: URL.
|
||||
* url() will still return the original URL, so it can't be used for this purpose.
|
||||
*/
|
||||
bool isErrorUrl() const;
|
||||
|
||||
/**
|
||||
* Saves config in a KConfigGroup
|
||||
*/
|
||||
|
@ -525,6 +537,7 @@ private:
|
|||
uint m_bURLDropHandling:1;
|
||||
uint m_bHierarchicalView:1;
|
||||
uint m_bDisableScrolling:1;
|
||||
uint m_bErrorURL:1;
|
||||
KService::List m_partServiceOffers;
|
||||
KService::List m_appServiceOffers;
|
||||
KService::Ptr m_service;
|
||||
|
|
|
@ -1044,15 +1044,24 @@ void KonqViewManager::doSetActivePart( KParts::ReadOnlyPart *part )
|
|||
return;
|
||||
}
|
||||
|
||||
if (m_pMainWindow && m_pMainWindow->currentView())
|
||||
// ## is this the right currentView() already?
|
||||
if (m_pMainWindow->currentView())
|
||||
m_pMainWindow->currentView()->setLocationBarURL(m_pMainWindow->locationBarURL());
|
||||
|
||||
KParts::PartManager::setActivePart( part );
|
||||
|
||||
if (part && part->widget())
|
||||
// Giving focus to the part widget will trigger PartManager which will call KonqViewManager::setActivePart
|
||||
if (part && part->widget()) {
|
||||
part->widget()->setFocus();
|
||||
|
||||
emitActivePartChanged();
|
||||
// However in case of an error URL we want to make it possible for the user to fix it
|
||||
KonqView* view = m_pMainWindow->viewMap().value(part);
|
||||
if (view && view->isErrorUrl()) {
|
||||
m_pMainWindow->focusLocationBar();
|
||||
}
|
||||
}
|
||||
|
||||
emitActivePartChanged(); // This is what triggers KonqMainWindow::slotPartActivated
|
||||
}
|
||||
|
||||
void KonqViewManager::slotActivePartChanged ( KParts::Part *newPart )
|
||||
|
|
Loading…
Reference in a new issue