summaryrefslogtreecommitdiff
path: root/liblightdm-qt/QLightDM/user.h
blob: 08841fc16ea649e8c4cf1babda5164aec2173b80 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright (C) 2010-2011 David Edmundson.
 * Author: David Edmundson <kde@davidedmundson.co.uk>
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option) any
 * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
 * license.
 */

#ifndef QLIGHTDM_USER_H
#define QLIGHTDM_USER_H

#include <QtCore/QString>
#include <QtCore/QSharedDataPointer>
#include <QAbstractListModel>

class UserPrivate;
class UsersModelPrivate;

namespace QLightDM
{
    //public facing User class
    /** Class storing user information.
      This is an implicitly shared class. */

    class Q_DECL_EXPORT User
    {
    public:
        explicit User();
        User(const QString &name, const QString &realName, const QString &homeDirectory, const QString &image, bool isLoggedIn);
        User(const User& other);
        ~User();
        User &operator=(const User& other);

        bool update(const QString &realName, const QString &homeDirectory, const QString &image, bool isLoggedIn);

        /** The name to display (the real name if available, otherwise use the username */
        QString displayName() const;

        /** The username of the user*/
        QString name() const;
        /** The user's real name, use this for displaying*/
        QString realName() const;

        /** Returns the home directory of this user*/
        QString homeDirectory() const;

        /** Returns the path to an avatar of this user*/
        QString image() const;

        /** Returns true if this user is already logged in on another session*/
        bool isLoggedIn() const;

    //    LdmUser &operator=(const LdmUser user);
    private:
        QSharedDataPointer<UserPrivate> d;
    };

    class Q_DECL_EXPORT UsersModel : public QAbstractListModel
    {
        Q_OBJECT
    public:
        explicit UsersModel(QObject *parent = 0);
        ~UsersModel();

        enum UserModelRoles {NameRole = Qt::UserRole,
                             RealNameRole,
                             LoggedInRole};

        int rowCount(const QModelIndex &parent) const;
        QVariant data(const QModelIndex &index, int role) const;

    signals:

    public slots:

    private slots:
        /** Updates the model with new changes in the password file*/
        void loadUsers();

    private:
        /** Returns a list of all users in the password file*/
        QList<User> getUsers();
        UsersModelPrivate *d;
    };

    UsersModel *users();
}

#endif // QLIGHTDM_USER_H