filemanager/src/desktop/desktopsettings.cpp

68 lines
1.9 KiB
C++
Raw Normal View History

2021-03-16 00:02:20 -07:00
#include "desktopsettings.h"
#include <QDBusServiceWatcher>
#include <QProcess>
DesktopSettings::DesktopSettings(QObject *parent)
: QObject(parent)
, m_interface("org.cutefish.Settings",
"/Theme", "org.cutefish.Theme",
QDBusConnection::sessionBus(), this)
{
QDBusServiceWatcher *watcher = new QDBusServiceWatcher(this);
watcher->setConnection(QDBusConnection::sessionBus());
watcher->addWatchedService("org.cutefish.Settings");
connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &DesktopSettings::init);
init();
}
QString DesktopSettings::wallpaper() const
{
return m_wallpaper;
}
bool DesktopSettings::dimsWallpaper() const
{
return m_interface.property("darkModeDimsWallpaer").toBool();
}
2021-03-21 02:00:14 -07:00
int DesktopSettings::backgroundType() const
{
return m_interface.property("backgroundType").toInt();
}
QString DesktopSettings::backgroundColor() const
{
return m_interface.property("backgroundColor").toString();
}
2021-03-16 00:02:20 -07:00
void DesktopSettings::launch(const QString &command, const QStringList &args)
{
QProcess process;
process.setProgram(command);
process.setArguments(args);
process.startDetached();
}
void DesktopSettings::init()
{
if (m_interface.isValid()) {
connect(&m_interface, SIGNAL(wallpaperChanged(QString)), this, SLOT(onWallpaperChanged(QString)));
connect(&m_interface, SIGNAL(darkModeDimsWallpaerChanged()), this, SIGNAL(dimsWallpaperChanged()));
2021-03-21 02:00:14 -07:00
connect(&m_interface, SIGNAL(backgroundTypeChanged()), this, SIGNAL(backgroundTypeChanged()));
connect(&m_interface, SIGNAL(backgroundColorChanged()), this, SIGNAL(backgroundColorChanged()));
2021-03-16 00:02:20 -07:00
m_wallpaper = m_interface.property("wallpaper").toString();
emit wallpaperChanged();
}
}
void DesktopSettings::onWallpaperChanged(QString path)
{
if (path != m_wallpaper) {
m_wallpaper = path;
emit wallpaperChanged();
}
}