Put the shorter, simpler body into the if statement

parent b3d6b5f3
...@@ -80,14 +80,24 @@ bool ScanManager::start(const QUrl &url) ...@@ -80,14 +80,24 @@ bool ScanManager::start(const QUrl &url)
m_files = 0; m_files = 0;
m_abort = false; m_abort = false;
if (url.isLocalFile()) { if (!url.isLocalFile()) {
QString path = url.toLocalFile(); QGuiApplication::changeOverrideCursor(QCursor(Qt::BusyCursor));
//will start listing straight away
Filelight::RemoteLister *remoteLister = new Filelight::RemoteLister(url, (QWidget*)parent(), this);
connect(remoteLister, SIGNAL(branchCompleted(Folder*,bool)), this, SLOT(cacheTree(Folder*,bool)), Qt::QueuedConnection);
remoteLister->setParent(this);
remoteLister->setObjectName(QLatin1String( "remote_lister" ));
remoteLister->openUrl(url);
return true;
}
QString path = url.toLocalFile();
if (!path.endsWith(QDir::separator())) path += QDir::separator(); if (!path.endsWith(QDir::separator())) path += QDir::separator();
Chain<Folder> *trees = new Chain<Folder>; Chain<Folder> *trees = new Chain<Folder>;
/* CHECK CACHE /* CHECK CACHE
* user wants: /usr/local/ * user wants: /usr/local/
* cached: /usr/ * cached: /usr/
* *
...@@ -95,92 +105,82 @@ bool ScanManager::start(const QUrl &url) ...@@ -95,92 +105,82 @@ bool ScanManager::start(const QUrl &url)
* cached: /usr/local/, /usr/include/ * cached: /usr/local/, /usr/include/
*/ */
for (Iterator<Folder> it = m_cache->iterator(); it != m_cache->end(); ++it) for (Iterator<Folder> it = m_cache->iterator(); it != m_cache->end(); ++it)
{ {
QString cachePath = (*it)->name(); QString cachePath = (*it)->name();
if (path.startsWith(cachePath)) //then whole tree already scanned if (path.startsWith(cachePath)) //then whole tree already scanned
{ {
//find a pointer to the requested branch //find a pointer to the requested branch
qDebug() << "Cache-(a)hit: " << cachePath; qDebug() << "Cache-(a)hit: " << cachePath;
#if QT_VERSION >= 0x050400 #if QT_VERSION >= 0x050400
QVector<QStringRef> split = path.midRef(cachePath.length()).split(QLatin1Char( '/' )); QVector<QStringRef> split = path.midRef(cachePath.length()).split(QLatin1Char( '/' ));
#else #else
QStringList split = path.mid(cachePath.length()).split(QLatin1Char( '/' )); QStringList split = path.mid(cachePath.length()).split(QLatin1Char( '/' ));
#endif #endif
Folder *d = *it; Folder *d = *it;
Iterator<File> jt; Iterator<File> jt;
while (!split.isEmpty() && d != NULL) //if NULL we have got lost so abort!! while (!split.isEmpty() && d != NULL) //if NULL we have got lost so abort!!
{ {
jt = d->iterator(); jt = d->iterator();
const Link<File> *end = d->end(); const Link<File> *end = d->end();
#if QT_VERSION >= 0x050400 #if QT_VERSION >= 0x050400
if (split.first().isEmpty()) //found the dir if (split.first().isEmpty()) //found the dir
break; break;
QString s = split.first() % QLatin1Char( '/' ); QString s = split.first() % QLatin1Char( '/' );
#else #else
QString s = split.first(); QString s = split.first();
if (s.isEmpty()) //found the dir if (s.isEmpty()) //found the dir
break; break;
s += QLatin1Char( '/' ); s += QLatin1Char( '/' );
#endif #endif
for (d = 0; jt != end; ++jt) for (d = 0; jt != end; ++jt)
if (s == (*jt)->name()) if (s == (*jt)->name())
{ {
d = (Folder*)*jt; d = (Folder*)*jt;
break; break;
} }
split.pop_front(); split.pop_front();
}
if (d)
{
delete trees;
//we found a completed tree, thus no need to scan
qDebug() << "Found cache-handle, generating map..";
emit branchCacheHit(d);
return true;
}
else
{
//something went wrong, we couldn't find the folder we were expecting
qWarning() << "Didn't find " << path << " in the cache!\n";
delete it.remove(); //safest to get rid of it
break; //do a full scan
}
} }
else if (cachePath.startsWith(path)) //then part of the requested tree is already scanned
if (d)
{ {
qDebug() << "Cache-(b)hit: " << cachePath; delete trees;
it.transferTo(*trees);
}
}
QGuiApplication::changeOverrideCursor(QCursor(Qt::BusyCursor)); //we found a completed tree, thus no need to scan
//starts listing by itself qDebug() << "Found cache-handle, generating map..";
m_thread = new Filelight::LocalLister(path, trees, this);
connect(m_thread, SIGNAL(branchCompleted(Folder*,bool)), this, SLOT(cacheTree(Folder*,bool)), Qt::QueuedConnection);
m_thread->start();
return true; emit branchCacheHit(d);
return true;
}
else
{
//something went wrong, we couldn't find the folder we were expecting
qWarning() << "Didn't find " << path << " in the cache!\n";
delete it.remove(); //safest to get rid of it
break; //do a full scan
}
}
else if (cachePath.startsWith(path)) //then part of the requested tree is already scanned
{
qDebug() << "Cache-(b)hit: " << cachePath;
it.transferTo(*trees);
}
} }
QGuiApplication::changeOverrideCursor(QCursor(Qt::BusyCursor)); QGuiApplication::changeOverrideCursor(QCursor(Qt::BusyCursor));
//will start listing straight away //starts listing by itself
Filelight::RemoteLister *remoteLister = new Filelight::RemoteLister(url, (QWidget*)parent(), this); m_thread = new Filelight::LocalLister(path, trees, this);
connect(remoteLister, SIGNAL(branchCompleted(Folder*,bool)), this, SLOT(cacheTree(Folder*,bool)), Qt::QueuedConnection); connect(m_thread, SIGNAL(branchCompleted(Folder*,bool)), this, SLOT(cacheTree(Folder*,bool)), Qt::QueuedConnection);
remoteLister->setParent(this); m_thread->start();
remoteLister->setObjectName(QLatin1String( "remote_lister" ));
remoteLister->openUrl(url);
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment