support wallpaper slideshows

pull/5/head
Michail Vourlakos 6 years ago
parent bd688bd2dc
commit 362d50a1fd

@ -22,5 +22,15 @@
<method name="contextMenuData">
<arg name="data" type="as" direction="out"/>
</method>
<method name="setBackgroundFromBroadcast">
<arg name="activity" type="s" direction="in"/>
<arg name="screenName" type="s" direction="in"/>
<arg name="filename" type="s" direction="in"/>
</method>
<method name="setBroadcastedBackgroundsEnabled">
<arg name="activity" type="s" direction="in"/>
<arg name="screenName" type="s" direction="in"/>
<arg name="enabled" type="b" direction="in"/>
</method>
</interface>
</node>

@ -63,7 +63,7 @@
#include <KPackage/PackageLoader>
#include <KAboutData>
#include <KActivities/Consumer>
#include <KDeclarative/QmlObject>
#include <KDeclarative/QmlObjectSharedEngine>
#include <KWindowSystem>
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/registry.h>
@ -128,6 +128,12 @@ Corona::Corona(bool defaultLayoutOnStartup, QString layoutNameOnStartUp, int use
m_viewsScreenSyncTimer.setInterval(m_universalSettings->screenTrackerInterval());
});
//! initialize the background tracer for broadcasted backgrounds
m_backgroundTracer = new KDeclarative::QmlObjectSharedEngine(this);
m_backgroundTracer->setInitializationDelayed(true);
m_backgroundTracer->setSource(kPackage().filePath("backgroundTracer"));
m_backgroundTracer->completeInitialization();
//! Dbus adaptor initialization
new LatteDockAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
@ -170,6 +176,7 @@ Corona::~Corona()
m_screenPool->deleteLater();
m_universalSettings->deleteLater();
m_plasmaScreenPool->deleteLater();
m_backgroundTracer->deleteLater();
m_themeExtended->deleteLater();
disconnect(m_activityConsumer, &KActivities::Consumer::serviceStatusChanged, this, &Corona::load);
@ -783,13 +790,13 @@ void Corona::showAlternativesForApplet(Plasma::Applet *applet)
Latte::View *latteView = (*views)[applet->containment()];
KDeclarative::QmlObject *qmlObj{nullptr};
KDeclarative::QmlObjectSharedEngine *qmlObj{nullptr};
if (latteView) {
latteView->setAlternativesIsShown(true);
qmlObj = new KDeclarative::QmlObject(latteView);
qmlObj = new KDeclarative::QmlObjectSharedEngine(latteView);
} else {
qmlObj = new KDeclarative::QmlObject(this);
qmlObj = new KDeclarative::QmlObjectSharedEngine(this);
}
qmlObj->setInitializationDelayed(true);
@ -814,10 +821,10 @@ void Corona::showAlternativesForApplet(Plasma::Applet *applet)
return;
}
QMutableListIterator<KDeclarative::QmlObject *> it(m_alternativesObjects);
QMutableListIterator<KDeclarative::QmlObjectSharedEngine *> it(m_alternativesObjects);
while (it.hasNext()) {
KDeclarative::QmlObject *obj = it.next();
KDeclarative::QmlObjectSharedEngine *obj = it.next();
if (obj == qmlObj) {
it.remove();
@ -835,10 +842,10 @@ void Corona::alternativesVisibilityChanged(bool visible)
QObject *root = sender();
QMutableListIterator<KDeclarative::QmlObject *> it(m_alternativesObjects);
QMutableListIterator<KDeclarative::QmlObjectSharedEngine *> it(m_alternativesObjects);
while (it.hasNext()) {
KDeclarative::QmlObject *obj = it.next();
KDeclarative::QmlObjectSharedEngine *obj = it.next();
if (obj->rootObject() == root) {
it.remove();
@ -1003,6 +1010,28 @@ QStringList Corona::contextMenuData()
return data;
}
void Corona::setBackgroundFromBroadcast(QString activity, QString screenName, QString filename)
{
if (filename.startsWith("file://")) {
filename = filename.remove(0,7);
}
QMetaObject::invokeMethod(m_backgroundTracer->rootObject(),
"setBackgroundFromBroadcast",
Q_ARG(QVariant, activity),
Q_ARG(QVariant, screenName),
Q_ARG(QVariant, filename));
}
void Corona::setBroadcastedBackgroundsEnabled(QString activity, QString screenName, bool enabled)
{
QMetaObject::invokeMethod(m_backgroundTracer->rootObject(),
"setBroadcastedBackgroundsEnabled",
Q_ARG(QVariant, activity),
Q_ARG(QVariant, screenName),
Q_ARG(QVariant, enabled));
}
inline void Corona::qmlRegisterTypes() const
{
qmlRegisterType<QScreen>();

@ -36,7 +36,7 @@
#include <KAboutApplicationDialog>
namespace KDeclarative {
class QmlObject;
class QmlObjectSharedEngine;
}
namespace Plasma {
@ -125,10 +125,13 @@ public:
public slots:
void aboutApplication();
void activateLauncherMenu();
//! they are separated with a "-" character
void windowColorScheme(QString windowIdAndScheme);
void loadDefaultLayout() override;
void setBackgroundFromBroadcast(QString activity, QString screenName, QString filename);
void setBroadcastedBackgroundsEnabled(QString activity, QString screenName, bool enabled);
//! values are separated with a "-" character
void windowColorScheme(QString windowIdAndScheme);
void updateDockItemBadge(QString identifier, QString value);
void unload();
signals:
@ -171,7 +174,9 @@ private:
QString m_layoutNameOnStartUp;
QList<KDeclarative::QmlObject *> m_alternativesObjects;
QList<KDeclarative::QmlObjectSharedEngine *> m_alternativesObjects;
KDeclarative::QmlObjectSharedEngine *m_backgroundTracer;
QTimer m_viewsScreenSyncTimer;

@ -66,6 +66,8 @@ void Package::initPackage(KPackage::Package *package)
package->addFileDefinition("themesExtendedInfo", QStringLiteral("themes/themesExtendedInforc"), i18n("a file that contains extended information for plasma themes"));
package->addFileDefinition("backgroundTracer", QStringLiteral("scripting/BackgroundTracer.qml"), i18n("a qml file that is used to publish broadcasted backgrounds"));
package->setFallbackPackage(fallback);
qDebug() << "package is valid" << package->isValid();
}

@ -120,4 +120,14 @@ void BackgroundTracker::update()
emit isBusyChanged();
}
void BackgroundTracker::setBackgroundFromBroadcast(QString activity, QString screen, QString filename)
{
m_cache->setBackgroundFromBroadcast(activity, screen, filename);
}
void BackgroundTracker::setBroadcastedBackgroundsEnabled(QString activity, QString screen, bool enabled)
{
m_cache->setBroadcastedBackgroundsEnabled(activity, screen, enabled);
}
}

@ -59,6 +59,10 @@ public:
QString screenName() const;
void setScreenName(QString name);
public slots:
Q_INVOKABLE void setBackgroundFromBroadcast(QString activity, QString screen, QString filename);
Q_INVOKABLE void setBroadcastedBackgroundsEnabled(QString activity, QString screen, bool enabled);
signals:
void activityChanged();
void currentBrightnessChanged();

@ -24,7 +24,9 @@
// Qt
#include <QDebug>
#include <QFileInfo>
#include <QImage>
#include <QList>
#include <QRgb>
#include <QtMath>
@ -144,10 +146,16 @@ void BackgroundCache::reload()
background = returnedBackground.mid(7);
}
if (background.isEmpty()) continue;
if (background.isEmpty()) {
continue;
}
QString screenName = m_pool->connector(lastScreen);
if (backgroundIsBroadcasted(activity, screenName)) {
continue;
}
if(!m_backgrounds.contains(activity)
|| !m_backgrounds[activity].contains(screenName)
|| m_backgrounds[activity][screenName] != background) {
@ -387,5 +395,38 @@ bool BackgroundCache::busyForFile(QString imageFile, Plasma::Types::Location loc
return false;
}
void BackgroundCache::setBackgroundFromBroadcast(QString activity, QString screen, QString filename)
{
if (QFileInfo(filename).exists()) {
setBroadcastedBackgroundsEnabled(activity, screen, true);
m_backgrounds[activity][screen] = filename;
emit backgroundChanged(activity, screen);
}
}
void BackgroundCache::setBroadcastedBackgroundsEnabled(QString activity, QString screen, bool enabled)
{
if (enabled && !backgroundIsBroadcasted(activity, screen)) {
if (!m_broadcasted.contains(activity)) {
m_broadcasted[activity] = QList<QString>();
}
m_broadcasted[activity].append(screen);
} else if (!enabled && backgroundIsBroadcasted(activity, screen)) {
m_broadcasted[activity].removeAll(screen);
if (m_broadcasted[activity].isEmpty()) {
m_broadcasted.remove(activity);
}
reload();
}
}
bool BackgroundCache::backgroundIsBroadcasted(QString activity, QString screenName)
{
return m_broadcasted.contains(activity) && m_broadcasted[activity].contains(screenName);
}
}
}

