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

« back to all changes in this revision

Viewing changes to master/italc/src/client_manager.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_manager.cpp - implementation of client-manager (partly based on qt-clientManager-example)
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 <math.h>
26
 
#include <qmessagebox.h>
27
 
#include <qtimer.h>
28
 
#include <qfiledialog.h>
29
 
#include <qpopupmenu.h>
30
 
#include <qlabel.h>
31
 
#include <qworkspace.h>
32
 
#include <qvbox.h>
33
 
#include <qtoolbutton.h>
34
 
#include <qsplitter.h>
35
 
#include <qwhatsthis.h>
36
 
#include <qdatetime.h>
37
 
#if QT_VERSION >= 0x030200
38
 
#include <qsplashscreen.h>
39
 
#endif
40
 
 
41
 
#include "italc.h"
42
 
#include "client_manager.h"
43
 
#include "client.h"
44
 
#include "client_properties_edit.h"
45
 
#include "cmd_input_dialog.h"
46
 
#include "msg_input_dialog.h"
47
 
#include "text_input_dialog.h"
48
 
#include "embed.h"
49
 
#include "version.h"
50
 
#include "paths.h"
51
 
#include "progress_information.h"
52
 
#include "italc_side_bar.h"
53
 
#include "system_environment.h"
54
 
#include "qt3_compat.h"
55
 
 
56
 
#include "client_manager.moc"
57
 
 
58
 
 
59
 
template<typename T>
60
 
inline T roundCorrect( T _val )
61
 
{
62
 
        if( _val-floor( _val ) < 0.5 )
63
 
        {
64
 
                return( floor( _val ) );
65
 
        }
66
 
        return( ceil( _val ) );
67
 
}
68
 
 
69
 
 
70
 
 
71
 
 
72
 
const int widths[] = { 128, 192, 256, 320, 384, 448, 512, /*576, 640, 704, 768, 832, 896, 960, 1024, 1088, 1152, 1216, 1280, */0 };
73
 
 
74
 
 
75
 
 
76
 
QPixmap * classRoomItem::s_clientPixmap = NULL;
77
 
QPixmap * classRoomItem::s_clientObservedPixmap = NULL;
78
 
 
79
 
 
80
 
clientManager * clientManager::s_instOfMe = NULL;
81
 
 
82
 
 
83
 
clientManager::clientManager() :
84
 
        sideBarWidget( tr( "Client-Manager" ), embed::getIconPixmap( "client_manager" ), italc::inst()->m_splitter ),
85
 
        m_personalConfiguration( QDir::home().path() + "/" + QString( ITALC_CONFIG_PATH ) + "/personal-config.xml" ),
86
 
        m_globalClientConfiguration( QDir::home().path() + "/" + QString( ITALC_CONFIG_PATH ) + "/global-client-config.xml" ),
87
 
        m_quickSwitchMenu( new QPopupMenu( this ) ),
88
 
        m_clientUpdateInterval( 1 )
89
 
{
90
 
        s_instOfMe = this;
91
 
 
92
 
        m_list = new QListView( contentParent() );
93
 
        QWhatsThis::add( m_list, tr( "In this list clients and classrooms are managed. You can add clients or "
94
 
                                        "classrooms by clicking with the right mousebutton in this list." ) );
95
 
 
96
 
        m_list->addColumn( tr("Clients") );
97
 
        m_list->addColumn( tr("IP-address") );
98
 
        m_list->setSelectionMode( QListView::Extended );
99
 
        m_list->setTreeStepSize( 12 );
100
 
        m_list->setDefaultRenameAction( QListView::Accept );
101
 
        m_list->setSorting( 0 );
102
 
        m_list->setRootIsDecorated( TRUE );
103
 
        m_list->setShowToolTips( TRUE );
104
 
        m_list->setCaption( tr( "Client-Manager" ) );
105
 
#if QT_VERSION >= 0x030200
106
 
        connect( m_list, SIGNAL( doubleClicked( QListViewItem *, const QPoint &, int ) ), this,
107
 
                        SLOT( itemDoubleClicked( QListViewItem *, const QPoint &, int ) ) );
108
 
#else
109
 
        connect( m_list, SIGNAL( doubleClicked( QListViewItem * ) ), this,
110
 
                        SLOT( itemDoubleClicked( QListViewItem * ) ) );
111
 
#endif
112
 
        connect( m_list, SIGNAL( contextMenuRequested( QListViewItem *, const QPoint &, int ) ), this,
113
 
                        SLOT( contextMenuRequest( QListViewItem *, const QPoint &, int ) ) );
114
 
 
115
 
 
116
 
        QFont f;
117
 
        f.setPixelSize( 12 );
118
 
        QLabel * help_txt = new QLabel( tr( "Use the context-menu (right mouse-button) for adding/removing clients and/or "
119
 
                                                "classrooms. Once you added clients you can show or hide them by "
120
 
                                                "double-clicking them. You can also show or hide a whole classroom by "
121
 
                                                "clicking right at it and selecting \"Show/hide all clients in room\"." ),
122
 
                                        contentParent() );
123
 
        help_txt->setAlignment( help_txt->alignment()|WordBreak );
124
 
        help_txt->setFont( f );
125
 
 
126
 
        loadGlobalClientConfig();
127
 
        loadPersonalConfig();
128
 
 
129
 
        show();
130
 
}
131
 
 
132
 
 
133
 
 
134
 
 
135
 
clientManager::~clientManager()
136
 
{
137
 
}
138
 
 
139
 
 
140
 
 
141
 
 
142
 
void clientManager::doCleanupWork( void )
143
 
{
144
 
        while( m_clientsToRemove.size() )
145
 
        {
146
 
                delete m_clientsToRemove[0];
147
 
                m_clientsToRemove.erase( m_clientsToRemove.begin() );
148
 
        }
149
 
 
150
 
        while( m_classRoomsToRemove.size() )
151
 
        {
152
 
                QValueVector<classRoom *>::iterator it = qFind( m_classRooms.begin(), m_classRooms.end(),
153
 
                                                                        m_classRoomsToRemove[0] );
154
 
                if( it != m_classRooms.end() )
155
 
                {
156
 
                        m_classRooms.erase( it );
157
 
                }
158
 
                delete m_classRoomsToRemove[0];
159
 
                m_classRoomsToRemove.erase( m_classRoomsToRemove.begin() );
160
 
        }
161
 
        savePersonalConfig();
162
 
        saveGlobalClientConfig();
163
 
 
164
 
        //saveSettings();
165
 
}
166
 
 
167
 
 
168
 
 
169
 
 
170
 
void clientManager::saveGlobalClientConfig( void )
171
 
{
172
 
        QDomDocument doc( "italc-config-file" );
173
 
 
174
 
        QDomElement italc_config = doc.createElement( "globalclientconfig" );
175
 
        italc_config.setAttribute( "version", VER_STRING );
176
 
        doc.appendChild( italc_config );
177
 
 
178
 
        QDomElement root = doc.createElement( "body" );
179
 
        italc_config.appendChild( root );
180
 
 
181
 
        QListViewItem * lvi = m_list->firstChild();
182
 
 
183
 
        for( int i = 0; i < m_list->childCount(); ++i )
184
 
        {
185
 
                saveSettingsOfChildren( doc, root, lvi, TRUE );
186
 
                lvi = lvi->nextSibling();
187
 
        }
188
 
 
189
 
#if QT_VERSION >= 0x030100
190
 
        QString xml = "<?xml version=\"1.0\"?>\n" + doc.toString( 2 );
191
 
#else
192
 
        QString xml = "<?xml version=\"1.0\"?>\n" + doc.toString();
193
 
#endif
194
 
        if( italc::ensureConfigPathExists() == FALSE )
195
 
        {
196
 
                qFatal( "Could not read/write or create directory " + QString( ITALC_CONFIG_PATH ) + "! For running iTALC, make sure you have "
197
 
                        "write-access to your home-directory and to " + QString( ITALC_CONFIG_PATH ) + " (if already existing)." );
198
 
        }
199
 
 
200
 
        QFile outfile( m_globalClientConfiguration );
201
 
        outfile.open( IO_WriteOnly | IO_Truncate );
202
 
 
203
 
        outfile.writeBlock( xml.ascii(), xml.length() );
204
 
        outfile.close();
205
 
}
206
 
 
207
 
 
208
 
 
209
 
 
210
 
void clientManager::savePersonalConfig( void )
211
 
{
212
 
        QDomDocument doc( "italc-config-file" );
213
 
 
214
 
        QDomElement italc_config = doc.createElement( "personalconfig" );
215
 
        italc_config.setAttribute( "version", VER_STRING );
216
 
        doc.appendChild( italc_config );
217
 
 
218
 
        QDomElement head = doc.createElement( "head" );
219
 
        italc_config.appendChild( head );
220
 
 
221
 
        QDomElement globalsettings = doc.createElement( "globalsettings" );
222
 
        globalsettings.setAttribute( "client-update-interval", m_clientUpdateInterval );
223
 
        globalsettings.setAttribute( "use-big-icons", italc::inst()->usesBigPixmaps() );
224
 
        globalsettings.setAttribute( "win-width", italc::inst()->width() );
225
 
        globalsettings.setAttribute( "win-height", italc::inst()->height() );
226
 
        globalsettings.setAttribute( "opened-tab", italc::inst()->m_sideBar->openedTab() );
227
 
 
228
 
        QTextStream ts( m_winCfg, IO_WriteOnly );
229
 
        ts << *( italc::inst() );
230
 
        globalsettings.setAttribute( "wincfg", m_winCfg );
231
 
 
232
 
        QMap<QString, QString> ip_addr_map = systemEnvironment::localIPAddresses();
233
 
        int idx = ip_addr_map.values().findIndex( MASTER_HOST );
234
 
        if( idx != -1 )
235
 
        {
236
 
                globalsettings.setAttribute( "net-iface", ip_addr_map.keys()[idx] );
237
 
        }
238
 
 
239
 
        head.appendChild( globalsettings );
240
 
 
241
 
 
242
 
        QDomElement root = doc.createElement( "body" );
243
 
        italc_config.appendChild( root );
244
 
 
245
 
        QListViewItem * lvi = m_list->firstChild();
246
 
 
247
 
        for( int i = 0; i < m_list->childCount(); ++i )
248
 
        {
249
 
                saveSettingsOfChildren( doc, root, lvi, FALSE );
250
 
                lvi = lvi->nextSibling();
251
 
        }
252
 
 
253
 
 
254
 
#if QT_VERSION >= 0x030100
255
 
        QString xml = "<?xml version=\"1.0\"?>\n" + doc.toString( 2 );
256
 
#else
257
 
        QString xml = "<?xml version=\"1.0\"?>\n" + doc.toString();
258
 
#endif
259
 
        if( italc::ensureConfigPathExists() == FALSE )
260
 
        {
261
 
                qFatal( "Could not read/write or create directory " + QString( ITALC_CONFIG_PATH ) + "! For running iTALC, make sure you have "
262
 
                        "write-access to your home-directory and to " + QString( ITALC_CONFIG_PATH ) + " (if already existing)." );
263
 
        }
264
 
 
265
 
        QFile outfile( m_personalConfiguration );
266
 
        outfile.open( IO_WriteOnly | IO_Truncate );
267
 
 
268
 
        outfile.writeBlock( xml.ascii(), xml.length() );
269
 
        outfile.close();
270
 
}
271
 
 
272
 
 
273
 
 
274
 
 
275
 
void clientManager::saveSettingsOfChildren( QDomDocument & _doc, QDomElement & _root, QListViewItem * _parent, bool _is_global_config )
276
 
{
277
 
        QDomElement classroom = _doc.createElement( "classroom" );
278
 
        classroom.setAttribute( "name", _parent->text( 0 ) );
279
 
        _root.appendChild( classroom );
280
 
 
281
 
        QListViewItem * lvi = _parent->firstChild();
282
 
 
283
 
        for( int i = 0; i < _parent->childCount(); ++i )
284
 
        {
285
 
                if( lvi->childCount() || dynamic_cast<classRoom *>( lvi ) != NULL )
286
 
                {
287
 
                        saveSettingsOfChildren( _doc, classroom, lvi, _is_global_config );
288
 
                }
289
 
                else
290
 
                {
291
 
                        if( dynamic_cast<classRoomItem *>( lvi ) != NULL )
292
 
                        {
293
 
                                client * c = dynamic_cast<classRoomItem *>( lvi )->getClient();
294
 
                                QDomElement client_element = _doc.createElement( "client" );
295
 
                                client_element.setAttribute( "id", c->id() );
296
 
                                if( _is_global_config == TRUE )
297
 
                                {
298
 
                                        client_element.setAttribute( "name", c->name() );
299
 
                                        client_element.setAttribute( "ip", c->ip() );
300
 
                                        client_element.setAttribute( "mac", c->mac() );
301
 
                                }
302
 
                                else
303
 
                                {
304
 
                                        client_element.setAttribute( "visible", ( c->isShown() == TRUE ) ? "yes" : "no" );
305
 
/*                                      if( m_rotating )
306
 
                                        {
307
 
                                                client_element.setAttribute( "x", QString::number( static_cast<int>( c->m_rasterX ) ) );
308
 
                                                client_element.setAttribute( "y", QString::number( static_cast<int>( c->m_rasterY ) ) );
309
 
                                        }
310
 
                                        else
311
 
                                        {*/
312
 
                                                client_element.setAttribute( "x", QString::number( c->parentWidget()->pos().x() ) );
313
 
                                                client_element.setAttribute( "y", QString::number( c->parentWidget()->pos().y() ) );
314
 
                                                client_element.setAttribute( "w", QString::number( c->width() ) );
315
 
                                                client_element.setAttribute( "h", QString::number( c->height() ) );
316
 
                                        //}
317
 
                                }
318
 
                                classroom.appendChild( client_element );
319
 
                        }
320
 
                }
321
 
                lvi = lvi->nextSibling();
322
 
        }
323
 
}
324
 
 
325
 
 
326
 
 
327
 
 
328
 
// routine that returns m_list of all visible clients
329
 
QValueVector<client *> clientManager::visibleClients( void ) const
330
 
{
331
 
        QValueVector<client *> vv;
332
 
        QListViewItem * lvi = m_list->firstChild();
333
 
 
334
 
        for( int i = 0; i < m_list->childCount(); ++i )
335
 
        {
336
 
                getVisibleClients( lvi, vv );
337
 
                lvi = lvi->nextSibling();
338
 
        }
339
 
 
340
 
        return( vv );
341
 
}
342
 
 
343
 
 
344
 
 
345
 
 
346
 
void clientManager::getVisibleClients( QListViewItem * _p, QValueVector<client *> & _vv )
347
 
{
348
 
        QListViewItem * lvi = _p->firstChild();
349
 
 
350
 
        classRoomItem * l = NULL;
351
 
 
352
 
        for( int i = 0; i < _p->childCount(); ++i )
353
 
        {
354
 
                if( lvi->childCount() )
355
 
                {
356
 
                        getVisibleClients( lvi, _vv );
357
 
                }
358
 
                else if( ( l = dynamic_cast<classRoomItem *>( lvi ) ) != NULL && l->getClient()->isShown() )
359
 
                {
360
 
                        _vv.push_back( l->getClient() );
361
 
                }
362
 
                lvi = lvi->nextSibling();
363
 
        }
364
 
}
365
 
 
366
 
 
367
 
 
368
 
 
369
 
void clientManager::getHeaderInformation( const QDomElement & _header )
370
 
{
371
 
        QDomNode node = _header.firstChild();
372
 
 
373
 
        while( !node.isNull() )
374
 
        {
375
 
                if( node.isElement() && node.nodeName() == "globalsettings" )
376
 
                {
377
 
                        m_clientUpdateInterval = node.toElement().attribute( "client-update-interval" ).toInt();
378
 
                        if( node.toElement().attribute( "use-big-icons" ) != QString::null )
379
 
                        {
380
 
                                italc::inst()->setUsesBigPixmaps( node.toElement().attribute( "use-big-icons" ).toInt() );
381
 
                        }
382
 
                        if( node.toElement().attribute( "win-width" ) != QString::null &&
383
 
                                node.toElement().attribute( "win-height" ) != QString::null )
384
 
                        {
385
 
                                italc::inst()->resize( node.toElement().attribute( "win-width" ).toInt(),
386
 
                                                        node.toElement().attribute( "win-height" ).toInt() );
387
 
                        }
388
 
                        if( node.toElement().attribute( "opened-tab" ) != QString::null )
389
 
                        {
390
 
                                italc::inst()->m_openedTabInSideBar = node.toElement().attribute( "opened-tab" ).toInt();
391
 
                        }
392
 
                        if( node.toElement().attribute( "wincfg" ) != QString::null )
393
 
                        {
394
 
                                m_winCfg = node.toElement().attribute( "wincfg" );
395
 
                        }
396
 
 
397
 
                        // get list with all network-interfaces with according IP-addresses
398
 
                        QMap<QString, QString> ip_addr_map = systemEnvironment::localIPAddresses();
399
 
#ifdef DEBUG
400
 
                        for( int i = 0; i < ip_addr_map.count(); ++i )
401
 
                        {
402
 
                                printf( "%s: %s\n", ip_addr_map.keys()[i].ascii(), ip_addr_map.values()[i].ascii() );
403
 
                        }
404
 
#endif
405
 
                        // iface already set in configuration?
406
 
                        if( node.toElement().attribute( "net-iface" ) != QString::null && ip_addr_map.count() &&
407
 
                                ip_addr_map.find( node.toElement().attribute( "net-iface" ) ) != ip_addr_map.end() )
408
 
                        {
409
 
                                MASTER_HOST = ip_addr_map[node.toElement().attribute( "net-iface" )];
410
 
                        }
411
 
                        else if( ip_addr_map.count() )
412
 
                        {
413
 
                                if( ip_addr_map.find( "eth0" ) != ip_addr_map.end() )
414
 
                                {
415
 
                                        MASTER_HOST = ip_addr_map["eth0"];
416
 
                                }
417
 
                                else
418
 
                                {
419
 
                                        MASTER_HOST = ip_addr_map.values()[0];
420
 
                                }
421
 
                        }
422
 
                        else
423
 
                        {
424
 
                                // the guy running iTALC seems to have no network-ifaces configured, not even loopback!!!
425
 
                                qFatal( "You have no network-interfaces configured!!! iTALC can't run without at least a "
426
 
                                        "local loopback-interface.\n" );
427
 
                        }
428
 
 
429
 
                        // if the attr did not exist, we got zero as value, which is not acceptable
430
 
                        if( m_clientUpdateInterval < 1 )
431
 
                        {
432
 
                                m_clientUpdateInterval = 1;
433
 
                        }
434
 
                }
435
 
                node = node.nextSibling();
436
 
        }
437
 
}
438
 
 
439
 
 
440
 
 
441
 
 
442
 
