[PATCH] listdir for NetAccess

Tobias Koenig tokoe at kde.org
Tue Sep 17 10:42:17 BST 2002


On Tue, Sep 17, 2002 at 09:02:05AM +0200, Simon Hausmann wrote:
> On Tue, Sep 17, 2002 at 03:07:52AM +0200, Tobias Koenig wrote:
Hi Simon,

> > can I commit the attached patch to CVS HEAD?
> > I don't no if it break BC, since I've changed the constructor and
> > destructor.
> 
> I can't comment on the validity of the patch because I'm a
> NetAccess-Hater(tm) :) . Only two minor comments:
> 
> 1) It looks binary compatible :-)
Fine :)

> 2) Can you change listdir to listDir, to be consistent with
>    KIO::listDir?
Ok, new patch attached

Ciao,
Tobias
-- 
In a world without walls and fences who
needs Windows and Gates???
-------------- next part --------------
? netaccess.diff
Index: global.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/global.cpp,v
retrieving revision 1.100
diff -u -b -p -r1.100 global.cpp
--- global.cpp	2002/08/31 20:07:22	1.100
+++ global.cpp	2002/09/17 09:42:52
@@ -1830,3 +1830,41 @@ QString KIO::getCacheControlString(KIO::
     kdFatal() << "unrecognized Cache control enum value:"<<cacheControl<<endl;
     return QString::null;
 }
+
+QStringList KIO::convertUDSEntryListToFileNames( const UDSEntryList & list )
+{
+  QStringList retval;
+
+  UDSEntryListConstIterator it;
+  for ( it = list.begin(); it != list.end(); ++it )
+  {
+    QValueList<UDSAtom>::ConstIterator iter;
+    QString url, mimeType;
+    bool isDirectory = false;
+    for ( iter = (*it).begin(); iter != (*it).end(); ++iter )
+    {
+      if ( (*iter).m_uds == UDS_FILE_TYPE )
+        isDirectory = S_ISDIR( (mode_t)( (*iter).m_long) );
+
+      if ( (*iter).m_uds == UDS_MIME_TYPE )
+        mimeType = (*iter).m_str;
+
+      if ( (*iter).m_uds == UDS_NAME )
+        url = (*iter).m_str;
+    }
+
+    if ( !mimeType.isEmpty() ) {
+      if ( mimeType.contains( "inode/directory" ) )
+        isDirectory = true;
+      else
+        isDirectory = false;
+    }
+
+    if ( isDirectory )
+      url += "/";
+
+    retval.append( url );
+  }
+
+  return retval;
+}
Index: global.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/global.h,v
retrieving revision 1.53
diff -u -b -p -r1.53 global.h
--- global.h	2002/08/22 18:32:08	1.53
+++ global.h	2002/09/17 09:42:53
@@ -315,6 +315,17 @@ typedef QValueList<UDSEntry> UDSEntryLis
 typedef QValueListIterator<UDSEntry> UDSEntryListIterator;
 typedef QValueListConstIterator<UDSEntry> UDSEntryListConstIterator;
 
