mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-01 15:57:46 +02:00
Add factory for dropdowns
Replace ListEntry with libadwaita components
This commit is contained in:
parent
ba48f5ba33
commit
babc0e8cc4
10 changed files with 182 additions and 307 deletions
|
@ -2,44 +2,48 @@ use std::time::Duration;
|
|||
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{ComboRowExt, PreferencesRowExt};
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::Error;
|
||||
use glib::{Cast, clone};
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use glib::{clone, Cast};
|
||||
use gtk::{gio, StringObject};
|
||||
use gtk::{Align, gio, SignalListItemFactory, StringList, StringObject};
|
||||
use gtk::prelude::{GObjectPropertyExpressionExt, ListItemExt, WidgetExt};
|
||||
use ReSet_Lib::audio::audio::Card;
|
||||
|
||||
use super::cardEntryImpl;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct CardEntry(ObjectSubclass<cardEntryImpl::CardEntry>)
|
||||
@extends gtk::Box, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
|
||||
@extends adw::ComboRow, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable, adw::PreferencesRow;
|
||||
}
|
||||
|
||||
impl CardEntry {
|
||||
pub fn new(card: Card) -> Self {
|
||||
let entry: Self = Object::builder().build();
|
||||
let entry: CardEntry = Object::builder().build();
|
||||
{
|
||||
let imp = entry.imp();
|
||||
let mut map = imp.resetCardMap.borrow_mut();
|
||||
imp.resetCardName.set_text(&card.name);
|
||||
entry.set_title(&card.name);
|
||||
let mut i: u32 = 0;
|
||||
let mut index: u32 = 0;
|
||||
let list = StringList::new(&[]);
|
||||
for profile in card.profiles.iter() {
|
||||
if profile.name == card.active_profile {
|
||||
index = i;
|
||||
}
|
||||
imp.resetCardList.append(&profile.description);
|
||||
list.append(&profile.description);
|
||||
map.insert(
|
||||
profile.description.clone(),
|
||||
(card.index, profile.name.clone()),
|
||||
);
|
||||
i += 1;
|
||||
}
|
||||
imp.resetCardDropdown.set_selected(index);
|
||||
imp.resetCardDropdown
|
||||
.connect_selected_notify(clone!(@weak imp => move |dropdown| {
|
||||
entry.set_model(Some(&list));
|
||||
entry.set_selected(index);
|
||||
entry.set_use_subtitle(true);
|
||||
entry.connect_selected_notify(clone!(@weak imp => move |dropdown| {
|
||||
let selected = dropdown.selected_item();
|
||||
if selected.is_none() {
|
||||
return;
|
||||
|
@ -51,6 +55,19 @@ impl CardEntry {
|
|||
let (device_index, profile_name) = map.get(&selected).unwrap();
|
||||
set_card_profile_of_device(*device_index, profile_name.clone());
|
||||
}));
|
||||
|
||||
let factory = &SignalListItemFactory::new();
|
||||
factory.connect_setup(|_, item| {
|
||||
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
|
||||
let label = gtk::Label::new(None);
|
||||
label.set_halign(Align::Start);
|
||||
item.property_expression("item")
|
||||
.chain_property::<StringObject>("string")
|
||||
.bind(&label, "label", gtk::Widget::NONE);
|
||||
item.set_child(Some(&label));
|
||||
});
|
||||
entry.set_factory(Some(factory));
|
||||
|
||||
}
|
||||
entry
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use adw::ComboRow;
|
||||
use adw::subclass::action_row::ActionRowImpl;
|
||||
use adw::subclass::preferences_row::PreferencesRowImpl;
|
||||
use adw::subclass::prelude::ComboRowImpl;
|
||||
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, CompositeTemplate, DropDown, Label, StringList, TemplateChild};
|
||||
use gtk::{glib, CompositeTemplate};
|
||||
|
||||
use super::cardEntry;
|
||||
|
||||
|
@ -10,12 +14,6 @@ use super::cardEntry;
|
|||
#[derive(Default, CompositeTemplate)]
|
||||
#[template(resource = "/org/Xetibo/ReSet/resetCardEntry.ui")]
|
||||
pub struct CardEntry {
|
||||
#[template_child]
|
||||
pub resetCardName: TemplateChild<Label>,
|
||||
#[template_child]
|
||||
pub resetCardDropdown: TemplateChild<DropDown>,
|
||||
#[template_child]
|
||||
pub resetCardList: TemplateChild<StringList>,
|
||||
// first string is the alias name, the first return string is the index of the adapter and the
|
||||
// second the name of the profile
|
||||
pub resetCardMap: RefCell<HashMap<String, (u32, String)>>,
|
||||
|
@ -25,7 +23,7 @@ pub struct CardEntry {
|
|||
impl ObjectSubclass for CardEntry {
|
||||
const NAME: &'static str = "resetCardEntry";
|
||||
type Type = cardEntry::CardEntry;
|
||||
type ParentType = gtk::Box;
|
||||
type ParentType = ComboRow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
|
@ -36,7 +34,11 @@ impl ObjectSubclass for CardEntry {
|
|||
}
|
||||
}
|
||||
|
||||
impl BoxImpl for CardEntry {}
|
||||
impl ActionRowImpl for CardEntry {}
|
||||
|
||||
impl PreferencesRowImpl for CardEntry {}
|
||||
|
||||
impl ComboRowImpl for CardEntry {}
|
||||
|
||||
impl ObjectImpl for CardEntry {
|
||||
fn constructed(&self) {}
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{BoxExt, ButtonExt, CheckButtonExt, ComboRowExt, ListBoxRowExt, PreferencesGroupExt, RangeExt};
|
||||
use dbus::{Error, Path};
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::message::SignalArgs;
|
||||
use glib::{Cast, clone, Propagation, Variant};
|
||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||
use gtk::{Align, gio, SignalListItemFactory, StringObject};
|
||||
use gtk::prelude::{ActionableExt, GObjectPropertyExpressionExt, WidgetExt, ListItemExt};
|
||||
use ReSet_Lib::audio::audio::{Card, OutputStream, Source};
|
||||
|
||||
use crate::components::base::cardEntry::CardEntry;
|
||||
use crate::components::base::listEntry::ListEntry;
|
||||
use crate::components::base::utils::{
|
||||
|
@ -9,17 +21,6 @@ use crate::components::base::utils::{
|
|||
};
|
||||
use crate::components::input::sourceBoxImpl;
|
||||
use crate::components::input::sourceEntry::set_source_volume;
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt};
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::message::SignalArgs;
|
||||
use dbus::{Error, Path};
|
||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||
use glib::{clone, Cast, Propagation, Variant};
|
||||
use gtk::prelude::ActionableExt;
|
||||
use gtk::{gio, StringObject};
|
||||
use ReSet_Lib::audio::audio::{Card, OutputStream, Source};
|
||||
|
||||
use super::outputStreamEntry::OutputStreamEntry;
|
||||
use super::sourceEntry::{set_default_source, toggle_source_mute, SourceEntry};
|
||||
|
@ -40,12 +41,14 @@ impl SourceBox {
|
|||
|
||||
pub fn setupCallbacks(&self) {
|
||||
let selfImp = self.imp();
|
||||
selfImp.resetSourceRow.set_activatable(true);
|
||||
selfImp
|
||||
.resetSourceRow
|
||||
.set_action_name(Some("navigation.push"));
|
||||
selfImp
|
||||
.resetSourceRow
|
||||
.set_action_target_value(Some(&Variant::from("sources")));
|
||||
selfImp.resetCardsRow.set_activatable(true);
|
||||
selfImp
|
||||
.resetCardsRow
|
||||
.set_action_name(Some("navigation.push"));
|
||||
|
@ -58,6 +61,19 @@ impl SourceBox {
|
|||
selfImp
|
||||
.resetInputCardsBackButton
|
||||
.set_action_name(Some("navigation.pop"));
|
||||
|
||||
let factory = &SignalListItemFactory::new();
|
||||
factory.connect_setup(|_, item| {
|
||||
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
|
||||
let label = gtk::Label::new(None);
|
||||
label.set_halign(Align::Start);
|
||||
item.property_expression("item")
|
||||
.chain_property::<StringObject>("string")
|
||||
.bind(&label, "label", gtk::Widget::NONE);
|
||||
item.set_child(Some(&label));
|
||||
});
|
||||
|
||||
selfImp.resetSourceDropdown.set_factory(Some(factory));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,7 +246,7 @@ pub fn populate_cards(input_box: Arc<SourceBox>) {
|
|||
let imp = output_box_ref.imp();
|
||||
for card in cards {
|
||||
imp.resetCards
|
||||
.append(&ListEntry::new(&CardEntry::new(card)));
|
||||
.add(&CardEntry::new(card));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ use std::cell::RefCell;
|
|||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::time::SystemTime;
|
||||
use adw::{ActionRow, ComboRow, PreferencesGroup};
|
||||
|
||||
use crate::components::base::listEntry::ListEntry;
|
||||
use crate::components::input::sourceBox;
|
||||
|
@ -18,11 +19,11 @@ use super::sourceEntry::SourceEntry;
|
|||
#[template(resource = "/org/Xetibo/ReSet/resetAudioInput.ui")]
|
||||
pub struct SourceBox {
|
||||
#[template_child]
|
||||
pub resetSourceRow: TemplateChild<ListEntry>,
|
||||
pub resetSourceRow: TemplateChild<ActionRow>,
|
||||
#[template_child]
|
||||
pub resetCardsRow: TemplateChild<ListEntry>,
|
||||
pub resetCardsRow: TemplateChild<ActionRow>,
|
||||
#[template_child]
|
||||
pub resetSourceDropdown: TemplateChild<DropDown>,
|
||||
pub resetSourceDropdown: TemplateChild<ComboRow>,
|
||||
#[template_child]
|
||||
pub resetSourceMute: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
|
@ -40,7 +41,7 @@ pub struct SourceBox {
|
|||
#[template_child]
|
||||
pub resetInputCardsBackButton: TemplateChild<ListEntry>,
|
||||
#[template_child]
|
||||
pub resetCards: TemplateChild<gtk::Box>,
|
||||
pub resetCards: TemplateChild<PreferencesGroup>,
|
||||
pub resetDefaultCheckButton: Arc<CheckButton>,
|
||||
pub resetDefaultSource: Arc<RefCell<Source>>,
|
||||
pub resetSourceList: Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<SourceEntry>, String)>>>,
|
||||
|
|
|
@ -1,27 +1,30 @@
|
|||
use adw::prelude::PreferencesGroupExt;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use adw::{glib, prelude::ListBoxRowExt};
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{BoxExt, ButtonExt, CheckButtonExt, ComboRowExt, RangeExt};
|
||||
use dbus::{Error, Path};
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::message::SignalArgs;
|
||||
use glib::{Cast, clone, Propagation, Variant};
|
||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||
use gtk::{Align, gio, SignalListItemFactory, StringObject};
|
||||
use gtk::prelude::*;
|
||||
use gtk::prelude::{ActionableExt, GObjectPropertyExpressionExt, ListItemExt};
|
||||
use ReSet_Lib::audio::audio::{Card, InputStream, Sink};
|
||||
|
||||
use crate::components::base::cardEntry::CardEntry;
|
||||
use crate::components::base::listEntry::ListEntry;
|
||||
use crate::components::base::utils::{
|
||||
InputStreamAdded, InputStreamChanged, InputStreamRemoved, SinkAdded, SinkChanged, SinkRemoved,
|
||||
};
|
||||
use crate::components::output::sinkEntry::set_sink_volume;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::{BoxExt, ButtonExt, CheckButtonExt, RangeExt};
|
||||
use adw::{glib, prelude::ListBoxRowExt};
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::message::SignalArgs;
|
||||
use dbus::{Error, Path};
|
||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||
use glib::{clone, Cast, Propagation, Variant};
|
||||
use gtk::prelude::ActionableExt;
|
||||
use gtk::{gio, StringObject};
|
||||
use ReSet_Lib::audio::audio::{Card, InputStream, Sink};
|
||||
|
||||
use super::inputStreamEntry::InputStreamEntry;
|
||||
use super::sinkBoxImpl;
|
||||
use super::sinkEntry::{set_default_sink, toggle_sink_mute, SinkEntry};
|
||||
use super::sinkEntry::{set_default_sink, SinkEntry, toggle_sink_mute};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct SinkBox(ObjectSubclass<sinkBoxImpl::SinkBox>)
|
||||
|
@ -45,12 +48,14 @@ impl SinkBox {
|
|||
|
||||
pub fn setupCallbacks(&self) {
|
||||
let selfImp = self.imp();
|
||||
selfImp.resetSinksRow.set_activatable(true);
|
||||
selfImp
|
||||
.resetSinksRow
|
||||
.set_action_name(Some("navigation.push"));
|
||||
selfImp
|
||||
.resetSinksRow
|
||||
.set_action_target_value(Some(&Variant::from("outputDevices")));
|
||||
selfImp.resetCardsRow.set_activatable(true);
|
||||
selfImp
|
||||
.resetCardsRow
|
||||
.set_action_name(Some("navigation.push"));
|
||||
|
@ -65,6 +70,19 @@ impl SinkBox {
|
|||
selfImp
|
||||
.resetInputCardsBackButton
|
||||
.set_action_name(Some("navigation.pop"));
|
||||
|
||||
let factory = &SignalListItemFactory::new();
|
||||
factory.connect_setup(|_, item| {
|
||||
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
|
||||
let label = gtk::Label::new(None);
|
||||
label.set_halign(Align::Start);
|
||||
item.property_expression("item")
|
||||
.chain_property::<StringObject>("string")
|
||||
.bind(&label, "label", gtk::Widget::NONE);
|
||||
item.set_child(Some(&label));
|
||||
});
|
||||
|
||||
selfImp.resetSinkDropdown.set_factory(Some(factory));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -236,7 +254,7 @@ pub fn populate_cards(output_box: Arc<SinkBox>) {
|
|||
let imp = output_box_ref.imp();
|
||||
for card in cards {
|
||||
imp.resetCards
|
||||
.append(&ListEntry::new(&CardEntry::new(card)));
|
||||
.add(&CardEntry::new(card));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ use std::cell::RefCell;
|
|||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::time::SystemTime;
|
||||
use adw::{ActionRow, ComboRow, PreferencesGroup};
|
||||
|
||||
use crate::components::base::listEntry::ListEntry;
|
||||
use crate::components::output::inputStreamEntry::InputStreamEntry;
|
||||
|
@ -20,11 +21,11 @@ use super::sinkEntry::SinkEntry;
|
|||
#[template(resource = "/org/Xetibo/ReSet/resetAudioOutput.ui")]
|
||||
pub struct SinkBox {
|
||||
#[template_child]
|
||||
pub resetSinksRow: TemplateChild<ListEntry>,
|
||||
pub resetSinksRow: TemplateChild<ActionRow>,
|
||||
#[template_child]
|
||||
pub resetCardsRow: TemplateChild<ListEntry>,
|
||||
pub resetCardsRow: TemplateChild<ActionRow>,
|
||||
#[template_child]
|
||||
pub resetSinkDropdown: TemplateChild<DropDown>,
|
||||
pub resetSinkDropdown: TemplateChild<ComboRow>,
|
||||
#[template_child]
|
||||
pub resetSinkMute: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
|
@ -42,7 +43,7 @@ pub struct SinkBox {
|
|||
#[template_child]
|
||||
pub resetInputCardsBackButton: TemplateChild<ListEntry>,
|
||||
#[template_child]
|
||||
pub resetCards: TemplateChild<Box>,
|
||||
pub resetCards: TemplateChild<PreferencesGroup>,
|
||||
pub resetDefaultCheckButton: Arc<CheckButton>,
|
||||
pub resetDefaultSink: Arc<RefCell<Sink>>,
|
||||
pub resetSinkList: Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<SinkEntry>, String)>>>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue