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

#include "802-1xdbus.h"

#include "802-1x.h"

Security8021xDbus::Security8021xDbus(Knm::Security8021xSetting * setting) : SettingDbus(setting)
{
}

Security8021xDbus::~Security8021xDbus()
{
}

void Security8021xDbus::fromMap(const QVariantMap & map)
{
    Knm::Security8021xSetting * setting = static_cast<Knm::Security8021xSetting *>(m_setting);
    if (setting->enabled()) {
        if (map.contains("eap")) {
            setting->setEap(map.value("eap").value<QStringList>());
        }
        if (map.contains("identity")) {
            setting->setIdentity(map.value("identity").value<QString>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_ANONYMOUS_IDENTITY))) {
            setting->setAnonymousidentity(map.value(QLatin1String(NM_SETTING_802_1X_ANONYMOUS_IDENTITY)).value<QString>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_CA_CERT))) {
            setting->setCacert(map.value(QLatin1String(NM_SETTING_802_1X_CA_CERT)).value<QByteArray>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_CA_PATH))) {
            setting->setCapath(map.value(QLatin1String(NM_SETTING_802_1X_CA_PATH)).value<QString>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_CLIENT_CERT))) {
            setting->setClientcert(map.value(QLatin1String(NM_SETTING_802_1X_CLIENT_CERT)).value<QByteArray>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER))) {
            setting->setPhase1peapver(map.value(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER)).value<int>() + 1 ); // 0 is automatic
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPLABEL))) {
            setting->setPhase1peaplabel(map.value(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPLABEL)).value<QString>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING))) {
            setting->setPhase1fastprovisioning(map.value(QLatin1String(NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING)).value<QString>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH))) {
            setting->setPhase2auth(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH)).value<int>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP))) {
            setting->setPhase2autheap(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP)).value<int>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_CERT))) {
            setting->setPhase2cacert(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_CERT)).value<QByteArray>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_PATH))) {
            setting->setPhase2capath(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_PATH)).value<QString>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_CLIENT_CERT))) {
            setting->setPhase2clientcert(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_CLIENT_CERT)).value<QByteArray>());
        }
        // SECRET
        if (map.contains("password")) {
            setting->setPassword(map.value("password").value<QString>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY))) {
            setting->setPrivatekey(map.value(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY)).value<QByteArray>());
        }
        // SECRET
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD))) {
            setting->setPrivatekeypassword(map.value(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD)).value<QString>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY))) {
            setting->setPhase2privatekey(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY)).value<QByteArray>());
        }
        // SECRET
        if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD))) {
            setting->setPhase2privatekeypassword(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD)).value<QString>());
        }
        if (map.contains("pin")) {
            setting->setPin(map.value("pin").value<QString>());
        }
        if (map.contains("psk")) {
            setting->setPsk(map.value("psk").value<QString>());
        }
        if (map.contains(QLatin1String(NM_SETTING_802_1X_SYSTEM_CA_CERTS))) {
            setting->setUseSystemCaCerts(map.value(QLatin1String(NM_SETTING_802_1X_SYSTEM_CA_CERTS)).value<bool>());
        }
    }
}

QVariantMap Security8021xDbus::toMap()
{
    QVariantMap map;
    Knm::Security8021xSetting * setting = static_cast<Knm::Security8021xSetting *>(m_setting);
    if (setting->enabled()) {
        if (!setting->eap().isEmpty()) {
            map.insert("eap", setting->eap());
        }
        if (!setting->identity().isEmpty()) {
            map.insert("identity", setting->identity());
        }
        if (!setting->anonymousidentity().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_ANONYMOUS_IDENTITY), setting->anonymousidentity());
        }
        if (!setting->cacert().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_CA_CERT), setting->cacert());
        }
        if (!setting->capath().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_CA_PATH), setting->capath());
        }
        if (!setting->clientcert().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_CLIENT_CERT), setting->clientcert());
        }
        if (setting->eap().contains(QLatin1String("peap"))) {
            switch (setting->phase1peapver()) {
                case Knm::Security8021xSetting::EnumPhase1peapver::zero:
                    map.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER), "0");
                    break;
                case Knm::Security8021xSetting::EnumPhase1peapver::one:
                    map.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER), "1");
                    if (!setting->phase1peaplabel().isEmpty()) {
                        map.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPLABEL), setting->phase1peaplabel());
                    }
                    break;
            }
        }
        if (!setting->phase1fastprovisioning().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING), setting->phase1fastprovisioning());
        }
        switch (setting->phase2auth()) {
            case Knm::Security8021xSetting::EnumPhase2auth::none:
                //map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "none");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::pap:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "pap");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::mschap:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "mschap");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::mschapv2:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "mschapv2");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::chap:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "chap");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::md5:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "md5");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::gtc:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "gtc");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::otp:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "otp");
                break;
        }
        switch (setting->phase2autheap()) {
            case Knm::Security8021xSetting::EnumPhase2autheap::none:
                //map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "none");
                break;
            case Knm::Security8021xSetting::EnumPhase2autheap::md5:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "md5");
                break;
            case Knm::Security8021xSetting::EnumPhase2autheap::gtc:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "gtc");
                break;
            case Knm::Security8021xSetting::EnumPhase2autheap::otp:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "otp");
                break;
            case Knm::Security8021xSetting::EnumPhase2autheap::mschapv2:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "mschapv2");
                break;
            case Knm::Security8021xSetting::EnumPhase2autheap::tls:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "tls");
                break;
        }
        if (!setting->phase2cacert().isEmpty())
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_CERT), setting->phase2cacert());
        if (!setting->phase2capath().isEmpty())
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_PATH), setting->phase2capath());
        if (!setting->phase2clientcert().isEmpty())
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CLIENT_CERT), setting->phase2clientcert());
        if (!setting->phase2privatekey().isEmpty())
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY), setting->phase2privatekey());
        if (!setting->privatekey().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY), setting->privatekey());
        }
        if (!setting->pin().isEmpty()) {
            map.insert("pin", setting->pin());
        }
        if (!setting->psk().isEmpty()) {
            map.insert("psk", setting->psk());
        }
        if (!setting->eap().contains(QLatin1String("leap"))) {
            map.insert(QLatin1String(NM_SETTING_802_1X_SYSTEM_CA_CERTS), setting->useSystemCaCerts());
        }
    }
    return map;
}

QVariantMap Security8021xDbus::toSecretsMap()
{
  QVariantMap map;
  Knm::Security8021xSetting * setting = static_cast<Knm::Security8021xSetting *>(m_setting);
  if (setting->enabled()) {
  map.insert("password", setting->password());
  map.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD), setting->privatekeypassword());
  map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD), setting->phase2privatekeypassword());
  }
  return map;
}

