File: UsersModelPrivate.cpp

package info (click to toggle)
lomiri 0.5.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 24,088 kB
  • sloc: cpp: 39,498; python: 2,559; javascript: 1,426; ansic: 1,012; sh: 289; xml: 252; makefile: 69
file content (135 lines) | stat: -rw-r--r-- 4,863 bytes parent folder | download | duplicates (4)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright (C) 2014-2016 Canonical Ltd.
 *
 * 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; version 3.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include "UsersModelPrivate.h"
#include "UsersModel.h"

#include <QDir>

namespace QLightDM
{

UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
  : mockMode("single")
  , q_ptr(parent)
{
    char *envMockMode = getenv("LIBLIGHTDM_MOCK_MODE");
    if (envMockMode) {
        mockMode = envMockMode;
    }
    resetEntries();
}

void UsersModelPrivate::resetEntries()
{
    Q_Q(UsersModel);

    q->beginResetModel();

    if (mockMode == "single") {
        resetEntries_single();
    } else if (mockMode == "single-passphrase") {
        resetEntries_singlePassphrase();
    } else if (mockMode == "single-pin") {
        resetEntries_singlePin();
    }  else if (mockMode == "single-pin-clock") {
        resetEntries_singlePinClock();
    } else if (mockMode == "full") {
        resetEntries_full();
    }

    // Assign uids in a loop, just to avoid having to muck with them when
    // adding or removing test users.
    for (int i = 0; i < entries.size(); i++) {
        entries[i].uid = i + 1;
    }

    // Assign backgrounds
    QDir backgroundDir("/usr/share/backgrounds");
    QStringList backgrounds = backgroundDir.entryList(QDir::Files);
    if (!backgrounds.empty()) {
        for (int i = 0; i < entries.size(); i++) {
            if (entries[i].background.isNull()) {
                entries[i].background = backgroundDir.filePath(backgrounds[i % backgrounds.size()]);
            }
        }
    }

    q->endResetModel();
}

void UsersModelPrivate::resetEntries_single()
{
    entries =
    {
        { "single", "Single User", 0, 0, false, false, "lomiri", 0, 0 },
    };
}

void UsersModelPrivate::resetEntries_singlePassphrase()
{
    entries =
    {
        { "single", "Single User", 0, 0, false, false, "lomiri", 0, 0 },
    };
}

void UsersModelPrivate::resetEntries_singlePin()
{
    entries =
    {
        { "has-pin", "Has PIN", 0, 0, false, false, "lomiri", 0, 0 },
    };
}

void UsersModelPrivate::resetEntries_singlePinClock()
{
    entries =
    {
        { "has-pin-clock", "Has PIN Clock", 0, 0, false, false, "ubuntu", 0, 0 },
    };
}

void UsersModelPrivate::resetEntries_full()
{
    entries =
    {
        { "has-password",      "Has Password", 0, 0, false, false, "lomiri", 0, 0 },
        { "has-pin",           "Has PIN",      0, 0, false, false, "lomiri", 0, 0 },
        { "has-pin-clock",     "Has PIN Clock", 0, 0, false, false, "ubuntu", 0, 0 },
        { "different-prompt",  "Different Prompt", 0, 0, false, false, "lomiri", 0, 0 },
        { "no-password",       "No Password", 0, 0, false, false, "lomiri", 0, 0 },
        { "auth-error",        "Auth Error", 0, 0, false, false, "lomiri", 0, 0 },
        { "two-factor",        "Two Factor", 0, 0, false, false, "lomiri", 0, 0 },
        { "info-prompt",       "Info Prompt", 0, 0, false, false, "lomiri", 0, 0 },
        { "html-info-prompt",  "HTML Info Prompt", 0, 0, false, false, "lomiri", 0, 0 },
        { "long-info-prompt",  "Long Info Prompt", 0, 0, false, false, "lomiri", 0, 0 },
        { "wide-info-prompt",  "Wide Info Prompt", 0, 0, false, false, "lomiri", 0, 0 },
        { "multi-info-prompt", "Multi Info Prompt", 0, 0, false, false, "lomiri", 0, 0 },
        { "long-name",         "Long name (far far too long to fit, seriously this would never fit on the screen, you will never see this part of the name)", 0, 0, false, false, "lomiri", 0, 0 },
        { "color-background",  "Color Background", "#E95420", 0, false, false, "lomiri", 0, 0 },
        // white and black are a bit redundant, but useful for manually testing if UI is still readable
        { "white-background",  "White Background", "#ffffff", 0, false, false, "lomiri", 0, 0 },
        { "black-background",  "Black Background", "#000000", 0, false, false, "lomiri", 0, 0 },
        { "no-background",     "No Background", "", 0, false, false, "lomiri", 0, 0 },
        { "unicode",           "가나다라마", 0, 0, false, false, "lomiri", 0, 0 },
        { "no-response",       "No Response", 0, 0, false, false, "lomiri", 0, 0 },
        { "empty-name",        "", 0, 0, false, false, "lomiri", 0, 0 },
        { "active",            "Active Account", 0, 0, true, false, "lomiri", 0, 0 },
    };
}

} // namespace QLightDM