Commit 55269a9a authored by Janet Blackquill's avatar Janet Blackquill 🌈
Browse files

Add user creation and language selection

parent 5afdee00
......@@ -12,7 +12,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(GNUInstallDirs)
find_package(Qt5 COMPONENTS Core Quick QuickControls2 WaylandCompositor REQUIRED)
find_package(Qt5 COMPONENTS Core Quick QuickControls2 DBus REQUIRED)
find_package(KF5I18n)
set(DefaultPermissions
OWNER_WRITE OWNER_READ OWNER_EXECUTE
......
set(SOURCES
Sources/Main.cpp
Sources/KISS.h
Resources/Resources.qrc
)
qt5_add_dbus_interface(SOURCES
DBusProtocols/org.freedesktop.Accounts.Service.xml
AccountsService
)
qt5_add_dbus_interface(SOURCES
DBusProtocols/org.freedesktop.Accounts.User.xml
User
)
add_executable(org.kde.initialsystemsetup
${SOURCES}
)
......@@ -11,7 +21,9 @@ target_compile_definitions(org.kde.initialsystemsetup
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>
)
target_link_libraries(org.kde.initialsystemsetup
PRIVATE Qt5::Core Qt5::Quick Qt5::QuickControls2 Qt5::WaylandCompositor
PRIVATE
Qt5::Core Qt5::Quick Qt5::QuickControls2 Qt5::DBus
KF5::I18n
)
install(TARGETS org.kde.initialsystemsetup
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!-- GDBus 2.34.1 -->
<node>
<interface name="org.freedesktop.Accounts">
<method name="ListCachedUsers">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="ao" name="users" direction="out"/>
</method>
<method name="FindUserById">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="x" name="id" direction="in"/>
<arg type="o" name="user" direction="out"/>
</method>
<method name="FindUserByName">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="name" direction="in"/>
<arg type="o" name="user" direction="out"/>
</method>
<method name="CreateUser">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="name" direction="in"/>
<arg type="s" name="fullname" direction="in"/>
<arg type="i" name="accountType" direction="in"/>
<arg type="o" name="user" direction="out"/>
</method>
<method name="CacheUser">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="name" direction="in"/>
<arg type="o" name="user" direction="out"/>
</method>
<method name="UncacheUser">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="name" direction="in"/>
</method>
<method name="DeleteUser">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="x" name="id" direction="in"/>
<arg type="b" name="removeFiles" direction="in"/>
</method>
<signal name="UserAdded">
<arg type="o" name="user"/>
</signal>
<signal name="UserDeleted">
<arg type="o" name="user"/>
</signal>
<property type="s" name="DaemonVersion" access="read"/>
</interface>
</node>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!-- GDBus 2.34.1 -->
<node>
<interface name="org.freedesktop.Accounts.User">
<method name="SetUserName">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="name" direction="in"/>
</method>
<method name="SetRealName">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="name" direction="in"/>
</method>
<method name="SetEmail">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="email" direction="in"/>
</method>
<method name="SetLanguage">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="language" direction="in"/>
</method>
<method name="SetXSession">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="user_set_x_session"/>
<arg type="s" name="x_session" direction="in"/>
</method>
<method name="SetLocation">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="location" direction="in"/>
</method>
<method name="SetHomeDirectory">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="homedir" direction="in"/>
</method>
<method name="SetShell">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="shell" direction="in"/>
</method>
<method name="SetIconFile">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="filename" direction="in"/>
</method>
<method name="SetLocked">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="b" name="locked" direction="in"/>
</method>
<method name="SetAccountType">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="i" name="accountType" direction="in"/>
</method>
<method name="SetPasswordMode">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="i" name="mode" direction="in"/>
</method>
<method name="SetPassword">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="password" direction="in"/>
<arg type="s" name="hint" direction="in"/>
</method>
<method name="SetAutomaticLogin">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="b" name="enabled" direction="in"/>
</method>
<signal name="Changed"/>
<property type="t" name="Uid" access="read"/>
<property type="s" name="UserName" access="read"/>
<property type="s" name="RealName" access="read"/>
<property type="i" name="AccountType" access="read"/>
<property type="s" name="HomeDirectory" access="read"/>
<property type="s" name="Shell" access="read"/>
<property type="s" name="Email" access="read"/>
<property type="s" name="Language" access="read"/>
<property type="s" name="XSession" access="read"/>
<property type="s" name="Location" access="read"/>
<property type="t" name="LoginFrequency" access="read"/>
<property type="s" name="IconFile" access="read"/>
<property type="b" name="Locked" access="read"/>
<property type="i" name="PasswordMode" access="read"/>
<property type="s" name="PasswordHint" access="read"/>
<property type="b" name="AutomaticLogin" access="read"/>
<property type="b" name="SystemAccount" access="read"/>
<property type="b" name="LocalAccount" access="read"/>
</interface>
</node>
import QtQuick 2.0
import QtWayland.Compositor 1.3
import QtQuick 2.5
import QtQuick.Controls 2.15
import org.kde.kirigami 2.10 as Kirigami
WaylandCompositor {
id: waylandCompositor
ApplicationWindow {
id: appWindow
visible: true
Screen {
compositor: waylandCompositor
property string language: ""
Component {
id: userPage
Item {
Kirigami.FormLayout {
anchors.centerIn: parent
TextField {
id: name
}
TextField {
id: user
}
TextField {
id: pass
}
Button {
text: "clicc"
onClicked: {
KISS.createAccount(name.text, user.text, pass.text, false, appWindow.language)
}
}
}
}
}
}
StackView {
id: staccy
anchors.fill: parent
initialItem: ListView {
model: KISS.locales
delegate: Kirigami.BasicListItem {
text: modelData
onClicked: {
appWindow.language = modelData
staccy.push(userPage)
}
}
}
}
}
<RCC>
<qresource prefix="/">
<file>Main.qml</file>
<file>Screen.qml</file>
</qresource>
</RCC>
import QtQuick 2.5
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.5
import QtQuick.Window 2.2
import QtWayland.Compositor 1.0
WaylandOutput {
id: output
property bool isNestedCompositor: Qt.platform.pluginName.startsWith("wayland") || Qt.platform.pluginName === "xcb"
sizeFollowsWindow: output.isNestedCompositor
window: Window {
id: window
width: 1024
height: 760
visible: true
Rectangle {
anchors.fill: parent
color: "cyan"
}
}
}
#pragma once
#include <QDBusPendingCallWatcher>
#include <QObject>
#include <QStringList>
#include <KLocalizedString>
#include "AccountsService.h"
#define org org_collision_prevention
#include "User.h"
#undef org
class KISS : public QObject
{
Q_OBJECT
QStringList m_locales;
OrgFreedesktopAccountsInterface* m_accountsInterface;
public: KISS(QObject* parent = nullptr) : QObject(parent)
{
m_locales = QStringList(KLocalizedString::availableDomainTranslations("plasmashell").values());
m_accountsInterface = new OrgFreedesktopAccountsInterface(QStringLiteral("org.freedesktop.Accounts"), QStringLiteral("/org/freedesktop/Accounts"), QDBusConnection::systemBus(), this);
}
Q_PROPERTY(QStringList locales READ locales)
public: QStringList locales() const
{
return m_locales;
}
public: Q_SIGNAL void finished(bool success);
public: Q_INVOKABLE void createAccount(const QString& realname, const QString& username, const QString& password, const bool& admin, const QString& language)
{
auto watcher = new QDBusPendingCallWatcher(m_accountsInterface->CreateUser(username, realname, admin ? 1 : 0), this);
connect(watcher, &QDBusPendingCallWatcher::finished, [=](QDBusPendingCallWatcher* self) {
QDBusPendingReply<QDBusObjectPath> reply = *self;
if (reply.isError()) {
Q_EMIT finished(false);
return;
}
auto user = OrgFreedesktopAccountsUserInterface(QStringLiteral("org.freedesktop.Accounts"), reply.value().path(), QDBusConnection::systemBus(), this);
user.SetLanguage(language);
user.SetPassword(password, QString());
Q_EMIT finished(true);
});
}
};
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "KISS.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QScopedPointer<KISS> kiss(new KISS);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/Main.qml"));
engine.rootContext()->setContextProperty("KISS", kiss.data());
QObject::connect(
&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment