diff options
author | Sebastien Braun | 2010-08-04 17:28:45 +0200 |
---|---|---|
committer | Sebastien Braun | 2010-08-04 17:28:45 +0200 |
commit | f8e6e94b25a092d51acdec600465074b4eb32cb8 (patch) | |
tree | 8251b788b2a63abba5cf0d9e046102471cce1e59 /src/gui/clientConfigDialog.cpp | |
parent | Fix a bug where transfer IDs would linger in the pvs daemon's data structures... (diff) | |
download | pvs-f8e6e94b25a092d51acdec600465074b4eb32cb8.tar.gz pvs-f8e6e94b25a092d51acdec600465074b4eb32cb8.tar.xz pvs-f8e6e94b25a092d51acdec600465074b4eb32cb8.zip |
Make PGM interface configurable
Diffstat (limited to 'src/gui/clientConfigDialog.cpp')
-rw-r--r-- | src/gui/clientConfigDialog.cpp | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/gui/clientConfigDialog.cpp b/src/gui/clientConfigDialog.cpp index 76b4f5e..3867118 100644 --- a/src/gui/clientConfigDialog.cpp +++ b/src/gui/clientConfigDialog.cpp @@ -16,15 +16,32 @@ # ----------------------------------------------------------------------------- */ +#include <QtDebug> #include "clientConfigDialog.h" +#include <cerrno> +#include <cstdlib> +#include <cstring> + +// For getting the network interface list: +#ifdef __linux +# include <sys/ioctl.h> +# include <net/if.h> +#endif + +using namespace std; ClientConfigDialog::ClientConfigDialog(QWidget *parent) : - QDialog(parent) + QDialog(parent), + _interfaceListModel(0) { setupUi(this); connect(this, SIGNAL(accepted()), this, SLOT(writeSettings())); connect(radioButtonOtherRO, SIGNAL(clicked()), this, SLOT(checkPermissions())); + connect(reloadInterfaceListButton, SIGNAL(clicked()), this, SLOT(reloadNetworkInterfaceList())); + reloadNetworkInterfaceList(); + interfaceList->setModel(_interfaceListModel); + interfaceList->setModelColumn(0); } @@ -66,6 +83,9 @@ void ClientConfigDialog::readSettings() checkBoxAllowFiletransfer->setChecked(_settings.value( "Permissions/allow_filetransfer").toBool()); + if(!_settings.value("Muticast/interface").isNull()) + interfaceList->setEditText(_settings.value("Multicast/interface").toString()); + qDebug("[%s] Setting read from: '%s'", metaObject()->className(), qPrintable(_settings.fileName())); } @@ -88,6 +108,7 @@ void ClientConfigDialog::writeSettings() _settings.setValue("Permissions/allow_chat", checkBoxAllowChat->isChecked()); _settings.setValue("Permissions/allow_filetransfer", checkBoxAllowFiletransfer->isChecked()); + _settings.setValue("Multicast/interface", interfaceList->currentText()); _settings.sync(); emit configChanged(); @@ -103,3 +124,41 @@ void ClientConfigDialog::checkPermissions() if (radioButtonLecturerNO->isChecked() && radioButtonOtherRO->isChecked()) radioButtonLecturerRO->setChecked(true); } + +void ClientConfigDialog::reloadNetworkInterfaceList() +{ +#ifdef __linux + static struct ifreq ifreqs[20]; + ifconf ifconfigs; + memset(&ifconfigs, 0, sizeof(ifconfigs)); + ifconfigs.ifc_len = sizeof(ifreqs); + ifconfigs.ifc_buf = (char*)&ifreqs; + + int nosock = socket(AF_INET, SOCK_STREAM, 0); + if (nosock < 0) + { + qWarning() << "Could not get a socket descriptor:" << strerror(errno); + } + int retval; + if ((retval = ioctl(nosock, SIOCGIFCONF, (char*)(&ifconfigs))) < 0) + { + qWarning() << "Could not get the list of interfaces:" << strerror(errno); + return; + } + + QStringList interfaces; + for(int i = 0; i < ifconfigs.ifc_len/sizeof(struct ifreq); i++) + { + char ifname[IFNAMSIZ + 1]; + strncpy(ifname, ifreqs[i].ifr_name, IFNAMSIZ); + ifname[IFNAMSIZ] = '\0'; + interfaces << QString::fromLocal8Bit(ifname); + } + if(!_interfaceListModel) + _interfaceListModel = new QStringListModel(interfaces, this); + else + _interfaceListModel->setStringList(interfaces); +#else +# warning "We have no way to get your system's network interface list. Some porting may be required." +#endif +} |