"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/threadedlister.cpp" between
krename-4.0.9.tar.gz and krename-4.90.90.tar.gz

About: KRename is a batch file-renamer (KDE).

threadedlister.cpp  (krename-4.0.9):threadedlister.cpp  (krename-4.90.90)
skipping to change at line 26 skipping to change at line 26
* * * *
***************************************************************************/ ***************************************************************************/
#include "threadedlister.h" #include "threadedlister.h"
#include "krenamemodel.h" #include "krenamemodel.h"
#include <kio/job.h> #include <kio/job.h>
#include <kio/jobclasses.h> #include <kio/jobclasses.h>
#include <kapplication.h>
#include <QMutex> #include <QMutex>
#include <QRegExp> #include <QRegExp>
QMutex ThreadedLister::s_mutex; QMutex ThreadedLister::s_mutex;
ThreadedLister::ThreadedLister( const KUrl & dirname, QWidget* cache, KRenameMod ThreadedLister::ThreadedLister(const QUrl &dirname, QWidget *cache, KRenameModel
el* model ) *model)
: QObject( NULL ), m_dirname( dirname ), m_cache( cache ), m_model( model ) : QObject(nullptr), m_dirname(dirname), m_cache(cache), m_model(model)
{ {
m_listHiddenFiles = false; m_listHiddenFiles = false;
m_listRecursive = false; m_listRecursive = false;
m_listDirnamesOnly = false; m_listDirnamesOnly = false;
m_listDirnames = false; m_listDirnames = false;
m_eSplitMode = m_model->splitMode(); m_eSplitMode = m_model->splitMode();
m_dot = m_model->splitDot(); m_dot = m_model->splitDot();
qRegisterMetaType<KFileItemList>("KFileItemList"); qRegisterMetaType<KFileItemList>("KFileItemList");
} }
ThreadedLister::~ThreadedLister() ThreadedLister::~ThreadedLister()
{ {
} }
void ThreadedLister::run() void ThreadedLister::run()
{ {
s_mutex.lock(); s_mutex.lock();
if( m_listDirnames || m_listDirnamesOnly ) if (m_listDirnames || m_listDirnamesOnly) {
{
QString name = m_dirname.fileName(); QString name = m_dirname.fileName();
if( !m_listHiddenFiles && !name.startsWith(".") ) if (!m_listHiddenFiles && !name.startsWith(QLatin1Char('.'))) {
{
KRenameFile::List list; KRenameFile::List list;
list.append( KRenameFile( m_dirname, true, m_eSplitMode, m_dot ) ); list.append(KRenameFile(m_dirname, true, m_eSplitMode, m_dot));
m_model->addFiles( list ); m_model->addFiles(list);
} }
} }
s_mutex.unlock(); s_mutex.unlock();
KIO::ListJob* job = NULL; // Will delete itself automatically KIO::ListJob *job = nullptr; // Will delete itself automatically
KIO::JobFlags flags = KIO::HideProgressInfo; KIO::JobFlags flags = KIO::HideProgressInfo;
if( m_listRecursive ) if (m_listRecursive) {
job = KIO::listRecursive( m_dirname, flags, m_listHiddenFiles ); job = KIO::listRecursive(m_dirname, flags, m_listHiddenFiles);
else } else {
job = KIO::listDir( m_dirname, flags, m_listHiddenFiles ); job = KIO::listDir(m_dirname, flags, m_listHiddenFiles);
}
connect( job, SIGNAL(entries( KIO::Job*, const KIO::UDSEntryList & )), SLOT( connect(job, &KIO::ListJob::entries, this, &ThreadedLister::foundItem);
foundItem(KIO::Job*, const KIO::UDSEntryList &))); connect(job, &KIO::ListJob::result, this, &ThreadedLister::completed);
connect( job, SIGNAL(result( KJob* )), SLOT( completed() ) );
job->start(); job->start();
} }
void ThreadedLister::foundItem(KIO::Job*, const KIO::UDSEntryList & list) void ThreadedLister::foundItem(KIO::Job *, const KIO::UDSEntryList &list)
{ {
QString displayName; QString displayName;
QRegExp filter( m_filter ); QRegExp filter(m_filter);
filter.setPatternSyntax( QRegExp::Wildcard ); filter.setPatternSyntax(QRegExp::Wildcard);
m_files.reserve( m_files.count() + list.count() ); m_files.reserve(m_files.count() + list.count());
KIO::UDSEntryList::const_iterator it = list.begin(); KIO::UDSEntryList::const_iterator it = list.begin();
while( it != list.end() ) while (it != list.end()) {
{ displayName = (*it).stringValue(KIO::UDSEntry::UDS_NAME);
displayName = (*it).stringValue( KIO::UDSEntry::UDS_NAME ); if (!filter.isEmpty() && !filter.exactMatch(displayName)) {
if( !filter.isEmpty() && !filter.exactMatch( displayName ) )
{
// does not match filter // does not match filter
// skip it // skip it
++it; ++it;
} } else {
else QUrl url = m_dirname;
{ url = url.adjusted(QUrl::StripTrailingSlash);
KUrl url = m_dirname; url.setPath(url.path() + '/' + (displayName));
url.addPath( displayName ); // displayName is a relative path
if( (m_listDirnames || m_listDirnamesOnly) && (*it).isDir() ) if ((m_listDirnames || m_listDirnamesOnly) && (*it).isDir()) {
{
// Filter out parent and current directory // Filter out parent and current directory
if( displayName != "." && displayName != ".." ) if (displayName != "." && displayName != "..") {
m_files.append( KRenameFile( KFileItem( *it, url ), m_eSplit m_files.append(KRenameFile(KFileItem(*it, url), m_eSplitMode
Mode, m_dot ) ); , m_dot));
} }
else if( !m_listDirnamesOnly && !(*it).isDir() ) } else if (!m_listDirnamesOnly && !(*it).isDir()) {
{ m_files.append(KRenameFile(KFileItem(*it, url), m_eSplitMode, m_
m_files.append( KRenameFile( KFileItem( *it, url), m_eSplitMode, dot));
m_dot ) );
} }
++it; ++it;
} }
} }
} }
void ThreadedLister::completed() void ThreadedLister::completed()
{ {
if( m_files.count() > 0 ) if (m_files.count() > 0) {
{
// We add the files in the completed slot // We add the files in the completed slot
// and not directly in the foundItem slot, // and not directly in the foundItem slot,
// as the latter can produce deadlocks if // as the latter can produce deadlocks if
// we get a signal while we keep the mutex! // we get a signal while we keep the mutex!
//s_mutex.lock(); //s_mutex.lock();
m_model->addFiles( m_files ); m_model->addFiles(m_files);
//s_mutex.unlock(); //s_mutex.unlock();
} }
emit listerDone( this ); emit listerDone(this);
} }
#include "threadedlister.moc"
 End of changes. 20 change blocks. 
46 lines changed or deleted 37 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)