Commit 2ce60f4e authored by Konrad Materka's avatar Konrad Materka
Browse files

[applets/systemtray] Lazy initialize SystemTray model

Summary:
SystemTray model was created in constructor, delay initialization and
create it lazily.
The `SystemTray::appletAdded` signal is connected to both SystemTray's
model and `Container`. `Container` must be connected first, because it sets
some properties of newly added applet: `visible` to false and `parent`
to the root item (container). If `Container` is connected second, then
newly created applet ios added to the model and rendered, but immediately
after that `Container` changes visibility to false.

BUG: 420993

Test Plan:
1. Do not play anything (no Medial Player icon at all)
2. Run Gwenview
3. Check if Medial Player icon in hidden view is rendered correct.
Before change:
Sometimes icon is not rendered, looks like invisible or fully transparent.
After change:
Icon rendered correctly.
parent 220d3540
......@@ -43,23 +43,12 @@
SystemTray::SystemTray(QObject *parent, const QVariantList &args)
: Plasma::Containment(parent, args),
m_systemTrayModel(new SystemTrayModel(this)),
m_systemTrayModel(nullptr),
m_sortedSystemTrayModel(nullptr),
m_configSystemTrayModel(nullptr)
{
setHasConfigurationInterface(true);
setContainmentType(Plasma::Types::CustomEmbeddedContainment);
PlasmoidModel *currentPlasmoidsModel = new PlasmoidModel(m_systemTrayModel);
connect(this, &SystemTray::appletAdded, currentPlasmoidsModel, &PlasmoidModel::addApplet);
connect(this, &SystemTray::appletRemoved, currentPlasmoidsModel, &PlasmoidModel::removeApplet);
connect(this, &SystemTray::configurationChanged, currentPlasmoidsModel, &PlasmoidModel::onConfigurationChanged);
m_statusNotifierModel = new StatusNotifierModel(m_systemTrayModel);
connect(this, &SystemTray::configurationChanged, m_statusNotifierModel, &StatusNotifierModel::onConfigurationChanged);
m_systemTrayModel->addSourceModel(currentPlasmoidsModel);
m_systemTrayModel->addSourceModel(m_statusNotifierModel);
}
SystemTray::~SystemTray()
......@@ -446,11 +435,34 @@ void SystemTray::configChanged()
emit configurationChanged(config());
}
QAbstractItemModel *SystemTray::systemTrayModel()
SystemTrayModel *SystemTray::systemTrayModel()
{
if (!m_systemTrayModel) {
m_systemTrayModel = new SystemTrayModel(this);
PlasmoidModel *currentPlasmoidsModel = new PlasmoidModel(m_systemTrayModel);
connect(this, &SystemTray::appletAdded, currentPlasmoidsModel, &PlasmoidModel::addApplet);
connect(this, &SystemTray::appletRemoved, currentPlasmoidsModel, &PlasmoidModel::removeApplet);
connect(this, &SystemTray::configurationChanged, currentPlasmoidsModel, &PlasmoidModel::onConfigurationChanged);
for (auto applet : applets()) {
currentPlasmoidsModel->addApplet(applet);
}
m_statusNotifierModel = new StatusNotifierModel(m_systemTrayModel);
connect(this, &SystemTray::configurationChanged, m_statusNotifierModel, &StatusNotifierModel::onConfigurationChanged);
m_systemTrayModel->addSourceModel(currentPlasmoidsModel);
m_systemTrayModel->addSourceModel(m_statusNotifierModel);
}
return m_systemTrayModel;
}
QAbstractItemModel *SystemTray::sortedSystemTrayModel()
{
if (!m_sortedSystemTrayModel) {
m_sortedSystemTrayModel = new SortedSystemTrayModel(SortedSystemTrayModel::SortingType::SystemTray, this);
m_sortedSystemTrayModel->setSourceModel(m_systemTrayModel);
m_sortedSystemTrayModel->setSourceModel(systemTrayModel());
}
return m_sortedSystemTrayModel;
}
......@@ -459,7 +471,7 @@ QAbstractItemModel *SystemTray::configSystemTrayModel()
{
if (!m_configSystemTrayModel) {
m_configSystemTrayModel = new SortedSystemTrayModel(SortedSystemTrayModel::SortingType::ConfigurationPage, this);
m_configSystemTrayModel->setSourceModel(m_systemTrayModel);
m_configSystemTrayModel->setSourceModel(systemTrayModel());
}
return m_configSystemTrayModel;
}
......
......@@ -40,7 +40,7 @@ class SortedSystemTrayModel;
class SystemTray : public Plasma::Containment
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel* systemTrayModel READ systemTrayModel CONSTANT)
Q_PROPERTY(QAbstractItemModel* systemTrayModel READ sortedSystemTrayModel CONSTANT)
Q_PROPERTY(QAbstractItemModel* configSystemTrayModel READ configSystemTrayModel CONSTANT)
Q_PROPERTY(QStringList allowedPlasmoids READ allowedPlasmoids WRITE setAllowedPlasmoids NOTIFY allowedPlasmoidsChanged)
......@@ -55,7 +55,7 @@ public:
void configChanged() override;
QAbstractItemModel *systemTrayModel();
QAbstractItemModel *sortedSystemTrayModel();
QAbstractItemModel *configSystemTrayModel();
......@@ -113,6 +113,8 @@ Q_SIGNALS:
private:
void initDBusActivatables();
SystemTrayModel *systemTrayModel();
QStringList m_defaultPlasmoids;
QHash<QString /*plugin name*/, KPluginMetaData> m_systrayApplets;
QHash<QString /*plugin name*/, QRegExp /*DBus Service*/> m_dbusActivatableTasks;
......
  • @kmaterka

    This commit causes a significant regression for me: when plasma starts, my custom tray item visibility settings are ignored and the tray uses its default settings until I change a visibility setting and apply the changes. Fixing this is somewhat urgent considering that it's on the stable branch which will be tarred for release in a little over a week.

  • I will fix that immediately!

  • Fix in !23 (merged).

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