From 395fe67bd4b1bd27c50199e99f700588f74ae3b6 Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Wed, 22 Nov 2023 10:33:00 +0100 Subject: [PATCH] Fix uninstalling items Path vairable changed and the logic did not make sense. First remove the item so that the qml engine removes all open images then remove the files. --- .../public/ScreenPlay/installedlistmodel.h | 2 +- ScreenPlay/qml/Installed/Installed.qml | 4 ++- ScreenPlay/src/installedlistmodel.cpp | 34 +++++++++---------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/ScreenPlay/inc/public/ScreenPlay/installedlistmodel.h b/ScreenPlay/inc/public/ScreenPlay/installedlistmodel.h index cc0ce26a..86b3f3ab 100644 --- a/ScreenPlay/inc/public/ScreenPlay/installedlistmodel.h +++ b/ScreenPlay/inc/public/ScreenPlay/installedlistmodel.h @@ -77,7 +77,7 @@ public slots: void append(const QString& projectJsonFilePath); void reset(); void init(); - void deinstallItemAt(const QString& absoluteStoragePath); + bool deinstallItemAt(const QString& absoluteStoragePath); void setCount(int count) { diff --git a/ScreenPlay/qml/Installed/Installed.qml b/ScreenPlay/qml/Installed/Installed.qml index a4e82ca7..92e03bf4 100644 --- a/ScreenPlay/qml/Installed/Installed.qml +++ b/ScreenPlay/qml/Installed/Installed.qml @@ -333,7 +333,9 @@ Item { anchors.centerIn: Overlay.overlay onAccepted: { root.sidebar.clear(); - App.installedListModel.deinstallItemAt(contextMenu.absoluteStoragePath); + if(!App.installedListModel.deinstallItemAt(contextMenu.absoluteStoragePath)){ + console.error("Unable to uninstall item",contextMenu.absoluteStoragePath) + } } } diff --git a/ScreenPlay/src/installedlistmodel.cpp b/ScreenPlay/src/installedlistmodel.cpp index 7fbf57fa..ed555713 100644 --- a/ScreenPlay/src/installedlistmodel.cpp +++ b/ScreenPlay/src/installedlistmodel.cpp @@ -59,28 +59,27 @@ void InstalledListModel::init() installed list. We wait for the qml engine to free all resources before we proceed. This like the preview.gif will be in use when clicking on an item */ -void InstalledListModel::deinstallItemAt(const QString& absoluteStoragePath) +bool InstalledListModel::deinstallItemAt(const QString& absoluteStoragePath) { - QTimer::singleShot(1000, this, [this, absoluteStoragePath]() { - int index = -1; - for (int i = 0; i < m_screenPlayFiles.size(); ++i) { - if (m_screenPlayFiles.at(i).projectJsonFilePath.absoluteFilePath() == absoluteStoragePath) { - index = i; - break; - } + const QString path = ScreenPlayUtil::toLocal(absoluteStoragePath); + int index = -1; + for (int i = 0; i < m_screenPlayFiles.size(); ++i) { + if (m_screenPlayFiles.at(i).projectJsonFilePath.path() == path) { + index = i; + break; } + } - if (index < 0 || index >= m_screenPlayFiles.count()) { - qWarning() << "Remove folder error, invalid index " << index; - return; - } + if (index < 0 || index >= m_screenPlayFiles.count()) { + qWarning() << "Remove folder error, invalid index " << index; + return false; + } - beginRemoveRows(QModelIndex(), index, index); - m_screenPlayFiles.removeAt(index); - endRemoveRows(); - - const QString path = ScreenPlayUtil::toLocal(absoluteStoragePath); + beginRemoveRows(QModelIndex(), index, index); + m_screenPlayFiles.removeAt(index); + endRemoveRows(); + QTimer::singleShot(1000, this, [this, path]() { QDir dir(path); bool success = true; if (!dir.exists()) { @@ -115,6 +114,7 @@ void InstalledListModel::deinstallItemAt(const QString& absoluteStoragePath) m_fileSystemWatcher.blockSignals(false); }); }); + return true; } /*!