1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 13:33:50 +03:00

protect from crashes of application interfaces

This commit is contained in:
Michail Vourlakos 2020-05-02 19:09:54 +03:00
parent b43e864e8a
commit b3ec491863
2 changed files with 97 additions and 19 deletions

View File

@ -34,21 +34,89 @@ QObject *Interfaces::globalShortcuts() const
return m_globalShortcuts;
}
void Interfaces::setGlobalShortcuts(QObject *shortcuts)
{
if (m_globalShortcuts == shortcuts) {
return;
}
m_globalShortcuts = shortcuts;
if (m_globalShortcuts) {
connect(m_globalShortcuts, &QObject::destroyed, this, [&]() {
setGlobalShortcuts(nullptr);
});
}
emit globalShortcutsChanged();
}
QObject *Interfaces::layoutsManager() const
{
return m_layoutsManager;
}
void Interfaces::setLayoutsManager(QObject *manager)
{
if (m_layoutsManager == manager) {
return;
}
m_layoutsManager = manager;
if (m_layoutsManager) {
connect(m_layoutsManager, &QObject::destroyed, this, [&]() {
setLayoutsManager(nullptr);
});
}
emit layoutsManagerChanged();
}
QObject *Interfaces::themeExtended() const
{
return m_themeExtended;
}
void Interfaces::setThemeExtended(QObject *theme)
{
if (m_themeExtended == theme) {
return;
}
m_themeExtended = theme;
if (m_themeExtended) {
connect(m_themeExtended, &QObject::destroyed, this, [&]() {
setThemeExtended(nullptr);
});
}
emit themeExtendedChanged();
}
QObject *Interfaces::universalSettings() const
{
return m_universalSettings;
}
void Interfaces::setUniversalSettings(QObject *settings)
{
if (m_universalSettings == settings) {
return;
}
m_universalSettings = settings;
if (m_universalSettings) {
connect(m_universalSettings, &QObject::destroyed, this, [&]() {
setUniversalSettings(nullptr);
});
}
emit universalSettingsChanged();
}
QObject *Interfaces::view() const
{
return m_view;
@ -61,7 +129,14 @@ void Interfaces::setView(QObject *view)
}
m_view = view;
emit interfacesChanged();
if (m_view) {
connect(m_view, &QObject::destroyed, this, [&]() {
setView(nullptr);
});
}
emit viewChanged();
}
QObject *Interfaces::plasmoidInterface() const
@ -76,15 +151,13 @@ void Interfaces::setPlasmoidInterface(QObject *interface)
if (plasmoid && m_plasmoid != plasmoid) {
m_plasmoid = plasmoid;
m_globalShortcuts = plasmoid->property("_latte_globalShortcuts_object").value<QObject *>();
m_layoutsManager = plasmoid->property("_latte_layoutsManager_object").value<QObject *>();
m_themeExtended = plasmoid->property("_latte_themeExtended_object").value<QObject *>();
m_universalSettings = plasmoid->property("_latte_universalSettings_object").value<QObject *>();
setGlobalShortcuts(plasmoid->property("_latte_globalShortcuts_object").value<QObject *>());
setLayoutsManager(plasmoid->property("_latte_layoutsManager_object").value<QObject *>());
setThemeExtended(plasmoid->property("_latte_themeExtended_object").value<QObject *>());
setUniversalSettings(plasmoid->property("_latte_universalSettings_object").value<QObject *>());
setView(plasmoid->property("_latte_view_object").value<QObject *>());
connect(m_view, &QObject::destroyed, this, [&]() {
setView(nullptr);
});
emit interfaceChanged();
}
}

View File

@ -33,34 +33,39 @@ namespace Latte{
class Interfaces: public QObject
{
Q_OBJECT
Q_PROPERTY(QObject *plasmoidInterface READ plasmoidInterface WRITE setPlasmoidInterface NOTIFY interfacesChanged)
Q_PROPERTY(QObject *plasmoidInterface READ plasmoidInterface WRITE setPlasmoidInterface NOTIFY interfaceChanged)
Q_PROPERTY(QObject *globalShortcuts READ globalShortcuts NOTIFY interfacesChanged)
Q_PROPERTY(QObject *layoutsManager READ layoutsManager NOTIFY interfacesChanged)
Q_PROPERTY(QObject *themeExtended READ themeExtended NOTIFY interfacesChanged)
Q_PROPERTY(QObject *universalSettings READ universalSettings NOTIFY interfacesChanged)
Q_PROPERTY(QObject *view READ view NOTIFY interfacesChanged)
Q_PROPERTY(QObject *globalShortcuts READ globalShortcuts NOTIFY globalShortcutsChanged)
Q_PROPERTY(QObject *layoutsManager READ layoutsManager NOTIFY layoutsManagerChanged)
Q_PROPERTY(QObject *themeExtended READ themeExtended NOTIFY themeExtendedChanged)
Q_PROPERTY(QObject *universalSettings READ universalSettings NOTIFY universalSettingsChanged)
Q_PROPERTY(QObject *view READ view NOTIFY viewChanged)
public:
explicit Interfaces(QObject *parent = nullptr);
QObject *globalShortcuts() const;
QObject *layoutsManager() const;
QObject *themeExtended() const;
QObject *universalSettings() const;
QObject *view() const;
QObject *plasmoidInterface() const;
void setPlasmoidInterface(QObject *interface);
signals:
void interfacesChanged();
void interfaceChanged();
void globalShortcutsChanged();
void layoutsManagerChanged();
void themeExtendedChanged();
void universalSettingsChanged();
void viewChanged();
private:
void setGlobalShortcuts(QObject *shortcuts);
void setLayoutsManager(QObject *manager);
void setThemeExtended(QObject *theme);
void setUniversalSettings(QObject *settings);
void setView(QObject *view);
private: