File indexing completed on 2024-05-12 17:04:39
0001 /* 0002 * Copyright 2018 Michail Vourlakos <mvourlakos@gmail.com> 0003 * 0004 * This file is part of Latte-Dock 0005 * 0006 * Latte-Dock is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * Latte-Dock is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef PLASMABACKGROUNDCACHE_H 0021 #define PLASMABACKGROUNDCACHE_H 0022 0023 // local 0024 #include "screenpool.h" 0025 0026 // Qt 0027 #include <QHash> 0028 #include <QObject> 0029 0030 // Plasma 0031 #include <Plasma> 0032 0033 // KDE 0034 #include <KConfigGroup> 0035 #include <KSharedConfig> 0036 0037 struct imageHints { 0038 bool busy{false}; 0039 float brightness{-1000}; 0040 }; 0041 0042 typedef QHash<Plasma::Types::Location, imageHints> EdgesHash; 0043 0044 namespace Latte { 0045 namespace PlasmaExtended { 0046 0047 class BackgroundCache: public QObject 0048 { 0049 Q_OBJECT 0050 0051 public: 0052 static BackgroundCache *self(); 0053 ~BackgroundCache() override; 0054 0055 bool busyFor(QString activity, QString screen, Plasma::Types::Location location); 0056 float brightnessFor(QString activity, QString screen, Plasma::Types::Location location); 0057 0058 QString background(QString activity, QString screen); 0059 0060 void setBackgroundFromBroadcast(QString activity, QString screen, QString filename); 0061 void setBroadcastedBackgroundsEnabled(QString activity, QString screen, bool enabled); 0062 0063 signals: 0064 void backgroundChanged(const QString &activity, const QString &screenName); 0065 0066 private slots: 0067 void reload(); 0068 void settingsFileChanged(const QString &file); 0069 0070 private: 0071 BackgroundCache(QObject *parent = nullptr); 0072 0073 bool backgroundIsBroadcasted(QString activity, QString screenName); 0074 bool pluginExistsFor(QString activity, QString screenName); 0075 bool areaIsBusy(float bright1, float bright2); 0076 bool busyForFile(QString imageFile, Plasma::Types::Location location); 0077 bool isDesktopContainment(const KConfigGroup &containment) const; 0078 0079 float brightnessForFile(QString imageFile, Plasma::Types::Location location); 0080 float brightnessFromArea(QImage &image, int firstRow, int firstColumn, int endRow, int endColumn); 0081 QString backgroundFromConfig(const KConfigGroup &config, QString wallpaperPlugin) const; 0082 0083 void cleanupHashes(); 0084 void updateImageCalculations(QString imageFile, Plasma::Types::Location location); 0085 0086 private: 0087 bool m_initialized{false}; 0088 0089 QString m_defaultWallpaperPath; 0090 0091 ScreenPool *m_pool{nullptr}; 0092 0093 //! screen aware backgrounds: activity id, screen name, backgroundfile 0094 QHash<QString, QHash<QString, QString>> m_backgrounds; 0095 0096 //! plugin names tracked: activity id, screen name, pluginName 0097 QHash<QString, QHash<QString, QString>> m_plugins; 0098 0099 //! backgrounds that are broadcasted (not found through plasma files): 0100 //! and have higher priority: activity id, screen names 0101 QHash<QString, QList<QString>> m_broadcasted; 0102 0103 //! image file and brightness per edge 0104 QHash<QString, EdgesHash> m_hintsCache; 0105 0106 KSharedConfig::Ptr m_plasmaConfig; 0107 }; 0108 0109 } 0110 } 0111 0112 #endif