From 045cefae56268d7a5f1dd6b7c230a46a1f4f5f51 Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Tue, 11 Aug 2020 20:30:28 +0200 Subject: [PATCH] Add deletion of content if it is not a steam item Deleting a steam subscription folder would be pointless because Steam would just download it again. For now this works only with none steam items, based if their have a steamID in their project.json --- ScreenPlay/Resources.qrc | 1 + ScreenPlay/assets/icons/icon_delete.svg | 1 + ScreenPlay/qml/Installed/ScreenPlayItem.qml | 35 +++++++++++++++------ ScreenPlay/src/installedlistmodel.cpp | 27 ++++++++++++++-- ScreenPlay/src/installedlistmodel.h | 3 +- 5 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 ScreenPlay/assets/icons/icon_delete.svg diff --git a/ScreenPlay/Resources.qrc b/ScreenPlay/Resources.qrc index a7be202c..2461a0f8 100644 --- a/ScreenPlay/Resources.qrc +++ b/ScreenPlay/Resources.qrc @@ -100,5 +100,6 @@ legal/Qt LGPLv3.txt legal/gpl-3.0.txt legal/lgpl-2.1.txt + assets/icons/icon_delete.svg diff --git a/ScreenPlay/assets/icons/icon_delete.svg b/ScreenPlay/assets/icons/icon_delete.svg new file mode 100644 index 00000000..3acec0ad --- /dev/null +++ b/ScreenPlay/assets/icons/icon_delete.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ScreenPlay/qml/Installed/ScreenPlayItem.qml b/ScreenPlay/qml/Installed/ScreenPlayItem.qml index 852cf4f9..ff9fb4a6 100644 --- a/ScreenPlay/qml/Installed/ScreenPlayItem.qml +++ b/ScreenPlay/qml/Installed/ScreenPlayItem.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtGraphicalEffects 1.0 -import QtQuick.Controls 2.3 +import QtQuick.Controls 2.12 import QtQuick.Controls.Styles 1.4 import ScreenPlay 1.0 import ScreenPlay.Enums.InstalledType 1.0 @@ -219,14 +219,9 @@ Item { onClicked: { if (mouse.button === Qt.LeftButton) { - ScreenPlay.util.setSidebarItem( - screenPlayItem.screenId, - screenPlayItem.type) + ScreenPlay.util.setSidebarItem(screenPlayItem.screenId, + screenPlayItem.type) } else if (mouse.button === Qt.RightButton) { - if (workshopID != 0) { - miWorkshop.enabled = true - } - contextMenu.popup() hasMenuOpen = true } @@ -238,21 +233,41 @@ Item { onClosed: hasMenuOpen = false MenuItem { text: qsTr("Open containing folder") + icon.source: "qrc:/assets/icons/icon_folder_open.svg" onClicked: { ScreenPlay.util.openFolderInExplorer(absoluteStoragePath) } } + MenuItem { + text: qsTr("Deinstall Item") + icon.source: "qrc:/assets/icons/icon_delete.svg" + enabled: screenPlayItem.workshopID === 0 + onClicked: { + deleteDialog.open() + } + } MenuItem { id: miWorkshop text: qsTr("Open workshop Page") - enabled: false - + enabled: screenPlayItem.workshopID !== 0 + icon.source: "qrc:/assets/icons/icon_steam.svg" onClicked: { Qt.openUrlExternally( "steam://url/CommunityFilePage/" + workshopID) } } } + Dialog { + id: deleteDialog + title: "Are you sure you want to delete this item?" + standardButtons: Dialog.Ok | Dialog.Cancel + modal: true + dim: true + anchors.centerIn: Overlay.overlay + + onAccepted: ScreenPlay.installedListModel.deinstallItemAt( + screenPlayItem.itemIndex) + } } states: [ diff --git a/ScreenPlay/src/installedlistmodel.cpp b/ScreenPlay/src/installedlistmodel.cpp index 21b58b96..7264f655 100644 --- a/ScreenPlay/src/installedlistmodel.cpp +++ b/ScreenPlay/src/installedlistmodel.cpp @@ -36,9 +36,9 @@ void InstalledListModel::init() loadInstalledContent(); - auto reloadLambda = [this](){ - QTimer::singleShot(500,[this](){ - reset(); + auto reloadLambda = [this]() { + QTimer::singleShot(500, [this]() { + reset(); }); }; @@ -46,6 +46,27 @@ void InstalledListModel::init() QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, reloadLambda); } +bool InstalledListModel::deinstallItemAt(const int index) +{ + if (index < 0 || index >= m_screenPlayFiles.count()) { + qWarning() << "remove folder error, invalid index " << index; + return false; + } + + beginRemoveRows(QModelIndex(), index, index); + const QString path = QUrl::fromUserInput(m_screenPlayFiles.at(index).m_absoluteStoragePath.toString()).toLocalFile(); + + QDir dir(path); + const bool success = dir.removeRecursively(); + + if (!success) + qWarning() << "Could not remove folder: " << m_screenPlayFiles.at(index).m_absoluteStoragePath.toString(); + + m_screenPlayFiles.removeAt(index); + endRemoveRows(); + return success; +} + /*! \brief Returns the length of the installed items. */ diff --git a/ScreenPlay/src/installedlistmodel.h b/ScreenPlay/src/installedlistmodel.h index bfecc4b8..730e5df0 100644 --- a/ScreenPlay/src/installedlistmodel.h +++ b/ScreenPlay/src/installedlistmodel.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -100,6 +101,7 @@ public slots: void reset(); void init(); QVariantMap get(QString folderId) const; + bool deinstallItemAt(const int index); void setCount(int count) { @@ -109,7 +111,6 @@ public slots: m_count = count; emit countChanged(m_count); } - signals: void setScreenVisible(bool visible); void setScreenToVideo(QString absolutePath);