2
* client_properties_edit.cpp - implementation of dialog for editing properties of a client
5
* Copyright (c) 2004-2005 Tobias Doerffel <tobias@doerffel.de>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* General Public License for more details.
17
* You should have received a copy of the GNU General Public
18
* License along with this program (see COPYING); if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
25
#include <qpushbutton.h>
26
#include <qlineedit.h>
27
#include <qcombobox.h>
30
#include <qmessagebox.h>
32
#include "client_properties_edit.h"
34
#include "client_manager.h"
37
#include "client_properties_edit.moc"
40
clientPropertiesEdit::clientPropertiesEdit( client * _client, const QString & _group_name, QWidget * _parent ) :
44
setCaption( tr( "Edit properties of client...") );
46
m_groupLbl = new QLabel( tr( "Client-group:" ), this );
47
m_groupLbl->setGeometry( 10, 25, 120, 20 );
49
m_nameLbl = new QLabel( tr( "Name:" ), this );
50
m_nameLbl->setGeometry( 10, 60, 120, 20 );
52
m_ipLbl = new QLabel( tr( "IP-address:" ), this );
53
m_ipLbl->setGeometry( 10, 95, 120, 20 );
55
m_macLbl = new QLabel( tr( "MAC-address:" ), this );
56
m_macLbl->setGeometry( 10, 130, 120, 20);
58
m_groupBox = new QComboBox( this );
59
m_groupBox->setGeometry( 130, 20, 200, 25 );
63
for( unsigned int i = 0; i < clientManager::inst()->m_classRooms.size(); ++i )
65
m_groupBox->insertItem( clientManager::inst()->m_classRooms[i]->text( 0 ) );
66
if( _group_name == clientManager::inst()->m_classRooms[i]->text( 0 ) )
72
m_groupBox->setCurrentItem( set_to_group );
74
m_nameEdit = new QLineEdit( this );
75
m_nameEdit->setGeometry( 130, 55, 200, 25 );
77
m_ipEdit = new QLineEdit( this );
78
m_ipEdit->setGeometry( 130, 90, 200, 25 );
80
m_macEdit = new QLineEdit( this );
81
m_macEdit->setGeometry( 130, 125, 200, 25 );
83
m_okBtn = new QPushButton( embed::getIconPixmap( "apply" ), tr( "OK" ), this );
84
m_okBtn->setGeometry( 90, 170, 110, 28 );
86
m_cancelBtn = new QPushButton( embed::getIconPixmap( "cancel" ), tr( "Cancel" ), this );
87
m_cancelBtn->setGeometry( 220, 170, 110, 28 );
90
if( m_client != NULL )
92
m_nameEdit->setText( m_client->name() );
93
m_ipEdit->setText( m_client->ip() );
94
m_macEdit->setText( m_client->mac() );
97
connect( m_okBtn, SIGNAL( clicked() ), this, SLOT( okBtnClicked() ) );
98
connect( m_cancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
104
clientPropertiesEdit::~clientPropertiesEdit()
111
void clientPropertiesEdit::okBtnClicked( void )
113
if( m_nameEdit->text() == "" )
115
QMessageBox::warning( NULL, tr( "Missing name for client" ), tr( "You didn't specify a name for the client!" ),
116
QMessageBox::Ok, QMessageBox::NoButton );
119
if( m_ipEdit->text() == "" )
121
QMessageBox::warning( NULL, tr( "Missing IP-address/hostname for client" ), tr( "You didn't specify an IP-address or hostname "
122
"for the client!" ), QMessageBox::Ok, QMessageBox::NoButton );
125
// check whether mac-address is valid
126
if( m_macEdit->text() != "" && QString( m_macEdit->text().upper()+":").find( QRegExp( "^([\\dA-F]{2}:){6}$" ) ) != 0 )
128
QMessageBox::warning( NULL, tr( "Invalid MAC-address" ), tr( "You specified an invalid MAC-address. Either leave the "
129
"field blank or enter a valid MAC-address." ), QMessageBox::Ok, QMessageBox::NoButton );
133
if( m_client == NULL )
135
m_client = new client( m_ipEdit->text(), m_macEdit->text(), m_nameEdit->text(),
136
clientManager::inst()->m_classRooms[m_groupBox->currentItem()] );
140
m_client->setName( m_nameEdit->text() );
141
m_client->setIP( m_ipEdit->text() );
142
m_client->setMac( m_macEdit->text() );
143
m_client->setClassRoom( clientManager::inst()->m_classRooms[m_groupBox->currentItem()] );
144
m_client->resetConnection();
153
void clientPropertiesEdit::keyPressEvent( QKeyEvent * _ke )
155
if( _ke->key() == Qt::Key_Escape )