+
+  /**
+   * Converts a list of UDSEntries like it is returned by @ref listdir to
+   * a list of file names.
+   *
+   * @param list The list of UDSEntries.
+   * @return The list of file names.
+   */
+  QStringList convertUDSEntryListToFileNames( const UDSEntryList & list );
+
+
 class MetaData : public QMap<QString, QString>
 {
 public:
Index: netaccess.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/netaccess.cpp,v
retrieving revision 1.38
diff -u -b -p -r1.38 netaccess.cpp
--- netaccess.cpp	2002/06/19 17:46:02	1.38
+++ netaccess.cpp	2002/09/17 09:42:54
@@ -21,6 +21,8 @@
     Boston, MA 02111-1307, USA.
 */
 
+#include <sys/stat.h>
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <signal.h>
@@ -44,6 +46,23 @@ using namespace KIO;
 
 QString * NetAccess::lastErrorMsg = 0L;
 
+class KIO::NetAccessPrivate
+{
+public:
+  UDSEntryList m_entryList;
+};
+
+NetAccess::NetAccess()
+  : d( new NetAccessPrivate )
+{
+}
+
+NetAccess::~NetAccess()
+{
+  delete d;
+  d = 0;
+}
+
 bool NetAccess::download(const KURL& u, QString & target)
 {
   if (u.isLocalFile()) {
@@ -120,6 +139,16 @@ bool NetAccess::stat( const KURL & url, 
   return ret;
 }
 
+bool NetAccess::listDir( const KURL & url, KIO::UDSEntryList & list,
+                         bool showProgressInfo, bool includeHidden )
+{
+  NetAccess kioNet;
+  bool ret = kioNet.listDirInternal( url, showProgressInfo, includeHidden );
+  if (ret)
+    list = kioNet.d->m_entryList;
+  return ret;
+}
+
 bool NetAccess::del( const KURL & url )
 {
   NetAccess kioNet;
@@ -180,6 +209,19 @@ bool NetAccess::statInternal( const KURL
   return bJobOK;
 }
 
+bool NetAccess::listDirInternal( const KURL & url, bool progress, bool hidden )
+{
+  bJobOK = true; // success unless further error occurs
+  KIO::Job * job = KIO::listDir( url, progress, hidden );
+  connect( job, SIGNAL( result (KIO::Job *) ),
+           this, SLOT( slotResult (KIO::Job *) ) );
+  connect( job, SIGNAL( entries (KIO::Job *, const KIO::UDSEntryList &) ), this,
+           SLOT( slotListEntries (KIO::Job *, const KIO::UDSEntryList &) ) );
+
+  enter_loop();
+  return bJobOK;
+}
+
 bool NetAccess::delInternal( const KURL & url )
 {
   bJobOK = true; // success unless further error occurs
@@ -242,7 +284,13 @@ void NetAccess::slotResult( KIO::Job * j
   }
   if ( job->isA("KIO::StatJob") )
     m_entry = static_cast<KIO::StatJob *>(job)->statResult();
+
   qApp->exit_loop();
+}
+
+void NetAccess::slotListEntries( KIO::Job *, const KIO::UDSEntryList & list )
+{
+  d->m_entryList = list;
 }
 
 #include "netaccess.moc"
Index: netaccess.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/netaccess.h,v
retrieving revision 1.44
diff -u -b -p -r1.44 netaccess.h
--- netaccess.h	2002/08/02 08:35:38	1.44
+++ netaccess.h	2002/09/17 09:42:54
@@ -163,6 +163,16 @@ public:
     static bool stat(const KURL& url, KIO::UDSEntry & entry);
 
     /**
+     * List the content of a directory.
+     *
+     * @param url The URL of the directory.
+     * @param entry The result of the dirlist. Iterate over the list
+     * of to get hold of the names of file.
+     */
+    static bool listDir( const KURL& url, KIO::UDSEntryList & list,
+                         bool showProgressInfo = true, bool includeHidden = true );
+
+    /**
      * Deletes a file or a directory in an synchronous way.
      *
      * This is a convenience function for @ref KIO::del
@@ -209,17 +219,18 @@ private:
     /**
      * Private constructor
      */
-    NetAccess() {}
+    NetAccess();
     /**
      * Private destructor
      */
-    ~NetAccess() {}
+    ~NetAccess();
     /**
      * Internal methods
      */
     bool copyInternal(const KURL& src, const KURL& target, bool overwrite);
     bool dircopyInternal(const KURL& src, const KURL& target);
     bool statInternal(const KURL & url);
+    bool listDirInternal(const KURL& url, bool progress, bool hidden);
     UDSEntry m_entry;
     bool delInternal(const KURL & url);
     bool mkdirInternal(const KURL & url, int permissions);
@@ -241,6 +252,8 @@ private:
 private slots:
     void slotResult( KIO::Job * job );
     void slotMimetype( KIO::Job * job, const QString & type );
+    void slotListEntries( KIO::Job * job, const KIO::UDSEntryList & list );
+
 private:
     class NetAccessPrivate* d;
 };


More information about the kde-core-devel mailing list