mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-08 22:52:01 +02:00
extract signallistitemfactory to utils
This commit is contained in:
parent
d3afe5675e
commit
00ffb7faf9
|
@ -5,12 +5,15 @@ use adw::glib::Object;
|
|||
use adw::prelude::{ComboRowExt, PreferencesRowExt};
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::Error;
|
||||
use glib::{Cast, clone, ObjectExt};
|
||||
use glib::{Cast, clone};
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use gtk::{Align, gio, SignalListItemFactory, StringList, StringObject};
|
||||
use gtk::prelude::{GObjectPropertyExpressionExt, ListItemExt, WidgetExt};
|
||||
use gtk::{gio, StringList, StringObject};
|
||||
use ReSet_Lib::audio::audio::Card;
|
||||
|
||||
use components::utils::createDropdownLabelFactory;
|
||||
|
||||
use crate::components;
|
||||
|
||||
use super::cardEntryImpl;
|
||||
|
||||
glib::wrapper! {
|
||||
|
@ -55,18 +58,7 @@ 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.set_factory(Some(&createDropdownLabelFactory()));
|
||||
}
|
||||
entry
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use glib::subclass::types::ObjectSubclassIsExt;
|
|||
use glib::{clone, Cast, Propagation};
|
||||
use gtk::{gio, StringObject};
|
||||
use ReSet_Lib::audio::audio::OutputStream;
|
||||
use crate::components::utils::createDropdownLabelFactory;
|
||||
|
||||
use super::outputStreamEntryImpl;
|
||||
use super::sourceBox::SourceBox;
|
||||
|
@ -32,6 +33,7 @@ impl OutputStreamEntry {
|
|||
let imp = obj.imp();
|
||||
let name = stream.application_name.clone() + ": " + stream.name.as_str();
|
||||
imp.resetSourceSelection.set_title(name.as_str());
|
||||
imp.resetSourceSelection.set_factory(Some(&createDropdownLabelFactory()));
|
||||
let volume = stream.volume.first().unwrap_or(&0_u32);
|
||||
let fraction = (*volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
|
|
|
@ -10,8 +10,8 @@ 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, ListItemExt, WidgetExt};
|
||||
use gtk::{gio, StringObject};
|
||||
use gtk::prelude::{ActionableExt};
|
||||
use ReSet_Lib::audio::audio::{Card, OutputStream, Source};
|
||||
|
||||
use crate::components::base::cardEntry::CardEntry;
|
||||
|
@ -22,6 +22,7 @@ use crate::components::base::utils::{
|
|||
};
|
||||
use crate::components::input::sourceBoxImpl;
|
||||
use crate::components::input::sourceEntry::set_source_volume;
|
||||
use crate::components::utils::createDropdownLabelFactory;
|
||||
|
||||
use super::outputStreamEntry::OutputStreamEntry;
|
||||
use super::sourceEntry::{set_default_source, SourceEntry, toggle_source_mute};
|
||||
|
@ -63,18 +64,7 @@ impl SourceBox {
|
|||
selfImp.resetInputCardsBackButton.set_activatable(true);
|
||||
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));
|
||||
selfImp.resetSourceDropdown.set_factory(Some(&createDropdownLabelFactory()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,4 +4,5 @@ mod input;
|
|||
pub mod output;
|
||||
pub mod wifi;
|
||||
pub mod window;
|
||||
pub mod utils;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use glib::subclass::types::ObjectSubclassIsExt;
|
|||
use glib::{clone, Cast, Propagation};
|
||||
use gtk::{gio, StringObject};
|
||||
use ReSet_Lib::audio::audio::InputStream;
|
||||
use crate::components::utils::createDropdownLabelFactory;
|
||||
|
||||
use super::inputStreamEntryImpl;
|
||||
use super::sinkBox::SinkBox;
|
||||
|
@ -37,6 +38,7 @@ impl InputStreamEntry {
|
|||
}
|
||||
let name = stream.application_name.clone() + ": " + stream.name.as_str();
|
||||
imp.resetSinkSelection.set_title(name.as_str());
|
||||
imp.resetSinkSelection.set_factory(Some(&createDropdownLabelFactory()));
|
||||
let volume = stream.volume.first().unwrap_or(&0_u32);
|
||||
let fraction = (*volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
|
|
|
@ -11,9 +11,8 @@ 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 gtk::{gio, StringObject};
|
||||
use gtk::prelude::ActionableExt;
|
||||
use ReSet_Lib::audio::audio::{Card, InputStream, Sink};
|
||||
|
||||
use crate::components::base::cardEntry::CardEntry;
|
||||
|
@ -22,6 +21,7 @@ use crate::components::base::utils::{
|
|||
InputStreamAdded, InputStreamChanged, InputStreamRemoved, SinkAdded, SinkChanged, SinkRemoved,
|
||||
};
|
||||
use crate::components::output::sinkEntry::set_sink_volume;
|
||||
use crate::components::utils::createDropdownLabelFactory;
|
||||
|
||||
use super::inputStreamEntry::InputStreamEntry;
|
||||
use super::sinkBoxImpl;
|
||||
|
@ -71,18 +71,7 @@ impl SinkBox {
|
|||
selfImp.resetInputCardsBackButton.set_activatable(true);
|
||||
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));
|
||||
selfImp.resetSinkDropdown.set_factory(Some(&createDropdownLabelFactory()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
17
src/components/utils.rs
Normal file
17
src/components/utils.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use glib::Cast;
|
||||
use gtk::{Align, SignalListItemFactory, StringObject};
|
||||
use gtk::prelude::{GObjectPropertyExpressionExt, ListItemExt, WidgetExt};
|
||||
|
||||
pub fn createDropdownLabelFactory() -> SignalListItemFactory {
|
||||
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));
|
||||
});
|
||||
factory
|
||||
}
|
|
@ -5,7 +5,7 @@ use adw::glib::Object;
|
|||
use adw::prelude::{ActionRowExt, ComboRowExt, PreferencesGroupExt};
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use dbus::arg::PropMap;
|
||||
use glib::{clone, ObjectExt, PropertySet};
|
||||
use glib::{clone, PropertySet};
|
||||
use gtk::prelude::{EditableExt, WidgetExt};
|
||||
use regex::Regex;
|
||||
use ReSet_Lib::network::connection::{Connection, Enum, TypeSettings};
|
||||
|
@ -183,12 +183,15 @@ fn setupCallbacks(wifiOptions: &Arc<WifiOptions>) {
|
|||
wifiOptionsIP4.setIP4Visibility(selected);
|
||||
}));
|
||||
|
||||
// TODO not finished
|
||||
let dnsRegex = Regex::new(r"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$").unwrap();
|
||||
imp.resetIP4DNS.connect_changed(clone!(@weak imp => move |entry| {
|
||||
let dnsInput = entry.text();
|
||||
let mut conn = imp.connection.borrow_mut();
|
||||
conn.ipv4.dns.clear();
|
||||
if dnsInput.as_str().is_empty() {
|
||||
imp.resetIP4DNS.remove_css_class("error");
|
||||
return;
|
||||
}
|
||||
for dnsEntry in dnsInput.as_str().split(',').collect::<Vec<&str>>() {
|
||||
if dnsRegex.is_match(dnsEntry) {
|
||||
imp.resetIP4DNS.remove_css_class("error");
|
||||
|
|
Loading…
Reference in a new issue