@ -13,20 +13,26 @@ mod imp {
use super ::* ;
use super ::* ;
#[ derive(Debug, Default, CompositeTemplate, glib::Properties) ]
#[ derive(Debug, Default, CompositeTemplate, glib::Properties) ]
#[ template(resource = " /org/gnome/Fractal/ui/login/idp_button.ui " ) ]
#[ template(resource = " /org/gnome/Fractal/ui/login/sso_idp_button.ui " ) ]
#[ properties(wrapper_type = super::IdpButton) ]
#[ properties(wrapper_type = super::SsoIdpButton) ]
pub struct IdpButton {
pub struct SsoIdpButton {
/// The identity provider brand of this button.
/// The identity provider of this button.
brand : OnceCell < IdentityProviderBrand > ,
identity_provider : OnceCell < IdentityProvider > ,
/// The identity provider brand of this button, as a string.
/// The ID of the identity provider.
#[ property(get = Self::id) ]
id : PhantomData < String > ,
/// The name of the identity provider.
#[ property(get = Self::name) ]
name : PhantomData < String > ,
/// The brand of the identity provider, as a string.
#[ property(get = Self::brand_string) ]
#[ property(get = Self::brand_string) ]
brand_string : PhantomData < String > ,
brand_string : PhantomData < String > ,
}
}
#[ glib::object_subclass ]
#[ glib::object_subclass ]
impl ObjectSubclass for IdpButton {
impl ObjectSubclass for Sso IdpButton {
const NAME : & ' static str = "IdpButton" ;
const NAME : & ' static str = "Sso IdpButton" ;
type Type = super ::IdpButton ;
type Type = super ::Sso IdpButton;
type ParentType = gtk ::Button ;
type ParentType = gtk ::Button ;
fn class_init ( klass : & mut Self ::Class ) {
fn class_init ( klass : & mut Self ::Class ) {
@ -41,15 +47,15 @@ mod imp {
}
}
#[ glib::derived_properties ]
#[ glib::derived_properties ]
impl ObjectImpl for IdpButton { }
impl ObjectImpl for Sso IdpButton { }
impl WidgetImpl for IdpButton { }
impl WidgetImpl for Sso IdpButton { }
impl ButtonImpl for IdpButton { }
impl ButtonImpl for Sso IdpButton { }
impl IdpButton {
impl Sso IdpButton {
/// Set the identity provider brand of this button.
/// Set the identity provider of this button.
pub ( super ) fn set_brand ( & self , brand : IdentityProviderBrand ) {
pub ( super ) fn set_identity_provider ( & self , identity_provider : IdentityProvider ) {
let brand = self . brand . get_or_init ( | | brand ) ;
let identity_provider = self . identity_provider . get_or_init ( | | identity_provider ) ;
adw ::StyleManager ::default ( ) . connect_dark_notify ( clone ! (
adw ::StyleManager ::default ( ) . connect_dark_notify ( clone ! (
#[ weak(rename_to = imp) ]
#[ weak(rename_to = imp) ]
@ -58,29 +64,49 @@ mod imp {
) ) ;
) ) ;
self . update_icon ( ) ;
self . update_icon ( ) ;
let obj = self . obj ( ) ;
self . obj ( )
obj . set_action_target_value ( Some ( & Some ( & brand . as_str ( ) ) . to_variant ( ) ) ) ;
. set_action_target_value ( Some ( & Some ( & identity_provider . id ) . to_variant ( ) ) ) ;
obj . set_tooltip_text ( Some ( & gettext_f (
self . obj ( ) . set_tooltip_text ( Some ( & gettext_f (
// Translators: Do NOT translate the content between '{' and '}', this is a
// Translators: Do NOT translate the content between '{' and '}', this is a
// variable name.
// variable name.
// This is the tooltip text on buttons to log in via Single Sign-On.
// This is the tooltip text on buttons to log in via Single Sign-On.
// The brand is something like Facebook, Apple, GitHub…
// The brand is something like Facebook, Apple, GitHub…
"Log in with {brand}" ,
"Log in with {brand}" ,
& [ ( "brand" , brand . as_str ( ) ) ] ,
& [ ( "brand" , & identity_provider . name ) ] ,
) ) ) ;
) ) ) ;
}
}
/// The identity provider brand of this button.
/// The identity provider of this button.
fn identity_provider ( & self ) -> & IdentityProvider {
self . identity_provider
. get ( )
. expect ( "identity provider is initialized" )
}
/// The ID of the identity provider.
fn id ( & self ) -> String {
self . identity_provider ( ) . id . clone ( )
}
/// The name of the identity provider.
fn name ( & self ) -> String {
self . identity_provider ( ) . name . clone ( )
}
/// The brand of the identity provider.
fn brand ( & self ) -> & IdentityProviderBrand {
fn brand ( & self ) -> & IdentityProviderBrand {
self . brand . get ( ) . expect ( "brand is initialized" )
self . identity_provider ( )
. brand
. as_ref ( )
. expect ( "identity provider has a brand" )
}
}
/// The identity provider brand of this button, as a string.
/// The brand of the identity provider, as a string.
fn brand_string ( & self ) -> String {
fn brand_string ( & self ) -> String {
self . brand ( ) . to_string ( )
self . brand ( ) . to_string ( )
}
}
/// The icon name of the current brand, according to the current theme.
/// The icon name of the brand, according to the current theme.
fn brand_icon ( & self ) -> & str {
fn brand_icon ( & self ) -> & str {
let is_dark = adw ::StyleManager ::default ( ) . is_dark ( ) ;
let is_dark = adw ::StyleManager ::default ( ) . is_dark ( ) ;
@ -123,13 +149,13 @@ mod imp {
glib ::wrapper ! {
glib ::wrapper ! {
/// A button to represent an SSO identity provider.
/// A button to represent an SSO identity provider.
pub struct IdpButton ( ObjectSubclass < imp ::IdpButton > )
pub struct Sso IdpButton( ObjectSubclass < imp ::Sso IdpButton> )
@ extends gtk ::Widget , gtk ::Button ,
@ extends gtk ::Widget , gtk ::Button ,
@ implements gtk ::Accessible , gtk ::Actionable ;
@ implements gtk ::Accessible , gtk ::Actionable ;
}
}
impl IdpButton {
impl Sso IdpButton {
/// The supported SSO identity provider brands of `IdpButton`.
/// The supported SSO identity provider brands of `Sso IdpButton`.
const SUPPORTED_IDP_BRANDS : & [ IdentityProviderBrand ] = & [
const SUPPORTED_IDP_BRANDS : & [ IdentityProviderBrand ] = & [
IdentityProviderBrand ::Apple ,
IdentityProviderBrand ::Apple ,
IdentityProviderBrand ::Facebook ,
IdentityProviderBrand ::Facebook ,
@ -139,18 +165,18 @@ impl IdpButton {
IdentityProviderBrand ::Twitter ,
IdentityProviderBrand ::Twitter ,
] ;
] ;
/// Create a new `IdpButton` with the given identity provider.
/// Create a new `Sso IdpButton` with the given identity provider.
///
///
/// Returns `None` if the identity provider's brand is not supported.
/// Returns `None` if the identity provider's brand is not supported.
pub fn new ( idp : & IdentityProvider ) -> Option < Self > {
pub fn new ( identity_ provider : IdentityProvider ) -> Option < Self > {
// If this is not a supported brand, return `None`.
// If this is not a supported brand, return `None`.
let brand = idp . brand . as_ref ( ) ? ;
let brand = identity_ provider . brand . as_ref ( ) ? ;
if ! Self ::SUPPORTED_IDP_BRANDS . contains ( brand ) {
if ! Self ::SUPPORTED_IDP_BRANDS . contains ( brand ) {
return None ;
return None ;
}
}
let obj = glib ::Object ::new ::< Self > ( ) ;
let obj = glib ::Object ::new ::< Self > ( ) ;
obj . imp ( ) . set_brand ( brand . clone ( ) ) ;
obj . imp ( ) . set_identity_provider ( identity_provider ) ;
Some ( obj )
Some ( obj )
}
}