[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kdecore/services
From:       David Faure <faure () kde ! org>
Date:       2010-11-13 1:53:44
Message-ID: 20101113015344.7D82DAC89E () svn ! kde ! org
[Download RAW message or body]

SVN commit 1196331 by dfaure:

Rather than multiplying the static mutexes, move the code to the KMimeTypeRepository \
singleton and use its mutex there. This is a new fix for sharedMimeInfoVersion(), as \
                well as a fix for useFavIcons which also had static bools.
CCMAIL: adawit@kde.org


 M  +4 -38     kmimetype.cpp  
 M  +48 -1     kmimetyperepository.cpp  
 M  +10 -0     kmimetyperepository_p.h  


--- trunk/KDE/kdelibs/kdecore/services/kmimetype.cpp #1196330:1196331
@@ -22,8 +22,6 @@
 #include "kmimetypefactory.h"
 #include "kmimetyperepository_p.h"
 
-#include <ksharedconfig.h>
-#include <kconfiggroup.h>
 #include <kdebug.h>
 #include <kde_file.h> // KDE::stat
 #include <kdeversion.h> // KDE_MAKE_VERSION
@@ -471,18 +469,9 @@
 
 QString KMimeType::favIconForUrl( const KUrl& url )
 {
-    // this method will be called quite often, so better not read the config
-    // again and again.
-    static bool useFavIcons = true;
-    static bool check = true;
-    if ( check ) {
-        check = false;
-        KConfigGroup cg( KGlobal::config(), "HTML Settings" );
-        useFavIcons = cg.readEntry("EnableFavicon", true);
-    }
-
-    if ( url.isLocalFile() || !url.protocol().startsWith(QLatin1String("http"))
-         || !useFavIcons )
+    if (url.isLocalFile()
+        || !url.protocol().startsWith(QLatin1String("http"))
+        || !KMimeTypeRepository::self()->useFavIcons())
         return QString();
 
     QDBusInterface kded( QString::fromLatin1("org.kde.kded"),
@@ -712,31 +701,8 @@
 
 int KMimeType::sharedMimeInfoVersion()
 {
-    static int s_version = 0;
-    static QMutex s_versionMutex;
-    QMutexLocker locker(&s_versionMutex);
-    if (s_version == 0) {
-        QProcess smi;
-        const QString umd = \
                KStandardDirs::findExe(QString::fromLatin1("update-mime-database"));
-        if (umd.isEmpty()) {
-            kWarning() << "update-mime-database not found!";
-            s_version = -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) {
-                s_version = 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;
-                s_version = -1;
+    return KMimeTypeRepository::self()->sharedMimeInfoVersion();
             }
-        }
-    }
-    return s_version;
-}
 
 QString KMimeType::mainExtension() const
 {
--- trunk/KDE/kdelibs/kdecore/services/kmimetyperepository.cpp #1196330:1196331
@@ -19,11 +19,15 @@
 
 #include "kmimetyperepository_p.h"
 #include <kstandarddirs.h>
-#include <QFile>
+#include <ksharedconfig.h>
+#include <kconfiggroup.h>
 #include "kmimetype.h"
+#include <kdeversion.h> // KDE_MAKE_VERSION
 #include <kmessage.h>
 #include <klocale.h>
 #include "kfoldermimetype.h"
+#include <QFile>
+#include <QProcess>
 
 extern int servicesDebugArea();
 
@@ -40,6 +44,9 @@
       m_globsFilesParsed(false),
       m_patternsMapCalculated(false),
       m_mimeTypesChecked(false),
+      m_useFavIcons(true),
+      m_useFavIconsChecked(false),
+      m_sharedMimeInfoVersion(0),
       m_mutex(QReadWriteLock::Recursive)
 {
 }
@@ -662,3 +669,43 @@
 
 }
 
+bool KMimeTypeRepository::useFavIcons()
+{
+    // this method will be called quite often, so better not read the config
+    // again and again.
+    m_mutex.lockForWrite();
+    if (!m_useFavIconsChecked) {
+        m_useFavIconsChecked = true;
+        KConfigGroup cg( KGlobal::config(), "HTML Settings" );
+        m_useFavIcons = cg.readEntry("EnableFavicon", true);
+    }
+    m_mutex.unlock();
+    return m_useFavIcons;
+}
+
+int KMimeTypeRepository::sharedMimeInfoVersion()
+{
+    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;
+            }
+        }
+    }
+    m_mutex.unlock();
+    return m_sharedMimeInfoVersion;
+}
--- trunk/KDE/kdelibs/kdecore/services/kmimetyperepository_p.h #1196330:1196331
@@ -79,6 +79,13 @@
 
     KMimeType::Ptr defaultMimeTypePtr();
 
+    /**
+     * Returns true if KMimeType::favIconForUrl should talk to kded's favicons \
module. +     */
+    bool useFavIcons();
+
+    int sharedMimeInfoVersion();
+
 private: // only for KMimeType and unittests
     friend class KMimeType;
     friend class KMimeFileParserTest;
@@ -159,6 +166,9 @@
     bool m_globsFilesParsed;
     bool m_patternsMapCalculated;
     bool m_mimeTypesChecked;
+    bool m_useFavIcons;
+    bool m_useFavIconsChecked;
+    int m_sharedMimeInfoVersion;
     QList<KMimeMagicRule> m_magicRules;
     KMimeGlobsFileParser::AllGlobs m_globs;
     KMimeType::Ptr m_defaultMimeType;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic