OSDN Git Service

use only one case switch in DBusMenu::eventFilter()
[kde/libdbusmenu-qt.git] / src / dbusmenu_p.cpp
1 /* This file is part of the dbusmenu-qt library
2    Copyright 2009 Canonical
3    Author: Aurelien Gateau <aurelien.gateau@canonical.com>
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     switch (event->type()) {
49     case QEvent::ActionAdded:
50         addAction(static_cast<QActionEvent *>(event)->action());
51         break;
52     case QEvent::ActionChanged:
53         updateAction(static_cast<QActionEvent *>(event)->action());
54         break;
55     case QEvent::ActionRemoved:
56         removeAction(static_cast<QActionEvent *>(event)->action());
57         break;
58     default:
59         break;
60     }
61     return false;
62 }
63
64 void DBusMenu::addAction(QAction *action)
65 {
66     m_exporter->d->addAction(action, m_parentId);
67 }
68
69 void DBusMenu::updateAction(QAction *action)
70 {
71     m_exporter->d->updateAction(action);
72 }
73
74 void DBusMenu::removeAction(QAction *action)
75 {
76     m_exporter->d->removeAction(action, m_parentId);
77 }
78
79 void DBusMenu::deleteMe()
80 {
81     delete this;
82 }
83
84 #include "moc_dbusmenu_p.cpp"