Changeset View
Changeset View
Standalone View
Standalone View
src/file/fileindexerconfig.cpp
Show All 40 Lines | 40 | do { | |||
---|---|---|---|---|---|
41 | if (QFileInfo(d.path()).isHidden()) | 41 | if (QFileInfo(d.path()).isHidden()) | ||
42 | return true; | 42 | return true; | ||
43 | } while (d.cdUp()); | 43 | } while (d.cdUp()); | ||
44 | 44 | | |||
45 | return false; | 45 | return false; | ||
46 | #endif | 46 | #endif | ||
47 | } | 47 | } | ||
48 | 48 | | |||
49 | QString stripTrailingSlash(const QString& path) | 49 | QString normalizeTrailingSlashes(QString&& path) | ||
50 | { | 50 | { | ||
51 | return path.endsWith(QLatin1Char('/')) ? path.mid(0, path.length()-1) : path; | 51 | while (path.endsWith(QLatin1Char('/'))) { | ||
52 | path.chop(1); | ||||
53 | } | ||||
54 | path += QLatin1Char('/'); | ||||
55 | return path; | ||||
52 | } | 56 | } | ||
53 | 57 | | |||
54 | } | 58 | } | ||
55 | 59 | | |||
56 | using namespace Baloo; | 60 | using namespace Baloo; | ||
57 | 61 | | |||
58 | FileIndexerConfig::FileIndexerConfig(QObject* parent) | 62 | FileIndexerConfig::FileIndexerConfig(QObject* parent) | ||
59 | : QObject(parent) | 63 | : QObject(parent) | ||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Line(s) | 229 | { | |||
226 | QString str; | 230 | QString str; | ||
227 | return folderInFolderList(path, str); | 231 | return folderInFolderList(path, str); | ||
228 | } | 232 | } | ||
229 | 233 | | |||
230 | bool FileIndexerConfig::folderInFolderList(const QString& path, QString& folder) const | 234 | bool FileIndexerConfig::folderInFolderList(const QString& path, QString& folder) const | ||
231 | { | 235 | { | ||
232 | const_cast<FileIndexerConfig*>(this)->buildFolderCache(); | 236 | const_cast<FileIndexerConfig*>(this)->buildFolderCache(); | ||
233 | 237 | | |||
234 | const QString p = stripTrailingSlash(path); | 238 | const QString p = normalizeTrailingSlashes(QString(path)); | ||
235 | 239 | | |||
236 | // we traverse the list backwards to catch all exclude folders | 240 | // we traverse the list backwards to catch all exclude folders | ||
237 | int i = m_folderCache.count(); | 241 | int i = m_folderCache.count(); | ||
238 | while (--i >= 0) { | 242 | while (--i >= 0) { | ||
239 | const QString& f = m_folderCache[i].first; | 243 | const QString& f = m_folderCache[i].first; | ||
240 | const bool include = m_folderCache[i].second; | 244 | const bool include = m_folderCache[i].second; | ||
241 | if (p.startsWith(f)) { | 245 | if (p.startsWith(f)) { | ||
242 | folder = f; | 246 | folder = f; | ||
Show All 12 Lines | |||||
255 | * Returns true if the specified folder f would already be excluded using the list | 259 | * Returns true if the specified folder f would already be excluded using the list | ||
256 | * folders. | 260 | * folders. | ||
257 | */ | 261 | */ | ||
258 | bool alreadyExcluded(const QList<QPair<QString, bool> >& folders, const QString& f) | 262 | bool alreadyExcluded(const QList<QPair<QString, bool> >& folders, const QString& f) | ||
259 | { | 263 | { | ||
260 | bool included = false; | 264 | bool included = false; | ||
261 | for (int i = 0; i < folders.count(); ++i) { | 265 | for (int i = 0; i < folders.count(); ++i) { | ||
262 | QString path = folders[i].first; | 266 | QString path = folders[i].first; | ||
263 | if (!path.endsWith(QLatin1Char('/'))) | | |||
264 | path.append(QLatin1Char('/')); | | |||
265 | 267 | | |||
266 | if (f != folders[i].first && f.startsWith(path)) { | 268 | if (f != folders[i].first && f.startsWith(path)) { | ||
267 | included = folders[i].second; | 269 | included = folders[i].second; | ||
268 | } | 270 | } | ||
269 | } | 271 | } | ||
270 | return !included; | 272 | return !included; | ||
271 | } | 273 | } | ||
272 | 274 | | |||
273 | /** | 275 | /** | ||
274 | * Simple insertion sort | 276 | * Simple insertion sort | ||
275 | */ | 277 | */ | ||
276 | void insertSortFolders(const QStringList& folders, bool include, QList<QPair<QString, bool> >& result) | 278 | void insertSortFolders(const QStringList& folders, bool include, QList<QPair<QString, bool> >& result) | ||
277 | { | 279 | { | ||
278 | Q_FOREACH (const QString& f, folders) { | 280 | Q_FOREACH (QString path, folders) { | ||
279 | int pos = 0; | 281 | int pos = 0; | ||
280 | QString path = stripTrailingSlash(f); | 282 | path = normalizeTrailingSlashes(std::move(path)); | ||
281 | while (result.count() > pos && | 283 | while (result.count() > pos && | ||
282 | result[pos].first < path) | 284 | result[pos].first < path) | ||
283 | ++pos; | 285 | ++pos; | ||
284 | result.insert(pos, qMakePair(path, include)); | 286 | result.insert(pos, qMakePair(path, include)); | ||
285 | } | 287 | } | ||
286 | } | 288 | } | ||
287 | 289 | | |||
288 | /** | 290 | /** | ||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |