[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: Listing files in directory
From: Joachim Eibl <joachim.eibl () gmx ! de>
Date: 2004-02-05 21:02:16
Message-ID: 200402052202.16254.joachim.eibl () gmx ! de
[Download RAW message or body]
Hi,
I had quite a similar problem while programming KDiff3.
For KDiff3 I wanted to put all file-access stuff into an own class and didn't
want to care about KIO-specialities.
I've called the resulting class FileAccess and it contains the most needed
functions from KIO::NetAccess, QFileInfo, KIO-Jobs, QDir and KURL in one
class, and you can show a progressbar if you want to, but that's a bit
experimental.
If you are interested, here is a short description of how to use it in your
program:
1. Check out
kdeextragear-1/kdiff3/src/fileaccess.cpp
kdeextragear-1/kdiff3/src/fileaccess.h
and add them to your project. (Allow that moc runs over fileaccess.h)
2. During startup: Create one instance of ProgressDialog and assign it to the
global variable g_pProgressDialog. e.g:
g_pProgressDialog = new ProgressDialog( pYourParentWidget )
This is necessary, even if you never show it. If you show() it, then every
operation is abortable too!
3. In your program, create an instance of the class FileAccess, with your
directory-path or url (local or remote) as parameter during construction:
e.g.: FileAccess myDir( "/home" );
4. Use FileAccess::listDir() which allows you to specify many params:
bool listDir( t_DirectoryList* pDirList, bool bRecursive, bool bFindHidden,
const QString& filePattern, const QString& fileAntiPattern,
const QString& dirAntiPattern, bool bFollowDirLinks,
bool bUseCvsIgnore );
e.g.:
t_DirectoryList dirList;
myDir.listDir( &dirList, true, true, "*", "", "", false, false );
Note that you don't need to connect to any slots of your program to achieve
abortability.
5. Because t_DirectoryList is a list of FileAccess-Items with
this declaration ...
class t_DirectoryList : public std::list<FileAccess> { };
... get all items, by traversing the result-list. e.g.:
t_DirectoryList::iterator i;
for(i=dirList.begin(); i!=dirList.end(); ++i)
{
FileAccess& f=*i;
std::cout << f.absFilePath().ascii() << std::endl;
}
Have a look at the other methods in class FileAccess.
I think it might eventually be put into some library, but for this it still
would need some fine-tuning (and documentation).
Please drop me a line, if this was helpful.
Joachim
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic