mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
dolphin: use the recursive listing feature of KDirLister
the bits for symlinks will be moved to KIO::ListJob to make applications like kfind and gwenview also list directory links Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
0883607c14
commit
bb5e46748b
2 changed files with 14 additions and 42 deletions
|
@ -36,8 +36,7 @@ FileNameSearchProtocol::FileNameSearchProtocol( const QByteArray &app ) :
|
|||
SlaveBase("search", app),
|
||||
m_checkContent(""),
|
||||
m_checkType(""),
|
||||
m_regExp(0),
|
||||
m_iteratedDirs()
|
||||
m_regExp(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -50,6 +49,15 @@ void FileNameSearchProtocol::listDir(const KUrl& url)
|
|||
{
|
||||
cleanup();
|
||||
|
||||
const KUrl directory = KUrl(url.queryItemValue("url"));
|
||||
// Don't try to iterate the pseudo filesystem directories of Linux
|
||||
if (directory.path() == QLatin1String("/dev")
|
||||
|| directory.path() == QLatin1String("/proc")
|
||||
|| directory.path() == QLatin1String("/sys")) {
|
||||
finished();
|
||||
return;
|
||||
}
|
||||
|
||||
m_checkContent = url.queryItemValue("checkContent");
|
||||
|
||||
m_literal = url.queryItemValue("literal");
|
||||
|
@ -66,22 +74,6 @@ void FileNameSearchProtocol::listDir(const KUrl& url)
|
|||
m_regExp = new QRegExp(search, Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
const QString urlString = url.queryItemValue("url");
|
||||
searchDirectory(KUrl(urlString));
|
||||
|
||||
cleanup();
|
||||
finished();
|
||||
}
|
||||
|
||||
void FileNameSearchProtocol::searchDirectory(const KUrl& directory)
|
||||
{
|
||||
// Don't try to iterate the pseudo filesystem directories of Linux
|
||||
if (directory.path() == QLatin1String("/dev")
|
||||
|| directory.path() == QLatin1String("/proc")
|
||||
|| directory.path() == QLatin1String("/sys")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all items of the directory
|
||||
KDirLister *dirLister = new KDirLister();
|
||||
dirLister->setAutoUpdate(false);
|
||||
|
@ -90,7 +82,7 @@ void FileNameSearchProtocol::searchDirectory(const KUrl& directory)
|
|||
QEventLoop eventLoop;
|
||||
QObject::connect(dirLister, SIGNAL(canceled()), &eventLoop, SLOT(quit()));
|
||||
QObject::connect(dirLister, SIGNAL(completed()), &eventLoop, SLOT(quit()));
|
||||
dirLister->openUrl(directory);
|
||||
dirLister->openUrl(directory, true);
|
||||
eventLoop.exec();
|
||||
|
||||
// Visualize all items that match the search pattern
|
||||
|
@ -116,35 +108,19 @@ void FileNameSearchProtocol::searchDirectory(const KUrl& directory)
|
|||
|
||||
if (addItem) {
|
||||
KIO::UDSEntry entry = item.entry();
|
||||
entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, item.url().fileName());
|
||||
entry.insert(KIO::UDSEntry::UDS_URL, item.url().url());
|
||||
entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, item.mimetype());
|
||||
listEntry(entry, false);
|
||||
}
|
||||
|
||||
if (item.isDir()) {
|
||||
if (item.isLink()) {
|
||||
// Assure that no endless searching is done in directories that
|
||||
// have already been iterated.
|
||||
const KUrl linkDest(item.url(), item.linkDest());
|
||||
if (!m_iteratedDirs.contains(linkDest.path())) {
|
||||
pendingDirs.append(linkDest);
|
||||
}
|
||||
} else {
|
||||
pendingDirs.append(item.url());
|
||||
}
|
||||
}
|
||||
}
|
||||
listEntry(KIO::UDSEntry(), true);
|
||||
|
||||
m_iteratedDirs.insert(directory.path());
|
||||
|
||||
delete dirLister;
|
||||
dirLister = 0;
|
||||
|
||||
// Recursively iterate all sub directories
|
||||
foreach (const KUrl& pendingDir, pendingDirs) {
|
||||
searchDirectory(pendingDir);
|
||||
}
|
||||
cleanup();
|
||||
finished();
|
||||
}
|
||||
|
||||
bool FileNameSearchProtocol::contentContainsPattern(const KUrl& fileName) const
|
||||
|
@ -191,7 +167,6 @@ void FileNameSearchProtocol::cleanup()
|
|||
{
|
||||
delete m_regExp;
|
||||
m_regExp = 0;
|
||||
m_iteratedDirs.clear();
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
|
|
|
@ -45,8 +45,6 @@ public:
|
|||
void listDir(const KUrl &url) final;
|
||||
|
||||
private:
|
||||
void searchDirectory(const KUrl &directory);
|
||||
|
||||
/**
|
||||
* @return True, if the pattern m_searchPattern is part of
|
||||
* the file \a fileName.
|
||||
|
@ -59,7 +57,6 @@ private:
|
|||
QString m_literal;
|
||||
QString m_checkType;
|
||||
QRegExp* m_regExp;
|
||||
QSet<QString> m_iteratedDirs;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue