1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-03-20 18:50:15 +03:00

set a limit for backgrounds hash size

--Latte should remember 300 backgrounds
maximum and afterwards that cache is removed.
That way we can avoid cases that because
a slideshow plugin uses too many wallpapers
does not make Latte to have high memory usage.
This commit is contained in:
Michail Vourlakos 2019-02-21 00:34:36 +02:00
parent c6178e58bd
commit 19815138c5
2 changed files with 16 additions and 0 deletions

View File

@ -37,6 +37,8 @@
#include <KConfigGroup>
#include <KDirWatch>
#define MAXHASHSIZE 300
#define PLASMACONFIG "plasma-org.kde.plasma.desktop-appletsrc"
#define DEFAULTWALLPAPER "/usr/share/wallpapers/Next/contents/images/1920x1080.png"
@ -256,6 +258,10 @@ bool BackgroundCache::areaIsBusy(float bright1, float bright2)
//! subareas. If the difference it too big then the area is busy
void BackgroundCache::updateImageCalculations(QString imageFile, Plasma::Types::Location location)
{
if (m_hintsCache.size() > MAXHASHSIZE) {
cleanupHashes();
}
//! if it is a local image
QImage image(imageFile);
@ -401,6 +407,15 @@ bool BackgroundCache::busyForFile(QString imageFile, Plasma::Types::Location loc
return false;
}
void BackgroundCache::cleanupHashes()
{
if (m_hintsCache.count() <= MAXHASHSIZE) {
return;
}
m_hintsCache.clear();
}
void BackgroundCache::setBackgroundFromBroadcast(QString activity, QString screen, QString filename)
{
if (QFileInfo(filename).exists()) {

View File

@ -80,6 +80,7 @@ private:
float brightnessFromArea(QImage &image, int firstRow, int firstColumn, int endRow, int endColumn);
QString backgroundFromConfig(const KConfigGroup &config, QString wallpaperPlugin) const;
void cleanupHashes();
void updateImageCalculations(QString imageFile, Plasma::Types::Location location);
private: