[fractal/fractal-next] login: Move brand_to_icon as a method on IdpBrand
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] login: Move brand_to_icon as a method on IdpBrand
- Date: Mon, 28 Mar 2022 20:35:02 +0000 (UTC)
commit ce6da47adcd8a4c5dc11cd1ed65f2a26a4f1630f
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Sat Mar 26 19:02:07 2022 +0100
login: Move brand_to_icon as a method on IdpBrand
src/login/idp_button.rs | 64 ++++++++++++++++++++++++++++++-------------------
1 file changed, 40 insertions(+), 24 deletions(-)
---
diff --git a/src/login/idp_button.rs b/src/login/idp_button.rs
index 0963b3b72..e685f3183 100644
--- a/src/login/idp_button.rs
+++ b/src/login/idp_button.rs
@@ -17,6 +17,34 @@ pub enum IdpBrand {
Google = 4,
Twitter = 5,
}
+
+impl IdpBrand {
+ /// Get the icon name of this brand, according to the current theme.
+ pub fn icon(&self) -> &'static str {
+ let dark = adw::StyleManager::default().is_dark();
+ match self {
+ 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",
+ }
+ }
+}
+
impl Default for IdpBrand {
fn default() -> Self {
IdpBrand::Apple
@@ -38,6 +66,7 @@ impl TryFrom<&IdentityProviderBrand> for IdpBrand {
}
}
}
+
impl From<IdpBrand> for &str {
fn from(val: IdpBrand) -> Self {
let dark = adw::StyleManager::default().is_dark();
@@ -127,6 +156,7 @@ mod imp {
PROPERTIES.as_ref()
}
+
fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
match pspec.name() {
"id" => obj.id().unwrap().to_value(),
@@ -135,6 +165,7 @@ mod imp {
_ => unimplemented!(),
}
}
+
fn set_property(
&self,
obj: &Self::Type,
@@ -168,33 +199,41 @@ mod imp {
impl ButtonImpl for IdpButton {}
}
+
glib::wrapper! {
pub struct IdpButton(ObjectSubclass<imp::IdpButton>)
@extends gtk::Widget, gtk::Button, @implements gtk::Accessible;
}
+
impl IdpButton {
pub fn update_icon(&self) {
- self.set_icon_name(brand_to_icon(self.brand()));
+ self.set_icon_name(self.brand().icon());
}
pub fn set_id(&self, id: String) {
self.imp().id.replace(Some(id));
}
+
pub fn set_homeserver(&self, url: String) {
self.imp().homeserver.replace(Some(url));
}
+
pub fn set_brand(&self, brand: IdpBrand) {
self.imp().brand.replace(brand);
}
+
pub fn id(&self) -> Option<String> {
self.imp().id.borrow().clone()
}
+
pub fn homeserver(&self) -> Option<String> {
self.imp().homeserver.borrow().clone()
}
+
pub fn brand(&self) -> IdpBrand {
self.imp().brand.get()
}
+
pub fn new_from_identity_provider(homeserver: Url, idp: &IdentityProvider) -> Option<Self> {
let gidp: IdpBrand = idp.brand.as_ref()?.try_into().ok()?;
let ret: IdpButton = glib::Object::new(&[
@@ -206,26 +245,3 @@ impl IdpButton {
Some(ret)
}
}
-fn brand_to_icon(brand: IdpBrand) -> &'static str {
- let dark = adw::StyleManager::default().is_dark();
- match brand {
- 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",
- }
-}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]