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

#include "gsmdbus.h"

#include "gsm.h"

GsmDbus::GsmDbus(Knm::GsmSetting * setting) : SettingDbus(setting)
{
}

GsmDbus::~GsmDbus()
{
}

void GsmDbus::fromMap(const QVariantMap & map)
{
  Knm::GsmSetting * setting = static_cast<Knm::GsmSetting *>(m_setting);
  if (map.contains("number")) {
    setting->setNumber(map.value("number").value<QString>());
  }
  if (map.contains("username")) {
    setting->setUsername(map.value("username").value<QString>());
  }
  // SECRET
  if (map.contains("password")) {
    setting->setPassword(map.value("password").value<QString>());
  }
  if (map.contains("apn")) {
    setting->setApn(map.value("apn").value<QString>());
  }
  if (map.contains(QLatin1String(NM_SETTING_GSM_NETWORK_ID))) {
    setting->setNetworkid(map.value(QLatin1String(NM_SETTING_GSM_NETWORK_ID)).value<QString>());
  }
  if (map.contains(QLatin1String(NM_SETTING_GSM_NETWORK_TYPE))) {
    setting->setNetworktype(map.value(QLatin1String(NM_SETTING_GSM_NETWORK_TYPE)).value<int>());
  } else {
      setting->setNetworktype(NM_GSM_NETWORK_ANY);
  }
  if (map.contains("band")) {
    setting->setBand(map.value("band").value<int>());
  }
  // SECRET
  if (map.contains("pin")) {
    setting->setPin(map.value("pin").value<QString>());
  }
  // SECRET
  if (map.contains("puk")) {
    setting->setPuk(map.value("puk").value<QString>());
  }
}

QVariantMap GsmDbus::toMap()
{
  QVariantMap map;
  Knm::GsmSetting * setting = static_cast<Knm::GsmSetting *>(m_setting);
  if (!setting->number().isEmpty())
      map.insert("number", setting->number());
  if (!setting->username().isEmpty())
      map.insert("username", setting->username());
  if (!setting->apn().isEmpty())
      map.insert("apn", setting->apn());
  if (!setting->networkid().isEmpty())
      map.insert(QLatin1String(NM_SETTING_GSM_NETWORK_ID), setting->networkid());
  if (setting->networktype() != NM_GSM_NETWORK_ANY) {
      map.insert(QLatin1String(NM_SETTING_GSM_NETWORK_TYPE), setting->networktype());
  }

  //map.insert("band", setting->band());
  return map;
}

QVariantMap GsmDbus::toSecretsMap()
{
  QVariantMap map;
  Knm::GsmSetting * setting = static_cast<Knm::GsmSetting *>(m_setting);
  if (!setting->password().isEmpty())
      map.insert("password", setting->password());
  if (!setting->pin().isEmpty())
      map.insert("pin", setting->pin());
  if (!setting->puk().isEmpty())
      map.insert("puk", setting->puk());
  return map;
}

