login: Add tooltip on SSO providers buttons

This commit is contained in:
Kévin Commaille 2023-12-21 11:22:43 +01:00
parent e0de9d1eea
commit 0f13d447d9
No known key found for this signature in database
GPG key ID: 29A48C1F03620416
2 changed files with 13 additions and 27 deletions

View file

@ -21,6 +21,7 @@ src/greeter.ui
src/login/advanced_dialog.ui src/login/advanced_dialog.ui
src/login/homeserver_page.rs src/login/homeserver_page.rs
src/login/homeserver_page.ui src/login/homeserver_page.ui
src/login/idp_button.rs
src/login/method_page.rs src/login/method_page.rs
src/login/method_page.ui src/login/method_page.ui
src/login/mod.rs src/login/mod.rs

View file

@ -3,7 +3,9 @@ use matrix_sdk::ruma::api::client::session::get_login_types::v3::{
IdentityProvider, IdentityProviderBrand, IdentityProvider, IdentityProviderBrand,
}; };
#[derive(Debug, Default, Hash, Eq, PartialEq, Clone, Copy, glib::Enum)] use crate::gettext_f;
#[derive(Debug, Default, Hash, Eq, PartialEq, Clone, Copy, glib::Enum, strum::Display)]
#[repr(i32)] #[repr(i32)]
#[enum_type(name = "IdpBrand")] #[enum_type(name = "IdpBrand")]
pub enum IdpBrand { pub enum IdpBrand {
@ -59,32 +61,6 @@ impl TryFrom<&IdentityProviderBrand> for IdpBrand {
} }
} }
impl From<IdpBrand> for &str {
fn from(val: IdpBrand) -> Self {
let dark = adw::StyleManager::default().is_dark();
match val {
IdpBrand::Apple => {
if dark {
"idp-apple-dark"
} else {
"idp-apple"
}
}
IdpBrand::Facebook => "idp-facebook",
IdpBrand::GitHub => {
if dark {
"idp-github-dark"
} else {
"idp-github"
}
}
IdpBrand::GitLab => "idp-gitlab",
IdpBrand::Google => "idp-google",
IdpBrand::Twitter => "idp-twitter",
}
}
}
mod imp { mod imp {
use std::cell::{Cell, OnceCell}; use std::cell::{Cell, OnceCell};
@ -129,6 +105,15 @@ mod imp {
adw::StyleManager::default() adw::StyleManager::default()
.connect_dark_notify(clone!(@weak obj => move |_| obj.update_icon())); .connect_dark_notify(clone!(@weak obj => move |_| obj.update_icon()));
obj.update_icon(); obj.update_icon();
obj.set_tooltip_text(Some(&gettext_f(
// Translators: Do NOT translate the content between '{' and '}', this is a
// variable name.
// This is the tooltip text on buttons to log in via Single Sign-On.
// The brand is something like Facebook, Apple, GitHub…
"Log in with {brand}",
&[("brand", &self.brand.get().to_string())],
)))
} }
} }