void clientManager::loadTree( classRoom * _parent_item, const QDomElement & _parent_element, bool _is_global_config )
443
 
{
444
 
        for( QDomNode node = _parent_element.firstChild(); node.isNull() == FALSE; node = node.nextSibling() )
445
 
        {
446
 
                if( node.isElement() == FALSE )
447
 
                {
448
 
                        continue;
449
 
                }
450
 
 
451
 
                if( node.nodeName() == "classroom"
452
 
#warning TODO: remove this compat-code
453
 
                         || node.nodeName() == "clientgroup"
454
 
                                                        )
455
 
                {
456
 
                        classRoom * cur_item = NULL;
457
 
                        if( _is_global_config == TRUE )
458
 
                        {
459
 
                                // add new classroom
460
 
                                QString name = node.toElement().attribute( "name" );
461
 
                                if( _parent_item == NULL )
462
 
                                {
463
 
                                        cur_item = new classRoom( m_list, name );
464
 
                                }
465
 
                                else
466
 
                                {
467
 
                                        cur_item = new classRoom( _parent_item, name );
468
 
                                }
469
 
 
470
 
                                if( node.toElement().attribute( "opened" ) == "yes" )
471
 
                                {
472
 
                                        cur_item->setOpen( TRUE );
473
 
                                }
474
 
 
475
 
                                m_classRooms.push_back( cur_item );
476
 
                        }
477
 
 
478
 
                        // recursive build of the tree
479
 
                        loadTree( cur_item, node.toElement(), _is_global_config );
480
 
                }
481
 
                else if( node.nodeName() == "client" )
482
 
                {
483
 
                        if( _is_global_config == TRUE )
484
 
                        {
485
 
                                // add new client
486
 
                                QString ip = node.toElement().attribute( "ip" );
487
 
                                QString mac = node.toElement().attribute( "mac" );
488
 
                                QString name = node.toElement().attribute( "name" );
489
 
 
490
 
                                /*client * c = */
491
 
                                (void) new client( ip, mac, name, _parent_item, node.toElement().attribute( "id" ).toInt() );
492
 
                        }
493
 
                        else
494
 
                        {
495
 
                                client * c = client::clientFromID( node.toElement().attribute( "id" ).toInt() );
496
 
                                if( c == NULL )
497
 
                                {
498
 
                                        continue;
499
 
                                }
500
 
                                QPoint pos = c->mapFrom( c->parentWidget()->parentWidget(),
501
 
                                                        QPoint( node.toElement().attribute("x").toInt(),
502
 
                                                                node.toElement().attribute("y").toInt() ) );
503
 
                                // workaround for Qt-Bug
504
 
                                if( pos.x() == 0 )
505
 
                                {
506
 
                                        pos.setX( 1 );
507
 
                                }
508
 
                                c->move( pos );
509
 
                                //c->parentWidget()->move (node.toElement().attribute("x").toInt(), node.toElement().attribute("y").toInt());
510
 
                                c->m_rasterX = node.toElement().attribute( "x" ).toInt();
511
 
                                c->m_rasterY = node.toElement().attribute( "y" ).toInt();
512
 
                                c->setFixedSize( node.toElement().attribute( "w" ).toInt(),
513
 
                                                        node.toElement().attribute( "h" ).toInt() );
514
 
                                //c->setFixedSize( m_stdWidth, m_stdWidth*3/4 );
515
 
 
516
 
                                if( node.toElement().attribute( "visible" ) == "yes" )
517
 
                                {
518
 
                                        c->show();
519
 
                                }
520
 
                                else
521
 
                                {
522
 
                                        c->hide();
523
 
                                }
524
 
                        }
525
 
                }
526
 
        }
527
 
}
528
 
 
529
 
 
530
 
 
531
 
 
532
 
void clientManager::loadGlobalClientConfig( void )
533
 
{
534
 
        m_list->clear();
535
 
 
536
 
        // read the XML file and create DOM tree
537
 
        QFile cfg_file( m_globalClientConfiguration );
538
 
        if( !cfg_file.open( IO_ReadOnly ) )
539
 
        {
540
 
#if QT_VERSION >= 0x030200
541
 
                if( splashScreen != NULL )
542
 
                {
543
 
                        splashScreen->close();
544
 
                }
545
 
#endif
546
 
                QMessageBox::warning( this, tr( "No configuration-file found" ), tr( "Could not open configuration file %1.\n"
547
 
                                                                                        "You will have to add at least one "
548
 
                                                                                        "classroom and clients by using the "
549
 
                                                                                        "context-menu in the client-manager."
550
 
                                                                                        ).arg( m_globalClientConfiguration ) );
551
 
                return;
552
 
        }
553
 
 
554
 
        if( !m_domTree.setContent( &cfg_file ) )
555
 
        {
556
 
#if QT_VERSION >= 0x030200
557
 
                if( splashScreen != NULL )
558
 
                {
559
 
                        splashScreen->close();
560
 
                }
561
 
#endif
562
 
                QMessageBox::critical( 0, tr( "Error in configuration-file" ), tr( "Error while parsing configuration-file %1.\n"
563
 
                                                                                        "Please edit it. Otherwise you should "
564
 
                                                                                        "delete this file and have to add all "
565
 
                                                                                        "classrooms and clients again."
566
 
                                                                                        ).arg( m_globalClientConfiguration ) );
567
 
                cfg_file.close();
568
 
                return;
569
 
        }
570
 
        cfg_file.close();
571
 
 
572
 
 
573
 
        // get the head information from the DOM
574
 
        QDomElement root = m_domTree.documentElement();
575
 
        QDomNode node = root.firstChild();
576
 
 
577
 
        // create the tree view out of the DOM
578
 
        node = root.firstChild();
579
 
        while( !node.isNull() )
580
 
        {
581
 
                if( node.isElement() && node.nodeName() == "body" )
582
 
                {
583
 
                        loadTree( NULL, node.toElement(), TRUE );
584
 
                        break;
585
 
                }
586
 
                node = node.nextSibling();
587
 
        }
588
 
}
589
 
 
590
 
 
591
 
 
592
 
 
593
 
void clientManager::loadPersonalConfig( void )
594
 
{
595
 
        // read the XML file and create DOM tree
596
 
        QFile cfg_file( m_personalConfiguration );
597
 
        if( !cfg_file.open( IO_ReadOnly ) )
598
 
        {
599
 
                return;
600
 
        }
601
 
 
602
 
        if( !m_domTree.setContent( &cfg_file ) )
603
 
        {
604
 
#if QT_VERSION >= 0x030200
605
 
                if( splashScreen != NULL )
606
 
                {
607
 
                        splashScreen->close();
608
 
                }
609
 
#endif
610
 
                QMessageBox::critical( 0, tr( "Error in configuration-file" ), tr( "Error while parsing configuration-file %1.\n"
611
 
                                                                                        "Please edit it. Otherwise you should "
612
 
                                                                                        "delete this file."
613
 
                                                                                        ).arg( m_personalConfiguration ) );
614
 
                cfg_file.close();
615
 
                return;
616
 
        }
617
 
        cfg_file.close();
618
 
 
619
 
 
620
 
        // get the head information from the DOM
621
 
        QDomElement root = m_domTree.documentElement();
622
 
        QDomNode node = root.firstChild();
623
 
 
624
 
        while( !node.isNull() )
625
 
        {
626
 
                if( node.isElement() && node.nodeName() == "head" )
627
 
                {
628
 
                        getHeaderInformation( node.toElement() );
629
 
                        break;
630
 
                }
631
 
                node = node.nextSibling();
632
 
        }
633
 
 
634
 
        // create the tree view out of the DOM
635
 
        node = root.firstChild();
636
 
        while( !node.isNull() )
637
 
        {
638
 
                if( node.isElement() && node.nodeName() == "body" )
639
 
                {
640
 
                        loadTree( NULL, node.toElement(), FALSE );
641
 
                        break;
642
 
                }
643
 
                node = node.nextSibling();
644
 
        }
645
 
}
646
 
 
647
 
 
648
 
 
649
 
void clientManager::createActionMenu( QPopupMenu * _m )
650
 
{
651
 
        QListViewItem * lvi = m_list->firstChild();
652
 
 
653
 
        for( int i = 0; i < m_list->childCount(); ++i )
654
 
        {
655
 
                if( lvi->childCount() )
656
 
                {
657
 
                        createActionMenu( lvi, _m );
658
 
                }
659
 
                lvi = lvi->nextSibling();
660
 
        }
661
 
}
662
 
 
663
 
 
664
 
 
665
 
 
666
 
void clientManager::createActionMenu( QListViewItem * _p, QPopupMenu * _m )
667
 
{
668
 
        QPopupMenu * root = new QPopupMenu( _m );
669
 
        _m->insertItem( _p->text( 0 ), root );
670
 
 
671
 
        QListViewItem * lvi = _p->firstChild();
672
 
        classRoomItem * l = NULL;
673
 
 
674
 
        for( int i = 0; i < _p->childCount(); ++i )
675
 
        {
676
 
                if( lvi->childCount() )
677
 
                {
678
 
                        createActionMenu( lvi, root );
679
 
                }
680
 
                else if( ( l = dynamic_cast<classRoomItem *>( lvi ) ) != NULL )
681
 
                {
682
 
                        QPopupMenu * client_submenu = new QPopupMenu( root );
683
 
                        l->getClient()->createActionMenu( client_submenu );
684
 
                        root->insertItem( l->getClient()->fullName(), client_submenu );
685
 
                }
686
 
                lvi = lvi->nextSibling();
687
 
        }
688
 
}
689
 
 
690
 
 
691
 
 
692
 
 
693
 
