diff --git a/src/cpp/videosqlmodel.cpp b/src/cpp/videosqlmodel.cpp index c810b76..815839e 100644 --- a/src/cpp/videosqlmodel.cpp +++ b/src/cpp/videosqlmodel.cpp @@ -361,3 +361,34 @@ void VideoProxyModel::deleteVideos(const QVector &rows) { model->removeItem(rows.at(i)); } } + +bool VideoProxyModel::updateLoop(int row, bool value) { + auto model = qobject_cast(sourceModel()); + qDebug() << "THIS:" << row; + bool ret = model->updateLoop(row, value); + return ret; +} + +bool VideoProxyModel::updateStartTime(int row, float value) { + auto model = qobject_cast(sourceModel()); + bool ret = model->updateStartTime(row, value); + return ret; +} + +bool VideoProxyModel::updateEndTime(int row, float value) { + auto model = qobject_cast(sourceModel()); + bool ret = model->updateEndTime(row, value); + return ret; +} + +bool VideoProxyModel::updateTitle(int row, QString value) { + auto model = qobject_cast(sourceModel()); + bool ret = model->updateTitle(row, value); + return ret; +} + +bool VideoProxyModel::updatePath(int row, QString value) { + auto model = qobject_cast(sourceModel()); + bool ret = model->updatePath(row, value); + return ret; +} diff --git a/src/cpp/videosqlmodel.h b/src/cpp/videosqlmodel.h index bb81e2e..a39daa0 100644 --- a/src/cpp/videosqlmodel.h +++ b/src/cpp/videosqlmodel.h @@ -82,6 +82,11 @@ public slots: Q_INVOKABLE QVariantMap getVideo(const int &row); Q_INVOKABLE void deleteVideo(const int &row); Q_INVOKABLE void deleteVideos(const QVector &row); + Q_INVOKABLE bool updateLoop(int row, bool value); + Q_INVOKABLE bool updateTitle(int row, QString value); + Q_INVOKABLE bool updatePath(int row, QString value); + Q_INVOKABLE bool updateStartTime(int row, float value); + Q_INVOKABLE bool updateEndTime(int row, float value); private: VideoModel *m_videoModel; diff --git a/src/qml/presenter/Library.qml b/src/qml/presenter/Library.qml index 3ed70e7..a42b496 100644 --- a/src/qml/presenter/Library.qml +++ b/src/qml/presenter/Library.qml @@ -36,7 +36,7 @@ Item { libraryType: "song" headerLabel: "Songs" itemIcon: "folder-music-symbolic" - itemSubtitle: "hi" + itemSubtitle: model.author newItemFunction: (function() { songProxyModel.setFilterRegularExpression(""); songProxyModel.songModel.newSong(); @@ -63,12 +63,7 @@ Item { libraryType: "video" headerLabel: "Videos" itemIcon: "folder-videos-symbolic" - itemSubtitle: { - if (fileValidation) - model.path; - else - "file is missing" - } + itemSubtitle: model.path newItemFunction: (function() { videoProxyModel.setFilterRegularExpression(""); }) @@ -88,12 +83,7 @@ Item { libraryType: "image" headerLabel: "Images" itemIcon: "folder-pictures-symbolic" - itemSubtitle: { - if (fileValidation) - model.path; - else - "file is missing" - } + itemSubtitle: model.path newItemFunction: (function() { imageProxyModel.setFilterRegularExpression(""); }) @@ -113,12 +103,7 @@ Item { libraryType: "presentation" headerLabel: "Presentations" itemIcon: "x-office-presentation-symbolic" - itemSubtitle: { - if (fileValidation) - model.filePath; - else - "file is missing" - } + itemSubtitle: model.path newItemFunction: (function() { presProxyModel.setFilterRegularExpression(""); }) diff --git a/src/qml/presenter/LibraryItem.qml b/src/qml/presenter/LibraryItem.qml index 3d97c4f..ee3359a 100644 --- a/src/qml/presenter/LibraryItem.qml +++ b/src/qml/presenter/LibraryItem.qml @@ -70,7 +70,7 @@ ColumnLayout { anchors {left: libraryLabel.right verticalCenter: libraryLabel.verticalCenter leftMargin: 15} - text: libraryType == "song" ? innerModel.rowCount() : innerModel.count() + text: libraryType == "song" ? innerModel.rowCount() : innerModel.count(innerModel) color: Kirigami.Theme.disabledTextColor } diff --git a/src/qml/presenter/VideoEditor.qml b/src/qml/presenter/VideoEditor.qml index f157fb2..2956b1a 100644 --- a/src/qml/presenter/VideoEditor.qml +++ b/src/qml/presenter/VideoEditor.qml @@ -245,28 +245,28 @@ Item { function updateEndTime(value) { /* changeStartTime(value, false); */ - videosqlmodel.updateEndTime(video.id, value); + videoProxyModel.updateEndTime(video.id, value); video.endTime = value; showPassiveNotification(video.endTime); } function updateStartTime(value) { /* changeStartTime(value, false); */ - videosqlmodel.updateStartTime(video.id, value); + videoProxyModel.updateStartTime(video.id, value); video.startTime = value; showPassiveNotification(video.startTime); } function updateTitle(text) { changeTitle(text, false); - videosqlmodel.updateTitle(video.id, text); + videoProxyModel.updateTitle(video.id, text); showPassiveNotification(video.title); } function updateLoop(value) { /* changeStartTime(value, false); */ - videosqlmodel.updateLoop(video.id, value); - /* video.loop = value; */ + let bool = videoProxyModel.updateLoop(video.id, value); + video.loop = value; showPassiveNotification("Loop changed to: " + video.loop); } diff --git a/src/rust/video_model.rs b/src/rust/video_model.rs index 9cd9da9..51d55a0 100644 --- a/src/rust/video_model.rs +++ b/src/rust/video_model.rs @@ -98,9 +98,9 @@ mod video_model { id: video.id, title: QString::from(&video.title), path: QString::from(&video.path), - start_time: 0.0, - end_time: 0.0, - looping: false, + start_time: video.start_time.unwrap_or(0.0), + end_time: video.end_time.unwrap_or(0.0), + looping: video.looping, }; self.as_mut().add_video(img); @@ -239,6 +239,7 @@ mod video_model { self.as_ref().data(&idx, *i.0), ); } + println!("gotted-video: {:?}", video); }; qvariantmap } @@ -260,6 +261,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()); + println!("rust-video: {:?}", index); + println!("rust-loop: {:?}", loop_value); let db = &mut self.as_mut().get_db(); let result = update(videos.filter(id.eq(index))) @@ -267,10 +270,69 @@ mod video_model { .execute(db); match result { Ok(_i) => { - let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap(); - video.looping = loop_value; + for video in self.as_mut().videos_mut().iter_mut() { + if video.id == index { + video.looping = loop_value.clone(); + println!("rust-video: {:?}", video.title); + } + } self.as_mut() .emit_data_changed(model_index, model_index, &vector_roles); + println!("rust-looping: {:?}", loop_value); + true + } + Err(_e) => false, + } + } + + #[qinvokable] + pub fn update_end_time( + mut self: Pin<&mut Self>, + index: i32, + updated_end_time: f32, + ) -> bool { + 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 db = &mut self.as_mut().get_db(); + let result = update(videos.filter(id.eq(index))) + .set(end_time.eq(updated_end_time)) + .execute(db); + match result { + Ok(_i) => { + let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap(); + video.end_time = updated_end_time.clone(); + self.as_mut() + .emit_data_changed(model_index, model_index, &vector_roles); + println!("rust-end-time: {:?}", updated_end_time); + true + } + Err(_e) => false, + } + } + + #[qinvokable] + pub fn update_start_time( + mut self: Pin<&mut Self>, + index: i32, + updated_start_time: f32, + ) -> bool { + 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 db = &mut self.as_mut().get_db(); + let result = update(videos.filter(id.eq(index))) + .set(start_time.eq(updated_start_time)) + .execute(db); + match result { + Ok(_i) => { + let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap(); + video.start_time = updated_start_time.clone(); + self.as_mut() + .emit_data_changed(model_index, model_index, &vector_roles); + println!("rust-start-time: {:?}", updated_start_time); true } Err(_e) => false, @@ -290,9 +352,33 @@ mod video_model { match result { Ok(_i) => { let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap(); - video.title = updated_title; + video.title = updated_title.clone(); self.as_mut() .emit_data_changed(model_index, model_index, &vector_roles); + println!("rust-title: {:?}", updated_title); + true + } + Err(_e) => false, + } + } + + #[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()); + + let db = &mut self.as_mut().get_db(); + let result = update(videos.filter(id.eq(index))) + .set(path.eq(updated_path.to_string())) + .execute(db); + match result { + Ok(_i) => { + let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap(); + video.path = updated_path.clone(); + self.as_mut() + .emit_data_changed(model_index, model_index, &vector_roles); + println!("rust-path: {:?}", updated_path); true } Err(_e) => false,