File indexing completed on 2024-04-21 04:42:44

0001 /*
0002     SPDX-FileCopyrightText: 2018 Frederik Gladhorn <gladhorn@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include <QCoreApplication>
0008 #include <QTextStream>
0009 
0010 #include "dumper.h"
0011 
0012 using namespace QAccessibleClient;
0013 
0014 QTextStream out(stdout);
0015 
0016 Dumper::Dumper(QObject *parent)
0017     : QObject(parent)
0018 {
0019 }
0020 
0021 void Dumper::run(const QString &appname) const {
0022     Registry r;
0023     const auto apps = r.applications();
0024     for (const AccessibleObject &app : apps) {
0025         if (appname.isEmpty() || app.name().contains(appname)) {
0026             printChild(app);
0027         }
0028     }
0029 }
0030 
0031 void Dumper::printChild(const AccessibleObject &object, int indent) const
0032 {
0033     auto spaces = QStringLiteral("  ");
0034     if (!object.isValid()) {
0035         out << spaces.repeated(indent) << "INVALID CHILD" << Qt::endl;
0036         return;
0037     }
0038 
0039     auto name = object.name().isEmpty() ? QStringLiteral("[unnamed]") : object.name();
0040     QString info = QStringLiteral("%1 [%2 - %3] '%4'").arg(name, QString::number(object.role()), object.roleName(), object.description());
0041     if (m_showStates) {
0042         info += QStringLiteral(" [%1]").arg(object.stateString());
0043     }
0044     out << spaces.repeated(indent) << info << Qt::endl;
0045     int childCount = object.childCount();
0046     for (int i = 0; i < childCount; ++i) {
0047         AccessibleObject child = object.child(i);
0048         // simple test if the parent is consistent
0049         if (child.parent() != object) {
0050             out << spaces.repeated(indent + 4) << "WARNING: inconsistent parent/child hierarchy";
0051         }
0052         if (child.indexInParent() != i) {
0053             out << spaces.repeated(indent + 4) << QString::fromLatin1("WARNING: child index inconsistent: child claims to be child %1 parent thinks it is %2").arg(child.indexInParent(), i);
0054         }
0055         printChild(child, indent + 1);
0056     }
0057 }
0058 
0059 #include "moc_dumper.cpp"