@ -57,6 +57,9 @@ public:
QString background(QString activity, QString screen);
void setBackgroundFromBroadcast(QString activity, QString screen, QString filename);
void setBroadcastedBackgroundsEnabled(QString activity, QString screen, bool enabled);
signals:
void backgroundChanged(const QString &activity, const QString &screenName);
@ -67,6 +70,7 @@ private slots:
private:
BackgroundCache(QObject *parent = nullptr);
bool backgroundIsBroadcasted(QString activity, QString screenName);
bool areaIsBusy(float bright1, float bright2);
bool busyForFile(QString imageFile, Plasma::Types::Location location);
bool isDesktopContainment(const KConfigGroup &containment) const;
@ -84,6 +88,9 @@ private:
//! screen aware backgrounds: activity id, screen name, backgroundfile
QHash<QString, QHash<QString, QString>> m_backgrounds;
//! backgrounds that are broadcasted (not found through plasma files)
//! for specific: activity id, screen names tracked
QHash<QString, QList<QString>> m_broadcasted;
//! image file and brightness per edge
QHash<QString, EdgesHash> m_hintsCache;

@ -0,0 +1,39 @@
/*
* Copyright 2019 Michail Vourlakos <mvourlakos@gmail.com>
*
* This file is part of Latte-Dock
*
* Latte-Dock is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* Latte-Dock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.7
import org.kde.latte 0.2 as Latte
Item{
Latte.BackgroundTracker {
id: backgroundTracker
}
function setBackgroundFromBroadcast(activity, screen, filename) {
console.log(" Background Tracer set image ::: " + activity + " _ " + screen + " _ " + filename);
backgroundTracker.setBackgroundFromBroadcast(activity, screen, filename);
}
function setBroadcastedBackgroundsEnabled(activity, screen, enabled) {
console.log(" Background Tracer State ::: " + activity + " _ " + screen + " _ " + enabled);
backgroundTracker.setBroadcastedBackgroundsEnabled(activity, screen, enabled);
}
}
Loading…
Cancel
Save