rust side builds but having trouble linking in main.cpp

This commit is contained in:
Chris Cochrun 2025-03-12 09:35:36 -05:00
parent fbcb6afc7a
commit 92f2b18a20
14 changed files with 377 additions and 140 deletions

View file

@ -31,19 +31,19 @@
// #include "cpp/mpv/mpvproperties.h"
// RUST
#include "cxx-qt-gen/file_helper.cxxqt.h"
#include "cxx-qt-gen/slide_object.cxxqt.h"
#include "cxx-qt-gen/slide_model.cxxqt.h"
#include "cxx-qt-gen/service_item_model.cxxqt.h"
#include "cxx-qt-gen/settings.cxxqt.h"
#include "cxx-qt-gen/ytdl.cxxqt.h"
#include "cxx-qt-gen/presentation_model.cxxqt.h"
#include "cxx-qt-gen/song_model.cxxqt.h"
#include "cxx-qt-gen/video_model.cxxqt.h"
#include "cxx-qt-gen/image_model.cxxqt.h"
#include "cxx-qt-gen/utils.cxxqt.h"
#include "cxx-qt-gen/song_editor.cxxqt.h"
#include "cxx-qt-gen/obs.cxxqt.h"
#include <liblumina/src/rust/file_helper.cxxqt.h>
#include <liblumina/src/rust/slide_object.cxxqt.h>
#include <liblumina/src/rust/slide_model.cxxqt.h>
#include <liblumina/src/rust/service_item_model.cxxqt.h>
#include <liblumina/src/rust/settings.cxxqt.h>
#include <liblumina/src/rust/ytdl.cxxqt.h>
#include <liblumina/src/rust/presentation_model.cxxqt.h>
#include <liblumina/src/rust/songs/song_model.cxxqt.h>
#include <liblumina/src/rust/video_model.cxxqt.h>
#include <liblumina/src/rust/image_model.cxxqt.h>
#include <liblumina/src/rust/utils.cxxqt.h>
#include <liblumina/src/rust/songs/song_editor.cxxqt.h>
#include <liblumina/src/rust/obs.cxxqt.h>
static QWindow *windowFromEngine(QQmlApplicationEngine *engine)
{

View file

@ -2,6 +2,7 @@
pub mod image_model {
unsafe extern "C++" {
include!(< QAbstractListModel >);
type QAbstractListModel;
include!("cxx-qt-lib/qhash.h");
type QHash_i32_QByteArray =
cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
@ -33,13 +34,14 @@ pub mod image_model {
unsafe extern "RustQt" {
#[qobject]
#[base = "QAbstractListModel"]
#[base = QAbstractListModel]
#[qml_element]
#[qproperty(i32, count)]
type ImageModel = super::ImageModelRust;
#[inherit]
#[qsignal]
#[cxx_name = "dataChanged"]
fn data_changed(
self: Pin<&mut ImageModel>,
top_left: &QModelIndex,
@ -83,6 +85,7 @@ pub mod image_model {
unsafe extern "RustQt" {
#[inherit]
#[cxx_name = "beginInsertRows"]
unsafe fn begin_insert_rows(
self: Pin<&mut ImageModel>,
parent: &QModelIndex,
@ -91,9 +94,11 @@ pub mod image_model {
);
#[inherit]
#[cxx_name = "endInsertRows"]
unsafe fn end_insert_rows(self: Pin<&mut ImageModel>);
#[inherit]
#[cxx_name = "beginRemoveRows"]
unsafe fn begin_remove_rows(
self: Pin<&mut ImageModel>,
parent: &QModelIndex,
@ -102,6 +107,7 @@ pub mod image_model {
);
#[inherit]
#[cxx_name = "beginMoveRows"]
unsafe fn begin_move_rows(
self: Pin<&mut ImageModel>,
source_parent: &QModelIndex,
@ -112,18 +118,23 @@ pub mod image_model {
) -> bool;
#[inherit]
#[cxx_name = "endMoveRows"]
unsafe fn end_move_rows(self: Pin<&mut ImageModel>);
#[inherit]
#[cxx_name = "endRemoveRows"]
unsafe fn end_remove_rows(self: Pin<&mut ImageModel>);
#[inherit]
#[cxx_name = "beginResetModel"]
unsafe fn begin_reset_model(self: Pin<&mut ImageModel>);
#[inherit]
#[cxx_name = "endResetModel"]
unsafe fn end_reset_model(self: Pin<&mut ImageModel>);
#[inherit]
#[cxx_name = "canFetchMore"]
fn can_fetch_more(
self: &ImageModel,
parent: &QModelIndex,
@ -147,18 +158,20 @@ pub mod image_model {
#[qinvokable]
#[cxx_override]
#[cxx_name = "roleNames"]
fn role_names(self: &ImageModel) -> QHash_i32_QByteArray;
#[qinvokable]
#[cxx_override]
#[cxx_name = "rowCount"]
fn row_count(self: &ImageModel, _parent: &QModelIndex)
-> i32;
-> i32;
}
}
use cxx_qt::CxxQtType;
use cxx_qt_lib::{QModelIndex, QString, QUrl, QVariant};
use sqlx::{query, query_as, Connection, SqliteConnection};
use sqlx::{Connection, SqliteConnection, query, query_as};
use std::path::PathBuf;
use std::pin::Pin;
use tracing::{debug, error};

View file

@ -4,8 +4,20 @@ pub mod settings;
fn main() {
let mut app = QGuiApplication::new();
let mut engine = QQmlApplicationEngine::new();
let mut kde_qml_dir =
String::from("/usr/lib/x86_64-linux-gnu/qt6/qml/");
if let Ok(qml_dir) = env::var("NIXPKGS_QT6_QML_IMPORT_PATH") {
kde_qml_dir = qml_dir;
} else {
println!(
"cargo:warning=KDE_QMLDIR is not defined, used default value: {}",
kde_qml_dir
);
}
if let Some(engine) = engine.as_mut() {
engine.add_import_path(&QString::from(kde_qml_dir.as_str()));
engine.load(&QUrl::from(
"qrc:/qt/qml/com/cochrun/xyz/qml/main.qml",
));

View file

@ -2,6 +2,7 @@
pub mod presentation_model {
unsafe extern "C++" {
include!(< QAbstractListModel >);
type QAbstractListModel;
include!("cxx-qt-lib/qhash.h");
type QHash_i32_QByteArray =
cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
@ -35,13 +36,14 @@ pub mod presentation_model {
unsafe extern "RustQt" {
#[qobject]
#[base = "QAbstractListModel"]
#[base = QAbstractListModel]
#[qml_element]
#[qproperty(i32, count)]
type PresentationModel = super::PresentationModelRust;
#[inherit]
#[qsignal]
#[cxx_name = "dataChanged"]
fn data_changed(
self: Pin<&mut PresentationModel>,
top_left: &QModelIndex,
@ -101,6 +103,7 @@ pub mod presentation_model {
unsafe extern "RustQt" {
#[inherit]
#[cxx_name = "beginInsertRows"]
unsafe fn begin_insert_rows(
self: Pin<&mut PresentationModel>,
parent: &QModelIndex,
@ -109,9 +112,11 @@ pub mod presentation_model {
);
#[inherit]
#[cxx_name = "endInsertRows"]
unsafe fn end_insert_rows(self: Pin<&mut PresentationModel>);
#[inherit]
#[cxx_name = "beginRemoveRows"]
unsafe fn begin_remove_rows(
self: Pin<&mut PresentationModel>,
parent: &QModelIndex,
@ -120,6 +125,7 @@ pub mod presentation_model {
);
#[inherit]
#[cxx_name = "beginMoveRows"]
unsafe fn begin_move_rows(
self: Pin<&mut PresentationModel>,
source_parent: &QModelIndex,
@ -130,20 +136,25 @@ pub mod presentation_model {
) -> bool;
#[inherit]
#[cxx_name = "endMoveRows"]
unsafe fn end_move_rows(self: Pin<&mut PresentationModel>);
#[inherit]
#[cxx_name = "endRemoveRows"]
unsafe fn end_remove_rows(self: Pin<&mut PresentationModel>);
#[inherit]
#[cxx_name = "beginResetModel"]
unsafe fn begin_reset_model(
self: Pin<&mut PresentationModel>,
);
#[inherit]
#[cxx_name = "endResetModel"]
unsafe fn end_reset_model(self: Pin<&mut PresentationModel>);
#[inherit]
#[cxx_name = "canFetchMore"]
fn can_fetch_more(
self: &PresentationModel,
parent: &QModelIndex,
@ -167,12 +178,14 @@ pub mod presentation_model {
#[qinvokable]
#[cxx_override]
#[cxx_name = "roleNames"]
fn role_names(
self: &PresentationModel,
) -> QHash_i32_QByteArray;
#[qinvokable]
#[cxx_override]
#[cxx_name = "rowCount"]
fn row_count(
self: &PresentationModel,
_parent: &QModelIndex,
@ -184,7 +197,7 @@ use crate::presentation_model::presentation_model::QMap_QString_QVariant;
use crate::reveal_js;
use cxx_qt::CxxQtType;
use cxx_qt_lib::{QModelIndex, QString, QUrl, QVariant};
use sqlx::{query, query_as, Connection, SqliteConnection};
use sqlx::{Connection, SqliteConnection, query, query_as};
use std::path::PathBuf;
use std::pin::Pin;
use tracing::{debug, error};

View file

@ -2,6 +2,7 @@
mod service_item_model {
unsafe extern "C++" {
include!(< QAbstractListModel >);
type QAbstractListModel;
include!("cxx-qt-lib/qhash.h");
type QHash_i32_QByteArray =
cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
@ -45,7 +46,7 @@ mod service_item_model {
unsafe extern "RustQt" {
#[qobject]
#[base = "QAbstractListModel"]
#[base = QAbstractListModel]
#[qml_element]
#[qproperty(i32, count)]
#[qproperty(f32, save_progress)]
@ -54,6 +55,7 @@ mod service_item_model {
#[inherit]
#[qsignal]
#[cxx_name = "dataChanged"]
fn data_changed(
self: Pin<&mut ServiceItemModel>,
top_left: &QModelIndex,
@ -182,17 +184,18 @@ mod service_item_model {
#[qinvokable]
fn save(self: Pin<&mut ServiceItemModel>, file: QUrl)
-> bool;
-> bool;
#[qinvokable]
fn load(self: Pin<&mut ServiceItemModel>, file: QUrl)
-> bool;
-> bool;
}
impl cxx_qt::Threading for ServiceItemModel {}
unsafe extern "RustQt" {
#[inherit]
#[cxx_name = "beginInsertRows"]
unsafe fn begin_insert_rows(
self: Pin<&mut ServiceItemModel>,
parent: &QModelIndex,
@ -201,9 +204,11 @@ mod service_item_model {
);
#[inherit]
#[cxx_name = "endInsertRows"]
unsafe fn end_insert_rows(self: Pin<&mut ServiceItemModel>);
#[inherit]
#[cxx_name = "beginRemoveRows"]
unsafe fn begin_remove_rows(
self: Pin<&mut ServiceItemModel>,
parent: &QModelIndex,
@ -212,6 +217,7 @@ mod service_item_model {
);
#[inherit]
#[cxx_name = "beginMoveRows"]
unsafe fn begin_move_rows(
self: Pin<&mut ServiceItemModel>,
source_parent: &QModelIndex,
@ -222,18 +228,23 @@ mod service_item_model {
) -> bool;
#[inherit]
#[cxx_name = "endMoveRows"]
unsafe fn end_move_rows(self: Pin<&mut ServiceItemModel>);
#[inherit]
#[cxx_name = "endRemoveRows"]
unsafe fn end_remove_rows(self: Pin<&mut ServiceItemModel>);
#[inherit]
#[cxx_name = "beginResetModel"]
unsafe fn begin_reset_model(self: Pin<&mut ServiceItemModel>);
#[inherit]
#[cxx_name = "endResetModel"]
unsafe fn end_reset_model(self: Pin<&mut ServiceItemModel>);
#[inherit]
#[cxx_name = "canFetchMore"]
fn can_fetch_more(
self: &ServiceItemModel,
parent: &QModelIndex,
@ -257,12 +268,14 @@ mod service_item_model {
#[qinvokable]
#[cxx_override]
#[cxx_name = "roleNames"]
fn role_names(
self: &ServiceItemModel,
) -> QHash_i32_QByteArray;
#[qinvokable]
#[cxx_override]
#[cxx_name = "rowCount"]
fn row_count(
self: &ServiceItemModel,
_parent: &QModelIndex,
@ -277,7 +290,7 @@ use self::service_item_model::{
};
use crate::service_item_model::service_item_model::QList_QString;
use crate::slide_types::SlideType;
use crate::songs::song_model::{get_song, Song};
use crate::songs::song_model::{Song, get_song};
use crate::{image_model, presentation_model, video_model};
use cxx_qt::{CxxQtType, Threading};
use cxx_qt_lib::{
@ -285,7 +298,7 @@ use cxx_qt_lib::{
};
use dirs;
// use lumina_core::service_items::ServiceItem as SI;
use serde_json::{json, Value};
use serde_json::{Value, json};
use std::iter;
use std::path::{Path, PathBuf};
use std::pin::Pin;
@ -1295,7 +1308,9 @@ impl service_item_model::ServiceItemModel {
..Default::default()
};
self.as_mut().add_service_item(&service_item);
error!("Loaded service item with generic type since it was an unknown type.");
error!(
"Loaded service item with generic type since it was an unknown type."
);
// // files implement the Read trait
}
}

View file

@ -2,6 +2,7 @@
pub mod slide_model {
unsafe extern "C++" {
include!(< QAbstractListModel >);
type QAbstractListModel;
include!("cxx-qt-lib/qhash.h");
type QHash_i32_QByteArray =
cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
@ -18,20 +19,23 @@ pub mod slide_model {
type QVector_i32 = cxx_qt_lib::QVector<i32>;
include!("cxx-qt-lib/qlist.h");
type QList_QString = cxx_qt_lib::QList<QString>;
include!("cxx-qt-gen/slide_object.cxxqt.h");
type SlideObject =
crate::slide_object::slide_object::SlideObject;
include!("cxx-qt-gen/song_model.cxxqt.h");
include!("src/rust/slide_object.cxxqt.h");
type SlideObject = crate::slide_object::qobject::SlideObject;
include!("src/rust/songs/song_model.cxxqt.h");
type SongModel =
crate::songs::song_model::song_model::SongModel;
include!("cxx-qt-gen/video_model.cxxqt.h");
include!("src/rust/video_model.cxxqt.h");
type VideoModel = crate::video_model::video_model::VideoModel;
include!("cxx-qt-gen/image_model.cxxqt.h");
include!("src/rust/image_model.cxxqt.h");
type ImageModel = crate::image_model::image_model::ImageModel;
include!("cxx-qt-gen/presentation_model.cxxqt.h");
include!("src/rust/presentation_model.cxxqt.h");
type PresentationModel = crate::presentation_model::presentation_model::PresentationModel;
}
// extern "C++" {
// type SlideObject = crate::slide_object::qobject::SlideObject;
// }
#[qenum(SlideModel)]
enum SlideRoles {
Ty,
@ -58,7 +62,7 @@ pub mod slide_model {
unsafe extern "RustQt" {
#[qobject]
#[base = "QAbstractListModel"]
#[base = QAbstractListModel]
#[qml_element]
#[qproperty(i32, count)]
#[qproperty(*mut SlideObject, slide_object)]
@ -70,6 +74,7 @@ pub mod slide_model {
#[inherit]
#[qsignal]
#[cxx_name = "dataChanged"]
fn data_changed(
self: Pin<&mut SlideModel>,
top_left: &QModelIndex,
@ -155,6 +160,7 @@ pub mod slide_model {
unsafe extern "RustQt" {
#[inherit]
#[cxx_name = "beginInsertRows"]
unsafe fn begin_insert_rows(
self: Pin<&mut SlideModel>,
parent: &QModelIndex,
@ -163,9 +169,11 @@ pub mod slide_model {
);
#[inherit]
#[cxx_name = "endInsertRows"]
unsafe fn end_insert_rows(self: Pin<&mut SlideModel>);
#[inherit]
#[cxx_name = "beginRemoveRows"]
unsafe fn begin_remove_rows(
self: Pin<&mut SlideModel>,
parent: &QModelIndex,
@ -174,15 +182,19 @@ pub mod slide_model {
);
#[inherit]
#[cxx_name = "endRemoveRows"]
unsafe fn end_remove_rows(self: Pin<&mut SlideModel>);
#[inherit]
#[cxx_name = "beginResetModel"]
unsafe fn begin_reset_model(self: Pin<&mut SlideModel>);
#[inherit]
#[cxx_name = "endResetModel"]
unsafe fn end_reset_model(self: Pin<&mut SlideModel>);
#[inherit]
#[cxx_name = "beginMoveRows"]
unsafe fn begin_move_rows(
self: Pin<&mut SlideModel>,
source_parent: &QModelIndex,
@ -193,9 +205,11 @@ pub mod slide_model {
) -> bool;
#[inherit]
#[cxx_name = "endMoveRows"]
unsafe fn end_move_rows(self: Pin<&mut SlideModel>);
#[inherit]
#[cxx_name = "canFetchMore"]
fn can_fetch_more(
self: &SlideModel,
parent: &QModelIndex,
@ -219,12 +233,14 @@ pub mod slide_model {
#[qinvokable]
#[cxx_override]
#[cxx_name = "roleNames"]
fn role_names(self: &SlideModel) -> QHash_i32_QByteArray;
#[qinvokable]
#[cxx_override]
#[cxx_name = "rowCount"]
fn row_count(self: &SlideModel, _parent: &QModelIndex)
-> i32;
-> i32;
}
}
@ -238,12 +254,12 @@ use crate::presentation_model::{
};
use crate::slide_model::slide_model::QList_QString;
use crate::songs::song_model::song_model::{self, SongModel};
use crate::songs::song_model::{get_song, Song, SongModelRust};
use crate::songs::song_model::{Song, SongModelRust, get_song};
use crate::video_model::video_model::VideoModel;
use crate::video_model::{self, Video, VideoModelRust};
use crate::{ffmpeg, slide_types::SlideType};
use color_eyre::eyre::Result;
use color_eyre::Section;
use color_eyre::eyre::Result;
use cxx_qt::{CxxQtType, Threading};
use cxx_qt_lib::{
CaseSensitivity, QByteArray, QList, QModelIndex, QString,
@ -324,7 +340,9 @@ impl Display for ParseSlideError {
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
let message = match self {
Self::UnknownType => "The type does not exist. It needs to be one of 'song', 'video', 'image', 'presentation', or 'content'",
Self::UnknownType => {
"The type does not exist. It needs to be one of 'song', 'video', 'image', 'presentation', or 'content'"
}
};
write!(f, "Error: {message}")
}
@ -798,7 +816,9 @@ impl slide_model::SlideModel {
// Change the service_item_id of the moved slide
if count > 1 {
if move_down {
debug!("While moving down, change service items id of moved slide");
debug!(
"While moving down, change service items id of moved slide"
);
for (i, _slide) in slides_iter
.clone()
.enumerate()
@ -816,13 +836,16 @@ impl slide_model::SlideModel {
debug!(
?slide,
"rust: these ones right here officer. from {:?} to {:?}",
slide.service_item_id, destination_index
slide.service_item_id,
destination_index
);
slide.service_item_id = destination_index;
}
}
} else {
debug!("While moving up, change service items id of moved slide");
debug!(
"While moving up, change service items id of moved slide"
);
for (i, _slide) in slides_iter
.clone()
.enumerate()
@ -835,7 +858,8 @@ impl slide_model::SlideModel {
debug!(
?slide,
"rust: these ones right here officer. from {:?} to {:?}",
slide.service_item_id, destination_index
slide.service_item_id,
destination_index
);
slide.service_item_id = destination_index;
}
@ -907,7 +931,9 @@ impl slide_model::SlideModel {
// self.as_mut().end_reset_model();
// }
debug!("rust-move: {first_slide} to {dest_slide} with {count} slides");
debug!(
"rust-move: {first_slide} to {dest_slide} with {count} slides"
);
}
fn move_items(

View file

@ -1,5 +1,5 @@
#[cxx_qt::bridge]
pub mod slide_object {
pub mod qobject {
unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString;
@ -11,6 +11,28 @@ pub mod slide_object {
}
unsafe extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(i32, slide_index)]
#[qproperty(i32, slide_size)]
#[qproperty(i32, inner_slide_index)]
#[qproperty(bool, is_playing)]
#[qproperty(bool, looping)]
#[qproperty(QString, text)]
#[qproperty(QString, ty)]
#[qproperty(QString, audio)]
#[qproperty(QString, image_background)]
#[qproperty(QString, video_background)]
#[qproperty(bool, html)]
#[qproperty(QString, vtext_alignment)]
#[qproperty(QString, htext_alignment)]
#[qproperty(QString, font)]
#[qproperty(i32, font_size)]
#[qproperty(f32, video_start_time)]
#[qproperty(f32, video_end_time)]
// #[qproperty(*mut SlideModel, slide_model)]
type SlideObject = super::SlideObjectRust;
#[qsignal]
fn playing_changed(
self: Pin<&mut SlideObject>,
@ -35,28 +57,6 @@ pub mod slide_object {
#[qsignal]
fn reveal_prev(self: Pin<&mut SlideObject>);
#[qobject]
#[qml_element]
#[qproperty(i32, slide_index)]
#[qproperty(i32, slide_size)]
#[qproperty(i32, inner_slide_index)]
#[qproperty(bool, is_playing)]
#[qproperty(bool, looping)]
#[qproperty(QString, text)]
#[qproperty(QString, ty)]
#[qproperty(QString, audio)]
#[qproperty(QString, image_background)]
#[qproperty(QString, video_background)]
#[qproperty(bool, html)]
#[qproperty(QString, vtext_alignment)]
#[qproperty(QString, htext_alignment)]
#[qproperty(QString, font)]
#[qproperty(i32, font_size)]
#[qproperty(f32, video_start_time)]
#[qproperty(f32, video_end_time)]
// #[qproperty(*mut SlideModel, slide_model)]
type SlideObject = super::SlideObjectRust;
#[qinvokable]
fn change_slide(
self: Pin<&mut SlideObject>,
@ -89,11 +89,11 @@ use cxx_qt_lib::{CaseSensitivity, QString, QVariant};
use tracing::{debug, error};
use crate::{
slide_model::{slide_model, Slide},
slide_model::{Slide, slide_model},
slide_types::SlideType,
};
use self::slide_object::QMap_QString_QVariant;
use self::qobject::QMap_QString_QVariant;
#[derive(Clone, Debug)]
pub struct SlideObjectRust {
@ -142,7 +142,7 @@ impl Default for SlideObjectRust {
}
}
impl slide_object::SlideObject {
impl qobject::SlideObject {
pub fn change_slide(
mut self: Pin<&mut Self>,
item: QMap_QString_QVariant,

View file

@ -15,7 +15,7 @@ pub mod song_editor {
include!("cxx-qt-lib/qlist.h");
type QList_QString = cxx_qt_lib::QList<QString>;
include!("cxx-qt-gen/song_model.cxxqt.h");
include!("src/rust/songs/song_model.cxxqt.h");
type SongModel =
crate::songs::song_model::song_model::SongModel;
}

View file

@ -2,6 +2,7 @@
pub mod song_model {
unsafe extern "C++" {
include!(< QAbstractListModel >);
type QAbstractListModel;
include!("cxx-qt-lib/qhash.h");
type QHash_i32_QByteArray =
cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
@ -41,13 +42,14 @@ pub mod song_model {
unsafe extern "RustQt" {
#[qobject]
#[base = "QAbstractListModel"]
#[base = QAbstractListModel]
#[qml_element]
#[qproperty(i32, count)]
type SongModel = super::SongModelRust;
#[inherit]
#[qsignal]
#[cxx_name = "dataChanged"]
fn data_changed(
self: Pin<&mut SongModel>,
top_left: &QModelIndex,
@ -75,7 +77,7 @@ pub mod song_model {
fn setup(self: Pin<&mut SongModel>);
#[qinvokable]
fn remove_item(self: Pin<&mut SongModel>, index: i32)
-> bool;
-> bool;
#[qinvokable]
fn new_song(self: Pin<&mut SongModel>) -> bool;
#[qinvokable]
@ -168,6 +170,7 @@ pub mod song_model {
unsafe extern "RustQt" {
#[inherit]
#[cxx_name = "beginInsertRows"]
unsafe fn begin_insert_rows(
self: Pin<&mut SongModel>,
parent: &QModelIndex,
@ -176,9 +179,11 @@ pub mod song_model {
);
#[inherit]
#[cxx_name = "endInsertRows"]
unsafe fn end_insert_rows(self: Pin<&mut SongModel>);
#[inherit]
#[cxx_name = "beginRemoveRows"]
unsafe fn begin_remove_rows(
self: Pin<&mut SongModel>,
parent: &QModelIndex,
@ -187,6 +192,7 @@ pub mod song_model {
);
#[inherit]
#[cxx_name = "beginMoveRows"]
unsafe fn begin_move_rows(
self: Pin<&mut SongModel>,
source_parent: &QModelIndex,
@ -197,18 +203,23 @@ pub mod song_model {
) -> bool;
#[inherit]
#[cxx_name = "endMoveRows"]
unsafe fn end_move_rows(self: Pin<&mut SongModel>);
#[inherit]
#[cxx_name = "endRemoveRows"]
unsafe fn end_remove_rows(self: Pin<&mut SongModel>);
#[inherit]
#[cxx_name = "beginResetModel"]
unsafe fn begin_reset_model(self: Pin<&mut SongModel>);
#[inherit]
#[cxx_name = "endResetModel"]
unsafe fn end_reset_model(self: Pin<&mut SongModel>);
#[inherit]
#[cxx_name = "canFetchMore"]
fn can_fetch_more(
self: &SongModel,
parent: &QModelIndex,
@ -232,10 +243,12 @@ pub mod song_model {
#[qinvokable]
#[cxx_override]
#[cxx_name = "roleNames"]
fn role_names(self: &SongModel) -> QHash_i32_QByteArray;
#[qinvokable]
#[cxx_override]
#[cxx_name = "rowCount"]
fn row_count(self: &SongModel, _parent: &QModelIndex) -> i32;
}
}
@ -246,7 +259,7 @@ use cxx_qt::{CxxQtType, Threading};
use cxx_qt_lib::{
QByteArray, QModelIndex, QString, QStringList, QVariant,
};
use sqlx::{query, query_as, Connection, SqliteConnection};
use sqlx::{Connection, SqliteConnection, query, query_as};
use std::collections::HashMap;
use std::pin::Pin;
use tracing::{debug, error};
@ -592,16 +605,23 @@ impl song_model::SongModel {
let rt = tokio::runtime::Runtime::new().unwrap();
let db_string = updated_title.clone().to_string();
rt.block_on(async {
let result = query!("UPDATE songs SET title = ? where id = ?", db_string, song_id)
.execute(&mut self.as_mut().rust_mut().db)
.await;
let result = query!(
"UPDATE songs SET title = ? where id = ?",
db_string,
song_id
)
.execute(&mut self.as_mut().rust_mut().db)
.await;
match result {
Ok(_i) => {
if let Some(song) =
self.as_mut().rust_mut().songs.get_mut(index)
{
debug!(?song, title = updated_title.to_string());
debug!(
?song,
title = updated_title.to_string()
);
song.title = updated_title.to_string();
self.as_mut().data_changed(
&model_index,
@ -614,9 +634,11 @@ impl song_model::SongModel {
}
}
Err(e) => {
error!("There was an error updating title in db: {e}");
error!(
"There was an error updating title in db: {e}"
);
false
},
}
}
});
true
@ -720,9 +742,13 @@ impl song_model::SongModel {
let db_string = updated_audio.clone().to_string();
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let result = query!("UPDATE songs SET audio = ? where id = ?", db_string, song_id)
.execute(&mut self.as_mut().rust_mut().db)
.await;
let result = query!(
"UPDATE songs SET audio = ? where id = ?",
db_string,
song_id
)
.execute(&mut self.as_mut().rust_mut().db)
.await;
match result {
Ok(_i) => {
@ -745,9 +771,11 @@ impl song_model::SongModel {
}
}
Err(e) => {
error!("There was an error updating audio in db: {e}");
error!(
"There was an error updating audio in db: {e}"
);
false
},
}
}
});
true

View file

@ -2,6 +2,7 @@
pub mod video_model {
unsafe extern "C++" {
include!(< QAbstractListModel >);
type QAbstractListModel;
include!("cxx-qt-lib/qhash.h");
type QHash_i32_QByteArray =
cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
@ -36,13 +37,14 @@ pub mod video_model {
unsafe extern "RustQt" {
#[qobject]
#[base = "QAbstractListModel"]
#[base = QAbstractListModel]
#[qml_element]
#[qproperty(i32, count)]
type VideoModel = super::VideoModelRust;
#[inherit]
#[qsignal]
#[cxx_name = "dataChanged"]
fn data_changed(
self: Pin<&mut VideoModel>,
top_left: &QModelIndex,
@ -104,6 +106,7 @@ pub mod video_model {
unsafe extern "RustQt" {
#[inherit]
#[cxx_name = "beginInsertRows"]
unsafe fn begin_insert_rows(
self: Pin<&mut VideoModel>,
parent: &QModelIndex,
@ -112,9 +115,11 @@ pub mod video_model {
);
#[inherit]
#[cxx_name = "endInsertRows"]
unsafe fn end_insert_rows(self: Pin<&mut VideoModel>);
#[inherit]
#[cxx_name = "beginRemoveRows"]
unsafe fn begin_remove_rows(
self: Pin<&mut VideoModel>,
parent: &QModelIndex,
@ -123,6 +128,7 @@ pub mod video_model {
);
#[inherit]
#[cxx_name = "beginMoveRows"]
unsafe fn begin_move_rows(
self: Pin<&mut VideoModel>,
source_parent: &QModelIndex,
@ -133,18 +139,23 @@ pub mod video_model {
) -> bool;
#[inherit]
#[cxx_name = "endMoveRows"]
unsafe fn end_move_rows(self: Pin<&mut VideoModel>);
#[inherit]
#[cxx_name = "endRemoveRows"]
unsafe fn end_remove_rows(self: Pin<&mut VideoModel>);
#[inherit]
#[cxx_name = "beginResetModel"]
unsafe fn begin_reset_model(self: Pin<&mut VideoModel>);
#[inherit]
#[cxx_name = "endResetModel"]
unsafe fn end_reset_model(self: Pin<&mut VideoModel>);
#[inherit]
#[cxx_name = "canFetchMore"]
fn can_fetch_more(
self: &VideoModel,
parent: &QModelIndex,
@ -168,12 +179,14 @@ pub mod video_model {
#[qinvokable]
#[cxx_override]
#[cxx_name = "roleNames"]
fn role_names(self: &VideoModel) -> QHash_i32_QByteArray;
#[qinvokable]
#[cxx_override]
#[cxx_name = "rowCount"]
fn row_count(self: &VideoModel, _parent: &QModelIndex)
-> i32;
-> i32;
}
}
@ -181,7 +194,7 @@ pub mod video_model {
use color_eyre::eyre::Error;
use cxx_qt::{CxxQtType, Threading};
use cxx_qt_lib::{QByteArray, QModelIndex, QString, QUrl, QVariant};
use sqlx::{query, query_as, Connection, SqliteConnection};
use sqlx::{Connection, SqliteConnection, query, query_as};
use std::path::PathBuf;
use std::pin::Pin;
use tracing::{debug, error};