adding a basic obs implementation

This commit is contained in:
Chris Cochrun 2023-11-02 06:30:16 -05:00
parent 499567a4ed
commit de0c26271f
3 changed files with 79 additions and 25 deletions

View file

@ -24,6 +24,7 @@ mod service_item_model {
type QUrl = cxx_qt_lib::QUrl;
}
use crate::obs::Obs;
use serde::{Deserialize, Serialize};
#[cxx_qt::qobject]
#[derive(Clone, Debug)]
@ -83,13 +84,26 @@ mod service_item_model {
}
#[cxx_qt::qobject(base = "QAbstractListModel")]
#[derive(Default, Debug)]
#[derive(Debug)]
pub struct ServiceItemMod {
id: i32,
service_items: Vec<ServiceItm>,
obs: Obs,
}
impl Default for ServiceItemMod {
fn default() -> Self {
let obs = tokio::runtime::Runtime::new()
.unwrap()
.block_on(async { Obs::new().await.ok().unwrap() });
Self {
id: 0,
service_items: Vec::new(),
obs,
}
}
}
#[cxx_qt::qsignals(ServiceItemMod)]
pub enum Signals<'a> {
#[inherit]
@ -152,7 +166,6 @@ mod service_item_model {
use tracing::{debug, debug_span, error, info, instrument};
use zstd::{Decoder, Encoder};
use crate::obs::Obs;
impl qobject::ServiceItemMod {
pub fn setup(mut self: Pin<&mut Self>) {
todo!()
@ -349,6 +362,8 @@ mod service_item_model {
let dest_id = dest_index as usize;
let cnt = count as usize;
let end_service_item = source_id + cnt - 1;
// This needs to point to the index above the intended position if moving
// up. Qt's begin_move_rows requires that knowledge for some reason.
let qt_dest_index = if source_index < dest_index {
dest_index + 1
} else {
@ -585,25 +600,19 @@ mod service_item_model {
// println!("service_item is deactivating {:?}", i);
service_item.active = false;
}
let obs = self.as_mut().obs_mut().clone();
if let Some(service_item) = self
.as_mut()
.service_items_mut()
.get_mut(index as usize)
{
println!("service_item is activating {:?}", index);
println!(
"service_item_title: {:?}",
service_item.name
);
println!(
"service_item_background: {:?}",
service_item.background
);
println!(
"service_item_background_type: {:?}",
service_item.background_type
);
debug!(activating_item = index,
title = ?service_item.name,
background = ?service_item.background,
background_type = ?service_item.background_type);
service_item.active = true;
obs.set_scene(service_item.obs_scene.to_string());
self.as_mut().emit_data_changed(
tl,
br,
@ -612,7 +621,6 @@ mod service_item_model {
// We use this signal generated by our signals enum to tell QML that
// the active service_item has changed which is used to reposition views.
self.as_mut().emit_active_changed();
Obs::set_scene(service_item.obs_scene.to_string());
true
} else {
false