Manager toolbar: Improve the logic for updating the toolbar button state on VM selection change

This commit is contained in:
Alexander Babikov
2025-12-06 03:47:23 +05:00
parent 517a9f2c02
commit b5c6ebd589
4 changed files with 39 additions and 17 deletions

View File

@@ -423,9 +423,11 @@ illegal_chars:
completer->setModel(completerModel);
ui->searchBar->setCompleter(completer);
// Set initial status bar after the event loop starts
QTimer::singleShot(0, this, [this] {
// Set initial status bar after the event loop starts
emit updateStatusRight(machineCountString());
// Tell the mainwindow to enable the toolbar buttons if needed
emit selectionChanged((this->proxy_model->rowCount(QModelIndex()) > 0) ? selected_sysconfig : nullptr);
});
#if EMU_BUILD_NUM != 0
@@ -461,7 +463,7 @@ VMManagerMain::currentSelectionChanged(const QModelIndex &current,
vm_details->updateData(selected_sysconfig);
// Emit that the selection changed, include with the process state
emit selectionChanged(current, selected_sysconfig->process->state());
emit selectionChanged(selected_sysconfig);
}
void
@@ -722,6 +724,8 @@ VMManagerMain::deleteSystem(VMManagerSystem *sysconfig)
delete vm_details;
vm_details = new VMManagerDetails();
ui->detailsArea->layout()->addWidget(vm_details);
/* tell the mainwindow to disable the toolbar buttons */
emit selectionChanged(nullptr);
}
}
}

View File

@@ -56,7 +56,7 @@ public:
Settings,
};
signals:
void selectionChanged(const QModelIndex &currentSelection, QProcess::ProcessState processState);
void selectionChanged(VMManagerSystem *sysconfig);
void updateStatusLeft(const QString &text);
void updateStatusRight(const QString &text);

View File

@@ -69,12 +69,14 @@ VMManagerMainWindow::
#endif
// TODO: Unhide the toolbar once the actions are fixed to properly update on VM status change
ui->actionStartPause->setEnabled(false);
ui->actionStartPause->setIcon(QIcon(":/menuicons/qt/icons/run.ico"));
ui->actionStartPause->setText(tr("Start"));
ui->actionStartPause->setToolTip(tr("Start"));
ui->actionHard_Reset->setEnabled(false);
ui->actionForce_Shutdown->setEnabled(false);
ui->actionCtrl_Alt_Del->setEnabled(false);
ui->actionSettings->setEnabled(false);
// Preferences
connect(ui->actionPreferences, &QAction::triggered, this, &VMManagerMainWindow::preferencesTriggered);
@@ -147,29 +149,45 @@ VMManagerMainWindow::~VMManagerMainWindow()
= default;
void
VMManagerMainWindow::vmmSelectionChanged(const QModelIndex &currentSelection, const QProcess::ProcessState processState) const
VMManagerMainWindow::vmmSelectionChanged(const VMManagerSystem *sysconfig) const
{
if (processState == QProcess::Running) {
ui->actionStartPause->setEnabled(true);
ui->actionStartPause->setIcon(QIcon(":/menuicons/qt/icons/pause.ico"));
ui->actionStartPause->setText(tr("Pause"));
ui->actionStartPause->setToolTip(tr("Pause"));
if (sysconfig == nullptr) {
// This doubles both as a safety check and a way to disable
// all machine-related buttons when no machines are present
ui->actionStartPause->setEnabled(false);
ui->actionSettings->setEnabled(false);
ui->actionHard_Reset->setEnabled(false);
ui->actionForce_Shutdown->setEnabled(false);
ui->actionCtrl_Alt_Del->setEnabled(false);
return;
}
const bool running = sysconfig->process->state() == QProcess::ProcessState::Running;
if (running) {
if (sysconfig->getProcessStatus() == VMManagerSystem::ProcessStatus::Running) {
ui->actionStartPause->setIcon(QIcon(":/menuicons/qt/icons/pause.ico"));
ui->actionStartPause->setText(tr("Pause"));
ui->actionStartPause->setToolTip(tr("Pause"));
} else {
ui->actionStartPause->setIcon(QIcon(":/menuicons/qt/icons/run.ico"));
ui->actionStartPause->setText(tr("Continue"));
ui->actionStartPause->setToolTip(tr("Continue"));
}
disconnect(ui->actionStartPause, &QAction::triggered, vmm, &VMManagerMain::startButtonPressed);
connect(ui->actionStartPause, &QAction::triggered, vmm, &VMManagerMain::pauseButtonPressed);
ui->actionHard_Reset->setEnabled(true);
ui->actionForce_Shutdown->setEnabled(true);
ui->actionCtrl_Alt_Del->setEnabled(true);
} else {
ui->actionStartPause->setEnabled(true);
ui->actionStartPause->setIcon(QIcon(":/menuicons/qt/icons/run.ico"));
ui->actionStartPause->setText(tr("Start"));
ui->actionStartPause->setToolTip(tr("Start"));
disconnect(ui->actionStartPause, &QAction::triggered, vmm, &VMManagerMain::pauseButtonPressed);
connect(ui->actionStartPause, &QAction::triggered, vmm, &VMManagerMain::startButtonPressed);
ui->actionHard_Reset->setEnabled(false);
ui->actionForce_Shutdown->setEnabled(false);
ui->actionCtrl_Alt_Del->setEnabled(false);
}
ui->actionStartPause->setEnabled(!sysconfig->window_obscured);
ui->actionSettings->setEnabled(!sysconfig->window_obscured);
ui->actionHard_Reset->setEnabled(sysconfig->window_obscured ? false : running);
ui->actionForce_Shutdown->setEnabled(sysconfig->window_obscured ? false : running);
ui->actionCtrl_Alt_Del->setEnabled(sysconfig->window_obscured ? false : running);
}
void
VMManagerMainWindow::preferencesTriggered()

View File

@@ -55,7 +55,7 @@ public slots:
#endif
private slots:
void vmmSelectionChanged(const QModelIndex &currentSelection, QProcess::ProcessState processState) const;
void vmmSelectionChanged(const VMManagerSystem *sysconfig) const;
void preferencesTriggered();
#if EMU_BUILD_NUM != 0
void checkForUpdatesTriggered();