#include "chooseversiondialog.h"
#include "ui_chooseversiondialog.h"

#include "models/lotrodatmanager.h"
#include "models/patchdownloader.h"
#include "widgets/mainwindow.h"

ChooseVersionDialog::ChooseVersionDialog(QSettings *settings, PatchDownloader *patch_downloader, LotroDatManager *lotro_dat_manager, QWidget *parent) :
    QWidget(parent), app_settings(settings), lotro_manager(lotro_dat_manager),
    ui(new Ui::ChooseVersionDialog)
{
//    setWindowModality(Qt::WindowModal);
    ui->setupUi(this);
    ui->wait_widget->hide();
    ui->cancel_widget->show();
}

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

void ChooseVersionDialog::show()
{
    QString locale_prefix = app_settings->value("General/original_locale", "English").toString();
    ui->start_original->setStyleSheet("QWidget#start_original{\n	border: 0;\n	border-image: url(:/buttons/run_" + locale_prefix + ".png);\n}\n\nQWidget#start_original:hover{\n	border: 3px;\n	border-image: url(:/buttons/run_" + locale_prefix + ".png);\n}");
    QWidget::show();
}

void ChooseVersionDialog::on_start_patched_clicked()
{
    ui->wait_widget->show();
    ui->cancel_widget->hide();
    QMetaObject::invokeMethod(lotro_manager, "StartGame", Qt::QueuedConnection, Q_ARG(LOTRO_DAT::DatLocaleManager::LOCALE, LOTRO_DAT::DatLocaleManager::PATCHED));
}

void ChooseVersionDialog::on_start_original_clicked()
{
    ui->wait_widget->show();
    ui->cancel_widget->hide();
    QMetaObject::invokeMethod(lotro_manager, "StartGame", Qt::QueuedConnection, Q_ARG(LOTRO_DAT::DatLocaleManager::LOCALE, LOTRO_DAT::DatLocaleManager::ORIGINAL));
}

void ChooseVersionDialog::on_cancel_clicked()
{
    hide();
    emit cancelled();
}
