schedule a rect cache sync when stuff gets in
do a disc sync with a 2 minutes delay
This commit is contained in:
parent
0b10a16113
commit
0596cf176f
@ -69,10 +69,16 @@ ThemePrivate::ThemePrivate(QObject *parent)
|
||||
ThemeConfig config;
|
||||
cacheTheme = config.cacheTheme();
|
||||
|
||||
saveTimer = new QTimer(this);
|
||||
saveTimer->setSingleShot(true);
|
||||
saveTimer->setInterval(600);
|
||||
QObject::connect(saveTimer, SIGNAL(timeout()), this, SLOT(scheduledCacheUpdate()));
|
||||
pixmapSaveTimer = new QTimer(this);
|
||||
pixmapSaveTimer->setSingleShot(true);
|
||||
pixmapSaveTimer->setInterval(600);
|
||||
QObject::connect(pixmapSaveTimer, SIGNAL(timeout()), this, SLOT(scheduledCacheUpdate()));
|
||||
|
||||
rectSaveTimer = new QTimer(this);
|
||||
rectSaveTimer->setSingleShot(true);
|
||||
//2 minutes
|
||||
rectSaveTimer->setInterval(2 * 60 * 1000);
|
||||
QObject::connect(rectSaveTimer, SIGNAL(timeout()), this, SLOT(saveSvgElementsCache()));
|
||||
|
||||
updateNotificationTimer = new QTimer(this);
|
||||
updateNotificationTimer->setSingleShot(true);
|
||||
@ -290,7 +296,7 @@ void ThemePrivate::discardCache(CacheTypes caches)
|
||||
{
|
||||
if (caches & PixmapCache) {
|
||||
pixmapsToCache.clear();
|
||||
saveTimer->stop();
|
||||
pixmapSaveTimer->stop();
|
||||
if (pixmapCache) {
|
||||
pixmapCache->clear();
|
||||
}
|
||||
@ -465,6 +471,21 @@ void ThemePrivate::settingsChanged(bool emitChanges)
|
||||
setThemeName(cg.readEntry("name", ThemePrivate::defaultTheme), false, emitChanges);
|
||||
}
|
||||
|
||||
void ThemePrivate::saveSvgElementsCache()
|
||||
{
|
||||
if (svgElementsCache) {
|
||||
QHashIterator<QString, QSet<QString> > it(invalidElements);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
KConfigGroup imageGroup(svgElementsCache, it.key());
|
||||
imageGroup.writeEntry("invalidElements", it.value().toList()); //FIXME: add QSet support to KConfig
|
||||
}
|
||||
|
||||
//Pretty drastic, but this is executed only very rarely
|
||||
svgElementsCache->sync();
|
||||
}
|
||||
}
|
||||
|
||||
QColor ThemePrivate::color(Theme::ColorRole role) const
|
||||
{
|
||||
switch (role) {
|
||||
|
@ -94,6 +94,7 @@ public Q_SLOTS:
|
||||
void onAppExitCleanup();
|
||||
void notifyOfChanged();
|
||||
void settingsChanged(bool emitChanges);
|
||||
void saveSvgElementsCache();
|
||||
|
||||
Q_SIGNALS:
|
||||
void themeChanged();
|
||||
@ -134,7 +135,8 @@ public:
|
||||
QHash<QString, QString> idsToCache;
|
||||
QHash<styles, QString> cachedStyleSheets;
|
||||
QHash<QString, QString> discoveries;
|
||||
QTimer *saveTimer;
|
||||
QTimer *pixmapSaveTimer;
|
||||
QTimer *rectSaveTimer;
|
||||
QTimer *updateNotificationTimer;
|
||||
unsigned cacheSize;
|
||||
CacheTypes cachesToDiscard;
|
||||
|
@ -91,17 +91,7 @@ Theme::Theme(const QString &themeName, QObject *parent)
|
||||
|
||||
Theme::~Theme()
|
||||
{
|
||||
if (d->svgElementsCache) {
|
||||
QHashIterator<QString, QSet<QString> > it(d->invalidElements);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
KConfigGroup imageGroup(d->svgElementsCache, it.key());
|
||||
imageGroup.writeEntry("invalidElements", it.value().toList()); //FIXME: add QSet support to KConfig
|
||||
}
|
||||
|
||||
//The application is probably dying, last occasion to write to disk
|
||||
d->svgElementsCache->sync();
|
||||
}
|
||||
d->saveSvgElementsCache();
|
||||
|
||||
if (d == ThemePrivate::globalTheme) {
|
||||
if (!ThemePrivate::globalThemeRefCount.deref()) {
|
||||
@ -346,8 +336,8 @@ void Theme::insertIntoCache(const QString &key, const QPixmap &pix, const QStrin
|
||||
d->keysToCache.insert(key, id);
|
||||
d->idsToCache.insert(id, key);
|
||||
|
||||
//always start timer in d->saveTimer's thread
|
||||
QMetaObject::invokeMethod(d->saveTimer, "start", Qt::QueuedConnection);
|
||||
//always start timer in d->pixmapSaveTimer's thread
|
||||
QMetaObject::invokeMethod(d->pixmapSaveTimer, "start", Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
@ -428,6 +418,8 @@ void Theme::insertIntoRectsCache(const QString &image, const QString &element, c
|
||||
it.value().insert(element);
|
||||
}
|
||||
}
|
||||
|
||||
d->rectSaveTimer->start();
|
||||
}
|
||||
|
||||
void Theme::invalidateRectsCache(const QString &image)
|
||||
|
Loading…
Reference in New Issue
Block a user