From 34130b9caf001682f1decb6ba69b80657b814ed0 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 27 Jul 2015 00:22:11 +0200 Subject: QMimeDatabase: use QElapsedTimer instead of QDateTime::currentDateTime() This reduces the number of syscalls greatly, by avoiding the timezone conversion every time. Change-Id: I39a54def4b45f25c6e037ced6943b05ddc749c9d Reviewed-by: Milian Wolff --- src/corelib/mimetypes/qmimeprovider.cpp | 5 ++--- src/corelib/mimetypes/qmimeprovider_p.h | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib/mimetypes') diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index 7342a5cd77..1ab1a44392 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -79,10 +79,9 @@ Q_CORE_EXPORT int qmime_secondsBetweenChecks = 5; // exported for the unit test bool QMimeProviderBase::shouldCheck() { - const QDateTime now = QDateTime::currentDateTime(); - if (m_lastCheck.isValid() && m_lastCheck.secsTo(now) < qmime_secondsBetweenChecks) + if (m_lastCheck.isValid() && m_lastCheck.elapsed() < qmime_secondsBetweenChecks * 1000) return false; - m_lastCheck = now; + m_lastCheck.start(); return true; } diff --git a/src/corelib/mimetypes/qmimeprovider_p.h b/src/corelib/mimetypes/qmimeprovider_p.h index 5a89ac23c3..eaf95942f7 100644 --- a/src/corelib/mimetypes/qmimeprovider_p.h +++ b/src/corelib/mimetypes/qmimeprovider_p.h @@ -51,6 +51,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -77,7 +78,7 @@ public: QMimeDatabasePrivate *m_db; protected: bool shouldCheck(); - QDateTime m_lastCheck; + QElapsedTimer m_lastCheck; }; /* -- cgit v1.2.3 From af3152adee2de79c03c0926400e920122b669c4d Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Mon, 13 Jul 2015 15:42:35 +0200 Subject: QMimeProvider: Do not crash when globPatterns is empty. Change-Id: I351a533a1f03ac2e7bdec876b657a80fac60b2ed Reviewed-by: Milian Wolff --- src/corelib/mimetypes/qmimeprovider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/mimetypes') diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index 1ab1a44392..dab5bb81c9 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -624,7 +624,7 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data) // Let's assume that shared-mime-info is at least version 0.70 // Otherwise we would need 1) a version check, and 2) code for parsing patterns from the globs file. #if 1 - if (!mainPattern.isEmpty() && data.globPatterns.first() != mainPattern) { + if (!mainPattern.isEmpty() && (data.globPatterns.isEmpty() || data.globPatterns.first() != mainPattern)) { // ensure it's first in the list of patterns data.globPatterns.removeAll(mainPattern); data.globPatterns.prepend(mainPattern); -- cgit v1.2.3 From 4ccf5c6f4a411d367749565323f7c7fd469b025e Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 13 Aug 2015 23:51:34 +0200 Subject: QMimeDatabase: adapt to changes in shared-mime-info 1.3 The generated xml file is now lowercase. This was changed in shared-mime-info 3805d0bcf2. It led to runtime warnings "No file found for ...", which helped notice the bug. Change-Id: I31f0fc7f0fe8a098c3f79c0bcbeeb1909d2cc05a Reviewed-by: Thiago Macieira --- src/corelib/mimetypes/qmimeprovider.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/corelib/mimetypes') diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index dab5bb81c9..887db51e5c 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -560,10 +560,13 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data) // load comment and globPatterns const QString file = data.name + QLatin1String(".xml"); - const QStringList mimeFiles = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1("mime/") + file); + // shared-mime-info since 1.3 lowercases the xml files + QStringList mimeFiles = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1("mime/") + file.toLower()); if (mimeFiles.isEmpty()) { - // TODO: ask Thiago about this - qWarning() << "No file found for" << file << ", even though the file appeared in a directory listing."; + mimeFiles = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1("mime/") + file); // pre-1.3 + } + if (mimeFiles.isEmpty()) { + qWarning() << "No file found for" << file << ", even though update-mime-info said it would exist."; qWarning() << "Either it was just removed, or the directory doesn't have executable permission..."; qWarning() << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime"), QStandardPaths::LocateDirectory); return; -- cgit v1.2.3