Manager: Simplify the connection chain for the configuration refresh signals

This allows refreshing the config without redrawing the entire details pane
Also refresh the config and screenshots on VM termination
This commit is contained in:
Alexander Babikov
2025-12-05 17:44:21 +05:00
parent 11da4936fd
commit fd3a79e526
6 changed files with 17 additions and 20 deletions

View File

@@ -199,6 +199,8 @@ VMManagerDetails::updateData(VMManagerSystem *passed_sysconfig)
disconnect(configureButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::launchSettings);
disconnect(cadButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::cadButtonPressed);
disconnect(sysconfig, &VMManagerSystem::configurationChanged, this, &VMManagerDetails::onConfigUpdated);
sysconfig = passed_sysconfig;
connect(resetButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::restartButtonPressed);
connect(stopButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::shutdownForceButtonPressed);
@@ -234,9 +236,18 @@ VMManagerDetails::updateData(VMManagerSystem *passed_sysconfig)
disconnect(sysconfig, &VMManagerSystem::clientProcessStatusChanged, this, &VMManagerDetails::updateProcessStatus);
connect(sysconfig, &VMManagerSystem::clientProcessStatusChanged, this, &VMManagerDetails::updateProcessStatus);
connect(sysconfig, &VMManagerSystem::configurationChanged, this, &VMManagerDetails::onConfigUpdated);
updateProcessStatus();
}
void
VMManagerDetails::onConfigUpdated(VMManagerSystem *passed_sysconfig)
{
updateConfig(passed_sysconfig);
updateScreenshots(passed_sysconfig);
}
void
VMManagerDetails::updateConfig(VMManagerSystem *passed_sysconfig)
{

View File

@@ -87,6 +87,7 @@ private slots:
void saveNotes() const;
void nextScreenshot();
void previousScreenshot();
void onConfigUpdated(VMManagerSystem *passed_sysconfig);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;

View File

@@ -456,19 +456,9 @@ VMManagerMain::currentSelectionChanged(const QModelIndex &current,
if (!current.isValid())
return;
/* hack to prevent strange segfaults when adding a machine after
removing all machines previously */
if (selected_sysconfig->config_signal_connected == true) {
disconnect(selected_sysconfig, &VMManagerSystem::configurationChanged, this, &VMManagerMain::onConfigUpdated);
selected_sysconfig->config_signal_connected = false;
}
const auto mapped_index = proxy_model->mapToSource(current);
selected_sysconfig = vm_model->getConfigObjectForIndex(mapped_index);
vm_details->updateData(selected_sysconfig);
if (selected_sysconfig->config_signal_connected == false) {
connect(selected_sysconfig, &VMManagerSystem::configurationChanged, this, &VMManagerMain::onConfigUpdated);
selected_sysconfig->config_signal_connected = true;
}
// Emit that the selection changed, include with the process state
emit selectionChanged(current, selected_sysconfig->process->state());
@@ -593,12 +583,6 @@ VMManagerMain::currentSelectionIsValid() const
return ui->listView->currentIndex().isValid() && selected_sysconfig->isValid();
}
void
VMManagerMain::onConfigUpdated(const QString &uuid)
{
if (selected_sysconfig->uuid == uuid)
vm_details->updateData(selected_sysconfig);
}
// Used from MainWindow during app exit to obtain and persist the current selection
QString
VMManagerMain::getCurrentSelection() const

View File

@@ -83,7 +83,6 @@ public slots:
#ifdef Q_OS_WINDOWS
void onDarkModeUpdated();
#endif
void onConfigUpdated(const QString &uuid);
int getActiveMachineCount();
QList<int> getPaneSizes() const;

View File

@@ -449,6 +449,8 @@ VMManagerSystem::launchMainProcess()
tr("The virtual machine \"%1\"'s process has unexpectedly terminated with exit code %2.").arg(displayName, QString("%1 (0x%2)").arg(QString::number(exitCode), QString::number(exitCode, 16))));
return;
}
configurationChangeReceived();
});
}
@@ -1241,8 +1243,9 @@ void
VMManagerSystem::configurationChangeReceived()
{
reloadConfig();
emit configurationChanged(this->uuid);
emit configurationChanged(this);
}
void
VMManagerSystem::reloadConfig()
{

View File

@@ -138,7 +138,6 @@ public:
QProcess *process = new QProcess();
bool window_obscured;
bool config_signal_connected = false;
QString getDisplayValue(VMManager::Display::Name key);
QFileInfoList getScreenshots();
@@ -158,7 +157,7 @@ signals:
void windowStatusChanged();
void itemDataChanged();
void clientProcessStatusChanged();
void configurationChanged(const QString &uuid);
void configurationChanged(VMManagerSystem *sysconfig);
void globalConfigurationChanged();
private: