Skip to content

Commit

Permalink
Added info about Caps Lock in login screen (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
przebor authored Oct 17, 2021
1 parent 3a71639 commit 2f5d707
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
11 changes: 8 additions & 3 deletions po/spot.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: spot\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-10-02 16:37-0400\n"
"POT-Creation-Date: 2021-10-16 13:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -187,13 +187,18 @@ msgstr ""
msgid "Password"
msgstr ""

#. This error is shown when authentication fails.
#. This information is shown when Caps Lock is enabled.
#: src/app/components/login/login.ui:95
msgid "Caps Lock is enabled!"
msgstr ""

#. This error is shown when authentication fails.
#: src/app/components/login/login.ui:126
msgid "Authentication failed!"
msgstr ""

#. Log in button label
#: src/app/components/login/login.ui:110
#: src/app/components/login/login.ui:141
msgid "Log in"
msgstr ""

Expand Down
21 changes: 15 additions & 6 deletions src/app/components/login/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ mod imp {
pub login_button: TemplateChild<gtk::Button>,

#[template_child]
pub error_container: TemplateChild<gtk::Revealer>,
pub caps_lock_info_container: TemplateChild<gtk::Revealer>,

#[template_child]
pub auth_error_container: TemplateChild<gtk::Revealer>,
}

#[glib::object_subclass]
Expand Down Expand Up @@ -84,7 +87,8 @@ impl LoginWindow {
let controller = gtk::EventControllerKey::new();
controller.set_propagation_phase(gtk::PropagationPhase::Capture);
controller.connect_key_pressed(
clone!(@weak self as _self => @default-return gtk::Inhibit(false), move |_, key, _, _| {
clone!(@weak self as _self => @default-return gtk::Inhibit(false), move |_, key, _, modifier| {
_self.show_caps_lock_info((modifier == gdk::ModifierType::LOCK_MASK) ^ (key == gdk::keys::constants::Caps_Lock));
if key == gdk::keys::constants::Return {
_self.submit(&on_submit_clone);
gtk::Inhibit(true)
Expand All @@ -102,9 +106,14 @@ impl LoginWindow {
}));
}

fn show_error(&self, shown: bool) {
fn show_auth_error(&self, shown: bool) {
let widget = imp::LoginWindow::from_instance(self);
widget.auth_error_container.set_reveal_child(shown);
}

fn show_caps_lock_info(&self, shown: bool) {
let widget = imp::LoginWindow::from_instance(self);
widget.error_container.set_reveal_child(shown);
widget.caps_lock_info_container.set_reveal_child(shown);
}

fn submit<SubmitFn>(&self, on_submit: &SubmitFn)
Expand All @@ -113,7 +122,7 @@ impl LoginWindow {
{
let widget = imp::LoginWindow::from_instance(self);

self.show_error(false);
self.show_auth_error(false);

let username_text = widget.username.text();
let password_text = widget.password.text();
Expand Down Expand Up @@ -181,7 +190,7 @@ impl Login {
}

fn reveal_error(&self) {
self.login_window.show_error(true);
self.login_window.show_auth_error(true);
}
}

Expand Down
33 changes: 32 additions & 1 deletion src/app/components/login/login.ui
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,38 @@
</object>
</child>
<child>
<object class="GtkRevealer" id="error_container">
<object class="GtkRevealer" id="caps_lock_info_container">
<property name="vexpand">1</property>
<property name="transition-type">slide-up</property>
<property name="child">
<object class="GtkBox">
<property name="spacing">8</property>
<child>
<object class="GtkImage">
<property name="halign">center</property>
<property name="valign">start</property>
<property name="margin-top">2</property>
<property name="vexpand">1</property>
<property name="icon-name">dialog-information-symbolic</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes" comments="This information is shown when Caps Lock is enabled.">Caps Lock is enabled!</property>
<property name="wrap">1</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<attributes>
<attribute name="weight" value="bold"></attribute>
</attributes>
</object>
</child>
</object>
</property>
</object>
</child>
<child>
<object class="GtkRevealer" id="auth_error_container">
<property name="vexpand">1</property>
<property name="transition-type">slide-up</property>
<property name="child">
Expand Down

0 comments on commit 2f5d707

Please sign in to comment.