Debian Codegraph @

src/dbusmenu_p.cpp

raw symbols SCIP
1 /* This file is part of the dbusmenu-qt library
2 Copyright 2009 Canonical
3 Author: Aurelien Gateau <[email protected]>
4
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
9 version.
10
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.
15
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.
20 */
21 #include "dbusmenu_p.h"
22
23 // Qt
24 #include <QAction>
25 #include <QActionEvent>
26 #include <QMenu>
27
28 // Local
29 #include "dbusmenuexporter.h"
30 #include "dbusmenuexporterprivate_p.h"
31 #include "debug_p.h"
32
33 DBusMenu::DBusMenu(QMenu *menu, DBusMenuExporter *exporter, int parentId)
34 : QObject(menu)
35 , m_exporter(exporter)
36 , m_parentId(parentId)
37 {
38 menu->installEventFilter(this);
39 connect(m_exporter, SIGNAL(destroyed(QObject*)), SLOT(deleteMe()));
40 }
41
42 DBusMenu::~DBusMenu()
43 {
44 }
45
46 bool DBusMenu::eventFilter(QObject *, QEvent *event)
47 {
48 QActionEvent *actionEvent = 0;
49 switch (event->type()) {
50 case QEvent::ActionAdded:
51 case QEvent::ActionChanged:
52 case QEvent::ActionRemoved:
53 actionEvent = static_cast<QActionEvent *>(event);
54 break;
55 default:
56 return false;
57 }
58 switch (event->type()) {
59 case QEvent::ActionAdded:
60 addAction(actionEvent->action());
61 break;
62 case QEvent::ActionChanged:
63 updateAction(actionEvent->action());
64 break;
65 case QEvent::ActionRemoved:
66 removeAction(actionEvent->action());
67 break;
68 default:
69 break;
70 }
71 return false;
72 }
73
74 void DBusMenu::addAction(QAction *action)
75 {
76 m_exporter->d->addAction(action, m_parentId);
77 }
78
79 void DBusMenu::updateAction(QAction *action)
80 {
81 m_exporter->d->updateAction(action);
82 }
83
84 void DBusMenu::removeAction(QAction *action)
85 {
86 m_exporter->d->removeAction(action, m_parentId);
87 }
88
89 void DBusMenu::deleteMe()
90 {
91 delete this;
92 }
93
94 #include "dbusmenu_p.moc"