~ubuntu-branches/debian/lenny/italc/lenny

« back to all changes in this revision

Viewing changes to master/italc/src/client_properties_edit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-06-17 13:46:54 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080617134654-cl0gi4u524cv1ici
Tags: 1:1.0.9~rc3-1
* Package new upstream version
  - upstream ported the code to qt4.4 (Closes: #481974)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * client_properties_edit.cpp - implementation of dialog for editing properties of a client
3
 
 *
4
 
 * iTALC
5
 
 * Copyright (c) 2004-2005 Tobias Doerffel <tobias@doerffel.de>
6
 
 *
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.
11
 
 *
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.
16
 
 *
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.
21
 
 *
22
 
 */
23
 
 
24
 
 
25
 
#include <qpushbutton.h>
26
 
#include <qlineedit.h>
27
 
#include <qcombobox.h>
28
 
#include <qlabel.h>
29
 
#include <qregexp.h>
30
 
#include <qmessagebox.h>
31
 
 
32
 
#include "client_properties_edit.h"
33
 
#include "client.h"
34
 
#include "client_manager.h"
35
 
#include "embed.h"
36
 
 
37
 
#include "client_properties_edit.moc"
38
 
 
39
 
 
40
 
clientPropertiesEdit::clientPropertiesEdit( client * _client, const QString & _group_name, QWidget * _parent ) :
41
 
        QDialog( _parent ),
42
 
        m_client( _client )
43
 
{
44
 
        setCaption( tr( "Edit properties of client...") );
45
 
 
46
 
        m_groupLbl = new QLabel( tr( "Client-group:" ), this );
47
 
        m_groupLbl->setGeometry( 10, 25, 120, 20 );
48
 
 
49
 
        m_nameLbl = new QLabel( tr( "Name:" ), this );
50
 
        m_nameLbl->setGeometry( 10, 60, 120, 20 );
51
 
 
52
 
        m_ipLbl = new QLabel( tr( "IP-address:" ), this );
53
 
        m_ipLbl->setGeometry( 10, 95, 120, 20 );
54
 
 
55
 
        m_macLbl = new QLabel( tr( "MAC-address:" ), this );
56
 
        m_macLbl->setGeometry( 10, 130, 120, 20);
57
 
 
58
 
        m_groupBox = new QComboBox( this );
59
 
        m_groupBox->setGeometry( 130, 20, 200, 25 );
60
 
        
61
 
        int set_to_group = 0;
62
 
 
63
 
        for( unsigned int i = 0; i < clientManager::inst()->m_classRooms.size(); ++i )
64
 
        {
65
 
                m_groupBox->insertItem( clientManager::inst()->m_classRooms[i]->text( 0 ) );
66
 
                if( _group_name == clientManager::inst()->m_classRooms[i]->text( 0 ) )
67
 
                {
68
 
                        set_to_group = i;
69
 
                }
70
 
        }
71
 
 
72
 
        m_groupBox->setCurrentItem( set_to_group );
73
 
 
74
 
        m_nameEdit = new QLineEdit( this );
75
 
        m_nameEdit->setGeometry( 130, 55, 200, 25 );
76
 
 
77
 
        m_ipEdit = new QLineEdit( this );
78
 
        m_ipEdit->setGeometry( 130, 90, 200, 25 );
79
 
 
80
 
        m_macEdit = new QLineEdit( this );
81
 
        m_macEdit->setGeometry( 130, 125, 200, 25 );
82
 
 
83
 
        m_okBtn = new QPushButton( embed::getIconPixmap( "apply" ), tr( "OK" ), this );
84
 
        m_okBtn->setGeometry( 90, 170, 110, 28 );
85
 
 
86
 
        m_cancelBtn = new QPushButton( embed::getIconPixmap( "cancel" ), tr( "Cancel" ), this );
87
 
        m_cancelBtn->setGeometry( 220, 170, 110, 28 );
88
 
 
89
 
 
90
 
        if( m_client != NULL )
91
 
        {
92
 
                m_nameEdit->setText( m_client->name() );
93
 
                m_ipEdit->setText( m_client->ip() );
94
 
                m_macEdit->setText( m_client->mac() );
95
 
        }
96
 
 
97
 
        connect( m_okBtn, SIGNAL( clicked() ), this, SLOT( okBtnClicked() ) );
98
 
        connect( m_cancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
99
 
}
100
 
 
101
 
 
102
 
 
103
 
 
104
 
clientPropertiesEdit::~clientPropertiesEdit()
105
 
{
106
 
}
107
 
 
108
 
 
109
 
 
110
 
 
111
 
void clientPropertiesEdit::okBtnClicked( void )
112
 
{
113
 
        if( m_nameEdit->text() == "" )
114
 
        {
115
 
                QMessageBox::warning( NULL, tr( "Missing name for client" ), tr( "You didn't specify a name for the client!" ),
116
 
                                        QMessageBox::Ok, QMessageBox::NoButton );
117
 
                return;
118
 
        }
119
 
        if( m_ipEdit->text() == "" )
120
 
        {
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 );
123
 
                return;
124
 
        }
125
 
        // check whether mac-address is valid
126
 
        if( m_macEdit->text() != "" && QString( m_macEdit->text().upper()+":").find( QRegExp( "^([\\dA-F]{2}:){6}$" ) ) != 0 )
127
 
        {
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 );
130
 
                return;
131
 
        }
132
 
 
133
 
        if( m_client == NULL )
134
 
        {
135
 
                m_client = new client( m_ipEdit->text(), m_macEdit->text(), m_nameEdit->text(),
136
 
                                        clientManager::inst()->m_classRooms[m_groupBox->currentItem()] );
137
 
        }
138
 
        else
139
 
        {
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();
145
 
        }
146
 
 
147
 
        accept();
148
 
}
149
 
 
150
 
 
151
 
 
152
 
 
153
 
void clientPropertiesEdit::keyPressEvent( QKeyEvent * _ke )
154
 
{
155
 
        if( _ke->key() == Qt::Key_Escape )
156
 
        {
157
 
                reject();
158
 
        }
159
 
}
160