From 4dc4036ddac10d1499bc7364e80922b56409dc90 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 17 May 2023 11:09:21 -0500 Subject: [PATCH] bug: fixing insertion bugs of many items Videos, images, and presentations were all look at the wrong index. I needed to look for the count - 1 in order to find the right index from the model when switching to the editMode --- src/qml/presenter/Library.qml | 188 ++++++++++++++++----------------- src/qml/presenter/NewVideo.qml | 26 +++++ 2 files changed, 116 insertions(+), 98 deletions(-) diff --git a/src/qml/presenter/Library.qml b/src/qml/presenter/Library.qml index 91becaf..cc02108 100644 --- a/src/qml/presenter/Library.qml +++ b/src/qml/presenter/Library.qml @@ -291,104 +291,6 @@ Item { } onExited: overlay = false - function addVideo(url) { - videoProxyModel.videoModel.newItem(url); - selectedLibrary = "video"; - videoLibrary.libraryList.currentIndex = videoProxyModel.videoModel.count(); - console.log(videoProxyModel.getVideo(videoLibrary.libraryList.currentIndex)); - const video = videoProxyModel.getVideo(videoLibrary.libraryList.currentIndex); - showPassiveNotification("newest video: " + video.title); - if (!editMode) - editMode = true; - editSwitch(video, "video"); - } - - function addImg(url) { - imageProxyModel.newItem(url); - selectedLibrary = "image"; - imageLibrary.libraryList.currentIndex = imageProxyModel.imageModel.count(); - console.log(imageProxyModel.getImage(imageLibrary.libraryList.currentIndex)); - const image = imageProxyModel.getImage(imageLibrary.libraryList.currentIndex); - showPassiveNotification("newest image: " + image.title); - if (!editMode) - editMode = true; - editSwitch(image, "image"); - } - - function addPres(url) { - console.log(pdf.status); - let pageCount = 1; - pdf.source = url; - while (pdf.status != 2) { - console.log(pdf.status); - console.log("PAGECOUNT: " + pdf.pageCount); - pageCount = pdf.pageCount; - } - presProxyModel.presentationModel.newItem(url, pageCount); - selectedLibrary = "presentation"; - presentationLibrary.libraryList.currentIndex = presProxyModel.presentationModel.count(); - console.log(presProxyModel.getPresentation(presentationLibrary.libraryList.currentIndex)); - const presentation = presProxyModel.getPresentation(presentationLibrary.libraryList.currentIndex); - showPassiveNotification("newest image: " + presentation.title); - if (!editMode) - editMode = true; - editSwitch(presentation, "presentation"); - pdf.source = ""; - } - - function isDragFile(item) { - var extension = item.split('.').pop(); - var valid = false; - - if(extension) { - console.log(extension); - valid = true; - } - - return valid; - } - - function addFile(file) { - let extension = file.split('.').pop(); - if (videoexts.includes(extension)) - { - addVideo(file); - } - if (imgexts.includes(extension)) - { - addImg(file); - } - if (presexts.includes(extension)) - { - if (file.endsWith(".html")) { - web.url = file; - } else - addPres(file); - } - - } - - function addFiles(files) { - showPassiveNotification("More than one file"); - for (let i = 0; i < files.length; i++) { - let file = files[i]; - let ext = file.split('.').pop() - if (videoexts.includes(ext)) - { - addVideo(file); - } - if (imgexts.includes(ext)) - { - console.log(file); - addImg(file); - console.log(file); - } - if (presexts.includes(ext)) - { - addPres(file); - } - } - } } Rectangle { @@ -415,6 +317,96 @@ Item { } } + function addVideo(url) { + videoProxyModel.videoModel.newItem(url); + selectedLibrary = "video"; + videoLibrary.libraryList.currentIndex = videoProxyModel.videoModel.count() - 1; + if (!editMode) + editMode = true; + editSwitch(videoLibrary.libraryList.currentIndex, "video"); + } + + function addImg(url) { + imageProxyModel.newItem(url); + selectedLibrary = "image"; + imageLibrary.libraryList.currentIndex = imageProxyModel.imageModel.count() - 1; + if (!editMode) + editMode = true; + editSwitch(imageLibrary.libraryList.currentIndex, "image"); + } + + function addPres(url) { + console.log(pdf.status); + let pageCount = 1; + pdf.source = url; + while (pdf.status != 2) { + console.log(pdf.status); + console.log("PAGECOUNT: " + pdf.pageCount); + pageCount = pdf.pageCount; + } + presProxyModel.presentationModel.newItem(url, pageCount); + selectedLibrary = "presentation"; + presentationLibrary.libraryList.currentIndex = presProxyModel.presentationModel.count() - 1; + if (!editMode) + editMode = true; + editSwitch(presentationLibrary.libraryList.currentIndex, "presentation"); + pdf.source = ""; + } + + function isDragFile(item) { + var extension = item.split('.').pop(); + var valid = false; + + if(extension) { + console.log(extension); + valid = true; + } + + return valid; + } + + function addFile(file) { + let extension = file.split('.').pop(); + if (videoexts.includes(extension)) + { + addVideo(file); + } + if (imgexts.includes(extension)) + { + addImg(file); + } + if (presexts.includes(extension)) + { + if (file.endsWith(".html")) { + web.url = file; + } else + addPres(file); + } + + } + + function addFiles(files) { + showPassiveNotification("More than one file"); + for (let i = 0; i < files.length; i++) { + let file = files[i]; + let ext = file.split('.').pop() + if (videoexts.includes(ext)) + { + addVideo(file); + } + if (imgexts.includes(ext)) + { + console.log(file); + addImg(file); + console.log(file); + } + if (presexts.includes(ext)) + { + addPres(file); + } + } + } + function addHtml(url) { console.log("adding an html"); var pageCount = 1; diff --git a/src/qml/presenter/NewVideo.qml b/src/qml/presenter/NewVideo.qml index 25c14a7..a5414ea 100644 --- a/src/qml/presenter/NewVideo.qml +++ b/src/qml/presenter/NewVideo.qml @@ -36,6 +36,14 @@ Kirigami.OverlaySheet { text: "" onEditingFinished: videoInput.text.startsWith("http") ? loadVideo() : showPassiveNotification("Coach called, this isn't it."); } + + Controls.ToolButton { + id: localButton + text: "Local Video" + icon.name: "fileopen" + hoverEnabled: true + onClicked: videoFileDialog.open() + } } } @@ -117,6 +125,24 @@ Kirigami.OverlaySheet { } } + + FileDialog { + id: videoFileDialog + title: "Please choose a video" + folder: shortcuts.home + selectMultiple: false + nameFilters: ["Video files (*.mp4 *.mkv *.mov *.wmv *.avi *.MP4 *.MOV *.MKV)"] + onAccepted: { + console.log("video = " + videoFileDialog.fileUrls[0]); + addVideo(videoFileDialog.fileUrls[0]); + root.close(); + } + onRejected: { + console.log("Canceled") + } + + } + } function loadVideo() {