1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
# Copyright (c) 2009, 2010 - OpenSLX Project, Computer Center University of
# Freiburg
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# clientConfigDialog.cpp
# - graphical interface
# - all configuration used by pvs/pvsgui is done here
# -----------------------------------------------------------------------------
*/
#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),
_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);
}
ClientConfigDialog::~ClientConfigDialog()
{
}
////////////////////////////////////////////////////////////////////////////////
// Public
void ClientConfigDialog::open()
{
readSettings();
setVisible(true);
}
void ClientConfigDialog::readSettings()
{
if (_settings.value("Display/location").isNull())
comboBox->setCurrentIndex(1);
else
comboBox->setCurrentIndex(_settings.value("Display/location").toInt());
if (_settings.value("Permissions/vnc_lecturer").toString() == "rw")
radioButtonLecturerRW->setChecked(true);
else if (_settings.value("Permissions/vnc_lecturer").toString() == "ro")
radioButtonLecturerRO->setChecked(true);
else
radioButtonLecturerNO->setChecked(true);
if (_settings.value("Permissions/vnc_other").toString() == "rw")
radioButtonOtherRW->setChecked(true);
else if (_settings.value("Permissions/vnc_other").toString() == "ro")
radioButtonOtherRO->setChecked(true);
else
radioButtonOtherNO->setChecked(true);
checkBoxAllowChat->setChecked(
_settings.value("Permissions/allow_chat").toBool());
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()));
}
void ClientConfigDialog::writeSettings()
{
_settings.setValue("Display/location", comboBox->currentIndex());
if (radioButtonLecturerRW->isChecked())
_settings.setValue("Permissions/vnc_lecturer", "rw");
else if (radioButtonLecturerRO->isChecked())
_settings.setValue("Permissions/vnc_lecturer", "ro");
else
_settings.setValue("Permissions/vnc_lecturer", "no");
if (radioButtonOtherRW->isChecked())
_settings.setValue("Permissions/vnc_other", "rw");
else if (radioButtonOtherRO->isChecked())
_settings.setValue("Permissions/vnc_other", "ro");
else
_settings.setValue("Permissions/vnc_other", "no");
_settings.setValue("Permissions/allow_chat", checkBoxAllowChat->isChecked());
_settings.setValue("Permissions/allow_filetransfer",
checkBoxAllowFiletransfer->isChecked());
_settings.setValue("Multicast/interface", interfaceList->currentText());
_settings.sync();
emit configChanged();
qDebug("[%s] Settings written to: '%s'.", metaObject()->className(),
qPrintable(_settings.fileName()));
}
////////////////////////////////////////////////////////////////////////////////
// Private
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
}
|