File indexing completed on 2024-04-28 05:36:12

0001 /*  This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
0003     SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef IDENTITIESMODEL_H
0009 #define IDENTITIESMODEL_H
0010 
0011 #include <PolkitQt1/Identity>
0012 #include <QAbstractListModel>
0013 #include <QIcon>
0014 
0015 class IdentitiesModel : public QAbstractListModel
0016 {
0017     Q_OBJECT
0018 public:
0019     IdentitiesModel(QObject *parent = nullptr);
0020 
0021     void setIdentities(const PolkitQt1::Identity::List &identities, bool withVoidItem);
0022     PolkitQt1::Identity::List identities() const
0023     {
0024         return m_identities;
0025     }
0026 
0027     QVariant data(const QModelIndex &index, int role) const override;
0028     int rowCount(const QModelIndex &parent) const override;
0029     Qt::ItemFlags flags(const QModelIndex &index) const override;
0030     int indexForUser(const QString &loginName) const;
0031     Q_INVOKABLE QString iconForIndex(int index) const;
0032 
0033     QHash<int, QByteArray> roleNames() const override;
0034 
0035 private:
0036     PolkitQt1::Identity::List m_identities;
0037 
0038     struct Id {
0039         QString decoration;
0040         QString display;
0041         QString userRole;
0042         QString loginName;
0043     };
0044     QList<Id> m_ids;
0045 };
0046 
0047 #endif