Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit c3254844 authored by David Edmundson's avatar David Edmundson

Simplify Alternatives Dialog code

Summary: Replace QObject::sender() and tracking objects in a list with a simple lambda.

Test Plan: Opened and closed dialog.

Reviewers: #plasma, mart

Reviewed By: #plasma, mart

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D6615
parent e3bbe82e
......@@ -38,6 +38,8 @@
#include <klocalizedstring.h>
#include <Plasma/Package>
#include <Plasma/PluginLoader>
#include <PlasmaQuick/Dialog>
#include <kactivities/controller.h>
#include <kactivities/consumer.h>
#include <ksycoca.h>
......@@ -820,42 +822,26 @@ void ShellCorona::showAlternativesForApplet(Plasma::Applet *applet)
AlternativesHelper *helper = new AlternativesHelper(applet, qmlObj);
qmlObj->rootContext()->setContextProperty(QStringLiteral("alternativesHelper"), helper);
m_alternativesObjects << qmlObj;
qmlObj->completeInitialization();
connect(qmlObj->rootObject(), SIGNAL(visibleChanged(bool)),
this, SLOT(alternativesVisibilityChanged(bool)));
connect(applet, &Plasma::Applet::destroyedChanged, this, [this, qmlObj] (bool destroyed) {
auto dialog = qobject_cast<PlasmaQuick::Dialog*>(qmlObj->rootObject());
if (!dialog) {
qWarning() << "Alternatives UI does not inherit from Dialog";
delete qmlObj;
return;
}
connect(applet, &Plasma::Applet::destroyedChanged, qmlObj, [qmlObj] (bool destroyed) {
if (!destroyed) {
return;
}
QMutableListIterator<KDeclarative::QmlObject *> it(m_alternativesObjects);
while (it.hasNext()) {
KDeclarative::QmlObject *obj = it.next();
if (obj == qmlObj) {
it.remove();
obj->deleteLater();
}
}
qmlObj->deleteLater();
});
}
void ShellCorona::alternativesVisibilityChanged(bool visible)
{
if (visible) {
return;
}
QObject *root = sender();
QMutableListIterator<KDeclarative::QmlObject *> it(m_alternativesObjects);
while (it.hasNext()) {
KDeclarative::QmlObject *obj = it.next();
if (obj->rootObject() == root) {
it.remove();
obj->deleteLater();
connect(dialog, &PlasmaQuick::Dialog::visibleChanged, qmlObj, [qmlObj](bool visible) {
if (visible) {
return;
}
}
qmlObj->deleteLater();
});
}
void ShellCorona::unload()
......
......@@ -202,7 +202,6 @@ private Q_SLOTS:
void panelContainmentDestroyed(QObject* cont);
void desktopContainmentDestroyed(QObject*);
void showOpenGLNotCompatibleWarning();
void alternativesVisibilityChanged(bool visible);
void interactiveConsoleVisibilityChanged(bool visible);
void screenRemoved(QScreen* screen);
......@@ -242,7 +241,6 @@ private:
QMenu *m_addPanelsMenu;
KPackage::Package m_lookAndFeelPackage;
QSet<QScreen*> m_redundantOutputs;
QList<KDeclarative::QmlObject *> m_alternativesObjects;
KDeclarative::QmlObject *m_interactiveConsole;
QTimer m_waitingPanelsTimer;
......
Markdown is supported
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