1 /* This file is part of the dbusmenu-qt library
2 Copyright 2009 Canonical
3 Author: Aurelien Gateau <aurelien.gateau@canonical.com>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License (LGPL) as published by the Free Software Foundation;
8 either version 2 of the License, or (at your option) any later
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
21 #include "dbusmenu_p.h"
25 #include <QActionEvent>
29 #include "dbusmenuexporter.h"
30 #include "dbusmenuexporterprivate_p.h"
33 DBusMenu::DBusMenu(QMenu *menu, DBusMenuExporter *exporter, int parentId)
35 , m_exporter(exporter)
36 , m_parentId(parentId)
38 menu->installEventFilter(this);
39 connect(m_exporter, SIGNAL(destroyed(QObject*)), SLOT(deleteMe()));
46 bool DBusMenu::eventFilter(QObject *, QEvent *event)
48 switch (event->type()) {
49 case QEvent::ActionAdded:
50 addAction(static_cast<QActionEvent *>(event)->action());
52 case QEvent::ActionChanged:
53 updateAction(static_cast<QActionEvent *>(event)->action());
55 case QEvent::ActionRemoved:
56 removeAction(static_cast<QActionEvent *>(event)->action());
64 void DBusMenu::addAction(QAction *action)
66 m_exporter->d->addAction(action, m_parentId);
69 void DBusMenu::updateAction(QAction *action)
71 m_exporter->d->updateAction(action);
74 void DBusMenu::removeAction(QAction *action)
76 m_exporter->d->removeAction(action, m_parentId);
79 void DBusMenu::deleteMe()
84 #include "moc_dbusmenu_p.cpp"