Changeset View
Changeset View
Standalone View
Standalone View
kerfuffle/archiveinterface.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Line(s) | |||||
164 | void ReadOnlyArchiveInterface::setWaitForFinishedSignal(bool value) | 164 | void ReadOnlyArchiveInterface::setWaitForFinishedSignal(bool value) | ||
165 | { | 165 | { | ||
166 | m_waitForFinishedSignal = value; | 166 | m_waitForFinishedSignal = value; | ||
167 | } | 167 | } | ||
168 | 168 | | |||
169 | QStringList ReadOnlyArchiveInterface::entryFullPaths(const QVector<Archive::Entry*> &entries, PathFormat format) | 169 | QStringList ReadOnlyArchiveInterface::entryFullPaths(const QVector<Archive::Entry*> &entries, PathFormat format) | ||
170 | { | 170 | { | ||
171 | QStringList filesList; | 171 | QStringList filesList; | ||
172 | foreach (const Archive::Entry *file, entries) { | 172 | for (const Archive::Entry *file : entries) { | ||
173 | filesList << file->fullPath(format); | 173 | filesList << file->fullPath(format); | ||
174 | } | 174 | } | ||
175 | return filesList; | 175 | return filesList; | ||
176 | } | 176 | } | ||
177 | 177 | | |||
178 | QVector<Archive::Entry*> ReadOnlyArchiveInterface::entriesWithoutChildren(const QVector<Archive::Entry*> &entries) | 178 | QVector<Archive::Entry*> ReadOnlyArchiveInterface::entriesWithoutChildren(const QVector<Archive::Entry*> &entries) | ||
179 | { | 179 | { | ||
180 | // QMap is easy way to get entries sorted by their fullPath. | 180 | // QMap is easy way to get entries sorted by their fullPath. | ||
181 | QMap<QString, Archive::Entry*> sortedEntries; | 181 | QMap<QString, Archive::Entry*> sortedEntries; | ||
182 | foreach (Archive::Entry *entry, entries) { | 182 | for (Archive::Entry *entry : entries) { | ||
183 | sortedEntries.insert(entry->fullPath(), entry); | 183 | sortedEntries.insert(entry->fullPath(), entry); | ||
184 | } | 184 | } | ||
185 | 185 | | |||
186 | QVector<Archive::Entry*> filteredEntries; | 186 | QVector<Archive::Entry*> filteredEntries; | ||
187 | QString lastFolder; | 187 | QString lastFolder; | ||
188 | foreach (Archive::Entry *entry, sortedEntries) { | 188 | for (Archive::Entry *entry : qAsConst(sortedEntries)) { | ||
189 | if (lastFolder.count() > 0 && entry->fullPath().startsWith(lastFolder)) { | 189 | if (lastFolder.count() > 0 && entry->fullPath().startsWith(lastFolder)) { | ||
190 | continue; | 190 | continue; | ||
191 | } | 191 | } | ||
192 | 192 | | |||
193 | lastFolder = (entry->fullPath().right(1) == QLatin1String("/")) ? entry->fullPath() : QString(); | 193 | lastFolder = (entry->fullPath().right(1) == QLatin1String("/")) ? entry->fullPath() : QString(); | ||
194 | filteredEntries << entry; | 194 | filteredEntries << entry; | ||
195 | } | 195 | } | ||
196 | 196 | | |||
197 | return filteredEntries; | 197 | return filteredEntries; | ||
198 | } | 198 | } | ||
199 | 199 | | |||
200 | QStringList ReadOnlyArchiveInterface::entryPathsFromDestination(QStringList entries, const Archive::Entry *destination, int entriesWithoutChildren) | 200 | QStringList ReadOnlyArchiveInterface::entryPathsFromDestination(QStringList entries, const Archive::Entry *destination, int entriesWithoutChildren) | ||
201 | { | 201 | { | ||
202 | QStringList paths = QStringList(); | 202 | QStringList paths = QStringList(); | ||
203 | entries.sort(); | 203 | entries.sort(); | ||
204 | QString lastFolder; | 204 | QString lastFolder; | ||
205 | const QString destinationPath = (destination == nullptr) ? QString() : destination->fullPath(); | 205 | const QString destinationPath = (destination == nullptr) ? QString() : destination->fullPath(); | ||
206 | 206 | | |||
207 | QString newPath; | 207 | QString newPath; | ||
208 | int nameLength = 0; | 208 | int nameLength = 0; | ||
209 | foreach (const QString &entryPath, entries) { | 209 | for (const QString &entryPath : qAsConst(entries)) { | ||
210 | if (lastFolder.count() > 0 && entryPath.startsWith(lastFolder)) { | 210 | if (lastFolder.count() > 0 && entryPath.startsWith(lastFolder)) { | ||
211 | // Replace last moved or copied folder path with destination path. | 211 | // Replace last moved or copied folder path with destination path. | ||
212 | int charsCount = entryPath.count() - lastFolder.count(); | 212 | int charsCount = entryPath.count() - lastFolder.count(); | ||
213 | if (entriesWithoutChildren != 1) { | 213 | if (entriesWithoutChildren != 1) { | ||
214 | charsCount += nameLength; | 214 | charsCount += nameLength; | ||
215 | } | 215 | } | ||
216 | newPath = destinationPath + entryPath.right(charsCount); | 216 | newPath = destinationPath + entryPath.right(charsCount); | ||
217 | } else { | 217 | } else { | ||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |