diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..676f4f7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "resources/hass-hue-icons"] + path = resources/hass-hue-icons + url = https://github.com/arallsopp/hass-hue-icons diff --git a/Cargo.toml b/Cargo.toml index 7fefb9e..577fc5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] angular-units = "0.2.4" dirs = "4.0.0" +gio = "0.14.8" gtk = "0.14.3" log = "0.4.14" miette = { version = "3.2.0", features = ["fancy"] } @@ -22,4 +23,6 @@ simplelog = "0.10.2" tokio = { version = "1.12.0", features = ["rt-multi-thread", "macros", "net", "sync", "fs"] } url = { version = "2.2.2", features = ["serde"] } -[features] +[build-dependencies] +gio = "0.14.8" + diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..c807327 --- /dev/null +++ b/build.rs @@ -0,0 +1,7 @@ +fn main() { + gio::compile_resources( + "resources", + "resources/resources.gresource.xml", + "compiled.gresource", + ); +} diff --git a/resources/hass-hue-icons b/resources/hass-hue-icons new file mode 160000 index 0000000..80ded5c --- /dev/null +++ b/resources/hass-hue-icons @@ -0,0 +1 @@ +Subproject commit 80ded5c407137f5f8c4128b959e1384d19cefbff diff --git a/resources/resources.gresource.xml b/resources/resources.gresource.xml new file mode 100644 index 0000000..a70719a --- /dev/null +++ b/resources/resources.gresource.xml @@ -0,0 +1,36 @@ + + + + hass-hue-icons/docs/custom_svgs/centris.svg + hass-hue-icons/docs/custom_svgs/lightstrip-tv.svg + hass-hue-icons/docs/svgs/bloom.svg + hass-hue-icons/docs/svgs/bollard.svg + hass-hue-icons/docs/svgs/bulb-candle.svg + hass-hue-icons/docs/svgs/bulb-classic.svg + hass-hue-icons/docs/svgs/bulb-filament.svg + hass-hue-icons/docs/svgs/bulb-flood.svg + hass-hue-icons/docs/svgs/bulb-spot.svg + hass-hue-icons/docs/svgs/bulb-sultan.svg + hass-hue-icons/docs/svgs/ceiling-round.svg + hass-hue-icons/docs/svgs/ceiling-square.svg + hass-hue-icons/docs/svgs/desk-lamp.svg + hass-hue-icons/docs/svgs/double-spot.svg + hass-hue-icons/docs/svgs/floor-lantern.svg + hass-hue-icons/docs/svgs/floor-shade.svg + hass-hue-icons/docs/svgs/floor-spot.svg + hass-hue-icons/docs/svgs/go.svg + hass-hue-icons/docs/svgs/iris.svg + hass-hue-icons/docs/svgs/lightstrip.svg + hass-hue-icons/docs/svgs/pendant-long.svg + hass-hue-icons/docs/svgs/pendant-round.svg + hass-hue-icons/docs/svgs/play-bar.svg + hass-hue-icons/docs/svgs/recessed-ceiling.svg + hass-hue-icons/docs/svgs/recessed-floor.svg + hass-hue-icons/docs/svgs/single-spot.svg + hass-hue-icons/docs/svgs/table-shade.svg + hass-hue-icons/docs/svgs/table-wash.svg + hass-hue-icons/docs/svgs/wall-lantern.svg + hass-hue-icons/docs/svgs/wall-shade.svg + hass-hue-icons/docs/svgs/wall-spot.svg + + diff --git a/screenshot.png b/screenshot.png index 3dbb1a0..60b947a 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/src/gui/light_entry.rs b/src/gui/light_entry.rs index faeb875..3b927be 100644 --- a/src/gui/light_entry.rs +++ b/src/gui/light_entry.rs @@ -4,7 +4,10 @@ use log::debug; use prisma::{Hsv, Rgb}; use relm::Widget; use relm_derive::{widget, Msg}; -use rhue::{api::Light, bridge::StateUpdate}; +use rhue::{ + api::{Light, LightArchetype}, + bridge::StateUpdate, +}; use std::{cell::Cell, rc::Rc}; use tokio::sync::mpsc::UnboundedSender; @@ -17,6 +20,7 @@ pub struct LightEntryModel { on: bool, brightness: f64, color: Rc>>, + icon: String, } #[derive(Clone, Msg)] @@ -48,6 +52,7 @@ impl Widget for LightEntry { ) .into(), )), + icon: resource_of_archetype(params.1.config.archetype), } } @@ -134,6 +139,10 @@ impl Widget for LightEntry { gtk::Box { orientation: Orientation::Horizontal, + gtk::Image { + from_resource: Some(&self.model.icon), + }, + #[name = "color_indicator"] gtk::DrawingArea { width_request: 25, @@ -170,3 +179,51 @@ impl Widget for LightEntry { } } } + +fn resource_of_archetype(atype: LightArchetype) -> String { + type At = LightArchetype; + // types of directories used in the gresource paths + let s = "svgs"; + let cs = "custom_svgs"; + + let (dir, file) = match atype { + At::Bollard => (s, "bollard"), + At::Candlebulb => (s, "bulb-candle"), + At::Ceilinground => (s, "ceiling-round"), + At::Ceilingsquare => (s, "ceiling-square"), + // wtf? + At::Christmastree => (s, "bulb-classic"), + At::Classicbulb => (s, "bulb-classic"), + At::Doublespot => (s, "double-spot"), + At::Flexiblelamp => (s, "desk-lamp"), + At::Floodbulb => (s, "bulb-flood"), + At::Floorlantern => (s, "floor-lantern"), + At::Floorshade => (s, "floor-shade"), + At::Groundspot => (s, "floor-spot"), + At::Huebloom => (s, "bloom"), + At::Huecentris => (cs, "centris"), + At::Huego => (s, "go"), + At::Hueiris => (s, "iris"), + At::Huelightstrip => (s, "lightstrip"), + At::Huelightstriptv => (cs, "lightstrip-tv"), + At::Hueplay => (s, "play-bar"), + At::Pendantlong => (s, "pendant-long"), + At::Pendantround => (s, "pendant-round"), + At::Recessedceiling => (s, "recessed-ceiling"), + At::Recessedfloor => (s, "recessed-floor"), + At::Singlespot => (s, "single-spot"), + At::Spotbulb => (s, "bulb-spot"), + At::Sultanbulb => (s, "bulb-sultan"), + At::Tableshade => (s, "table-shade"), + At::Tablewash => (s, "table-wash"), + At::Vintagebulb => (s, "bulb-filament"), + At::Walllantern => (s, "wall-lantern"), + At::Wallshade => (s, "wall-shade"), + At::Wallspot => (s, "wall-spot"), + + // default to classic bulb + At::Other => (s, "bulb-classic"), + }; + + format!("/de/mzte/gue/hass-hue-icons/docs/{}/{}.svg", dir, file) +} diff --git a/src/main.rs b/src/main.rs index db542bc..8b35146 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,10 @@ async fn main() -> miette::Result<()> { .into_diagnostic() .wrap_err("Failed to init logger")?; + gio::resources_register_include!("compiled.gresource") + .into_diagnostic() + .wrap_err("Failed to register gresource")?; + let (tx, rx) = tokio::sync::mpsc::unbounded_channel(); let runtime = Runtime::init(rx).await.wrap_err("Failed to init runtime")?;