on xenial help sign in
Let tests pass again
e5a2091Michael Terry
plugins/LightDM/UsersModel.cpp+51−20
@@ -44,41 +44,50 @@ private:
44 QString realName;
44 QString realName;
45 };
45 };
46
46
47− void addCustomRow(const CustomRow &newRow);
47+ int sourceRowCount() const;
48− void removeCustomRow(const QString &rowName);
48+
49 void updateGuestRow();
49 void updateGuestRow();
50 void updateManualRow();
50 void updateManualRow();
51+ void updateCustomRows();
52+
53+ void addCustomRow(const CustomRow &newRow);
54+ void removeCustomRow(const QString &rowName);
51
55
52 QList<CustomRow> m_customRows;
56 QList<CustomRow> m_customRows;
57+ bool m_updatingCustomRows;
53};
58};
54
59
55MangleModel::MangleModel(QObject* parent)
60MangleModel::MangleModel(QObject* parent)
56 : QIdentityProxyModel(parent)
61 : QIdentityProxyModel(parent)
62+ , m_updatingCustomRows(false)
57{
63{
58− if (!Greeter::instance()->hideUsersHint()) {
59− setSourceModel(new QLightDM::UsersModel(this));
64+ setSourceModel(new QLightDM::UsersModel(this));
60− }
61
65
62− updateGuestRow();
66+ updateCustomRows();
63− updateManualRow();
64
67
65− // Would be nice if there were a rowCountChanged signal in the base class
68+ // Would be nice if there were a rowCountChanged signal in the base class.
69+ // We redo all custom rows on any row count change, because (A) some of
70+ // custom rows (manual login) use row count information and (B) when
71+ // testing, we use a modelReset signal as a way to indicate that a custom
72+ // row has been toggled off or on.
66 connect(this, &QIdentityProxyModel::modelReset,
73 connect(this, &QIdentityProxyModel::modelReset,
67− this, &MangleModel::updateManualRow);
74+ this, &MangleModel::updateCustomRows);
68 connect(this, &QIdentityProxyModel::rowsInserted,
75 connect(this, &QIdentityProxyModel::rowsInserted,
69− this, &MangleModel::updateManualRow);
76+ this, &MangleModel::updateCustomRows);
70 connect(this, &QIdentityProxyModel::rowsRemoved,
77 connect(this, &QIdentityProxyModel::rowsRemoved,
71− this, &MangleModel::updateManualRow);
78+ this, &MangleModel::updateCustomRows);
72}
79}
73
80
74QVariant MangleModel::data(const QModelIndex &index, int role) const
81QVariant MangleModel::data(const QModelIndex &index, int role) const
75{
82{
76 QVariant variantData;
83 QVariant variantData;
77
84
85+ if (index.row() >= rowCount())
86+ return QVariant();
87+
78− bool isCustomRow = index.row() >= sourceModel()->rowCount() &&
88+ bool isCustomRow = index.row() >= sourceRowCount();
79− index.row() < rowCount();
80 if (isCustomRow && index.column() == 0) {
89 if (isCustomRow && index.column() == 0) {
81− int customIndex = index.row() - sourceModel()->rowCount();
90+ int customIndex = index.row() - sourceRowCount();
82 if (role == QLightDM::UsersModel::NameRole) {
91 if (role == QLightDM::UsersModel::NameRole) {
83 variantData = m_customRows[customIndex].name;
92 variantData = m_customRows[customIndex].name;
84 } else if (role == QLightDM::UsersModel::RealNameRole) {
93 } else if (role == QLightDM::UsersModel::RealNameRole) {
@@ -120,7 +129,7 @@ void MangleModel::removeCustomRow(const QString &rowName)
120{
129{
121 for (int i = 0; i < m_customRows.size(); i++) {
130 for (int i = 0; i < m_customRows.size(); i++) {
122 if (m_customRows[i].name == rowName) {
131 if (m_customRows[i].name == rowName) {
123− int rowNum = sourceModel()->rowCount() + i;
132+ int rowNum = sourceRowCount() + i;
124 beginRemoveRows(QModelIndex(), rowNum, rowNum);
133 beginRemoveRows(QModelIndex(), rowNum, rowNum);
125 m_customRows.removeAt(i);
134 m_customRows.removeAt(i);
126 endRemoveRows();
135 endRemoveRows();
@@ -131,7 +140,7 @@ void MangleModel::removeCustomRow(const QString &rowName)
131
140
132void MangleModel::updateManualRow()
141void MangleModel::updateManualRow()
133{
142{
134− bool hasAnotherEntry = sourceModel()->rowCount() > 0;
143+ bool hasAnotherEntry = sourceRowCount() > 0;
135 for (int i = 0; !hasAnotherEntry && i < m_customRows.size(); i++) {
144 for (int i = 0; !hasAnotherEntry && i < m_customRows.size(); i++) {
136 if (m_customRows[i].name != QStringLiteral("*other")) {
145 if (m_customRows[i].name != QStringLiteral("*other")) {
137 hasAnotherEntry = true;
146 hasAnotherEntry = true;
@@ -153,16 +162,38 @@ void MangleModel::updateGuestRow()
153 removeCustomRow(QStringLiteral("*guest"));
162 removeCustomRow(QStringLiteral("*guest"));
154}
163}
155
164
165+void MangleModel::updateCustomRows()
166+{
167+ // We update when rowCount changes, but we also insert/remove rows here.
168+ // So guard this function to avoid recursion.
169+ if (m_updatingCustomRows)
170+ return;
171+
172+ m_updatingCustomRows = true;
173+ updateGuestRow();
174+ updateManualRow();
175+ m_updatingCustomRows = false;
176+}
177+
156int MangleModel::rowCount(const QModelIndex &parent) const
178int MangleModel::rowCount(const QModelIndex &parent) const
157{
179{
158− return QIdentityProxyModel::rowCount(parent) +
180+ if (parent.isValid())
159− (parent.isValid() ? 0 : m_customRows.size());
181+ return 0;
182+ else
183+ return sourceRowCount() + m_customRows.size();
184+}
185+
186+int MangleModel::sourceRowCount() const
187+{
188+ return Greeter::instance()->hideUsersHint() ? 0 : sourceModel()->rowCount();
160}
189}
161
190
162QModelIndex MangleModel::index(int row, int column, const QModelIndex &parent) const
191QModelIndex MangleModel::index(int row, int column, const QModelIndex &parent) const
163{
192{
193+ if (row >= rowCount())
194+ return QModelIndex();
195+
164− bool isCustomRow = row >= sourceModel()->rowCount() &&
196+ bool isCustomRow = row >= sourceRowCount();
165− row < rowCount();
166 if (isCustomRow && !parent.isValid()) {
197 if (isCustomRow && !parent.isValid()) {
167 return createIndex(row, column);
198 return createIndex(row, column);
168 } else {
199 } else {
tests/mocks/liblightdm/MockUsersModel.cpp+2
@@ -69,6 +69,8 @@ UsersModel::UsersModel(QObject *parent)
69 this, &UsersModel::resetEntries);
69 this, &UsersModel::resetEntries);
70 connect(MockController::instance(), &MockController::showManualLoginHintChanged,
70 connect(MockController::instance(), &MockController::showManualLoginHintChanged,
71 this, &UsersModel::resetEntries);
71 this, &UsersModel::resetEntries);
72+ connect(MockController::instance(), &MockController::hideUsersHintChanged,
73+ this, &UsersModel::resetEntries);
72 connect(MockController::instance(), &MockController::userModeChanged,
74 connect(MockController::instance(), &MockController::userModeChanged,
73 this, &UsersModel::resetEntries);
75 this, &UsersModel::resetEntries);
74 resetEntries();
76 resetEntries();
tests/qmltests/Greeter/tst_Greeter.qml+2−2
@@ -201,7 +201,7 @@ Item {
201 var i = getIndexOf(name);
201 var i = getIndexOf(name);
202 compare(view.currentIndex, i);
202 compare(view.currentIndex, i);
203 compare(AccountsService.user, name);
203 compare(AccountsService.user, name);
204− if (name === "*guest") // guest has no authenticationUser set
204+ if (name[0] === "*") // custom rows have no authenticationUser set
205 compare(LightDM.Greeter.authenticationUser, "");
205 compare(LightDM.Greeter.authenticationUser, "");
206 else
206 else
207 compare(LightDM.Greeter.authenticationUser, name);
207 compare(LightDM.Greeter.authenticationUser, name);
@@ -612,7 +612,7 @@ Item {
612 verify(!view.locked);
612 verify(!view.locked);
613 }
613 }
614
614
615− function test_hasManualLoginHint() {
615+ function test_showManualLoginHint() {
616 LightDMController.showManualLoginHint = true;
616 LightDMController.showManualLoginHint = true;
617 resetLoader();
617 resetLoader();
618 var i = selectUser("*other");
618 var i = selectUser("*other");