void clientManager::createActionMenuForClassRooms( QPopupMenu * _m )
694
 
{
695
 
        for( unsigned int i = 0; i < m_classRooms.size(); ++i )
696
 
        {
697
 
                m_classRooms[i]->createActionMenu( _m );
698
 
        }
699
 
}
700
 
 
701
 
 
702
 
 
703
 
 
704
 
bool clientManager::demoRunning( void ) const
705
 
{
706
 
        QValueVector<client *> vc = visibleClients();
707
 
 
708
 
        for( unsigned int i = 0; i < vc.size(); ++i )
709
 
        {
710
 
                if( vc[i]->demoRunning() )
711
 
                        return( TRUE );
712
 
        }
713
 
        return( FALSE );
714
 
}
715
 
 
716
 
 
717
 
 
718
 
 
719
 
void clientManager::updateClients( void )
720
 
{
721
 
        QValueVector<client *> clients = visibleClients();
722
 
 
723
 
        //unsigned int cur_client = static_cast<unsigned int>( clients.size() * ( rand() * ( 1.0f/RAND_MAX ) ) );
724
 
 
725
 
        // loop through all clients
726
 
        for( unsigned int cl = 0; cl < clients.size(); ++cl )
727
 
        {
728
 
/*              if( m_rotating && cl == cur_client )
729
 
                {
730
 
                        // set focus -> client zoomes automatically if zoom-res. != standard-res.
731
 
                        clients[cl]->setFocus();
732
 
                }
733
 
                else
734
 
                {*/
735
 
                        // update current client
736
 
                        clients[cl]->update();
737
 
                //}
738
 
        }
739
 
 
740
 
        //QTimer::singleShot (50, this, SLOT(updateClients()));
741
 
        QTimer::singleShot( m_clientUpdateInterval*1000, this, SLOT( updateClients() ) );
742
 
}
743
 
 
744
 
 
745
 
 
746
 
 
747
 
 
748
 
 
749
 
 
750
 
inline void clientManager::cmdToActiveClients( client::clientCmds _cmd, const QString & _u_data )
751
 
{
752
 
        QValueVector<client *> clients = visibleClients();
753
 
        for( unsigned int cl = 0; cl < clients.size(); ++cl )
754
 
        {
755
 
                clients[cl]->processCmd( _cmd, _u_data );
756
 
                // there're sometimes problems, when action on all clients are started simulanous (especially demo, because all clients
757
 
                // connect to the same IVS on master), so add a little delay between each client...
758
 
                QTime t;
759
 
                t.start();
760
 
                while( t.elapsed() < 300 )
761
 
                {
762
 
                }
763
 
        }
764
 
}
765
 
 
766
 
 
767
 
 
768
 
 
769
 
 
770
 
void clientManager::startDemo( void )
771
 
{
772
 
        progressInformation pi( tr( "Please wait, while the demo is started." ) );
773
 
        cmdToActiveClients( client::START_DEMO );
774
 
}
775
 
 
776
 
 
777
 
 
778
 
 
779
 
void clientManager::startFullScreenDemo( void )
780
 
{
781
 
        progressInformation pi( tr( "Please wait, while the demo is started." ) );
782
 
        cmdToActiveClients( client::START_FULLSCREEN_DEMO );
783
 
}
784
 
 
785
 
 
786
 
 
787
 
 
788
 
void clientManager::stopDemo(void )
789
 
{
790
 
        progressInformation pi( tr( "Please wait, while the demo is stopped." ) );
791
 
        cmdToActiveClients( client::STOP_DEMO );
792
 
}
793
 
 
794
 
 
795
 
 
796
 
 
797
 
void clientManager::powerOnClients( void )
798
 
{
799
 
        progressInformation pi( tr( "Please wait, while the clients are being turned on." ) );
800
 
        cmdToActiveClients( client::POWER_ON );
801
 
}
802
 
 
803
 
 
804
 
 
805
 
 
806
 
void clientManager::rebootClients( void )
807
 
