Commit 36da69b6 authored by Michael Reeves's avatar Michael Reeves

Refactor FileAccess

Begin de-coupling FileAccessJobHandler from FileAccess.
Shift some generic dueties to FileAccess.
parent 8d3441b5
......@@ -22,7 +22,8 @@
#include <QString>
#include <QStringList>
#include <QHash>
#include <QRegExp>
#include <KLocalizedString>
/* Split the command line into arguments.
......@@ -99,4 +100,26 @@ QString Utils::getArguments(QString cmd, QString& program, QStringList& args)
args.pop_front();
}
return QString();
}
bool Utils::wildcardMultiMatch(const QString& wildcard, const QString& testString, bool bCaseSensitive)
{
static QHash<QString, QRegExp> s_patternMap;
QStringList sl = wildcard.split(";");
for(QStringList::Iterator it = sl.begin(); it != sl.end(); ++it)
{
QHash<QString, QRegExp>::iterator patIt = s_patternMap.find(*it);
if(patIt == s_patternMap.end())
{
QRegExp pattern(*it, bCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard);
patIt = s_patternMap.insert(*it, pattern);
}
if(patIt.value().exactMatch(testString))
return true;
}
return false;
}
\ No newline at end of file
......@@ -26,7 +26,8 @@
class Utils{
public:
static QString getArguments(QString cmd, QString& program, QStringList& args);
static bool wildcardMultiMatch(const QString& wildcard, const QString& testString, bool bCaseSensitive);
static QString getArguments(QString cmd, QString& program, QStringList& args);
};
#endif
\ No newline at end of file
......@@ -15,6 +15,7 @@
#include "guiutils.h"
#include "options.h"
#include "progress.h"
#include "Utils.h"
#include <algorithm>
#include <map>
......@@ -3519,7 +3520,7 @@ void DirectoryMergeWindow::updateFileVisibilities()
(bShowIdentical && bExistsEverywhere && pMFI->m_bEqualAB && (pMFI->m_bEqualAC || !bThreeDirs)) || ((bShowDifferent || bDir) && existCount >= 2 && (!pMFI->m_bEqualAB || !(pMFI->m_bEqualAC || !bThreeDirs))) || (bShowOnlyInA && pMFI->existsInA() && !pMFI->existsInB() && !pMFI->existsInC()) || (bShowOnlyInB && !pMFI->existsInA() && pMFI->existsInB() && !pMFI->existsInC()) || (bShowOnlyInC && !pMFI->existsInA() && !pMFI->existsInB() && pMFI->existsInC());
QString fileName = pMFI->fileName();
bVisible = bVisible && ((bDir && !wildcardMultiMatch(d->m_pOptions->m_DmDirAntiPattern, fileName, d->m_bCaseSensitive)) || (wildcardMultiMatch(d->m_pOptions->m_DmFilePattern, fileName, d->m_bCaseSensitive) && !wildcardMultiMatch(d->m_pOptions->m_DmFileAntiPattern, fileName, d->m_bCaseSensitive)));
bVisible = bVisible && ((bDir && !Utils::wildcardMultiMatch(d->m_pOptions->m_DmDirAntiPattern, fileName, d->m_bCaseSensitive)) || (Utils::wildcardMultiMatch(d->m_pOptions->m_DmFilePattern, fileName, d->m_bCaseSensitive) && !Utils::wildcardMultiMatch(d->m_pOptions->m_DmFileAntiPattern, fileName, d->m_bCaseSensitive)));
setRowHidden(mi.row(), mi.parent(), !bVisible);
......
......@@ -11,6 +11,7 @@
#include "cvsignorelist.h"
#include "common.h"
#include "progress.h"
#include "Utils.h"
#include <QDir>
#include <QProcess>
......@@ -721,6 +722,52 @@ bool FileAccess::createBackup(const QString& bakExtension)
return true;
}
void FileAccess::doError(void)
{
m_bExists = false;
}
void FileAccess::filterList(t_DirectoryList *pDirList, const QString& filePattern,
const QString& fileAntiPattern, const QString& dirAntiPattern,
const bool bUseCvsIgnore)
{
CvsIgnoreList cvsIgnoreList;
if(bUseCvsIgnore)
{
cvsIgnoreList.init(*this, pDirList);
}
//TODO: Ask os for this information don't hard code it.
#if defined(Q_OS_WIN)
bool bCaseSensitive = false;
#else
bool bCaseSensitive = true;
#endif
// Now remove all entries that should be ignored:
t_DirectoryList::iterator i;
for(i = pDirList->begin(); i != pDirList->end();)
{
t_DirectoryList::iterator i2 = i;
++i2;
QString fn = i->fileName();
if( (i->isFile() &&
(!Utils::wildcardMultiMatch(filePattern, fn, bCaseSensitive) ||
Utils::wildcardMultiMatch(fileAntiPattern, fn, bCaseSensitive))) ||
(i->isDir() && Utils::wildcardMultiMatch(dirAntiPattern, fn, bCaseSensitive)) ||
(bUseCvsIgnore && cvsIgnoreList.matches(fn, bCaseSensitive)))
{
// Remove it
pDirList->erase(i);
i = i2;
}
else
{
++i;
}
}
}
FileAccessJobHandler::FileAccessJobHandler(FileAccess* pFileAccess)
{
m_pFileAccess = pFileAccess;
......@@ -747,14 +794,13 @@ void FileAccessJobHandler::slotStatResult(KJob* pJob)
if(pJob->error())
{
//pJob->uiDelegate()->showErrorMessage();
m_pFileAccess->m_bExists = false;
m_pFileAccess->doError();
m_bSuccess = true;
}
else
{
m_bSuccess = true;
m_pFileAccess->m_bValidData = true;
const KIO::UDSEntry e = static_cast<KIO::StatJob*>(pJob)->statResult();
m_pFileAccess->setUdsEntry(e);
......@@ -1001,30 +1047,8 @@ bool FileAccessJobHandler::copyFile(const QString& dest)
// Note that the KIO-slave preserves the original date, if this is supported.
}
bool wildcardMultiMatch(const QString& wildcard, const QString& testString, bool bCaseSensitive)
{
static QHash<QString, QRegExp> s_patternMap;
QStringList sl = wildcard.split(";");
for(QStringList::Iterator it = sl.begin(); it != sl.end(); ++it)
{
QHash<QString, QRegExp>::iterator patIt = s_patternMap.find(*it);
if(patIt == s_patternMap.end())
{
QRegExp pattern(*it, bCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard);
patIt = s_patternMap.insert(*it, pattern);
}
if(patIt.value().exactMatch(testString))
return true;
}
return false;
}
bool FileAccessJobHandler::listDir(t_DirectoryList* pDirList, bool bRecursive, bool bFindHidden, const QString& filePattern,
const QString& fileAntiPattern, const QString& dirAntiPattern, bool bFollowDirLinks, bool bUseCvsIgnore)
const QString& fileAntiPattern, const QString& dirAntiPattern, bool bFollowDirLinks, const bool bUseCvsIgnore)
{
ProgressProxyExtender pp;
m_pDirList = pDirList;
......@@ -1103,45 +1127,11 @@ bool FileAccessJobHandler::listDir(t_DirectoryList* pDirList, bool bRecursive, b
}
}
CvsIgnoreList cvsIgnoreList;
if(bUseCvsIgnore)
{
cvsIgnoreList.init(*m_pFileAccess, pDirList);
}
//TODO: Ask os for this information don't hard code it.
#if defined(Q_OS_WIN)
bool bCaseSensitive = false;
#else
bool bCaseSensitive = true;
#endif
// Now remove all entries that should be ignored:
t_DirectoryList::iterator i;
for(i = pDirList->begin(); i != pDirList->end();)
{
t_DirectoryList::iterator i2 = i;
++i2;
QString fn = i->fileName();
Q_ASSERT(bFindHidden || !i->isHidden());
if((!bFindHidden && i->isHidden()) ||
(i->isFile() &&
(!wildcardMultiMatch(filePattern, fn, bCaseSensitive) ||
wildcardMultiMatch(fileAntiPattern, fn, bCaseSensitive))) ||
(i->isDir() && wildcardMultiMatch(dirAntiPattern, fn, bCaseSensitive)) ||
(bUseCvsIgnore && cvsIgnoreList.matches(fn, bCaseSensitive)))
{
// Remove it
pDirList->erase(i);
i = i2;
}
else
{
++i;
}
}
m_pFileAccess->filterList(pDirList, filePattern, fileAntiPattern, dirAntiPattern, bUseCvsIgnore);
if(bRecursive)
{
t_DirectoryList::iterator i;
t_DirectoryList subDirsList;
for(i = m_pDirList->begin(); i != m_pDirList->end(); ++i)
......@@ -1180,8 +1170,9 @@ void FileAccessJobHandler::slotListDirProcessNewEntries(KIO::Job*, const KIO::UD
if(fa.fileName() != "." && fa.fileName() != "..")
{
fa.m_url = parentUrl;
QUrl url = fa.m_url.adjusted(QUrl::StripTrailingSlash);
fa.m_url.setPath(url.path() + "/" + fa.fileName());
QUrl url = parentUrl.adjusted(QUrl::StripTrailingSlash);
url.setPath(url.path() + "/" + fa.fileName());
fa.setUrl(url);
//fa.m_absoluteFilePath = fa.url().url();
m_pDirList->push_back(fa);
}
......
......@@ -27,8 +27,6 @@ namespace KIO {
class Job;
}
bool wildcardMultiMatch( const QString& wildcard, const QString& testString, bool bCaseSensitive );
class t_DirectoryList;
class FileAccess
......@@ -59,6 +57,7 @@ public:
QString fileRelPath() const; // The path relitive to base comparison directory
QString prettyAbsPath() const;
QUrl url() const;
void setUrl(const QUrl inUrl) { m_url = inUrl; }
QString absoluteFilePath() const;
bool isLocal() const;
......@@ -90,8 +89,14 @@ public:
QString getStatusText();
FileAccess* parent() const; // !=0 for listDir-results, but only valid if the parent was not yet destroyed.
private:
void setUdsEntry( const KIO::UDSEntry& e );
void doError(void);
void filterList(t_DirectoryList* pDirList, const QString& filePattern,
const QString& fileAntiPattern, const QString& dirAntiPattern,
const bool bUseCvsIgnore);
private:
friend class FileAccessJobHandler;
void setUdsEntry(const KIO::UDSEntry& e);
void setFilePrivate( FileAccess* pParent );
void setStatusText( const QString& s );
......@@ -112,18 +117,16 @@ private:
qint64 m_size;
QDateTime m_modificationTime;
bool m_bSymLink : 1;
bool m_bFile : 1;
bool m_bDir : 1;
bool m_bExists : 1;
bool m_bWritable : 1;
bool m_bReadable : 1;
bool m_bExecutable:1;
bool m_bHidden : 1;
bool m_bSymLink;
bool m_bFile;
bool m_bDir;
bool m_bExists;
bool m_bWritable;
bool m_bReadable;
bool m_bExecutable;
bool m_bHidden;
QString m_statusText; // Might contain an error string, when the last operation didn't succeed.
friend class FileAccessJobHandler;
};
class t_DirectoryList : public std::list<FileAccess>
......
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