Commit 3c786666 authored by Konrad Materka's avatar Konrad Materka
Browse files

Avoid side effects during menu initialization

Summary: Setting some attributes, like visible, enabled, etc has side effects. Do not set them if these are not changed.

Test Plan: Without this change menus (mostly submenus) randomly shows up when the SNI is updated, e.g. every time VLC changes a track I get its "speed (slower, normal, faster)" menu open.

Reviewers: #plasma, #frameworks, broulik

Reviewed By: #plasma, broulik

Subscribers: nicolasfella, davidedmundson, cgiboudeaux, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25223
parent f14c3ff8
......@@ -29,9 +29,9 @@
SystemTrayMenu::SystemTrayMenu()
: QPlatformMenu()
, m_enabled(true)
, m_visible(true)
, m_separatorsCollapsible(true)
, m_enabled(QVariant::Bool)
, m_visible(QVariant::Bool)
, m_separatorsCollapsible(QVariant::Bool)
, m_tag(0)
{
}
......@@ -177,11 +177,21 @@ void SystemTrayMenu::createMenu()
connect(m_menu, &QMenu::aboutToShow, this, &QPlatformMenu::aboutToShow);
connect(m_menu, &QMenu::aboutToHide, this, &QPlatformMenu::aboutToHide);
m_menu->setEnabled(m_enabled);
m_menu->setIcon(m_icon);
m_menu->setTitle(m_text);
m_menu->setVisible(m_visible);
m_menu->setSeparatorsCollapsible(m_separatorsCollapsible);
if (!m_icon.isNull()) {
m_menu->setIcon(m_icon);
}
if (m_menu->title() != m_text) {
m_menu->setTitle(m_text);
}
if (!m_enabled.isNull()) {
m_menu->setEnabled(m_enabled.toBool());
}
if (!m_visible.isNull()) {
m_menu->setVisible(m_visible.toBool());
}
if (!m_separatorsCollapsible.isNull()) {
m_menu->setSeparatorsCollapsible(m_separatorsCollapsible.toBool());
}
for (auto item : m_items) {
m_menu->addAction(item->action());
}
......
......@@ -22,6 +22,7 @@
#include <qpa/qplatformmenu.h>
#include <qpa/qplatformsystemtrayicon.h>
#include <QVariant>
class KStatusNotifierItem;
class SystemTrayMenuItem;
......@@ -56,9 +57,9 @@ private:
QString m_text;
QIcon m_icon;
bool m_enabled;
bool m_visible;
bool m_separatorsCollapsible;
QVariant m_enabled;
QVariant m_visible;
QVariant m_separatorsCollapsible;
quintptr m_tag;
QPointer<QMenu> m_menu;
QList<SystemTrayMenuItem*> m_items;
......
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