[PATCH] listdir for NetAccess
Tobias Koenig
tokoe at kde.org
Tue Sep 17 02:07:52 BST 2002
Hi,
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.
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/17 01:07:09
@@ -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,51 @@ 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;
+}
+
+QStringList NetAccess::UDSEntryListToFileNames( 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;
}
#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 01:07:10
@@ -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
@@ -205,21 +215,31 @@ public:
*/
static QString lastErrorString() { return lastErrorMsg ? *lastErrorMsg : QString::null; }
+ /**
+ * 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.
+ */
+ static QStringList UDSEntryListToFileNames( const UDSEntryList & list );
+
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 +261,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