{
808
 
        if( QMessageBox::question( this, tr( "Reboot clients" ), tr( "Are you sure want to reboot all visible clients?" ),
809
 
                                         QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
810
 
        {
811
 
                progressInformation pi( tr( "Please wait, while the clients are being rebooted." ) );
812
 
                cmdToActiveClients( client::REBOOT );
813
 
        }
814
 
}
815
 
 
816
 
 
817
 
 
818
 
 
819
 
void clientManager::powerOffClients( void )
820
 
{
821
 
        if( QMessageBox::question( this, tr( "Power off clients" ), tr( "Are you sure want to power off all visible clients?" ),
822
 
                                        QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
823
 
        {
824
 
                progressInformation pi( tr( "Please wait, while the clients are being powered off." ) );
825
 
                cmdToActiveClients( client::POWER_OFF );
826
 
        }
827
 
}
828
 
 
829
 
 
830
 
 
831
 
 
832
 
void clientManager::lockScreens( void )
833
 
{
834
 
//      if (QMessageBox::question(this, tr("Lock screen on clients"), tr("Are you sure want to lock the screen on all visible clients?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
835
 
//              return;
836
 
        progressInformation pi( tr( "Please wait, while the screens are locked." ) );
837
 
        cmdToActiveClients( client::LOCK_X );
838
 
}
839
 
 
840
 
 
841
 
 
842
 
 
843
 
void clientManager::unlockScreens( void )
844
 
{
845
 
//      if (QMessageBox::question(this, tr("Unlock screen on all clients"), tr("Are you sure want to unlock the screen on all visible clients?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
846
 
//              return;
847
 
        progressInformation pi( tr( "Please wait, while the screens are unlocked." ) );
848
 
        cmdToActiveClients( client::UNLOCK_X );
849
 
}
850
 
 
851
 
 
852
 
 
853
 
 
854
 
void clientManager::killGames( void )
855
 
{
856
 
        progressInformation pi( tr( "Please wait, while games are killed." ) );
857
 
        cmdToActiveClients( client::KILL_GAMES );
858
 
}
859
 
 
860
 
 
861
 
 
862
 
 
863
 
void clientManager::killBrowsers( void )
864
 
{
865
 
        if( QMessageBox::question( this, tr( "Kill Mozilla/FireFox on clients" ), tr( "Are you sure want to kill Mozilla/FireFox on all "
866
 
                                                "visible clients?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
867
 
        {
868
 
                progressInformation pi( tr( "Please wait, while browsers are killed." ) );
869
 
                cmdToActiveClients( client::KILL_BROWSERS );
870
 
        }
871
 
}
872
 
 
873
 
 
874
 
 
875
 
 
876
 
void clientManager::execCmds( void )
877
 
{
878
 
        QString cmds;
879
 
 
880
 
        cmdInputDialog cmd_input_dialog( cmds, this );
881
 
        if( cmd_input_dialog.exec() == QDialog::Accepted && cmds != "" )
882
 
        {
883
 
                cmdToActiveClients( client::EXEC_CMDS, cmds );
884
 
        }
885
 
}
886
 
 
887
 
 
888
 
 
889
 
void clientManager::sendMessage( void )
890
 
{
891
 
        QString msg;
892
 
 
893
 
        msgInputDialog msg_input_dialog( msg, this );
894
 
        if( msg_input_dialog.exec() == QDialog::Accepted && msg != "" )
895
 
        {
896
 
                progressInformation pi( tr( "Please wait, while the message is being sent." ) );
897
 
                cmdToActiveClients( client::SEND_MESSAGE, msg );
898
 
        }
899
 
}
900
 
 
901
 
 
902
 
 
903
 
void clientManager::distributeFile( void )
904
 
{
905
 
/*      QMessageBox::information (this, tr("Function not implemented yet."), tr("This function is not completely implemented yet. This is why it is disabled at the moment."), QMessageBox::Ok);
906
 
        return;*/
907
 
 
908
 
        QFileDialog ofd( QDir::home().path(), QString::null, this, "", TRUE );
909
 
        ofd.setMode( QFileDialog::ExistingFile );
910
 
        ofd.setCaption( client::tr( "Select file to distribute" ) );
911
 
        if( ofd.exec() == QDialog::Accepted )
912
 
        {
913
 
                cmdToActiveClients( client::DISTRIBUTE_FILE, ofd.selectedFile() );
914
 
        }
915
 
}
916
 
 
917
 
 
918
 
 
919
 
 
920
 
void clientManager::collectFiles( void )
921
 
{
922
 
/*      QMessageBox::information (this, tr("Function not implemented yet."), tr("This function is not completely implemented yet. This is why it is disabled at the moment."), QMessageBox::Ok);
923
 
        return;*/
924
 
 
925
 
        QString fn;
926
 
        textInputDialog file_name_input( client::tr( "Please enter the name(s) of the file(s) to be collected (wildcards are "
927
 
                                                        "allowed).\nThe base-directory is HOME/PUBLIC." ), fn, this );
928
 
        file_name_input.setCaption( client::tr( "Collect files" ) );
929
 
 
930
 
        if( file_name_input.exec() == QDialog::Accepted && fn != "" )
931
 
        {
932
 
                cmdToActiveClients( client::COLLECT_FILES, fn );
933
 
        }
934
 
}
935
 
 
936
 
 
937
 
 
938
 
#ifdef COMPILE_LINUX
939
 
 
940
 
void clientManager::restartX( void )
941
 
{
942
 
        if( QMessageBox::question( this, tr( "Restart X on clients" ), tr( "Are you sure want to restart X on all visible clients?" ),
943
 
                                        QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
944
 
        {
945
 
                cmdToActiveClients( client::RESTART_X );
946
 
        }
947
 
}
948
 
 
949
 
#endif
950
 
 
951
 
 
952
 
const int decor_w = 4;
953
 
const int decor_h = 22;
954
 
 
955
 
 
956
 
void clientManager::optimizeClientSize( void )
957
 
{
958
 
        QValueVector<client *> vc = visibleClients();
959
 
        if( vc.size() )
960
 
        {
961
 
                const int avail_w = italc::inst()->workspace()->width();
962
 
                const int avail_h = italc::inst()->workspace()->height();
963
 
                float cw = vc[0]->width()+decor_w;      // add width of decoration
964
 
                float ch = vc[0]->height()+decor_h;     // add height of titlebar
965
 
 
966
 
                // later we divide by cw, so assume standard-value if zero
967
 
                if( static_cast<int>( cw ) == 0 )
968
 
                {
969
 
                        cw = 256.0f;
970
 
                }
971
 
                // later we divide by ch, so assume standard-value if zero
972
 
                if( static_cast<int>( ch ) == 0 )
973
 
                {
974
 
                        ch = 192.0f;
975
 
                }
976
 
                int x_offset = vc[0]->parentWidget()->pos().x();
977
 
                int y_offset = vc[0]->parentWidget()->pos().y();
978
 
 
979
 
                for( unsigned int i = 0; i < vc.size(); ++i )
980
 
                {
981
 
                        if( vc[i]->parentWidget()->pos().x() < x_offset )
982
 
                        {
983
 
                                x_offset = vc[i]->parentWidget()->pos().x();
984
 
                        }
985
 
                        if( vc[i]->parentWidget()->pos().y() < y_offset )
986
 
                        {
987
 
                                y_offset = vc[i]->parentWidget()->pos().y();
988
 
                        }
989
 
                }
990
 
 
991
 
                float max_rx = 0.0;
992
 
                float max_ry = 0.0;
993
 
                for( unsigned int i = 0; i < vc.size(); ++i )
994
 
                {
995
 
                        vc[i]->m_rasterX = roundCorrect( ( vc[i]->parentWidget()->pos().x()-x_offset ) / cw );
996
 
                        vc[i]->m_rasterY = roundCorrect( ( vc[i]->parentWidget()->pos().y()-y_offset ) / ch );
997
 
                        if( vc[i]->m_rasterX > max_rx )
998
 
                        {
999
 
                                max_rx = vc[i]->m_rasterX;
1000
 
                        }
1001
 
                        if( vc[i]->m_rasterY > max_ry )
1002
 
                        {
1003
 
                                max_ry = vc[i]->m_rasterY;
1004
 
                        }
1005
 
                }
1006
 
                ++max_rx;
1007
 
                ++max_ry;
1008
 
                // now we have length of col and length of row and can calculate a width and a height (independent from each other)
1009
 
                // divide available width by max length of rows
1010
 
                int nw = static_cast<int>( floor( avail_w / max_rx ) );
1011
 
                // calculate according height
1012
 
                int nh = (nw-decor_w)*3/4+decor_h;
1013
 
                // is this height fit max_ry times into available height?
1014
 
                if( nh*max_ry >= avail_h )
1015
 
                {
1016
 
                        // no, then divide available height by max length of cols
1017
 
                        nh = static_cast<int>( floor( avail_h / max_ry ) );
1018
 
                        // and calculate according width
1019
 
                        nw = (nh-decor_h)*4/3+decor_w;
1020
 
                }
1021
 
                for( unsigned int i = 0; i < vc.size(); ++i )
1022
 
                {
1023
 
                        vc[i]->setFixedSize( nw-decor_w, nh-decor_h );
1024
 
                        vc[i]->parentWidget()->move( static_cast<int>( vc[i]->m_rasterX*nw ), static_cast<int>( vc[i]->m_rasterY*nh ) );
1025
 
                }
1026
 
        }
1027
 
}
1028
 
 
1029
 
 
1030
 
 
1031
 
 
1032
 
void clientManager::resizeClients( const int _new_width )
1033
 
{
1034
 
        QValueVector<client *> vc = visibleClients();
1035
 
 
1036
 
        if( vc.size() )
1037
 
        {
1038
 
                const int _new_height = _new_width*3/4;
1039
 
                float cw = vc[0]->width()+decor_w;      // add width of decoration
1040
 
                float ch = vc[0]->height()+decor_h;     // add height of titlebar
1041
 
                // later we divide by cw, so assume standard-value if zero
1042
 
                if( static_cast<int>( cw ) == 0 )
1043
 
                        cw = 256.0f;
1044
 
                // later we divide by ch, so assume standard-value if zero
1045
 
                if( static_cast<int>( ch  )== 0 )
1046
 
                        ch = 192.0f;
1047
 
 
1048
 
                int x_offset = vc[0]->parentWidget()->pos().x();
1049
 
                int y_offset = vc[0]->parentWidget()->pos().y();
1050
 
 
1051
 
                for( unsigned int i = 0; i < vc.size(); ++i )
1052
 
                {
1053
 
                        if( vc[i]->parentWidget()->pos().x() < x_offset )
1054
 
                        {
1055
 
                                x_offset = vc[i]->parentWidget()->pos().x();
1056
 
                        }
1057
 
                        if( vc[i]->parentWidget()->pos().y() < y_offset )
1058
 
                        {
1059
 
                                y_offset = vc[i]->parentWidget()->pos().y();
1060
 
                        }
1061
 
                }
1062
 
 
1063
 
                for( unsigned int i = 0; i < vc.size(); ++i )
1064
 
                {
1065
 
                        vc[i]->setFixedSize( _new_width, _new_height );
1066
 
                        const int xp = static_cast<int>( ( vc[i]->parentWidget()->pos().x() - x_offset ) / cw *
1067
 
                                                        ( _new_width + decor_w ) ) + x_offset;
1068
 
                        const int yp = static_cast<int>( ( vc[i]->parentWidget()->pos().y() - y_offset ) / ch *
1069
 
                                                        ( _new_height + decor_h ) ) + y_offset;
1070
 
                        vc[i]->parentWidget()->move( xp, yp );
1071
 
                }
1072
 
        }
1073
 
}
1074
 
 
1075
 
 
1076
 
 
1077
 
 
1078
 
void clientManager::increaseClientSize( void )
1079
 
{
1080
 
        QValueVector<client *> vc = visibleClients();
1081
 
 
1082
 
        if( vc.size() )
1083
 
        {
1084
 
                const int cw = vc[0]->width();
1085
 
                int i = 0;
1086
 
                // seek to first width which is greater than current client-width
1087
 
                while( widths[i] > 0 && cw >= widths[i] )
1088
 
                {
1089
 
                        ++i;
1090
 
                }
1091
 
                if( widths[i] > 0 )
1092
 
                {
1093
 
                        resizeClients( widths[i] );
1094
 
                }
1095
 
        }
1096
 
}
1097
 
 
1098
 
 
1099
 
 
1100
 
 
1101
 
void clientManager::decreaseClientSize( void )
1102
 
{
1103
 
        QValueVector<client *> vc = visibleClients();
1104
 
 
1105
 
        if( vc.size() )
1106
 
        {
1107
 
                const int cw = vc[0]->width();
1108
 
                int i = 0;
1109
 
                // seek to last width
1110
 
                while( widths[i] > 0 )
1111
 
                {
1112
 
                        ++i;
1113
 
                }
1114
 
                --i;
1115
 
                // seek to first width which is smaller than current client-width
1116
 
                while( i > 0 && cw <= widths[i] )
1117
 
                {
1118
 
                        --i;
1119
 
                }
1120
 
                if( i >= 0 && widths[i] > 0 )
1121
 
                {
1122
 
                        resizeClients( widths[i] );
1123
 
                }
1124
 
        }
1125
 
}
1126
 
 
1127
 
 
1128
 
 
1129
 
 
1130
 
void clientManager::updateIntervalChanged( int _value )
1131
 
{
1132
 
        m_clientUpdateInterval = _value;
1133
 
}
1134
 
 
1135
 
 
1136
 
 
1137
 
 
1138
 
void clientManager::closeEvent( QCloseEvent * _ce )
1139
 
{
1140
 
        _ce->ignore();
1141
 
}
1142
 
 
1143
 
 
1144
 
 
1145
 
 
1146
 
#if QT_VERSION >= 0x030200
1147
 
 
1148
 
void clientManager::itemDoubleClicked( QListViewItem * _i )
1149
 
{
1150
 
}
1151
 
 
1152
 
void clientManager::itemDoubleClicked( QListViewItem * _i, const QPoint &, int )
1153
 
 
1154
 
#else
1155
 
 
1156
 
void clientManager::itemDoubleClicked( QListViewItem * _i, const QPoint &, int )
1157
 
{
1158
 
}
1159
 
void clientManager::itemDoubleClicked( QListViewItem * _i )
1160
 
 
1161
 
#endif
1162
 
{
1163
 
        classRoomItem * cri = dynamic_cast<classRoomItem *>( _i );
1164
 
 
1165
 
        if( cri != NULL )
1166
 
        {
1167
 
                if( cri->getClient()->isShown() )
1168
 
                {
1169
 
                        cri->getClient()->hide();
1170
 
                }
1171
 
                else
1172
 
                {
1173
 
                        cri->getClient()->show();
1174
 
                }
1175
 
        }
1176
 
}
1177
 
 
1178
 
 
1179
 
 
1180
 
 
1181
 
void clientManager::contextMenuRequest( QListViewItem * _i, const QPoint &, int )
1182
 
{
1183
 
        QPopupMenu * context_menu = new QPopupMenu( this );
1184
 
 
1185
 
        classRoomItem * cri = dynamic_cast<classRoomItem *>( _i );
1186
 
        classRoom * cr = dynamic_cast<classRoom *>( _i );
1187
 
 
1188
 
        if( cri != NULL )
1189
 
        {
1190
 
                context_menu->insertItem( embed::getIconPixmap( "client_show" ), tr( "Show/hide" ), this, SLOT( showHideClient() ) );
1191
 
                context_menu->insertItem( embed::getIconPixmap( "client_settings" ), tr( "Edit properties" ), this,
1192
 
                                                                SLOT( editClientProperties() ) );
1193
 
                context_menu->insertItem( embed::getIconPixmap( "client_remove" ), tr( "Remove" ), this, SLOT( removeClient() ) );
1194
 
                context_menu->insertSeparator();
1195
 
 
1196
 
                QPopupMenu * single_clients_submenu = new QPopupMenu( context_menu );
1197
 
 
1198
 
                cri->getClient()->createActionMenu( single_clients_submenu );
1199
 
 
1200
 
                context_menu->insertItem( embed::getIconPixmap( "client" ), tr( "Actions" ), single_clients_submenu );
1201
 
                context_menu->insertSeparator();
1202
 
        }
1203
 
        else if( cr != NULL )
1204
 
        {
1205
 
                context_menu->insertItem( embed::getIconPixmap( "classroom_show" ), tr( "Show all clients in classroom" ), this,
1206
 
                                                SLOT( showSelectedClassRooms() ) );
1207
 
                context_menu->insertItem( embed::getIconPixmap( "classroom_closed" ), tr( "Hide all clients in classroom" ), this,
1208
 
                                                SLOT( hideSelectedClassRooms() ) );
1209
 
                context_menu->insertItem( embed::getIconPixmap( "client_settings" ), tr( "Edit name" ), this, SLOT( editClassRoomName() ) );
1210
 
                context_menu->insertItem( embed::getIconPixmap( "classroom_remove" ), tr("Remove classroom" ), this,
1211
 
                                                SLOT( removeClassRoom() ) );
1212
 
 
1213
 
                context_menu->insertSeparator();
1214
 
 
1215
 
                QPopupMenu * actions_for_classroom_submenu = new QPopupMenu( context_menu );
1216
 
 
1217
 
                cr->createActionMenu( actions_for_classroom_submenu, FALSE );
1218
 
 
1219
 
                context_menu->insertItem( embed::getIconPixmap( "classroom_opened" ), tr( "Actions for %1" ).arg( cr->text( 0 ) ),
1220
 
                                                actions_for_classroom_submenu );
1221
 
                context_menu->insertSeparator();
1222
 
        }
1223
 
        else
1224
 
        { 
1225
 
                QPopupMenu * actions_for_classroom_submenu = new QPopupMenu( context_menu );
1226
 
 
1227
 
                for( unsigned int i = 0; i < m_classRooms.size(); ++i )
1228
 
                {
1229
 
                        m_classRooms[i]->createActionMenu( actions_for_classroom_submenu );
1230
 
                }
1231
 
 
1232
 
                context_menu->insertItem( embed::getIconPixmap( "classroom_closed" ), italc::tr( "Action for whole classroom" ),
1233
 
                                                actions_for_classroom_submenu );
1234
 
                context_menu->insertSeparator();
1235
 
        }
1236
 
 
1237
 
        context_menu->insertItem( embed::getIconPixmap( "client_add" ), tr( "Add client" ), this, SLOT( addClient() ) );
1238
 
        context_menu->insertItem( embed::getIconPixmap( "classroom_add" ), tr( "Add classroom" ), this, SLOT( addClassRoom() ) );
1239
 
 
1240
 
        context_menu->exec( QCursor::pos() );
1241
 
 
1242
 
        delete context_menu;
1243
 
}
1244
 
 
1245
 
 
1246
 
 
1247
 
 
1248
 
QValueVector<classRoomItem *> clientManager::selectedItems( void )
1249
 
{
1250
 
        QValueVector<classRoomItem *> vv;
1251
 
        QListViewItem * lvi = m_list->firstChild();
1252
 
 
1253
 
        for( int i = 0; i < m_list->childCount(); ++i )
1254
 
        {
1255
 
                getSelectedItems( lvi, vv );
1256
 
                lvi = lvi->nextSibling();
1257
 
        }
1258
 
 
1259
 
        return( vv );
1260
 
}
1261
 
 
1262
 
 
1263
 
 
1264
 
 
1265
 
void clientManager::getSelectedItems( QListViewItem * _p, QValueVector<classRoomItem *> & _vv, bool _add_all )
1266
 
{
1267
 
        QListViewItem * lvi = _p->firstChild();
1268
 
 
1269
 
        for( int i = 0; i < _p->childCount(); ++i )
1270
 
        {
1271
 
                if( lvi->childCount() )
1272
 
                {
1273
 
                        getSelectedItems( lvi, _vv, m_list->isSelected( lvi ) );
1274
 
                }
1275
 
                else if( _add_all || ( dynamic_cast<classRoomItem *>( lvi ) != NULL && m_list->isSelected( lvi ) ) )
1276
 
                {
1277
 
                        _vv.push_back( dynamic_cast<classRoomItem *>( lvi ) );
1278
 
                }
1279
 
                lvi = lvi->nextSibling();
1280
 
        }
1281
 
}
1282
 
 
1283
 
 
1284
 
 
1285
 
 
1286
 
// slots for client-actions in context-menu
1287
 
void clientManager::showHideClient( void )
1288
 
{
1289
 
        QValueVector<classRoomItem *> si = selectedItems();
1290
 
 
1291
 
        if( si.size() > 0 )
1292
 
        {
1293
 
                bool all_shown = TRUE;
1294
 
                for( unsigned int i = 0; i < si.size(); ++i )
1295
 
                {
1296
 
                        if( si[i]->getClient()->isShown() == FALSE )
1297
 
                        {
1298
 
                                all_shown = FALSE;
1299
 
                                break;
1300
 
                        }
1301
 
                }
1302
 
                for( unsigned int i = 0; i < si.size(); ++i )
1303
 
                {
1304
 
                        if( all_shown )
1305
 
                        {
1306
 
                                si[i]->getClient()->hide();
1307
 
                        }
1308
 
                        else
1309
 
                        {
1310
 
                                si[i]->getClient()->show();
1311
 
                        }
1312
 
                }
1313
 
        }
1314
 
}
1315
 
 
1316
 
 
1317
 
 
1318
 
 
1319
 
void clientManager::editClientProperties( void )
1320
 
{
1321
 
        QValueVector<classRoomItem *> si = selectedItems();
1322
 
 
1323
 
        if( si.size() > 0 )
1324
 
        {
1325
 
                for( unsigned int i = 0; i < si.size(); ++i )
1326
 
                {
1327
 
                        clientPropertiesEdit edit( si[i]->getClient(), si[i]->parent()->text( 0 ), this );
1328
 
                        edit.exec();
1329
 
                }
1330
 
        }
1331
 
}
1332
 
 
1333
 
 
1334
 
 
1335
 
 
1336
 
void clientManager::removeClient( void )
1337
 
{
1338
 
        QValueVector<classRoomItem *> si = selectedItems();
1339
 
 
1340
 
        if( si.size() > 0 )
1341
 
        {
1342
 
                for( unsigned int i = 0; i < si.size(); ++i )
1343
 
                {
1344
 
                        si[i]->getClient()->hide();
1345
 
                        m_clientsToRemove.push_back( si[i]->getClient() );
1346
 
                        si[i]->setVisible (FALSE);
1347
 
                }
1348
 
        }
1349
 
}
1350
 
 
1351
 
 
1352
 
 
1353
 
 
1354
 
void clientManager::setStateOfClassRoom( classRoom * _cr, bool _shown )
1355
 
{
1356
 
        QListViewItem * cri = _cr->firstChild();
1357
 
 
1358
 
        // If all clients are shown, we hide them all. Otherwise we show all.
1359
 
        for( int i = 0; i < _cr->childCount(); ++i )
1360
 
        {
1361
 
                if( dynamic_cast<classRoomItem *>( cri ) != NULL )
1362
 
                {
1363
 
                        if( _shown )
1364
 
                        {
1365
 
                                dynamic_cast<classRoomItem *>( cri )->getClient()->show();
1366
 
                        }
1367
 
                        else
1368
 
                        {
1369
 
                                dynamic_cast<classRoomItem *>( cri )->getClient()->hide();
1370
 
                        }
1371
 
                }
1372
 
                cri = cri->nextSibling();
1373
 
        }
1374
 
}
1375
 
 
1376
 
 
1377
 
 
1378
 
 
1379
 
int clientManager::addClassRoomToQuickSwitchMenu( classRoom * _cr )
1380
 
{
1381
 
        return( m_quickSwitchMenu->insertItem( _cr->text( 0 ), _cr, SLOT( switchToClassRoom() ) ) );
1382
 
}
1383
 
 
1384
 
 
1385
 
 
1386
 
 
1387
 
void clientManager::removeClassRoomFromQuickSwitchMenu( int _id )
1388
 
{
1389
 
        m_quickSwitchMenu->removeItem( _id );
1390
 
}
1391
 
 
1392
 
 
1393
 
 
1394
 
 
1395
 
void clientManager::showSelectedClassRooms( void )
1396
 
{
1397
 
        for( unsigned int i = 0; i < m_classRooms.size(); ++i )
1398
 
        {
1399
 
                classRoom * cr = NULL;
1400
 
                if( m_list->isSelected( m_classRooms[i] ) )
1401
 
                {
1402
 
                        cr = m_classRooms[i];
1403
 
                }
1404
 
 
1405
 
                if( cr != NULL && cr->childCount() )
1406
 
                {
1407
 
                        setStateOfClassRoom( cr, TRUE );
1408
 
                }
1409
 
        }
1410
 
}
1411
 
 
1412
 
 
1413
 
 
1414
 
 
1415
 
void clientManager::hideSelectedClassRooms( void )
1416
 
{
1417
 
        for( unsigned int i = 0; i < m_classRooms.size(); ++i )
1418
 
        {
1419
 
                if( m_list->isSelected( m_classRooms[i] ) && m_classRooms[i]->childCount() )
1420
 
                {
1421
 
                        setStateOfClassRoom( m_classRooms[i], FALSE );
1422
 
                }
1423
 
        }
1424
 
}
1425
 
 
1426
 
 
1427
 
 
1428
 
 
1429
 
void clientManager::hideAllClassRooms( void )
1430
 
{
1431
 
        for( unsigned int i = 0; i < m_classRooms.size(); ++i )
1432
 
        {
1433
 
                setStateOfClassRoom( m_classRooms[i], FALSE );
1434
 
        }
1435
 
}
1436
 
 
1437
 
 
1438
 
 
1439
 
 
1440
 
void clientManager::editClassRoomName( void )
1441
 
{
1442
 
        for( unsigned int i = 0; i < m_classRooms.size(); ++i )
1443
 
        {
1444
 
                classRoom * cr = NULL;
1445
 
                if( m_list->isSelected( m_classRooms[i] ) )
1446
 
                {
1447
 
                        cr = m_classRooms[i];
1448
 
                }
1449
 
 
1450
 
                if( cr != NULL )
1451
 
                {
1452
 
                        QString classroom_name = cr->text( 0 );
1453
 
 
1454
 
                        textInputDialog classroom_name_input( tr( "Please enter a new name for classroom \"%1\"."
1455
 
                                                                ).arg( classroom_name ), classroom_name, this );
1456
 
                        classroom_name_input.setCaption( tr( "New name for classroom" ) );
1457
 
                        if( classroom_name_input.exec() == QDialog::Accepted && classroom_name != "" )
1458
 
                        {
1459
 
                                cr->setText( 0, classroom_name );
1460
 
                        }
1461
 
                }
1462
 
        }
1463
 
}
1464
 
 
1465
 
 
1466
 
 
1467
 
 
1468
 
void clientManager::removeClassRoom( void )
1469
 
{
1470
 
        for( unsigned int i = 0; i < m_classRooms.size(); ++i )
1471
 
        {
1472
 
                classRoom * cr = NULL;
1473
 
                if( m_list->isSelected( m_classRooms[i] ) )
1474
 
                {
1475
 
                        cr = m_classRooms[i];
1476
 
                }
1477
 
                if( cr != NULL )
1478
 
                {
1479
 
                        if( QMessageBox::question( this, tr( "Remove classroom" ),
1480
 
                                                        tr( "Are you sure want to remove classroom \"%1\"?\nAll clients in it will also be "
1481
 
                                                                "removed!" ).arg( cr->text( 0 ) ), QMessageBox::Yes, QMessageBox::No )
1482
 
                                == QMessageBox::No )
1483
 
                        {
1484
 
                                continue;
1485
 
                        }
1486
 
 
1487
 
                        cr->setVisible( FALSE );
1488
 
 
1489
 
                        QValueVector<client *> vv;
1490
 
                        getVisibleClients( cr, vv );
1491
 
                        for( unsigned int i = 0; i < vv.size(); ++i )
1492
 
                        {
1493
 
                                vv[i]->hide();
1494
 
                                m_clientsToRemove.push_back( vv[i] );
1495
 
                        }
1496
 
                        m_classRoomsToRemove.push_back( cr );
1497
 
                }
1498
 
        }
1499
 
}
1500
 
 
1501
 
 
1502
 
 
1503
 
 
1504
 
// slots for general actions in context-menu
1505
 
void clientManager::addClient( void )
1506
 
{
1507
 
        if( m_classRooms.size() == 0 )
1508
 
        {
1509
 
                QMessageBox::information( this, tr( "Missing classroom" ), tr( "Before you add clients, please add at least one "
1510
 
                                                                                        "classroom!" ), QMessageBox::Ok );
1511
 
                return;
1512
 
        }
1513
 
 
1514
 
        QString classroom_name = "";
1515
 
 
1516
 
        for( unsigned int i = 0; i < m_classRooms.size(); ++i )
1517
 
        {
1518
 
                if( m_list->isSelected( m_classRooms[i] ) )
1519
 
                {
1520
 
                        classroom_name = m_classRooms[i]->text( 0 );
1521
 
                        break;
1522
 
                }
1523
 
        }
1524
 
 
1525
 
        clientPropertiesEdit edit( NULL, classroom_name, this );
1526
 
        edit.setCaption( tr( "Add client" ) );
1527
 
        edit.exec();
1528
 
}
1529
 
 
1530
 
 
1531
 
 
1532
 
 
1533
 
void clientManager::addClassRoom( void )
1534
 
{
1535
 
        QString classroom_name = tr( "New classroom" );
1536
 
 
1537
 
        textInputDialog classroom_name_input( tr( "Please enter the name of the classroom you want to create." ), classroom_name, this );
1538
 
        classroom_name_input.setCaption( tr( "Name for new classroom" ) );
1539
 
 
1540
 
        if( classroom_name_input.exec() == QDialog::Accepted && classroom_name != "" )
1541
 
        {
1542
 
                classRoom * cr = NULL;
1543
 
                for( unsigned int i = 0; i < m_classRooms.size(); ++i )
1544
 
                {
1545
 
                        if( m_list->isSelected( m_classRooms[i] ) )
1546
 
                        {
1547
 
                                cr = m_classRooms[i];
1548
 
                                break;
1549
 
                        }
1550
 
                }
1551
 
                if( cr != NULL )
1552
 
                {
1553
 
                        m_classRooms.push_back( new classRoom( cr, classroom_name ) );
1554
 
                }
1555
 
                else
1556
 
                {
1557
 
                        m_classRooms.push_back( new classRoom( m_list, classroom_name ) );
1558
 
                }
1559
 
        }
1560
 
}
1561
 
 
1562
 
 
1563
 
 
1564
 
 
1565
 
 
1566
 
 
1567
 
 
1568
 
/*****************************************************************************
1569
 
 *
1570
 
 * Class classRoom
1571
 
 *
1572
 
 *****************************************************************************/
1573
 
 
1574
 
 
1575
 
QPixmap * classRoom::s_classRoomClosedPixmap = NULL;
1576
 
QPixmap * classRoom::s_classRoomOpenedPixmap = NULL;
1577
 
 
1578
 
 
1579
 
classRoom::classRoom( QListViewItem * _parent, const QString & _name ) :
1580
 
        QListViewItem(_parent, _name ),
1581
 
        m_pix( NULL ),
1582
 
        m_qsMenuId( clientManager::inst()->addClassRoomToQuickSwitchMenu( this ) )
1583
 
{
1584
 
        initPixmaps();
1585
 
}
1586
 
 
1587
 
 
1588
 
 
1589
 
 
1590
 
classRoom::classRoom( QListView * _parent, const QString & _name ) :
1591
 
        QListViewItem( _parent, _name ),
1592
 
        m_pix( NULL ),
1593
 
        m_qsMenuId( clientManager::inst()->addClassRoomToQuickSwitchMenu( this ) )
1594
 
{
1595
 
        initPixmaps();
1596
 
}
1597
 
 
1598
 
 
1599
 
 
1600
 
 
1601
 
classRoom::~classRoom()
1602
 
{
1603
 
        clientManager::inst()->removeClassRoomFromQuickSwitchMenu( m_qsMenuId );
1604
 
}
1605
 
 
1606
 
 
1607
 
 
1608
 
 
1609
 
void classRoom::initPixmaps( void )
1610
 
{
1611
 
        if( s_classRoomClosedPixmap == NULL )
1612
 
        {
1613
 
                s_classRoomClosedPixmap = new QPixmap( embed::getIconPixmap( "classroom_closed" ) );
1614
 
        }
1615
 
 
1616
 
        if( s_classRoomOpenedPixmap == NULL )
1617
 
        {
1618
 
                s_classRoomOpenedPixmap = new QPixmap( embed::getIconPixmap( "classroom_opened" ) );
1619
 
        }
1620
 
 
1621
 
        setPixmap( s_classRoomClosedPixmap );
1622
 
}
1623
 
 
1624
 
 
1625
 
 
1626
 
 
1627
 
void classRoom::createActionMenu( QPopupMenu * _m, bool _add_sub_menu )
1628
 
{
1629
 
        QPopupMenu * this_classroom_submenu = _m;
1630
 
        QPopupMenu * orig_root = _m;
1631
 
 
1632
 
        if( _add_sub_menu == TRUE )
1633
 
        {
1634
 
                this_classroom_submenu = new QPopupMenu( _m );
1635
 
                orig_root = this_classroom_submenu;
1636
 
                _m->insertItem( text( 0 ), this_classroom_submenu );
1637
 
        }
1638
 
        QPopupMenu * admin_submenu = new QPopupMenu( this_classroom_submenu );
1639
 
 
1640
 
        for( int i = client::START_FULLSCREEN_DEMO; i < client::CMD_COUNT; ++i )
1641
 
        {
1642
 
                if( i >= client::EXEC_CMDS )
1643
 
                        this_classroom_submenu = admin_submenu;
1644
 
 
1645
 
                int id = this_classroom_submenu->insertItem( embed::getIconPixmap( client::s_commands[i].m_icon ),
1646
 
                                                client::tr( client::s_commands[i].m_name ), this, SLOT( processCmdOnAllClients( int ) ) );
1647
 
                this_classroom_submenu->setItemParameter( id, i );
1648
 
 
1649
 
                if( client::s_commands[i].m_insertSep == TRUE )
1650
 
                {
1651
 
                        this_classroom_submenu->insertSeparator();
1652
 
                }
1653
 
        }
1654
 
 
1655
 
        orig_root->insertItem( embed::getIconPixmap( "client_settings" ), tr( "Administation" ), admin_submenu );
1656
 
}
1657
 
 
1658
 
 
1659
 
 
1660
 
 
1661
 
void classRoom::processCmdOnAllClients( int _cmd )
1662
 
{
1663
 
        QValueVector<client *> vv;
1664
 
 
1665
 
        // get all visible clients for this classroom
1666
 
        clientManager::getVisibleClients( this, vv );
1667
 
 
1668
 
        QString u_data = CONFIRM_NO;
1669
 
 
1670
 
        // may be we have to do something (e.g. confirm) before executing cmd
1671
 
        switch( static_cast<client::clientCmds>( _cmd ) )
1672
 
        {
1673
 
                case client::SEND_MESSAGE:
1674
 
                {
1675
 
                        msgInputDialog msg_input_dialog( u_data, NULL );
1676
 
                        if( msg_input_dialog.exec() != QDialog::Accepted || u_data == "" )
1677
 
                        {
1678
 
                                return;
1679
 
                        }
1680
 
                        break;
1681
 
                }
1682
 
                case client::RESTART_X:
1683
 
                {
1684
 
                        if( QMessageBox::question( NULL, clientManager::tr( "Restart X on clients" ),
1685
 
                                clientManager::tr( "Are you sure want to restart X on all visible clients?" ),
1686
 
                                QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
1687
 
                        {
1688
 
                                return;
1689
 
                        }
1690
 
                        break;
1691
 
                }
1692
 
                case client::KILL_BROWSERS:
1693
 
                {
1694
 
                        if( QMessageBox::question( NULL, clientManager::tr( "Kill Mozilla/FireFox on clients" ),
1695
 
                                clientManager::tr( "Are you sure want to kill Mozilla/FireFox on all visible clients?" ),
1696
 
                                QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
1697
 
                        {
1698
 
                                return;
1699
 
                        }
1700
 
                        break;
1701
 
                }
1702
 
                case client::EXEC_CMDS:
1703
 
                {
1704
 
                        cmdInputDialog cmd_input_dialog( u_data, NULL );
1705
 
                        if( cmd_input_dialog.exec() != QDialog::Accepted || u_data == "" )
1706
 
                        {
1707
 
                                return;
1708
 
                        }
1709
 
                        break;
1710
 
                }
1711
 
                case client::RUN_X_APP:
1712
 
                {
1713
 
                        textInputDialog app_input( client::tr( "Please enter the name of the application you want to run "
1714
 
                                                                "and redirect." ), u_data, NULL );
1715
 
                        app_input.setCaption( client::tr( "Run application..." ) );
1716
 
                        if( app_input.exec() != QDialog::Accepted || u_data == "" )
1717
 
                        {
1718
 
                                return;
1719
 
                        }
1720
 
                        break;
1721
 
                }
1722
 
                case client::SSH_LOGIN:
1723
 
                {
1724
 
                        u_data = "root";
1725
 
                        textInputDialog user_input( client::tr( "Please enter the user-name you want to login with." ), u_data, NULL );
1726
 
                        user_input.setCaption( client::tr( "SSH-Login" ) );
1727
 
                        if( user_input.exec() != QDialog::Accepted || u_data == "" )
1728
 
                        {
1729
 
                                return;
1730
 
                        }
1731
 
                        break;
1732
 
                }
1733
 
                case client::REBOOT:
1734
 
                {
1735
 
                        if( QMessageBox::question( NULL, clientManager::tr( "Reboot clients" ),
1736
 
                                clientManager::tr( "Are you sure want to reboot all visible clients?" ),
1737
 
                                QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
1738
 
                        {
1739
 
                                return;
1740
 
                        }
1741
 
                        break;
1742
 
                }
1743
 
                case client::POWER_OFF:
1744
 
                {
1745
 
                        if( QMessageBox::question( NULL, clientManager::tr( "Power off clients" ),
1746
 
                                clientManager::tr( "Are you sure want to power off all visible clients?" ),
1747
 
                                QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
1748
 
                        {
1749
 
                                return;
1750
 
                        }
1751
 
                        break;
1752
 
                }
1753
 
                default:
1754
 
                        break;
1755
 
        }
1756
 
 
1757
 
        for( unsigned int i = 0; i < vv.size(); ++i )
1758
 
        {
1759
 
                vv[i]->processCmd( static_cast<client::clientCmds>( _cmd ), u_data );
1760
 
        }
1761
 
}
1762
 
 
1763
 
 
1764
 
 
1765
 
 
1766
 
void classRoom::setPixmap( QPixmap * _pix )
1767
 
{
1768
 
        m_pix = _pix;
1769
 
 
1770
 
        setup();
1771
 
        widthChanged( 0 );
1772
 
        invalidateHeight();
1773
 
        repaint();
1774
 
}
1775
 
 
1776
 
 
1777
 
 
1778
 
 
1779
 
void classRoom::setOpen( bool _o )
1780
 
{
1781
 
        if( _o )
1782
 
        {
1783
 
                setPixmap( s_classRoomOpenedPixmap );
1784
 
        }
1785
 
        else
1786
 
        {
1787
 
                setPixmap( s_classRoomClosedPixmap );
1788
 
        }
1789
 
 
1790
 
        QListViewItem::setOpen( _o );
1791
 
}
1792
 
 
1793
 
 
1794
 
 
1795
 
 
1796
 
void classRoom::setup( void )
1797
 
{
1798
 
        setExpandable( TRUE );
1799
 
        QListViewItem::setup();
1800
 
}
1801
 
 
1802
 
 
1803
 
 
1804
 
 
1805
 
void classRoom::switchToClassRoom( void )
1806
 
{
1807
 
        clientManager::inst()->hideAllClassRooms();
1808
 
        clientManager::inst()->setStateOfClassRoom( this, TRUE );
1809
 
}
1810
 
 
1811
 
 
1812
 
 
1813
 
 
1814
 
 
1815
 
 
1816
 
 
1817
 
 
1818
 
 
1819
 
 
1820
 
classRoomItem::classRoomItem( client * _client, QListViewItem * _parent, const QString & _name ) :
1821
 
        QListViewItem( _parent, _name ),
1822
 
        m_client( _client )
1823
 
{
1824
 
        if( s_clientPixmap == NULL )
1825
 
        {
1826
 
                s_clientPixmap = new QPixmap( embed::getIconPixmap( "client" ) );
1827
 
        }
1828
 
        if( s_clientObservedPixmap == NULL )
1829
 
        {
1830
 
                s_clientObservedPixmap = new QPixmap( embed::getIconPixmap( "client_observed" ) );
1831
 
        }
1832
 
 
1833
 
        m_pix = s_clientPixmap;
1834
 
        setText( 1, m_client->ip() );
1835
 
}
1836
 
 
1837
 
 
1838
 
 
1839
 
 
1840
 
classRoomItem::~classRoomItem()
1841
 
{
1842
 
        m_client->setClassRoomItem( NULL );
1843
 
}
1844
 
 
1845
 
 
1846
 
 
1847
 
 
1848
 
void classRoomItem::setObserved( bool _obs )
1849
 
{
1850
 
        if( _obs == FALSE )
1851
 
        {
1852
 
                setPixmap( s_clientPixmap );
1853
 
        }
1854
 
        else
1855
 
        {
1856
 
                setPixmap( s_clientObservedPixmap );
1857
 
        }
1858
 
}
1859
 
 
1860
 
 
1861
 
 
1862
 
 
1863
 
void classRoomItem::setPixmap( QPixmap * _pix )
1864
 
{
1865
 
        m_pix = _pix;
1866
 
 
1867
 
        setup();
1868
 
        widthChanged( 0 );
1869
 
        invalidateHeight();
1870
 
        repaint();
1871
 
}