mirror of
https://gitdl.cn/https://github.com/chakralinux/desktop.git
synced 2025-01-24 18:42:12 +08:00
120 lines
4.9 KiB
Diff
120 lines
4.9 KiB
Diff
commit 4d0569da8d362b6869158beb724319023e4c705a
|
|
Author: Dawit Alemayehu <adawit@kde.org>
|
|
Date: Fri Feb 4 18:29:51 2011 -0500
|
|
|
|
Workaround for the hang (freeze) when opening VLC's file dialog under KDE.
|
|
See http://git.reviewboard.kde.org/r/100539/ for the details.
|
|
|
|
BUG:260719
|
|
REVIEW:100539
|
|
(cherry picked from commit 7ca7e81303c50769e286897be0afe0793dabdf52)
|
|
|
|
diff --git a/kdecore/services/kmimetyperepository.cpp b/kdecore/services/kmimetyperepository.cpp
|
|
index 9f4c3ca..39e6a61 100644
|
|
--- a/kdecore/services/kmimetyperepository.cpp
|
|
+++ b/kdecore/services/kmimetyperepository.cpp
|
|
@@ -683,29 +683,84 @@ bool KMimeTypeRepository::useFavIcons()
|
|
return m_useFavIcons;
|
|
}
|
|
|
|
-int KMimeTypeRepository::sharedMimeInfoVersion()
|
|
+static void addPlatformSpecificPkgConfigPath(QStringList& paths)
|
|
{
|
|
- m_mutex.lockForWrite();
|
|
- if (m_sharedMimeInfoVersion == 0) {
|
|
- QProcess smi;
|
|
- const QString umd = KStandardDirs::findExe(QString::fromLatin1("update-mime-database"));
|
|
- if (umd.isEmpty()) {
|
|
- kWarning() << "update-mime-database not found!";
|
|
- m_sharedMimeInfoVersion = -1;
|
|
- } else {
|
|
- smi.start(umd, QStringList() << QString::fromLatin1("-v"));
|
|
- smi.waitForStarted();
|
|
- smi.waitForFinished();
|
|
- const QString out = QString::fromLocal8Bit(smi.readAllStandardError());
|
|
- QRegExp versionRe(QString::fromLatin1("update-mime-database \\(shared-mime-info\\) (\\d+)\\.(\\d+)(\\.(\\d+))?"));
|
|
- if (versionRe.indexIn(out) > -1) {
|
|
- m_sharedMimeInfoVersion = KDE_MAKE_VERSION(versionRe.cap(1).toInt(), versionRe.cap(2).toInt(), versionRe.cap(4).toInt());
|
|
- } else {
|
|
- kWarning() << "Unexpected version scheme from update-mime-database -v: got" << out;
|
|
- m_sharedMimeInfoVersion = -1;
|
|
+#if defined (Q_OS_FREEBSD)
|
|
+ paths << QLatin1String("/usr/local/libdata/pkgconfig"); // FreeBSD
|
|
+#elif defined(Q_OS_OPENBSD) || defined(Q_OS_NETBSD) || defined(Q_OS_SOLARIS)
|
|
+ paths << QLatin1String("/usr/local/lib/pkgconfig"); // {Net,Open}BSD/OpenSolaris
|
|
+#elif defined (Q_OS_UNIX)
|
|
+ paths << QLatin1String("/usr/share/pkgconfig"); // Linux and all other unix
|
|
+#endif
|
|
+}
|
|
+
|
|
+static int mimeDataBaseVersion()
|
|
+{
|
|
+ // TODO: Remove the #idef'ed code below once the issue is fixed either
|
|
+ // in QProcess or the shared-mime-info utility provides its version number.
|
|
+#ifdef Q_OS_UNIX
|
|
+ // Try to read the version number from the shared-mime-info.pc file
|
|
+ QStringList paths;
|
|
+ const QByteArray pkgConfigPath = qgetenv("PKG_CONFIG_PATH");
|
|
+ if (!pkgConfigPath.isEmpty()) {
|
|
+ paths << QFile::decodeName(pkgConfigPath).split(QLatin1Char(':'), QString::SkipEmptyParts);
|
|
+ }
|
|
+
|
|
+ // Add platform specific hard-coded default paths to the list...
|
|
+ addPlatformSpecificPkgConfigPath(paths);
|
|
+
|
|
+ Q_FOREACH(const QString& path, paths) {
|
|
+ const QString fileName = path + QLatin1String("/shared-mime-info.pc");
|
|
+ if (!QFile::exists(fileName)) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ QFile file (fileName);
|
|
+ if (!file.open(QIODevice::ReadOnly)) {
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ while (!file.atEnd()) {
|
|
+ const QByteArray line = file.readLine().simplified();
|
|
+ if (!line.startsWith("Version")) {
|
|
+ continue;
|
|
+ }
|
|
+ QRegExp versionRe(QString::fromLatin1("Version: (\\d+)\\.(\\d+)(\\.(\\d+))?"));
|
|
+ if (versionRe.indexIn(QString::fromLocal8Bit(line)) > -1) {
|
|
+ return KDE_MAKE_VERSION(versionRe.cap(1).toInt(), versionRe.cap(2).toInt(), versionRe.cap(4).toInt());
|
|
}
|
|
}
|
|
}
|
|
+#endif
|
|
+
|
|
+ // Execute "update-mime-database -v" to determine version number.
|
|
+ // NOTE: On *nix, the code below is known to cause freezes/hangs in apps
|
|
+ // that block signals. See https://bugs.kde.org/show_bug.cgi?id=260719.
|
|
+ const QString umd = KStandardDirs::findExe(QString::fromLatin1("update-mime-database"));
|
|
+ if (umd.isEmpty()) {
|
|
+ kWarning(servicesDebugArea()) << "update-mime-database not found!";
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ QProcess smi;
|
|
+ smi.start(umd, QStringList() << QString::fromLatin1("-v"));
|
|
+ smi.waitForStarted();
|
|
+ smi.waitForFinished();
|
|
+ const QString out = QString::fromLocal8Bit(smi.readAllStandardError());
|
|
+ QRegExp versionRe(QString::fromLatin1("update-mime-database \\(shared-mime-info\\) (\\d+)\\.(\\d+)(\\.(\\d+))?"));
|
|
+ if (versionRe.indexIn(out) > -1) {
|
|
+ return KDE_MAKE_VERSION(versionRe.cap(1).toInt(), versionRe.cap(2).toInt(), versionRe.cap(4).toInt());
|
|
+ }
|
|
+
|
|
+ kWarning(servicesDebugArea()) << "Unexpected version scheme from update-mime-database -v: got" << out;
|
|
+ return -1;
|
|
+}
|
|
+
|
|
+int KMimeTypeRepository::sharedMimeInfoVersion()
|
|
+{
|
|
+ m_mutex.lockForWrite();
|
|
+ if (m_sharedMimeInfoVersion == 0)
|
|
+ m_sharedMimeInfoVersion = mimeDataBaseVersion();
|
|
m_mutex.unlock();
|
|
return m_sharedMimeInfoVersion;
|
|
}
|