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 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 == 0xff534d42 ) )
78 QFileInfo fi( configFilePath );
79 mCachedCapabilitiesTimestamps[ configFilePath ] = fi.lastModified();
87 mCachedCapabilities.remove( path );
88 mCachedCapabilitiesTimestamps.remove( path );
89 mFileSystemWatcher.removePath( path );
92 void QgsCapabilitiesCache::removeChangedEntry(
const QString &path )
94 QgsDebugMsg( QStringLiteral(
"Remove capabilities cache entry because file changed" ) );
98 void QgsCapabilitiesCache::removeOutdatedEntries()
100 QgsDebugMsg( QStringLiteral(
"Checking for outdated entries" ) );
101 for (
const QString &configFilePath : mCachedCapabilitiesTimestamps.keys() )
103 QFileInfo fi( configFilePath );
104 if ( !fi.exists() || mCachedCapabilitiesTimestamps[ configFilePath ] < fi.lastModified() )
105 removeChangedEntry( configFilePath );
108 if ( !mCachedCapabilitiesTimestamps.isEmpty() )
110 mTimer.start( 1000 );
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) ...
const QDomDocument * searchCapabilitiesDocument(const QString &configFilePath, const QString &key)
Returns cached capabilities document (or 0 if document for configuration file not in cache) ...
void removeCapabilitiesDocument(const QString &path)
Remove capabilities document.