on 34be00a help sign in
124 lines 4.5 kB history raw
1/*
2 * Copyright (C) 2014-2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "UsersModelPrivate.h"
18#include "UsersModel.h"
20#include <QDir>
22namespace QLightDM
25UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
26 : mockMode("single")
27 , q_ptr(parent)
29 char *envMockMode = getenv("LIBLIGHTDM_MOCK_MODE");
30 if (envMockMode) {
31 mockMode = envMockMode;
32 }
33 resetEntries();
36void UsersModelPrivate::resetEntries()
38 Q_Q(UsersModel);
40 q->beginResetModel();
42 if (mockMode == "single") {
43 resetEntries_single();
44 } else if (mockMode == "single-passphrase") {
45 resetEntries_singlePassphrase();
46 } else if (mockMode == "single-pin") {
47 resetEntries_singlePin();
48 } else if (mockMode == "full") {
49 resetEntries_full();
50 }
52 // Assign uids in a loop, just to avoid having to muck with them when
53 // adding or removing test users.
54 for (int i = 0; i < entries.size(); i++) {
55 entries[i].uid = i + 1;
56 }
58 // Assign backgrounds
59 QDir backgroundDir("/usr/share/backgrounds");
60 QStringList backgrounds = backgroundDir.entryList(QDir::Files);
61 if (!backgrounds.empty()) {
62 for (int i = 0; i < entries.size(); i++) {
63 if (entries[i].background.isNull()) {
64 entries[i].background = backgroundDir.filePath(backgrounds[i % backgrounds.size()]);
65 }
66 }
67 }
69 q->endResetModel();
72void UsersModelPrivate::resetEntries_single()
74 entries =
75 {
76 { "single", "Single User", 0, 0, false, false, "ubuntu", 0 },
77 };
80void UsersModelPrivate::resetEntries_singlePassphrase()
82 entries =
83 {
84 { "single", "Single User", 0, 0, false, false, "ubuntu", 0 },
85 };
88void UsersModelPrivate::resetEntries_singlePin()
90 entries =
91 {
92 { "has-pin", "Has PIN", 0, 0, false, false, "ubuntu", 0 },
93 };
96void UsersModelPrivate::resetEntries_full()
98 entries =
99 {
100 { "has-password", "Has Password", 0, 0, false, false, "ubuntu", 0 },
101 { "has-pin", "Has PIN", 0, 0, false, false, "ubuntu", 0 },
102 { "different-prompt", "Different Prompt", 0, 0, false, false, "ubuntu", 0 },
103 { "no-password", "No Password", 0, 0, false, false, "ubuntu", 0 },
104 { "auth-error", "Auth Error", 0, 0, false, false, "ubuntu", 0 },
105 { "two-factor", "Two Factor", 0, 0, false, false, "ubuntu", 0 },
106 { "info-prompt", "Info Prompt", 0, 0, false, false, "ubuntu", 0 },
107 { "html-info-prompt", "HTML Info Prompt", 0, 0, false, false, "ubuntu", 0 },
108 { "long-info-prompt", "Long Info Prompt", 0, 0, false, false, "ubuntu", 0 },
109 { "wide-info-prompt", "Wide Info Prompt", 0, 0, false, false, "ubuntu", 0 },
110 { "multi-info-prompt", "Multi Info Prompt", 0, 0, false, false, "ubuntu", 0 },
111 { "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, "ubuntu", 0 },
112 { "color-background", "Color Background", "#E95420", 0, false, false, "ubuntu", 0 },
113 // white and black are a bit redundant, but useful for manually testing if UI is still readable
114 { "white-background", "White Background", "#ffffff", 0, false, false, "ubuntu", 0 },
115 { "black-background", "Black Background", "#000000", 0, false, false, "ubuntu", 0 },
116 { "no-background", "No Background", "", 0, false, false, "ubuntu", 0 },
117 { "unicode", "가나다라마", 0, 0, false, false, "ubuntu", 0 },
118 { "no-response", "No Response", 0, 0, false, false, "ubuntu", 0 },
119 { "empty-name", "", 0, 0, false, false, "ubuntu", 0 },
120 { "active", "Active Account", 0, 0, true, false, "ubuntu", 0 },
121 };
124} // namespace QLightDM