Logo Search packages:      
Sourcecode: kdeadmin-kde4 version File versions  Download package

void KNetworkConf::configureDeviceSlot (  )  [private, virtual, slot]

Pops up the window for adding a new interface.

Definition at line 231 of file knetworkconf.cpp.

References KAddDeviceContainer::addButtons(), KAddDeviceContainer::addDlg, KAddDeviceContainer::addWirelessWidget(), KAddDeviceContainer::advanced(), KAddressValidator::calculateBroadcast(), KAddressValidator::calculateNetwork(), enableApplyButtonSlot(), KAddDeviceContainer::extDlg, KNetworkInterface::getBootProto(), KNetworkInterface::getBroadcast(), KNetworkInterface::getDescription(), getDeviceInfo(), KWirelessInterface::getEssid(), KNetworkInterface::getIpAddress(), KNetworkInterface::getNetmask(), KNetworkInterface::getOnBoot(), KNetworkInterface::getType(), KWirelessInterface::getWepKey(), KAddDeviceContainer::kpbAdvanced, KAddDeviceContainer::kpbApply, KAddDeviceContainer::modified(), KNetworkInterface::setBootProto(), KNetworkInterface::setBroadcast(), KNetworkInterface::setDescription(), KWirelessInterface::setEssid(), KNetworkInterface::setIpAddress(), KNetworkInterface::setNetmask(), KNetworkInterface::setNetwork(), KNetworkInterface::setOnBoot(), KWirelessInterface::setWepKey(), and valuesChanged().

Referenced by disableAll().

                                      {
  Q3ListViewItem *item = klvCardList->currentItem();
  KWirelessInterface *wifiDev = NULL;

  //KAddDeviceContainer *configDlg = new KAddDeviceContainer(this,0);
  KAddDeviceContainer configDlg(this,0);

  if (item != NULL)
  {
    QString currentDevice = item->text(0);
    configDlg.setCaption(i18n("Configure Device %1", currentDevice));
    KNetworkInterface *dev = getDeviceInfo(currentDevice);
    KAddDeviceDlgExtension *advancedOptions = (KAddDeviceDlgExtension *)configDlg.extension();

    if (dev->getBootProto() == "none")
    {
      configDlg.addDlg->rbBootProtoManual->setChecked(true);
      configDlg.addDlg->rbBootProtoAuto->setChecked(false);
    }
    else if (dev->getBootProto().toLower() == "dhcp")
    {
      configDlg.addDlg->kcbAutoBootProto->setCurrentItem(0);
      configDlg.addDlg->rbBootProtoManual->setChecked(false);
      configDlg.addDlg->rbBootProtoAuto->setChecked(true);
      configDlg.addDlg->kleIPAddress->setEnabled(false);
      configDlg.addDlg->kcbNetmask->setEnabled(false);
      configDlg.kpbAdvanced->setEnabled(false);
    }
   else if (dev->getBootProto().toLower() == "bootp")
    {
      configDlg.addDlg->kcbAutoBootProto->setCurrentIndex(1);
      configDlg.addDlg->rbBootProtoManual->setChecked(false);
      configDlg.addDlg->rbBootProtoAuto->setChecked(true);
      configDlg.kpbAdvanced->setEnabled(false);
    }
    if (dev->getOnBoot() == "yes")
      configDlg.addDlg->kcbstartAtBoot->setChecked(true);
    else
    {
      configDlg.addDlg->kcbstartAtBoot->setChecked(false);
    }
    configDlg.addDlg->kleIPAddress->setText(dev->getIpAddress());
    advancedOptions->kleDescription->setText(dev->getDescription());
    advancedOptions->kleBroadcast->setText(dev->getBroadcast());

    if (!dev->getNetmask().isEmpty())
      configDlg.addDlg->kcbNetmask->setCurrentText(dev->getNetmask());

    if (readOnly)
    {
      configDlg.addDlg->kcbAutoBootProto->setEnabled(false);
      configDlg.addDlg->kcbstartAtBoot->setEnabled(false);
      advancedOptions->gbAdvancedDeviceInfo->setEnabled(false);
    }

    //If the interface is wireless, then add the wireless configuration widget
    if (dev->getType() == WIRELESS_IFACE_TYPE){
      wifiDev = static_cast<KWirelessInterface*>(dev);
      configDlg.addWirelessWidget();
      configDlg.extDlg->kleEssid->setText(wifiDev->getEssid());
      configDlg.extDlg->kleWepKey->setText(wifiDev->getWepKey());
    }

    configDlg.addButtons();
    //Disable Apply button so it only is enabled when a change is made
    configDlg.kpbApply->setEnabled(false);
    configDlg.exec();

    if (configDlg.modified())
    {
      if(configDlg.addDlg->rbBootProtoManual->isChecked())
      {
        item->setText(2,i18n("Manual"));
      dev->setBootProto("none");
      }
      //If the selected boot protocol is dhcp or bootp (Auto), then we don't need the
      //past IP address, netmask, network and broadcast, as a new one will be assigned by
      //the dhcp server.
      else if (configDlg.addDlg->rbBootProtoAuto->isChecked())
      {
        if (configDlg.addDlg->kcbAutoBootProto->currentText() != dev->getBootProto())
        {
          dev->setIpAddress("");
          configDlg.addDlg->kleIPAddress->setText("");
          dev->setNetmask("");
          dev->setNetwork("");
          dev->setBroadcast("");
        }
        item->setText(2,configDlg.addDlg->kcbAutoBootProto->currentText());
        dev->setBootProto(configDlg.addDlg->kcbAutoBootProto->currentText());
      }
      item->setText(1,configDlg.addDlg->kleIPAddress->text());
      item->setText(4,advancedOptions->kleDescription->text());

        if (valuesChanged(dev,
                        configDlg.addDlg->kcbAutoBootProto->currentText(),
                        configDlg.addDlg->kcbNetmask->currentText(),
                        configDlg.addDlg->kleIPAddress->text(),
                        configDlg.addDlg->kcbstartAtBoot->isChecked(),
                  advancedOptions->kleDescription->text(),
                  advancedOptions->kleBroadcast->text()))
        {
          dev->setIpAddress(configDlg.addDlg->kleIPAddress->text().trimmed());
          dev->setNetmask(configDlg.addDlg->kcbNetmask->currentText().trimmed());
          QString network = KAddressValidator::calculateNetwork(dev->getIpAddress().trimmed(),dev->getNetmask().trimmed());
          dev->setNetwork(network);
          QString broadcast;
          if (configDlg.advanced())
                broadcast = advancedOptions->kleBroadcast->text().trimmed();
        else
            broadcast = KAddressValidator::calculateBroadcast(dev->getIpAddress().trimmed(),dev->getNetmask().trimmed());
          dev->setBroadcast(broadcast);
          dev->setDescription(advancedOptions->kleDescription->text());

          if (configDlg.addDlg->kcbstartAtBoot->isChecked())
            dev->setOnBoot("yes");
          else
            dev->setOnBoot("no");
        }
        //If the interface is wireless, then save the wireless configuration options
        if (dev->getType() == WIRELESS_IFACE_TYPE){
          wifiDev->setEssid(configDlg.extDlg->kleEssid->text());
          wifiDev->setWepKey(configDlg.extDlg->kleWepKey->text());
          dev = wifiDev;
        }
        devicesModified = true;
        enableApplyButtonSlot();
    }
  }
}


Generated by  Doxygen 1.6.0   Back to index