accountmodel.h 4.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*************************************************************************************
 *  Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org>              *
 *                                                                                   *
 *  This program is free software; you can redistribute it and/or                    *
 *  modify it under the terms of the GNU General Public License                      *
 *  as published by the Free Software Foundation; either version 2                   *
 *  of the License, or (at your option) any later version.                           *
 *                                                                                   *
 *  This program is distributed in the hope that it will be useful,                  *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
 *  GNU General Public License for more details.                                     *
 *                                                                                   *
 *  You should have received a copy of the GNU General Public License                *
 *  along with this program; if not, write to the Free Software                      *
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
 *************************************************************************************/


#ifndef ACCOUNTMODEL_H
#define ACCOUNTMODEL_H

Laurent Montel's avatar
Laurent Montel committed
23
#include "user_manager_debug.h"
Yuri Chornoivan's avatar
Yuri Chornoivan committed
24
25
#include <QStringList>
#include <QAbstractListModel>
26
#include <QDBusObjectPath>
27
#include <QDBusPendingReply>
28
#include <KEMailSettings>
29

30
class UserSession;
31
32
class OrgFreedesktopAccountsInterface;
class OrgFreedesktopAccountsUserInterface;
33
34
35
36
37
38
39
40
41
42

class AutomaticLoginSettings {
public:
    AutomaticLoginSettings();
    QString autoLoginUser() const;
    bool setAutoLoginUser(const QString &username);
private:
    QString m_autoLoginUser;
};

43
44
45
46
class AccountModel : public QAbstractListModel
{
    Q_OBJECT
    public:
Àlex Fiestas's avatar
Àlex Fiestas committed
47
        enum Role {
48
49
50
51
            FriendlyName = Qt::DisplayRole,
            Face = Qt::DecorationRole,
            RealName = Qt::UserRole,
            Username,
52
            Password,
53
54
            Email,
            Administrator,
55
            AutomaticLogin,
56
            Logged,
57
            Created
58
59
        };

Laurent Montel's avatar
Laurent Montel committed
60
        explicit AccountModel(QObject* parent);
Laurent Montel's avatar
Laurent Montel committed
61
62
63
64
65
66
        ~AccountModel() override;
        int rowCount(const QModelIndex& parent = QModelIndex()) const override;
        QVariant data(const QModelIndex& index, int role) const override;
        QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
        bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
        bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
67
        bool removeAccountKeepingFiles(int row, bool keepFile = false);
68
        void setDpr(qreal dpr);
69

70
        QVariant newUserData(int role) const;
71
        bool newUserSetData(const QModelIndex& index, const QVariant& value, int roleInt);
72

73
    public Q_SLOTS:
74
        void UserAdded(const QDBusObjectPath &dbusPah);
75
        void UserDeleted(const QDBusObjectPath &path);
76
        void Changed();
77
        void userLogged(uint uid, bool logged);
78

79
    private:
80
        const QString accountPathForUid(uint uid) const;
81
82
        void addAccount(const QString &path);
        void addAccountToCache(const QString &path, OrgFreedesktopAccountsUserInterface *acc, int pos = -1);
83
        void replaceAccount(const QString &path, OrgFreedesktopAccountsUserInterface *acc, int pos);
84
        void removeAccount(const QString &path);
85
        bool checkForErrors(QDBusPendingReply <void> reply) const;
86
        QString cryptPassword(const QString &password) const;
87
        UserSession* m_sessions;
88
89
        QStringList m_userPath;
        OrgFreedesktopAccountsInterface* m_dbus;
90
        QHash<AccountModel::Role, QVariant> m_newUserData;
91
        QHash<QString, OrgFreedesktopAccountsUserInterface*> m_users;
92
        QHash<QString, bool> m_loggedAccounts;
David Edmundson's avatar
David Edmundson committed
93
        KEMailSettings m_kEmailSettings;
94
        AutomaticLoginSettings m_autoLoginSettings;
95
        qreal m_dpr = 1;
96
97
};

98
QDebug operator<<(QDebug debug, AccountModel::Role role);
99
#endif // ACCOUNTMODEL_H