chore: Rename UI files

This commit is contained in:
Fabio Lenherr 2023-11-14 18:22:10 +01:00
parent ed00b26749
commit 2f1099267a
35 changed files with 679 additions and 176 deletions

View file

@ -1,5 +1,7 @@
#![allow(non_snake_case)]
pub mod inputStreamEntry;
pub mod sourceBox;
pub mod sourceBoxImpl;
pub mod inputStreamEntryImpl;
pub mod outputStreamEntry;
pub mod outputStreamEntryImpl;
pub mod sourceEntry;
pub mod sourceEntryImpl;

View file

@ -1,14 +1,15 @@
use crate::components::input::inputStreamEntryImpl;
use adw::glib;
use adw::glib::Object;
use super::outputStreamEntryImpl;
glib::wrapper! {
pub struct InputStreamEntry(ObjectSubclass<inputStreamEntryImpl::InputStreamEntry>)
pub struct OutputStreamEntry(ObjectSubclass<outputStreamEntryImpl::OutputStreamEntry>)
@extends gtk::Box, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
}
impl InputStreamEntry {
impl OutputStreamEntry {
pub fn new() -> Self {
Object::builder().build()
}

View file

@ -1,14 +1,16 @@
use gtk::{Button, CompositeTemplate, glib, Label, ProgressBar, Scale};
use crate::components::input::outputStreamEntry;
use gtk::subclass::prelude::*;
use crate::components::input::inputStreamEntry;
use gtk::{glib, Button, CompositeTemplate, Label, ProgressBar, Scale, DropDown};
#[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)]
#[template(resource = "/org/Xetibo/ReSet/resetInputStreamEntry.ui")]
pub struct InputStreamEntry {
#[template(resource = "/org/Xetibo/ReSet/resetOutputStreamEntry.ui")]
pub struct OutputStreamEntry {
#[template_child]
pub resetSourceName: TemplateChild<Label>,
#[template_child]
pub resetSelectedSource: TemplateChild<DropDown>,
#[template_child]
pub resetSourceMute: TemplateChild<Button>,
#[template_child]
pub resetVolumeSlider: TemplateChild<Scale>,
@ -19,9 +21,9 @@ pub struct InputStreamEntry {
}
#[glib::object_subclass]
impl ObjectSubclass for InputStreamEntry {
const NAME: &'static str = "resetInputStreamEntry";
type Type = inputStreamEntry::InputStreamEntry;
impl ObjectSubclass for OutputStreamEntry {
const NAME: &'static str = "resetOutputStreamEntry";
type Type = outputStreamEntry::OutputStreamEntry;
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {
@ -33,8 +35,9 @@ impl ObjectSubclass for InputStreamEntry {
}
}
impl BoxImpl for InputStreamEntry {}
impl BoxImpl for OutputStreamEntry {}
impl ObjectImpl for InputStreamEntry {}
impl ObjectImpl for OutputStreamEntry {}
impl WidgetImpl for OutputStreamEntry {}
impl WidgetImpl for InputStreamEntry {}

View file

@ -21,6 +21,6 @@ impl SourceBox {
selfImp.resetSourceRow.set_action_name(Some("navigation.push"));
selfImp.resetSourceRow.set_action_target_value(Some(&Variant::from("sources")));
selfImp.resetInputStreamButton.set_action_name(Some("navigation.pop"));
selfImp.resetOutputStreamButton.set_action_name(Some("navigation.pop"));
}
}

View file

@ -1,35 +1,50 @@
use std::cell::RefCell;
use std::sync::{Arc, Mutex};
use crate::components::base::listEntry::ListEntry;
use crate::components::input::inputStreamEntry::InputStreamEntry;
use crate::components::input::sourceBox;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate, DropDown, TemplateChild};
use gtk::{prelude::*, Button, Label, ProgressBar, Scale};
use ReSet_Lib::audio::audio::{OutputStream, Source};
use super::outputStreamEntry::OutputStreamEntry;
#[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)]
#[template(resource = "/org/Xetibo/ReSet/resetMicrophone.ui")]
#[template(resource = "/org/Xetibo/ReSet/resetAudioInput.ui")]
pub struct SourceBox {
#[template_child]
pub resetSourceDropdown: TemplateChild<DropDown>,
#[template_child]
pub resetSourceRow: TemplateChild<ListEntry>,
#[template_child]
pub resetInputStreamButton: TemplateChild<ListEntry>,
pub resetSources: Arc<Mutex<Vec<Source>>>,
pub resetOutputStreams: Arc<Mutex<Vec<OutputStream>>>,
pub resetSourceDropdown: TemplateChild<DropDown>,
#[template_child]
pub resetSourceMute: TemplateChild<Button>,
#[template_child]
pub resetVolumeSlider: TemplateChild<Scale>,
#[template_child]
pub resetVolumePercentage: TemplateChild<Label>,
#[template_child]
pub resetVolumeMeter: TemplateChild<ProgressBar>,
#[template_child]
pub resetSources: TemplateChild<gtk::Box>,
#[template_child]
pub resetOutputStreamButton: TemplateChild<ListEntry>,
#[template_child]
pub resetOutputStreams: TemplateChild<gtk::Box>,
pub resetDefaultSource: RefCell<Option<Source>>,
pub resetSourceList: Arc<Mutex<Vec<Source>>>,
pub resetOutputStreamList: Arc<Mutex<Vec<OutputStream>>>,
}
#[glib::object_subclass]
impl ObjectSubclass for SourceBox {
const NAME: &'static str = "resetMicrophone";
const NAME: &'static str = "resetAudioInput";
type Type = sourceBox::SourceBox;
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {
InputStreamEntry::ensure_type();
OutputStreamEntry::ensure_type();
ListEntry::ensure_type();
klass.bind_template();
}
@ -55,4 +70,3 @@ impl WidgetImpl for SourceBox {}
impl WindowImpl for SourceBox {}
impl ApplicationWindowImpl for SourceBox {}

View file

@ -0,0 +1,72 @@
use std::cell::RefCell;
use std::sync::Arc;
use std::time::Duration;
use adw::glib;
use adw::glib::Object;
use adw::prelude::RangeExt;
use dbus::blocking::Connection;
use dbus::Error;
use glib::subclass::types::ObjectSubclassIsExt;
use glib::{clone, Propagation};
use ReSet_Lib::audio::audio::Source;
use super::sourceEntryImpl;
glib::wrapper! {
pub struct SourceEntry(ObjectSubclass<sourceEntryImpl::SourceEntry>)
@extends gtk::Box, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
}
impl SourceEntry {
pub fn new(stream: Source) -> Self {
let obj: Self = Object::builder().build();
// TODO use event callback for progress bar -> this is the "im speaking" indicator
// TODO map the slider to volume
// TODO properly use volume fraction
// TODO map mute to callback
// TODO map dropdown
{
let imp = obj.imp();
imp.resetSourceName.set_text(stream.name.clone().as_str());
let volume = stream.volume.first().unwrap_or_else(|| &(0 as u32));
let fraction = (*volume as f64 / 655.36).round();
let percentage = (fraction).to_string() + "%";
imp.resetVolumePercentage.set_text(&percentage);
imp.resetVolumeSlider.set_value(*volume as f64);
imp.stream.replace(stream);
imp.resetVolumeSlider.connect_change_value(
clone!(@weak imp => @default-return Propagation::Stop, move |_, _, value| {
let fraction = (value / 655.36).round();
println!("{fraction}");
let percentage = (fraction).to_string() + "%";
imp.resetVolumePercentage.set_text(&percentage);
set_inputstream_volume(value, imp.stream.clone());
Propagation::Proceed
}),
);
}
obj
}
}
fn set_inputstream_volume(value: f64, stream: Arc<RefCell<Source>>) -> bool {
let mut stream = stream.borrow_mut().clone();
// let x = stream.volume.iter_mut().map(|_| value as u32);
stream.volume = vec![value as u32; stream.channels as usize];
dbg!(stream.volume.clone());
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(
"org.xetibo.ReSet",
"/org/xetibo/ReSet",
Duration::from_millis(100),
);
let res: Result<(bool,), Error> =
proxy.method_call("org.xetibo.ReSet", "SetSourceVolume", (stream,));
if res.is_err() {
return false;
}
res.unwrap().0
}

View file

@ -0,0 +1,48 @@
use std::cell::RefCell;
use std::sync::Arc;
use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, DropDown, Label, ProgressBar, Scale, CheckButton};
use ReSet_Lib::audio::audio::Source;
use super::sourceEntry;
#[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)]
#[template(resource = "/org/Xetibo/ReSet/resetSourceEntry.ui")]
pub struct SourceEntry {
#[template_child]
pub resetSourceName: TemplateChild<Label>,
#[template_child]
pub resetSelectedSource: TemplateChild<CheckButton>,
#[template_child]
pub resetSourceMute: TemplateChild<Button>,
#[template_child]
pub resetVolumeSlider: TemplateChild<Scale>,
#[template_child]
pub resetVolumePercentage: TemplateChild<Label>,
#[template_child]
pub resetVolumeMeter: TemplateChild<ProgressBar>,
pub stream: Arc<RefCell<Source>>,
}
#[glib::object_subclass]
impl ObjectSubclass for SourceEntry {
const NAME: &'static str = "resetSourceEntry";
type Type = sourceEntry::SourceEntry;
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl BoxImpl for SourceEntry {}
impl ObjectImpl for SourceEntry {}
impl WidgetImpl for SourceEntry {}