Changeset View
Changeset View
Standalone View
Standalone View
kerfuffle/addtoarchive.cpp
Show First 20 Lines • Show All 233 Lines • ▼ Show 20 Line(s) | 233 | if (job->error() && !job->errorText().isEmpty()) { | |||
---|---|---|---|---|---|
234 | KMessageBox::error(Q_NULLPTR, job->errorText()); | 234 | KMessageBox::error(Q_NULLPTR, job->errorText()); | ||
235 | } | 235 | } | ||
236 | 236 | | |||
237 | emitResult(); | 237 | emitResult(); | ||
238 | } | 238 | } | ||
239 | 239 | | |||
240 | QString AddToArchive::detectBaseName(const QStringList &paths) const | 240 | QString AddToArchive::detectBaseName(const QStringList &paths) const | ||
241 | { | 241 | { | ||
242 | QString base = QFileInfo(paths.first()).absoluteFilePath(); | 242 | QFileInfo fileInfo = QFileInfo(paths.first()); | ||
elvisangelaccio: Better use `fileInfo` for this variable name | |||||
243 | QDir parentDir = fileInfo.dir(); | ||||
Please change the name of this variable to "parentDir", to make code more readable. rthomsen: Please change the name of this variable to "parentDir", to make code more readable. | |||||
244 | QString base = parentDir.absolutePath() + QLatin1Char('/'); | ||||
245 | | ||||
243 | if (paths.size() > 1) { | 246 | if (paths.size() > 1) { | ||
244 | QDir dir = QFileInfo(paths.first()).dir(); | 247 | if (!parentDir.isRoot()) { | ||
245 | if (!dir.isRoot()) { | 248 | // Use directory name for the new archive. | ||
Please start comments with capital letter, and end with period. Same below. rthomsen: Please start comments with capital letter, and end with period. Same below. | |||||
246 | base = dir.absolutePath() + QLatin1Char('/') + dir.dirName(); | 249 | base += parentDir.dirName(); | ||
250 | } | ||||
251 | } else { | ||||
252 | // Strip filename of its extension. | ||||
253 | base += fileInfo.completeBaseName(); | ||||
What happens if I compress a file with name README-v1.4.2.txt ? Have a look at the function Archive::completeBaseName(), you should do the same thing here :) elvisangelaccio: What happens if I compress a file with name `README-v1.4.2.txt` ?
I get e.g. a zip file with… | |||||
247 | } | 254 | } | ||
255 | | ||||
256 | // Special case for compressed tar archives. | ||||
257 | if (base.right(4).toUpper() == QLatin1String(".TAR")) { | ||||
258 | base.chop(4); | ||||
248 | } | 259 | } | ||
249 | 260 | | |||
250 | if (base.endsWith(QLatin1Char('/'))) { | 261 | if (base.endsWith(QLatin1Char('/'))) { | ||
251 | base.chop(1); | 262 | base.chop(1); | ||
252 | } | 263 | } | ||
253 | 264 | | |||
254 | return base; | 265 | return base; | ||
255 | } | 266 | } | ||
256 | 267 | | |||
257 | } | 268 | } |
Better use fileInfo for this variable name