#include "entrywidget.h"
#include "ui_entrywidget.h"

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

void EntryWidget::initialize()
{
    ui->offlineWidget->hide();
    ui->loginWidget->hide();
    ui->settingsWidget->hide();
}

void EntryWidget::disconnectState()
{
    show();
    ui->offlineWidget->show();
    ui->loginWidget->hide();
}

void EntryWidget::settingsState()
{
    ui->loginWidget->hide();
    ui->offlineWidget->hide();
}

ClientAutorization* EntryWidget::getAuthData()
{
    ClientAutorization *data = new ClientAutorization;
    QString username = ui->loginInputField->text();
    QString password = ui->passwordInputField->text();
    data->Login = username;
    data->Password = password;

    return data;
}

void EntryWidget::showLoginWidget(bool flag)
{
    if(flag)
    {
        ui->loginWidget->show();
        ui->offlineWidget->hide();
    }
    else ui->loginWidget->hide();
}

void EntryWidget::on_loginButton_clicked()
{
    emit sigTryLogin();
}

void EntryWidget::on_saveServerButton_clicked()
{
    emit sigSaveServerSettings();
}

ServerSettings *EntryWidget::getServerSettings()
{
    ServerSettings *data = new ServerSettings;
    QString server = ui->serverInputField->text();
    QString port = ui->portInputField->text();
    //bool checked = ui->mathModelUsecheckBox->isChecked();

    data->Address = server;
    data->Port = port;
    data->mathModelUse = true;

    return data;
}

void EntryWidget::fillSettings(ServerSettings *settings)
{
    ui->serverInputField->setText(settings->Address);
    ui->portInputField->setText(settings->Port);
    //ui->mathModelUsecheckBox->setChecked(settings->mathModelUse);
}

void EntryWidget::isActive(bool flag)
{
    if (flag) ui->settingsWidget->show();
    else ui->settingsWidget->hide();
}

bool EntryWidget::getLoginWidgetIsHidden()
{
    return ui->loginWidget->isHidden();
}


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




