[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/apps/konqueror/src
From:       David Faure <faure () kde ! org>
Date:       2010-08-30 8:58:41
Message-ID: 20100830085841.E56B7AC857 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1169903 by dfaure:

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.


 M  +17 -88    konqmainwindow.cpp  
 M  +0 -6      konqmainwindow.h  
 M  +16 -11    konqmisc.cpp  
 M  +4 -4      konqmisc.h  
 M  +5 -4      konqtabs.cpp  
 M  +21 -2     konqview.cpp  
 M  +13 -0     konqview.h  
 M  +12 -3     konqviewmanager.cpp  


--- trunk/KDE/kdebase/apps/konqueror/src/konqmainwindow.cpp #1169902:1169903
@@ -482,13 +482,11 @@
 
     // #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)  {
     KonqOpenURLRequest req( _url );
@@ -513,20 +511,18 @@
     QString mimeType(_mimeType);
     KonqOpenURLRequest req(_req);
 
-  if ( url.url() == "about:blank" )
-  {
+    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";
   }
-  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;
-  }
 
   QString nameFilter = detectNameFilter( url );
   if ( !nameFilter.isEmpty() )
@@ -1450,74 +1446,6 @@
       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::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 @@
     }
   }
 
-    //kDebug() << "New current view" << newView;
+    kDebug() << "New current view" << newView;
   m_currentView = newView;
     if (!part) {
       //kDebug() << "No part activated - returning";
@@ -2332,6 +2260,7 @@
     //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;
--- trunk/KDE/kdebase/apps/konqueror/src/konqmainwindow.h #1169902:1169903
@@ -498,12 +498,6 @@
 
   void slotOpenURL( const KUrl& );
 
-#if 0
-  void slotToolFind();
-  void slotFindOpen( KonqDirPart * dirPart );
-  void slotFindClosed( KonqDirPart * dirPart );
-#endif
-
   void slotIconsChanged();
 
   virtual bool event( QEvent* );
--- trunk/KDE/kdebase/apps/konqueror/src/konqmisc.cpp #1169902:1169903
@@ -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,8 +196,9 @@
   return mainwindow;
 }
 
-QString KonqMisc::konqFilteredURL( QWidget* parent, const QString& _url, const \
QString& _path ) +KUrl KonqMisc::konqFilteredURL(KonqMainWindow* parent, const \
QString& _url, const QString& _path)  {
+  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,20 +212,24 @@
 
     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()
 {
--- trunk/KDE/kdebase/apps/konqueror/src/konqmisc.h #1169902:1169903
@@ -85,13 +85,13 @@
     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
--- trunk/KDE/kdebase/apps/konqueror/src/konqtabs.cpp #1169902:1169903
@@ -365,13 +365,14 @@
 
 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 @@
     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) {
--- trunk/KDE/kdebase/apps/konqueror/src/konqview.cpp #1169902:1169903
@@ -101,6 +101,7 @@
   m_bFollowActive = false;
   m_bBuiltinView = false;
   m_bURLDropHandling = false;
+  m_bErrorURL = false;
 
   switchView( viewFactory );
 }
@@ -133,6 +134,7 @@
                         const QString & nameFilter, bool tempFile )
 {
     kDebug() << "url=" << url << "locationBarURL=" << locationBarURL;
+
   setPartMimeType();
 
   KParts::OpenUrlArguments args;
@@ -172,7 +174,11 @@
   if ( m_bDisableScrolling )
     callExtensionMethod( "disableScrolling" );
 
+  // 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::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::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 @@
     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"
--- trunk/KDE/kdebase/apps/konqueror/src/konqview.h #1169902:1169903
@@ -372,6 +372,18 @@
   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
    */
   void saveConfig( KConfigGroup& config, const QString &prefix, const \
KonqFrameBase::Options &options); @@ -525,6 +537,7 @@
   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;
--- trunk/KDE/kdebase/apps/konqueror/src/konqviewmanager.cpp #1169902:1169903
@@ -1044,17 +1044,26 @@
       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 )
 {
     //kDebug() << newPart;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic