File indexing completed on 2025-01-12 03:40:50

0001 /* This file is part of the dbusmenu-qt library
0002    SPDX-FileCopyrightText: 2009 Canonical
0003    Author: Aurelien Gateau <aurelien.gateau@canonical.com>
0004 
0005    SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 #include "dbusmenu_p.h"
0008 
0009 // Qt
0010 #include <QAction>
0011 #include <QActionEvent>
0012 #include <QMenu>
0013 
0014 // Local
0015 #include "dbusmenuexporter.h"
0016 #include "dbusmenuexporterprivate_p.h"
0017 #include "debug_p.h"
0018 
0019 DBusMenu::DBusMenu(QMenu *menu, DBusMenuExporter *exporter, int parentId)
0020     : QObject(menu)
0021     , m_exporter(exporter)
0022     , m_parentId(parentId)
0023 {
0024     menu->installEventFilter(this);
0025     connect(m_exporter, SIGNAL(destroyed(QObject *)), SLOT(deleteMe()));
0026 }
0027 
0028 DBusMenu::~DBusMenu()
0029 {
0030 }
0031 
0032 bool DBusMenu::eventFilter(QObject *, QEvent *event)
0033 {
0034     QActionEvent *actionEvent = nullptr;
0035     switch (event->type()) {
0036     case QEvent::ActionAdded:
0037     case QEvent::ActionChanged:
0038     case QEvent::ActionRemoved:
0039         actionEvent = static_cast<QActionEvent *>(event);
0040         break;
0041     default:
0042         return false;
0043     }
0044     switch (event->type()) {
0045     case QEvent::ActionAdded:
0046         addAction(actionEvent->action());
0047         break;
0048     case QEvent::ActionChanged:
0049         updateAction(actionEvent->action());
0050         break;
0051     case QEvent::ActionRemoved:
0052         removeAction(actionEvent->action());
0053         break;
0054     default:
0055         break;
0056     }
0057     return false;
0058 }
0059 
0060 void DBusMenu::addAction(QAction *action)
0061 {
0062     m_exporter->d->addAction(action, m_parentId);
0063 }
0064 
0065 void DBusMenu::updateAction(QAction *action)
0066 {
0067     m_exporter->d->updateAction(action);
0068 }
0069 
0070 void DBusMenu::removeAction(QAction *action)
0071 {
0072     m_exporter->d->removeAction(action, m_parentId);
0073 }
0074 
0075 void DBusMenu::deleteMe()
0076 {
0077     delete this;
0078 }
0079 
0080 #include "moc_dbusmenu_p.cpp"