File: dumper.cpp

package info (click to toggle)
libqaccessibilityclient 0.6.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 612 kB
  • sloc: cpp: 3,632; makefile: 9; sh: 7
file content (59 lines) | stat: -rw-r--r-- 1,897 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
    SPDX-FileCopyrightText: 2018 Frederik Gladhorn <gladhorn@kde.org>

    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/

#include <QCoreApplication>
#include <QTextStream>

#include "dumper.h"

using namespace QAccessibleClient;

QTextStream out(stdout);

Dumper::Dumper(QObject *parent)
    : QObject(parent)
{
}

void Dumper::run(const QString &appname) const {
    Registry r;
    const auto apps = r.applications();
    for (const AccessibleObject &app : apps) {
        if (appname.isEmpty() || app.name().contains(appname)) {
            printChild(app);
        }
    }
}

void Dumper::printChild(const AccessibleObject &object, int indent) const
{
    auto spaces = QStringLiteral("  ");
    if (!object.isValid()) {
        out << spaces.repeated(indent) << "INVALID CHILD" << Qt::endl;
        return;
    }

    auto name = object.name().isEmpty() ? QStringLiteral("[unnamed]") : object.name();
    QString info = QStringLiteral("%1 [%2 - %3] '%4'").arg(name, QString::number(object.role()), object.roleName(), object.description());
    if (m_showStates) {
        info += QStringLiteral(" [%1]").arg(object.stateString());
    }
    out << spaces.repeated(indent) << info << Qt::endl;
    int childCount = object.childCount();
    for (int i = 0; i < childCount; ++i) {
        AccessibleObject child = object.child(i);
        // simple test if the parent is consistent
        if (child.parent() != object) {
            out << spaces.repeated(indent + 4) << "WARNING: inconsistent parent/child hierarchy";
        }
        if (child.indexInParent() != i) {
            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);
        }
        printChild(child, indent + 1);
    }
}

#include "moc_dumper.cpp"