refactor(appearance): split the library from its QML plugin
parent
7387a0f734
commit
164de9c9f6
@ -1,29 +1,62 @@
|
||||
set(CUTEFISH_APPEARANCE_SOURCES
|
||||
appearance.cpp
|
||||
appearance.h
|
||||
wallpaper.cpp
|
||||
wallpaper.h
|
||||
plugin.cpp
|
||||
)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick DBus)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml DBus)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
if(NOT COMMAND cutefish_install_qml_module)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/../cmake/CutefishFrameworkQml.cmake")
|
||||
endif()
|
||||
|
||||
add_library(cutefish-framework-appearance SHARED ${CUTEFISH_APPEARANCE_SOURCES})
|
||||
add_library(Cutefish::Appearance ALIAS cutefish-framework-appearance)
|
||||
|
||||
qt_add_qml_module(cutefish-framework-appearance
|
||||
URI Cutefish.Appearance
|
||||
VERSION 1.0
|
||||
PLUGIN_TARGET cutefish-framework-appearance
|
||||
CLASS_NAME QmlPlugins
|
||||
NO_GENERATE_PLUGIN_SOURCE
|
||||
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Cutefish/Appearance"
|
||||
target_include_directories(cutefish-framework-appearance
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/Cutefish>
|
||||
)
|
||||
|
||||
add_library(Cutefish::Appearance ALIAS cutefish-framework-appearance)
|
||||
|
||||
target_link_libraries(cutefish-framework-appearance PUBLIC
|
||||
Qt6::Core
|
||||
Qt6::Quick
|
||||
Qt6::Gui
|
||||
Qt6::DBus
|
||||
)
|
||||
|
||||
cutefish_install_qml_module(cutefish-framework-appearance)
|
||||
# Consumers pull this directory in with add_subdirectory to link the library;
|
||||
# only the framework's own build ships it and the QML module, so their packages
|
||||
# do not fight over the same files.
|
||||
if(PROJECT_NAME STREQUAL "CutefishFramework")
|
||||
install(TARGETS cutefish-framework-appearance
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
)
|
||||
install(FILES appearance.h wallpaper.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Cutefish)
|
||||
|
||||
# qmltyperegistrar resolves the QML_FOREIGN types out of this file.
|
||||
qt_extract_metatypes(cutefish-framework-appearance)
|
||||
|
||||
# The QML module is a plugin of its own so the module registration ships in
|
||||
# exactly one library, even in a process that also links the one above.
|
||||
qt_add_qml_module(cutefish-framework-appearance-qml
|
||||
URI Cutefish.Appearance
|
||||
VERSION 1.0
|
||||
PLUGIN_TARGET cutefish-framework-appearance-qml
|
||||
CLASS_NAME AppearanceQmlPlugin
|
||||
NO_PLUGIN_OPTIONAL
|
||||
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Cutefish/Appearance"
|
||||
SOURCES
|
||||
qmlregistration.cpp
|
||||
qmlregistration.h
|
||||
)
|
||||
|
||||
target_link_libraries(cutefish-framework-appearance-qml PRIVATE
|
||||
Cutefish::Appearance
|
||||
Qt6::Qml
|
||||
)
|
||||
|
||||
cutefish_install_qml_module(cutefish-framework-appearance-qml)
|
||||
endif()
|
||||
|
||||
@ -0,0 +1,254 @@
|
||||
#include "appearance.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusServiceWatcher>
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr auto Service = "com.cutefish.Services";
|
||||
constexpr auto ObjectPath = "/com/cutefish/Services/Appearance";
|
||||
constexpr auto Interface = "com.cutefish.Services.Appearance";
|
||||
}
|
||||
|
||||
Appearance::Appearance(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_interface(nullptr)
|
||||
{
|
||||
auto *watcher = new QDBusServiceWatcher(QString::fromLatin1(Service),
|
||||
QDBusConnection::sessionBus(),
|
||||
QDBusServiceWatcher::WatchForRegistration,
|
||||
this);
|
||||
connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &Appearance::init);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
void Appearance::init()
|
||||
{
|
||||
delete m_interface;
|
||||
m_interface = new QDBusInterface(QString::fromLatin1(Service),
|
||||
QString::fromLatin1(ObjectPath),
|
||||
QString::fromLatin1(Interface),
|
||||
QDBusConnection::sessionBus(),
|
||||
this);
|
||||
|
||||
if (!m_interface->isValid())
|
||||
return;
|
||||
|
||||
connect(m_interface, SIGNAL(darkModeChanged(bool)), this, SLOT(onDarkModeChanged(bool)));
|
||||
connect(m_interface, SIGNAL(wallpaperChanged(QString)), this, SLOT(onWallpaperChanged(QString)));
|
||||
connect(m_interface, SIGNAL(accentColorChanged(int)), this, SLOT(onAccentColorChanged(int)));
|
||||
connect(m_interface, SIGNAL(darkModeDimsWallpaerChanged()), this, SLOT(onDarkModeDimsWallpaperChanged()));
|
||||
connect(m_interface, SIGNAL(blurEnabledChanged()), this, SLOT(onBlurEnabledChanged()));
|
||||
connect(m_interface, SIGNAL(systemFontPointSizeChanged()), this, SLOT(onFontPointSizeChanged()));
|
||||
connect(m_interface, SIGNAL(systemFontChanged()), this, SLOT(onFontFamilyChanged()));
|
||||
connect(m_interface, SIGNAL(backgroundTypeChanged()), this, SLOT(onBackgroundTypeChanged()));
|
||||
connect(m_interface, SIGNAL(backgroundColorChanged()), this, SLOT(onBackgroundColorChanged()));
|
||||
connect(m_interface, SIGNAL(backgroundVisibleChanged()), this, SLOT(onBackgroundVisibleChanged()));
|
||||
|
||||
emit darkModeChanged();
|
||||
emit wallpaperChanged();
|
||||
emit accentColorIndexChanged();
|
||||
emit dimsWallpaperChanged();
|
||||
emit blurEnabledChanged();
|
||||
emit fontPointSizeChanged();
|
||||
emit fontFamilyChanged();
|
||||
emit fixedFontFamilyChanged();
|
||||
emit backgroundTypeChanged();
|
||||
emit backgroundColorChanged();
|
||||
emit backgroundVisibleChanged();
|
||||
}
|
||||
|
||||
QVariant Appearance::serviceProperty(const char *name) const
|
||||
{
|
||||
return m_interface && m_interface->isValid() ? m_interface->property(name) : QVariant();
|
||||
}
|
||||
|
||||
void Appearance::callService(const char *method)
|
||||
{
|
||||
if (m_interface && m_interface->isValid())
|
||||
m_interface->call(method);
|
||||
}
|
||||
|
||||
void Appearance::callService(const char *method, const QVariant &value)
|
||||
{
|
||||
if (m_interface && m_interface->isValid())
|
||||
m_interface->call(method, value);
|
||||
}
|
||||
|
||||
bool Appearance::darkMode() const
|
||||
{
|
||||
return serviceProperty("isDarkMode").toBool();
|
||||
}
|
||||
|
||||
void Appearance::switchDarkMode(bool darkMode)
|
||||
{
|
||||
callService("setDarkMode", darkMode);
|
||||
}
|
||||
|
||||
bool Appearance::dimsWallpaper() const
|
||||
{
|
||||
return serviceProperty("darkModeDimsWallpaer").toBool();
|
||||
}
|
||||
|
||||
void Appearance::setDimsWallpaper(bool value)
|
||||
{
|
||||
callService("setDarkModeDimsWallpaer", value);
|
||||
}
|
||||
|
||||
bool Appearance::blurEnabled() const
|
||||
{
|
||||
return serviceProperty("blurEnabled").toBool();
|
||||
}
|
||||
|
||||
void Appearance::setBlurEnabled(bool value)
|
||||
{
|
||||
callService("setBlurEnabled", value);
|
||||
}
|
||||
|
||||
int Appearance::accentColorIndex() const
|
||||
{
|
||||
return serviceProperty("accentColor").toInt();
|
||||
}
|
||||
|
||||
void Appearance::setAccentColor(int accentColor)
|
||||
{
|
||||
callService("setAccentColor", accentColor);
|
||||
}
|
||||
|
||||
qreal Appearance::fontPointSize() const
|
||||
{
|
||||
return serviceProperty("systemFontPointSize").toReal();
|
||||
}
|
||||
|
||||
void Appearance::setFontPointSize(qreal fontPointSize)
|
||||
{
|
||||
callService("setSystemFontPointSize", fontPointSize);
|
||||
}
|
||||
|
||||
QString Appearance::fontFamily() const
|
||||
{
|
||||
return serviceProperty("systemFont").toString();
|
||||
}
|
||||
|
||||
void Appearance::setFontFamily(const QString &name)
|
||||
{
|
||||
if (!name.isEmpty())
|
||||
callService("setSystemFont", name);
|
||||
}
|
||||
|
||||
QString Appearance::fixedFontFamily() const
|
||||
{
|
||||
return serviceProperty("systemFixedFont").toString();
|
||||
}
|
||||
|
||||
// com.cutefish.Services.Appearance has no systemFixedFontChanged signal, so
|
||||
// the change is announced here.
|
||||
void Appearance::setFixedFontFamily(const QString &name)
|
||||
{
|
||||
if (!name.isEmpty()) {
|
||||
callService("setSystemFixedFont", name);
|
||||
emit fixedFontFamilyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QString Appearance::wallpaper() const
|
||||
{
|
||||
return serviceProperty("wallpaper").toString();
|
||||
}
|
||||
|
||||
void Appearance::setWallpaper(const QString &path)
|
||||
{
|
||||
if (!path.isEmpty())
|
||||
callService("setWallpaper", path);
|
||||
}
|
||||
|
||||
int Appearance::backgroundType() const
|
||||
{
|
||||
return serviceProperty("backgroundType").toInt();
|
||||
}
|
||||
|
||||
void Appearance::setBackgroundType(int type)
|
||||
{
|
||||
callService("setBackgroundType", type);
|
||||
}
|
||||
|
||||
QString Appearance::backgroundColor() const
|
||||
{
|
||||
return serviceProperty("backgroundColor").toString();
|
||||
}
|
||||
|
||||
void Appearance::setBackgroundColor(const QString &color)
|
||||
{
|
||||
callService("setBackgroundColor", color);
|
||||
}
|
||||
|
||||
bool Appearance::backgroundVisible() const
|
||||
{
|
||||
return serviceProperty("backgroundVisible").toBool();
|
||||
}
|
||||
|
||||
void Appearance::setCursorTheme(const QString &theme)
|
||||
{
|
||||
if (!theme.isEmpty())
|
||||
callService("setCursorTheme", theme);
|
||||
}
|
||||
|
||||
void Appearance::applyFontSettings()
|
||||
{
|
||||
callService("applyFontSettings");
|
||||
}
|
||||
|
||||
void Appearance::onDarkModeChanged(bool darkMode)
|
||||
{
|
||||
Q_UNUSED(darkMode);
|
||||
emit darkModeChanged();
|
||||
}
|
||||
|
||||
void Appearance::onWallpaperChanged(const QString &path)
|
||||
{
|
||||
Q_UNUSED(path);
|
||||
emit wallpaperChanged();
|
||||
}
|
||||
|
||||
void Appearance::onAccentColorChanged(int accentColor)
|
||||
{
|
||||
Q_UNUSED(accentColor);
|
||||
emit accentColorIndexChanged();
|
||||
}
|
||||
|
||||
void Appearance::onDarkModeDimsWallpaperChanged()
|
||||
{
|
||||
emit dimsWallpaperChanged();
|
||||
}
|
||||
|
||||
void Appearance::onBlurEnabledChanged()
|
||||
{
|
||||
emit blurEnabledChanged();
|
||||
}
|
||||
|
||||
void Appearance::onFontPointSizeChanged()
|
||||
{
|
||||
emit fontPointSizeChanged();
|
||||
}
|
||||
|
||||
void Appearance::onFontFamilyChanged()
|
||||
{
|
||||
emit fontFamilyChanged();
|
||||
}
|
||||
|
||||
void Appearance::onBackgroundTypeChanged()
|
||||
{
|
||||
emit backgroundTypeChanged();
|
||||
}
|
||||
|
||||
void Appearance::onBackgroundColorChanged()
|
||||
{
|
||||
emit backgroundColorChanged();
|
||||
}
|
||||
|
||||
void Appearance::onBackgroundVisibleChanged()
|
||||
{
|
||||
emit backgroundVisibleChanged();
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
#ifndef CUTEFISH_APPEARANCE_H
|
||||
#define CUTEFISH_APPEARANCE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
class QDBusInterface;
|
||||
|
||||
class Appearance : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool darkMode READ darkMode NOTIFY darkModeChanged)
|
||||
Q_PROPERTY(bool dimsWallpaper READ dimsWallpaper WRITE setDimsWallpaper NOTIFY dimsWallpaperChanged)
|
||||
Q_PROPERTY(bool blurEnabled READ blurEnabled WRITE setBlurEnabled NOTIFY blurEnabledChanged)
|
||||
Q_PROPERTY(int accentColorIndex READ accentColorIndex NOTIFY accentColorIndexChanged)
|
||||
Q_PROPERTY(qreal fontPointSize READ fontPointSize WRITE setFontPointSize NOTIFY fontPointSizeChanged)
|
||||
Q_PROPERTY(QString fontFamily READ fontFamily WRITE setFontFamily NOTIFY fontFamilyChanged)
|
||||
Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily NOTIFY fixedFontFamilyChanged)
|
||||
Q_PROPERTY(QString wallpaper READ wallpaper WRITE setWallpaper NOTIFY wallpaperChanged)
|
||||
Q_PROPERTY(int backgroundType READ backgroundType WRITE setBackgroundType NOTIFY backgroundTypeChanged)
|
||||
Q_PROPERTY(QString backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
|
||||
Q_PROPERTY(bool backgroundVisible READ backgroundVisible NOTIFY backgroundVisibleChanged)
|
||||
|
||||
public:
|
||||
explicit Appearance(QObject *parent = nullptr);
|
||||
|
||||
bool darkMode() const;
|
||||
Q_INVOKABLE void switchDarkMode(bool darkMode);
|
||||
|
||||
bool dimsWallpaper() const;
|
||||
Q_INVOKABLE void setDimsWallpaper(bool value);
|
||||
|
||||
bool blurEnabled() const;
|
||||
Q_INVOKABLE void setBlurEnabled(bool value);
|
||||
|
||||
int accentColorIndex() const;
|
||||
Q_INVOKABLE void setAccentColor(int accentColor);
|
||||
|
||||
qreal fontPointSize() const;
|
||||
Q_INVOKABLE void setFontPointSize(qreal fontPointSize);
|
||||
|
||||
QString fontFamily() const;
|
||||
Q_INVOKABLE void setFontFamily(const QString &name);
|
||||
|
||||
QString fixedFontFamily() const;
|
||||
Q_INVOKABLE void setFixedFontFamily(const QString &name);
|
||||
|
||||
QString wallpaper() const;
|
||||
Q_INVOKABLE void setWallpaper(const QString &path);
|
||||
|
||||
int backgroundType() const;
|
||||
Q_INVOKABLE void setBackgroundType(int type);
|
||||
|
||||
QString backgroundColor() const;
|
||||
Q_INVOKABLE void setBackgroundColor(const QString &color);
|
||||
|
||||
bool backgroundVisible() const;
|
||||
|
||||
Q_INVOKABLE void setCursorTheme(const QString &theme);
|
||||
Q_INVOKABLE void applyFontSettings();
|
||||
|
||||
signals:
|
||||
void darkModeChanged();
|
||||
void dimsWallpaperChanged();
|
||||
void blurEnabledChanged();
|
||||
void accentColorIndexChanged();
|
||||
void fontPointSizeChanged();
|
||||
void fontFamilyChanged();
|
||||
void fixedFontFamilyChanged();
|
||||
void wallpaperChanged();
|
||||
void backgroundTypeChanged();
|
||||
void backgroundColorChanged();
|
||||
void backgroundVisibleChanged();
|
||||
|
||||
private slots:
|
||||
void init();
|
||||
void onDarkModeChanged(bool darkMode);
|
||||
void onWallpaperChanged(const QString &path);
|
||||
void onAccentColorChanged(int accentColor);
|
||||
void onDarkModeDimsWallpaperChanged();
|
||||
void onBlurEnabledChanged();
|
||||
void onFontPointSizeChanged();
|
||||
void onFontFamilyChanged();
|
||||
void onBackgroundTypeChanged();
|
||||
void onBackgroundColorChanged();
|
||||
void onBackgroundVisibleChanged();
|
||||
|
||||
private:
|
||||
QVariant serviceProperty(const char *name) const;
|
||||
void callService(const char *method);
|
||||
void callService(const char *method, const QVariant &value);
|
||||
|
||||
QDBusInterface *m_interface;
|
||||
};
|
||||
|
||||
#endif // CUTEFISH_APPEARANCE_H
|
||||
@ -1,17 +0,0 @@
|
||||
#include <QQmlExtensionPlugin>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "wallpaper.h"
|
||||
|
||||
class QmlPlugins : public QQmlExtensionPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
|
||||
|
||||
public:
|
||||
void registerTypes(const char * uri) override {
|
||||
qmlRegisterType<Wallpaper>(uri, 1, 0, "Wallpaper");
|
||||
}
|
||||
};
|
||||
|
||||
#include "plugin.moc"
|
||||
@ -0,0 +1 @@
|
||||
#include "qmlregistration.h"
|
||||
@ -0,0 +1,29 @@
|
||||
#ifndef CUTEFISH_APPEARANCE_QMLREGISTRATION_H
|
||||
#define CUTEFISH_APPEARANCE_QMLREGISTRATION_H
|
||||
|
||||
#include <QtQml/qqmlregistration.h>
|
||||
|
||||
#include "appearance.h"
|
||||
#include "wallpaper.h"
|
||||
|
||||
// The types themselves live in libcutefish-framework-appearance, which settings
|
||||
// and FishUI link against. Registering Cutefish.Appearance from a separate
|
||||
// plugin keeps the module registration in one library: a process that both
|
||||
// links the library and imports the module would otherwise load two copies of
|
||||
// the same .so, and Qt refuses the second registration of the URI.
|
||||
|
||||
struct AppearanceForeign
|
||||
{
|
||||
Q_GADGET
|
||||
QML_FOREIGN(Appearance)
|
||||
QML_NAMED_ELEMENT(Appearance)
|
||||
};
|
||||
|
||||
struct WallpaperForeign
|
||||
{
|
||||
Q_GADGET
|
||||
QML_FOREIGN(Wallpaper)
|
||||
QML_NAMED_ELEMENT(Wallpaper)
|
||||
};
|
||||
|
||||
#endif // CUTEFISH_APPEARANCE_QMLREGISTRATION_H
|
||||
@ -1,79 +1,56 @@
|
||||
#include "wallpaper.h"
|
||||
|
||||
#include <QDBusServiceWatcher>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
|
||||
Wallpaper::Wallpaper(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_interface(nullptr)
|
||||
: Appearance(parent)
|
||||
{
|
||||
// The shell starts before cutefish-services, so the signals are hooked up
|
||||
// again once the service appears; without this the desktop would keep the
|
||||
// background it read at startup for the rest of the session.
|
||||
QDBusServiceWatcher *watcher = new QDBusServiceWatcher(this);
|
||||
watcher->setConnection(QDBusConnection::sessionBus());
|
||||
watcher->addWatchedService("com.cutefish.Services");
|
||||
connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &Wallpaper::init);
|
||||
|
||||
init();
|
||||
connect(this, &Appearance::backgroundTypeChanged, this, &Wallpaper::typeChanged);
|
||||
connect(this, &Appearance::wallpaperChanged, this, &Wallpaper::pathChanged);
|
||||
connect(this, &Appearance::backgroundColorChanged, this, &Wallpaper::colorChanged);
|
||||
}
|
||||
|
||||
void Wallpaper::init()
|
||||
{
|
||||
delete m_interface;
|
||||
m_interface = new QDBusInterface("com.cutefish.Services",
|
||||
"/com/cutefish/Services/Appearance",
|
||||
"com.cutefish.Services.Appearance",
|
||||
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
|
||||
int Wallpaper::type() const
|
||||
{
|
||||
return m_interface ? m_interface->property(name) : QVariant();
|
||||
return backgroundType();
|
||||
}
|
||||
|
||||
int Wallpaper::type() const
|
||||
void Wallpaper::setType(int type)
|
||||
{
|
||||
return themeProperty("backgroundType").toInt();
|
||||
setBackgroundType(type);
|
||||
}
|
||||
|
||||
QString Wallpaper::path() const
|
||||
{
|
||||
return themeProperty("wallpaper").toString();
|
||||
return wallpaper();
|
||||
}
|
||||
|
||||
bool Wallpaper::dimsWallpaper() const
|
||||
void Wallpaper::setPath(const QString &path)
|
||||
{
|
||||
return themeProperty("darkModeDimsWallpaer").toBool();
|
||||
setWallpaper(path);
|
||||
}
|
||||
|
||||
QString Wallpaper::color() const
|
||||
{
|
||||
return themeProperty("backgroundColor").toString();
|
||||
return backgroundColor();
|
||||
}
|
||||
|
||||
bool Wallpaper::backgroundVisible() const
|
||||
void Wallpaper::setColor(const QString &color)
|
||||
{
|
||||
return themeProperty("backgroundVisible").toBool();
|
||||
setBackgroundColor(color);
|
||||
}
|
||||
|
||||
void Wallpaper::onPathChanged(QString path)
|
||||
QStringList Wallpaper::backgrounds() const
|
||||
{
|
||||
Q_UNUSED(path);
|
||||
QStringList result;
|
||||
QDirIterator iterator(QStringLiteral("/usr/share/backgrounds/cutefishos"),
|
||||
{QStringLiteral("*.jpg"), QStringLiteral("*.png")},
|
||||
QDir::Files,
|
||||
QDirIterator::Subdirectories);
|
||||
while (iterator.hasNext())
|
||||
result.append(iterator.next());
|
||||
|
||||
emit pathChanged();
|
||||
result.sort();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1,51 +1,40 @@
|
||||
#ifndef WALLPAPER_H
|
||||
#define WALLPAPER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusInterface>
|
||||
#include "appearance.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
/**
|
||||
* The desktop background as cutefish-services publishes it over
|
||||
* com.cutefish.Services.Appearance: an image (type 0) or a plain colour (type 1).
|
||||
*/
|
||||
class Wallpaper : public QObject
|
||||
class Wallpaper : public Appearance
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int type READ type NOTIFY typeChanged)
|
||||
Q_PROPERTY(QString path READ path NOTIFY pathChanged)
|
||||
Q_PROPERTY(bool dimsWallpaper READ dimsWallpaper NOTIFY dimsWallpaperChanged)
|
||||
Q_PROPERTY(QString color READ color NOTIFY colorChanged)
|
||||
Q_PROPERTY(bool backgroundVisible READ backgroundVisible NOTIFY backgroundVisibleChanged)
|
||||
Q_PROPERTY(int type READ type WRITE setType NOTIFY typeChanged)
|
||||
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
|
||||
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(QStringList backgrounds READ backgrounds CONSTANT)
|
||||
|
||||
public:
|
||||
explicit Wallpaper(QObject *parent = nullptr);
|
||||
|
||||
int type() const;
|
||||
Q_INVOKABLE void setType(int type);
|
||||
|
||||
QString path() const;
|
||||
bool dimsWallpaper() const;
|
||||
Q_INVOKABLE void setPath(const QString &path);
|
||||
|
||||
QString color() const;
|
||||
bool backgroundVisible() const;
|
||||
Q_INVOKABLE void setColor(const QString &color);
|
||||
|
||||
QStringList backgrounds() const;
|
||||
|
||||
signals:
|
||||
void pathChanged();
|
||||
void dimsWallpaperChanged();
|
||||
void typeChanged();
|
||||
void colorChanged();
|
||||
void backgroundVisibleChanged();
|
||||
|
||||
private:
|
||||
QVariant themeProperty(const char *name) const;
|
||||
|
||||
private slots:
|
||||
void init();
|
||||
void onPathChanged(QString path);
|
||||
|
||||
private:
|
||||
// Recreated in init(): a QDBusInterface built while cutefish-services is
|
||||
// not on the bus caches a failed introspection and never recovers.
|
||||
QDBusInterface *m_interface;
|
||||
};
|
||||
|
||||
#endif // WALLPAPER_H
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
qt_policy(SET QTP0001 NEW)
|
||||
|
||||
if(NOT DEFINED INSTALL_QMLDIR)
|
||||
find_program(QT_PATHS_EXECUTABLE NAMES qtpaths6 REQUIRED)
|
||||
execute_process(COMMAND ${QT_PATHS_EXECUTABLE} -query QT_INSTALL_QML
|
||||
OUTPUT_VARIABLE INSTALL_QMLDIR
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
endif()
|
||||
|
||||
function(cutefish_install_qml_module target)
|
||||
qt_query_qml_module("${target}"
|
||||
TARGET_PATH module_path
|
||||
QMLDIR module_qmldir
|
||||
TYPEINFO module_qmltypes
|
||||
)
|
||||
|
||||
set(module_install_dir "${INSTALL_QMLDIR}/${module_path}")
|
||||
install(TARGETS "${target}" DESTINATION "${module_install_dir}")
|
||||
install(FILES "${module_qmldir}" DESTINATION "${module_install_dir}")
|
||||
|
||||
if(module_qmltypes)
|
||||
install(FILES "${module_qmltypes}" DESTINATION "${module_install_dir}")
|
||||
endif()
|
||||
endfunction()
|
||||
@ -1,30 +1,6 @@
|
||||
#include "qmlplugins.h"
|
||||
#include "networkmodel.h"
|
||||
#include "networkmodelitem.h"
|
||||
#include "activeconnection.h"
|
||||
#include "appletproxymodel.h"
|
||||
#include "wirelessitemsettings.h"
|
||||
#include "identitymodel.h"
|
||||
#include "handler.h"
|
||||
#include "enabledconnections.h"
|
||||
#include "enums.h"
|
||||
#include "wifisettings.h"
|
||||
#include "configuration.h"
|
||||
|
||||
#include <QQmlEngine>
|
||||
|
||||
void QmlPlugins::registerTypes(const char* uri)
|
||||
{
|
||||
qmlRegisterUncreatableType<NetworkModelItem>(uri, 1, 0, "NetworkModelItem",
|
||||
QLatin1String("Cannot instantiate NetworkModelItem"));
|
||||
qmlRegisterType<ActiveConnection>(uri, 1, 0, "ActiveConnection");
|
||||
qmlRegisterType<AppletProxyModel>(uri, 1, 0, "AppletProxyModel");
|
||||
qmlRegisterType<NetworkModel>(uri, 1, 0, "NetworkModel");
|
||||
qmlRegisterType<WirelessItemSettings>(uri, 1, 0, "WirelessItemSettings");
|
||||
qmlRegisterType<IdentityModel>(uri, 1, 0, "IdentityModel");
|
||||
qmlRegisterType<Handler>(uri, 1, 0, "Handler");
|
||||
qmlRegisterType<EnabledConnections>(uri, 1, 0, "EnabledConnections");
|
||||
qmlRegisterType<WifiSettings>(uri, 1, 0, "WifiSettings");
|
||||
qmlRegisterType<Configuration>(uri, 1, 0, "Configuration");
|
||||
qmlRegisterUncreatableType<Enums>(uri, 1, 0, "Enums", "You cannot create Enums on yourself");
|
||||
Q_UNUSED(uri);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue