#include "systemitemsettingswidget.h"
#include "ui_systemitemsettingswidget.h"

SystemItemSettingsWidget::SystemItemSettingsWidget(std::weak_ptr<SystemItem> item, QWidget *parent) :
	QWidget(parent),
	item_(item),
	ui(new Ui::SystemItemSettingsWidget)
{
	ui->setupUi(this);
	if(auto itemPtr = item_.lock())
	{
		ui->lineEdit_on->setText(itemPtr->getOnCommand());
		ui->lineEdit_off->setText(itemPtr->getOffCommand());
	}
	else setDisabled(true);

	connect(ui->lineEdit_on, &QLineEdit::textChanged, this, &SystemItemSettingsWidget::setOn);
	connect(ui->lineEdit_off, &QLineEdit::textChanged, this, &SystemItemSettingsWidget::setOff);
}

void SystemItemSettingsWidget::setOn(const QString& in)
{
	if(auto itemPtr = item_.lock())
	{
		itemPtr->setOnCommand(in);
	}
}

void SystemItemSettingsWidget::setOff(const QString& in)
{
	if(auto itemPtr = item_.lock())
	{
		itemPtr->setOffCommand(in);
	}
}

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