listdir in NetAccess

Tobias Koenig tokoe at kde.org
Sun Sep 15 16:19:11 BST 2002


Hi,

I want to implement a listdir method for NetAccess but have a problem
with KIO::listDir().
I've attached my trials and the problematic code part is in
NetAccess:slotResult(). How can I get the UDSEntryList of the listDir job
here?

Thanks in advance

Ciao,
Tobias
-- 
In a world without walls and fences who
needs Windows and Gates???
-------------- next part --------------
? netaccess.diff
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/15 15:17:14
@@ -44,6 +44,12 @@ using namespace KIO;
 
 QString * NetAccess::lastErrorMsg = 0L;
 
+class NetAccess::NetAccessPrivate
+{
+public:
+  UDSEntryList m_entryList;
+};
+
 bool NetAccess::download(const KURL& u, QString & target)
 {
   if (u.isLocalFile()) {
@@ -120,6 +126,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.m_entryList;
+  return ret;
+}
+
 bool NetAccess::del( const KURL & url )
 {
   NetAccess kioNet;
@@ -180,6 +196,16 @@ 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 *) ) );
+  enter_loop();
+  return bJobOK;
+}
+
 bool NetAccess::delInternal( const KURL & url )
 {
   bJobOK = true; // success unless further error occurs
@@ -242,6 +268,13 @@ void NetAccess::slotResult( KIO::Job * j
   }
   if ( job->isA("KIO::StatJob") )
     m_entry = static_cast<KIO::StatJob *>(job)->statResult();
+  if ( job->isA("KIO::ListJob") ) {
+/**
+  How do I get the UDSEntryList here?
+    d->m_entry = static_cast<KIO::ListJob *>(job)->???();
+*/
+  }
+
   qApp->exit_loop();
 }
 
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/15 15:17:15
@@ -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() : d( new NetAccessPrivate ) {}
     /**
      * Private destructor
      */
-    ~NetAccess() {}
+    ~NetAccess() { delete d; d = 0; }
     /**
      * 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);


More information about the kde-core-devel mailing list