Quite a few of the models have been ported.. need more though.
Still need all the songs and some small utility modules
This commit is contained in:
parent
81b430e768
commit
62daf316a3
7 changed files with 2781 additions and 2535 deletions
14
TODO.org
14
TODO.org
|
@ -1,9 +1,21 @@
|
|||
#+TITLE: Todo List
|
||||
#+filetags: :projectdev:
|
||||
:PROPERTIES:
|
||||
:CATEGORY: dev
|
||||
:END:
|
||||
|
||||
* Tasks [61%] [47/76]
|
||||
* Tasks [0%] [0/0]
|
||||
** TODO Port to CXX-QT 6.0 [37%] [3/8]
|
||||
[[file:~/dev/lumina/src/rust/lib.rs]]
|
||||
|
||||
*** DONE image_model.rs
|
||||
*** DONE video_model.rs
|
||||
*** DONE presentation_model.rs
|
||||
*** TODO songs/song_model.rs
|
||||
*** TODO songs/song_editor.rs
|
||||
*** TODO ytdl.rs
|
||||
*** TODO utils.rs
|
||||
*** TODO obs.rs
|
||||
** TODO Write a function to handle switching to the next fragment in revealjs
|
||||
[[file:~/dev/lumina/src/qml/presenter/Slide.qml::WebEngineView {]]
|
||||
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
#[cxx_qt::bridge]
|
||||
mod image_model {
|
||||
use crate::image_model::image_model::Image;
|
||||
use crate::schema::images::dsl::*;
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use diesel::{delete, insert_into, prelude::*, update};
|
||||
use std::path::PathBuf;
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!(< QAbstractListModel >);
|
||||
include!("cxx-qt-lib/qhash.h");
|
||||
|
@ -30,6 +24,145 @@ mod image_model {
|
|||
type QList_QString = cxx_qt_lib::QList<QString>;
|
||||
}
|
||||
|
||||
#[qenum(ImageModel)]
|
||||
enum Role {
|
||||
Id,
|
||||
Path,
|
||||
Title,
|
||||
}
|
||||
|
||||
unsafe extern "RustQt" {
|
||||
#[qobject]
|
||||
#[base = "QAbstractListModel"]
|
||||
#[qml_element]
|
||||
#[qproperty(i32, count_rows)]
|
||||
type ImageModel = super::ImageModelRust;
|
||||
|
||||
#[inherit]
|
||||
#[qsignal]
|
||||
fn data_changed(
|
||||
self: Pin<&mut ImageModel>,
|
||||
top_left: &QModelIndex,
|
||||
bottom_right: &QModelIndex,
|
||||
roles: &QVector_i32,
|
||||
);
|
||||
|
||||
#[qinvokable]
|
||||
fn clear(self: Pin<&mut ImageModel>);
|
||||
#[qinvokable]
|
||||
fn setup(self: Pin<&mut ImageModel>);
|
||||
#[qinvokable]
|
||||
fn remove_item(
|
||||
self: Pin<&mut ImageModel>,
|
||||
index: i32,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn new_item(self: Pin<&mut ImageModel>, url: QUrl);
|
||||
#[qinvokable]
|
||||
fn update_title(
|
||||
self: Pin<&mut ImageModel>,
|
||||
index: i32,
|
||||
updated_title: QString,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn update_file_path(
|
||||
self: Pin<&mut ImageModel>,
|
||||
index: i32,
|
||||
updated_file_path: QString,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn get_item(
|
||||
self: Pin<&mut ImageModel>,
|
||||
index: i32,
|
||||
) -> QMap_QString_QVariant;
|
||||
}
|
||||
|
||||
impl cxx_qt::Threading for ImageModel {}
|
||||
|
||||
unsafe extern "RustQt" {
|
||||
#[inherit]
|
||||
unsafe fn begin_insert_rows(
|
||||
self: Pin<&mut ImageModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_insert_rows(self: Pin<&mut ImageModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_remove_rows(
|
||||
self: Pin<&mut ImageModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_move_rows(
|
||||
self: Pin<&mut ImageModel>,
|
||||
source_parent: &QModelIndex,
|
||||
source_first: i32,
|
||||
source_last: i32,
|
||||
destination_parent: &QModelIndex,
|
||||
destination_child: i32,
|
||||
) -> bool;
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_move_rows(self: Pin<&mut ImageModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_remove_rows(self: Pin<&mut ImageModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_reset_model(self: Pin<&mut ImageModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_reset_model(self: Pin<&mut ImageModel>);
|
||||
|
||||
#[inherit]
|
||||
fn can_fetch_more(
|
||||
self: &ImageModel,
|
||||
parent: &QModelIndex,
|
||||
) -> bool;
|
||||
|
||||
#[inherit]
|
||||
fn index(
|
||||
self: &ImageModel,
|
||||
row: i32,
|
||||
column: i32,
|
||||
parent: &QModelIndex,
|
||||
) -> QModelIndex;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn data(
|
||||
self: &ImageModel,
|
||||
index: &QModelIndex,
|
||||
role: i32,
|
||||
) -> QVariant;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn role_names(self: &ImageModel) -> QHash_i32_QByteArray;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn row_count(self: &ImageModel, _parent: &QModelIndex)
|
||||
-> i32;
|
||||
|
||||
#[qinvokable]
|
||||
fn count(self: &ImageModel) -> i32;
|
||||
}
|
||||
}
|
||||
|
||||
use crate::image_model::image_model::Image;
|
||||
use crate::schema::images::dsl::*;
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use diesel::{delete, insert_into, prelude::*, update};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct Image {
|
||||
id: i32,
|
||||
|
@ -37,47 +170,14 @@ mod image_model {
|
|||
path: QString,
|
||||
}
|
||||
|
||||
#[cxx_qt::qobject(base = "QAbstractListModel")]
|
||||
#[derive(Default, Debug)]
|
||||
pub struct ImageModel {
|
||||
#[qproperty]
|
||||
pub struct ImageModelRust {
|
||||
count_rows: i32,
|
||||
highest_id: i32,
|
||||
images: Vec<self::Image>,
|
||||
}
|
||||
|
||||
#[cxx_qt::qsignals(ImageModel)]
|
||||
pub enum Signals<'a> {
|
||||
#[inherit]
|
||||
DataChanged {
|
||||
top_left: &'a QModelIndex,
|
||||
bottom_right: &'a QModelIndex,
|
||||
roles: &'a QVector_i32,
|
||||
},
|
||||
}
|
||||
|
||||
enum Role {
|
||||
IdRole,
|
||||
PathRole,
|
||||
TitleRole,
|
||||
}
|
||||
|
||||
// impl FromStr for Role {
|
||||
// type Err = ();
|
||||
// fn from_str(input: &str) -> Result<Role, Self::Err> {
|
||||
// match input {
|
||||
// "id" => Ok(Role::IdRole),
|
||||
// "title" => Ok(Role::TitleRole),
|
||||
// "path" => Ok(Role::PathRole),
|
||||
// _ => Err(()),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// use crate::entities::{images, prelude::Images};
|
||||
// use sea_orm::{ConnectionTrait, Database, DbBackend, DbErr, Statement, ActiveValue};
|
||||
impl qobject::ImageModel {
|
||||
#[qinvokable]
|
||||
pub fn clear(mut self: Pin<&mut Self>) {
|
||||
unsafe {
|
||||
self.as_mut().begin_reset_model();
|
||||
|
@ -86,7 +186,6 @@ mod image_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn setup(mut self: Pin<&mut Self>) {
|
||||
let db = &mut self.as_mut().get_db();
|
||||
let results = images
|
||||
|
@ -118,18 +217,13 @@ mod image_model {
|
|||
println!("--------------------------------------");
|
||||
}
|
||||
|
||||
#[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() {
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
|
@ -142,9 +236,7 @@ mod image_model {
|
|||
index,
|
||||
index,
|
||||
);
|
||||
self.as_mut()
|
||||
.images_mut()
|
||||
.remove(index as usize);
|
||||
self.as_mut().images_mut().remove(index as usize);
|
||||
self.as_mut().end_remove_rows();
|
||||
}
|
||||
println!("removed-item-at-index: {:?}", image_id);
|
||||
|
@ -166,26 +258,20 @@ mod image_model {
|
|||
db_url.push_str(data.to_str().unwrap());
|
||||
println!("DB: {:?}", db_url);
|
||||
|
||||
SqliteConnection::establish(&db_url).unwrap_or_else(
|
||||
|_| panic!("error connecting to {}", db_url),
|
||||
)
|
||||
SqliteConnection::establish(&db_url).unwrap_or_else(|_| {
|
||||
panic!("error connecting to {}", db_url)
|
||||
})
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn new_item(mut self: Pin<&mut Self>, url: QUrl) {
|
||||
println!("LETS INSERT THIS SUCKER!");
|
||||
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_title = QString::from(name);
|
||||
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);
|
||||
self.as_mut().set_highest_id(image_id);
|
||||
} else {
|
||||
|
@ -244,7 +330,6 @@ mod image_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn update_title(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -253,11 +338,8 @@ mod image_model {
|
|||
let mut vector_roles = QVector_i32::default();
|
||||
vector_roles
|
||||
.append(self.as_ref().get_role_id(Role::TitleRole));
|
||||
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 result = update(images.filter(id.eq(index)))
|
||||
|
@ -285,7 +367,6 @@ mod image_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn update_file_path(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -294,11 +375,8 @@ mod image_model {
|
|||
let mut vector_roles = QVector_i32::default();
|
||||
vector_roles
|
||||
.append(self.as_ref().get_role_id(Role::PathRole));
|
||||
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 result = update(images.filter(id.eq(index)))
|
||||
|
@ -326,7 +404,6 @@ mod image_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn get_item(
|
||||
self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -339,9 +416,7 @@ mod image_model {
|
|||
}
|
||||
let role_names = self.as_ref().role_names();
|
||||
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 {
|
||||
qvariantmap.insert(
|
||||
QString::from(&i.1.to_string()),
|
||||
|
@ -354,72 +429,23 @@ mod image_model {
|
|||
|
||||
fn get_role_id(&self, role: Role) -> i32 {
|
||||
match role {
|
||||
Role::IdRole => 0,
|
||||
Role::TitleRole => 1,
|
||||
Role::PathRole => 2,
|
||||
qobject::Role::Id => 0,
|
||||
qobject::Role::Title => 1,
|
||||
qobject::Role::Path => 2,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create Rust bindings for C++ functions of the base class (QAbstractItemModel)
|
||||
#[cxx_qt::inherit]
|
||||
extern "C++" {
|
||||
unsafe fn begin_insert_rows(
|
||||
self: Pin<&mut qobject::ImageModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
unsafe fn end_insert_rows(
|
||||
self: Pin<&mut qobject::ImageModel>,
|
||||
);
|
||||
|
||||
unsafe fn begin_remove_rows(
|
||||
self: Pin<&mut qobject::ImageModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
unsafe fn end_remove_rows(
|
||||
self: Pin<&mut qobject::ImageModel>,
|
||||
);
|
||||
|
||||
unsafe fn begin_reset_model(
|
||||
self: Pin<&mut qobject::ImageModel>,
|
||||
);
|
||||
unsafe fn end_reset_model(
|
||||
self: Pin<&mut qobject::ImageModel>,
|
||||
);
|
||||
}
|
||||
|
||||
#[cxx_qt::inherit]
|
||||
unsafe extern "C++" {
|
||||
#[cxx_name = "canFetchMore"]
|
||||
fn base_can_fetch_more(
|
||||
self: &qobject::ImageModel,
|
||||
parent: &QModelIndex,
|
||||
) -> bool;
|
||||
|
||||
fn index(
|
||||
self: &qobject::ImageModel,
|
||||
row: i32,
|
||||
column: i32,
|
||||
parent: &QModelIndex,
|
||||
) -> QModelIndex;
|
||||
}
|
||||
|
||||
// QAbstractListModel implementation
|
||||
impl qobject::ImageModel {
|
||||
#[qinvokable(cxx_override)]
|
||||
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
||||
if let Some(image) =
|
||||
self.images().get(index.row() as usize)
|
||||
{
|
||||
let role = qobject::Roles { repr: role };
|
||||
if let Some(image) = self.images().get(index.row() as usize) {
|
||||
return match role {
|
||||
0 => QVariant::from(&image.id),
|
||||
1 => QVariant::from(&image.title),
|
||||
2 => QVariant::from(&image.path),
|
||||
qobject::Roles::Id => QVariant::from(&image.id),
|
||||
qobject::Roles::Title => QVariant::from(&image.title),
|
||||
qobject::Roles::Path => QVariant::from(&image.path),
|
||||
_ => QVariant::default(),
|
||||
};
|
||||
}
|
||||
|
@ -428,21 +454,28 @@ mod image_model {
|
|||
}
|
||||
|
||||
// Example of overriding a C++ virtual method and calling the base class implementation.
|
||||
#[qinvokable(cxx_override)]
|
||||
|
||||
pub fn can_fetch_more(&self, parent: &QModelIndex) -> bool {
|
||||
self.base_can_fetch_more(parent)
|
||||
}
|
||||
|
||||
#[qinvokable(cxx_override)]
|
||||
pub fn role_names(&self) -> QHash_i32_QByteArray {
|
||||
let mut roles = QHash_i32_QByteArray::default();
|
||||
roles.insert(0, cxx_qt_lib::QByteArray::from("id"));
|
||||
roles.insert(1, cxx_qt_lib::QByteArray::from("title"));
|
||||
roles.insert(2, cxx_qt_lib::QByteArray::from("filePath"));
|
||||
roles.insert(
|
||||
qobject::Roles::Id.repr,
|
||||
cxx_qt_lib::QByteArray::from("id"),
|
||||
);
|
||||
roles.insert(
|
||||
qobject::Roles::Title.repr,
|
||||
cxx_qt_lib::QByteArray::from("title"),
|
||||
);
|
||||
roles.insert(
|
||||
qobject::Roles::Path.repr,
|
||||
cxx_qt_lib::QByteArray::from("filePath"),
|
||||
);
|
||||
roles
|
||||
}
|
||||
|
||||
#[qinvokable(cxx_override)]
|
||||
pub fn row_count(&self, _parent: &QModelIndex) -> i32 {
|
||||
let cnt = self.rust().images.len() as i32;
|
||||
// self.as_mut().set_count(cnt);
|
||||
|
@ -450,11 +483,9 @@ mod image_model {
|
|||
cnt
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn count(mut self: Pin<&mut Self>) -> i32 {
|
||||
let cnt = self.rust().images.len() as i32;
|
||||
self.as_mut().set_count_rows(cnt);
|
||||
cnt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,3 +16,4 @@ pub mod utils;
|
|||
pub mod video_model;
|
||||
pub mod ytdl;
|
||||
// mod video_thumbnail;
|
||||
|
||||
|
|
|
@ -1,14 +1,5 @@
|
|||
#[cxx_qt::bridge]
|
||||
mod presentation_model {
|
||||
use crate::presentation_model::presentation_model::Presentation;
|
||||
use crate::reveal_js;
|
||||
use crate::schema::presentations::dsl::*;
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use diesel::{delete, insert_into, prelude::*, update};
|
||||
// use sqlx::Connection;
|
||||
use std::path::PathBuf;
|
||||
use tracing::debug;
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!(< QAbstractListModel >);
|
||||
include!("cxx-qt-lib/qhash.h");
|
||||
|
@ -33,6 +24,178 @@ mod presentation_model {
|
|||
type QList_QString = cxx_qt_lib::QList<QString>;
|
||||
}
|
||||
|
||||
#[qenum(PresentationModel)]
|
||||
enum Role {
|
||||
Id,
|
||||
Title,
|
||||
Path,
|
||||
Html,
|
||||
PageCount,
|
||||
}
|
||||
|
||||
unsafe extern "RustQt" {
|
||||
#[qobject]
|
||||
#[base = "QAbstractListModel"]
|
||||
#[qml_element]
|
||||
#[qproperty(i32, count_rows)]
|
||||
type PresentationModel = super::PresentationModelRust;
|
||||
|
||||
#[inherit]
|
||||
#[qsignal]
|
||||
fn data_changed(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
top_left: &QModelIndex,
|
||||
bottom_right: &QModelIndex,
|
||||
roles: &QVector_i32,
|
||||
);
|
||||
|
||||
#[qinvokable]
|
||||
fn clear(self: Pin<&mut PresentationModel>);
|
||||
#[qinvokable]
|
||||
fn setup(self: Pin<&mut PresentationModel>);
|
||||
#[qinvokable]
|
||||
fn remove_item(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
index: i32,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn new_item(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
url: QUrl,
|
||||
new_page_count: i32,
|
||||
);
|
||||
#[qinvokable]
|
||||
fn update_path(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
index: i32,
|
||||
updated_path: QString,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn get_item(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
index: i32,
|
||||
) -> QMap_QString_QVariant;
|
||||
#[qinvokable]
|
||||
fn update_loop(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
index: i32,
|
||||
loop_value: bool,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn update_title(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
index: i32,
|
||||
updated_title: QString,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn update_page_count(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
index: i32,
|
||||
updated_page_count: i32,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn update_end_time(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
index: i32,
|
||||
updated_end_stime: QString,
|
||||
) -> bool;
|
||||
}
|
||||
|
||||
impl cxx_qt::Threading for PresentationModel {}
|
||||
|
||||
unsafe extern "RustQt" {
|
||||
#[inherit]
|
||||
unsafe fn begin_insert_rows(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_insert_rows(self: Pin<&mut PresentationModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_remove_rows(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_move_rows(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
source_parent: &QModelIndex,
|
||||
source_first: i32,
|
||||
source_last: i32,
|
||||
destination_parent: &QModelIndex,
|
||||
destination_child: i32,
|
||||
) -> bool;
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_move_rows(self: Pin<&mut PresentationModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_remove_rows(self: Pin<&mut PresentationModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_reset_model(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_reset_model(self: Pin<&mut PresentationModel>);
|
||||
|
||||
#[inherit]
|
||||
fn can_fetch_more(
|
||||
self: &PresentationModel,
|
||||
parent: &QModelIndex,
|
||||
) -> bool;
|
||||
|
||||
#[inherit]
|
||||
fn index(
|
||||
self: &PresentationModel,
|
||||
row: i32,
|
||||
column: i32,
|
||||
parent: &QModelIndex,
|
||||
) -> QModelIndex;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn data(
|
||||
self: &PresentationModel,
|
||||
index: &QModelIndex,
|
||||
role: i32,
|
||||
) -> QVariant;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn role_names(
|
||||
self: &PresentationModel,
|
||||
) -> QHash_i32_QByteArray;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn row_count(
|
||||
self: &PresentationModel,
|
||||
_parent: &QModelIndex,
|
||||
) -> i32;
|
||||
|
||||
#[qinvokable]
|
||||
fn count(self: &PresentationModel) -> i32;
|
||||
}
|
||||
}
|
||||
|
||||
use crate::presentation_model::presentation_model::Presentation;
|
||||
use crate::reveal_js;
|
||||
use crate::schema::presentations::dsl::*;
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use diesel::{delete, insert_into, prelude::*, update};
|
||||
// use sqlx::Connection;
|
||||
use std::path::PathBuf;
|
||||
use tracing::debug;
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct Presentation {
|
||||
id: i32,
|
||||
|
@ -42,35 +205,13 @@ mod presentation_model {
|
|||
page_count: i32,
|
||||
}
|
||||
|
||||
#[cxx_qt::qobject(base = "QAbstractListModel")]
|
||||
#[derive(Default, Debug)]
|
||||
pub struct PresentationModel {
|
||||
pub struct PresentationModelRust {
|
||||
highest_id: i32,
|
||||
presentations: Vec<self::Presentation>,
|
||||
}
|
||||
|
||||
#[cxx_qt::qsignals(PresentationModel)]
|
||||
pub enum Signals<'a> {
|
||||
#[inherit]
|
||||
DataChanged {
|
||||
top_left: &'a QModelIndex,
|
||||
bottom_right: &'a QModelIndex,
|
||||
roles: &'a QVector_i32,
|
||||
},
|
||||
}
|
||||
|
||||
enum Role {
|
||||
IdRole,
|
||||
PathRole,
|
||||
TitleRole,
|
||||
HtmlRole,
|
||||
PageCountRole,
|
||||
}
|
||||
|
||||
// use crate::entities::{presentations, prelude::Presentations};
|
||||
// use sea_orm::{ConnectionTrait, Database, DbBackend, DbErr, Statement, ActiveValue};
|
||||
impl qobject::PresentationModel {
|
||||
#[qinvokable]
|
||||
pub fn clear(mut self: Pin<&mut Self>) {
|
||||
unsafe {
|
||||
self.as_mut().begin_reset_model();
|
||||
|
@ -79,7 +220,6 @@ mod presentation_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn setup(mut self: Pin<&mut Self>) {
|
||||
let db = &mut self.as_mut().get_db();
|
||||
// let table_info = diesel::sql_query("PRAGMA table_info(presentations)").load(db);
|
||||
|
@ -116,13 +256,8 @@ mod presentation_model {
|
|||
println!("--------------------------------------");
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn remove_item(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
) -> bool {
|
||||
if index < 0
|
||||
|| (index as usize) >= self.presentations().len()
|
||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
|
||||
if index < 0 || (index as usize) >= self.presentations().len()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -173,12 +308,11 @@ mod presentation_model {
|
|||
db_url.push_str(data.to_str().unwrap());
|
||||
println!("DB: {:?}", db_url);
|
||||
|
||||
SqliteConnection::establish(&db_url).unwrap_or_else(
|
||||
|_| panic!("error connecting to {}", db_url),
|
||||
)
|
||||
SqliteConnection::establish(&db_url).unwrap_or_else(|_| {
|
||||
panic!("error connecting to {}", db_url)
|
||||
})
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn new_item(
|
||||
mut self: Pin<&mut Self>,
|
||||
url: QUrl,
|
||||
|
@ -186,8 +320,7 @@ mod presentation_model {
|
|||
) {
|
||||
println!("LETS INSERT THIS SUCKER!");
|
||||
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_title = QString::from(name);
|
||||
let presentation_path = url;
|
||||
|
@ -209,7 +342,6 @@ mod presentation_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn add_item(
|
||||
mut self: Pin<&mut Self>,
|
||||
presentation_id: i32,
|
||||
|
@ -222,13 +354,10 @@ mod presentation_model {
|
|||
// println!("{:?}", db);
|
||||
let mut actual_page_count = new_page_count;
|
||||
if presentation_html {
|
||||
let actual_path = PathBuf::from(
|
||||
presentation_path.path().to_string(),
|
||||
);
|
||||
let actual_path =
|
||||
PathBuf::from(presentation_path.path().to_string());
|
||||
actual_page_count =
|
||||
reveal_js::count_slides_and_fragments(
|
||||
&actual_path,
|
||||
);
|
||||
reveal_js::count_slides_and_fragments(&actual_path);
|
||||
}
|
||||
debug!(
|
||||
page_count = actual_page_count,
|
||||
|
@ -285,7 +414,6 @@ mod presentation_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn get_item(
|
||||
self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -311,20 +439,15 @@ mod presentation_model {
|
|||
qvariantmap
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn update_title(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
updated_title: QString,
|
||||
) -> bool {
|
||||
let mut vector_roles = QVector_i32::default();
|
||||
vector_roles
|
||||
.append(self.as_ref().get_role(Role::TitleRole));
|
||||
let model_index = &self.as_ref().index(
|
||||
index,
|
||||
0,
|
||||
&QModelIndex::default(),
|
||||
);
|
||||
vector_roles.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 result = update(presentations.filter(id.eq(index)))
|
||||
|
@ -338,12 +461,8 @@ mod presentation_model {
|
|||
.iter_mut()
|
||||
.filter(|x| x.id == index)
|
||||
{
|
||||
presentation.title =
|
||||
updated_title.to_string();
|
||||
println!(
|
||||
"rust-title: {:?}",
|
||||
presentation.title
|
||||
);
|
||||
presentation.title = updated_title.to_string();
|
||||
println!("rust-title: {:?}", presentation.title);
|
||||
}
|
||||
// TODO this seems to not be updating in the actual list
|
||||
self.as_mut().emit_data_changed(
|
||||
|
@ -359,7 +478,6 @@ mod presentation_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn update_page_count(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -368,11 +486,8 @@ mod presentation_model {
|
|||
let mut vector_roles = QVector_i32::default();
|
||||
vector_roles
|
||||
.append(self.as_ref().get_role(Role::PageCountRole));
|
||||
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 result = update(presentations.filter(id.eq(index)))
|
||||
|
@ -399,10 +514,7 @@ mod presentation_model {
|
|||
&vector_roles,
|
||||
);
|
||||
// self.as_mut().emit_page_count_changed();
|
||||
println!(
|
||||
"rust-page_count: {:?}",
|
||||
updated_page_count
|
||||
);
|
||||
println!("rust-page_count: {:?}", updated_page_count);
|
||||
true
|
||||
}
|
||||
Err(_e) => false,
|
||||
|
@ -421,70 +533,27 @@ mod presentation_model {
|
|||
}
|
||||
}
|
||||
|
||||
// Create Rust bindings for C++ functions of the base class (QAbstractItemModel)
|
||||
#[cxx_qt::inherit]
|
||||
extern "C++" {
|
||||
unsafe fn begin_insert_rows(
|
||||
self: Pin<&mut qobject::PresentationModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
unsafe fn end_insert_rows(
|
||||
self: Pin<&mut qobject::PresentationModel>,
|
||||
);
|
||||
|
||||
unsafe fn begin_remove_rows(
|
||||
self: Pin<&mut qobject::PresentationModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
unsafe fn end_remove_rows(
|
||||
self: Pin<&mut qobject::PresentationModel>,
|
||||
);
|
||||
|
||||
unsafe fn begin_reset_model(
|
||||
self: Pin<&mut qobject::PresentationModel>,
|
||||
);
|
||||
unsafe fn end_reset_model(
|
||||
self: Pin<&mut qobject::PresentationModel>,
|
||||
);
|
||||
}
|
||||
|
||||
#[cxx_qt::inherit]
|
||||
unsafe extern "C++" {
|
||||
#[cxx_name = "canFetchMore"]
|
||||
fn base_can_fetch_more(
|
||||
self: &qobject::PresentationModel,
|
||||
parent: &QModelIndex,
|
||||
) -> bool;
|
||||
|
||||
fn index(
|
||||
self: &qobject::PresentationModel,
|
||||
row: i32,
|
||||
column: i32,
|
||||
parent: &QModelIndex,
|
||||
) -> QModelIndex;
|
||||
}
|
||||
|
||||
// QAbstractListModel implementation
|
||||
impl qobject::PresentationModel {
|
||||
#[qinvokable(cxx_override)]
|
||||
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
||||
let role = qobject::Roles { repr: role };
|
||||
if let Some(presentation) =
|
||||
self.presentations().get(index.row() as usize)
|
||||
{
|
||||
return match role {
|
||||
0 => QVariant::from(&presentation.id),
|
||||
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),
|
||||
qobject::Role::Id => QVariant::from(&presentation.id),
|
||||
qobject::Role::Title => QVariant::from(
|
||||
&QString::from(&presentation.title),
|
||||
),
|
||||
qobject::Role::Path => {
|
||||
QVariant::from(&QString::from(&presentation.path))
|
||||
}
|
||||
qobject::Role::Html => {
|
||||
QVariant::from(&presentation.html)
|
||||
}
|
||||
qobject::Role::PageCount => {
|
||||
QVariant::from(&presentation.page_count)
|
||||
}
|
||||
_ => QVariant::default(),
|
||||
};
|
||||
}
|
||||
|
@ -493,33 +562,43 @@ mod presentation_model {
|
|||
}
|
||||
|
||||
// Example of overriding a C++ virtual method and calling the base class implementation.
|
||||
#[qinvokable(cxx_override)]
|
||||
|
||||
pub fn can_fetch_more(&self, parent: &QModelIndex) -> bool {
|
||||
self.base_can_fetch_more(parent)
|
||||
}
|
||||
|
||||
#[qinvokable(cxx_override)]
|
||||
pub fn role_names(&self) -> QHash_i32_QByteArray {
|
||||
let mut roles = QHash_i32_QByteArray::default();
|
||||
roles.insert(0, cxx_qt_lib::QByteArray::from("id"));
|
||||
roles.insert(1, cxx_qt_lib::QByteArray::from("title"));
|
||||
roles.insert(2, cxx_qt_lib::QByteArray::from("filePath"));
|
||||
roles.insert(3, cxx_qt_lib::QByteArray::from("html"));
|
||||
roles
|
||||
.insert(4, cxx_qt_lib::QByteArray::from("pageCount"));
|
||||
roles.insert(
|
||||
qobject::Roles::Id.repr,
|
||||
cxx_qt_lib::QByteArray::from("id"),
|
||||
);
|
||||
roles.insert(
|
||||
qobject::Roles::Title.repr,
|
||||
cxx_qt_lib::QByteArray::from("title"),
|
||||
);
|
||||
roles.insert(
|
||||
qobject::Roles::Path.repr,
|
||||
cxx_qt_lib::QByteArray::from("filePath"),
|
||||
);
|
||||
roles.insert(
|
||||
qobject::Roles::Html.repr,
|
||||
cxx_qt_lib::QByteArray::from("html"),
|
||||
);
|
||||
roles.insert(
|
||||
qobject::Roles::PageCount.repr,
|
||||
cxx_qt_lib::QByteArray::from("pageCount"),
|
||||
);
|
||||
roles
|
||||
}
|
||||
|
||||
#[qinvokable(cxx_override)]
|
||||
pub fn row_count(&self, _parent: &QModelIndex) -> i32 {
|
||||
let cnt = self.rust().presentations.len() as i32;
|
||||
// println!("row count is {cnt}");
|
||||
cnt
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn count(&self) -> i32 {
|
||||
self.rust().presentations.len() as i32
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,40 +24,258 @@ mod service_item_model {
|
|||
type QUrl = cxx_qt_lib::QUrl;
|
||||
}
|
||||
|
||||
#[qenum(ServiceItemModel)]
|
||||
enum Role {
|
||||
Name,
|
||||
Type,
|
||||
Audio,
|
||||
Background,
|
||||
BackgroundType,
|
||||
Text,
|
||||
Font,
|
||||
FontSize,
|
||||
SlideCount,
|
||||
Active,
|
||||
Selected,
|
||||
Looping,
|
||||
VideoStartTime,
|
||||
VideoEndTime,
|
||||
}
|
||||
|
||||
unsafe extern "RustQt" {
|
||||
#[qobject]
|
||||
#[base = "QAbstractListModel"]
|
||||
#[qml_element]
|
||||
type ServiceItemModel = super::ServiceItemModelRust;
|
||||
|
||||
#[inherit]
|
||||
#[qsignal]
|
||||
fn data_changed(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
top_left: &QModelIndex,
|
||||
bottom_right: &QModelIndex,
|
||||
roles: &QVector_i32,
|
||||
);
|
||||
|
||||
#[qsignal]
|
||||
fn active_changed(self: Pin<&mut ServiceItemModel>, index: &i32);
|
||||
#[qsignal]
|
||||
fn selected_changed(self: Pin<&mut ServiceItemModel>);
|
||||
#[qsignal]
|
||||
fn item_inserted(self: Pin<&mut ServiceItemModel>, index: &i32, item: &QMap_QString_QVariant);
|
||||
#[qsignal]
|
||||
fn item_added(self: Pin<&mut ServiceItemModel>, index: &i32, item: &QMap_QString_QVariant);
|
||||
#[qsignal]
|
||||
fn item_removed(self: Pin<&mut ServiceItemModel>, index: &i32, item: &QMap_QString_QVariant);
|
||||
#[qsignal]
|
||||
fn item_moved(self: Pin<&mut ServiceItemModel>, source_index: &i32, dest_index: &i32, item: &QMap_QString_QVariant);
|
||||
#[qsignal]
|
||||
fn cleared(self: Pin<&mut ServiceItemModel>);
|
||||
|
||||
#[qinvokable]
|
||||
fn clear(self: Pin<&mut ServiceItemModel>);
|
||||
|
||||
#[qinvokable]
|
||||
fn remove_item(self: Pin<&mut ServiceItemModel>, index: i32);
|
||||
|
||||
#[qinvokable]
|
||||
fn add_item(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
name: QString,
|
||||
ty: QString,
|
||||
background: QString,
|
||||
background_type: QString,
|
||||
text: QStringList,
|
||||
audio: QString,
|
||||
font: QString,
|
||||
font_size: i32,
|
||||
slide_count: i32,
|
||||
looping: bool,
|
||||
video_start_time: f32,
|
||||
video_end_time: f32,
|
||||
);
|
||||
|
||||
#[qinvokable]
|
||||
fn insert_item(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
index: i32,
|
||||
name: QString,
|
||||
text: QStringList,
|
||||
ty: QString,
|
||||
background: QString,
|
||||
background_type: QString,
|
||||
audio: QString,
|
||||
font: QString,
|
||||
font_size: i32,
|
||||
slide_count: i32,
|
||||
looping: bool,
|
||||
video_start_time: f32,
|
||||
video_end_time: f32,
|
||||
);
|
||||
|
||||
#[qinvokable]
|
||||
fn get_item(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
index: i32,
|
||||
) -> QMap_QString_QVariant;
|
||||
|
||||
#[qinvokable]
|
||||
fn move_rows(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
source_index: i32,
|
||||
dest_index: i32,
|
||||
count: i32,
|
||||
) -> bool;
|
||||
|
||||
#[qinvokable]
|
||||
fn move_up(self: Pin<&mut ServiceItemModel>, index: i32) -> bool;
|
||||
|
||||
#[qinvokable]
|
||||
fn move_down(self: Pin<&mut ServiceItemModel>, index: i32) -> bool;
|
||||
|
||||
#[qinvokable]
|
||||
fn select(self: Pin<&mut ServiceItemModel>, index: i32) -> bool;
|
||||
|
||||
#[qinvokable]
|
||||
fn select_items(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
final_index: i32,
|
||||
) -> bool;
|
||||
|
||||
#[qinvokable]
|
||||
pub fn activate(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
index: i32,
|
||||
) -> bool;
|
||||
|
||||
#[qinvokable]
|
||||
pub fn deactivate(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
index: i32,
|
||||
) -> bool;
|
||||
|
||||
#[qinvokable]
|
||||
fn save(self: Pin<&mut ServiceItemModel>, file: QUrl) -> bool;
|
||||
|
||||
#[qinvokable]
|
||||
fn load(self: Pin<&mut ServiceItemModel>, file: QUrl) -> bool;
|
||||
}
|
||||
|
||||
impl cxx_qt::Threading for ServiceItemModel {}
|
||||
|
||||
unsafe extern "RustQt" {
|
||||
#[inherit]
|
||||
unsafe fn begin_insert_rows(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_insert_rows(self: Pin<&mut ServiceItemModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_remove_rows(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_move_rows(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
source_parent: &QModelIndex,
|
||||
source_first: i32,
|
||||
source_last: i32,
|
||||
destination_parent: &QModelIndex,
|
||||
destination_child: i32,
|
||||
) -> bool;
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_move_rows(
|
||||
self: Pin<&mut ServiceItemModel>,
|
||||
);
|
||||
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_remove_rows(self: Pin<&mut ServiceItemModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_reset_model(self: Pin<&mut ServiceItemModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_reset_model(self: Pin<&mut ServiceItemModel>);
|
||||
|
||||
#[inherit]
|
||||
fn can_fetch_more(
|
||||
self: &ServiceItemModel,
|
||||
parent: &QModelIndex,
|
||||
) -> bool;
|
||||
|
||||
#[inherit]
|
||||
fn index(
|
||||
self: &ServiceItemModel,
|
||||
row: i32,
|
||||
column: i32,
|
||||
parent: &QModelIndex,
|
||||
) -> QModelIndex;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn data(
|
||||
self: &ServiceItemModel,
|
||||
index: &QModelIndex,
|
||||
role: i32,
|
||||
) -> QVariant;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn role_names(self: &ServiceItemModel) -> QHash_i32_QByteArray;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn row_count(self: &ServiceItemModel, _parent: &QModelIndex)
|
||||
-> i32;
|
||||
|
||||
#[qinvokable]
|
||||
fn count(self: &ServiceItemModel) -> i32;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
use dirs;
|
||||
use serde_json::{json, Deserializer, Map, Serializer, Value};
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::iter;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str;
|
||||
use std::{fs, println};
|
||||
use tar::{Archive, Builder};
|
||||
use tracing::{debug, debug_span, error, info, instrument};
|
||||
use zstd::{Decoder, Encoder};
|
||||
use crate::obs::Obs;
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cxx_qt::qobject]
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ServiceItm {
|
||||
#[qproperty]
|
||||
name: QString,
|
||||
#[qproperty]
|
||||
ty: QString,
|
||||
#[qproperty]
|
||||
audio: QString,
|
||||
#[qproperty]
|
||||
background: QString,
|
||||
#[qproperty]
|
||||
background_type: QString,
|
||||
#[qproperty]
|
||||
text: QStringList,
|
||||
#[qproperty]
|
||||
font: QString,
|
||||
#[qproperty]
|
||||
font_size: i32,
|
||||
#[qproperty]
|
||||
slide_count: i32,
|
||||
#[qproperty]
|
||||
active: bool,
|
||||
#[qproperty]
|
||||
selected: bool,
|
||||
#[qproperty]
|
||||
looping: bool,
|
||||
#[qproperty]
|
||||
video_start_time: f32,
|
||||
#[qproperty]
|
||||
video_end_time: f32,
|
||||
#[qproperty]
|
||||
obs_scene: QString,
|
||||
}
|
||||
|
||||
|
@ -83,15 +301,14 @@ mod service_item_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[cxx_qt::qobject(base = "QAbstractListModel")]
|
||||
#[derive(Debug)]
|
||||
pub struct ServiceItemMod {
|
||||
pub struct ServiceItemModelRust {
|
||||
id: i32,
|
||||
service_items: Vec<ServiceItm>,
|
||||
obs: Option<Obs>,
|
||||
}
|
||||
|
||||
impl Default for ServiceItemMod {
|
||||
impl Default for ServiceItemModelRust {
|
||||
fn default() -> Self {
|
||||
let obs = tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
|
@ -112,76 +329,11 @@ mod service_item_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[cxx_qt::qsignals(ServiceItemMod)]
|
||||
pub enum Signals<'a> {
|
||||
#[inherit]
|
||||
DataChanged {
|
||||
top_left: &'a QModelIndex,
|
||||
bottom_right: &'a QModelIndex,
|
||||
roles: &'a QVector_i32,
|
||||
},
|
||||
ActiveChanged {
|
||||
index: &'a i32,
|
||||
},
|
||||
SelectedChanged,
|
||||
ItemInserted {
|
||||
index: &'a i32,
|
||||
item: &'a QMap_QString_QVariant,
|
||||
},
|
||||
ItemAdded {
|
||||
index: &'a i32,
|
||||
item: &'a QMap_QString_QVariant,
|
||||
},
|
||||
ItemRemoved {
|
||||
index: &'a i32,
|
||||
item: &'a QMap_QString_QVariant,
|
||||
},
|
||||
ItemMoved {
|
||||
source_index: &'a i32,
|
||||
dest_index: &'a i32,
|
||||
// index: &'a i32,
|
||||
item: &'a QMap_QString_QVariant,
|
||||
},
|
||||
Cleared {},
|
||||
}
|
||||
|
||||
enum Role {
|
||||
NameRole,
|
||||
TyRole,
|
||||
AudioRole,
|
||||
BackgroundRole,
|
||||
BackgroundTypeRole,
|
||||
TextRole,
|
||||
FontRole,
|
||||
FontSizeRole,
|
||||
SlideCountRole,
|
||||
ActiveRole,
|
||||
SelectedRole,
|
||||
LoopingRole,
|
||||
VideoStartTimeRole,
|
||||
VideoEndTimeRole,
|
||||
}
|
||||
|
||||
// use crate::video_thumbnail;
|
||||
// use image::{ImageBuffer, Rgba};
|
||||
use dirs;
|
||||
use serde_json::{json, Deserializer, Map, Serializer, Value};
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::iter;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str;
|
||||
use std::{fs, println};
|
||||
use tar::{Archive, Builder};
|
||||
use tracing::{debug, debug_span, error, info, instrument};
|
||||
use zstd::{Decoder, Encoder};
|
||||
|
||||
impl qobject::ServiceItemMod {
|
||||
impl qobject::ServiceItemModel {
|
||||
pub fn setup(mut self: Pin<&mut Self>) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn clear(mut self: Pin<&mut Self>) {
|
||||
println!("CLEARING ALL ITEMS");
|
||||
unsafe {
|
||||
|
@ -192,7 +344,6 @@ mod service_item_model {
|
|||
self.emit(Signals::Cleared {});
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) {
|
||||
if index < 0
|
||||
|| (index as usize) >= self.service_items().len()
|
||||
|
@ -215,7 +366,6 @@ mod service_item_model {
|
|||
self.as_mut().emit_item_removed(&index, &item);
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn add_item(
|
||||
mut self: Pin<&mut Self>,
|
||||
name: QString,
|
||||
|
@ -270,7 +420,6 @@ mod service_item_model {
|
|||
self.as_mut().emit_item_added(&index, &item);
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn insert_item(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -327,7 +476,6 @@ mod service_item_model {
|
|||
self.as_mut().emit_item_inserted(&id, &item);
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn get_item(
|
||||
self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -353,7 +501,6 @@ mod service_item_model {
|
|||
map
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn move_rows(
|
||||
mut self: Pin<&mut Self>,
|
||||
source_index: i32,
|
||||
|
@ -418,17 +565,14 @@ mod service_item_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn move_up(self: Pin<&mut Self>, index: i32) -> bool {
|
||||
self.move_rows(index, index - 1, 1)
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn move_down(self: Pin<&mut Self>, index: i32) -> bool {
|
||||
self.move_rows(index, index + 1, 1)
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn select(mut self: Pin<&mut Self>, index: i32) -> bool {
|
||||
let rc = self.as_ref().count() - 1;
|
||||
let tl =
|
||||
|
@ -464,7 +608,6 @@ mod service_item_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn select_items(
|
||||
mut self: Pin<&mut Self>,
|
||||
final_index: i32,
|
||||
|
@ -592,7 +735,6 @@ mod service_item_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn activate(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -644,12 +786,10 @@ mod service_item_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn deactivate(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
) -> bool {
|
||||
todo!();
|
||||
let rc = self.as_ref().count() - 1;
|
||||
let tl =
|
||||
&self.as_ref().index(0, 0, &QModelIndex::default());
|
||||
|
@ -689,7 +829,7 @@ mod service_item_model {
|
|||
false
|
||||
}
|
||||
}
|
||||
#[qinvokable]
|
||||
|
||||
pub fn save(mut self: Pin<&mut Self>, file: QUrl) -> bool {
|
||||
println!("rust-save-file: {file}");
|
||||
let path =
|
||||
|
@ -888,7 +1028,6 @@ mod service_item_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn load(mut self: Pin<&mut Self>, file: QUrl) -> bool {
|
||||
self.as_mut().clear();
|
||||
println!("file is: {file}");
|
||||
|
@ -1132,7 +1271,6 @@ mod service_item_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn load_last_saved(mut self: Pin<&mut Self>) -> bool {
|
||||
todo!();
|
||||
// Don't actually need
|
||||
|
@ -1159,92 +1297,32 @@ mod service_item_model {
|
|||
}
|
||||
}
|
||||
|
||||
// Create Rust bindings for C++ functions of the base class (QAbstractItem_Modelel)
|
||||
#[cxx_qt::inherit]
|
||||
extern "C++" {
|
||||
unsafe fn begin_insert_rows(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
unsafe fn end_insert_rows(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
);
|
||||
|
||||
unsafe fn begin_move_rows(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
source_parent: &QModelIndex,
|
||||
source_first: i32,
|
||||
source_last: i32,
|
||||
destination_parent: &QModelIndex,
|
||||
destination_child: i32,
|
||||
) -> bool;
|
||||
|
||||
unsafe fn end_move_rows(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
);
|
||||
|
||||
unsafe fn begin_remove_rows(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
unsafe fn end_remove_rows(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
);
|
||||
|
||||
unsafe fn begin_reset_model(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
);
|
||||
unsafe fn end_reset_model(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
);
|
||||
}
|
||||
|
||||
#[cxx_qt::inherit]
|
||||
unsafe extern "C++" {
|
||||
#[cxx_name = "canFetchMore"]
|
||||
fn base_can_fetch_more(
|
||||
self: &qobject::ServiceItemMod,
|
||||
parent: &QModelIndex,
|
||||
) -> bool;
|
||||
|
||||
fn index(
|
||||
self: &qobject::ServiceItemMod,
|
||||
row: i32,
|
||||
column: i32,
|
||||
parent: &QModelIndex,
|
||||
) -> QModelIndex;
|
||||
}
|
||||
|
||||
// QAbstractListModel implementation
|
||||
impl qobject::ServiceItemMod {
|
||||
#[qinvokable(cxx_override)]
|
||||
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
||||
let role = qobject::Roles { repr: role };
|
||||
if let Some(service_item) =
|
||||
self.service_items().get(index.row() as usize)
|
||||
{
|
||||
return match role {
|
||||
0 => QVariant::from(&service_item.name),
|
||||
1 => QVariant::from(&service_item.ty),
|
||||
2 => QVariant::from(&service_item.audio),
|
||||
3 => QVariant::from(&service_item.background),
|
||||
4 => {
|
||||
qobject::Roles::Name => QVariant::from(&service_item.name),
|
||||
qobject::Roles::Type => QVariant::from(&service_item.ty),
|
||||
qobject::Roles::Audio => QVariant::from(&service_item.audio),
|
||||
qobject::Roles::Background => QVariant::from(&service_item.background),
|
||||
qobject::Roles::BackgroundType => {
|
||||
QVariant::from(&service_item.background_type)
|
||||
}
|
||||
5 => QVariant::from(&service_item.text),
|
||||
6 => QVariant::from(&service_item.font),
|
||||
7 => QVariant::from(&service_item.font_size),
|
||||
8 => QVariant::from(&service_item.slide_count),
|
||||
9 => QVariant::from(&service_item.active),
|
||||
10 => QVariant::from(&service_item.selected),
|
||||
11 => QVariant::from(&service_item.looping),
|
||||
12 => {
|
||||
qobject::Roles::Text => QVariant::from(&service_item.text),
|
||||
qobject::Roles::Font => QVariant::from(&service_item.font),
|
||||
qobject::Roles::FontSize => QVariant::from(&service_item.font_size),
|
||||
qobject::Roles::SlideCount => QVariant::from(&service_item.slide_count),
|
||||
qobject::Roles::Active => QVariant::from(&service_item.active),
|
||||
qobject::Roles::Selected => QVariant::from(&service_item.selected),
|
||||
qobject::Roles::Looping => QVariant::from(&service_item.looping),
|
||||
qobject::Roles::VideoStartTime => {
|
||||
QVariant::from(&service_item.video_start_time)
|
||||
}
|
||||
13 => {
|
||||
qobject::Roles::VideoEndTime => {
|
||||
QVariant::from(&service_item.video_end_time)
|
||||
}
|
||||
_ => QVariant::default(),
|
||||
|
@ -1255,57 +1333,52 @@ mod service_item_model {
|
|||
}
|
||||
|
||||
// Example of overriding a C++ virtual method and calling the base class implementation.
|
||||
#[qinvokable(cxx_override)]
|
||||
pub fn can_fetch_more(&self, parent: &QModelIndex) -> bool {
|
||||
self.base_can_fetch_more(parent)
|
||||
}
|
||||
|
||||
#[qinvokable(cxx_override)]
|
||||
pub fn role_names(&self) -> QHash_i32_QByteArray {
|
||||
let mut roles = QHash_i32_QByteArray::default();
|
||||
roles.insert(0, cxx_qt_lib::QByteArray::from("name"));
|
||||
roles.insert(1, cxx_qt_lib::QByteArray::from("ty"));
|
||||
roles.insert(2, cxx_qt_lib::QByteArray::from("audio"));
|
||||
roles.insert(qobject::Roles::Name.repr, cxx_qt_lib::QByteArray::from("name"));
|
||||
roles.insert(qobject::Roles::Type.repr, cxx_qt_lib::QByteArray::from("ty"));
|
||||
roles.insert(qobject::Roles::Audio.repr, cxx_qt_lib::QByteArray::from("audio"));
|
||||
roles.insert(
|
||||
3,
|
||||
qobject::Roles::Background.repr,
|
||||
cxx_qt_lib::QByteArray::from("background"),
|
||||
);
|
||||
roles.insert(
|
||||
4,
|
||||
qobject::Roles::BackgroundType,
|
||||
cxx_qt_lib::QByteArray::from("backgroundType"),
|
||||
);
|
||||
roles.insert(5, cxx_qt_lib::QByteArray::from("text"));
|
||||
roles.insert(6, cxx_qt_lib::QByteArray::from("font"));
|
||||
roles.insert(7, cxx_qt_lib::QByteArray::from("fontSize"));
|
||||
roles.insert(qobject::Roles::Text.repr, cxx_qt_lib::QByteArray::from("text"));
|
||||
roles.insert(qobject::Roles::Font.repr, cxx_qt_lib::QByteArray::from("font"));
|
||||
roles.insert(qobject::Roles::FontSize.repr, cxx_qt_lib::QByteArray::from("fontSize"));
|
||||
roles.insert(
|
||||
8,
|
||||
qobject::Roles::SlideCount.repr,
|
||||
cxx_qt_lib::QByteArray::from("slideCount"),
|
||||
);
|
||||
roles.insert(9, cxx_qt_lib::QByteArray::from("active"));
|
||||
roles.insert(qobject::Roles::Active.repr, cxx_qt_lib::QByteArray::from("active"));
|
||||
roles
|
||||
.insert(10, cxx_qt_lib::QByteArray::from("selected"));
|
||||
roles.insert(11, cxx_qt_lib::QByteArray::from("looping"));
|
||||
.insert(qobject::Roles::Selected.repr, cxx_qt_lib::QByteArray::from("selected"));
|
||||
roles.insert(qobject::Roles::Looping.repr, cxx_qt_lib::QByteArray::from("looping"));
|
||||
roles.insert(
|
||||
12,
|
||||
qobject::Roles::VideoStartTime.repr,
|
||||
cxx_qt_lib::QByteArray::from("videoStartTime"),
|
||||
);
|
||||
roles.insert(
|
||||
13,
|
||||
qobject::Roles::VideoEndTime.repr,
|
||||
cxx_qt_lib::QByteArray::from("videoEndTime"),
|
||||
);
|
||||
roles
|
||||
}
|
||||
|
||||
#[qinvokable(cxx_override)]
|
||||
pub fn row_count(&self, _parent: &QModelIndex) -> i32 {
|
||||
let cnt = self.rust().service_items.len() as i32;
|
||||
// println!("row count is {cnt}");
|
||||
cnt
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn count(&self) -> i32 {
|
||||
self.rust().service_items.len() as i32
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -253,7 +253,6 @@ pub struct SlideModelRust {
|
|||
}
|
||||
|
||||
impl qobject::SlideModel {
|
||||
#[qinvokable]
|
||||
pub fn add_video_thumbnail(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -285,7 +284,6 @@ impl qobject::SlideModel {
|
|||
true
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn clear(mut self: Pin<&mut Self>) {
|
||||
println!("CLEARING ALL SLIDES");
|
||||
unsafe {
|
||||
|
@ -295,7 +293,6 @@ impl qobject::SlideModel {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn remove_item_from_service(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -324,7 +321,6 @@ impl qobject::SlideModel {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) {
|
||||
if index < 0 || (index as usize) >= self.slides().len() {
|
||||
return;
|
||||
|
@ -394,7 +390,6 @@ impl qobject::SlideModel {
|
|||
});
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn insert_item_from_service(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -586,7 +581,6 @@ impl qobject::SlideModel {
|
|||
println!("Item added in slide model!");
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn add_item_from_service(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -742,7 +736,6 @@ impl qobject::SlideModel {
|
|||
println!("Item added in rust model!");
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn move_item_from_service(
|
||||
mut self: Pin<&mut Self>,
|
||||
source_index: i32,
|
||||
|
@ -948,7 +941,6 @@ impl qobject::SlideModel {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn get_item(
|
||||
self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -972,7 +964,6 @@ impl qobject::SlideModel {
|
|||
qvariantmap
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn get_slide_from_service(
|
||||
self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -992,7 +983,6 @@ impl qobject::SlideModel {
|
|||
id
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn activate(mut self: Pin<&mut Self>, index: i32) -> bool {
|
||||
let rc = self.as_ref().count() - 1;
|
||||
let tl = &self.as_ref().index(0, 0, &QModelIndex::default());
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
#[cxx_qt::bridge]
|
||||
mod video_model {
|
||||
use crate::models::*;
|
||||
use crate::schema::videos::dsl::*;
|
||||
use crate::video_model::video_model::Video;
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use diesel::{delete, insert_into, prelude::*, update};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!(< QAbstractListModel >);
|
||||
include!("cxx-qt-lib/qhash.h");
|
||||
|
@ -31,6 +24,167 @@ mod video_model {
|
|||
type QList_QString = cxx_qt_lib::QList<QString>;
|
||||
}
|
||||
|
||||
#[qenum(VideoModel)]
|
||||
enum Role {
|
||||
Id,
|
||||
Title,
|
||||
Path,
|
||||
StartTime,
|
||||
EndTime,
|
||||
Looping,
|
||||
}
|
||||
|
||||
unsafe extern "RustQt" {
|
||||
#[qobject]
|
||||
#[base = "QAbstractListModel"]
|
||||
#[qml_element]
|
||||
#[qproperty(i32, count_rows)]
|
||||
type VideoModel = super::VideoModelRust;
|
||||
|
||||
#[inherit]
|
||||
#[qsignal]
|
||||
fn data_changed(
|
||||
self: Pin<&mut VideoModel>,
|
||||
top_left: &QModelIndex,
|
||||
bottom_right: &QModelIndex,
|
||||
roles: &QVector_i32,
|
||||
);
|
||||
|
||||
#[qinvokable]
|
||||
fn clear(self: Pin<&mut VideoModel>);
|
||||
#[qinvokable]
|
||||
fn setup(self: Pin<&mut VideoModel>);
|
||||
#[qinvokable]
|
||||
fn remove_item(
|
||||
self: Pin<&mut VideoModel>,
|
||||
index: i32,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn new_item(self: Pin<&mut VideoModel>, url: QUrl);
|
||||
#[qinvokable]
|
||||
fn update_path(
|
||||
self: Pin<&mut VideoModel>,
|
||||
index: i32,
|
||||
updated_path: QString,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn get_item(
|
||||
self: Pin<&mut VideoModel>,
|
||||
index: i32,
|
||||
) -> QMap_QString_QVariant;
|
||||
#[qinvokable]
|
||||
fn update_loop(
|
||||
self: Pin<&mut VideoModel>,
|
||||
index: i32,
|
||||
loop_value: bool,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn update_title(
|
||||
self: Pin<&mut VideoModel>,
|
||||
index: i32,
|
||||
updated_title: QString,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn update_start_time(
|
||||
self: Pin<&mut VideoModel>,
|
||||
index: i32,
|
||||
updated_start_time: QString,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn update_end_time(
|
||||
self: Pin<&mut VideoModel>,
|
||||
index: i32,
|
||||
updated_end_time: QString,
|
||||
) -> bool;
|
||||
}
|
||||
|
||||
impl cxx_qt::Threading for VideoModel {}
|
||||
|
||||
unsafe extern "RustQt" {
|
||||
#[inherit]
|
||||
unsafe fn begin_insert_rows(
|
||||
self: Pin<&mut VideoModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_insert_rows(self: Pin<&mut VideoModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_remove_rows(
|
||||
self: Pin<&mut VideoModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_move_rows(
|
||||
self: Pin<&mut VideoModel>,
|
||||
source_parent: &QModelIndex,
|
||||
source_first: i32,
|
||||
source_last: i32,
|
||||
destination_parent: &QModelIndex,
|
||||
destination_child: i32,
|
||||
) -> bool;
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_move_rows(self: Pin<&mut VideoModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_remove_rows(self: Pin<&mut VideoModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn begin_reset_model(self: Pin<&mut VideoModel>);
|
||||
|
||||
#[inherit]
|
||||
unsafe fn end_reset_model(self: Pin<&mut VideoModel>);
|
||||
|
||||
#[inherit]
|
||||
fn can_fetch_more(
|
||||
self: &VideoModel,
|
||||
parent: &QModelIndex,
|
||||
) -> bool;
|
||||
|
||||
#[inherit]
|
||||
fn index(
|
||||
self: &VideoModel,
|
||||
row: i32,
|
||||
column: i32,
|
||||
parent: &QModelIndex,
|
||||
) -> QModelIndex;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn data(
|
||||
self: &VideoModel,
|
||||
index: &QModelIndex,
|
||||
role: i32,
|
||||
) -> QVariant;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn role_names(self: &VideoModel) -> QHash_i32_QByteArray;
|
||||
|
||||
#[qinvokable]
|
||||
#[cxx_override]
|
||||
fn row_count(self: &VideoModel, _parent: &QModelIndex)
|
||||
-> i32;
|
||||
|
||||
#[qinvokable]
|
||||
fn count(self: &VideoModel) -> i32;
|
||||
}
|
||||
}
|
||||
|
||||
use crate::models::*;
|
||||
use crate::schema::videos::dsl::*;
|
||||
use crate::video_model::video_model::Video;
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use diesel::{delete, insert_into, prelude::*, update};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct Video {
|
||||
id: i32,
|
||||
|
@ -41,34 +195,13 @@ mod video_model {
|
|||
looping: bool,
|
||||
}
|
||||
|
||||
#[cxx_qt::qobject(base = "QAbstractListModel")]
|
||||
#[derive(Default, Debug)]
|
||||
pub struct VideoModel {
|
||||
pub struct VideoModelRust {
|
||||
highest_id: i32,
|
||||
videos: Vec<self::Video>,
|
||||
}
|
||||
|
||||
#[cxx_qt::qsignals(VideoModel)]
|
||||
pub enum Signals<'a> {
|
||||
#[inherit]
|
||||
DataChanged {
|
||||
top_left: &'a QModelIndex,
|
||||
bottom_right: &'a QModelIndex,
|
||||
roles: &'a QVector_i32,
|
||||
},
|
||||
}
|
||||
|
||||
enum Role {
|
||||
IdRole,
|
||||
TitleRole,
|
||||
PathRole,
|
||||
StartTimeRole,
|
||||
EndTimeRole,
|
||||
LoopingRole,
|
||||
}
|
||||
|
||||
impl qobject::VideoModel {
|
||||
#[qinvokable]
|
||||
pub fn clear(mut self: Pin<&mut Self>) {
|
||||
unsafe {
|
||||
self.as_mut().begin_reset_model();
|
||||
|
@ -77,7 +210,6 @@ mod video_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn setup(mut self: Pin<&mut Self>) {
|
||||
let db = &mut self.as_mut().get_db();
|
||||
let results = videos
|
||||
|
@ -112,18 +244,13 @@ mod video_model {
|
|||
println!("--------------------------------------");
|
||||
}
|
||||
|
||||
#[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() {
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
|
@ -136,9 +263,7 @@ mod video_model {
|
|||
index,
|
||||
index,
|
||||
);
|
||||
self.as_mut()
|
||||
.videos_mut()
|
||||
.remove(index as usize);
|
||||
self.as_mut().videos_mut().remove(index as usize);
|
||||
self.as_mut().end_remove_rows();
|
||||
}
|
||||
println!("removed-item-at-index: {:?}", video_id);
|
||||
|
@ -160,26 +285,20 @@ mod video_model {
|
|||
db_url.push_str(data.to_str().unwrap());
|
||||
println!("DB: {:?}", db_url);
|
||||
|
||||
SqliteConnection::establish(&db_url).unwrap_or_else(
|
||||
|_| panic!("error connecting to {}", db_url),
|
||||
)
|
||||
SqliteConnection::establish(&db_url).unwrap_or_else(|_| {
|
||||
panic!("error connecting to {}", db_url)
|
||||
})
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn new_item(mut self: Pin<&mut Self>, url: QUrl) {
|
||||
println!("LETS INSERT THIS SUCKER!");
|
||||
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_title = QString::from(name);
|
||||
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);
|
||||
self.as_mut().set_highest_id(video_id);
|
||||
} else {
|
||||
|
@ -187,7 +306,6 @@ mod video_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn add_item(
|
||||
mut self: Pin<&mut Self>,
|
||||
video_id: i32,
|
||||
|
@ -247,7 +365,6 @@ mod video_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn get_item(
|
||||
self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -260,9 +377,7 @@ mod video_model {
|
|||
}
|
||||
let role_names = self.as_ref().role_names();
|
||||
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 {
|
||||
qvariantmap.insert(
|
||||
QString::from(&i.1.to_string()),
|
||||
|
@ -286,7 +401,6 @@ mod video_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn update_loop(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -295,11 +409,8 @@ mod video_model {
|
|||
let mut vector_roles = QVector_i32::default();
|
||||
vector_roles
|
||||
.append(self.as_ref().get_role(Role::LoopingRole));
|
||||
let model_index = &self.as_ref().index(
|
||||
index,
|
||||
0,
|
||||
&QModelIndex::default(),
|
||||
);
|
||||
let model_index =
|
||||
&self.as_ref().index(index, 0, &QModelIndex::default());
|
||||
println!("rust-video: {:?}", index);
|
||||
println!("rust-loop: {:?}", loop_value);
|
||||
|
||||
|
@ -330,7 +441,6 @@ mod video_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn update_end_time(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -339,11 +449,8 @@ mod video_model {
|
|||
let mut vector_roles = QVector_i32::default();
|
||||
vector_roles
|
||||
.append(self.as_ref().get_role(Role::EndTimeRole));
|
||||
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 result = update(videos.filter(id.eq(index)))
|
||||
|
@ -371,7 +478,6 @@ mod video_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn update_start_time(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
|
@ -380,11 +486,8 @@ mod video_model {
|
|||
let mut vector_roles = QVector_i32::default();
|
||||
vector_roles
|
||||
.append(self.as_ref().get_role(Role::StartTimeRole));
|
||||
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 result = update(videos.filter(id.eq(index)))
|
||||
|
@ -405,30 +508,22 @@ mod video_model {
|
|||
model_index,
|
||||
&vector_roles,
|
||||
);
|
||||
println!(
|
||||
"rust-start-time: {:?}",
|
||||
updated_start_time
|
||||
);
|
||||
println!("rust-start-time: {:?}", updated_start_time);
|
||||
true
|
||||
}
|
||||
Err(_e) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn update_title(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
updated_title: QString,
|
||||
) -> bool {
|
||||
let mut vector_roles = QVector_i32::default();
|
||||
vector_roles
|
||||
.append(self.as_ref().get_role(Role::TitleRole));
|
||||
let model_index = &self.as_ref().index(
|
||||
index,
|
||||
0,
|
||||
&QModelIndex::default(),
|
||||
);
|
||||
vector_roles.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 result = update(videos.filter(id.eq(index)))
|
||||
|
@ -459,20 +554,15 @@ mod video_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn update_path(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
updated_path: QString,
|
||||
) -> bool {
|
||||
let mut vector_roles = QVector_i32::default();
|
||||
vector_roles
|
||||
.append(self.as_ref().get_role(Role::PathRole));
|
||||
let model_index = &self.as_ref().index(
|
||||
index,
|
||||
0,
|
||||
&QModelIndex::default(),
|
||||
);
|
||||
vector_roles.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 result = update(videos.filter(id.eq(index)))
|
||||
|
@ -502,67 +592,24 @@ mod video_model {
|
|||
}
|
||||
}
|
||||
|
||||
// Create Rust bindings for C++ functions of the base class (QAbstractItemModel)
|
||||
#[cxx_qt::inherit]
|
||||
extern "C++" {
|
||||
unsafe fn begin_insert_rows(
|
||||
self: Pin<&mut qobject::VideoModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
unsafe fn end_insert_rows(
|
||||
self: Pin<&mut qobject::VideoModel>,
|
||||
);
|
||||
|
||||
unsafe fn begin_remove_rows(
|
||||
self: Pin<&mut qobject::VideoModel>,
|
||||
parent: &QModelIndex,
|
||||
first: i32,
|
||||
last: i32,
|
||||
);
|
||||
unsafe fn end_remove_rows(
|
||||
self: Pin<&mut qobject::VideoModel>,
|
||||
);
|
||||
|
||||
unsafe fn begin_reset_model(
|
||||
self: Pin<&mut qobject::VideoModel>,
|
||||
);
|
||||
unsafe fn end_reset_model(
|
||||
self: Pin<&mut qobject::VideoModel>,
|
||||
);
|
||||
}
|
||||
|
||||
#[cxx_qt::inherit]
|
||||
unsafe extern "C++" {
|
||||
#[cxx_name = "canFetchMore"]
|
||||
fn base_can_fetch_more(
|
||||
self: &qobject::VideoModel,
|
||||
parent: &QModelIndex,
|
||||
) -> bool;
|
||||
|
||||
fn index(
|
||||
self: &qobject::VideoModel,
|
||||
row: i32,
|
||||
column: i32,
|
||||
parent: &QModelIndex,
|
||||
) -> QModelIndex;
|
||||
}
|
||||
|
||||
// QAbstractListModel implementation
|
||||
impl qobject::VideoModel {
|
||||
#[qinvokable(cxx_override)]
|
||||
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
||||
if let Some(video) =
|
||||
self.videos().get(index.row() as usize)
|
||||
{
|
||||
let role = qobject::Roles { repr: role };
|
||||
if let Some(video) = self.videos().get(index.row() as usize) {
|
||||
return match role {
|
||||
0 => QVariant::from(&video.id),
|
||||
1 => QVariant::from(&video.title),
|
||||
2 => QVariant::from(&video.path),
|
||||
3 => QVariant::from(&video.start_time),
|
||||
4 => QVariant::from(&video.end_time),
|
||||
5 => QVariant::from(&video.looping),
|
||||
qobject::Role::Id => QVariant::from(&video.id),
|
||||
qobject::Role::Title => QVariant::from(&video.title),
|
||||
qobject::Role::Path => QVariant::from(&video.path),
|
||||
qobject::Role::StartTime => {
|
||||
QVariant::from(&video.start_time)
|
||||
}
|
||||
qobject::Role::EndTime => {
|
||||
QVariant::from(&video.end_time)
|
||||
}
|
||||
qobject::Role::Looping => {
|
||||
QVariant::from(&video.looping)
|
||||
}
|
||||
_ => QVariant::default(),
|
||||
};
|
||||
}
|
||||
|
@ -571,34 +618,47 @@ mod video_model {
|
|||
}
|
||||
|
||||
// Example of overriding a C++ virtual method and calling the base class implementation.
|
||||
#[qinvokable(cxx_override)]
|
||||
|
||||
pub fn can_fetch_more(&self, parent: &QModelIndex) -> bool {
|
||||
self.base_can_fetch_more(parent)
|
||||
}
|
||||
|
||||
#[qinvokable(cxx_override)]
|
||||
pub fn role_names(&self) -> QHash_i32_QByteArray {
|
||||
let mut roles = QHash_i32_QByteArray::default();
|
||||
roles.insert(0, cxx_qt_lib::QByteArray::from("id"));
|
||||
roles.insert(1, cxx_qt_lib::QByteArray::from("title"));
|
||||
roles.insert(2, cxx_qt_lib::QByteArray::from("filePath"));
|
||||
roles
|
||||
.insert(3, cxx_qt_lib::QByteArray::from("startTime"));
|
||||
roles.insert(4, cxx_qt_lib::QByteArray::from("endTime"));
|
||||
roles.insert(5, cxx_qt_lib::QByteArray::from("loop"));
|
||||
roles.insert(
|
||||
qobject::Roles::Id.repr,
|
||||
cxx_qt_lib::QByteArray::from("id"),
|
||||
);
|
||||
roles.insert(
|
||||
qobject::Roles::Title.repr,
|
||||
cxx_qt_lib::QByteArray::from("title"),
|
||||
);
|
||||
roles.insert(
|
||||
qobject::Roles::Path.repr,
|
||||
cxx_qt_lib::QByteArray::from("filePath"),
|
||||
);
|
||||
roles.insert(
|
||||
qobject::Roles::StartTime.repr,
|
||||
cxx_qt_lib::QByteArray::from("startTime"),
|
||||
);
|
||||
roles.insert(
|
||||
qobject::Roles::EndTime.repr,
|
||||
cxx_qt_lib::QByteArray::from("endTime"),
|
||||
);
|
||||
roles.insert(
|
||||
qobject::Roles::Looping.repr,
|
||||
cxx_qt_lib::QByteArray::from("loop"),
|
||||
);
|
||||
roles
|
||||
}
|
||||
|
||||
#[qinvokable(cxx_override)]
|
||||
pub fn row_count(&self, _parent: &QModelIndex) -> i32 {
|
||||
let cnt = self.rust().videos.len() as i32;
|
||||
// println!("row count is {cnt}");
|
||||
cnt
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn count(&self) -> i32 {
|
||||
self.rust().videos.len() as i32
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue