Commit 62e0513e authored by Matthieu Gallien's avatar Matthieu Gallien

properly get the path in the kcm module and use it cleanly in indexers

in MusicListenerManager, it is needed after calling canonicalPath to
check if the string is empty

checks that there is not trailing slash before adding it

never assume the paths are correct or follow some predefined pattern
parent a454b4f0
......@@ -89,12 +89,16 @@ void KCMElisaLocalFile::setRootPath(QStringList rootPath)
mRootPath.clear();
for (const auto &onePath : rootPath) {
if (onePath.startsWith(QLatin1String("file:///"))) {
mRootPath.push_back(onePath.mid(7));
} else if (onePath.startsWith(QLatin1String("file:/"))) {
mRootPath.push_back(onePath.mid(5));
} else {
mRootPath.push_back(onePath);
auto workPath = onePath;
if (workPath.startsWith(QLatin1String("file:/"))) {
auto urlPath = QUrl{workPath};
workPath = urlPath.toLocalFile();
}
QFileInfo pathFileInfo(workPath);
auto directoryPath = pathFileInfo.canonicalFilePath();
if (!directoryPath.isEmpty()) {
mRootPath.push_back(directoryPath);
}
}
......
......@@ -321,12 +321,24 @@ void MusicListenersManager::configChanged()
//resolve symlinks
QStringList allRootPaths;
for (const auto &path : currentConfiguration->rootPath()) {
QFileInfo pathFileInfo(path);
for (const auto &onePath : currentConfiguration->rootPath()) {
auto workPath = onePath;
if (workPath.startsWith(QLatin1String("file:/"))) {
auto urlPath = QUrl{workPath};
workPath = urlPath.toLocalFile();
}
QFileInfo pathFileInfo(workPath);
auto directoryPath = pathFileInfo.canonicalFilePath();
//directory must always end with a slash
directoryPath.append(QLatin1Char('/'));
allRootPaths << directoryPath;
if (!directoryPath.isEmpty()) {
if (directoryPath.rightRef(1) != QLatin1Char('/'))
{
directoryPath.append(QLatin1Char('/'));
}
allRootPaths.push_back(directoryPath);
}
currentConfiguration->setRootPath(allRootPaths);
currentConfiguration->save();
}
d->mFileListener.setAllRootPaths(allRootPaths);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment