fixing lots of bugs
This commit is contained in:
parent
da735aa00b
commit
0ba3e7588b
24 changed files with 781 additions and 486 deletions
|
|
@ -178,6 +178,7 @@ pub mod video_model {
|
|||
}
|
||||
}
|
||||
|
||||
use color_eyre::eyre::Error;
|
||||
use cxx_qt::{CxxQtType, Threading};
|
||||
use cxx_qt_lib::{QByteArray, QModelIndex, QString, QUrl, QVariant};
|
||||
use sqlx::{query, query_as, Connection, SqliteConnection};
|
||||
|
|
@ -224,9 +225,11 @@ impl Default for VideoModelRust {
|
|||
let mut db_url = String::from("sqlite://");
|
||||
db_url.push_str(data.to_str().unwrap());
|
||||
rt.block_on(async {
|
||||
SqliteConnection::connect(&db_url).await.expect("problems")
|
||||
SqliteConnection::connect(&db_url)
|
||||
.await
|
||||
.expect("problems")
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -240,12 +243,20 @@ pub fn get_video(index: i32) -> color_eyre::Result<Video> {
|
|||
let mut db_url = String::from("sqlite://");
|
||||
db_url.push_str(data.to_str().unwrap());
|
||||
rt.block_on(async {
|
||||
SqliteConnection::connect(&db_url).await.expect("problems")
|
||||
SqliteConnection::connect(&db_url)
|
||||
.await
|
||||
.expect("problems")
|
||||
})
|
||||
};
|
||||
rt.block_on(async {
|
||||
let result = query_as!(Video, r#"SELECT id as "id: i32", title as "title!", filePath as "path!", startTime as "start_time!: f32", endTime as "end_time!: f32", loop as "looping!" from videos where id = ?"#, index).fetch_one(&mut db).await?;
|
||||
Ok(result)
|
||||
let result = query_as!(Video, r#"SELECT id as "id: i32", title as "title!", file_path as "path!", start_time as "start_time!: f32", end_time as "end_time!: f32", loop as "looping!" from videos where id = ?"#, index).fetch_one(&mut db).await;
|
||||
match result {
|
||||
Ok(v) => Ok(v),
|
||||
Err(e) => {
|
||||
error!(?e);
|
||||
Err(color_eyre::Report::from(e))
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -261,7 +272,7 @@ impl video_model::VideoModel {
|
|||
pub fn setup(mut self: Pin<&mut Self>) {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let result = query_as!(Video, r#"SELECT id as "id: i32", title as "title!", filePath as "path!", startTime as "start_time!: f32", endTime as "end_time!: f32", loop as "looping!" from videos"#).fetch_all(&mut self.as_mut().rust_mut().db).await;
|
||||
let result = query_as!(Video, r#"SELECT id as "id: i32", title as "title!", file_path as "path!", start_time as "start_time!: f32", end_time as "end_time!: f32", loop as "looping!" from videos"#).fetch_all(&mut self.as_mut().rust_mut().db).await;
|
||||
match result {
|
||||
Ok(v) => v.into_iter().for_each(|v| self.as_mut().add_video(v)),
|
||||
Err(e) => error!("There was an error in converting songs: {e}"),
|
||||
|
|
@ -277,7 +288,10 @@ impl video_model::VideoModel {
|
|||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
|
||||
rt.block_on(async {
|
||||
let result = query!("delete from videos where id = ?", video_id).execute(&mut self.as_mut().rust_mut().db).await;
|
||||
let result =
|
||||
query!("delete from videos where id = ?", video_id)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
unsafe {
|
||||
|
|
@ -334,7 +348,7 @@ impl video_model::VideoModel {
|
|||
rt.block_on(async {
|
||||
let video_title = video_title.to_string();
|
||||
let video_path = video_path.to_string();
|
||||
let result = query!(r#"INSERT into videos (id, title, filePath, startTime, endTime, loop) VALUES (?, ?, ?, ?, ?, ?)"#,
|
||||
let result = query!(r#"INSERT into videos (id, title, file_path, start_time, end_time, loop) VALUES (?, ?, ?, ?, ?, ?)"#,
|
||||
video_id,
|
||||
video_title,
|
||||
video_path,
|
||||
|
|
@ -435,9 +449,13 @@ impl video_model::VideoModel {
|
|||
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let result = query!("UPDATE videos SET loop = ? where id = ?", loop_value, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
let result = query!(
|
||||
"UPDATE videos SET loop = ? where id = ?",
|
||||
loop_value,
|
||||
index
|
||||
)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for video in self
|
||||
|
|
@ -448,9 +466,11 @@ impl video_model::VideoModel {
|
|||
.filter(|x| x.id == index)
|
||||
{
|
||||
video.looping = loop_value;
|
||||
debug!(title = video.title,
|
||||
looping = loop_value,
|
||||
"updated video loop");
|
||||
debug!(
|
||||
title = video.title,
|
||||
looping = loop_value,
|
||||
"updated video loop"
|
||||
);
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
|
|
@ -462,7 +482,7 @@ impl video_model::VideoModel {
|
|||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
true
|
||||
|
|
@ -481,9 +501,13 @@ impl video_model::VideoModel {
|
|||
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let result = query!("UPDATE videos SET endTime = ? where id = ?", updated_end_time, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
let result = query!(
|
||||
"UPDATE videos SET end_time = ? where id = ?",
|
||||
updated_end_time,
|
||||
index
|
||||
)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for video in self
|
||||
|
|
@ -494,9 +518,11 @@ impl video_model::VideoModel {
|
|||
.filter(|x| x.id == index)
|
||||
{
|
||||
video.end_time = updated_end_time;
|
||||
debug!(title = video.title,
|
||||
end_time = updated_end_time,
|
||||
"updated video end_time");
|
||||
debug!(
|
||||
title = video.title,
|
||||
end_time = updated_end_time,
|
||||
"updated video end_time"
|
||||
);
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
|
|
@ -508,7 +534,7 @@ impl video_model::VideoModel {
|
|||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
true
|
||||
|
|
@ -527,9 +553,13 @@ impl video_model::VideoModel {
|
|||
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let result = query!("UPDATE videos SET startTime = ? where id = ?", updated_start_time, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
let result = query!(
|
||||
"UPDATE videos SET start_time = ? where id = ?",
|
||||
updated_start_time,
|
||||
index
|
||||
)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for video in self
|
||||
|
|
@ -540,9 +570,11 @@ impl video_model::VideoModel {
|
|||
.filter(|x| x.id == index)
|
||||
{
|
||||
video.start_time = updated_start_time;
|
||||
debug!(title = video.title,
|
||||
start_time = updated_start_time,
|
||||
"updated video start_time");
|
||||
debug!(
|
||||
title = video.title,
|
||||
start_time = updated_start_time,
|
||||
"updated video start_time"
|
||||
);
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
|
|
@ -554,7 +586,7 @@ impl video_model::VideoModel {
|
|||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
true
|
||||
|
|
@ -574,9 +606,13 @@ impl video_model::VideoModel {
|
|||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let title = updated_title.to_string();
|
||||
let result = query!("UPDATE videos SET title = ? where id = ?", title, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
let result = query!(
|
||||
"UPDATE videos SET title = ? where id = ?",
|
||||
title,
|
||||
index
|
||||
)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for video in self
|
||||
|
|
@ -587,9 +623,11 @@ impl video_model::VideoModel {
|
|||
.filter(|x| x.id == index)
|
||||
{
|
||||
video.title = title.clone();
|
||||
debug!(title = video.title,
|
||||
title = title,
|
||||
"updated video title");
|
||||
debug!(
|
||||
title = video.title,
|
||||
title = title,
|
||||
"updated video title"
|
||||
);
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
|
|
@ -601,7 +639,7 @@ impl video_model::VideoModel {
|
|||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
true
|
||||
|
|
@ -620,9 +658,13 @@ impl video_model::VideoModel {
|
|||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let updated_path = updated_path.to_string();
|
||||
let result = query!("UPDATE videos SET filePath = ? where id = ?", updated_path, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
let result = query!(
|
||||
"UPDATE videos SET file_path = ? where id = ?",
|
||||
updated_path,
|
||||
index
|
||||
)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for video in self
|
||||
|
|
@ -633,9 +675,11 @@ impl video_model::VideoModel {
|
|||
.filter(|x| x.id == index)
|
||||
{
|
||||
video.path = updated_path.clone();
|
||||
debug!(title = video.title,
|
||||
path = updated_path,
|
||||
"updated video path");
|
||||
debug!(
|
||||
title = video.title,
|
||||
path = updated_path,
|
||||
"updated video path"
|
||||
);
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
|
|
@ -647,7 +691,7 @@ impl video_model::VideoModel {
|
|||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue