/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2013, Regents of the University of California
 *                     Yingdi Yu
 *
 * BSD license, See the LICENSE file for more information
 *
 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
 */

#include "setting-dialog.hpp"
#include "ui_setting-dialog.h"

namespace chronos {

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

  connect(ui->saveButton, SIGNAL(clicked()),
          this, SLOT(onSaveClicked()));
  connect(ui->cancelButton, SIGNAL(clicked()),
          this, SLOT(onCancelClicked()));
}

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

void
SettingDialog::setNick(const QString& nick)
{
  m_nick = nick;
  ui->nickLine->setText(m_nick);
}

void
SettingDialog::onIdentityUpdated(const QString& identity)
{
  m_identity = identity;
  ui->identityLine->setText(m_identity);
}

void
SettingDialog::onSaveClicked()
{
  QString identity = ui->identityLine->text();
  QString nick = ui->nickLine->text();

  if(identity != m_identity)
    {
      m_identity = identity;
      emit identityUpdated(identity);
    }
  if(nick != m_nick)
    {
      m_nick = nick;
      emit nickUpdated(nick);
    }

  this->close();
}

void
SettingDialog::onCancelClicked()
{
  this->close();
}

} // namespace chronos

#if WAF
#include "setting-dialog.moc"
// #include "setting-dialog.cpp.moc"
#endif
