#include "dicomcfgdialog.h"
#include "ui_dicomcfgdialog.h"
#include <QDialogButtonBox>
#include <QPushButton>

#include "json/jsonobject.h"
dicomCfgDialog::dicomCfgDialog(QWidget* parent) :
	QDialog(parent),
	ui(new Ui::dicomCfgDialog)
{
	ui->setupUi(this);
	//this->setFixedWidth(500);
	this->setObjectName("formDialog");
	this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);

	ui->btn_group->button(QDialogButtonBox::Apply)->setText(tr("Apply"));
	ui->btn_group->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));

	loadServersInfo();

	connect(ui->btn_group->button(QDialogButtonBox::Apply), &QPushButton::clicked, [=]()
		{
			saveServersInfo();
			accept();
		});
	connect(ui->btn_group->button(QDialogButtonBox::Cancel), &QPushButton::clicked, [=]()
		{
			reject();
		});
	ui->tabWidget->setCurrentIndex(0);
}

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


void dicomCfgDialog::loadServersInfo()
{
	host h;
	h = JsonObject::Instance()->getServer(JsonObject::RECON);
	ui->recon_AE->setText(h.ae);
	ui->recon_IP->setText(h.ip);
	ui->recon_Name->setText(h.name);
	ui->recon_Port->setText(h.port);

	h = JsonObject::Instance()->getServer(JsonObject::PACS);
	ui->pacs_AE->setText(h.ae);
	ui->pacs_IP->setText(h.ip);
	ui->pacs_Name->setText(h.name);
	ui->pacs_Port->setText(h.port);


	h = JsonObject::Instance()->getServer(JsonObject::WORKLIST);
	ui->wl_AE->setText(h.ae);
	ui->wl_IP->setText(h.ip);
	ui->wl_Name->setText(h.name);
	ui->wl_Port->setText(h.port);



	//qIfConfig(lhost);


}


void dicomCfgDialog::saveServersInfo()
{

	host h;
	h.ae = ui->recon_AE->text();
	h.ip = ui->recon_IP->text();
	h.name = ui->recon_Name->text();
	h.port = ui->recon_Port->text();
	JsonObject::Instance()->setServer(JsonObject::RECON, h);

	h.ae = ui->pacs_AE->text();
	h.ip = ui->pacs_IP->text();
	h.name = ui->pacs_Name->text();
	h.port = ui->pacs_Port->text();
	JsonObject::Instance()->setServer(JsonObject::PACS, h);

	h.ip = ui->wl_IP->text();
	h.ae = ui->wl_AE->text();
	h.name = ui->wl_Name->text();
	h.port = ui->wl_Port->text();
	JsonObject::Instance()->setServer(JsonObject::WORKLIST, h);





}