File indexing completed on 2025-01-05 04:35:37

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003     SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org>
0004 */
0005 
0006 #include <QObject>
0007 
0008 #pragma once
0009 
0010 class UserManager;
0011 
0012 class User : public QObject
0013 {
0014     Q_OBJECT
0015     Q_PROPERTY(QString name READ name CONSTANT)
0016     Q_PROPERTY(bool inSamba READ inSamba NOTIFY inSambaChanged)
0017 public:
0018     explicit User(const QString &name, UserManager *parent);
0019 
0020     void resolve();
0021     QString name() const;
0022     bool inSamba() const;
0023 
0024     Q_INVOKABLE void addToSamba(const QString &password);
0025 
0026 Q_SIGNALS:
0027     void resolved();
0028     void inSambaChanged();
0029     // stderr of smbpasswd if it came back with a failure. This may be multiple lines but usually is not.
0030     void addToSambaError(const QString &error);
0031 
0032 private:
0033     const QString m_name;
0034     bool m_inSamba = false; // tdbsam knows about this user already
0035 };
0036 
0037 class UserManager : public QObject
0038 {
0039     Q_OBJECT
0040 public:
0041     using QObject::QObject;
0042 
0043     bool canManageSamba() const;
0044     QList<User *> users() const;
0045     Q_INVOKABLE User *currentUser() const;
0046 
0047 public Q_SLOTS:
0048     void load();
0049 
0050 Q_SIGNALS:
0051     void loaded();
0052 
0053 private:
0054     QList<User *> m_users;
0055     User *m_currentUser = nullptr;
0056     bool m_canManageSamba = false;
0057     int m_waitingForResolution = 0;
0058 };