diff --git a/data/resources/ui/window.ui b/data/resources/ui/window.ui index 27a4096..df0df23 100644 --- a/data/resources/ui/window.ui +++ b/data/resources/ui/window.ui @@ -77,6 +77,11 @@ + + + + + true diff --git a/src/ui/window.rs b/src/ui/window.rs index 6a09eda..dc41af1 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -5,9 +5,10 @@ use crate::{ application::PwvucontrolApplication, backend::{PwDeviceObject, PwNodeObject, PwvucontrolManager}, config::{APP_ID, PROFILE}, - ui::{devicebox::PwDeviceBox, PwStreamBox, PwSinkBox, PwVolumeBox}, + ui::{devicebox::PwDeviceBox, PwSinkBox, PwStreamBox, PwVolumeBox}, }; use adw::subclass::prelude::*; +use gettextrs::gettext; use glib::clone; use gtk::{gio, prelude::*}; @@ -39,6 +40,8 @@ mod imp { pub viewstack: TemplateChild, #[template_child] pub reconnectbtn: TemplateChild, + #[template_child] + pub info_banner: TemplateChild, pub settings: gio::Settings, } @@ -56,6 +59,7 @@ mod imp { viewstack: TemplateChild::default(), reconnectbtn: TemplateChild::default(), settings: gio::Settings::new(APP_ID), + info_banner: TemplateChild::default(), } } } @@ -104,6 +108,17 @@ mod imp { window.obj().set_view(PwvucontrolWindowView::Disconnected); })); + manager.node_model().connect_items_changed(clone!(@weak self as widget => move |_,_,_,_| { + widget.obj().update_info_bar(); + })); + manager + .device_model() + .connect_items_changed(clone!(@weak self as widget => move |_,_,_,_| { + widget.obj().update_info_bar(); + })); + + glib::idle_add_local_once(clone!(@weak self as widget => move || {widget.obj().update_info_bar();})); + self.playbacklist.bind_model( Some(&manager.stream_output_model()), clone!(@weak self as window => @default-panic, move |item| { @@ -209,8 +224,6 @@ impl PwvucontrolWindow { fn save_window_size(&self) -> Result<(), glib::BoolError> { let settings = &self.imp().settings; - - let size = self.default_size(); settings.set_int("window-width", size.0)?; @@ -267,6 +280,19 @@ impl PwvucontrolWindow { ); scrolledwindow.add_controller(ecs); } + + fn update_info_bar(&self) { + let manager = PwvucontrolManager::default(); + let imp = self.imp(); + + let message = if manager.device_model().n_items() == 0 { + gettext("No sound cards detected. Check pipewire configuration.") + } else { + gettext("No sound devices detected. Check profiles in Card tab.") + }; + imp.info_banner.set_title(&message); + imp.info_banner.set_revealed(manager.node_model().n_items() == 0); + } } impl Default for PwvucontrolWindow {