doing dumb things for obs
This commit is contained in:
parent
4b489d4e45
commit
b07e59659d
4 changed files with 101 additions and 43 deletions
|
@ -155,6 +155,8 @@ int main(int argc, char *argv[])
|
|||
QScopedPointer<ServiceItemModel> serviceItemC(new ServiceItemModel);
|
||||
QScopedPointer<SlideObject> slideobject(new SlideObject);
|
||||
QScopedPointer<ObsModel> obsModel(new ObsModel);
|
||||
obsModel.get()->getObs();
|
||||
obsModel.get()->updateScenes();
|
||||
|
||||
Settings *settings = new Settings;
|
||||
settings->setup();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import QtQuick 2.13
|
||||
/* import QtQuick.Dialogs 1.0 */
|
||||
import QtQuick.Controls 2.0 as Controls
|
||||
import QtQuick.Controls 2.12 as Controls
|
||||
/* import QtQuick.Window 2.15 */
|
||||
import QtQuick.Layouts 1.15
|
||||
import QtQuick.Shapes 1.15
|
||||
|
@ -279,35 +279,33 @@ Item {
|
|||
}
|
||||
Controls.Menu {
|
||||
id: rightClickMenu
|
||||
x: mouse.mouseX
|
||||
y: mouse.mouseY + 10
|
||||
Kirigami.Action {
|
||||
text: "copy"
|
||||
text: "Copy"
|
||||
}
|
||||
Kirigami.Action {
|
||||
text: "paste"
|
||||
text: "Paste"
|
||||
}
|
||||
Kirigami.Action {
|
||||
text: "delete"
|
||||
text: "Delete"
|
||||
onTriggered: removeItem(index)
|
||||
}
|
||||
Kirigami.Action {
|
||||
text: "Obs Scenes"
|
||||
onTriggered: {
|
||||
ObsModel.updateScenes();
|
||||
console.log("udated")
|
||||
obsList.model = ObsModel.scenes
|
||||
obsMenu.open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Controls.MenuSeparator {}
|
||||
|
||||
Controls.Menu {
|
||||
id: obsMenu
|
||||
x: rightClickMenu.x + rightClickMenu.width
|
||||
y: mouse.mouseY
|
||||
title: "Obs Scenes"
|
||||
|
||||
ListView {
|
||||
id: obsList
|
||||
delegate: Kirigami.Action { text: modelData }
|
||||
width: parent.width
|
||||
height: 200
|
||||
model: ObsModel.scenes
|
||||
delegate: Controls.ToolButton {
|
||||
width: parent.width
|
||||
text: modelData
|
||||
onClicked: ObsModel.setScene(modelData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,10 @@ Kirigami.OverlaySheet {
|
|||
text: "Settings"
|
||||
}
|
||||
|
||||
/* Component.onCompleted: { */
|
||||
/* showPassiveNotification(screenModel.get(1).name) */
|
||||
/* } */
|
||||
Component.onCompleted: {
|
||||
/* ObsModel.getObs(); */
|
||||
/* ObsModel.updateScenes(); */
|
||||
}
|
||||
|
||||
Kirigami.FormLayout {
|
||||
implicitHeight: Kirigami.Units.gridUnit * 30
|
||||
|
@ -61,6 +62,21 @@ Kirigami.OverlaySheet {
|
|||
text: "Sound Effect"
|
||||
onClicked: soundFileDialog.open()
|
||||
}
|
||||
|
||||
Controls.ToolButton {
|
||||
Kirigami.FormData.label: i18nc("@label:button", "OBS debug")
|
||||
text: "Obs Debug"
|
||||
onClicked: {
|
||||
ObsModel.updateScenes();
|
||||
console.log(ObsModel.scenes);
|
||||
}
|
||||
}
|
||||
|
||||
Kirigami.ActionTextField {
|
||||
Kirigami.FormData.label: i18nc("@label:textbox", "Obs Connection")
|
||||
text: ObsModel.connected
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use core::fmt;
|
||||
use std::error::Error;
|
||||
use std::time::Duration;
|
||||
|
||||
use obws::responses::scenes::Scenes;
|
||||
use obws::Client;
|
||||
|
@ -67,22 +68,18 @@ impl Obs {
|
|||
self,
|
||||
scene: String,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
debug!("Starting function");
|
||||
if self.client.is_some() {
|
||||
if let Some(scene) = self
|
||||
.scenes
|
||||
.scenes
|
||||
.iter()
|
||||
.filter(|x| x.name == scene)
|
||||
.next()
|
||||
{
|
||||
debug!("Starting to set");
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
tokio::spawn(async move {
|
||||
debug!(scene, "working in thread");
|
||||
self.client
|
||||
.unwrap()
|
||||
.scenes()
|
||||
.set_current_program_scene(scene.name.as_str());
|
||||
.set_current_program_scene(scene.as_str()).await
|
||||
});
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Couldn't set the scene".to_owned())?
|
||||
}
|
||||
} else {
|
||||
Err("There is no client".to_owned())?
|
||||
}
|
||||
|
@ -98,7 +95,7 @@ fn make_client() -> Client {
|
|||
|
||||
#[cxx_qt::bridge]
|
||||
mod obs_model {
|
||||
use tracing::debug;
|
||||
use tracing::{debug, error};
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!("cxx-qt-lib/qstring.h");
|
||||
|
@ -114,6 +111,10 @@ mod obs_model {
|
|||
pub struct ObsModel {
|
||||
#[qproperty]
|
||||
scenes: QStringList,
|
||||
#[qproperty]
|
||||
port: QString,
|
||||
#[qproperty]
|
||||
connected: bool,
|
||||
obs: Option<super::Obs>,
|
||||
}
|
||||
|
||||
|
@ -124,12 +125,53 @@ mod obs_model {
|
|||
debug!("updating scenes");
|
||||
let mut scenes_list = QList_QString::default();
|
||||
if let Some(obs) = self.obs() {
|
||||
obs.scenes.scenes.iter().map(|x| {
|
||||
debug!(?x);
|
||||
scenes_list.append(QString::from(&x.name))
|
||||
debug!("found obs");
|
||||
for scene in obs.scenes.scenes.iter() {
|
||||
debug!(?scene);
|
||||
scenes_list.append(QString::from(&scene.name));
|
||||
}
|
||||
}
|
||||
for s in scenes_list.iter() {
|
||||
debug!(?s);
|
||||
}
|
||||
let list = QStringList::from(&scenes_list);
|
||||
debug!(?list);
|
||||
self.as_mut().set_scenes(list.clone());
|
||||
list
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn get_obs(mut self: Pin<&mut Self>) -> bool {
|
||||
debug!("getting obs");
|
||||
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
match super::Obs::new().await {
|
||||
Ok(o) => {
|
||||
self.as_mut().set_connected(true);
|
||||
self.as_mut().set_obs(Some(o));
|
||||
self.as_mut().update_scenes();
|
||||
},
|
||||
Err(e) => error!(e)
|
||||
}
|
||||
});
|
||||
|
||||
if let Some(_obs) = self.obs() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn set_scene(mut self: Pin<&mut Self>, scene: QString) {
|
||||
let scene = scene.to_string();
|
||||
if let Some(obs) = self.obs_mut() {
|
||||
let obs = obs.clone();
|
||||
match obs.set_scene(scene) {
|
||||
Ok(()) => debug!("Successfully set scene"),
|
||||
Err(e) => error!(e),
|
||||
}
|
||||
}
|
||||
QStringList::from(&scenes_list)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue