// This file is generated by kconfig_compiler from serial.kcfg.
// All changes you do to this file will be lost.

#include "serialdbus.h"

#include "serial.h"

SerialDbus::SerialDbus(Knm::SerialSetting * setting) : SettingDbus(setting)
{
}

SerialDbus::~SerialDbus()
{
}

void SerialDbus::fromMap(const QVariantMap & map)
{
  Knm::SerialSetting * setting = static_cast<Knm::SerialSetting *>(m_setting);
  if (map.contains("baud")) {
    setting->setBaud(map.value("baud").value<uint>());
  }
  if (map.contains("bits")) {
    setting->setBits(map.value("bits").value<uint>());
  }
  if (map.contains("parity")) {
    setting->setParity(map.value("parity").value<int>());
  }
  if (map.contains("stopbits")) {
    setting->setStopbits(map.value("stopbits").value<uint>());
  }
  if (map.contains(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY))) {
    setting->setSenddelay(map.value(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY)).value<quint64>());
  }
}

QVariantMap SerialDbus::toMap()
{
  QVariantMap map;
  Knm::SerialSetting * setting = static_cast<Knm::SerialSetting *>(m_setting);
  insertIfNonZero(map, "baud", setting->baud());
  insertIfNonZero(map, "bits", setting->bits());
  switch (setting->parity()) {
//X     case Knm::SerialSetting::EnumParity::None:
//X       map.insert("parity", "n");
//X       break;
    case Knm::SerialSetting::EnumParity::Even:
      map.insert("parity", "E");
      break;
    case Knm::SerialSetting::EnumParity::Odd:
      map.insert("parity", "o");
      break;
  }
  insertIfNonZero(map, "stopbits", setting->stopbits());
  insertIfNonZero(map, NM_SETTING_SERIAL_SEND_DELAY, setting->senddelay());
  return map;
}

QVariantMap SerialDbus::toSecretsMap()
{
  QVariantMap map;
  return map;
}

