QMimeDatabasePrivate: deduplicate QStandardPaths uses

Change-Id: I81dc76ddcf2aaa8aa6fdca504384ed72ad27f344
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Igor Kushnir 2021-12-12 17:46:04 +02:00
parent 0dbbda670d
commit b330016cf2

View File

@ -101,6 +101,11 @@ bool QMimeDatabasePrivate::shouldCheck()
return true;
}
static QStringList locateMimeDirectories()
{
return QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("mime"), QStandardPaths::LocateDirectory);
}
#if defined(Q_OS_UNIX) && !defined(Q_OS_NACL) && !defined(Q_OS_INTEGRITY)
# define QT_USE_MMAP
#endif
@ -108,7 +113,7 @@ bool QMimeDatabasePrivate::shouldCheck()
void QMimeDatabasePrivate::loadProviders()
{
// We use QStandardPaths every time to check if new files appeared
const QStringList mimeDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("mime"), QStandardPaths::LocateDirectory);
const QStringList mimeDirs = locateMimeDirectories();
const auto fdoIterator = std::find_if(mimeDirs.constBegin(), mimeDirs.constEnd(), [](const QString &mimeDir) -> bool {
return QFileInfo::exists(mimeDir + QLatin1String("/packages/freedesktop.org.xml")); }
);
@ -249,7 +254,7 @@ void QMimeDatabasePrivate::loadMimeTypePrivate(QMimeTypePrivate &mimePrivate)
const QString file = mimePrivate.name + QLatin1String(".xml");
qWarning() << "No file found for" << file << ", even though update-mime-info said it would exist.\n"
"Either it was just removed, or the directory doesn't have executable permission..."
<< QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("mime"), QStandardPaths::LocateDirectory);
<< locateMimeDirectories();
}
mimePrivate.loaded = true;
}