summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-11 14:46:03 (GMT)
committerElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-11 15:02:06 (GMT)
commit2bd1c76ea35b519592837a2bdbeefff46166cc5f (patch)
tree8d9b0be4f6effd9dcfb02cf9296d528661ddf216
parentbcc22290ea2856d01a813594282c2d55beaca86a (diff)
Use an enum for trailing slash handling
The previous bool was confusing. Now the enum clearly says what the code does.
-rw-r--r--autotests/testhelper/testhelper.cpp2
-rw-r--r--kerfuffle/archiveentry.cpp4
-rw-r--r--kerfuffle/archiveentry.h8
-rw-r--r--kerfuffle/archiveinterface.cpp4
-rw-r--r--kerfuffle/archiveinterface.h2
-rw-r--r--kerfuffle/cliinterface.cpp18
-rw-r--r--part/archivemodel.cpp10
-rw-r--r--part/overwritedialog.cpp2
-rw-r--r--part/part.cpp2
-rw-r--r--plugins/clizipplugin/cliplugin.cpp2
10 files changed, 30 insertions, 24 deletions
diff --git a/autotests/testhelper/testhelper.cpp b/autotests/testhelper/testhelper.cpp
index 150c02a..52a2d88 100644
--- a/autotests/testhelper/testhelper.cpp
+++ b/autotests/testhelper/testhelper.cpp
@@ -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();
diff --git a/kerfuffle/archiveentry.cpp b/kerfuffle/archiveentry.cpp
index 7ffc011..3ffe990 100644
--- a/kerfuffle/archiveentry.cpp
+++ b/kerfuffle/archiveentry.cpp
@@ -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;
diff --git a/kerfuffle/archiveentry.h b/kerfuffle/archiveentry.h
index bf2b4f2..e569430 100644
--- a/kerfuffle/archiveentry.h
+++ b/kerfuffle/archiveentry.h
@@ -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;
diff --git a/kerfuffle/archiveinterface.cpp b/kerfuffle/archiveinterface.cpp
index c001e30..807614b 100644
--- a/kerfuffle/archiveinterface.cpp
+++ b/kerfuffle/archiveinterface.cpp
@@ -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;
}
diff --git a/kerfuffle/archiveinterface.h b/kerfuffle/archiveinterface.h
index 660022b..8a8a6d7 100644
--- a/kerfuffle/archiveinterface.h
+++ b/kerfuffle/archiveinterface.h
@@ -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.
diff --git a/kerfuffle/cliinterface.cpp b/kerfuffle/cliinterface.cpp
index 8f04b9a..05fef36 100644
--- a/kerfuffle/cliinterface.cpp
+++ b/kerfuffle/cliinterface.cpp
@@ -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;
}
diff --git a/part/archivemodel.cpp b/part/archivemodel.cpp
index ff3127d..31fa689 100644
--- a/part/archivemodel.cpp
+++ b/part/archivemodel.cpp
@@ -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();
}
diff --git a/part/overwritedialog.cpp b/part/overwritedialog.cpp
index ddecb67..106932b 100644
--- a/part/overwritedialog.cpp
+++ b/part/overwritedialog.cpp
@@ -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);
}
diff --git a/part/part.cpp b/part/part.cpp
index 4a78ce4..de0b863 100644
--- a/part/part.cpp
+++ b/part/part.cpp
@@ -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()));
diff --git a/plugins/clizipplugin/cliplugin.cpp b/plugins/clizipplugin/cliplugin.cpp
index 58053c2..3d927fe 100644
--- a/plugins/clizipplugin/cliplugin.cpp
+++ b/plugins/clizipplugin/cliplugin.cpp
@@ -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;