Commit af0d5239 authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa
Browse files

Style cleanup.

 * Add {}'s in all if clauses
 * Remove superfluous extra lines
 * Remove extra whitespace before trailing ;'s
 * While at it, remove some of the extra whitespace
   that montel's commits have introduced

svn path=/trunk/KDE/kdeutils/ark/; revision=1186941
parent fc66867d
......@@ -71,8 +71,9 @@ void BatchExtract::addExtraction(Kerfuffle::Archive* archive)
const QDir d(destination);
QString subfolderName = archive->subfolderName();
if (d.exists(subfolderName))
if (d.exists(subfolderName)) {
subfolderName = KIO::RenameDialog::suggestName(destination, subfolderName);
}
d.mkdir(subfolderName);
......
......@@ -78,11 +78,14 @@ void MainWindow::dragEnterEvent(QDragEnterEvent * event)
kDebug() << event;
Interface *iface = qobject_cast<Interface*>(m_part);
if (iface->isBusy()) return;
if (iface->isBusy()) {
return;
}
if (event->source() == NULL &&
isValidArchiveDrag(event->mimeData()))
if ((event->source() == NULL) &&
(isValidArchiveDrag(event->mimeData()))) {
event->acceptProposedAction();
}
return;
}
......@@ -91,11 +94,14 @@ void MainWindow::dropEvent(QDropEvent * event)
kDebug() << event;
Interface *iface = qobject_cast<Interface*>(m_part);
if (iface->isBusy()) return;
if (iface->isBusy()) {
return;
}
if (event->source() == NULL &&
isValidArchiveDrag(event->mimeData()))
if ((event->source() == NULL) &&
(isValidArchiveDrag(event->mimeData()))) {
event->acceptProposedAction();
}
//TODO: if this call provokes a message box the drag will still be going
//while the box is onscreen. looks buggy, do something about it
......@@ -107,11 +113,14 @@ void MainWindow::dragMoveEvent(QDragMoveEvent * event)
kDebug() << event;
Interface *iface = qobject_cast<Interface*>(m_part);
if (iface->isBusy()) return;
if (iface->isBusy()) {
return;
}
if (event->source() == NULL &&
isValidArchiveDrag(event->mimeData()))
if ((event->source() == NULL) &&
(isValidArchiveDrag(event->mimeData()))) {
event->acceptProposedAction();
}
}
bool MainWindow::loadPart()
......
......@@ -45,12 +45,14 @@ static bool comparePlugins(const KService::Ptr &p1, const KService::Ptr &p2)
static QString determineMimeType(const QString& filename)
{
if (!QFile::exists(filename))
if (!QFile::exists(filename)) {
return KMimeType::findByPath(filename)->name();
}
QFile file(filename);
if (!file.open(QIODevice::ReadOnly))
if (!file.open(QIODevice::ReadOnly)) {
return QString();
}
const qint64 maxSize = 0x100000; // 1MB
const qint64 bufferSize = qMin(maxSize, file.size());
......
......@@ -103,8 +103,9 @@ AddJob* ArchiveBase::addFiles(const QStringList & files, const CompressionOption
ExtractJob* ArchiveBase::copyFiles(const QList<QVariant> & files, const QString & destinationDir, ExtractionOptions options)
{
ExtractionOptions newOptions = options;
if (isPasswordProtected())
if (isPasswordProtected()) {
newOptions[QLatin1String( "PasswordProtectedHint" )] = true;
}
ExtractJob *newJob = new ExtractJob(files, destinationDir, newOptions, m_iface, this);
return newJob;
......@@ -140,8 +141,9 @@ void ArchiveBase::onListFinished(KJob* job)
QString base = fi.completeBaseName();
//special case for tar.gz/bzip2 files
if (base.right(4).toUpper() == QLatin1String( ".TAR" ))
if (base.right(4).toUpper() == QLatin1String(".TAR")) {
base.chop(4);
}
m_subfolderName = base;
}
......
......@@ -87,7 +87,7 @@ bool CliInterface::list()
bool CliInterface::copyFiles(const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options)
{
kDebug() ;
kDebug();
cacheParameterList();
m_operationMode = Copy;
......@@ -110,24 +110,25 @@ bool CliInterface::copyFiles(const QList<QVariant> & files, const QString & dest
}
if (argument == QLatin1String( "$PreservePathSwitch" )) {
QStringList replacementFlags = m_param.value(PreservePathSwitch).toStringList();
Q_ASSERT(replacementFlags.size() == 2);
bool preservePaths = options.value(QLatin1String( "PreservePaths" )).toBool();
QString theReplacement;
if (preservePaths)
if (preservePaths) {
theReplacement = replacementFlags.at(0);
else
} else {
theReplacement = replacementFlags.at(1);
}
if (theReplacement.isEmpty()) {
args.removeAt(i);
--i; //decrement to compensate for the variable we removed
} else
} else {
//but in this case we don't have to decrement, we just
//replace it
args[i] = theReplacement;
}
}
if (argument == QLatin1String( "$PasswordSwitch" )) {
......@@ -140,7 +141,8 @@ bool CliInterface::copyFiles(const QList<QVariant> & files, const QString & dest
//if we get a hint about this being a password protected archive, ask about
//the password in advance.
if (options.value(QLatin1String( "PasswordProtectedHint" )).toBool() && password().isEmpty()) {
if ((options.value(QLatin1String("PasswordProtectedHint")).toBool()) &&
(password().isEmpty())) {
kDebug() << "Password hint enabled, querying user";
Kerfuffle::PasswordNeededQuery query(filename());
......@@ -296,8 +298,7 @@ bool CliInterface::deleteFiles(const QList<QVariant> & files)
if (argument == QLatin1String( "$Archive" )) {
args[i] = filename();
}
else if (argument == QLatin1String( "$Files" )) {
} else if (argument == QLatin1String( "$Files" )) {
args.removeAt(i);
for (int j = 0; j < files.count(); ++j) {
args.insert(i + j, escapeFileName(files.at(j).toString()));
......@@ -329,8 +330,9 @@ bool CliInterface::createProcess()
m_process->setTextModeEnabled(true);
m_process->setOutputChannelMode(KProcess::MergedChannels);
if (QMetaType::type("QProcess::ExitStatus") == 0)
if (QMetaType::type("QProcess::ExitStatus") == 0) {
qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
}
connect(m_process, SIGNAL(started()), SLOT(started()), Qt::DirectConnection);
connect(m_process, SIGNAL(readyReadStandardOutput()), SLOT(readStdout()), Qt::DirectConnection);
......@@ -366,8 +368,9 @@ void CliInterface::processFinished(int exitCode, QProcess::ExitStatus exitStatus
//if the m_process pointer is gone, then there is nothing to worry
//about here
if (!m_process)
if (!m_process) {
return;
}
if (m_operationMode == Delete) {
foreach(const QVariant& v, m_removedFiles) {
......@@ -434,8 +437,9 @@ void CliInterface::readStdout(bool handleAll)
checkForErrorMessage(QLatin1String( lines.last() ), ExtractionFailedPatterns) ||
checkForFileExistsMessage(QLatin1String( lines.last() )));
if (foundErrorMessage)
if (foundErrorMessage) {
handleAll = true;
}
//this is complex, here's an explanation:
//if there is no newline, then there is no guaranteed full line to
......@@ -456,8 +460,9 @@ void CliInterface::readStdout(bool handleAll)
}
foreach(const QByteArray& line, lines) {
if (!line.isEmpty())
if (!line.isEmpty()) {
handleLine(QString::fromLocal8Bit(line));
}
}
}
......@@ -489,8 +494,9 @@ void CliInterface::handleLine(const QString& line)
return;
}
if (handleFileExistsMessage(line))
if (handleFileExistsMessage(line)) {
return;
}
}
if (m_operationMode == List) {
......@@ -509,8 +515,9 @@ void CliInterface::handleLine(const QString& line)
return;
}
if (handleFileExistsMessage(line))
if (handleFileExistsMessage(line)) {
return;
}
readListLine(line);
return;
......@@ -549,8 +556,9 @@ bool CliInterface::checkForFileExistsMessage(const QString& line)
bool CliInterface::handleFileExistsMessage(const QString& line)
{
if (!checkForFileExistsMessage(line))
if (!checkForFileExistsMessage(line)) {
return false;
}
const QString filename = m_existsPattern.cap(1);
......@@ -565,16 +573,17 @@ bool CliInterface::handleFileExistsMessage(const QString& line)
QString responseToProcess;
const QStringList choices = m_param.value(FileExistsInput).toStringList();
if (query.responseOverwrite())
if (query.responseOverwrite()) {
responseToProcess = choices.at(0);
else if (query.responseSkip())
} else if (query.responseSkip()) {
responseToProcess = choices.at(1);
else if (query.responseOverwriteAll())
} else if (query.responseOverwriteAll()) {
responseToProcess = choices.at(2);
else if (query.responseAutoSkip())
} else if (query.responseAutoSkip()) {
responseToProcess = choices.at(3);
else if (query.responseCancelled())
} else if (query.responseCancelled()) {
responseToProcess = choices.at(4);
}
Q_ASSERT(!responseToProcess.isEmpty());
......@@ -595,8 +604,9 @@ bool CliInterface::checkForErrorMessage(const QString& line, int parameterIndex)
if (patternCache.contains(parameterIndex)) {
patterns = patternCache.value(parameterIndex);
} else {
if (!m_param.contains(parameterIndex))
if (!m_param.contains(parameterIndex)) {
return false;
}
foreach(const QString& rawPattern, m_param.value(parameterIndex).toStringList()) {
patterns << QRegExp(rawPattern);
......@@ -617,8 +627,9 @@ bool CliInterface::doKill()
if (m_process) {
m_process->terminate();
if (!m_process->waitForFinished())
if (!m_process->waitForFinished()) {
m_process->kill();
}
m_process->waitForFinished();
......@@ -667,8 +678,9 @@ QString CliInterface::escapeFileName(const QString& fileName)
quoted.reserve(len * 2);
for (int i = 0; i < len; ++i) {
if (m_escapedCharacters.contains(fileName.at(i)))
if (m_escapedCharacters.contains(fileName.at(i))) {
quoted.append(backslash);
}
quoted.append(fileName.at(i));
}
......
......@@ -52,8 +52,9 @@ void Query::waitForResponse()
kDebug();
//if there is no response set yet, wait
if (!m_data.contains(QLatin1String( "response" )))
if (!m_data.contains(QLatin1String("response"))) {
m_responseCondition.wait(&m_responseMutex);
}
m_responseMutex.unlock();
}
......
......@@ -43,8 +43,9 @@ void ArchiveTest::testFileName()
{
Kerfuffle::Archive *archive = Kerfuffle::factory("/tmp/foo.tar.gz");
if (!archive)
if (!archive) {
QSKIP("There is no plugin to handle tar.gz files. Skipping test.", SkipSingle);
}
QCOMPARE(archive->fileName(), QString("/tmp/foo.tar.gz"));
......@@ -56,8 +57,9 @@ void ArchiveTest::testIsPasswordProtected()
Kerfuffle::Archive *archive;
archive = Kerfuffle::factory(KDESRCDIR "data/archivetest_encrypted.zip");
if (!archive)
if (!archive) {
QSKIP("There is no plugin to handle zip files. Skipping test.", SkipSingle);
}
QVERIFY(archive->isPasswordProtected());
......
......@@ -52,11 +52,13 @@ bool JSONArchiveInterface::open()
{
QFile file(filename());
if (!file.exists())
if (!file.exists()) {
return false;
}
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return false;
}
bool ok;
QJson::Parser parser;
......@@ -69,8 +71,9 @@ bool JSONArchiveInterface::open()
return false;
}
if (!parseJsonMap(jsonMap))
if (!parseJsonMap(jsonMap)) {
return false;
}
return true;
}
......@@ -103,17 +106,19 @@ bool JSONArchiveInterface::parseJsonMap(const QVariantMap& jsonMap)
foreach (const QVariant& entry, jsonMap["entries"].toList()) {
const QVariantMap entryMap = entry.toMap();
if (!entryMap.contains(QLatin1String("FileName")))
if (!entryMap.contains(QLatin1String("FileName"))) {
continue;
}
Kerfuffle::ArchiveEntry e;
QVariantMap::const_iterator entryIterator = entryMap.constBegin();
for (; entryIterator != entryMap.constEnd(); ++entryIterator) {
if (valueMap.contains(entryIterator.key()))
if (valueMap.contains(entryIterator.key())) {
e[valueMap[entryIterator.key()]] = entryIterator.value();
else
} else {
kDebug() << entryIterator.key() << "is not a valid entry key";
}
}
m_entryNameList.append(e[Kerfuffle::FileName].toString());
......@@ -131,8 +136,9 @@ bool JSONArchiveInterface::addFiles(const QStringList& files, const Kerfuffle::C
QList<Kerfuffle::ArchiveEntry> entryList;
foreach (const QString& file, files) {
if (m_entryNameList.contains(file))
if (m_entryNameList.contains(file)) {
return false;
}
Kerfuffle::ArchiveEntry e;
e[Kerfuffle::FileName] = file;
......@@ -166,8 +172,9 @@ bool JSONArchiveInterface::deleteFiles(const QList<QVariant>& files)
QList<Kerfuffle::ArchiveEntry> newEntryList;
QStringList newEntryNameList;
foreach (const Kerfuffle::ArchiveEntry& e, m_entryList) {
if (fileList.contains(e[Kerfuffle::FileName].toString()))
if (fileList.contains(e[Kerfuffle::FileName].toString())) {
continue;
}
newEntryList.append(e);
newEntryNameList.append(e[Kerfuffle::FileName].toString());
......
......@@ -60,30 +60,34 @@ public:
static bool compareAscending(const QPair<ArchiveNode*,int> &a, const QPair<ArchiveNode*,int> &b) {
// #234373: sort folders before files
if (a.first->isDir() != b.first->isDir())
if (a.first->isDir() != b.first->isDir()) {
return a.first->isDir();
}
if (currentSortColumn == FileName)
if (currentSortColumn == FileName) {
return (a.first->m_name < b.first->m_name);
else if ((currentSortColumn == Size) ||
(currentSortColumn == CompressedSize))
} else if ((currentSortColumn == Size) ||
(currentSortColumn == CompressedSize)) {
return (a.first->entry()[currentSortColumn].toInt() < b.first->entry()[currentSortColumn].toInt());
else
} else {
return (a.first->entry()[currentSortColumn].toString() < b.first->entry()[currentSortColumn].toString());
}
}
static bool compareDescending(const QPair<ArchiveNode*,int> &a, const QPair<ArchiveNode*,int> &b) {
// #234373: sort folders before files
if (a.first->isDir() != b.first->isDir())
if (a.first->isDir() != b.first->isDir()) {
return !(a.first->isDir());
}
if (currentSortColumn == FileName)
if (currentSortColumn == FileName) {
return (a.first->m_name > b.first->m_name);
else if ((currentSortColumn == Size) ||
(currentSortColumn == CompressedSize))
} else if ((currentSortColumn == Size) ||
(currentSortColumn == CompressedSize)) {
return (a.first->entry()[currentSortColumn].toInt() > b.first->entry()[currentSortColumn].toInt());
else
} else {
return (a.first->entry()[currentSortColumn].toString() > b.first->entry()[currentSortColumn].toString());
}
}
const ArchiveEntry &entry() const {
......@@ -410,8 +414,9 @@ int ArchiveModel::columnCount(const QModelIndex &parent) const
void ArchiveModel::sort(int column, Qt::SortOrder order)
{
if (m_showColumns.size() <= column)
if (m_showColumns.size() <= column) {
return;
}
currentSortColumn = m_showColumns.at(column);
......@@ -429,10 +434,11 @@ void ArchiveModel::sort(int column, Qt::SortOrder order)
sorting[i].second = i;
}
if (order == Qt::AscendingOrder)
if (order == Qt::AscendingOrder) {
qSort(sorting.begin(), sorting.end(), ArchiveNode::compareAscending);
else
} else {
qSort(sorting.begin(), sorting.end(), ArchiveNode::compareDescending);
}
QModelIndexList fromIndexes;
QModelIndexList toIndexes;
......@@ -473,7 +479,7 @@ QStringList ArchiveModel::mimeTypes() const
QMimeData * ArchiveModel::mimeData(const QModelIndexList & indexes) const
{
kDebug() ;
kDebug();
//prepare the fallback kio_slave filenames
QStringList files;
bool noFallback = false;
......@@ -497,7 +503,9 @@ QMimeData * ArchiveModel::mimeData(const QModelIndexList & indexes) const
foreach(const QModelIndex &index, indexes) {
//to limit only one index per row
if (index.column() != 0) continue;
if (index.column() != 0) {
continue;
}
const QString file = archiveName + static_cast<ArchiveNode*>(index.internalPointer())->entry()[ FileName ].toString();
files << file;
......@@ -512,8 +520,9 @@ QMimeData * ArchiveModel::mimeData(const QModelIndexList & indexes) const
);
if (!noFallback)
if (!noFallback) {
kiolist.populateMimeData(data);
}
return data;
}
......@@ -524,8 +533,9 @@ bool ArchiveModel::dropMimeData(const QMimeData * data, Qt::DropAction action, i
Q_UNUSED(column)
Q_UNUSED(parent)
if (!data->hasUrls())
if (!data->hasUrls()) {
return false;
}
QStringList paths;
foreach(const QUrl &url, data->urls()) {
......@@ -573,15 +583,15 @@ QString ArchiveModel::cleanFileName(const QString& fileName)
ArchiveDirNode* ArchiveModel::parentFor(const ArchiveEntry& entry)
{
QStringList pieces = entry[ FileName ].toString().split(QLatin1Char( '/' ), QString::SkipEmptyParts);
if (pieces.isEmpty()) return NULL;
if (pieces.isEmpty()) {
return NULL;
}
pieces.removeLast();
if (previousMatch) {
//the number of path elements must be the same for the shortcut
//to work
if (previousPieces.count() == pieces.count()) {
bool equal = true;
//make sure all the pieces match up
......@@ -595,10 +605,8 @@ ArchiveDirNode* ArchiveModel::parentFor(const ArchiveEntry& entry)
//if match return it
if (equal) {
return static_cast<ArchiveDirNode*>(previousMatch);
}
}
}
ArchiveDirNode *parent = m_rootNode;
......@@ -694,7 +702,6 @@ void ArchiveModel::newEntry(const ArchiveEntry& receivedEntry, InsertBehaviour b
//if there are no addidional columns registered, then have a look at the
//entry and populate some
if (m_showColumns.isEmpty()) {
//these are the columns we are interested in showing in the display
static const QList<int> columnsForDisplay =
QList<int>()
......@@ -714,15 +721,15 @@ void ArchiveModel::newEntry(const ArchiveEntry& receivedEntry, InsertBehaviour b
QList<int> toInsert;
foreach(int column, columnsForDisplay) {
if (receivedEntry.contains(column))
if (receivedEntry.contains(column)) {
toInsert << column;
}
}
beginInsertColumns(QModelIndex(), 0, toInsert.size() - 1);
m_showColumns << toInsert;
endInsertColumns();
kDebug() << "Show columns detected: " << m_showColumns;
}
//make a copy
......@@ -788,9 +795,13 @@ void ArchiveModel::insertNode(ArchiveNode *node, InsertBehaviour behaviour)
Q_ASSERT(node);
ArchiveDirNode *parent = node->parent();
Q_ASSERT(parent);
if (behaviour == NotifyViews) beginInsertRows(indexForNode(parent), parent->entries().count(), parent->entries().count());
if (behaviour == NotifyViews) {
beginInsertRows(indexForNode(parent), parent->entries().count(), parent->entries().count());
}
parent->entries().append(node);
if (behaviour == NotifyViews) endInsertRows();
if (behaviour == NotifyViews) {
endInsertRows();
}
}
Kerfuffle::Archive* ArchiveModel::archive() const
......@@ -849,7 +860,9 @@ ExtractJob* ArchiveModel::extractFiles(const QList<QVariant>& files, const QStri
AddJob* ArchiveModel::addFiles(const QStringList & filenames, const CompressionOptions& options)
{
if (!m_archive) return NULL;
if (!m_archive) {
return NULL;
}
if (!m_archive->isReadOnly()) {
AddJob *job = m_archive->addFiles(filenames, options);
......
......@@ -51,13 +51,15 @@ void ArchiveView::updateMouseButtons()
void ArchiveView::slotClicked(const QModelIndex& index)
{
if (KGlobalSettings::singleClick()) {
if (m_mouseButtons != Qt::LeftButton) // FIXME: see QTBUG-1067
if (m_mouseButtons != Qt::LeftButton) { // FIXME: see QTBUG-1067
return;
}
// If the user is pressing shift or control, more than one item is being selected
const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier))
if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) {
return;
}
emit itemTriggered(index);
}
......@@ -65,13 +67,14 @@ void ArchiveView::slotClicked(const QModelIndex& index)
void ArchiveView</