making sure sql models are in lumina folder
This commit is contained in:
parent
d65243a106
commit
4499d1a957
4 changed files with 732 additions and 238 deletions
|
@ -10,9 +10,11 @@ mod image_model {
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!(< QAbstractListModel >);
|
include!(< QAbstractListModel >);
|
||||||
include!("cxx-qt-lib/qhash.h");
|
include!("cxx-qt-lib/qhash.h");
|
||||||
type QHash_i32_QByteArray = cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
|
type QHash_i32_QByteArray =
|
||||||
|
cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
|
||||||
include!("cxx-qt-lib/qmap.h");
|
include!("cxx-qt-lib/qmap.h");
|
||||||
type QMap_QString_QVariant = cxx_qt_lib::QMap<cxx_qt_lib::QMapPair_QString_QVariant>;
|
type QMap_QString_QVariant =
|
||||||
|
cxx_qt_lib::QMap<cxx_qt_lib::QMapPair_QString_QVariant>;
|
||||||
include!("cxx-qt-lib/qvariant.h");
|
include!("cxx-qt-lib/qvariant.h");
|
||||||
type QVariant = cxx_qt_lib::QVariant;
|
type QVariant = cxx_qt_lib::QVariant;
|
||||||
include!("cxx-qt-lib/qstring.h");
|
include!("cxx-qt-lib/qstring.h");
|
||||||
|
@ -106,22 +108,32 @@ mod image_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
|
pub fn remove_item(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
) -> bool {
|
||||||
if index < 0 || (index as usize) >= self.images().len() {
|
if index < 0 || (index as usize) >= self.images().len() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let db = &mut self.as_mut().get_db();
|
let db = &mut self.as_mut().get_db();
|
||||||
|
|
||||||
let image_id = self.images().get(index as usize).unwrap().id;
|
let image_id =
|
||||||
|
self.images().get(index as usize).unwrap().id;
|
||||||
|
|
||||||
let result = delete(images.filter(id.eq(image_id))).execute(db);
|
let result =
|
||||||
|
delete(images.filter(id.eq(image_id))).execute(db);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
self.as_mut().begin_remove_rows(
|
||||||
|
&QModelIndex::default(),
|
||||||
|
index,
|
||||||
|
index,
|
||||||
|
);
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
.begin_remove_rows(&QModelIndex::default(), index, index);
|
.images_mut()
|
||||||
self.as_mut().images_mut().remove(index as usize);
|
.remove(index as usize);
|
||||||
self.as_mut().end_remove_rows();
|
self.as_mut().end_remove_rows();
|
||||||
}
|
}
|
||||||
println!("removed-item-at-index: {:?}", image_id);
|
println!("removed-item-at-index: {:?}", image_id);
|
||||||
|
@ -137,26 +149,32 @@ mod image_model {
|
||||||
|
|
||||||
fn get_db(self: Pin<&mut Self>) -> SqliteConnection {
|
fn get_db(self: Pin<&mut Self>) -> SqliteConnection {
|
||||||
let mut data = dirs::data_local_dir().unwrap();
|
let mut data = dirs::data_local_dir().unwrap();
|
||||||
data.push("librepresenter");
|
data.push("lumina");
|
||||||
data.push("library-db.sqlite3");
|
data.push("library-db.sqlite3");
|
||||||
let mut db_url = String::from("sqlite://");
|
let mut db_url = String::from("sqlite://");
|
||||||
db_url.push_str(data.to_str().unwrap());
|
db_url.push_str(data.to_str().unwrap());
|
||||||
println!("DB: {:?}", db_url);
|
println!("DB: {:?}", db_url);
|
||||||
|
|
||||||
SqliteConnection::establish(&db_url)
|
SqliteConnection::establish(&db_url).unwrap_or_else(
|
||||||
.unwrap_or_else(|_| panic!("error connecting to {}", db_url))
|
|_| panic!("error connecting to {}", db_url),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn new_item(mut self: Pin<&mut Self>, url: QUrl) {
|
pub fn new_item(mut self: Pin<&mut Self>, url: QUrl) {
|
||||||
println!("LETS INSERT THIS SUCKER!");
|
println!("LETS INSERT THIS SUCKER!");
|
||||||
let file_path = PathBuf::from(url.path().to_string());
|
let file_path = PathBuf::from(url.path().to_string());
|
||||||
let name = file_path.file_stem().unwrap().to_str().unwrap();
|
let name =
|
||||||
|
file_path.file_stem().unwrap().to_str().unwrap();
|
||||||
let image_id = self.rust().highest_id + 1;
|
let image_id = self.rust().highest_id + 1;
|
||||||
let image_title = QString::from(name);
|
let image_title = QString::from(name);
|
||||||
let image_path = url.to_qstring();
|
let image_path = url.to_qstring();
|
||||||
|
|
||||||
if self.as_mut().add_item(image_id, image_title, image_path) {
|
if self.as_mut().add_item(
|
||||||
|
image_id,
|
||||||
|
image_title,
|
||||||
|
image_path,
|
||||||
|
) {
|
||||||
println!("filename: {:?}", name);
|
println!("filename: {:?}", name);
|
||||||
self.as_mut().set_highest_id(image_id);
|
self.as_mut().set_highest_id(image_id);
|
||||||
} else {
|
} else {
|
||||||
|
@ -205,18 +223,30 @@ mod image_model {
|
||||||
let index = self.as_ref().images().len() as i32;
|
let index = self.as_ref().images().len() as i32;
|
||||||
println!("{:?}", image);
|
println!("{:?}", image);
|
||||||
unsafe {
|
unsafe {
|
||||||
self.as_mut()
|
self.as_mut().begin_insert_rows(
|
||||||
.begin_insert_rows(&QModelIndex::default(), index, index);
|
&QModelIndex::default(),
|
||||||
|
index,
|
||||||
|
index,
|
||||||
|
);
|
||||||
self.as_mut().images_mut().push(image);
|
self.as_mut().images_mut().push(image);
|
||||||
self.as_mut().end_insert_rows();
|
self.as_mut().end_insert_rows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn update_title(mut self: Pin<&mut Self>, index: i32, updated_title: QString) -> bool {
|
pub fn update_title(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
updated_title: QString,
|
||||||
|
) -> bool {
|
||||||
let mut vector_roles = QVector_i32::default();
|
let mut vector_roles = QVector_i32::default();
|
||||||
vector_roles.append(self.as_ref().get_role(Role::TitleRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::TitleRole));
|
||||||
|
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(images.filter(id.eq(index)))
|
let result = update(images.filter(id.eq(index)))
|
||||||
|
@ -233,8 +263,11 @@ mod image_model {
|
||||||
image.title = updated_title.clone();
|
image.title = updated_title.clone();
|
||||||
println!("rust-title: {:?}", image.title);
|
println!("rust-title: {:?}", image.title);
|
||||||
}
|
}
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(_e) => false,
|
||||||
|
@ -248,8 +281,13 @@ mod image_model {
|
||||||
updated_file_path: QString,
|
updated_file_path: 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
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::PathRole));
|
||||||
|
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(images.filter(id.eq(index)))
|
let result = update(images.filter(id.eq(index)))
|
||||||
|
@ -266,8 +304,11 @@ mod image_model {
|
||||||
image.path = updated_file_path.clone();
|
image.path = updated_file_path.clone();
|
||||||
println!("rust-title: {:?}", image.path);
|
println!("rust-title: {:?}", image.path);
|
||||||
}
|
}
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(_e) => false,
|
||||||
|
@ -275,7 +316,10 @@ mod image_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn get_item(self: Pin<&mut Self>, index: i32) -> QMap_QString_QVariant {
|
pub fn get_item(
|
||||||
|
self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
) -> QMap_QString_QVariant {
|
||||||
println!("{index}");
|
println!("{index}");
|
||||||
let mut qvariantmap = QMap_QString_QVariant::default();
|
let mut qvariantmap = QMap_QString_QVariant::default();
|
||||||
let idx = self.index(index, 0, &QModelIndex::default());
|
let idx = self.index(index, 0, &QModelIndex::default());
|
||||||
|
@ -284,7 +328,9 @@ mod image_model {
|
||||||
}
|
}
|
||||||
let role_names = self.as_ref().role_names();
|
let role_names = self.as_ref().role_names();
|
||||||
let role_names_iter = role_names.iter();
|
let role_names_iter = role_names.iter();
|
||||||
if let Some(image) = self.rust().images.get(index as usize) {
|
if let Some(image) =
|
||||||
|
self.rust().images.get(index as usize)
|
||||||
|
{
|
||||||
for i in role_names_iter {
|
for i in role_names_iter {
|
||||||
qvariantmap.insert(
|
qvariantmap.insert(
|
||||||
QString::from(&i.1.to_string()),
|
QString::from(&i.1.to_string()),
|
||||||
|
@ -314,7 +360,9 @@ mod image_model {
|
||||||
first: i32,
|
first: i32,
|
||||||
last: i32,
|
last: i32,
|
||||||
);
|
);
|
||||||
unsafe fn end_insert_rows(self: Pin<&mut qobject::ImageModel>);
|
unsafe fn end_insert_rows(
|
||||||
|
self: Pin<&mut qobject::ImageModel>,
|
||||||
|
);
|
||||||
|
|
||||||
unsafe fn begin_remove_rows(
|
unsafe fn begin_remove_rows(
|
||||||
self: Pin<&mut qobject::ImageModel>,
|
self: Pin<&mut qobject::ImageModel>,
|
||||||
|
@ -322,16 +370,25 @@ mod image_model {
|
||||||
first: i32,
|
first: i32,
|
||||||
last: i32,
|
last: i32,
|
||||||
);
|
);
|
||||||
unsafe fn end_remove_rows(self: Pin<&mut qobject::ImageModel>);
|
unsafe fn end_remove_rows(
|
||||||
|
self: Pin<&mut qobject::ImageModel>,
|
||||||
|
);
|
||||||
|
|
||||||
unsafe fn begin_reset_model(self: Pin<&mut qobject::ImageModel>);
|
unsafe fn begin_reset_model(
|
||||||
unsafe fn end_reset_model(self: Pin<&mut qobject::ImageModel>);
|
self: Pin<&mut qobject::ImageModel>,
|
||||||
|
);
|
||||||
|
unsafe fn end_reset_model(
|
||||||
|
self: Pin<&mut qobject::ImageModel>,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cxx_qt::inherit]
|
#[cxx_qt::inherit]
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
#[cxx_name = "canFetchMore"]
|
#[cxx_name = "canFetchMore"]
|
||||||
fn base_can_fetch_more(self: &qobject::ImageModel, parent: &QModelIndex) -> bool;
|
fn base_can_fetch_more(
|
||||||
|
self: &qobject::ImageModel,
|
||||||
|
parent: &QModelIndex,
|
||||||
|
) -> bool;
|
||||||
|
|
||||||
fn index(
|
fn index(
|
||||||
self: &qobject::ImageModel,
|
self: &qobject::ImageModel,
|
||||||
|
@ -345,7 +402,9 @@ mod image_model {
|
||||||
impl qobject::ImageModel {
|
impl qobject::ImageModel {
|
||||||
#[qinvokable(cxx_override)]
|
#[qinvokable(cxx_override)]
|
||||||
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
||||||
if let Some(image) = self.images().get(index.row() as usize) {
|
if let Some(image) =
|
||||||
|
self.images().get(index.row() as usize)
|
||||||
|
{
|
||||||
return match role {
|
return match role {
|
||||||
0 => QVariant::from(&image.id),
|
0 => QVariant::from(&image.id),
|
||||||
1 => QVariant::from(&image.title),
|
1 => QVariant::from(&image.title),
|
||||||
|
|
|
@ -12,9 +12,11 @@ mod presentation_model {
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!(< QAbstractListModel >);
|
include!(< QAbstractListModel >);
|
||||||
include!("cxx-qt-lib/qhash.h");
|
include!("cxx-qt-lib/qhash.h");
|
||||||
type QHash_i32_QByteArray = cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
|
type QHash_i32_QByteArray =
|
||||||
|
cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
|
||||||
include!("cxx-qt-lib/qmap.h");
|
include!("cxx-qt-lib/qmap.h");
|
||||||
type QMap_QString_QVariant = cxx_qt_lib::QMap<cxx_qt_lib::QMapPair_QString_QVariant>;
|
type QMap_QString_QVariant =
|
||||||
|
cxx_qt_lib::QMap<cxx_qt_lib::QMapPair_QString_QVariant>;
|
||||||
include!("cxx-qt-lib/qvariant.h");
|
include!("cxx-qt-lib/qvariant.h");
|
||||||
type QVariant = cxx_qt_lib::QVariant;
|
type QVariant = cxx_qt_lib::QVariant;
|
||||||
include!("cxx-qt-lib/qstring.h");
|
include!("cxx-qt-lib/qstring.h");
|
||||||
|
@ -115,26 +117,45 @@ mod presentation_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
|
pub fn remove_item(
|
||||||
if index < 0 || (index as usize) >= self.presentations().len() {
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
) -> bool {
|
||||||
|
if index < 0
|
||||||
|
|| (index as usize) >= self.presentations().len()
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let db = &mut self.as_mut().get_db();
|
let db = &mut self.as_mut().get_db();
|
||||||
|
|
||||||
let presentation_id = self.presentations().get(index as usize).unwrap().id;
|
let presentation_id =
|
||||||
|
self.presentations().get(index as usize).unwrap().id;
|
||||||
|
|
||||||
let result = delete(presentations.filter(id.eq(presentation_id))).execute(db);
|
let result =
|
||||||
|
delete(presentations.filter(id.eq(presentation_id)))
|
||||||
|
.execute(db);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
self.as_mut().begin_remove_rows(
|
||||||
|
&QModelIndex::default(),
|
||||||
|
index,
|
||||||
|
index,
|
||||||
|
);
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
.begin_remove_rows(&QModelIndex::default(), index, index);
|
.presentations_mut()
|
||||||
self.as_mut().presentations_mut().remove(index as usize);
|
.remove(index as usize);
|
||||||
self.as_mut().end_remove_rows();
|
self.as_mut().end_remove_rows();
|
||||||
}
|
}
|
||||||
println!("removed-item-at-index: {:?}", presentation_id);
|
println!(
|
||||||
println!("new-Vec: {:?}", self.as_mut().presentations());
|
"removed-item-at-index: {:?}",
|
||||||
|
presentation_id
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"new-Vec: {:?}",
|
||||||
|
self.as_mut().presentations()
|
||||||
|
);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
|
@ -146,26 +167,33 @@ mod presentation_model {
|
||||||
|
|
||||||
fn get_db(self: Pin<&mut Self>) -> SqliteConnection {
|
fn get_db(self: Pin<&mut Self>) -> SqliteConnection {
|
||||||
let mut data = dirs::data_local_dir().unwrap();
|
let mut data = dirs::data_local_dir().unwrap();
|
||||||
data.push("librepresenter");
|
data.push("lumina");
|
||||||
data.push("library-db.sqlite3");
|
data.push("library-db.sqlite3");
|
||||||
let mut db_url = String::from("sqlite://");
|
let mut db_url = String::from("sqlite://");
|
||||||
db_url.push_str(data.to_str().unwrap());
|
db_url.push_str(data.to_str().unwrap());
|
||||||
println!("DB: {:?}", db_url);
|
println!("DB: {:?}", db_url);
|
||||||
|
|
||||||
SqliteConnection::establish(&db_url)
|
SqliteConnection::establish(&db_url).unwrap_or_else(
|
||||||
.unwrap_or_else(|_| panic!("error connecting to {}", db_url))
|
|_| panic!("error connecting to {}", db_url),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn new_item(mut self: Pin<&mut Self>, url: QUrl, new_page_count: i32) {
|
pub fn new_item(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
url: QUrl,
|
||||||
|
new_page_count: i32,
|
||||||
|
) {
|
||||||
println!("LETS INSERT THIS SUCKER!");
|
println!("LETS INSERT THIS SUCKER!");
|
||||||
let file_path = PathBuf::from(url.path().to_string());
|
let file_path = PathBuf::from(url.path().to_string());
|
||||||
let name = file_path.file_stem().unwrap().to_str().unwrap();
|
let name =
|
||||||
|
file_path.file_stem().unwrap().to_str().unwrap();
|
||||||
let presentation_id = self.rust().highest_id + 1;
|
let presentation_id = self.rust().highest_id + 1;
|
||||||
let presentation_title = QString::from(name);
|
let presentation_title = QString::from(name);
|
||||||
let presentation_path = url.to_qstring();
|
let presentation_path = url.to_qstring();
|
||||||
println!("{:?}", file_path.extension().unwrap());
|
println!("{:?}", file_path.extension().unwrap());
|
||||||
let presentation_html = file_path.extension().unwrap() == std::ffi::OsStr::new(".html");
|
let presentation_html = file_path.extension().unwrap()
|
||||||
|
== std::ffi::OsStr::new(".html");
|
||||||
|
|
||||||
if self.as_mut().add_item(
|
if self.as_mut().add_item(
|
||||||
presentation_id,
|
presentation_id,
|
||||||
|
@ -194,8 +222,12 @@ mod presentation_model {
|
||||||
// println!("{:?}", db);
|
// println!("{:?}", db);
|
||||||
let mut actual_page_count = new_page_count;
|
let mut actual_page_count = new_page_count;
|
||||||
if presentation_html {
|
if presentation_html {
|
||||||
let actual_path = presentation_path.clone().to_string();
|
let actual_path =
|
||||||
actual_page_count = reveal_js::count_slides_and_fragments(actual_path.trim());
|
presentation_path.clone().to_string();
|
||||||
|
actual_page_count =
|
||||||
|
reveal_js::count_slides_and_fragments(
|
||||||
|
actual_path.trim(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let presentation = self::Presentation {
|
let presentation = self::Presentation {
|
||||||
|
@ -231,19 +263,28 @@ mod presentation_model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_presentation(mut self: Pin<&mut Self>, presentation: self::Presentation) {
|
fn add_presentation(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
presentation: self::Presentation,
|
||||||
|
) {
|
||||||
let index = self.as_ref().presentations().len() as i32;
|
let index = self.as_ref().presentations().len() as i32;
|
||||||
println!("{:?}", presentation);
|
println!("{:?}", presentation);
|
||||||
unsafe {
|
unsafe {
|
||||||
self.as_mut()
|
self.as_mut().begin_insert_rows(
|
||||||
.begin_insert_rows(&QModelIndex::default(), index, index);
|
&QModelIndex::default(),
|
||||||
|
index,
|
||||||
|
index,
|
||||||
|
);
|
||||||
self.as_mut().presentations_mut().push(presentation);
|
self.as_mut().presentations_mut().push(presentation);
|
||||||
self.as_mut().end_insert_rows();
|
self.as_mut().end_insert_rows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn get_item(self: Pin<&mut Self>, index: i32) -> QMap_QString_QVariant {
|
pub fn get_item(
|
||||||
|
self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
) -> QMap_QString_QVariant {
|
||||||
println!("{index}");
|
println!("{index}");
|
||||||
let mut qvariantmap = QMap_QString_QVariant::default();
|
let mut qvariantmap = QMap_QString_QVariant::default();
|
||||||
let idx = self.index(index, 0, &QModelIndex::default());
|
let idx = self.index(index, 0, &QModelIndex::default());
|
||||||
|
@ -252,7 +293,9 @@ mod presentation_model {
|
||||||
}
|
}
|
||||||
let role_names = self.as_ref().role_names();
|
let role_names = self.as_ref().role_names();
|
||||||
let role_names_iter = role_names.iter();
|
let role_names_iter = role_names.iter();
|
||||||
if let Some(presentation) = self.rust().presentations.get(index as usize) {
|
if let Some(presentation) =
|
||||||
|
self.rust().presentations.get(index as usize)
|
||||||
|
{
|
||||||
for i in role_names_iter {
|
for i in role_names_iter {
|
||||||
qvariantmap.insert(
|
qvariantmap.insert(
|
||||||
QString::from(&i.1.to_string()),
|
QString::from(&i.1.to_string()),
|
||||||
|
@ -264,10 +307,19 @@ mod presentation_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn update_title(mut self: Pin<&mut Self>, index: i32, updated_title: QString) -> bool {
|
pub fn update_title(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
updated_title: QString,
|
||||||
|
) -> bool {
|
||||||
let mut vector_roles = QVector_i32::default();
|
let mut vector_roles = QVector_i32::default();
|
||||||
vector_roles.append(self.as_ref().get_role(Role::TitleRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::TitleRole));
|
||||||
|
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(presentations.filter(id.eq(index)))
|
let result = update(presentations.filter(id.eq(index)))
|
||||||
|
@ -281,12 +333,19 @@ mod presentation_model {
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.filter(|x| x.id == index)
|
.filter(|x| x.id == index)
|
||||||
{
|
{
|
||||||
presentation.title = updated_title.to_string();
|
presentation.title =
|
||||||
println!("rust-title: {:?}", presentation.title);
|
updated_title.to_string();
|
||||||
|
println!(
|
||||||
|
"rust-title: {:?}",
|
||||||
|
presentation.title
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// TODO this seems to not be updating in the actual list
|
// TODO this seems to not be updating in the actual list
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
// self.as_mut().emit_title_changed();
|
// self.as_mut().emit_title_changed();
|
||||||
println!("rust-title: {:?}", updated_title);
|
println!("rust-title: {:?}", updated_title);
|
||||||
true
|
true
|
||||||
|
@ -302,8 +361,13 @@ mod presentation_model {
|
||||||
updated_page_count: i32,
|
updated_page_count: i32,
|
||||||
) -> 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::PageCountRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::PageCountRole));
|
||||||
|
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(presentations.filter(id.eq(index)))
|
let result = update(presentations.filter(id.eq(index)))
|
||||||
|
@ -318,13 +382,22 @@ mod presentation_model {
|
||||||
.filter(|x| x.id == index)
|
.filter(|x| x.id == index)
|
||||||
{
|
{
|
||||||
presentation.page_count = updated_page_count;
|
presentation.page_count = updated_page_count;
|
||||||
println!("rust-page_count: {:?}", presentation.page_count);
|
println!(
|
||||||
|
"rust-page_count: {:?}",
|
||||||
|
presentation.page_count
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// TODO this seems to not be updating in the actual list
|
// TODO this seems to not be updating in the actual list
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
// self.as_mut().emit_page_count_changed();
|
// self.as_mut().emit_page_count_changed();
|
||||||
println!("rust-page_count: {:?}", updated_page_count);
|
println!(
|
||||||
|
"rust-page_count: {:?}",
|
||||||
|
updated_page_count
|
||||||
|
);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(_e) => false,
|
||||||
|
@ -352,7 +425,9 @@ mod presentation_model {
|
||||||
first: i32,
|
first: i32,
|
||||||
last: i32,
|
last: i32,
|
||||||
);
|
);
|
||||||
unsafe fn end_insert_rows(self: Pin<&mut qobject::PresentationModel>);
|
unsafe fn end_insert_rows(
|
||||||
|
self: Pin<&mut qobject::PresentationModel>,
|
||||||
|
);
|
||||||
|
|
||||||
unsafe fn begin_remove_rows(
|
unsafe fn begin_remove_rows(
|
||||||
self: Pin<&mut qobject::PresentationModel>,
|
self: Pin<&mut qobject::PresentationModel>,
|
||||||
|
@ -360,16 +435,25 @@ mod presentation_model {
|
||||||
first: i32,
|
first: i32,
|
||||||
last: i32,
|
last: i32,
|
||||||
);
|
);
|
||||||
unsafe fn end_remove_rows(self: Pin<&mut qobject::PresentationModel>);
|
unsafe fn end_remove_rows(
|
||||||
|
self: Pin<&mut qobject::PresentationModel>,
|
||||||
|
);
|
||||||
|
|
||||||
unsafe fn begin_reset_model(self: Pin<&mut qobject::PresentationModel>);
|
unsafe fn begin_reset_model(
|
||||||
unsafe fn end_reset_model(self: Pin<&mut qobject::PresentationModel>);
|
self: Pin<&mut qobject::PresentationModel>,
|
||||||
|
);
|
||||||
|
unsafe fn end_reset_model(
|
||||||
|
self: Pin<&mut qobject::PresentationModel>,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cxx_qt::inherit]
|
#[cxx_qt::inherit]
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
#[cxx_name = "canFetchMore"]
|
#[cxx_name = "canFetchMore"]
|
||||||
fn base_can_fetch_more(self: &qobject::PresentationModel, parent: &QModelIndex) -> bool;
|
fn base_can_fetch_more(
|
||||||
|
self: &qobject::PresentationModel,
|
||||||
|
parent: &QModelIndex,
|
||||||
|
) -> bool;
|
||||||
|
|
||||||
fn index(
|
fn index(
|
||||||
self: &qobject::PresentationModel,
|
self: &qobject::PresentationModel,
|
||||||
|
@ -383,11 +467,17 @@ mod presentation_model {
|
||||||
impl qobject::PresentationModel {
|
impl qobject::PresentationModel {
|
||||||
#[qinvokable(cxx_override)]
|
#[qinvokable(cxx_override)]
|
||||||
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
||||||
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(&QString::from(&presentation.title)),
|
1 => QVariant::from(&QString::from(
|
||||||
2 => QVariant::from(&QString::from(&presentation.path)),
|
&presentation.title,
|
||||||
|
)),
|
||||||
|
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(),
|
||||||
|
@ -410,7 +500,8 @@ mod presentation_model {
|
||||||
roles.insert(1, cxx_qt_lib::QByteArray::from("title"));
|
roles.insert(1, cxx_qt_lib::QByteArray::from("title"));
|
||||||
roles.insert(2, cxx_qt_lib::QByteArray::from("filePath"));
|
roles.insert(2, cxx_qt_lib::QByteArray::from("filePath"));
|
||||||
roles.insert(3, cxx_qt_lib::QByteArray::from("html"));
|
roles.insert(3, cxx_qt_lib::QByteArray::from("html"));
|
||||||
roles.insert(4, cxx_qt_lib::QByteArray::from("pageCount"));
|
roles
|
||||||
|
.insert(4, cxx_qt_lib::QByteArray::from("pageCount"));
|
||||||
roles
|
roles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,11 @@ mod song_model {
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!(< QAbstractListModel >);
|
include!(< QAbstractListModel >);
|
||||||
include!("cxx-qt-lib/qhash.h");
|
include!("cxx-qt-lib/qhash.h");
|
||||||
type QHash_i32_QByteArray = cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
|
type QHash_i32_QByteArray =
|
||||||
|
cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
|
||||||
include!("cxx-qt-lib/qmap.h");
|
include!("cxx-qt-lib/qmap.h");
|
||||||
type QMap_QString_QVariant = cxx_qt_lib::QMap<cxx_qt_lib::QMapPair_QString_QVariant>;
|
type QMap_QString_QVariant =
|
||||||
|
cxx_qt_lib::QMap<cxx_qt_lib::QMapPair_QString_QVariant>;
|
||||||
include!("cxx-qt-lib/qvariant.h");
|
include!("cxx-qt-lib/qvariant.h");
|
||||||
type QVariant = cxx_qt_lib::QVariant;
|
type QVariant = cxx_qt_lib::QVariant;
|
||||||
include!("cxx-qt-lib/qstring.h");
|
include!("cxx-qt-lib/qstring.h");
|
||||||
|
@ -107,7 +109,10 @@ 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.background.clone().unwrap_or_default());
|
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);
|
||||||
|
@ -122,9 +127,15 @@ mod song_model {
|
||||||
audio: song.audio.unwrap_or_default(),
|
audio: song.audio.unwrap_or_default(),
|
||||||
verse_order: song.verse_order.unwrap_or_default(),
|
verse_order: song.verse_order.unwrap_or_default(),
|
||||||
background: song.background.unwrap_or_default(),
|
background: song.background.unwrap_or_default(),
|
||||||
background_type: song.background_type.unwrap_or_default(),
|
background_type: song
|
||||||
horizontal_text_alignment: song.horizontal_text_alignment.unwrap_or_default(),
|
.background_type
|
||||||
vertical_text_alignment: song.vertical_text_alignment.unwrap_or_default(),
|
.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: song.font.unwrap_or_default(),
|
||||||
font_size: song.font_size.unwrap_or_default(),
|
font_size: song.font_size.unwrap_or_default(),
|
||||||
};
|
};
|
||||||
|
@ -137,22 +148,32 @@ mod song_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
|
pub fn remove_item(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
) -> bool {
|
||||||
if index < 0 || (index as usize) >= self.songs().len() {
|
if index < 0 || (index as usize) >= self.songs().len() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let db = &mut self.as_mut().get_db();
|
let db = &mut self.as_mut().get_db();
|
||||||
|
|
||||||
let song_id = self.songs().get(index as usize).unwrap().id;
|
let song_id =
|
||||||
|
self.songs().get(index as usize).unwrap().id;
|
||||||
|
|
||||||
let result = delete(songs.filter(id.eq(song_id))).execute(db);
|
let result =
|
||||||
|
delete(songs.filter(id.eq(song_id))).execute(db);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
self.as_mut().begin_remove_rows(
|
||||||
|
&QModelIndex::default(),
|
||||||
|
index,
|
||||||
|
index,
|
||||||
|
);
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
.begin_remove_rows(&QModelIndex::default(), index, index);
|
.songs_mut()
|
||||||
self.as_mut().songs_mut().remove(index as usize);
|
.remove(index as usize);
|
||||||
self.as_mut().end_remove_rows();
|
self.as_mut().end_remove_rows();
|
||||||
}
|
}
|
||||||
println!("removed-item-at-index: {:?}", song_id);
|
println!("removed-item-at-index: {:?}", song_id);
|
||||||
|
@ -168,14 +189,15 @@ mod song_model {
|
||||||
|
|
||||||
fn get_db(self: Pin<&mut Self>) -> SqliteConnection {
|
fn get_db(self: Pin<&mut Self>) -> SqliteConnection {
|
||||||
let mut data = dirs::data_local_dir().unwrap();
|
let mut data = dirs::data_local_dir().unwrap();
|
||||||
data.push("librepresenter");
|
data.push("lumina");
|
||||||
data.push("library-db.sqlite3");
|
data.push("library-db.sqlite3");
|
||||||
let mut db_url = String::from("sqlite://");
|
let mut db_url = String::from("sqlite://");
|
||||||
db_url.push_str(data.to_str().unwrap());
|
db_url.push_str(data.to_str().unwrap());
|
||||||
println!("DB: {:?}", db_url);
|
println!("DB: {:?}", db_url);
|
||||||
|
|
||||||
SqliteConnection::establish(&db_url)
|
SqliteConnection::establish(&db_url).unwrap_or_else(
|
||||||
.unwrap_or_else(|_| panic!("error connecting to {}", db_url))
|
|_| panic!("error connecting to {}", db_url),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
|
@ -201,8 +223,10 @@ mod song_model {
|
||||||
verse_order.eq(&song.verse_order),
|
verse_order.eq(&song.verse_order),
|
||||||
background.eq(&song.background),
|
background.eq(&song.background),
|
||||||
background_type.eq(&song.background_type),
|
background_type.eq(&song.background_type),
|
||||||
horizontal_text_alignment.eq(&song.horizontal_text_alignment),
|
horizontal_text_alignment
|
||||||
vertical_text_alignment.eq(&song.vertical_text_alignment),
|
.eq(&song.horizontal_text_alignment),
|
||||||
|
vertical_text_alignment
|
||||||
|
.eq(&song.vertical_text_alignment),
|
||||||
font.eq(&song.font),
|
font.eq(&song.font),
|
||||||
font_size.eq(&song.font_size),
|
font_size.eq(&song.font_size),
|
||||||
))
|
))
|
||||||
|
@ -226,18 +250,30 @@ mod song_model {
|
||||||
let index = self.as_ref().songs().len() as i32;
|
let index = self.as_ref().songs().len() as i32;
|
||||||
println!("{:?}", song);
|
println!("{:?}", song);
|
||||||
unsafe {
|
unsafe {
|
||||||
self.as_mut()
|
self.as_mut().begin_insert_rows(
|
||||||
.begin_insert_rows(&QModelIndex::default(), index, index);
|
&QModelIndex::default(),
|
||||||
|
index,
|
||||||
|
index,
|
||||||
|
);
|
||||||
self.as_mut().songs_mut().push(song);
|
self.as_mut().songs_mut().push(song);
|
||||||
self.as_mut().end_insert_rows();
|
self.as_mut().end_insert_rows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn update_title(mut self: Pin<&mut Self>, index: i32, updated_title: QString) -> bool {
|
pub fn update_title(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
updated_title: QString,
|
||||||
|
) -> bool {
|
||||||
let mut vector_roles = QVector_i32::default();
|
let mut vector_roles = QVector_i32::default();
|
||||||
vector_roles.append(self.as_ref().get_role(Role::TitleRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::TitleRole));
|
||||||
|
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)))
|
||||||
|
@ -245,7 +281,11 @@ mod song_model {
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
|
.as_mut()
|
||||||
|
.songs_mut()
|
||||||
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
song.title = updated_title.to_string();
|
song.title = updated_title.to_string();
|
||||||
self.as_mut().emit(Signals::DataChanged {
|
self.as_mut().emit(Signals::DataChanged {
|
||||||
top_left: &model_index,
|
top_left: &model_index,
|
||||||
|
@ -269,8 +309,13 @@ mod song_model {
|
||||||
updated_lyrics: QString,
|
updated_lyrics: 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::LyricsRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::LyricsRole));
|
||||||
|
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)))
|
||||||
|
@ -278,10 +323,17 @@ mod song_model {
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
|
.as_mut()
|
||||||
|
.songs_mut()
|
||||||
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
song.lyrics = updated_lyrics.to_string();
|
song.lyrics = updated_lyrics.to_string();
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -298,8 +350,13 @@ mod song_model {
|
||||||
updated_author: QString,
|
updated_author: 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::AuthorRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::AuthorRole));
|
||||||
|
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)))
|
||||||
|
@ -307,10 +364,17 @@ mod song_model {
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
|
.as_mut()
|
||||||
|
.songs_mut()
|
||||||
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
song.author = updated_author.to_string();
|
song.author = updated_author.to_string();
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -321,10 +385,19 @@ mod song_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn update_audio(mut self: Pin<&mut Self>, index: i32, updated_audio: QString) -> bool {
|
pub fn update_audio(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
updated_audio: QString,
|
||||||
|
) -> bool {
|
||||||
let mut vector_roles = QVector_i32::default();
|
let mut vector_roles = QVector_i32::default();
|
||||||
vector_roles.append(self.as_ref().get_role(Role::AudioRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::AudioRole));
|
||||||
|
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)))
|
||||||
|
@ -332,10 +405,17 @@ mod song_model {
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
|
.as_mut()
|
||||||
|
.songs_mut()
|
||||||
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
song.audio = updated_audio.to_string();
|
song.audio = updated_audio.to_string();
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -346,10 +426,19 @@ mod song_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn update_ccli(mut self: Pin<&mut Self>, index: i32, updated_ccli: QString) -> bool {
|
pub fn update_ccli(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
updated_ccli: QString,
|
||||||
|
) -> bool {
|
||||||
let mut vector_roles = QVector_i32::default();
|
let mut vector_roles = QVector_i32::default();
|
||||||
vector_roles.append(self.as_ref().get_role(Role::CcliRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::CcliRole));
|
||||||
|
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)))
|
||||||
|
@ -357,10 +446,17 @@ mod song_model {
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
|
.as_mut()
|
||||||
|
.songs_mut()
|
||||||
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
song.ccli = updated_ccli.to_string();
|
song.ccli = updated_ccli.to_string();
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -377,8 +473,13 @@ mod song_model {
|
||||||
updated_verse_order: QString,
|
updated_verse_order: 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::VerseOrderRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::VerseOrderRole));
|
||||||
|
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)))
|
||||||
|
@ -386,10 +487,18 @@ mod song_model {
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
song.verse_order = updated_verse_order.to_string();
|
.as_mut()
|
||||||
self.as_mut()
|
.songs_mut()
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
|
song.verse_order =
|
||||||
|
updated_verse_order.to_string();
|
||||||
|
self.as_mut().emit_data_changed(
|
||||||
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -406,8 +515,13 @@ mod song_model {
|
||||||
updated_background: 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::BackgroundRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.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 db = &mut self.as_mut().get_db();
|
||||||
let result = update(songs.filter(id.eq(index)))
|
let result = update(songs.filter(id.eq(index)))
|
||||||
|
@ -415,10 +529,18 @@ mod song_model {
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
song.background = updated_background.to_string();
|
.as_mut()
|
||||||
self.as_mut()
|
.songs_mut()
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
|
song.background =
|
||||||
|
updated_background.to_string();
|
||||||
|
self.as_mut().emit_data_changed(
|
||||||
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -435,19 +557,36 @@ mod song_model {
|
||||||
updated_background_type: QString,
|
updated_background_type: 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::BackgroundTypeRole));
|
vector_roles.append(
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
self.as_ref().get_role(Role::BackgroundTypeRole),
|
||||||
|
);
|
||||||
|
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(background_type.eq(updated_background_type.to_string()))
|
.set(
|
||||||
|
background_type
|
||||||
|
.eq(updated_background_type.to_string()),
|
||||||
|
)
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
song.background_type = updated_background_type.to_string();
|
.as_mut()
|
||||||
self.as_mut()
|
.songs_mut()
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
|
song.background_type =
|
||||||
|
updated_background_type.to_string();
|
||||||
|
self.as_mut().emit_data_changed(
|
||||||
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -464,20 +603,37 @@ mod song_model {
|
||||||
updated_horizontal_text_alignment: QString,
|
updated_horizontal_text_alignment: 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::HorizontalTextAlignmentRole));
|
vector_roles.append(
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
self.as_ref()
|
||||||
|
.get_role(Role::HorizontalTextAlignmentRole),
|
||||||
|
);
|
||||||
|
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(horizontal_text_alignment.eq(updated_horizontal_text_alignment.to_string()))
|
.set(horizontal_text_alignment.eq(
|
||||||
|
updated_horizontal_text_alignment.to_string(),
|
||||||
|
))
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
|
.as_mut()
|
||||||
|
.songs_mut()
|
||||||
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
song.horizontal_text_alignment =
|
song.horizontal_text_alignment =
|
||||||
updated_horizontal_text_alignment.to_string();
|
updated_horizontal_text_alignment
|
||||||
self.as_mut()
|
.to_string();
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
self.as_mut().emit_data_changed(
|
||||||
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -494,19 +650,38 @@ mod song_model {
|
||||||
updated_vertical_text_alignment: QString,
|
updated_vertical_text_alignment: 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::VerticalTextAlignmentRole));
|
vector_roles.append(
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
self.as_ref()
|
||||||
|
.get_role(Role::VerticalTextAlignmentRole),
|
||||||
|
);
|
||||||
|
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 =
|
||||||
.set(vertical_text_alignment.eq(updated_vertical_text_alignment.to_string()))
|
update(songs.filter(id.eq(index)))
|
||||||
.execute(db);
|
.set(vertical_text_alignment.eq(
|
||||||
|
updated_vertical_text_alignment.to_string(),
|
||||||
|
))
|
||||||
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
song.vertical_text_alignment = updated_vertical_text_alignment.to_string();
|
.as_mut()
|
||||||
self.as_mut()
|
.songs_mut()
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
|
song.vertical_text_alignment =
|
||||||
|
updated_vertical_text_alignment
|
||||||
|
.to_string();
|
||||||
|
self.as_mut().emit_data_changed(
|
||||||
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -517,10 +692,19 @@ mod song_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn update_font(mut self: Pin<&mut Self>, index: i32, updated_font: QString) -> bool {
|
pub fn update_font(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
updated_font: QString,
|
||||||
|
) -> bool {
|
||||||
let mut vector_roles = QVector_i32::default();
|
let mut vector_roles = QVector_i32::default();
|
||||||
vector_roles.append(self.as_ref().get_role(Role::FontRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::FontRole));
|
||||||
|
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)))
|
||||||
|
@ -528,10 +712,17 @@ mod song_model {
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
|
.as_mut()
|
||||||
|
.songs_mut()
|
||||||
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
song.font = updated_font.to_string();
|
song.font = updated_font.to_string();
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -548,8 +739,13 @@ mod song_model {
|
||||||
updated_font_size: i32,
|
updated_font_size: i32,
|
||||||
) -> 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::FontSizeRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::FontSizeRole));
|
||||||
|
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)))
|
||||||
|
@ -557,10 +753,17 @@ mod song_model {
|
||||||
.execute(db);
|
.execute(db);
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) {
|
if let Some(song) = self
|
||||||
|
.as_mut()
|
||||||
|
.songs_mut()
|
||||||
|
.get_mut(index as usize)
|
||||||
|
{
|
||||||
song.font_size = updated_font_size;
|
song.font_size = updated_font_size;
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -571,7 +774,10 @@ mod song_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn get_item(self: Pin<&mut Self>, index: i32) -> QMap_QString_QVariant {
|
pub fn get_item(
|
||||||
|
self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
) -> QMap_QString_QVariant {
|
||||||
println!("{index}");
|
println!("{index}");
|
||||||
let mut qvariantmap = QMap_QString_QVariant::default();
|
let mut qvariantmap = QMap_QString_QVariant::default();
|
||||||
let idx = self.index(index, 0, &QModelIndex::default());
|
let idx = self.index(index, 0, &QModelIndex::default());
|
||||||
|
@ -580,7 +786,8 @@ mod song_model {
|
||||||
}
|
}
|
||||||
let role_names = self.as_ref().role_names();
|
let role_names = self.as_ref().role_names();
|
||||||
let role_names_iter = role_names.iter();
|
let role_names_iter = role_names.iter();
|
||||||
if let Some(song) = self.rust().songs.get(index as usize) {
|
if let Some(song) = self.rust().songs.get(index as usize)
|
||||||
|
{
|
||||||
for i in role_names_iter {
|
for i in role_names_iter {
|
||||||
qvariantmap.insert(
|
qvariantmap.insert(
|
||||||
QString::from(&i.1.to_string()),
|
QString::from(&i.1.to_string()),
|
||||||
|
@ -592,25 +799,32 @@ mod song_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn get_lyric_list(mut self: Pin<&mut Self>, index: i32) -> QStringList {
|
pub fn get_lyric_list(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
) -> QStringList {
|
||||||
println!("LYRIC_LIST: {index}");
|
println!("LYRIC_LIST: {index}");
|
||||||
let mut lyric_list = QList_QString::default();
|
let mut lyric_list = QList_QString::default();
|
||||||
let idx = self.index(index, 0, &QModelIndex::default());
|
let idx = self.index(index, 0, &QModelIndex::default());
|
||||||
if !idx.is_valid() {
|
if !idx.is_valid() {
|
||||||
return QStringList::default();
|
return QStringList::default();
|
||||||
}
|
}
|
||||||
if let Some(song) = self.rust().songs.get(index as usize) {
|
if let Some(song) = self.rust().songs.get(index as usize)
|
||||||
|
{
|
||||||
if song.lyrics.is_empty() {
|
if song.lyrics.is_empty() {
|
||||||
return QStringList::default();
|
return QStringList::default();
|
||||||
}
|
}
|
||||||
let raw_lyrics = song.lyrics.clone();
|
let raw_lyrics = song.lyrics.clone();
|
||||||
println!("raw-lyrics: {:?}", raw_lyrics);
|
println!("raw-lyrics: {:?}", raw_lyrics);
|
||||||
let vorder: Vec<&str> = song.verse_order.split(' ').collect();
|
let vorder: Vec<&str> =
|
||||||
|
song.verse_order.split(' ').collect();
|
||||||
let keywords = vec![
|
let keywords = vec![
|
||||||
"Verse 1", "Verse 2", "Verse 3", "Verse 4", "Verse 5", "Verse 6", "Verse 7",
|
"Verse 1", "Verse 2", "Verse 3", "Verse 4",
|
||||||
"Verse 8", "Chorus 1", "Chorus 2", "Chorus 3", "Chorus 4", "Bridge 1",
|
"Verse 5", "Verse 6", "Verse 7", "Verse 8",
|
||||||
"Bridge 2", "Bridge 3", "Bridge 4", "Intro 1", "Intro 2", "Ending 1",
|
"Chorus 1", "Chorus 2", "Chorus 3", "Chorus 4",
|
||||||
"Ending 2", "Other 1", "Other 2", "Other 3", "Other 4",
|
"Bridge 1", "Bridge 2", "Bridge 3", "Bridge 4",
|
||||||
|
"Intro 1", "Intro 2", "Ending 1", "Ending 2",
|
||||||
|
"Other 1", "Other 2", "Other 3", "Other 4",
|
||||||
];
|
];
|
||||||
let mut first_item = true;
|
let mut first_item = true;
|
||||||
|
|
||||||
|
@ -649,7 +863,9 @@ mod song_model {
|
||||||
"verse: {:?}, beginning: {:?}, end: {:?}, word: {:?}",
|
"verse: {:?}, beginning: {:?}, end: {:?}, word: {:?}",
|
||||||
verse, beg_verse, end_verse, word
|
verse, beg_verse, end_verse, word
|
||||||
);
|
);
|
||||||
if word.starts_with(beg_verse) && word.ends_with(end_verse) {
|
if word.starts_with(beg_verse)
|
||||||
|
&& word.ends_with(end_verse)
|
||||||
|
{
|
||||||
verse_name = word;
|
verse_name = word;
|
||||||
println!("TITLE: {verse_name}");
|
println!("TITLE: {verse_name}");
|
||||||
continue;
|
continue;
|
||||||
|
@ -657,12 +873,14 @@ mod song_model {
|
||||||
}
|
}
|
||||||
if let Some(lyric) = lyric_map.get(verse_name) {
|
if let Some(lyric) = lyric_map.get(verse_name) {
|
||||||
if lyric.contains("\n\n") {
|
if lyric.contains("\n\n") {
|
||||||
let split_lyrics: Vec<&str> = lyric.split("\n\n").collect();
|
let split_lyrics: Vec<&str> =
|
||||||
|
lyric.split("\n\n").collect();
|
||||||
for lyric in split_lyrics {
|
for lyric in split_lyrics {
|
||||||
if lyric == "" {
|
if lyric == "" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
lyric_list.append(QString::from(lyric));
|
lyric_list
|
||||||
|
.append(QString::from(lyric));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -717,14 +935,19 @@ mod song_model {
|
||||||
);
|
);
|
||||||
unsafe fn end_remove_rows(self: Pin<&mut qobject::SongModel>);
|
unsafe fn end_remove_rows(self: Pin<&mut qobject::SongModel>);
|
||||||
|
|
||||||
unsafe fn begin_reset_model(self: Pin<&mut qobject::SongModel>);
|
unsafe fn begin_reset_model(
|
||||||
|
self: Pin<&mut qobject::SongModel>,
|
||||||
|
);
|
||||||
unsafe fn end_reset_model(self: Pin<&mut qobject::SongModel>);
|
unsafe fn end_reset_model(self: Pin<&mut qobject::SongModel>);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cxx_qt::inherit]
|
#[cxx_qt::inherit]
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
#[cxx_name = "canFetchMore"]
|
#[cxx_name = "canFetchMore"]
|
||||||
fn base_can_fetch_more(self: &qobject::SongModel, parent: &QModelIndex) -> bool;
|
fn base_can_fetch_more(
|
||||||
|
self: &qobject::SongModel,
|
||||||
|
parent: &QModelIndex,
|
||||||
|
) -> bool;
|
||||||
|
|
||||||
fn index(
|
fn index(
|
||||||
self: &qobject::SongModel,
|
self: &qobject::SongModel,
|
||||||
|
@ -738,7 +961,8 @@ mod song_model {
|
||||||
impl qobject::SongModel {
|
impl qobject::SongModel {
|
||||||
#[qinvokable(cxx_override)]
|
#[qinvokable(cxx_override)]
|
||||||
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
||||||
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(&QString::from(&song.title)),
|
1 => QVariant::from(&QString::from(&song.title)),
|
||||||
|
@ -746,11 +970,21 @@ mod song_model {
|
||||||
3 => QVariant::from(&QString::from(&song.author)),
|
3 => QVariant::from(&QString::from(&song.author)),
|
||||||
4 => QVariant::from(&QString::from(&song.ccli)),
|
4 => QVariant::from(&QString::from(&song.ccli)),
|
||||||
5 => QVariant::from(&QString::from(&song.audio)),
|
5 => QVariant::from(&QString::from(&song.audio)),
|
||||||
6 => QVariant::from(&QString::from(&song.verse_order)),
|
6 => QVariant::from(&QString::from(
|
||||||
7 => QVariant::from(&QString::from(&song.background)),
|
&song.verse_order,
|
||||||
8 => QVariant::from(&QString::from(&song.background_type)),
|
)),
|
||||||
9 => QVariant::from(&QString::from(&song.horizontal_text_alignment)),
|
7 => QVariant::from(&QString::from(
|
||||||
10 => QVariant::from(&QString::from(&song.vertical_text_alignment)),
|
&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)),
|
11 => QVariant::from(&QString::from(&song.font)),
|
||||||
12 => QVariant::from(&song.font_size),
|
12 => QVariant::from(&song.font_size),
|
||||||
_ => QVariant::default(),
|
_ => QVariant::default(),
|
||||||
|
@ -776,12 +1010,27 @@ mod song_model {
|
||||||
roles.insert(4, cxx_qt_lib::QByteArray::from("ccli"));
|
roles.insert(4, cxx_qt_lib::QByteArray::from("ccli"));
|
||||||
roles.insert(5, cxx_qt_lib::QByteArray::from("audio"));
|
roles.insert(5, cxx_qt_lib::QByteArray::from("audio"));
|
||||||
roles.insert(6, cxx_qt_lib::QByteArray::from("vorder"));
|
roles.insert(6, cxx_qt_lib::QByteArray::from("vorder"));
|
||||||
roles.insert(7, cxx_qt_lib::QByteArray::from("background"));
|
roles.insert(
|
||||||
roles.insert(8, cxx_qt_lib::QByteArray::from("backgroundType"));
|
7,
|
||||||
roles.insert(9, cxx_qt_lib::QByteArray::from("horizontalTextAlignment"));
|
cxx_qt_lib::QByteArray::from("background"),
|
||||||
roles.insert(10, cxx_qt_lib::QByteArray::from("verticalTextAlignment"));
|
);
|
||||||
|
roles.insert(
|
||||||
|
8,
|
||||||
|
cxx_qt_lib::QByteArray::from("backgroundType"),
|
||||||
|
);
|
||||||
|
roles.insert(
|
||||||
|
9,
|
||||||
|
cxx_qt_lib::QByteArray::from(
|
||||||
|
"horizontalTextAlignment",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
roles.insert(
|
||||||
|
10,
|
||||||
|
cxx_qt_lib::QByteArray::from("verticalTextAlignment"),
|
||||||
|
);
|
||||||
roles.insert(11, cxx_qt_lib::QByteArray::from("font"));
|
roles.insert(11, cxx_qt_lib::QByteArray::from("font"));
|
||||||
roles.insert(12, cxx_qt_lib::QByteArray::from("fontSize"));
|
roles
|
||||||
|
.insert(12, cxx_qt_lib::QByteArray::from("fontSize"));
|
||||||
roles
|
roles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,11 @@ mod video_model {
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!(< QAbstractListModel >);
|
include!(< QAbstractListModel >);
|
||||||
include!("cxx-qt-lib/qhash.h");
|
include!("cxx-qt-lib/qhash.h");
|
||||||
type QHash_i32_QByteArray = cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
|
type QHash_i32_QByteArray =
|
||||||
|
cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
|
||||||
include!("cxx-qt-lib/qmap.h");
|
include!("cxx-qt-lib/qmap.h");
|
||||||
type QMap_QString_QVariant = cxx_qt_lib::QMap<cxx_qt_lib::QMapPair_QString_QVariant>;
|
type QMap_QString_QVariant =
|
||||||
|
cxx_qt_lib::QMap<cxx_qt_lib::QMapPair_QString_QVariant>;
|
||||||
include!("cxx-qt-lib/qvariant.h");
|
include!("cxx-qt-lib/qvariant.h");
|
||||||
type QVariant = cxx_qt_lib::QVariant;
|
type QVariant = cxx_qt_lib::QVariant;
|
||||||
include!("cxx-qt-lib/qstring.h");
|
include!("cxx-qt-lib/qstring.h");
|
||||||
|
@ -111,22 +113,32 @@ mod video_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
|
pub fn remove_item(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
) -> bool {
|
||||||
if index < 0 || (index as usize) >= self.videos().len() {
|
if index < 0 || (index as usize) >= self.videos().len() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let db = &mut self.as_mut().get_db();
|
let db = &mut self.as_mut().get_db();
|
||||||
|
|
||||||
let video_id = self.videos().get(index as usize).unwrap().id;
|
let video_id =
|
||||||
|
self.videos().get(index as usize).unwrap().id;
|
||||||
|
|
||||||
let result = delete(videos.filter(id.eq(video_id))).execute(db);
|
let result =
|
||||||
|
delete(videos.filter(id.eq(video_id))).execute(db);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
self.as_mut().begin_remove_rows(
|
||||||
|
&QModelIndex::default(),
|
||||||
|
index,
|
||||||
|
index,
|
||||||
|
);
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
.begin_remove_rows(&QModelIndex::default(), index, index);
|
.videos_mut()
|
||||||
self.as_mut().videos_mut().remove(index as usize);
|
.remove(index as usize);
|
||||||
self.as_mut().end_remove_rows();
|
self.as_mut().end_remove_rows();
|
||||||
}
|
}
|
||||||
println!("removed-item-at-index: {:?}", video_id);
|
println!("removed-item-at-index: {:?}", video_id);
|
||||||
|
@ -142,26 +154,32 @@ mod video_model {
|
||||||
|
|
||||||
fn get_db(self: Pin<&mut Self>) -> SqliteConnection {
|
fn get_db(self: Pin<&mut Self>) -> SqliteConnection {
|
||||||
let mut data = dirs::data_local_dir().unwrap();
|
let mut data = dirs::data_local_dir().unwrap();
|
||||||
data.push("librepresenter");
|
data.push("lumina");
|
||||||
data.push("library-db.sqlite3");
|
data.push("library-db.sqlite3");
|
||||||
let mut db_url = String::from("sqlite://");
|
let mut db_url = String::from("sqlite://");
|
||||||
db_url.push_str(data.to_str().unwrap());
|
db_url.push_str(data.to_str().unwrap());
|
||||||
println!("DB: {:?}", db_url);
|
println!("DB: {:?}", db_url);
|
||||||
|
|
||||||
SqliteConnection::establish(&db_url)
|
SqliteConnection::establish(&db_url).unwrap_or_else(
|
||||||
.unwrap_or_else(|_| panic!("error connecting to {}", db_url))
|
|_| panic!("error connecting to {}", db_url),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn new_item(mut self: Pin<&mut Self>, url: QUrl) {
|
pub fn new_item(mut self: Pin<&mut Self>, url: QUrl) {
|
||||||
println!("LETS INSERT THIS SUCKER!");
|
println!("LETS INSERT THIS SUCKER!");
|
||||||
let file_path = PathBuf::from(url.path().to_string());
|
let file_path = PathBuf::from(url.path().to_string());
|
||||||
let name = file_path.file_stem().unwrap().to_str().unwrap();
|
let name =
|
||||||
|
file_path.file_stem().unwrap().to_str().unwrap();
|
||||||
let video_id = self.rust().highest_id + 1;
|
let video_id = self.rust().highest_id + 1;
|
||||||
let video_title = QString::from(name);
|
let video_title = QString::from(name);
|
||||||
let video_path = url.to_qstring();
|
let video_path = url.to_qstring();
|
||||||
|
|
||||||
if self.as_mut().add_item(video_id, video_title, video_path) {
|
if self.as_mut().add_item(
|
||||||
|
video_id,
|
||||||
|
video_title,
|
||||||
|
video_path,
|
||||||
|
) {
|
||||||
println!("filename: {:?}", name);
|
println!("filename: {:?}", name);
|
||||||
self.as_mut().set_highest_id(video_id);
|
self.as_mut().set_highest_id(video_id);
|
||||||
} else {
|
} else {
|
||||||
|
@ -219,15 +237,21 @@ mod video_model {
|
||||||
let index = self.as_ref().videos().len() as i32;
|
let index = self.as_ref().videos().len() as i32;
|
||||||
println!("{:?}", video);
|
println!("{:?}", video);
|
||||||
unsafe {
|
unsafe {
|
||||||
self.as_mut()
|
self.as_mut().begin_insert_rows(
|
||||||
.begin_insert_rows(&QModelIndex::default(), index, index);
|
&QModelIndex::default(),
|
||||||
|
index,
|
||||||
|
index,
|
||||||
|
);
|
||||||
self.as_mut().videos_mut().push(video);
|
self.as_mut().videos_mut().push(video);
|
||||||
self.as_mut().end_insert_rows();
|
self.as_mut().end_insert_rows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn get_item(self: Pin<&mut Self>, index: i32) -> QMap_QString_QVariant {
|
pub fn get_item(
|
||||||
|
self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
) -> QMap_QString_QVariant {
|
||||||
println!("{index}");
|
println!("{index}");
|
||||||
let mut qvariantmap = QMap_QString_QVariant::default();
|
let mut qvariantmap = QMap_QString_QVariant::default();
|
||||||
let idx = self.index(index, 0, &QModelIndex::default());
|
let idx = self.index(index, 0, &QModelIndex::default());
|
||||||
|
@ -236,7 +260,9 @@ mod video_model {
|
||||||
}
|
}
|
||||||
let role_names = self.as_ref().role_names();
|
let role_names = self.as_ref().role_names();
|
||||||
let role_names_iter = role_names.iter();
|
let role_names_iter = role_names.iter();
|
||||||
if let Some(video) = self.rust().videos.get(index as usize) {
|
if let Some(video) =
|
||||||
|
self.rust().videos.get(index as usize)
|
||||||
|
{
|
||||||
for i in role_names_iter {
|
for i in role_names_iter {
|
||||||
qvariantmap.insert(
|
qvariantmap.insert(
|
||||||
QString::from(&i.1.to_string()),
|
QString::from(&i.1.to_string()),
|
||||||
|
@ -261,10 +287,19 @@ mod video_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn update_loop(mut self: Pin<&mut Self>, index: i32, loop_value: bool) -> bool {
|
pub fn update_loop(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
loop_value: 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::LoopingRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::LoopingRole));
|
||||||
|
let model_index = &self.as_ref().index(
|
||||||
|
index,
|
||||||
|
0,
|
||||||
|
&QModelIndex::default(),
|
||||||
|
);
|
||||||
println!("rust-video: {:?}", index);
|
println!("rust-video: {:?}", index);
|
||||||
println!("rust-loop: {:?}", loop_value);
|
println!("rust-loop: {:?}", loop_value);
|
||||||
|
|
||||||
|
@ -283,8 +318,11 @@ mod video_model {
|
||||||
video.looping = loop_value.clone();
|
video.looping = loop_value.clone();
|
||||||
println!("rust-video: {:?}", video.title);
|
println!("rust-video: {:?}", video.title);
|
||||||
}
|
}
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
println!("rust-looping: {:?}", loop_value);
|
println!("rust-looping: {:?}", loop_value);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -299,8 +337,13 @@ mod video_model {
|
||||||
updated_end_time: f32,
|
updated_end_time: f32,
|
||||||
) -> 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::EndTimeRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::EndTimeRole));
|
||||||
|
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(videos.filter(id.eq(index)))
|
let result = update(videos.filter(id.eq(index)))
|
||||||
|
@ -316,8 +359,11 @@ mod video_model {
|
||||||
{
|
{
|
||||||
video.end_time = updated_end_time.clone();
|
video.end_time = updated_end_time.clone();
|
||||||
}
|
}
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
println!("rust-end-time: {:?}", updated_end_time);
|
println!("rust-end-time: {:?}", updated_end_time);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -332,8 +378,13 @@ mod video_model {
|
||||||
updated_start_time: f32,
|
updated_start_time: f32,
|
||||||
) -> 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::StartTimeRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::StartTimeRole));
|
||||||
|
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(videos.filter(id.eq(index)))
|
let result = update(videos.filter(id.eq(index)))
|
||||||
|
@ -349,9 +400,15 @@ mod video_model {
|
||||||
{
|
{
|
||||||
video.start_time = updated_start_time.clone();
|
video.start_time = updated_start_time.clone();
|
||||||
}
|
}
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
println!("rust-start-time: {:?}", updated_start_time);
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"rust-start-time: {:?}",
|
||||||
|
updated_start_time
|
||||||
|
);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(_e) => false,
|
||||||
|
@ -359,10 +416,19 @@ mod video_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn update_title(mut self: Pin<&mut Self>, index: i32, updated_title: QString) -> bool {
|
pub fn update_title(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
updated_title: QString,
|
||||||
|
) -> bool {
|
||||||
let mut vector_roles = QVector_i32::default();
|
let mut vector_roles = QVector_i32::default();
|
||||||
vector_roles.append(self.as_ref().get_role(Role::TitleRole));
|
vector_roles
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::TitleRole));
|
||||||
|
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(videos.filter(id.eq(index)))
|
let result = update(videos.filter(id.eq(index)))
|
||||||
|
@ -380,8 +446,11 @@ mod video_model {
|
||||||
println!("rust-title: {:?}", video.title);
|
println!("rust-title: {:?}", video.title);
|
||||||
}
|
}
|
||||||
// TODO this seems to not be updating in the actual list
|
// TODO this seems to not be updating in the actual list
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
// self.as_mut().emit_title_changed();
|
// self.as_mut().emit_title_changed();
|
||||||
println!("rust-title: {:?}", updated_title);
|
println!("rust-title: {:?}", updated_title);
|
||||||
true
|
true
|
||||||
|
@ -391,10 +460,19 @@ mod video_model {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn update_path(mut self: Pin<&mut Self>, index: i32, updated_path: QString) -> bool {
|
pub fn update_path(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
updated_path: QString,
|
||||||
|
) -> 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
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
.append(self.as_ref().get_role(Role::PathRole));
|
||||||
|
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(videos.filter(id.eq(index)))
|
let result = update(videos.filter(id.eq(index)))
|
||||||
|
@ -411,8 +489,11 @@ mod video_model {
|
||||||
video.path = updated_path.clone();
|
video.path = updated_path.clone();
|
||||||
println!("rust-title: {:?}", video.title);
|
println!("rust-title: {:?}", video.title);
|
||||||
}
|
}
|
||||||
self.as_mut()
|
self.as_mut().emit_data_changed(
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
model_index,
|
||||||
|
model_index,
|
||||||
|
&vector_roles,
|
||||||
|
);
|
||||||
println!("rust-path: {:?}", updated_path);
|
println!("rust-path: {:?}", updated_path);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -430,7 +511,9 @@ mod video_model {
|
||||||
first: i32,
|
first: i32,
|
||||||
last: i32,
|
last: i32,
|
||||||
);
|
);
|
||||||
unsafe fn end_insert_rows(self: Pin<&mut qobject::VideoModel>);
|
unsafe fn end_insert_rows(
|
||||||
|
self: Pin<&mut qobject::VideoModel>,
|
||||||
|
);
|
||||||
|
|
||||||
unsafe fn begin_remove_rows(
|
unsafe fn begin_remove_rows(
|
||||||
self: Pin<&mut qobject::VideoModel>,
|
self: Pin<&mut qobject::VideoModel>,
|
||||||
|
@ -438,16 +521,25 @@ mod video_model {
|
||||||
first: i32,
|
first: i32,
|
||||||
last: i32,
|
last: i32,
|
||||||
);
|
);
|
||||||
unsafe fn end_remove_rows(self: Pin<&mut qobject::VideoModel>);
|
unsafe fn end_remove_rows(
|
||||||
|
self: Pin<&mut qobject::VideoModel>,
|
||||||
|
);
|
||||||
|
|
||||||
unsafe fn begin_reset_model(self: Pin<&mut qobject::VideoModel>);
|
unsafe fn begin_reset_model(
|
||||||
unsafe fn end_reset_model(self: Pin<&mut qobject::VideoModel>);
|
self: Pin<&mut qobject::VideoModel>,
|
||||||
|
);
|
||||||
|
unsafe fn end_reset_model(
|
||||||
|
self: Pin<&mut qobject::VideoModel>,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cxx_qt::inherit]
|
#[cxx_qt::inherit]
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
#[cxx_name = "canFetchMore"]
|
#[cxx_name = "canFetchMore"]
|
||||||
fn base_can_fetch_more(self: &qobject::VideoModel, parent: &QModelIndex) -> bool;
|
fn base_can_fetch_more(
|
||||||
|
self: &qobject::VideoModel,
|
||||||
|
parent: &QModelIndex,
|
||||||
|
) -> bool;
|
||||||
|
|
||||||
fn index(
|
fn index(
|
||||||
self: &qobject::VideoModel,
|
self: &qobject::VideoModel,
|
||||||
|
@ -461,7 +553,9 @@ mod video_model {
|
||||||
impl qobject::VideoModel {
|
impl qobject::VideoModel {
|
||||||
#[qinvokable(cxx_override)]
|
#[qinvokable(cxx_override)]
|
||||||
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
||||||
if let Some(video) = self.videos().get(index.row() as usize) {
|
if let Some(video) =
|
||||||
|
self.videos().get(index.row() as usize)
|
||||||
|
{
|
||||||
return match role {
|
return match role {
|
||||||
0 => QVariant::from(&video.id),
|
0 => QVariant::from(&video.id),
|
||||||
1 => QVariant::from(&video.title),
|
1 => QVariant::from(&video.title),
|
||||||
|
@ -488,7 +582,8 @@ mod video_model {
|
||||||
roles.insert(0, cxx_qt_lib::QByteArray::from("id"));
|
roles.insert(0, cxx_qt_lib::QByteArray::from("id"));
|
||||||
roles.insert(1, cxx_qt_lib::QByteArray::from("title"));
|
roles.insert(1, cxx_qt_lib::QByteArray::from("title"));
|
||||||
roles.insert(2, cxx_qt_lib::QByteArray::from("filePath"));
|
roles.insert(2, cxx_qt_lib::QByteArray::from("filePath"));
|
||||||
roles.insert(3, cxx_qt_lib::QByteArray::from("startTime"));
|
roles
|
||||||
|
.insert(3, cxx_qt_lib::QByteArray::from("startTime"));
|
||||||
roles.insert(4, cxx_qt_lib::QByteArray::from("endTime"));
|
roles.insert(4, cxx_qt_lib::QByteArray::from("endTime"));
|
||||||
roles.insert(5, cxx_qt_lib::QByteArray::from("loop"));
|
roles.insert(5, cxx_qt_lib::QByteArray::from("loop"));
|
||||||
roles
|
roles
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue