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

#include "802-3-ethernetpersistence.h"

#include "802-3-ethernet.h"

using namespace Knm;

WiredPersistence::WiredPersistence(WiredSetting * setting, KSharedConfig::Ptr config, ConnectionPersistence::SecretStorageMode mode) : SettingPersistence(setting, config, mode)
{
}

WiredPersistence::~WiredPersistence()
{
}

void WiredPersistence::load()
{
  WiredSetting * setting = static_cast<WiredSetting *>(m_setting);
  {
    QString contents = m_config->readEntry("port", "tp");
    if (contents == "tp")
      setting->setPort(WiredSetting::EnumPort::tp);
    else     if (contents == "aui")
      setting->setPort(WiredSetting::EnumPort::aui);
    else     if (contents == "bnc")
      setting->setPort(WiredSetting::EnumPort::bnc);
    else     if (contents == "mii")
      setting->setPort(WiredSetting::EnumPort::mii);

  }
  setting->setSpeed(m_config->readEntry("speed", 0));
  {
    QString contents = m_config->readEntry("duplex", "full");
    if (contents == "half")
      setting->setDuplex(WiredSetting::EnumDuplex::half);
    else     if (contents == "full")
      setting->setDuplex(WiredSetting::EnumDuplex::full);

  }
  setting->setAutonegotiate(m_config->readEntry("autonegotiate", true));
  setting->setMacaddress(m_config->readEntry("macaddress", QByteArray()));
  setting->setMtu(m_config->readEntry("mtu", 0));
  setting->setInitialized();
}

void WiredPersistence::save()
{
  WiredSetting * setting = static_cast<WiredSetting *>(m_setting);
  switch (setting->port()) {
    case WiredSetting::EnumPort::tp:
      m_config->writeEntry("port", "tp");
      break;
    case WiredSetting::EnumPort::aui:
      m_config->writeEntry("port", "aui");
      break;
    case WiredSetting::EnumPort::bnc:
      m_config->writeEntry("port", "bnc");
      break;
    case WiredSetting::EnumPort::mii:
      m_config->writeEntry("port", "mii");
      break;
  }
  m_config->writeEntry("speed", setting->speed());
  switch (setting->duplex()) {
    case WiredSetting::EnumDuplex::half:
      m_config->writeEntry("duplex", "half");
      break;
    case WiredSetting::EnumDuplex::full:
      m_config->writeEntry("duplex", "full");
      break;
  }
  m_config->writeEntry("autonegotiate", setting->autonegotiate());
  m_config->writeEntry("macaddress", setting->macaddress());
  m_config->writeEntry("mtu", setting->mtu());
}

QMap<QString,QString> WiredPersistence::secrets() const
{
  QMap<QString,QString> map;
  return map;
}

void WiredPersistence::restoreSecrets(QMap<QString,QString> secrets) const
{
  if (m_storageMode == ConnectionPersistence::Secure) {
  Q_UNUSED(secrets);
  }
}
