// Edit a timer of the list void MainWindow::editTimerTriggerred() { Timer* timer = getCurrentTimer(); // Prevent the user to edit the timer if its media is broken if (timer->isBroken()) { QMessageBox::warning(this, tr("Error"), tr("This timer can't be modified because it's broken"), QMessageBox::Ok); } else { QString filename = timer->getFilename(); int period = timer->getPeriod(); QKeySequence keySequence = timer->getKeySequence(); UINT virtualKey = timer->getVirtualKey(); UINT modifiers = timer->getModifiers(); QPointer<DlgEditTimer> dlg = new DlgEditTimer(filename, period, keySequence, modifiers, virtualKey, this); if (dlg->exec() == QDialog::Accepted) { try { timer->setNewData(dlg->getPeriod(), dlg->getKeySquence(), dlg->getNativeModifiers(), dlg->getNativeVirtualKey(), this->hotkeyID); this->hotkeyID++; } catch (const SMException& exception) { QString message = tr("Couldn't modify the timer: %1").arg(exception.getMessage()); QMessageBox::critical(this, tr("Error"), message, QMessageBox::Ok); return; } int period = timer->getPeriod(); QString displayedPeriod = QString("%1:%2").arg(period / 60, 2, 10, QChar('0')).arg(period % 60, 2, 10, QChar('0')); TableItem* itemPeriod = new TableItem(displayedPeriod); QKeySequence keySequence = timer->getKeySequence(); QString displayedHotkey = keySequence.toString(); TableItem* itemHotkey = new TableItem(displayedHotkey); int row = getCurrentRow(); this->timerTable->setItem(row, COLUMN_PERIOD, itemPeriod); this->timerTable->setItem(row, COLUMN_HOTKEY, itemHotkey); this->modified.setModified(true); } delete dlg; } }
// Add a timer to the list void MainWindow::newTimerTriggerred() { QPointer<DlgNewTimer> dlg = new DlgNewTimer(this); if (dlg->exec() == QDialog::Accepted) { Timer* timer; try { timer = new Timer(dlg->getFilename(), dlg->getPeriod(), dlg->getKeySquence(), dlg->getNativeModifiers(), dlg->getNativeVirtualKey(), this->hotkeyID); this->hotkeyID++; } catch (const SMException& exception) { QString message = tr("Couldn't create the timer: %1").arg(exception.getMessage()); QMessageBox::critical(this, tr("Error"), message, QMessageBox::Ok); return; } addTimerToTable(timer); this->modified.setModified(true); } delete dlg; }