Commit 2bd1c76e authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Use an enum for trailing slash handling

The previous bool was confusing.
Now the enum clearly says what the code does.
parent bcc22290
......@@ -94,7 +94,7 @@ QStringList TestHelper::getExpectedNewEntryPaths(const QVector<Archive::Entry*>
expectedPaths << destination->fullPath() + entryPath;
if (entryPath.right(1) == QLatin1String("/")) {
const QString workingDirectory = testDataPath + QLatin1Char('/') + entry->fullPath(true);
const QString workingDirectory = testDataPath + QLatin1Char('/') + entry->fullPath(NoTrailingSlash);
QDirIterator it(workingDirectory, QDir::AllEntries | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (it.hasNext()) {
QString path = it.next();
......
......@@ -111,9 +111,9 @@ void Archive::Entry::setFullPath(const QString &fullPath)
m_name = pieces.isEmpty() ? QString() : pieces.last();
}
QString Archive::Entry::fullPath(bool withoutTrailingSlash) const
QString Archive::Entry::fullPath(PathFormat format) const
{
if (withoutTrailingSlash && m_fullPath.endsWith(QLatin1Char('/'))) {
if (format == NoTrailingSlash && m_fullPath.endsWith(QLatin1Char('/'))) {
return m_fullPath.left(m_fullPath.size() - 1);
} else {
return m_fullPath;
......
......@@ -37,6 +37,12 @@
#include <KIconLoader>
namespace Kerfuffle {
enum PathFormat {
NoTrailingSlash,
WithTrailingSlash
};
class Archive::Entry : public QObject
{
Q_OBJECT
......@@ -82,7 +88,7 @@ public:
Entry *getParent() const;
void setParent(Entry *parent);
void setFullPath(const QString &fullPath);
QString fullPath(bool withoutTrailingSlash = false) const;
QString fullPath(PathFormat format = WithTrailingSlash) const;
QString name() const;
void setIsDirectory(const bool isDirectory);
bool isDir() const;
......
......@@ -165,11 +165,11 @@ void ReadOnlyArchiveInterface::setWaitForFinishedSignal(bool value)
m_waitForFinishedSignal = value;
}
QStringList ReadOnlyArchiveInterface::entryFullPaths(const QVector<Archive::Entry*> &entries, const bool withoutTrailingSlashes)
QStringList ReadOnlyArchiveInterface::entryFullPaths(const QVector<Archive::Entry*> &entries, PathFormat format)
{
QStringList filesList;
foreach (const Archive::Entry *file, entries) {
filesList << file->fullPath(withoutTrailingSlashes);
filesList << file->fullPath(format);
}
return filesList;
}
......
......@@ -117,7 +117,7 @@ public:
/**
* Returns the list of filenames retrieved from the list of entries.
*/
static QStringList entryFullPaths(const QVector<Archive::Entry*> &entries, const bool withoutTrailingSlashes = false);
static QStringList entryFullPaths(const QVector<Archive::Entry*> &entries, PathFormat format = WithTrailingSlash);
/**
* Returns the list of the entries, excluding their children.
......
......@@ -200,8 +200,8 @@ bool CliInterface::addFiles(const QVector<Archive::Entry*> &files, const Archive
preservedParent = file->parent();
}
const QString filePath = QDir::currentPath() + QLatin1Char('/') + file->fullPath(true);
const QString newFilePath = absoluteDestinationPath + file->fullPath(true);
const QString filePath = QDir::currentPath() + QLatin1Char('/') + file->fullPath(NoTrailingSlash);
const QString newFilePath = absoluteDestinationPath + file->fullPath(NoTrailingSlash);
if (QFile::link(filePath, newFilePath)) {
qCDebug(ARK) << "Symlink's created:" << filePath << newFilePath;
} else {
......@@ -784,7 +784,7 @@ QStringList CliInterface::substituteAddVariables(const QStringList &addArgs, con
}
if (arg == QLatin1String("$Files")) {
args << entryFullPaths(entries, true);
args << entryFullPaths(entries, NoTrailingSlash);
continue;
}
......@@ -852,7 +852,7 @@ QStringList CliInterface::substituteDeleteVariables(const QStringList &deleteArg
if (arg == QLatin1String("$Files")) {
foreach (const Archive::Entry *e, entries) {
args << escapeFileName(e->fullPath(true));
args << escapeFileName(e->fullPath(NoTrailingSlash));
}
continue;
}
......@@ -951,7 +951,7 @@ void CliInterface::setNewMovedFiles(const QVector<Archive::Entry*> &entries, con
} else {
// If there is only one passed file in the list,
// we have to use destination as newPath.
newPath = destination->fullPath(true);
newPath = destination->fullPath(NoTrailingSlash);
}
if (entry->isDir()) {
newPath += QLatin1Char('/');
......@@ -1071,7 +1071,7 @@ QStringList CliInterface::extractFilesList(const QVector<Archive::Entry*> &entri
{
QStringList filesList;
foreach (const Archive::Entry *e, entries) {
filesList << escapeFileName(e->fullPath(true));
filesList << escapeFileName(e->fullPath(NoTrailingSlash));
}
return filesList;
......@@ -1210,7 +1210,7 @@ bool CliInterface::setAddedFiles()
{
QDir::setCurrent(m_tempAddDir->path());
foreach (const Archive::Entry *file, m_passedFiles) {
const QString oldPath = m_tempExtractDir->path() + QLatin1Char('/') + file->fullPath(true);
const QString oldPath = m_tempExtractDir->path() + QLatin1Char('/') + file->fullPath(NoTrailingSlash);
const QString newPath = m_tempAddDir->path() + QLatin1Char('/') + file->name();
if (!QFile::rename(oldPath, newPath)) {
return false;
......@@ -1482,10 +1482,10 @@ QStringList CliInterface::entryPathDestinationPairs(const QVector<Archive::Entry
QStringList pairList;
if (entriesWithoutChildren.count() > 1) {
foreach (const Archive::Entry *file, entriesWithoutChildren) {
pairList << file->fullPath(true) << destination->fullPath() + file->name();
pairList << file->fullPath(NoTrailingSlash) << destination->fullPath() + file->name();
}
} else {
pairList << entriesWithoutChildren.at(0)->fullPath(true) << destination->fullPath(true);
pairList << entriesWithoutChildren.at(0)->fullPath(NoTrailingSlash) << destination->fullPath(NoTrailingSlash);
}
return pairList;
}
......
......@@ -220,7 +220,7 @@ QVariant ArchiveModel::data(const QModelIndex &index, int role) const
if (index.column() == 0) {
const Archive::Entry *e = static_cast<Archive::Entry*>(index.internalPointer());
QIcon::Mode mode = (filesToMove.contains(e->fullPath())) ? QIcon::Disabled : QIcon::Normal;
return m_entryIcons.value(e->fullPath(true)).pixmap(IconSize(KIconLoader::Small), IconSize(KIconLoader::Small), mode);
return m_entryIcons.value(e->fullPath(NoTrailingSlash)).pixmap(IconSize(KIconLoader::Small), IconSize(KIconLoader::Small), mode);
}
return QVariant();
case Qt::FontRole: {
......@@ -540,7 +540,7 @@ Archive::Entry *ArchiveModel::parentFor(const Archive::Entry *entry, InsertBehav
entry->setProperty("fullPath", (parent == &m_rootEntry)
? piece + QLatin1Char('/')
: parent->fullPath(false) + piece + QLatin1Char('/'));
: parent->fullPath(WithTrailingSlash) + piece + QLatin1Char('/'));
entry->setProperty("isDirectory", true);
insertEntry(entry, behaviour);
}
......@@ -585,7 +585,7 @@ void ArchiveModel::slotEntryRemoved(const QString & path)
Q_UNUSED(index);
beginRemoveRows(indexForEntry(parent), entry->row(), entry->row());
m_entryIcons.remove(parent->entries().at(entry->row())->fullPath(true));
m_entryIcons.remove(parent->entries().at(entry->row())->fullPath(NoTrailingSlash));
parent->removeEntryAt(entry->row());
endRemoveRows();
}
......@@ -718,7 +718,7 @@ void ArchiveModel::insertEntry(Archive::Entry *entry, InsertBehaviour behaviour)
IconSize(KIconLoader::Small))
: icon = QIcon::fromTheme(db.mimeTypeForFile(entry->fullPath()).iconName()).pixmap(IconSize(KIconLoader::Small),
IconSize(KIconLoader::Small));
m_entryIcons.insert(entry->fullPath(true), icon);
m_entryIcons.insert(entry->fullPath(NoTrailingSlash), icon);
}
Kerfuffle::Archive* ArchiveModel::archive() const
......@@ -988,7 +988,7 @@ void ArchiveModel::slotCleanupEmptyDirs()
Archive::Entry *rawEntry = static_cast<Archive::Entry*>(node.internalPointer());
qCDebug(ARK) << "Delete with parent entries " << rawEntry->getParent()->entries() << " and row " << rawEntry->row();
beginRemoveRows(parent(node), rawEntry->row(), rawEntry->row());
m_entryIcons.remove(rawEntry->getParent()->entries().at(rawEntry->row())->fullPath(true));
m_entryIcons.remove(rawEntry->getParent()->entries().at(rawEntry->row())->fullPath(NoTrailingSlash));
rawEntry->getParent()->removeEntryAt(rawEntry->row());
endRemoveRows();
}
......
......@@ -57,7 +57,7 @@ OverwriteDialog::OverwriteDialog(QWidget *parent, const QList<const Archive::Ent
connect(&m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
foreach (const Archive::Entry *entry, entries) {
QListWidgetItem *item = new QListWidgetItem(icons.value(entry->fullPath(true)), entry->fullPath(true));
QListWidgetItem *item = new QListWidgetItem(icons.value(entry->fullPath(NoTrailingSlash)), entry->fullPath(NoTrailingSlash));
m_entriesList.addItem(item);
}
......
......@@ -1437,7 +1437,7 @@ void Part::slotRenameFile(const QString &name)
QVector<Archive::Entry*> entriesToMove = filesForIndexes(addChildren(m_view->selectionModel()->selectedRows()));
m_destination = new Archive::Entry();
const QString &entryPath = entry->fullPath(true);
const QString &entryPath = entry->fullPath(NoTrailingSlash);
const QString rootPath = entryPath.left(entryPath.count() - entry->name().count());
m_destination->setFullPath(rootPath + name + ((entry->isDir()) ? QLatin1Char('/') : QChar()));
......
......@@ -259,7 +259,7 @@ bool CliPlugin::setMovingAddedFiles()
QDir::setCurrent(m_tempAddDir->path());
const Archive::Entry *file = m_passedFiles.at(0);
const QString oldPath = m_tempExtractDir->path() + QLatin1Char('/') + file->fullPath(true);
const QString oldPath = m_tempExtractDir->path() + QLatin1Char('/') + file->fullPath(NoTrailingSlash);
const QString newPath = m_tempAddDir->path() + QLatin1Char('/') + m_passedDestination->name();
if (!QFile::rename(oldPath, newPath)) {
return false;
......
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