void StaticPage::on_advWriteConfigBtn_clicked() {
    emit showStatusMessage(NULL, -1);

    if(!ui->advProgramMulKeysBox->isChecked()) {
        m_keysProgrammedCtr = 0;
    }

    //Validate settings
    if(!validateAdvSettings()) {
        return;
    }

    clearState();

    freezeAdvPage(true);

    // Change state
    if(ui->advProgramMulKeysBox->isChecked()) {
        if(ui->advAutoProgramKeysCheck->isChecked()) {
            m_keysProgrammedCtr = 0;
            m_state = State_Programming_Multiple_Auto;
        } else {
            m_state = State_Programming_Multiple;
        }
    } else {
        m_keysProgrammedCtr = 0;
        m_state = State_Programming;
    }

    writeAdvConfig();
}
void StaticPage::keyFound(bool found, bool* featuresMatrix) {
    if(found) {
        if(m_state == State_Initial) {
            ui->quickWriteConfigBtn->setEnabled(true);
            ui->advWriteConfigBtn->setEnabled(true);

            if(!featuresMatrix[YubiKeyFinder::Feature_MultipleConfigurations]) {
                ui->quickConfigSlot2Radio->setEnabled(false);
                ui->advConfigSlot2Radio->setEnabled(false);
            } else {
                ui->quickConfigSlot2Radio->setEnabled(true);
                ui->advConfigSlot2Radio->setEnabled(true);
            }

            if(!featuresMatrix[YubiKeyFinder::Feature_ShortTicket]) {
                ui->advStaticLen16Radio->setEnabled(false);
                ui->advStaticLen32Radio->setChecked(true);
            }

            if(!featuresMatrix[YubiKeyFinder::Feature_StrongPwd]) {
                ui->advStrongPw1Check->setEnabled(false);
                ui->advStrongPw2Check->setEnabled(false);
                ui->advStrongPw3Check->setEnabled(false);
            }

            if(!featuresMatrix[YubiKeyFinder::Feature_ScanCodeMode]) {
                ui->quickBtn->setEnabled(false);

                ui->quickConfigBox->setEnabled(false);
                ui->quickProgramMulKeysBox->setEnabled(false);
                ui->quickConfigProtectionBox->setEnabled(false);
                ui->quickKeyParamsBox->setEnabled(false);

                ui->quickWriteConfigBtn->setEnabled(false);
            }

            if(!featuresMatrix[YubiKeyFinder::Feature_StaticPassword]) {
                this->setEnabled(false);
            }
        } else if(m_state >= State_Programming_Multiple && m_keyPresent == false) {
            if(this->currentIndex() == Page_Quick) {
                if(m_state == State_Programming_Multiple) {
                    ui->quickWriteConfigBtn->setEnabled(true);
                } else {
                    writeQuickConfig();
                }
            } else {
                if(m_state == State_Programming_Multiple) {
                    ui->advWriteConfigBtn->setEnabled(true);
                } else {
                    writeAdvConfig();
                }
            }
        }
        m_keyPresent = true;
    } else {
        ui->quickBtn->setEnabled(true);
        ui->quickWriteConfigBtn->setEnabled(false);
        ui->advWriteConfigBtn->setEnabled(false);

        m_keyPresent = false;

        if(m_state == State_Initial) {
            ui->quickConfigSlot2Radio->setEnabled(true);
            ui->advConfigSlot2Radio->setEnabled(true);

            ui->advStaticLen16Radio->setEnabled(true);

            ui->advStrongPw1Check->setEnabled(true);
            ui->advStrongPw2Check->setEnabled(true);
            ui->advStrongPw3Check->setEnabled(true);

            ui->quickConfigBox->setEnabled(true);
            ui->quickProgramMulKeysBox->setEnabled(true);
            ui->quickConfigProtectionBox->setEnabled(true);
            ui->quickKeyParamsBox->setEnabled(true);

            this->setEnabled(true);
        } else if(m_state >= State_Programming_Multiple) {
            if(m_keysProgrammedCtr > 0 && !m_ready) {
                if(this->currentIndex() == Page_Quick) {
                    changeQuickConfigParams();
                } else {
                    changeAdvConfigParams();
                }
            }
        }
    }
}
void ChalRespPage::keyFound(bool found, bool* featuresMatrix) {
    if(found) {
        if(m_state == State_Initial) {
            ui->quickWriteConfigBtn->setEnabled(true);
            ui->quickExportConfigBtn->setEnabled(true);
            ui->advWriteConfigBtn->setEnabled(true);
            ui->advExportConfigBtn->setEnabled(true);

            if(!featuresMatrix[YubiKeyFinder::Feature_MultipleConfigurations]) {
                ui->quickConfigSlot2Radio->setEnabled(false);
                ui->advConfigSlot2Radio->setEnabled(false);
            } else {
                ui->quickConfigSlot2Radio->setEnabled(true);
                ui->advConfigSlot2Radio->setEnabled(true);
            }
            if(!featuresMatrix[YubiKeyFinder::Feature_ChallengeResponseFixed]) {
                ui->advHmacFixedInputRadio->setEnabled(false);
                ui->advHmacVarInputRadio->setChecked(true);
            } else {
                ui->advHmacFixedInputRadio->setEnabled(true);
            }

            if(!featuresMatrix[YubiKeyFinder::Feature_ChallengeResponse]) {
                this->setEnabled(false);
            }
        } else if(m_state >= State_Programming_Multiple && m_keyPresent == false) {
            if(this->currentIndex() == Page_Quick) {
                if(m_state == State_Programming_Multiple) {
                    ui->quickWriteConfigBtn->setEnabled(true);
                    ui->quickExportConfigBtn->setEnabled(true);
                } else {
                    writeQuickConfig(WRITE_CONFIG);
                }

            } else {
                if(m_state == State_Programming_Multiple) {
                    ui->advWriteConfigBtn->setEnabled(true);
                    ui->advExportConfigBtn->setEnabled(true);
                } else {
                    writeAdvConfig(WRITE_CONFIG);
                }
            }
        }
        m_keyPresent = true;
    } else {
        ui->quickWriteConfigBtn->setEnabled(false);
        ui->quickExportConfigBtn->setEnabled(false);
        ui->advWriteConfigBtn->setEnabled(false);
        ui->advExportConfigBtn->setEnabled(false);
        ui->advHmacFixedInputRadio->setEnabled(true);
        m_keyPresent = false;

        if(m_state == State_Initial) {
            ui->quickConfigSlot2Radio->setEnabled(true);
            ui->advConfigSlot2Radio->setEnabled(true);

            this->setEnabled(true);
        } else if(m_state >= State_Programming_Multiple) {
            if(m_keysProgrammedCtr > 0 && !m_ready) {
                if(this->currentIndex() == Page_Quick) {
                    changeQuickConfigParams();
                } else {

                    changeAdvConfigParams();
                }
            }
        }
    }
}