1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00

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.
This commit is contained in:
Elias Steurer 2023-11-22 10:33:00 +01:00
parent 7ea263dc2f
commit 395fe67bd4
3 changed files with 21 additions and 19 deletions

View File

@ -77,7 +77,7 @@ public slots:
void append(const QString& projectJsonFilePath); void append(const QString& projectJsonFilePath);
void reset(); void reset();
void init(); void init();
void deinstallItemAt(const QString& absoluteStoragePath); bool deinstallItemAt(const QString& absoluteStoragePath);
void setCount(int count) void setCount(int count)
{ {

View File

@ -333,7 +333,9 @@ Item {
anchors.centerIn: Overlay.overlay anchors.centerIn: Overlay.overlay
onAccepted: { onAccepted: {
root.sidebar.clear(); root.sidebar.clear();
App.installedListModel.deinstallItemAt(contextMenu.absoluteStoragePath); if(!App.installedListModel.deinstallItemAt(contextMenu.absoluteStoragePath)){
console.error("Unable to uninstall item",contextMenu.absoluteStoragePath)
}
} }
} }

View File

@ -59,12 +59,12 @@ void InstalledListModel::init()
installed list. We wait for the qml engine to free all resources before 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 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]() { const QString path = ScreenPlayUtil::toLocal(absoluteStoragePath);
int index = -1; int index = -1;
for (int i = 0; i < m_screenPlayFiles.size(); ++i) { for (int i = 0; i < m_screenPlayFiles.size(); ++i) {
if (m_screenPlayFiles.at(i).projectJsonFilePath.absoluteFilePath() == absoluteStoragePath) { if (m_screenPlayFiles.at(i).projectJsonFilePath.path() == path) {
index = i; index = i;
break; break;
} }
@ -72,15 +72,14 @@ void InstalledListModel::deinstallItemAt(const QString& absoluteStoragePath)
if (index < 0 || index >= m_screenPlayFiles.count()) { if (index < 0 || index >= m_screenPlayFiles.count()) {
qWarning() << "Remove folder error, invalid index " << index; qWarning() << "Remove folder error, invalid index " << index;
return; return false;
} }
beginRemoveRows(QModelIndex(), index, index); beginRemoveRows(QModelIndex(), index, index);
m_screenPlayFiles.removeAt(index); m_screenPlayFiles.removeAt(index);
endRemoveRows(); endRemoveRows();
const QString path = ScreenPlayUtil::toLocal(absoluteStoragePath); QTimer::singleShot(1000, this, [this, path]() {
QDir dir(path); QDir dir(path);
bool success = true; bool success = true;
if (!dir.exists()) { if (!dir.exists()) {
@ -115,6 +114,7 @@ void InstalledListModel::deinstallItemAt(const QString& absoluteStoragePath)
m_fileSystemWatcher.blockSignals(false); m_fileSystemWatcher.blockSignals(false);
}); });
}); });
return true;
} }
/*! /*!