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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
|
/*
* Remote Laboratory User Management Part
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (c) 2013 Timothy Pearson
* Raptor Engineering
* http://www.raptorengineeringinc.com
*/
#include "define.h"
#include "part.h"
#include <kaboutdata.h> //::createAboutData()
#include <kaction.h>
#include <klocale.h>
#include <ktextedit.h>
#include <kfiledialog.h>
#include <kmessagebox.h> //::start()
#include <kparts/genericfactory.h>
#include <kstatusbar.h>
#include <kstdaction.h>
#include <knuminput.h>
#include <kmdcodec.h>
#include <kurlrequester.h>
#include <tqfile.h> //encodeName()
#include <tqtimer.h> //postInit() hack
#include <tqvbox.h>
#include <tqsocket.h>
#include <tqmutex.h>
#include <tqeventloop.h>
#include <tqapplication.h>
#include <tqgroupbox.h>
#include <tqcheckbox.h>
#include <tqpushbutton.h>
#include <tqprogressbar.h>
#include <tqlistview.h>
#include <klistview.h>
#include <unistd.h> //access()
#include <stdint.h>
#include <tqpainter.h>
#include "tracewidget.h"
#include "floatspinbox.h"
#include "layout.h"
#include "groupauthdlg.h"
#define NETWORK_COMM_TIMEOUT_MS 2500
enum connectionModes {
ModeIdle = 0,
ModeUpdate = 1,
ModeDelete = 2
};
enum connectionStates {
ModeIdle_None = 0,
ModeIdle_StateTerminalListRequest = 1,
ModeIdle_StateProcessTerminalList = 2,
ModeIdle_StateWorkspaceListRequest = 3,
ModeIdle_StateProcessWorkspaceList = 4,
ModeIdle_StateTerminalAuthGroupListRequest = 5,
ModeIdle_StateProcessTerminalAuthGroupList = 6,
ModeIdle_StateWorkspaceServiceAuthGroupListRequest = 7,
ModeIdle_StateProcessWorkspaceServiceAuthGroupList = 8,
ModeIdle_StateDelay = 9,
ModeUpdate_TerminalServices = 10,
ModeUpdate_LaboratoryWorkspace = 11,
ModeUpdate_ProcessResponse = 12,
ModeDelete_TerminalServices = 13,
ModeDelete_LaboratoryWorkspace = 14,
ModeDelete_ProcessResponse = 15
};
namespace RemoteLab {
typedef KParts::GenericFactory<RemoteLab::UserManagementPart> Factory;
#define CLIENT_LIBRARY "libremotelab_adminusermgmt"
K_EXPORT_COMPONENT_FACTORY(libremotelab_adminusermgmt, RemoteLab::Factory)
UserManagementPart::UserManagementPart(TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const TQStringList&)
: RemoteInstrumentPart( parent, name ), m_base(NULL), m_commHandlerState(0), m_connectionActiveAndValid(false), m_tickerState(0)
{
// Initialize important base class variables
m_clientLibraryName = CLIENT_LIBRARY;
// Initialize mutex
m_connectionMutex = new TQMutex(false);
// Initialize kpart
setInstance(Factory::instance());
setWidget(new TQVBox(parentWidget, widgetName));
// Create timers
m_forcedUpdateTimer = new TQTimer(this);
connect(m_forcedUpdateTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop()));
m_updateTimeoutTimer = new TQTimer(this);
connect(m_updateTimeoutTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop()));
m_pingDelayTimer = new TQTimer(this);
connect(m_pingDelayTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop()));
// Create widgets
m_base = new UserManagementBase(widget());
// Initialize widgets
connect(m_base->ts_buttonAddGroup, SIGNAL(clicked()), this, SLOT(terminalServiceAddGroupButtonClicked()));
connect(m_base->ts_buttonModifyGroup, SIGNAL(clicked()), this, SLOT(terminalServiceModifyGroupButtonClicked()));
connect(m_base->ts_buttonDeleteGroup, SIGNAL(clicked()), this, SLOT(terminalServiceDeleteGroupButtonClicked()));
connect(m_base->workspace_buttonAddGroup, SIGNAL(clicked()), this, SLOT(workspaceAddGroupButtonClicked()));
connect(m_base->workspace_buttonModifyGroup, SIGNAL(clicked()), this, SLOT(workspaceModifyGroupButtonClicked()));
connect(m_base->workspace_buttonDeleteGroup, SIGNAL(clicked()), this, SLOT(workspaceDeleteGroupButtonClicked()));
connect(m_base->ts_list, SIGNAL(doubleClicked(TQListViewItem*, const TQPoint&, int)), this, SLOT(terminalServiceModifyGroupButtonClicked()));
connect(m_base->workspace_list, SIGNAL(doubleClicked(TQListViewItem*, const TQPoint&, int)), this, SLOT(workspaceModifyGroupButtonClicked()));
m_base->ts_list->setAllColumnsShowFocus(true);
connect(m_base->ts_list, SIGNAL(selectionChanged()), this, SLOT(terminalServiceListSelect()));
m_base->workspace_list->setAllColumnsShowFocus(true);
connect(m_base->workspace_list, SIGNAL(selectionChanged()), this, SLOT(workspaceListSelect()));
TQTimer::singleShot(0, this, TQT_SLOT(postInit()));
}
UserManagementPart::~UserManagementPart() {
if (m_connectionMutex->locked()) {
printf("[WARNING] Exiting when data transfer still in progress!\n\r"); fflush(stdout);
}
disconnectFromServer();
delete m_connectionMutex;
}
void UserManagementPart::processLockouts() {
TQWidget* mainWidget = widget();
if (mainWidget) {
if ((m_socket) && (m_socket->state() == TQSocket::Connected) && (connToServerState > 0) && (connToServerConnecting == false) && (m_commHandlerNextMode == ModeIdle)) {
mainWidget->setEnabled(true);
}
else {
mainWidget->setEnabled(false);
}
}
if (m_connectionActiveAndValid == true) {
m_base->ts_buttonAddGroup->setEnabled(true);
m_base->workspace_buttonAddGroup->setEnabled(true);
}
else {
m_base->ts_buttonAddGroup->setEnabled(false);
m_base->workspace_buttonAddGroup->setEnabled(false);
}
if ((m_connectionActiveAndValid == true) && (m_base->ts_list->selectedItem())) {
m_base->ts_buttonModifyGroup->setEnabled(true);
m_base->ts_buttonDeleteGroup->setEnabled(true);
}
else {
m_base->ts_buttonModifyGroup->setEnabled(false);
m_base->ts_buttonDeleteGroup->setEnabled(false);
}
if ((m_connectionActiveAndValid == true) && (m_base->workspace_list->selectedItem())) {
m_base->workspace_buttonModifyGroup->setEnabled(true);
m_base->workspace_buttonDeleteGroup->setEnabled(true);
}
else {
m_base->workspace_buttonModifyGroup->setEnabled(false);
m_base->workspace_buttonDeleteGroup->setEnabled(false);
}
}
void UserManagementPart::resizeToHint() {
resize(widget()->sizeHint());
}
void UserManagementPart::connectionClosed() {
closeURL();
}
void UserManagementPart::postInit() {
setUsingFixedSize(false);
}
bool UserManagementPart::openURL(const KURL &url) {
int ret;
ret = connectToServer(url.url());
processLockouts();
return (ret != 0);
}
bool UserManagementPart::closeURL() {
disconnectFromServer();
m_url = KURL();
return true;
}
void UserManagementPart::disconnectFromServerCallback() {
m_forcedUpdateTimer->stop();
m_updateTimeoutTimer->stop();
}
void UserManagementPart::connectionFinishedCallback() {
connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData()));
m_socket->processPendingData();
connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(mainEventLoop()));
m_tickerState = 0;
m_commHandlerState = ModeIdle_StateTerminalListRequest;
m_commHandlerMode = ModeIdle;
m_commHandlerNextState = ModeIdle_None;
m_commHandlerNextMode = ModeIdle;
m_socket->setDataTimeout(NETWORK_COMM_TIMEOUT_MS);
m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE);
processLockouts();
mainEventLoop();
return;
}
void UserManagementPart::connectionStatusChangedCallback() {
processLockouts();
}
void UserManagementPart::terminalServiceAddGroupButtonClicked() {
GroupPermissionsDialog groupauthdlg(0);
groupauthdlg.setPermissionsSelectorLabel(i18n("Allowed Servers"));
{
TQKeyedStringList keyedServerList;
for (TQStringList::Iterator it2 = m_availableTerminalServersList.begin(); it2 != m_availableTerminalServersList.end(); ++it2) {
keyedServerList.append(TQKeyedStringPair(TQString("%1").arg(*it2), 0));
}
groupauthdlg.setAvailableServers(keyedServerList);
groupauthdlg.setSessionLimit(0, true);
}
if (groupauthdlg.exec() == TQDialog::Accepted) {
m_updateTerminalServiceAuthGroupList.clear();
TerminalServiceAuthGroupType agt;
agt.groupName = groupauthdlg.groupName();
TQKeyedStringList selectedServers = groupauthdlg.selectedServers();
agt.allowedServerNames.clear();
for (TQKeyedStringList::Iterator it = selectedServers.begin(); it != selectedServers.end(); ++it) {
agt.allowedServerNames.append((*it).first);
}
agt.maximumActiveSessionCount = groupauthdlg.sessionLimit();
m_updateTerminalServiceAuthGroupList.append(agt);
m_commHandlerNextState = ModeUpdate_TerminalServices;
m_commHandlerNextMode = ModeUpdate;
}
processLockouts();
}
void UserManagementPart::terminalServiceModifyGroupButtonClicked() {
TQListViewItem* item = m_base->ts_list->selectedItem();
GroupPermissionsDialog groupauthdlg(0);
groupauthdlg.setPermissionsSelectorLabel(i18n("Allowed Servers"));
{
TQKeyedStringList keyedServerList;
for (TQStringList::Iterator it2 = m_availableTerminalServersList.begin(); it2 != m_availableTerminalServersList.end(); ++it2) {
keyedServerList.append(TQKeyedStringPair(TQString("%1").arg(*it2), 0));
}
groupauthdlg.setAvailableServers(keyedServerList);
}
TerminalServiceAuthGroupList::iterator it = m_terminalServiceAuthGroupList.findByName(item->text(0));
if (it != m_terminalServiceAuthGroupList.end()) {
TQKeyedStringList keyedServerList;
for (TQStringList::Iterator it2 = (*it).allowedServerNames.begin(); it2 != (*it).allowedServerNames.end(); ++it2) {
keyedServerList.append(TQKeyedStringPair(TQString("%1").arg(*it2), 0));
}
groupauthdlg.setSelectedServers(keyedServerList);
groupauthdlg.setSessionLimit((*it).maximumActiveSessionCount, true);
}
groupauthdlg.setGroupName(item->text(0), false);
if (groupauthdlg.exec() == TQDialog::Accepted) {
m_updateTerminalServiceAuthGroupList.clear();
TerminalServiceAuthGroupType agt;
agt.groupName = groupauthdlg.groupName();
TQKeyedStringList selectedServers = groupauthdlg.selectedServers();
agt.allowedServerNames.clear();
for (TQKeyedStringList::Iterator it = selectedServers.begin(); it != selectedServers.end(); ++it) {
agt.allowedServerNames.append((*it).first);
}
agt.maximumActiveSessionCount = groupauthdlg.sessionLimit();
m_updateTerminalServiceAuthGroupList.append(agt);
m_commHandlerNextState = ModeUpdate_TerminalServices;
m_commHandlerNextMode = ModeUpdate;
}
processLockouts();
}
void UserManagementPart::terminalServiceDeleteGroupButtonClicked() {
TQListViewItem* item = m_base->ts_list->selectedItem();
if (KMessageBox::warningYesNo(0, i18n("<qt><b>You are attempting to delete the group '%1'</b><br>You will not be able to undo this action<p>Do you wish to proceed?</qt>").arg(item->text(0)), i18n("Delete group?")) == KMessageBox::Yes) {
m_updateTerminalServiceAuthGroupList.clear();
TerminalServiceAuthGroupType agt;
agt.groupName = item->text(0);
m_updateTerminalServiceAuthGroupList.append(agt);
m_commHandlerNextState = ModeDelete_TerminalServices;
m_commHandlerNextMode = ModeDelete;
}
processLockouts();
}
void UserManagementPart::workspaceAddGroupButtonClicked() {
GroupPermissionsDialog groupauthdlg(0);
groupauthdlg.setPermissionsSelectorLabel(i18n("Allowed Stations"));
groupauthdlg.setSessionLimit(-1, false);
{
TQKeyedStringList friendlyStations;
for (StationList::iterator it = m_availableWorkspaceStationsList.begin(); it != m_availableWorkspaceStationsList.end(); ++it) {
friendlyStations.append(TQKeyedStringPair(TQString("%1").arg((*it).name), (*it).id));
}
groupauthdlg.setAvailableServers(friendlyStations);
}
if (groupauthdlg.exec() == TQDialog::Accepted) {
m_updateWorkspaceServiceAuthGroupList.clear();
WorkspaceServiceAuthGroupType agt;
agt.groupName = groupauthdlg.groupName();
TQKeyedStringList selectedStations = groupauthdlg.selectedServers();
agt.allowedStationIDs.clear();
for (TQKeyedStringList::Iterator it = selectedStations.begin(); it != selectedStations.end(); ++it) {
agt.allowedStationIDs.append((*it).second);
}
m_updateWorkspaceServiceAuthGroupList.append(agt);
m_commHandlerNextState = ModeUpdate_LaboratoryWorkspace;
m_commHandlerNextMode = ModeUpdate;
}
processLockouts();
}
void UserManagementPart::workspaceModifyGroupButtonClicked() {
TQListViewItem* item = m_base->workspace_list->selectedItem();
GroupPermissionsDialog groupauthdlg(0);
groupauthdlg.setPermissionsSelectorLabel(i18n("Allowed Stations"));
groupauthdlg.setSessionLimit(-1, false);
{
TQKeyedStringList friendlyStations;
for (StationList::iterator it = m_availableWorkspaceStationsList.begin(); it != m_availableWorkspaceStationsList.end(); ++it) {
friendlyStations.append(TQKeyedStringPair(TQString("%1").arg((*it).name), (*it).id));
}
groupauthdlg.setAvailableServers(friendlyStations);
}
WorkspaceServiceAuthGroupList::iterator it = m_workspaceAuthGroupList.findByName(item->text(0));
if (it != m_workspaceAuthGroupList.end()) {
TQKeyedStringList friendlyStations;
for (TQInt32List::Iterator it2 = (*it).allowedStationIDs.begin(); it2 != (*it).allowedStationIDs.end(); ++it2) {
int stationID = *it2;
StationList::iterator stationInfoIterator = m_availableWorkspaceStationsList.findByID(stationID);
if (stationInfoIterator != m_availableWorkspaceStationsList.end()) {
friendlyStations.append(TQKeyedStringPair(TQString("%1").arg((*stationInfoIterator).name), (*stationInfoIterator).id));
}
else {
friendlyStations.append(TQKeyedStringPair(TQString("<unknown>"), stationID));
}
}
groupauthdlg.setSelectedServers(friendlyStations);
}
groupauthdlg.setGroupName(item->text(0), false);
if (groupauthdlg.exec() == TQDialog::Accepted) {
m_updateWorkspaceServiceAuthGroupList.clear();
WorkspaceServiceAuthGroupType agt;
agt.groupName = groupauthdlg.groupName();
TQKeyedStringList selectedStations = groupauthdlg.selectedServers();
agt.allowedStationIDs.clear();
for (TQKeyedStringList::Iterator it = selectedStations.begin(); it != selectedStations.end(); ++it) {
agt.allowedStationIDs.append((*it).second);
}
m_updateWorkspaceServiceAuthGroupList.append(agt);
m_commHandlerNextState = ModeUpdate_LaboratoryWorkspace;
m_commHandlerNextMode = ModeUpdate;
}
processLockouts();
}
void UserManagementPart::workspaceDeleteGroupButtonClicked() {
TQListViewItem* item = m_base->workspace_list->selectedItem();
if (KMessageBox::warningYesNo(0, i18n("<qt><b>You are attempting to delete the group '%1'</b><br>You will not be able to undo this action<p>Do you wish to proceed?</qt>").arg(item->text(0)), i18n("Delete group?")) == KMessageBox::Yes) {
m_updateWorkspaceServiceAuthGroupList.clear();
WorkspaceServiceAuthGroupType agt;
agt.groupName = item->text(0);
agt.allowedStationIDs.clear();
m_updateWorkspaceServiceAuthGroupList.append(agt);
m_commHandlerNextState = ModeDelete_LaboratoryWorkspace;
m_commHandlerNextMode = ModeDelete;
}
processLockouts();
}
void UserManagementPart::terminalServiceListSelect() {
// Highlight the matching user session in the workspace list,
// or deselect all workspace list items if no matching workspace session is found
TQListViewItem* item = m_base->ts_list->selectedItem();
if (item) {
TQString username = item->text(1);
TQListViewItemIterator it;
it = TQListViewItemIterator(m_base->workspace_list);
bool found = false;
TQListViewItem* item2 = NULL;
while (it.current()) {
item2 = *it;
if (item2->text(1) == username) {
found = true;
break;
}
++it;
}
if (found) {
m_base->workspace_list->setCurrentItem(item2);
}
else {
m_base->workspace_list->clearSelection();
}
}
else {
m_base->workspace_list->clearSelection();
}
processLockouts();
}
void UserManagementPart::workspaceListSelect() {
// Highlight the matching user session in the terminal services list,
// or deselect all workspace list items if no matching terminal services session is found
TQListViewItem* item = m_base->workspace_list->selectedItem();
if (item) {
TQString username = item->text(1);
TQListViewItemIterator it;
it = TQListViewItemIterator(m_base->ts_list);
bool found = false;
TQListViewItem* item2 = NULL;
while (it.current()) {
item2 = *it;
if (item2->text(1) == username) {
found = true;
break;
}
++it;
}
if (found) {
m_base->ts_list->setCurrentItem(item2);
}
else {
m_base->ts_list->clearSelection();
}
}
else {
m_base->ts_list->clearSelection();
}
processLockouts();
}
#define UPDATEDISPLAY_TIMEOUT m_connectionActiveAndValid = false; \
m_tickerState = 0; \
m_commHandlerState = ModeIdle_StateTerminalListRequest; \
m_commHandlerMode = ModeIdle; \
m_commHandlerNextState = ModeIdle_None; \
m_commHandlerNextMode = ModeIdle; \
m_socket->clearIncomingData(); \
setStatusMessage(i18n("Server ping timeout. Please verify the status of your network connection.")); \
m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); \
m_connectionMutex->unlock(); \
return;
#define SET_WATCHDOG_TIMER if (!m_updateTimeoutTimer->isActive()) m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE);
#define PAT_WATCHDOG_TIMER m_updateTimeoutTimer->stop(); m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE);
#define SET_NEXT_STATE(x) m_commHandlerState = x;
#define EXEC_NEXT_STATE_IMMEDIATELY m_forcedUpdateTimer->start(0, TRUE);
void UserManagementPart::setTickerMessage(TQString message) {
m_connectionActiveAndValid = true;
TQString tickerChar;
switch (m_tickerState) {
case 0:
tickerChar = "-";
break;
case 1:
tickerChar = "\\";
break;
case 2:
tickerChar = "|";
break;
case 3:
tickerChar = "/";
break;
}
setStatusMessage(message + TQString("... %1").arg(tickerChar));
m_tickerState++;
if (m_tickerState > 3) {
m_tickerState = 0;
}
}
void UserManagementPart::mainEventLoop() {
TQDataStream ds(m_socket);
ds.setPrintableData(true);
if (!m_connectionMutex->tryLock()) {
EXEC_NEXT_STATE_IMMEDIATELY
return;
}
if (m_socket) {
if (m_commHandlerMode == ModeIdle) {
// Normal operation
switch (m_commHandlerState) {
case ModeIdle_StateTerminalListRequest:
// Get status of remote system
// Clear buffers to synchronize frames in case of data corruption
m_socket->clearIncomingData();
ds << TQString("LIST");
ds << TQString("TERMINALS");
m_socket->writeEndOfFrame();
SET_NEXT_STATE(ModeIdle_StateProcessTerminalList)
break;
case ModeIdle_StateProcessTerminalList:
// Get all data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
TQString status;
ds >> status;
if (status == "OK") {
ds >> m_availableTerminalServersList;
m_socket->clearFrameTail();
setTickerMessage(i18n("Connected"));
}
SET_NEXT_STATE(ModeIdle_StateWorkspaceListRequest);
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
break;
case ModeIdle_StateWorkspaceListRequest:
// Get status of remote system
// Clear buffers to synchronize frames in case of data corruption
m_socket->clearIncomingData();
ds << TQString("LIST");
ds << TQString("WORKSPACES");
m_socket->writeEndOfFrame();
SET_NEXT_STATE(ModeIdle_StateProcessWorkspaceList)
EXEC_NEXT_STATE_IMMEDIATELY
break;
case ModeIdle_StateProcessWorkspaceList:
// Get all data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
TQString status;
ds >> status;
if (status == "OK") {
ds >> m_availableWorkspaceStationsList;
m_socket->clearFrameTail();
setTickerMessage(i18n("Connected"));
}
SET_NEXT_STATE(ModeIdle_StateTerminalAuthGroupListRequest);
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
break;
case ModeIdle_StateTerminalAuthGroupListRequest:
// Get status of remote system
// Clear buffers to synchronize frames in case of data corruption
m_socket->clearIncomingData();
ds << TQString("LISTGROUPACCESS");
ds << TQString("TERMINALS");
m_socket->writeEndOfFrame();
SET_NEXT_STATE(ModeIdle_StateProcessTerminalAuthGroupList)
break;
case ModeIdle_StateProcessTerminalAuthGroupList:
// Get all data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
TQString status;
ds >> status;
if (status == "OK") {
ds >> m_terminalServiceAuthGroupList;
m_socket->clearFrameTail();
TerminalServiceAuthGroupList::iterator it;
TQListViewItemIterator it2;
for (it = m_terminalServiceAuthGroupList.begin(); it != m_terminalServiceAuthGroupList.end(); ++it) {
TerminalServiceAuthGroupType info = *it;
it2 = TQListViewItemIterator(m_base->ts_list);
bool found = false;
TQListViewItem* item = NULL;
while (it2.current()) {
item = *it2;
if (info.groupName == item->text(0)) {
found = true;
break;
}
++it2;
}
if (!found) {
item = new TQListViewItem(m_base->ts_list);
}
item->setText(0, TQString("%1").arg(info.groupName));
item->setText(1, info.allowedServerNames.join(", "));
item->setText(2, TQString("%1").arg(info.maximumActiveSessionCount));
}
it2 = TQListViewItemIterator(m_base->ts_list);
while (it2.current()) {
TQListViewItem* item = *it2;
bool found = false;
for (it = m_terminalServiceAuthGroupList.begin(); it != m_terminalServiceAuthGroupList.end(); ++it) {
TerminalServiceAuthGroupType info = *it;
if (info.groupName == item->text(0)) {
found = true;
}
}
if (!found) {
delete item;
}
++it2;
}
setTickerMessage(i18n("Connected"));
}
SET_NEXT_STATE(ModeIdle_StateWorkspaceServiceAuthGroupListRequest);
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
break;
case ModeIdle_StateWorkspaceServiceAuthGroupListRequest:
// Get status of remote system
// Clear buffers to synchronize frames in case of data corruption
m_socket->clearIncomingData();
ds << TQString("LISTGROUPACCESS");
ds << TQString("WORKSPACES");
m_socket->writeEndOfFrame();
SET_NEXT_STATE(ModeIdle_StateProcessWorkspaceServiceAuthGroupList)
EXEC_NEXT_STATE_IMMEDIATELY
break;
case ModeIdle_StateProcessWorkspaceServiceAuthGroupList:
// Get all data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
TQString status;
ds >> status;
if (status == "OK") {
ds >> m_workspaceAuthGroupList;
m_socket->clearFrameTail();
WorkspaceServiceAuthGroupList::iterator it;
TQListViewItemIterator it2;
for (it = m_workspaceAuthGroupList.begin(); it != m_workspaceAuthGroupList.end(); ++it) {
WorkspaceServiceAuthGroupType info = *it;
it2 = TQListViewItemIterator(m_base->workspace_list);
bool found = false;
TQListViewItem* item = NULL;
while (it2.current()) {
item = *it2;
if (info.groupName == item->text(0)) {
found = true;
break;
}
++it2;
}
if (!found) {
item = new TQListViewItem(m_base->workspace_list);
}
item->setText(0, TQString("%1").arg(info.groupName));
TQString allowedStationsText;
TQInt32List::iterator it3;
for (it3 = info.allowedStationIDs.begin(); it3 != info.allowedStationIDs.end(); ++it3) {
StationList::iterator stationInfoIterator = m_availableWorkspaceStationsList.findByID(*it3);
if (stationInfoIterator != m_availableWorkspaceStationsList.end()) {
if (allowedStationsText != "") {
allowedStationsText.append(", ");
}
allowedStationsText.append((*stationInfoIterator).name);
}
}
item->setText(1, allowedStationsText);
}
it2 = TQListViewItemIterator(m_base->workspace_list);
while (it2.current()) {
TQListViewItem* item = *it2;
bool found = false;
for (it = m_workspaceAuthGroupList.begin(); it != m_workspaceAuthGroupList.end(); ++it) {
WorkspaceServiceAuthGroupType info = *it;
if (info.groupName == item->text(0)) {
found = true;
}
}
if (!found) {
delete item;
}
++it2;
}
setTickerMessage(i18n("Connected"));
}
if (m_commHandlerState == ModeIdle_StateProcessWorkspaceServiceAuthGroupList) {
m_pingDelayTimer->start(250, TRUE);
SET_NEXT_STATE(ModeIdle_StateDelay);
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
break;
case ModeIdle_StateDelay:
if (m_commHandlerNextMode == ModeIdle) {
// Let the client and server rest for a bit to lower CPU/network overhead
if (!m_pingDelayTimer->isActive()) {
EXEC_NEXT_STATE_IMMEDIATELY
// Execute query on next event loop
SET_NEXT_STATE(ModeIdle_StateTerminalListRequest);
}
PAT_WATCHDOG_TIMER
}
else {
m_commHandlerMode = m_commHandlerNextMode;
SET_NEXT_STATE(m_commHandlerNextState);
EXEC_NEXT_STATE_IMMEDIATELY
m_commHandlerNextState = ModeIdle_None;
m_commHandlerNextMode = ModeIdle;
}
break;
}
}
else if (m_commHandlerMode == ModeUpdate) {
switch (m_commHandlerState) {
case ModeUpdate_TerminalServices:
ds << TQString("SETGROUPACCESS");
ds << TQString("TERMINALS");
ds << m_updateTerminalServiceAuthGroupList;
m_socket->writeEndOfFrame();
SET_NEXT_STATE(ModeUpdate_ProcessResponse)
EXEC_NEXT_STATE_IMMEDIATELY
break;
case ModeUpdate_LaboratoryWorkspace:
ds << TQString("SETGROUPACCESS");
ds << TQString("WORKSPACES");
ds << m_updateWorkspaceServiceAuthGroupList;
m_socket->writeEndOfFrame();
SET_NEXT_STATE(ModeUpdate_ProcessResponse)
EXEC_NEXT_STATE_IMMEDIATELY
break;
case ModeUpdate_ProcessResponse:
// Get all data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
TQString status;
WorkspaceServiceStatusList list;
ds >> status;
if (status != "OK") {
// Command failed!
KMessageBox::error(0, i18n("Command Failure"), i18n("Unable to execute command!"));
}
m_commHandlerMode = ModeIdle;
SET_NEXT_STATE(ModeIdle_StateTerminalListRequest);
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
break;
}
}
else if (m_commHandlerMode == ModeDelete) {
switch (m_commHandlerState) {
case ModeDelete_TerminalServices:
ds << TQString("DELETEGROUPACCESS");
ds << TQString("TERMINALS");
ds << m_updateTerminalServiceAuthGroupList;
m_socket->writeEndOfFrame();
SET_NEXT_STATE(ModeDelete_ProcessResponse)
EXEC_NEXT_STATE_IMMEDIATELY
break;
case ModeDelete_LaboratoryWorkspace:
ds << TQString("DELETEGROUPACCESS");
ds << TQString("WORKSPACES");
ds << m_updateWorkspaceServiceAuthGroupList;
m_socket->writeEndOfFrame();
SET_NEXT_STATE(ModeDelete_ProcessResponse)
EXEC_NEXT_STATE_IMMEDIATELY
break;
case ModeDelete_ProcessResponse:
// Get all data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
TQString status;
WorkspaceServiceStatusList list;
ds >> status;
if (status != "OK") {
// Command failed!
KMessageBox::error(0, i18n("Command Failure"), i18n("Unable to execute command!"));
}
m_commHandlerMode = ModeIdle;
SET_NEXT_STATE(ModeIdle_StateTerminalListRequest);
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
break;
}
}
processLockouts();
SET_WATCHDOG_TIMER
}
else {
SET_NEXT_STATE(ModeIdle_StateTerminalListRequest);
m_commHandlerMode = ModeIdle;
}
m_connectionMutex->unlock();
}
KAboutData* UserManagementPart::createAboutData() {
return new KAboutData( APP_NAME, I18N_NOOP( APP_PRETTYNAME ), APP_VERSION );
}
} //namespace RemoteLab
#include "part.moc"
|