From: Michal MalĂ˝ Date: Wed, 8 Jul 2015 15:39:14 +0000 (+0200) Subject: Use a function to display some more common error messageboxes. X-Git-Tag: 0.4a~3 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=bf9b158fbdfd5aa1b23eb54f8e0cb6740f1f98f0;p=FFBChecker.git Use a function to display some more common error messageboxes. --- diff --git a/mainwindow.cpp b/mainwindow.cpp index c62d60c..07257f0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -132,7 +132,7 @@ void MainWindow::onEffectSlotSelected(const int cboxIdx) effectIdx = ui->cbox_effectSlots->currentData(Qt::UserRole).toInt(&ok); if (!ok) { - QMessageBox::critical(this, "Runtime error", "Nonsensical data passed as effect slot index."); + showErrorMsgBox(ErrorMessages::BAD_EFFECT_SLOT); return; } FFBEffectTypes etype = m_activeDevice->effectTypeByEffectIdx(effectIdx); @@ -180,7 +180,7 @@ void MainWindow::onRemoveEffectClicked() if (m_activeDevice == nullptr) return; if (!m_activeDevice->removeAndEraseEffect(ui->cbox_effectSlots->currentIndex())) - QMessageBox::warning(this, res_deviceErrorCap, "Unable to remove the effect."); + showErrorMsgBox(ErrorMessages::CANT_REMOVE_EFFECT); else setEffectStatusText(FFBEffect::FFBEffectStatus::NOT_LOADED); } @@ -197,7 +197,7 @@ void MainWindow::onStartEffectClicked() std::shared_ptr params; effectSlot = ui->cbox_effectSlots->currentData().toInt(&ok); if (!ok) { - QMessageBox::critical(this, "Runtime error", "Nonsensical data passed as effect slot index."); + showErrorMsgBox(ErrorMessages::BAD_EFFECT_SLOT); return; } @@ -209,7 +209,7 @@ void MainWindow::onStartEffectClicked() if (ret) setEffectStatusText(m_activeDevice->effectStatusByIdx(effectSlot)); else - QMessageBox::warning(this, res_deviceErrorCap, "Unable to start the effect."); + showErrorMsgBox(ErrorMessages::CANT_START_EFFECT); } void MainWindow::onStopEffectClicked() @@ -222,7 +222,7 @@ void MainWindow::onStopEffectClicked() effectSlot = ui->cbox_effectSlots->currentData().toInt(&ok); if (!ok) { - QMessageBox::critical(this, "Runtime error", "Nonsensical data passed as effect slot index."); + showErrorMsgBox(ErrorMessages::BAD_EFFECT_SLOT); return; } m_activeDevice->stopEffect(effectSlot); @@ -241,7 +241,7 @@ void MainWindow::onUploadEffectClicked() std::shared_ptr params; effectSlot = ui->cbox_effectSlots->currentData().toInt(&ok); if (!ok) { - QMessageBox::critical(this, "Runtime error", "Nonsensical data passed as effect slot index."); + showErrorMsgBox(ErrorMessages::BAD_EFFECT_SLOT); return; } @@ -253,7 +253,7 @@ void MainWindow::onUploadEffectClicked() if (ret) setEffectStatusText(m_activeDevice->effectStatusByIdx(effectSlot)); else - QMessageBox::warning(this, res_deviceErrorCap, "Unable to upload the effect."); + showErrorMsgBox(ErrorMessages::CANT_UPLOAD_EFFECT); } bool MainWindow::readEnvelopeParameters(std::shared_ptr params, const EnvelopeSettings* es) @@ -483,6 +483,25 @@ void MainWindow::setEffectTypeIndexByType(const FFBEffectTypes etype) } } +void MainWindow::showErrorMsgBox(const ErrorMessages msgCode) +{ + switch (msgCode) { + case ErrorMessages::BAD_EFFECT_SLOT: + QMessageBox::critical(this, "Runtime error", "Nonsensical data passed as effect slot index."); + break; + case ErrorMessages::CANT_REMOVE_EFFECT: + QMessageBox::warning(this, res_deviceErrorCap, "Unable to remove the effect."); + break; + case ErrorMessages::CANT_START_EFFECT: + QMessageBox::warning(this, res_deviceErrorCap, "Unable to start the effect."); + break; + case ErrorMessages::CANT_UPLOAD_EFFECT: + QMessageBox::warning(this, res_deviceErrorCap, "Unable to upload effect."); + break; + } +} + + MainWindow::~MainWindow() { delete ui; diff --git a/mainwindow.h b/mainwindow.h index cdd1ca9..261912a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -28,6 +28,11 @@ public: ~MainWindow(); private: + enum class ErrorMessages { BAD_EFFECT_SLOT, + CANT_REMOVE_EFFECT, + CANT_START_EFFECT, + CANT_UPLOAD_EFFECT }; + EffectSettings* effectSettingsByType(FFBEffectTypes type); QString effectTypeToEffectName(const FFBEffectTypes type) const; void fillDeviceList(); @@ -38,6 +43,7 @@ private: bool readGeneralEffectParameters(std::shared_ptr params); void setEffectStatusText(const FFBEffect::FFBEffectStatus status); void setEffectTypeIndexByType(const FFBEffectTypes etype); + void showErrorMsgBox(const ErrorMessages msgCode); std::shared_ptr m_activeDevice; ConditionEffectSettings* m_conditionEffSet;