1/* This file is part of the KDE project
2 * Copyright (C) 2010 Sebastian Sauer <sebsauer@kdab.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19#ifndef KACCESSIBLEINTERFACE_H
20#define KACCESSIBLEINTERFACE_H
21
22#include <QMetaType>
23#include <QMetaObject>
24#include <QList>
25#include <QAccessibleInterface>
26#include <QDBusArgument>
27
28/**
29 * This class represents the QAccessibleInterface information of
30 * a QObject transported over dbus from the \a Bridge dbus-service to
31 * the \a KAccessibleApp application.
32 */
33class KAccessibleInterface
34{
35 public:
36 QString name;
37 QString description;
38 QString value;
39 QString accelerator;
40 QRect rect;
41
42 QString objectName;
43 QString className;
44
45 QAccessible::State state;
46
47 explicit KAccessibleInterface() : state(QFlags<QAccessible::StateFlag>()) {}
48
49 void set(QAccessibleInterface *interface, int child)
50 {
51 name = interface->text(QAccessible::Name, child);
52 const QString desc = interface->text(QAccessible::Description, child);
53 description = desc.isEmpty() ? interface->text(QAccessible::Help, child) : desc;
54 value = interface->text(QAccessible::Value, child);
55 accelerator = interface->text(QAccessible::Accelerator, child);
56 rect = interface->rect(child);
57 objectName = interface->object()->objectName();
58 QObject *object = interface->object();
59 className = QString::fromLatin1(object->metaObject()->className());
60 state = interface->state(child);
61 }
62};
63
64Q_DECLARE_METATYPE(KAccessibleInterface)
65
66//typedef QList<KAccessibleInterface*> KAccessibleInterfaceList;
67//Q_DECLARE_METATYPE(KAccessibleInterfaceList)
68
69QDBusArgument &operator<<(QDBusArgument &argument, const KAccessibleInterface &a)
70{
71 argument.beginStructure();
72 argument << a.name << a.description << a.value << a.accelerator << a.rect << a.objectName << a.className << int(a.state);
73 argument.endStructure();
74 return argument;
75}
76
77const QDBusArgument &operator>>(const QDBusArgument &argument, KAccessibleInterface &a)
78{
79 argument.beginStructure();
80 int state;
81 argument >> a.name >> a.description >> a.value >> a.accelerator >> a.rect >> a.objectName >> a.className >> state;
82 a.state = QAccessible::State(state);
83 argument.endStructure();
84 return argument;
85}
86
87QString reasonToString(int reason)
88{
89 switch(reason) {
90 case QAccessible::Focus: return QLatin1String( "Focus" );
91 case QAccessible::MenuCommand: return QLatin1String( "MenuCommand" );
92 case QAccessible::MenuStart: return QLatin1String( "MenuStart" );
93 case QAccessible::MenuEnd: return QLatin1String( "MenuEnd" );
94 case QAccessible::PopupMenuEnd: return QLatin1String( "PopupMenuEnd" );
95 case QAccessible::PopupMenuStart: return QLatin1String( "PopupMenuStart" );
96 case QAccessible::ScrollingEnd: return QLatin1String( "ScrollingEnd" );
97 case QAccessible::ScrollingStart: return QLatin1String( "ScrollingStart" );
98 case QAccessible::Selection: return QLatin1String( "Selection" );
99 case QAccessible::StateChanged: return QLatin1String( "StateChanged" );
100 case QAccessible::ValueChanged: return QLatin1String( "ValueChanged" );
101 case QAccessible::NameChanged: return QLatin1String( "NameChanged" );
102 case QAccessible::ObjectCreated: return QLatin1String( "ObjectCreated" );
103 case QAccessible::ObjectDestroyed: return QLatin1String( "ObjectDestroyed" );
104 case QAccessible::ObjectHide: return QLatin1String( "ObjectHide" );
105 case QAccessible::ObjectReorder: return QLatin1String( "ObjectReorder" );
106 case QAccessible::ObjectShow: return QLatin1String( "ObjectShow" );
107 case QAccessible::ParentChanged: return QLatin1String( "ParentChanged" );
108 case QAccessible::Alert: return QLatin1String( "Alert" );
109 case QAccessible::DefaultActionChanged: return QLatin1String( "DefaultActionChanged" );
110 case QAccessible::DialogEnd: return QLatin1String( "DialogEnd" );
111 case QAccessible::DialogStart: return QLatin1String( "DialogStart" );
112 case QAccessible::DragDropEnd: return QLatin1String( "DragDropEnd" );
113 case QAccessible::DragDropStart: return QLatin1String( "DragDropStart" );
114 case QAccessible::ForegroundChanged: return QLatin1String( "ForegroundChanged" );
115 case QAccessible::LocationChanged: return QLatin1String( "LocationChanged" );
116 case QAccessible::SelectionAdd: return QLatin1String( "SelectionAdd" );
117 case QAccessible::SelectionRemove: return QLatin1String( "SelectionRemove" );
118 case QAccessible::SelectionWithin: return QLatin1String( "SelectionWithin" );
119 }
120 return QString::number(reason);
121}
122
123QString stateToString(QAccessible::State flags)
124{
125 QString result;
126 if(flags & QAccessible::Animated) result += QLatin1String( "Animated " );
127 if(flags & QAccessible::Busy) result += QLatin1String( "Busy " );
128 if(flags & QAccessible::Checked) result += QLatin1String( "Checked " );
129 if(flags & QAccessible::Collapsed) result += QLatin1String( "Collapsed " );
130 if(flags & QAccessible::DefaultButton) result += QLatin1String( "DefaultButton " );
131 if(flags & QAccessible::Expanded) result += QLatin1String( "Expanded " );
132 if(flags & QAccessible::ExtSelectable) result += QLatin1String( "ExtSelectable " );
133 if(flags & QAccessible::Focusable) result += QLatin1String( "Focusable " );
134 if(flags & QAccessible::Focused) result += QLatin1String( "Focused " );
135 if(flags & QAccessible::HasPopup) result += QLatin1String( "HasPopup " );
136 if(flags & QAccessible::HotTracked) result += QLatin1String( "HotTracked " );
137 if(flags & QAccessible::Invisible) result += QLatin1String( "Invisible " );
138 if(flags & QAccessible::Linked) result += QLatin1String( "Linked " );
139 if(flags & QAccessible::Marqueed) result += QLatin1String( "Marqueed " );
140 if(flags & QAccessible::Mixed) result += QLatin1String( "Mixed " );
141 if(flags & QAccessible::Modal) result += QLatin1String( "Modal " );
142 if(flags & QAccessible::Movable) result += QLatin1String( "Movable " );
143 if(flags & QAccessible::MultiSelectable) result += QLatin1String( "MultiSelectable " );
144 if(flags & QAccessible::Normal) result += QLatin1String( "Normal " );
145 if(flags & QAccessible::Offscreen) result += QLatin1String( "Offscreen " );
146 if(flags & QAccessible::Pressed) result += QLatin1String( "Pressed " );
147 if(flags & QAccessible::Protected) result += QLatin1String( "Protected " );
148 if(flags & QAccessible::ReadOnly) result += QLatin1String( "ReadOnly " );
149 if(flags & QAccessible::Selectable) result += QLatin1String( "Selectable " );
150 if(flags & QAccessible::Selected) result += QLatin1String( "Selected " );
151 if(flags & QAccessible::SelfVoicing) result += QLatin1String( "SelfVoicing " );
152 if(flags & QAccessible::Sizeable) result += QLatin1String( "Sizeable " );
153 if(flags & QAccessible::Traversed) result += QLatin1String( "Traversed " );
154 if(flags & QAccessible::Unavailable) result += QLatin1String( "Unavailable " );
155 return result.trimmed();
156}
157
158#endif
159