Manager: Add machine deletion

This commit is contained in:
Alexander Babikov
2025-08-07 13:36:46 +05:00
parent d10d77481a
commit 74501db7fc
4 changed files with 41 additions and 1 deletions

View File

@@ -107,6 +107,13 @@ VMManagerMain::VMManagerMain(QWidget *parent) :
});
killIcon.setEnabled(selected_sysconfig->process->state() == QProcess::Running);
QAction deleteAction(tr("&Delete"));
contextMenu.addAction(&deleteAction);
connect(&deleteAction, &QAction::triggered, [this, parent] {
deleteSystem(selected_sysconfig);
});
deleteAction.setEnabled(selected_sysconfig->process->state() == QProcess::NotRunning);
contextMenu.addSeparator();
QAction showRawConfigFile(tr("Show &config file"));
@@ -433,6 +440,25 @@ VMManagerMain::addNewSystem(const QString &name, const QString &dir, const QStri
});
}
void
VMManagerMain::deleteSystem(VMManagerSystem *sysconfig)
{
QMessageBox msgbox(QMessageBox::Icon::Warning, tr("Warning"), tr("Do you really want to delete the virtual machine \"%1\" and all its files? This action cannot be undone!").arg(sysconfig->displayName), QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, qobject_cast<QWidget *>(this->parent()));
msgbox.exec();
if (msgbox.result() == QMessageBox::Yes) {
auto qrmdir = new QDir(sysconfig->config_dir);
if (const bool rmdirResult = qrmdir->removeRecursively(); !rmdirResult) {
QMessageBox::critical(this, tr("Remove directory failed"), tr("Some files in the machine's directory were unable to be deleted. Please delete them manually."));
return;
}
auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General);
config->remove(sysconfig->uuid);
vm_model->removeConfigFromModel(sysconfig);
delete sysconfig;
}
}
QStringList
VMManagerMain::getSearchCompletionList() const
{