feat(system): add backgroundVisible and reconnect Wallpaper to settings

main
reionwong 3 weeks ago
parent ba1fa5897c
commit 38fe85203f

@ -1,37 +1,73 @@
#include "wallpaper.h" #include "wallpaper.h"
#include <QDBusServiceWatcher>
Wallpaper::Wallpaper(QObject *parent) Wallpaper::Wallpaper(QObject *parent)
: QObject(parent) : QObject(parent)
, m_interface("com.cutefish.Settings", , m_interface(nullptr)
"/Theme", "com.cutefish.Theme",
QDBusConnection::sessionBus(), this)
{ {
if (m_interface.isValid()) { // The shell starts before cutefish-settings, so the signals are hooked up
connect(&m_interface, SIGNAL(wallpaperChanged(QString)), this, SLOT(onPathChanged(QString))); // again once the service appears; without this the desktop would keep the
connect(&m_interface, SIGNAL(darkModeDimsWallpaerChanged()), this, SIGNAL(dimsWallpaperChanged())); // background it read at startup for the rest of the session.
connect(&m_interface, SIGNAL(backgroundTypeChanged()), this, SIGNAL(typeChanged())); QDBusServiceWatcher *watcher = new QDBusServiceWatcher(this);
connect(&m_interface, SIGNAL(backgroundColorChanged()), this, SIGNAL(colorChanged())); watcher->setConnection(QDBusConnection::sessionBus());
} watcher->addWatchedService("com.cutefish.Settings");
connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &Wallpaper::init);
init();
}
void Wallpaper::init()
{
delete m_interface;
m_interface = new QDBusInterface("com.cutefish.Settings",
"/Theme", "com.cutefish.Theme",
QDBusConnection::sessionBus(), this);
if (!m_interface->isValid())
return;
connect(m_interface, SIGNAL(wallpaperChanged(QString)), this, SLOT(onPathChanged(QString)));
connect(m_interface, SIGNAL(darkModeDimsWallpaerChanged()), this, SIGNAL(dimsWallpaperChanged()));
connect(m_interface, SIGNAL(backgroundTypeChanged()), this, SIGNAL(typeChanged()));
connect(m_interface, SIGNAL(backgroundColorChanged()), this, SIGNAL(colorChanged()));
connect(m_interface, SIGNAL(backgroundVisibleChanged()), this, SIGNAL(backgroundVisibleChanged()));
emit typeChanged();
emit pathChanged();
emit colorChanged();
emit dimsWallpaperChanged();
emit backgroundVisibleChanged();
}
QVariant Wallpaper::themeProperty(const char *name) const
{
return m_interface ? m_interface->property(name) : QVariant();
} }
int Wallpaper::type() const int Wallpaper::type() const
{ {
return m_interface.property("backgroundType").toInt(); return themeProperty("backgroundType").toInt();
} }
QString Wallpaper::path() const QString Wallpaper::path() const
{ {
return m_interface.property("wallpaper").toString(); return themeProperty("wallpaper").toString();
} }
bool Wallpaper::dimsWallpaper() const bool Wallpaper::dimsWallpaper() const
{ {
return m_interface.property("darkModeDimsWallpaer").toBool(); return themeProperty("darkModeDimsWallpaer").toBool();
} }
QString Wallpaper::color() const QString Wallpaper::color() const
{ {
return m_interface.property("backgroundColor").toString(); return themeProperty("backgroundColor").toString();
}
bool Wallpaper::backgroundVisible() const
{
return themeProperty("backgroundVisible").toBool();
} }
void Wallpaper::onPathChanged(QString path) void Wallpaper::onPathChanged(QString path)

@ -4,6 +4,10 @@
#include <QObject> #include <QObject>
#include <QDBusInterface> #include <QDBusInterface>
/**
* The desktop background as cutefish-settings publishes it over
* com.cutefish.Theme: an image (type 0) or a plain colour (type 1).
*/
class Wallpaper : public QObject class Wallpaper : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -11,6 +15,7 @@ class Wallpaper : public QObject
Q_PROPERTY(QString path READ path NOTIFY pathChanged) Q_PROPERTY(QString path READ path NOTIFY pathChanged)
Q_PROPERTY(bool dimsWallpaper READ dimsWallpaper NOTIFY dimsWallpaperChanged) Q_PROPERTY(bool dimsWallpaper READ dimsWallpaper NOTIFY dimsWallpaperChanged)
Q_PROPERTY(QString color READ color NOTIFY colorChanged) Q_PROPERTY(QString color READ color NOTIFY colorChanged)
Q_PROPERTY(bool backgroundVisible READ backgroundVisible NOTIFY backgroundVisibleChanged)
public: public:
explicit Wallpaper(QObject *parent = nullptr); explicit Wallpaper(QObject *parent = nullptr);
@ -21,19 +26,26 @@ public:
bool dimsWallpaper() const; bool dimsWallpaper() const;
QString color() const; QString color() const;
bool backgroundVisible() const;
signals: signals:
void pathChanged(); void pathChanged();
void dimsWallpaperChanged(); void dimsWallpaperChanged();
void typeChanged(); void typeChanged();
void colorChanged(); void colorChanged();
void backgroundVisibleChanged();
private:
QVariant themeProperty(const char *name) const;
private slots: private slots:
void init();
void onPathChanged(QString path); void onPathChanged(QString path);
private: private:
QDBusInterface m_interface; // Recreated in init(): a QDBusInterface built while cutefish-settings is
QString m_wallpaper; // not on the bus caches a failed introspection and never recovers.
QDBusInterface *m_interface;
}; };
#endif // WALLPAPER_H #endif // WALLPAPER_H

Loading…
Cancel
Save