Default to name if realName is not available
Currently, the ComboBox that shows the selected user has textRole set
to "realName", meaning it shows the real name of a user (from the
gecos field in /etc/passwd
, which can be set with chfn --full-name
).
However, it's not true that this field is necessarily set.
A user who does not set the real name attribute will have an empty name, displaying nothing. Instead, we should default to showing the username if realName is empty.
Normally I would use the getValue()
function in
SimpleControls/ComboBox.qml
to get the username. However,
the first time getValue()
is called (i.e. before any
user is selected), it throws an index error. Running
sddm-greeter --test-mode --theme /usr/share/sddm/themes/simplicity
:
Main.qml:152:5: QML ComboBox (parent or ancestor of VisualDataGroup): get: index out of range
Main.qml:48:9: QML ComboBox (parent or ancestor of VisualDataGroup): get: index out of range
This index error is particularly strange because
control.delegateModel.items.count
is right, so it should be accessible.
Because of this index error, I had to wrap getValue()
in a try-catch,
and return userModel.lastUser
on an error, which is the string username
of the last user selected. This is a reasonable default because as
stated previously, the error only occurs when a user has not been
selected, in which case the theme defaults to selecting the last user.
In conclusion,
- on initial startup, if the last user has a
non-empty real name,
displayText
is used directly - otherwise,
getValue()
is called, which throws an error, souserModel.lastUser
is used (which should match the last user) - if the user then selects an account with a
non-empty real name,
displayText
is used directly - otherwise,
getValue()
is called, which properly returns the username