20 #include <QCoreApplication>
23 #if defined(Q_OS_LINUX)
32 QObject::connect( &mFileSystemWatcher, &QFileSystemWatcher::fileChanged,
this, &QgsCapabilitiesCache::removeChangedEntry );
34 #if defined(Q_OS_LINUX)
35 QObject::connect( &mTimer, &QTimer::timeout,
this, &QgsCapabilitiesCache::removeOutdatedEntries );
41 QCoreApplication::processEvents();
43 if ( mCachedCapabilities.contains( configFilePath ) && mCachedCapabilities[ configFilePath ].contains( key ) )
45 return &mCachedCapabilities[ configFilePath ][ key ];
55 if ( mCachedCapabilities.size() > 40 )
58 const QHash<QString, QHash<QString, QDomDocument> >::iterator capIt = mCachedCapabilities.begin();
59 mFileSystemWatcher.removePath( capIt.key() );
60 mCachedCapabilities.erase( capIt );
63 if ( !mCachedCapabilities.contains( configFilePath ) )
65 mFileSystemWatcher.addPath( configFilePath );
66 mCachedCapabilities.insert( configFilePath, QHash<QString, QDomDocument>() );
69 mCachedCapabilities[ configFilePath ].insert( key, doc->cloneNode().toDocument() );
71 #if defined(Q_OS_LINUX)
72 struct statfs sStatFS;
73 if ( statfs( configFilePath.toUtf8().constData(), &sStatFS ) == 0 &&
74 ( sStatFS.f_type == 0x6969 ||
75 sStatFS.f_type == 0x517b ||
76 sStatFS.f_type == 0xff534d42ul ||
77 sStatFS.f_type == 0xfe534d42ul ) )
79 const QFileInfo fi( configFilePath );
80 mCachedCapabilitiesTimestamps[ configFilePath ] = fi.lastModified();
88 mCachedCapabilities.remove( path );
89 mCachedCapabilitiesTimestamps.remove( path );
90 mFileSystemWatcher.removePath( path );
93 void QgsCapabilitiesCache::removeChangedEntry(
const QString &path )
95 QgsDebugMsg( QStringLiteral(
"Remove capabilities cache entry because file changed" ) );
99 void QgsCapabilitiesCache::removeOutdatedEntries()
101 QgsDebugMsg( QStringLiteral(
"Checking for outdated entries" ) );
102 for (
const QString &configFilePath : mCachedCapabilitiesTimestamps.keys() )
104 const QFileInfo fi( configFilePath );
105 if ( !fi.exists() || mCachedCapabilitiesTimestamps[ configFilePath ] < fi.lastModified() )
106 removeChangedEntry( configFilePath );
109 if ( !mCachedCapabilitiesTimestamps.isEmpty() )
111 mTimer.start( 1000 );
void removeCapabilitiesDocument(const QString &path)
Remove capabilities document.
const QDomDocument * searchCapabilitiesDocument(const QString &configFilePath, const QString &key)
Returns cached capabilities document (or 0 if document for configuration file not in cache)
void insertCapabilitiesDocument(const QString &configFilePath, const QString &key, const QDomDocument *doc)
Inserts new capabilities document (creates a copy of the document, does not take ownership)