Commit 093da790 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

Split constructor with tons of arguments into separate setters

Also init after having connected to signals, this might fix issues where the menu won't show up the first time
an application window shows as the menu might have requested setting the window properties before we connected
to that (unlikely, but who knows).
This is in preparation for being able to fall back from window menu to application menu should the former be empty.
parent e1ce3d4c
......@@ -39,24 +39,23 @@
static const QString s_orgGtkActions = QStringLiteral("org.gtk.Actions");
static const QString s_orgGtkMenus = QStringLiteral("org.gtk.Menus");
Menu::Menu(WId winId,
const QString &serviceName,
const QString &applicationObjectPath,
const QString &unityObjectPath,
const QString &windowObjectPath,
const QString &menuObjectPath)
Menu::Menu(const QString &serviceName)
: QObject()
, m_winId(winId)
, m_serviceName(serviceName)
, m_applicationObjectPath(applicationObjectPath)
, m_unityObjectPath(unityObjectPath)
, m_windowObjectPath(windowObjectPath)
, m_menuObjectPath(menuObjectPath)
{
qCDebug(DBUSMENUPROXY) << "Created menu for" << m_winId << "on" << m_serviceName << "at app" << m_applicationObjectPath << "win" << m_windowObjectPath << "unity" << m_unityObjectPath << "menu" << m_menuObjectPath;
qCDebug(DBUSMENUPROXY) << "Created menu on" << serviceName;
Q_ASSERT(!serviceName.isEmpty());
GDBusMenuTypes_register();
DBusMenuTypes_register();
}
Menu::~Menu() = default;
void Menu::init()
{
qCDebug(DBUSMENUPROXY) << "Inited menu for" << m_winId << "on" << m_serviceName << "at app" << m_applicationObjectPath << "win" << m_windowObjectPath << "unity" << m_unityObjectPath << "menu" << m_menuObjectPath;
if (!QDBusConnection::sessionBus().connect(m_serviceName,
m_menuObjectPath,
......@@ -99,11 +98,11 @@ Menu::Menu(WId winId,
getActions(m_applicationObjectPath, [this](const GMenuActionMap &actions, bool ok) {
if (ok) {
// TODO just do all of this in getActions instead of copying it thrice
if (m_inited) {
if (m_menuInited) {
onApplicationActionsChanged({}, {}, {}, actions);
} else {
m_applicationActions = actions;
init();
initMenu();
}
}
});
......@@ -112,11 +111,11 @@ Menu::Menu(WId winId,
if (!m_unityObjectPath.isEmpty()) {
getActions(m_unityObjectPath, [this](const GMenuActionMap &actions, bool ok) {
if (ok) {
if (m_inited) {
if (m_menuInited) {
onUnityActionsChanged({}, {}, {}, actions);
} else {
m_unityActions = actions;
init();
initMenu();
}
}
});
......@@ -125,19 +124,17 @@ Menu::Menu(WId winId,
if (!m_windowObjectPath.isEmpty()) {
getActions(m_windowObjectPath, [this](const GMenuActionMap &actions, bool ok) {
if (ok) {
if (m_inited) {
if (m_menuInited) {
onWindowActionsChanged({}, {}, {}, actions);
} else {
m_windowActions = actions;
init();
initMenu();
}
}
});
}
}
Menu::~Menu() = default;
void Menu::cleanup()
{
stop(m_subscriptions);
......@@ -150,6 +147,11 @@ WId Menu::winId() const
return m_winId;
}
void Menu::setWinId(WId winId)
{
m_winId = winId;
}
QString Menu::serviceName() const
{
return m_serviceName;
......@@ -160,24 +162,49 @@ QString Menu::applicationObjectPath() const
return m_applicationObjectPath;
}
void Menu::setApplicationObjectPath(const QString &applicationObjectPath)
{
m_applicationObjectPath = applicationObjectPath;
}
QString Menu::unityObjectPath() const
{
return m_unityObjectPath;
}
void Menu::setUnityObjectPath(const QString &unityObjectPath)
{
m_unityObjectPath = unityObjectPath;
}
QString Menu::windowObjectPath() const
{
return m_windowObjectPath;
}
void Menu::setWindowObjectPath(const QString &windowObjectPath)
{
m_windowObjectPath = windowObjectPath;
}
QString Menu::menuObjectPath() const
{
return m_menuObjectPath;
}
void Menu::setMenuObjectPath(const QString &menuObjectPath)
{
m_menuObjectPath = menuObjectPath;
}
QString Menu::proxyObjectPath() const
{
return m_proxyObjectPath;
}
void Menu::init()
void Menu::initMenu()
{
if (m_inited) {
if (m_menuInited) {
return;
}
......@@ -186,7 +213,7 @@ void Menu::init()
}
emit requestWriteWindowProperties();
m_inited = true;
m_menuInited = true;
}
void Menu::start(uint id)
......@@ -392,7 +419,7 @@ void Menu::onMenuChanged(const GMenuChangeList &changes)
void Menu::onApplicationActionsChanged(const QStringList &removed, const StringBoolMap &enabledChanges, const QVariantMap &stateChanges, const GMenuActionMap &added)
{
if (!m_inited) {
if (!m_menuInited) {
return;
}
actionsChanged(removed, enabledChanges, stateChanges, added, m_applicationActions, QStringLiteral("app."));
......@@ -400,7 +427,7 @@ void Menu::onApplicationActionsChanged(const QStringList &removed, const StringB
void Menu::onUnityActionsChanged(const QStringList &removed, const StringBoolMap &enabledChanges, const QVariantMap &stateChanges, const GMenuActionMap &added)
{
if (!m_inited) {
if (!m_menuInited) {
return;
}
actionsChanged(removed, enabledChanges, stateChanges, added, m_unityActions, QStringLiteral("unity."));
......@@ -408,7 +435,7 @@ void Menu::onUnityActionsChanged(const QStringList &removed, const StringBoolMap
void Menu::onWindowActionsChanged(const QStringList &removed, const StringBoolMap &enabledChanges, const QVariantMap &stateChanges, const GMenuActionMap &added)
{
if (!m_inited) {
if (!m_menuInited) {
return;
}
actionsChanged(removed, enabledChanges, stateChanges, added, m_windowActions, QStringLiteral("win."));
......
......@@ -41,23 +41,28 @@ class Menu : public QObject, protected QDBusContext
Q_PROPERTY(uint Version READ version)
public:
Menu(WId winId,
const QString &serviceName,
const QString &applicationObjectPath,
const QString &unityObjectPath,
const QString &windowObjectPath,
const QString &menuObjectPath);
Menu(const QString &serviceName);
~Menu();
void init();
void cleanup();
WId winId() const;
void setWinId(WId winId);
QString serviceName() const;
QString applicationObjectPath() const;
void setApplicationObjectPath(const QString &applicationObjectPath);
QString unityObjectPath() const;
void setUnityObjectPath(const QString &unityObjectPath);
QString windowObjectPath() const;
void setWindowObjectPath(const QString &windowObjectPath);
QString menuObjectPath() const;
void setMenuObjectPath(const QString &menuObjectPath);
QString proxyObjectPath() const;
......@@ -88,7 +93,7 @@ private slots:
void onWindowActionsChanged(const QStringList &removed, const StringBoolMap &enabledChanges, const QVariantMap &stateChanges, const GMenuActionMap &added);
private:
void init();
void initMenu();
void start(uint id);
void stop(const QList<uint> &id);
......@@ -110,7 +115,7 @@ private:
QVariantMap gMenuToDBusMenuProperties(const QVariantMap &source) const;
WId m_winId;
WId m_winId = 0;
QString m_serviceName; // original GMenu service (the gtk app)
QString m_applicationObjectPath;
......@@ -131,6 +136,6 @@ private:
GMenuActionMap m_windowActions;
GMenuActionMap m_unityActions;
bool m_inited = false;
bool m_menuInited = false;
};
......@@ -185,7 +185,12 @@ void MenuProxy::onWindowAdded(WId id)
return;
}
Menu *menu = new Menu(id, serviceName, applicationObjectPath, unityObjectPath, windowObjectPath, menuObjectPath);
Menu *menu = new Menu(serviceName);
menu->setWinId(id);
menu->setApplicationObjectPath(applicationObjectPath);
menu->setUnityObjectPath(unityObjectPath);
menu->setWindowObjectPath(windowObjectPath);
menu->setMenuObjectPath(menuObjectPath);
m_menus.insert(id, menu);
connect(menu, &Menu::requestWriteWindowProperties, this, [this, menu] {
......@@ -198,6 +203,8 @@ void MenuProxy::onWindowAdded(WId id)
writeWindowProperty(menu->winId(), s_kdeNetWmAppMenuServiceName, QByteArray());
writeWindowProperty(menu->winId(), s_kdeNetWmAppMenuObjectPath, QByteArray());
});
menu->init();
}
void MenuProxy::onWindowRemoved(WId id)
......
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