// This file is generated by kconfig_compiler from 802-11-wireless.kcfg.
// All changes you do to this file will be lost.

#include "802-11-wirelessdbus.h"

#include "802-11-wireless.h"

WirelessDbus::WirelessDbus(Knm::WirelessSetting * setting) : SettingDbus(setting)
{
}

WirelessDbus::~WirelessDbus()
{
}

void WirelessDbus::fromMap(const QVariantMap & map)
{
  Knm::WirelessSetting * setting = static_cast<Knm::WirelessSetting *>(m_setting);
  if (map.contains("ssid")) {
    setting->setSsid(map.value("ssid").value<QByteArray>());
  }
  if (map.contains("mode")) {
    setting->setMode(map.value("mode").value<int>());
  }
  if (map.contains("band")) {
    setting->setBand(map.value("band").value<int>());
  }
  if (map.contains("channel")) {
    setting->setChannel(map.value("channel").value<uint>());
  }
  if (map.contains("bssid")) {
    setting->setBssid(map.value("bssid").value<QByteArray>());
  }
  if (map.contains("rate")) {
    setting->setRate(map.value("rate").value<uint>());
  }
  if (map.contains(QLatin1String(NM_SETTING_WIRELESS_TX_POWER))) {
    setting->setTxpower(map.value(QLatin1String(NM_SETTING_WIRELESS_TX_POWER)).value<uint>());
  }
  if (map.contains(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS))) {
    setting->setMacaddress(map.value(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS)).value<QByteArray>());
  }
  if (map.contains("mtu")) {
    setting->setMtu(map.value("mtu").value<uint>());
  }
  if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS))) {
    setting->setSeenbssids(map.value(QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS)).value<QStringList>());
  }
  if (map.contains("security")) {
    setting->setSecurity(map.value("security").value<QString>());
  }
}

QVariantMap WirelessDbus::toMap()
{
  QVariantMap map;
  Knm::WirelessSetting * setting = static_cast<Knm::WirelessSetting *>(m_setting);
  map.insert("ssid", setting->ssid());
  switch (setting->mode()) {
    case Knm::WirelessSetting::EnumMode::infrastructure:
      map.insert("mode", "infrastructure");
      break;
    case Knm::WirelessSetting::EnumMode::adhoc:
      map.insert("mode", "adhoc");
      break;
  }
  // leave out band, NM seems to work automatically without it
#if 0
  switch (setting->band()) {
    case Knm::WirelessSetting::EnumBand::a:
      map.insert("band", "a");
      break;
    case Knm::WirelessSetting::EnumBand::bg:
      map.insert("band", "bg");
      break;
  }
#endif
  //map.insert("channel", setting->channel());
  if (!setting->bssid().isEmpty()) {
      map.insert("bssid", setting->bssid());
  }
  //map.insert("rate", setting->rate());
  //map.insert(QLatin1String(NM_SETTING_WIRELESS_TX_POWER), setting->txpower());
  if (!setting->macaddress().isEmpty()) {
      map.insert(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS), setting->macaddress());
  }
  if (setting->mtu() > 0 )
       map.insert("mtu", setting->mtu());
  if (!setting->seenbssids().isEmpty()) {
      map.insert(QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS), setting->seenbssids());
  }
  if (!setting->security().isEmpty()) {
      map.insert("security", setting->security());
  }
  return map;
}

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

