1 /*
2     Copyright 2012 Frederik Gladhorn <gladhorn@kde.org>
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License as published by the Free Software Foundation; either
7     version 2.1 of the License, or (at your option) version 3, or any
8     later version accepted by the membership of KDE e.V. (or its
9     successor approved by the membership of KDE e.V.), which shall
10     act as a proxy defined in Section 6 of version 3 of the license.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Lesser General Public License for more details.
16 
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "registry.h"
22 #include "registry_p.h"
23 
24 #include <qurl.h>
25 
26 using namespace QAccessibleClient;
27 
Registry(QObject * parent)28 Registry::Registry(QObject *parent)
29     : QObject(parent), d(new RegistryPrivate(this))
30 {
31     registerDBusTypes();
32 }
33 
~Registry()34 Registry::~Registry()
35 {
36     delete d;
37 }
38 
isEnabled() const39 bool Registry::isEnabled() const
40 {
41     return d->isEnabled();
42 }
43 
setEnabled(bool enable)44 void Registry::setEnabled(bool enable)
45 {
46     d->setEnabled(enable);
47 }
48 
isScreenReaderEnabled() const49 bool Registry::isScreenReaderEnabled() const
50 {
51     return d->isScreenReaderEnabled();
52 }
53 
setScreenReaderEnabled(bool enable)54 void Registry::setScreenReaderEnabled(bool enable)
55 {
56     d->setScreenReaderEnabled(enable);
57 }
58 
subscribeEventListeners(const EventListeners & listeners) const59 void Registry::subscribeEventListeners(const EventListeners &listeners) const
60 {
61     d->subscribeEventListeners(listeners);
62 }
63 
subscribedEventListeners() const64 Registry::EventListeners Registry::subscribedEventListeners() const
65 {
66     return d->eventListeners();
67 }
68 
applications() const69 QList<AccessibleObject> Registry::applications() const
70 {
71     return d->topLevelAccessibles();
72 }
73 
accessibleFromUrl(const QUrl & url) const74 AccessibleObject Registry::accessibleFromUrl(const QUrl &url) const
75 {
76     return d->fromUrl(url);
77 }
78 
cacheType() const79 Registry::CacheType Registry::cacheType() const
80 {
81     if (dynamic_cast<CacheWeakStrategy*>(d->m_cache))
82         return WeakCache;
83     return NoCache;
84 }
85 
setCacheType(Registry::CacheType type)86 void Registry::setCacheType(Registry::CacheType type)
87 {
88     //if (cacheType() == type) return;
89     delete d->m_cache;
90     d->m_cache = nullptr;
91     switch (type) {
92         case NoCache:
93             break;
94         case WeakCache:
95             d->m_cache = new CacheWeakStrategy();
96             break;
97     }
98 }
99 
clientCacheObject(const QString & id) const100 AccessibleObject Registry::clientCacheObject(const QString &id) const
101 {
102     if (d->m_cache) {
103         QSharedPointer<AccessibleObjectPrivate> p = d->m_cache->get(id);
104         if (p)
105             return AccessibleObject(p);
106     }
107     return AccessibleObject();
108 }
109 
clientCacheObjects() const110 QStringList Registry::clientCacheObjects() const
111 {
112     QStringList result;
113     if (d->m_cache)
114         return d->m_cache->ids();
115     return QStringList();
116 }
117 
clearClientCache()118 void Registry::clearClientCache()
119 {
120     if (d->m_cache)
121         d->m_cache->clear();
122 }
123 
124 #include "moc_registry.cpp"
125