fixing more of pres model and setting up song model

This commit is contained in:
Chris Cochrun 2023-05-04 09:30:03 -05:00
parent 5f2f2a90a2
commit 68b30877ed
6 changed files with 98 additions and 77 deletions

View file

@ -10,6 +10,7 @@ fn main() {
.file("src/rust/image_model.rs")
.file("src/rust/video_model.rs")
.file("src/rust/presentation_model.rs")
.file("src/rust/song_model.rs")
.file("src/rust/ytdl.rs")
.build();
}

View file

@ -3,10 +3,11 @@ mod file_helper;
pub mod image_model;
pub mod models;
pub mod presentation_model;
pub mod song_model;
pub mod schema;
mod service_thing;
mod settings;
mod slide_model;
pub mod slide_model;
mod slide_obj;
pub mod video_model;
pub mod ytdl;

View file

@ -33,9 +33,9 @@ mod presentation_model {
#[derive(Default, Clone, Debug)]
pub struct Presentation {
id: i32,
title: QString,
title: String,
html: bool,
path: QString,
path: String,
page_count: i32,
}
@ -100,9 +100,9 @@ mod presentation_model {
let pres = self::Presentation {
id: presentation.id,
title: QString::from(&presentation.title),
title: presentation.title,
html: presentation.path.ends_with(".html"),
path: QString::from(&presentation.path),
path: presentation.path,
page_count: presentation.page_count.unwrap(),
};
@ -189,9 +189,9 @@ mod presentation_model {
// println!("{:?}", db);
let presentation = self::Presentation {
id: presentation_id,
title: presentation_title.clone(),
title: presentation_title.clone().to_string(),
html: false,
path: presentation_path.clone(),
path: presentation_path.clone().to_string(),
page_count: new_page_count,
};
println!("{:?}", presentation);
@ -307,8 +307,8 @@ mod presentation_model {
if let Some(presentation) = self.presentations().get(index.row() as usize) {
return match role {
0 => QVariant::from(&presentation.id),
1 => QVariant::from(&presentation.title),
2 => QVariant::from(&presentation.path),
1 => QVariant::from(&QString::from(&presentation.title)),
2 => QVariant::from(&QString::from(&presentation.path)),
3 => QVariant::from(&presentation.html),
4 => QVariant::from(&presentation.page_count),
_ => QVariant::default(),

View file

@ -35,9 +35,9 @@ diesel::table! {
#[sql_name = "backgroundType"]
background_type -> Nullable<Text>,
#[sql_name = "horizontalTextAlignment"]
horizontal_text_alignment -> Nullable<Binary>,
horizontal_text_alignment -> Nullable<Text>,
#[sql_name = "verticalTextAlignment"]
vertical_text_alignment -> Nullable<Binary>,
vertical_text_alignment -> Nullable<Text>,
font -> Nullable<Text>,
#[sql_name = "fontSize"]
font_size -> Nullable<Integer>,

View file

@ -72,11 +72,7 @@ mod slide_model {
}
}
#[cxx_qt::qobject(
base = "QAbstractListModel",
// qml_uri = "com.kdab.cxx_qt.demo",
// qml_version = "1.0"
)]
#[cxx_qt::qobject(base = "QAbstractListModel")]
#[derive(Default, Debug)]
pub struct SlideyMod {
id: i32,

View file

@ -32,7 +32,6 @@ mod song_model {
#[derive(Default, Clone, Debug)]
pub struct Song {
id: i32,
title: QString,
title: String,
lyrics: String,
author: String,
@ -105,16 +104,26 @@ mod song_model {
for song in results {
println!("{}", song.title);
println!("{}", song.id);
println!("{}", song.path);
println!("{}", song.background.clone().unwrap_or_default());
println!("--------------");
if self.as_mut().highest_id() < &song.id {
self.as_mut().set_highest_id(song.id);
}
let img = self::Song {
let img = Song {
id: song.id,
title: QString::from(&song.title),
path: QString::from(&song.path),
title: song.title,
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);
@ -171,50 +180,50 @@ mod song_model {
let song_title = QString::from(name);
let song_path = url.to_qstring();
if self.as_mut().add_item(song_id, song_title, song_path) {
println!("filename: {:?}", name);
self.as_mut().set_highest_id(song_id);
} else {
println!("Error in inserting item");
}
// if self.as_mut().add_item(song_id, song_title, song_path) {
// println!("filename: {:?}", name);
// self.as_mut().set_highest_id(song_id);
// } else {
// println!("Error in inserting item");
// }
}
fn add_item(
mut self: Pin<&mut Self>,
song_id: i32,
song_title: QString,
song_path: QString,
) -> bool {
let db = &mut self.as_mut().get_db();
// println!("{:?}", db);
let song = self::Song {
id: song_id,
title: song_title.clone(),
path: song_path.clone(),
};
println!("{:?}", song);
// fn add_item(
// mut self: Pin<&mut Self>,
// song_id: i32,
// song_title: QString,
// song_path: QString,
// ) -> bool {
// let db = &mut self.as_mut().get_db();
// // println!("{:?}", db);
// let song = self::Song {
// id: song_id,
// title: song_title.clone(),
// path: song_path.clone(),
// };
// println!("{:?}", song);
let result = insert_into(songs)
.values((
id.eq(&song_id),
title.eq(&song_title.to_string()),
path.eq(&song_path.to_string()),
))
.execute(db);
println!("{:?}", result);
// let result = insert_into(songs)
// .values((
// id.eq(&song_id),
// title.eq(&song_title.to_string()),
// path.eq(&song_path.to_string()),
// ))
// .execute(db);
// println!("{:?}", result);
match result {
Ok(_i) => {
self.as_mut().add_song(song);
println!("{:?}", self.as_mut().songs());
true
}
Err(_e) => {
println!("Cannot connect to database");
false
}
}
}
// match result {
// Ok(_i) => {
// self.as_mut().add_song(song);
// println!("{:?}", self.as_mut().songs());
// true
// }
// Err(_e) => {
// println!("Cannot connect to database");
// false
// }
// }
// }
fn add_song(mut self: Pin<&mut Self>, song: self::Song) {
let index = self.as_ref().songs().len() as i32;
@ -240,7 +249,7 @@ mod song_model {
match result {
Ok(_i) => {
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()
.emit_data_changed(model_index, model_index, &vector_roles);
true
@ -253,20 +262,20 @@ mod song_model {
pub fn update_file_path(
mut self: Pin<&mut Self>,
index: i32,
updated_file_path: QString,
updated_background: QString,
) -> bool {
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 db = &mut self.as_mut().get_db();
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);
match result {
Ok(_i) => {
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()
.emit_data_changed(model_index, model_index, &vector_roles);
true
@ -296,6 +305,20 @@ mod song_model {
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 {
match role {
Role::IdRole => 0,
@ -359,17 +382,17 @@ mod song_model {
if let Some(song) = self.songs().get(index.row() as usize) {
return match role {
0 => QVariant::from(&song.id),
1 => QVariant::from(&song.title),
2 => QVariant::from(&song.lyrics),
3 => QVariant::from(&song.author),
4 => QVariant::from(&song.ccli),
5 => QVariant::from(&song.audio),
6 => QVariant::from(&song.verse_order),
7 => QVariant::from(&song.background),
8 => QVariant::from(&song.background_type),
9 => QVariant::from(&song.horizontal_text_alignment),
10 => QVariant::from(&song.vertical_text_alignment),
11 => QVariant::from(&song.font),
1 => QVariant::from(&QString::from(&song.title)),
2 => QVariant::from(&QString::from(&song.lyrics)),
3 => QVariant::from(&QString::from(&song.author)),
4 => QVariant::from(&QString::from(&song.ccli)),
5 => QVariant::from(&QString::from(&song.audio)),
6 => QVariant::from(&QString::from(&song.verse_order)),
7 => QVariant::from(&QString::from(&song.background)),
8 => QVariant::from(&QString::from(&song.background_type)),
9 => QVariant::from(&QString::from(&song.horizontal_text_alignment)),
10 => QVariant::from(&QString::from(&song.vertical_text_alignment)),
11 => QVariant::from(&QString::from(&song.font)),
12 => QVariant::from(&song.font_size),
_ => QVariant::default(),
};