#include "globalsettingsform.h"
#include "ui_globalsettingsform.h"

#include "globalsettings.h"
#include "../settingsservice.h"

GlobalSettingsForm::GlobalSettingsForm(QWidget *parent) :
    FormBinder<GlobalSettings>(parent),
    ui(new Ui::GlobalSettingsForm)
{
    ui->setupUi(this);

    registerBinding(ui->firmName);
    registerBinding(ui->street);
    registerBinding(ui->houseNumber);
    registerBinding(ui->zipCode);
    registerBinding(ui->city);
    registerBinding(ui->ic);
    registerBinding(ui->vatPayer);
    registerBinding(ui->dic);
}

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

bool GlobalSettingsForm::saveRecord()
{
    bindToData();
    SettingsService srv("CORE");
    srv.saveSettings(entity());

    return true;
}

void GlobalSettingsForm::loadEntity()
{
    SettingsService srv("CORE");
    QSharedPointer<GlobalSettings> settings = srv.loadSettings<GlobalSettings>();
    setEntity(settings);
}
