File indexing completed on 2024-04-28 16:49:37

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 
0021 #include "backgroundtracker.h"
0022 
0023 // local
0024 #include "plasma/extended/backgroundcache.h"
0025 
0026 namespace Latte {
0027 
0028 BackgroundTracker::BackgroundTracker(QObject *parent)
0029     : QObject(parent)
0030 {
0031     m_cache = PlasmaExtended::BackgroundCache::self();
0032 
0033     connect(this, &BackgroundTracker::activityChanged, this, &BackgroundTracker::update);
0034     connect(this, &BackgroundTracker::locationChanged, this, &BackgroundTracker::update);
0035     connect(this, &BackgroundTracker::screenNameChanged, this, &BackgroundTracker::update);
0036 
0037     connect(m_cache, &PlasmaExtended::BackgroundCache::backgroundChanged, this, &BackgroundTracker::backgroundChanged);
0038 }
0039 
0040 BackgroundTracker::~BackgroundTracker()
0041 {
0042 }
0043 
0044 bool BackgroundTracker::isBusy() const
0045 {
0046     return m_busy;
0047 }
0048 
0049 int BackgroundTracker::location() const
0050 {
0051     return m_location;
0052 }
0053 
0054 void BackgroundTracker::setLocation(int location)
0055 {
0056     Plasma::Types::Location pLocation = static_cast<Plasma::Types::Location>(location);
0057 
0058     if (m_location == pLocation) {
0059         return;
0060     }
0061 
0062     m_location = pLocation;
0063 
0064     emit locationChanged();
0065 }
0066 
0067 float BackgroundTracker::currentBrightness() const
0068 {
0069     return m_brightness;
0070 }
0071 
0072 QString BackgroundTracker::activity() const
0073 {
0074     return m_activity;
0075 }
0076 
0077 void BackgroundTracker::setActivity(QString id)
0078 {
0079     if (m_activity == id) {
0080         return;
0081     }
0082 
0083     m_activity = id;
0084 
0085     emit activityChanged();
0086 }
0087 
0088 QString BackgroundTracker::screenName() const
0089 {
0090     return m_screenName;
0091 }
0092 
0093 void BackgroundTracker::setScreenName(QString name)
0094 {
0095     if (m_screenName == name) {
0096         return;
0097     }
0098 
0099     m_screenName = name;
0100 
0101     emit screenNameChanged();
0102 }
0103 
0104 void BackgroundTracker::backgroundChanged(const QString &activity, const QString &screenName)
0105 {
0106     if (m_activity==activity && m_screenName==screenName) {
0107         update();
0108     }
0109 }
0110 
0111 void BackgroundTracker::update()
0112 {
0113     if (m_activity.isEmpty() || m_screenName.isEmpty()) {
0114         return;
0115     }
0116 
0117     m_brightness = m_cache->brightnessFor(m_activity, m_screenName, m_location);
0118     m_busy = m_cache->busyFor(m_activity, m_screenName, m_location);
0119 
0120     emit currentBrightnessChanged();
0121     emit isBusyChanged();
0122 }
0123 
0124 void BackgroundTracker::setBackgroundFromBroadcast(QString activity, QString screen, QString filename)
0125 {
0126     m_cache->setBackgroundFromBroadcast(activity, screen, filename);
0127 }
0128 
0129 void BackgroundTracker::setBroadcastedBackgroundsEnabled(QString activity, QString screen, bool enabled)
0130 {
0131     m_cache->setBroadcastedBackgroundsEnabled(activity, screen, enabled);
0132 }
0133 
0134 }