mirror of
https://github.com/KDE/latte-dock.git
synced 2025-03-20 18:50:15 +03:00
fixes for BackgroundCache
This commit is contained in:
parent
fabd989146
commit
f1712ca7a5
@ -20,6 +20,7 @@
|
||||
|
||||
#include "backgroundtracker.h"
|
||||
|
||||
#include "plasma/extended/backgroundcache.h"
|
||||
|
||||
namespace Latte {
|
||||
|
||||
@ -31,6 +32,8 @@ BackgroundTracker::BackgroundTracker(QObject *parent)
|
||||
connect(this, &BackgroundTracker::activityChanged, this, &BackgroundTracker::update);
|
||||
connect(this, &BackgroundTracker::locationChanged, this, &BackgroundTracker::update);
|
||||
connect(this, &BackgroundTracker::screenNameChanged, this, &BackgroundTracker::update);
|
||||
|
||||
connect(m_cache, &PlasmaExtended::BackgroundCache::backgroundChanged, this, &BackgroundTracker::backgroundChanged);
|
||||
}
|
||||
|
||||
BackgroundTracker::~BackgroundTracker()
|
||||
@ -92,6 +95,13 @@ void BackgroundTracker::setScreenName(QString name)
|
||||
emit screenNameChanged();
|
||||
}
|
||||
|
||||
void BackgroundTracker::backgroundChanged(const QString &activity, const QString &screenName)
|
||||
{
|
||||
if (m_activity==activity && m_screenName==screenName) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void BackgroundTracker::update()
|
||||
{
|
||||
if (m_activity.isEmpty() || m_screenName.isEmpty()) {
|
||||
|
@ -62,6 +62,7 @@ signals:
|
||||
void screenNameChanged();
|
||||
|
||||
private slots:
|
||||
void backgroundChanged(const QString &activity, const QString &screenName);
|
||||
void update();
|
||||
|
||||
private:
|
||||
|
@ -106,19 +106,34 @@ QString BackgroundCache::backgroundFromConfig(const KConfigGroup &config) const
|
||||
return QString();
|
||||
}
|
||||
|
||||
void BackgroundCache::reload() {
|
||||
bool BackgroundCache::isDesktopContainment(const KConfigGroup &containment) const
|
||||
{
|
||||
const auto type = containment.readEntry("plugin", QString());
|
||||
|
||||
if (type == "org.kde.desktopcontainment" || type == "org.kde.plasma.folder" ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void BackgroundCache::reload()
|
||||
{
|
||||
// Traversing through all containments in search for
|
||||
// containments that define activities in plasma
|
||||
KConfigGroup plasmaConfigContainments = m_plasmaConfig->group("Containments");
|
||||
|
||||
//!activityId and screen names for which their background was updated
|
||||
QHash<QString, QList<QString>> updates;
|
||||
|
||||
for (const auto &containmentId : plasmaConfigContainments.groupList()) {
|
||||
const auto containment = plasmaConfigContainments.group(containmentId);
|
||||
const auto lastScreen = containment.readEntry("lastScreen", 0);
|
||||
const auto activity = containment.readEntry("activityId", QString());
|
||||
|
||||
// Ignore the containment if the activity is not defined
|
||||
if (activity.isEmpty()) continue;
|
||||
//! Ignore the containment if the activity is not defined or
|
||||
//! the containment is not a plasma desktop
|
||||
if (activity.isEmpty() || !isDesktopContainment(containment)) continue;
|
||||
|
||||
const auto returnedBackground = backgroundFromConfig(containment);
|
||||
|
||||
@ -130,12 +145,25 @@ void BackgroundCache::reload() {
|
||||
|
||||
if (background.isEmpty()) continue;
|
||||
|
||||
m_backgrounds[activity][m_pool->connector(lastScreen)] = background;
|
||||
QString screenName = m_pool->connector(lastScreen);
|
||||
|
||||
if(!m_backgrounds.contains(activity)
|
||||
|| !m_backgrounds[activity].contains(screenName)
|
||||
|| m_backgrounds[activity][screenName] != background) {
|
||||
|
||||
updates[activity].append(screenName);
|
||||
}
|
||||
|
||||
m_backgrounds[activity][screenName] = background;
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
|
||||
qDebug() << m_backgrounds;
|
||||
foreach (auto activity, updates.keys()) {
|
||||
foreach (auto screen, updates[activity]) {
|
||||
emit backgroundChanged(activity, screen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString BackgroundCache::background(QString activity, QString screen)
|
||||
|
@ -51,6 +51,9 @@ public:
|
||||
|
||||
QString background(QString activity, QString screen);
|
||||
|
||||
signals:
|
||||
void backgroundChanged(const QString &activity, const QString &screenName);
|
||||
|
||||
private slots:
|
||||
void reload();
|
||||
void settingsFileChanged(const QString &file);
|
||||
@ -58,6 +61,7 @@ private slots:
|
||||
private:
|
||||
BackgroundCache(QObject *parent = nullptr);
|
||||
|
||||
bool isDesktopContainment(const KConfigGroup &containment) const;
|
||||
float luminasFromFile(QString imageFile, Plasma::Types::Location location);
|
||||
QString backgroundFromConfig(const KConfigGroup &config) const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user