Skip to content

Commit

Permalink
Show banner when no sound cards are found.
Browse files Browse the repository at this point in the history
  • Loading branch information
saivert committed Jul 7, 2024
1 parent 5a87987 commit fcdeb91
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
5 changes: 5 additions & 0 deletions data/resources/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
</object>
</child>

<child type="top">
<object class="AdwBanner" id="info_banner">
</object>
</child>

<property name="content">
<object class="AdwViewStack" id="stack">
<property name="hexpand">true</property>
Expand Down
32 changes: 29 additions & 3 deletions src/ui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*};

Expand Down Expand Up @@ -39,6 +40,8 @@ mod imp {
pub viewstack: TemplateChild<gtk::Stack>,
#[template_child]
pub reconnectbtn: TemplateChild<gtk::Button>,
#[template_child]
pub info_banner: TemplateChild<adw::Banner>,

pub settings: gio::Settings,
}
Expand All @@ -56,6 +59,7 @@ mod imp {
viewstack: TemplateChild::default(),
reconnectbtn: TemplateChild::default(),
settings: gio::Settings::new(APP_ID),
info_banner: TemplateChild::default(),
}
}
}
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit fcdeb91

Please sign in to comment.