Manager: Add machine deletion
This commit is contained in:
@@ -107,6 +107,13 @@ VMManagerMain::VMManagerMain(QWidget *parent) :
|
|||||||
});
|
});
|
||||||
killIcon.setEnabled(selected_sysconfig->process->state() == QProcess::Running);
|
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();
|
contextMenu.addSeparator();
|
||||||
|
|
||||||
QAction showRawConfigFile(tr("Show &config file"));
|
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
|
QStringList
|
||||||
VMManagerMain::getSearchCompletionList() const
|
VMManagerMain::getSearchCompletionList() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public slots:
|
|||||||
void shutdownForceButtonPressed() const;
|
void shutdownForceButtonPressed() const;
|
||||||
void searchSystems(const QString &text) const;
|
void searchSystems(const QString &text) const;
|
||||||
void newMachineWizard();
|
void newMachineWizard();
|
||||||
|
void deleteSystem(VMManagerSystem *sysconfig);
|
||||||
void addNewSystem(const QString &name, const QString &dir, const QString &displayName = QString(), const QString &configFile = {});
|
void addNewSystem(const QString &name, const QString &dir, const QString &displayName = QString(), const QString &configFile = {});
|
||||||
#if __GNUC__ >= 11
|
#if __GNUC__ >= 11
|
||||||
[[nodiscard]] QStringList getSearchCompletionList() const;
|
[[nodiscard]] QStringList getSearchCompletionList() const;
|
||||||
|
|||||||
@@ -140,6 +140,18 @@ VMManagerModel::addConfigToModel(VMManagerSystem *system_config)
|
|||||||
connect(system_config, &VMManagerSystem::itemDataChanged, this, &VMManagerModel::modelDataChanged);
|
connect(system_config, &VMManagerSystem::itemDataChanged, this, &VMManagerModel::modelDataChanged);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
VMManagerModel::removeConfigFromModel(VMManagerSystem *system_config)
|
||||||
|
{
|
||||||
|
const QModelIndex index = getIndexForConfigFile(system_config->config_file);
|
||||||
|
disconnect(system_config, &VMManagerSystem::itemDataChanged, this, &VMManagerModel::modelDataChanged);
|
||||||
|
beginRemoveRows(QModelIndex(), index.row(), index.row());
|
||||||
|
machines.remove(index.row());
|
||||||
|
endRemoveRows();
|
||||||
|
emit systemDataChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VMManagerModel::modelDataChanged()
|
VMManagerModel::modelDataChanged()
|
||||||
{
|
{
|
||||||
@@ -177,4 +189,4 @@ VMManagerModel::getActiveMachineCount()
|
|||||||
running++;
|
running++;
|
||||||
}
|
}
|
||||||
return running;
|
return running;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public:
|
|||||||
[[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation,
|
[[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation,
|
||||||
int role) const override;
|
int role) const override;
|
||||||
void addConfigToModel(VMManagerSystem *system_config);
|
void addConfigToModel(VMManagerSystem *system_config);
|
||||||
|
void removeConfigFromModel(VMManagerSystem *system_config);
|
||||||
|
|
||||||
[[nodiscard]] VMManagerSystem * getConfigObjectForIndex(const QModelIndex &index) const;
|
[[nodiscard]] VMManagerSystem * getConfigObjectForIndex(const QModelIndex &index) const;
|
||||||
QModelIndex getIndexForConfigFile(const QFileInfo& config_file);
|
QModelIndex getIndexForConfigFile(const QFileInfo& config_file);
|
||||||
|
|||||||
Reference in New Issue
Block a user