File: kconfigplugin.cpp

package info (click to toggle)
kdeclarative 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 24,072 kB
  • sloc: cpp: 8,161; sh: 21; makefile: 11
file content (36 lines) | stat: -rw-r--r-- 1,276 bytes parent folder | download
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
/*
    SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de>

    SPDX-License-Identifier: LGPL-2.1-or-later
*/

#include "kconfigplugin.h"

#include <KAuthorized>
#include <QQmlEngine>

#include "kauthorizedproxy.h"

void KConfigPlugin::registerTypes(const char *uri)
{
    Q_ASSERT(QString::fromLatin1(uri) == QLatin1String("org.kde.kconfig"));

    qmlRegisterSingletonType<KAuthorizedProxy>(uri, 1, 0, "KAuthorized", [](QQmlEngine *, QJSEngine *) {
        auto proxy = new KAuthorizedProxy();

        // Register the enum values dynamically, just like one can access them in from KAuthorized namespace in C++
        const QMetaEnum restriction = QMetaEnum::fromType<KAuthorized::GenericRestriction>();
        for (int i = 0, count = restriction.keyCount(); i < count; ++i) {
            const auto key = restriction.key(i);
            proxy->setProperty(key, QString::fromLatin1(key).toLower());
        }
        const QMetaEnum action = QMetaEnum::fromType<KAuthorized::GenericAction>();
        for (int i = 0, count = action.keyCount(); i < count; ++i) {
            const auto key = action.key(i);
            proxy->setProperty(key, QString::fromLatin1(key).toLower());
        }
        return proxy;
    });
}

#include "moc_kconfigplugin.cpp"