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

List:       kde-commits
Subject:    KDE/kdelibs/kio/kio
From:       Michael Brade <brade () kde ! org>
Date:       2006-03-13 21:15:18
Message-ID: 1142284518.092576.30578.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 518388 by brade:

Port the KDirLister fix for #123034 (commit 516606) to KDE 4:

This commit prevents bad urls from being passed to KDirLister, mainly urls that
do not support listing. It also prevents KDirListerCache from doing redundant
work.

Also updated the error message and removed KDirLister::validURL() completely.
It makes no sense for a KDirLister to check the url, KDirListerCache does the
listing.



 M  +37 -29    kdirlister.cpp  
 M  +0 -7      kdirlister.h  
 M  +3 -2      kdirlister_p.h  


--- trunk/KDE/kdelibs/kio/kio/kdirlister.cpp #518387:518388
@@ -34,6 +34,7 @@
 #include <kglobal.h>
 #include <kglobalsettings.h>
 #include <kstaticdeleter.h>
+#include <kprotocolinfo.h>
 
 #include "kdirlister_p.h"
 
@@ -85,7 +86,7 @@
 
 // setting _reload to true will emit the old files and
 // call updateDirectory
-void KDirListerCache::listDir( KDirLister* lister, const KUrl& _u,
+bool KDirListerCache::listDir( KDirLister *lister, const KUrl& _u,
                                bool _keep, bool _reload )
 {
   // like this we don't have to worry about trailing slashes any further
@@ -94,6 +95,9 @@
   _url.adjustPath(-1);
   QString urlStr = _url.url();
 
+  if ( !validURL( lister, _url ) )
+    return false;
+
 #ifdef DEBUG_CACHE
   printDebug();
 #endif
@@ -271,8 +275,35 @@
   // automatic updating of directories
   if ( lister->d->autoUpdate )
     itemU->incAutoUpdate();
+
+  return true;
 }
 
+bool KDirListerCache::validURL( const KDirLister *lister, const KUrl& url ) const
+{
+  if ( !url.isValid() )
+  {
+    if ( lister->d->autoErrorHandling )
+    {
+      QString tmp = i18n("Malformed URL\n%1").arg( url.prettyURL() );
+      KMessageBox::error( lister->d->errorParent, tmp );
+    }
+    return false;
+  }
+
+  if ( !KProtocolInfo::supportsListing( url ) )
+  {
+    if ( lister->d->autoErrorHandling )
+    {
+      QString tmp = i18n("URL cannot be listed\n%1").arg( url.prettyURL() );
+      KMessageBox::error( lister->d->errorParent, tmp );
+    }
+    return false;
+  }
+
+  return true;
+}
+
 void KDirListerCache::stop( KDirLister *lister )
 {
 #ifdef DEBUG_CACHE
@@ -1033,15 +1064,15 @@
   KUrl oldUrl = job->url();  // here we really need the old url!
   KUrl newUrl = url;
 
+  // strip trailing slashes
+  oldUrl.adjustPath(-1);
+  newUrl.adjustPath(-1);
+
   if ( oldUrl == newUrl ) 
   {
     kDebug(7004) << k_funcinfo << "New redirection url same as old, giving up." << endl;
-    killJob(job);
     return;
   }
-  // strip trailing slashes
-  oldUrl.adjustPath(-1);
-  newUrl.adjustPath(-1);
 
   kDebug(7004) << k_funcinfo << oldUrl.prettyURL() << " -> " << newUrl.prettyURL() << endl;
 
@@ -1816,9 +1847,6 @@
 
 bool KDirLister::openURL( const KUrl& _url, bool _keep, bool _reload )
 {
-  if ( !validURL( _url ) )
-    return false;
-
   kDebug(7003) << k_funcinfo << _url.prettyURL()
                 << " keep=" << _keep << " reload=" << _reload << endl;
 
@@ -1828,9 +1856,7 @@
 
   d->changes = NONE;
 
-  s_pCache->listDir( this, _url, _keep, _reload );
-
-  return true;
+  return s_pCache->listDir( this, _url, _keep, _reload );
 }
 
 void KDirLister::stop()
@@ -2170,24 +2196,6 @@
   return true;
 }
 
-
-bool KDirLister::validURL( const KUrl& _url ) const
-{
-  if ( !_url.isValid() )
-  {
-    if ( d->autoErrorHandling )
-    {
-      QString tmp = i18n("Malformed URL\n%1").arg( _url.prettyURL() );
-      KMessageBox::error( d->errorParent, tmp );
-    }
-    return false;
-  }
-
-  // TODO: verify that this is really a directory?
-
-  return true;
-}
-
 void KDirLister::handleError( KIO::Job *job )
 {
   if ( d->autoErrorHandling )
--- trunk/KDE/kdelibs/kio/kio/kdirlister.h #518387:518388
@@ -583,13 +583,6 @@
    */
   bool doMimeExcludeFilter( const QString& mimeExclude, const QStringList& filters ) const;
 
-  /**
-   * Checks if an url is malformed or not and displays an error message
-   * if it is and autoErrorHandling is set to true.
-   * @return true if url is valid, otherwise false.
-   */
-  virtual bool validURL( const KUrl& ) const;
-
   /** Reimplement to customize error handling */
   virtual void handleError( KIO::Job * );
 
--- trunk/KDE/kdelibs/kio/kio/kdirlister_p.h #518387:518388
@@ -167,8 +167,9 @@
 protected:
   KDirListerCache( int maxCount = 10 );
 
-  void listDir( KDirLister *lister, const KUrl &_url, bool _keep, bool _reload );
-
+  bool listDir( KDirLister *lister, const KUrl& _url, bool _keep, bool _reload );
+  bool validURL( const KDirLister *lister, const KUrl& _url ) const;
+ 
   // stop all running jobs for lister
   void stop( KDirLister *lister );
   // stop just the job listing url for lister
[prev in list] [next in list] [prev in thread] [next in thread] 

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