fixing more of pres model and setting up song model
This commit is contained in:
parent
5f2f2a90a2
commit
68b30877ed
6 changed files with 98 additions and 77 deletions
1
build.rs
1
build.rs
|
@ -10,6 +10,7 @@ fn main() {
|
||||||
.file("src/rust/image_model.rs")
|
.file("src/rust/image_model.rs")
|
||||||
.file("src/rust/video_model.rs")
|
.file("src/rust/video_model.rs")
|
||||||
.file("src/rust/presentation_model.rs")
|
.file("src/rust/presentation_model.rs")
|
||||||
|
.file("src/rust/song_model.rs")
|
||||||
.file("src/rust/ytdl.rs")
|
.file("src/rust/ytdl.rs")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,11 @@ mod file_helper;
|
||||||
pub mod image_model;
|
pub mod image_model;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
pub mod presentation_model;
|
pub mod presentation_model;
|
||||||
|
pub mod song_model;
|
||||||
pub mod schema;
|
pub mod schema;
|
||||||
mod service_thing;
|
mod service_thing;
|
||||||
mod settings;
|
mod settings;
|
||||||
mod slide_model;
|
pub mod slide_model;
|
||||||
mod slide_obj;
|
mod slide_obj;
|
||||||
pub mod video_model;
|
pub mod video_model;
|
||||||
pub mod ytdl;
|
pub mod ytdl;
|
||||||
|
|
|
@ -33,9 +33,9 @@ mod presentation_model {
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone, Debug)]
|
||||||
pub struct Presentation {
|
pub struct Presentation {
|
||||||
id: i32,
|
id: i32,
|
||||||
title: QString,
|
title: String,
|
||||||
html: bool,
|
html: bool,
|
||||||
path: QString,
|
path: String,
|
||||||
page_count: i32,
|
page_count: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,9 +100,9 @@ mod presentation_model {
|
||||||
|
|
||||||
let pres = self::Presentation {
|
let pres = self::Presentation {
|
||||||
id: presentation.id,
|
id: presentation.id,
|
||||||
title: QString::from(&presentation.title),
|
title: presentation.title,
|
||||||
html: presentation.path.ends_with(".html"),
|
html: presentation.path.ends_with(".html"),
|
||||||
path: QString::from(&presentation.path),
|
path: presentation.path,
|
||||||
page_count: presentation.page_count.unwrap(),
|
page_count: presentation.page_count.unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -189,9 +189,9 @@ mod presentation_model {
|
||||||
// println!("{:?}", db);
|
// println!("{:?}", db);
|
||||||
let presentation = self::Presentation {
|
let presentation = self::Presentation {
|
||||||
id: presentation_id,
|
id: presentation_id,
|
||||||
title: presentation_title.clone(),
|
title: presentation_title.clone().to_string(),
|
||||||
html: false,
|
html: false,
|
||||||
path: presentation_path.clone(),
|
path: presentation_path.clone().to_string(),
|
||||||
page_count: new_page_count,
|
page_count: new_page_count,
|
||||||
};
|
};
|
||||||
println!("{:?}", presentation);
|
println!("{:?}", presentation);
|
||||||
|
@ -307,8 +307,8 @@ mod presentation_model {
|
||||||
if let Some(presentation) = self.presentations().get(index.row() as usize) {
|
if let Some(presentation) = self.presentations().get(index.row() as usize) {
|
||||||
return match role {
|
return match role {
|
||||||
0 => QVariant::from(&presentation.id),
|
0 => QVariant::from(&presentation.id),
|
||||||
1 => QVariant::from(&presentation.title),
|
1 => QVariant::from(&QString::from(&presentation.title)),
|
||||||
2 => QVariant::from(&presentation.path),
|
2 => QVariant::from(&QString::from(&presentation.path)),
|
||||||
3 => QVariant::from(&presentation.html),
|
3 => QVariant::from(&presentation.html),
|
||||||
4 => QVariant::from(&presentation.page_count),
|
4 => QVariant::from(&presentation.page_count),
|
||||||
_ => QVariant::default(),
|
_ => QVariant::default(),
|
||||||
|
|
|
@ -35,9 +35,9 @@ diesel::table! {
|
||||||
#[sql_name = "backgroundType"]
|
#[sql_name = "backgroundType"]
|
||||||
background_type -> Nullable<Text>,
|
background_type -> Nullable<Text>,
|
||||||
#[sql_name = "horizontalTextAlignment"]
|
#[sql_name = "horizontalTextAlignment"]
|
||||||
horizontal_text_alignment -> Nullable<Binary>,
|
horizontal_text_alignment -> Nullable<Text>,
|
||||||
#[sql_name = "verticalTextAlignment"]
|
#[sql_name = "verticalTextAlignment"]
|
||||||
vertical_text_alignment -> Nullable<Binary>,
|
vertical_text_alignment -> Nullable<Text>,
|
||||||
font -> Nullable<Text>,
|
font -> Nullable<Text>,
|
||||||
#[sql_name = "fontSize"]
|
#[sql_name = "fontSize"]
|
||||||
font_size -> Nullable<Integer>,
|
font_size -> Nullable<Integer>,
|
||||||
|
|
|
@ -72,11 +72,7 @@ mod slide_model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cxx_qt::qobject(
|
#[cxx_qt::qobject(base = "QAbstractListModel")]
|
||||||
base = "QAbstractListModel",
|
|
||||||
// qml_uri = "com.kdab.cxx_qt.demo",
|
|
||||||
// qml_version = "1.0"
|
|
||||||
)]
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct SlideyMod {
|
pub struct SlideyMod {
|
||||||
id: i32,
|
id: i32,
|
||||||
|
|
|
@ -32,7 +32,6 @@ mod song_model {
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone, Debug)]
|
||||||
pub struct Song {
|
pub struct Song {
|
||||||
id: i32,
|
id: i32,
|
||||||
title: QString,
|
|
||||||
title: String,
|
title: String,
|
||||||
lyrics: String,
|
lyrics: String,
|
||||||
author: String,
|
author: String,
|
||||||
|
@ -105,16 +104,26 @@ mod song_model {
|
||||||
for song in results {
|
for song in results {
|
||||||
println!("{}", song.title);
|
println!("{}", song.title);
|
||||||
println!("{}", song.id);
|
println!("{}", song.id);
|
||||||
println!("{}", song.path);
|
println!("{}", song.background.clone().unwrap_or_default());
|
||||||
println!("--------------");
|
println!("--------------");
|
||||||
if self.as_mut().highest_id() < &song.id {
|
if self.as_mut().highest_id() < &song.id {
|
||||||
self.as_mut().set_highest_id(song.id);
|
self.as_mut().set_highest_id(song.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
let img = self::Song {
|
let img = Song {
|
||||||
id: song.id,
|
id: song.id,
|
||||||
title: QString::from(&song.title),
|
title: song.title,
|
||||||
path: QString::from(&song.path),
|
lyrics: song.lyrics.unwrap_or_default(),
|
||||||
|
author: song.author.unwrap_or_default(),
|
||||||
|
ccli: song.ccli.unwrap_or_default(),
|
||||||
|
audio: song.audio.unwrap_or_default(),
|
||||||
|
verse_order: song.verse_order.unwrap_or_default(),
|
||||||
|
background: song.background.unwrap_or_default(),
|
||||||
|
background_type: song.background_type.unwrap_or_default(),
|
||||||
|
horizontal_text_alignment: song.horizontal_text_alignment.unwrap_or_default(),
|
||||||
|
vertical_text_alignment: song.vertical_text_alignment.unwrap_or_default(),
|
||||||
|
font: song.font.unwrap_or_default(),
|
||||||
|
font_size: song.font_size.unwrap_or_default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.as_mut().add_song(img);
|
self.as_mut().add_song(img);
|
||||||
|
@ -171,50 +180,50 @@ mod song_model {
|
||||||
let song_title = QString::from(name);
|
let song_title = QString::from(name);
|
||||||
let song_path = url.to_qstring();
|
let song_path = url.to_qstring();
|
||||||
|
|
||||||
if self.as_mut().add_item(song_id, song_title, song_path) {
|
// if self.as_mut().add_item(song_id, song_title, song_path) {
|
||||||
println!("filename: {:?}", name);
|
// println!("filename: {:?}", name);
|
||||||
self.as_mut().set_highest_id(song_id);
|
// self.as_mut().set_highest_id(song_id);
|
||||||
} else {
|
// } else {
|
||||||
println!("Error in inserting item");
|
// println!("Error in inserting item");
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_item(
|
// fn add_item(
|
||||||
mut self: Pin<&mut Self>,
|
// mut self: Pin<&mut Self>,
|
||||||
song_id: i32,
|
// song_id: i32,
|
||||||
song_title: QString,
|
// song_title: QString,
|
||||||
song_path: QString,
|
// song_path: QString,
|
||||||
) -> bool {
|
// ) -> bool {
|
||||||
let db = &mut self.as_mut().get_db();
|
// let db = &mut self.as_mut().get_db();
|
||||||
// println!("{:?}", db);
|
// // println!("{:?}", db);
|
||||||
let song = self::Song {
|
// let song = self::Song {
|
||||||
id: song_id,
|
// id: song_id,
|
||||||
title: song_title.clone(),
|
// title: song_title.clone(),
|
||||||
path: song_path.clone(),
|
// path: song_path.clone(),
|
||||||
};
|
// };
|
||||||
println!("{:?}", song);
|
// println!("{:?}", song);
|
||||||
|
|
||||||
let result = insert_into(songs)
|
// let result = insert_into(songs)
|
||||||
.values((
|
// .values((
|
||||||
id.eq(&song_id),
|
// id.eq(&song_id),
|
||||||
title.eq(&song_title.to_string()),
|
// title.eq(&song_title.to_string()),
|
||||||
path.eq(&song_path.to_string()),
|
// path.eq(&song_path.to_string()),
|
||||||
))
|
// ))
|
||||||
.execute(db);
|
// .execute(db);
|
||||||
println!("{:?}", result);
|
// println!("{:?}", result);
|
||||||
|
|
||||||
match result {
|
// match result {
|
||||||
Ok(_i) => {
|
// Ok(_i) => {
|
||||||
self.as_mut().add_song(song);
|
// self.as_mut().add_song(song);
|
||||||
println!("{:?}", self.as_mut().songs());
|
// println!("{:?}", self.as_mut().songs());
|
||||||
true
|
// true
|
||||||
}
|
// }
|
||||||
Err(_e) => {
|
// Err(_e) => {
|
||||||
println!("Cannot connect to database");
|
// println!("Cannot connect to database");
|
||||||
false
|
// false
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn add_song(mut self: Pin<&mut Self>, song: self::Song) {
|
fn add_song(mut self: Pin<&mut Self>, song: self::Song) {
|
||||||
let index = self.as_ref().songs().len() as i32;
|
let index = self.as_ref().songs().len() as i32;
|
||||||
|
@ -240,7 +249,7 @@ mod song_model {
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
|
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
|
||||||
song.title = updated_title;
|
song.title = updated_title.to_string();
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
.emit_data_changed(model_index, model_index, &vector_roles);
|
||||||
true
|
true
|
||||||
|
@ -253,20 +262,20 @@ mod song_model {
|
||||||
pub fn update_file_path(
|
pub fn update_file_path(
|
||||||
mut self: Pin<&mut Self>,
|
mut self: Pin<&mut Self>,
|
||||||
index: i32,
|
index: i32,
|
||||||
updated_file_path: QString,
|
updated_background: QString,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut vector_roles = QVector_i32::default();
|
let mut vector_roles = QVector_i32::default();
|
||||||
vector_roles.append(self.as_ref().get_role(Role::PathRole));
|
vector_roles.append(self.as_ref().get_role(Role::BackgroundRole));
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
||||||
|
|
||||||
let db = &mut self.as_mut().get_db();
|
let db = &mut self.as_mut().get_db();
|
||||||
let result = update(songs.filter(id.eq(index)))
|
let result = update(songs.filter(id.eq(index)))
|
||||||
.set(path.eq(updated_file_path.to_string()))
|
.set(background.eq(updated_background.to_string()))
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
|
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
|
||||||
song.path = updated_file_path;
|
song.background = updated_background.to_string();
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
.emit_data_changed(model_index, model_index, &vector_roles);
|
||||||
true
|
true
|
||||||
|
@ -296,6 +305,20 @@ mod song_model {
|
||||||
qvariantmap
|
qvariantmap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn get_lyric_list(mut self: Pin<&mut Self>, index: i32) -> QList_QString {
|
||||||
|
println!("{index}");
|
||||||
|
let lyric_list = QList_QString::default();
|
||||||
|
let idx = self.index(index, 0, &QModelIndex::default());
|
||||||
|
if !idx.is_valid() {
|
||||||
|
return lyric_list;
|
||||||
|
}
|
||||||
|
if let Some(song) = self.rust().songs.get(index as usize) {
|
||||||
|
let raw_lyrics = song.lyrics.clone();
|
||||||
|
}
|
||||||
|
lyric_list
|
||||||
|
}
|
||||||
|
|
||||||
fn get_role(&self, role: Role) -> i32 {
|
fn get_role(&self, role: Role) -> i32 {
|
||||||
match role {
|
match role {
|
||||||
Role::IdRole => 0,
|
Role::IdRole => 0,
|
||||||
|
@ -359,17 +382,17 @@ mod song_model {
|
||||||
if let Some(song) = self.songs().get(index.row() as usize) {
|
if let Some(song) = self.songs().get(index.row() as usize) {
|
||||||
return match role {
|
return match role {
|
||||||
0 => QVariant::from(&song.id),
|
0 => QVariant::from(&song.id),
|
||||||
1 => QVariant::from(&song.title),
|
1 => QVariant::from(&QString::from(&song.title)),
|
||||||
2 => QVariant::from(&song.lyrics),
|
2 => QVariant::from(&QString::from(&song.lyrics)),
|
||||||
3 => QVariant::from(&song.author),
|
3 => QVariant::from(&QString::from(&song.author)),
|
||||||
4 => QVariant::from(&song.ccli),
|
4 => QVariant::from(&QString::from(&song.ccli)),
|
||||||
5 => QVariant::from(&song.audio),
|
5 => QVariant::from(&QString::from(&song.audio)),
|
||||||
6 => QVariant::from(&song.verse_order),
|
6 => QVariant::from(&QString::from(&song.verse_order)),
|
||||||
7 => QVariant::from(&song.background),
|
7 => QVariant::from(&QString::from(&song.background)),
|
||||||
8 => QVariant::from(&song.background_type),
|
8 => QVariant::from(&QString::from(&song.background_type)),
|
||||||
9 => QVariant::from(&song.horizontal_text_alignment),
|
9 => QVariant::from(&QString::from(&song.horizontal_text_alignment)),
|
||||||
10 => QVariant::from(&song.vertical_text_alignment),
|
10 => QVariant::from(&QString::from(&song.vertical_text_alignment)),
|
||||||
11 => QVariant::from(&song.font),
|
11 => QVariant::from(&QString::from(&song.font)),
|
||||||
12 => QVariant::from(&song.font_size),
|
12 => QVariant::from(&song.font_size),
|
||||||
_ => QVariant::default(),
|
_ => QVariant::default(),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue