Commit 484e4be7 authored by Martin Flöser's avatar Martin Flöser
Browse files

[kcmkwin/deco] Delay deleting of PreviewBridge

Our decoration is deleted using deleteLater() and that might cause access
to the bridge. Given that we also need to deleteLater() the
PreviewBridge.

To do so the PreviewBridge is no longer directly exposed to QML, but
in a wrapper object which holds the bridge as only element.

BUG: 344278
FIXED-IN: 5.4.3
REVIEW: 125724
parent 10ad9262
......@@ -38,7 +38,7 @@ namespace Preview
void Plugin::registerTypes(const char *uri)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.kwin.private.kdecoration"));
qmlRegisterType<KDecoration2::Preview::PreviewBridge>(uri, 1, 0, "Bridge");
qmlRegisterType<KDecoration2::Preview::BridgeItem>(uri, 1, 0, "Bridge");
qmlRegisterType<KDecoration2::Preview::Settings>(uri, 1, 0, "Settings");
qmlRegisterType<KDecoration2::Preview::PreviewItem>(uri, 1, 0, "Decoration");
qmlRegisterType<KDecoration2::Preview::PreviewButtonItem>(uri, 1, 0, "Button");
......@@ -46,6 +46,7 @@ void Plugin::registerTypes(const char *uri)
qmlRegisterType<KDecoration2::Preview::PreviewClient>();
qmlRegisterType<KDecoration2::Decoration>();
qmlRegisterType<KDecoration2::DecorationShadow>();
qmlRegisterType<KDecoration2::Preview::PreviewBridge>();
}
}
......
......@@ -237,5 +237,19 @@ void PreviewBridge::configure()
dialog.exec();
}
BridgeItem::BridgeItem(QObject *parent)
: QObject(parent)
, m_bridge(new PreviewBridge())
{
connect(m_bridge, &PreviewBridge::themeChanged, this, &BridgeItem::themeChanged);
connect(m_bridge, &PreviewBridge::pluginChanged, this, &BridgeItem::pluginChanged);
connect(m_bridge, &PreviewBridge::validChanged, this, &BridgeItem::validChanged);
}
BridgeItem::~BridgeItem()
{
m_bridge->deleteLater();
}
}
}
......@@ -89,6 +89,48 @@ private:
bool m_valid;
};
class BridgeItem : public QObject
{
Q_OBJECT
Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged)
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
Q_PROPERTY(KDecoration2::Preview::PreviewBridge *bridge READ bridge CONSTANT)
public:
explicit BridgeItem(QObject *parent = nullptr);
virtual ~BridgeItem();
void setPlugin(const QString &plugin) {
m_bridge->setPlugin(plugin);
}
QString plugin() const {
return m_bridge->plugin();
}
void setTheme(const QString &theme) {
m_bridge->setTheme(theme);
}
QString theme() const {
return m_bridge->theme();
}
bool isValid() const {
return m_bridge->isValid();
}
PreviewBridge *bridge() const {
return m_bridge;
}
Q_SIGNALS:
void pluginChanged();
void themeChanged();
void validChanged();
private:
PreviewBridge *m_bridge;
};
}
}
......
......@@ -37,7 +37,7 @@ ListView {
id: button
property int itemIndex: index
property var buttonsModel: parent.ListView.view.model
bridge: bridgeItem
bridge: bridgeItem.bridge
settings: settingsItem
type: model["button"]
anchors.fill: Drag.active ? undefined : parent
......
......@@ -32,7 +32,7 @@ Item {
}
KDecoration.Settings {
id: settingsItem
bridge: bridgeItem
bridge: bridgeItem.bridge
}
Rectangle {
anchors.fill: parent
......@@ -153,7 +153,7 @@ Item {
KDecoration.Button {
id: availableButton
anchors.centerIn: Drag.active ? undefined : parent
bridge: bridgeItem
bridge: bridgeItem.bridge
settings: settingsItem
type: model["button"]
width: units.iconSizes.small
......
......@@ -52,7 +52,7 @@ ScrollView {
}
KDecoration.Settings {
id: settingsItem
bridge: bridgeItem
bridge: bridgeItem.bridge
borderSizesIndex: listView.borderSizesIndex
}
MouseArea {
......@@ -67,7 +67,7 @@ ScrollView {
Item {
KDecoration.Decoration {
id: inactivePreview
bridge: bridgeItem
bridge: bridgeItem.bridge
settings: settingsItem
anchors.fill: parent
Component.onCompleted: {
......@@ -81,7 +81,7 @@ ScrollView {
}
KDecoration.Decoration {
id: activePreview
bridge: bridgeItem
bridge: bridgeItem.bridge
settings: settingsItem
anchors.fill: parent
Component.onCompleted: {
......@@ -107,7 +107,7 @@ ScrollView {
id: configureButton
enabled: model["configureable"]
iconName: "configure"
onClicked: bridgeItem.configure()
onClicked: bridgeItem.bridge.configure()
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment