1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-01 16:19:47 +02: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 reset();
void init();
void deinstallItemAt(const QString& absoluteStoragePath);
bool deinstallItemAt(const QString& absoluteStoragePath);
void setCount(int count)
{

View File

@ -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)
}
}
}

View File

@ -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;
}
/*!