#include "qmk_kbd_list.h"
#include "ui_qmk_kbd_list.h"

qmk_kbd_list::qmk_kbd_list(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::qmk_kbd_list)
{
    ui->setupUi(this);
}

qmk_kbd_list::~qmk_kbd_list()
{
    delete ui;
}

void qmk_kbd_list::setInfo(QFileInfoList revisions, QFileInfoList keymaps)
{
    m_revisions = revisions;
    m_keymaps = keymaps;
    ui->revList->clear();
    ui->keymapList->clear();
    foreach (QFileInfo info, revisions)
        ui->revList->addItem(info.fileName());
    foreach (QFileInfo info, keymaps)
        ui->keymapList->addItem(info.fileName());
    if(revisions.size() != 0)
        ui->revList->setCurrentRow(0);
    if(keymaps.size() != 0)
        ui->keymapList->setCurrentRow(0);
    m_currentRev = -1;
    m_currentKeymap = -1;
}

QFileInfo qmk_kbd_list::getRev()
{

}

QFileInfo qmk_kbd_list::getKeymap()
{

}

void qmk_kbd_list::on_ok_clicked()
{
//    m_isShowing = false;
//    if ((ui->revList->currentRow() < 0) || (ui->keymapList->currentRow() < 0))
//        emit kbdSelected(QFileInfo(""), QFileInfo(""));
//    else
//        emit kbdSelected(m_revisions[ui->revList->currentRow()], m_keymaps[ui->keymapList->currentRow()]);
    m_currentRev = ui->revList->currentRow();
    m_currentKeymap = ui->keymapList->currentRow();
    this->close();
}

void qmk_kbd_list::on_cancel_clicked()
{
    this->close();
}

void qmk_kbd_list::closeEvent(QCloseEvent *e)
{
    emit kbdSelected(m_currentRev, m_currentKeymap);
}
