forked from mumble-voip/mumble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathACLEditor.cpp
1025 lines (858 loc) · 27.6 KB
/
ACLEditor.cpp
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
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2005, Thorvald Natvig <thorvald@natvig.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of the Mumble Developers nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <QApplication>
#include <QIcon>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QGroupBox>
#include <QLabel>
#include "ACLEditor.h"
#include "ACL.h"
#include "ServerHandler.h"
#include "Channel.h"
#include "Global.h"
ACLEditor::ACLEditor(const MessageEditACL *mea, QWidget *p) : QDialog(p) {
QLabel *l;
MessageEditACL::ACLStruct as;
MessageEditACL::GroupStruct gs;
MessageEditACL::ACLStruct *asp;
MessageEditACL::GroupStruct *gsp;
iId = mea->iId;
setWindowTitle(QString("Mumble - Edit ACL for %1").arg(Channel::get(iId)->qsName));
QTabWidget *qtwTab = new QTabWidget(this);
QWidget *groupEditor=new QWidget();
QWidget *aclEditor=new QWidget();
QGroupBox *qgbACLs = new QGroupBox(tr("Active ACLs"));
QGroupBox *qgbACLapply = new QGroupBox(tr("Context"));
QGroupBox *qgbACLugroup = new QGroupBox(tr("User/Group"));
QGroupBox *qgbACLpermissions = new QGroupBox(tr("Permissions"));
QGroupBox *qgbGroups = new QGroupBox(tr("Group"));
QGroupBox *qgbGroupMembers = new QGroupBox(tr("Members"));
qlwACLs = new QListWidget();
qlwACLs->setObjectName("ACLList");
qpbACLAdd=new QPushButton(tr("&Add"));
qpbACLAdd->setObjectName("ACLAdd");
qpbACLRemove=new QPushButton(tr("&Remove"));
qpbACLRemove->setObjectName("ACLRemove");
qpbACLUp=new QPushButton(tr("&Up"));
qpbACLUp->setObjectName("ACLUp");
qpbACLDown=new QPushButton(tr("&Down"));
qpbACLDown->setObjectName("ACLDown");
qcbACLInherit=new QCheckBox(tr("Inherit ACLs"));
qcbACLInherit->setObjectName("ACLInherit");
QHBoxLayout *qhblAclList = new QHBoxLayout;
qhblAclList->addWidget(qcbACLInherit);
qhblAclList->addStretch(1);
qhblAclList->addWidget(qpbACLUp);
qhblAclList->addWidget(qpbACLDown);
qhblAclList->addWidget(qpbACLAdd);
qhblAclList->addWidget(qpbACLRemove);
QVBoxLayout *qvblAclList = new QVBoxLayout;
qvblAclList->addWidget(qlwACLs);
qvblAclList->addLayout(qhblAclList);
qgbACLs->setLayout(qvblAclList);
QGridLayout *grid = new QGridLayout();
qcbACLApplyHere=new QCheckBox(tr("Applies to this channel"));
qcbACLApplyHere->setObjectName("ACLApplyHere");
qcbACLApplySubs=new QCheckBox(tr("Applies to subchannels"));
qcbACLApplySubs->setObjectName("ACLApplySubs");
grid->addWidget(qcbACLApplyHere,0,0);
grid->addWidget(qcbACLApplySubs,1,0);
qgbACLapply->setLayout(grid);
grid = new QGridLayout();
qcbACLGroup=new QComboBox();
qcbACLGroup->setObjectName("ACLGroup");
l=new QLabel(tr("Group"));
l->setBuddy(qcbACLGroup);
grid->addWidget(qcbACLGroup,0,0);
grid->addWidget(l,0,1);
qleACLUser=new QLineEdit();
qleACLUser->setObjectName("ACLUser");
l=new QLabel(tr("User ID"));
l->setBuddy(qleACLUser);
grid->addWidget(qleACLUser,1,0);
grid->addWidget(l,1,1);
qgbACLugroup->setLayout(grid);
grid = new QGridLayout();
l=new QLabel(tr("Deny"));
grid->addWidget(l,0,1);
l=new QLabel(tr("Allow"));
grid->addWidget(l,0,2);
int perm=1;
int idx=1;
QString name;
while (! (name = ChanACL::permName(static_cast<ChanACL::Perm>(perm))).isEmpty()) {
QCheckBox *qcb;
l = new QLabel(name);
grid->addWidget(l,idx,0);
qcb=new QCheckBox();
connect(qcb, SIGNAL(clicked(bool)), this, SLOT(ACLPermissions_clicked()));
grid->addWidget(qcb,idx,1);
qlACLDeny << qcb;
qcb=new QCheckBox();
connect(qcb, SIGNAL(clicked(bool)), this, SLOT(ACLPermissions_clicked()));
grid->addWidget(qcb,idx,2);
qlACLAllow << qcb;
idx++;
perm = perm * 2;
}
qgbACLpermissions->setLayout(grid);
grid = new QGridLayout();
grid->addWidget(qgbACLs, 0, 0, 1, 2);
grid->addWidget(qgbACLapply, 1, 0);
grid->addWidget(qgbACLugroup, 2, 0);
grid->addWidget(qgbACLpermissions,1, 1, 2, 1);
aclEditor->setLayout(grid);
grid = new QGridLayout();
qcbGroupList=new QComboBox();
qcbGroupList->setObjectName("GroupList");
qcbGroupList->setEditable(true);
grid->addWidget(qcbGroupList,0,0);
qpbGroupRemove=new QPushButton(tr("Remove"));
qpbGroupRemove->setObjectName("GroupRemove");
grid->addWidget(qpbGroupRemove,0,1);
qcbGroupInherit=new QCheckBox(tr("Inherit"));
qcbGroupInherit->setObjectName("GroupInherit");
grid->addWidget(qcbGroupInherit,0,2);
qcbGroupInheritable=new QCheckBox(tr("Inheritable"));
qcbGroupInheritable->setObjectName("GroupInheritable");
grid->addWidget(qcbGroupInheritable,0,3);
qcbGroupInherited=new QCheckBox(tr("Inherited"));
qcbGroupInherited->setObjectName("GroupInherited");
qcbGroupInherited->setEnabled(false);
grid->addWidget(qcbGroupInherited,0,4);
qgbGroups->setLayout(grid);
grid = new QGridLayout();
qlwGroupAdd = new QListWidget();
qlwGroupAdd->setObjectName("ListGroupAdd");
qlwGroupRemove = new QListWidget();
qlwGroupRemove->setObjectName("ListGroupRemove");
qlwGroupInherit = new QListWidget();
qlwGroupInherit->setObjectName("ListGroupInherit");
l = new QLabel(tr("Add"));
grid->addWidget(l, 0, 0, 1, 2);
l = new QLabel(tr("Remove"));
grid->addWidget(l, 0, 2, 1, 2);
l = new QLabel(tr("Inherit"));
grid->addWidget(l, 0, 4, 1, 2);
grid->addWidget(qlwGroupAdd, 1, 0, 1, 2);
grid->addWidget(qlwGroupRemove, 1, 2, 1, 2);
grid->addWidget(qlwGroupInherit, 1, 4, 2, 2);
qleGroupAdd=new QLineEdit();
qleGroupAdd->setObjectName("GroupAddName");
qleGroupRemove=new QLineEdit();
qleGroupRemove->setObjectName("GroupRemoveName");
qpbGroupAddAdd=new QPushButton(tr("Add"));
qpbGroupAddAdd->setObjectName("GroupAddAdd");
qpbGroupAddRemove=new QPushButton(tr("Remove"));
qpbGroupAddRemove->setObjectName("GroupAddRemove");
qpbGroupRemoveAdd=new QPushButton(tr("Add"));
qpbGroupRemoveAdd->setObjectName("GroupRemoveAdd");
qpbGroupRemoveRemove=new QPushButton(tr("Remove"));
qpbGroupRemoveRemove->setObjectName("GroupRemoveRemove");
qpbGroupInheritRemove=new QPushButton(tr("Add to Remove"));
qpbGroupInheritRemove->setObjectName("GroupInheritRemove");
grid->addWidget(qleGroupAdd, 2, 0);
grid->addWidget(qpbGroupAddAdd, 2, 1);
grid->addWidget(qpbGroupAddRemove, 3, 0, 1, 2);
grid->addWidget(qleGroupRemove, 2, 2);
grid->addWidget(qpbGroupRemoveAdd, 2, 3);
grid->addWidget(qpbGroupRemoveRemove, 3, 2, 1, 2);
grid->addWidget(qpbGroupInheritRemove, 3, 4, 1, 2);
qgbGroupMembers->setLayout(grid);
grid = new QGridLayout();
grid->addWidget(qgbGroups, 0, 0);
grid->addWidget(qgbGroupMembers, 1, 0);
groupEditor->setLayout(grid);
qtwTab->addTab(groupEditor, tr("&Groups"));
qtwTab->addTab(aclEditor, tr("&ACL"));
QPushButton *okButton = new QPushButton(tr("&OK"));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
okButton->setToolTip(tr("Accept changes"));
okButton->setWhatsThis(tr("This button will accept current groups/ACLs and send them to "
"the server. Note that if you mistakenly remove write permission "
"from yourself, the server will add it."));
QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
cancelButton->setToolTip(tr("Reject changes"));
cancelButton->setWhatsThis(tr("This button will cancels all changes and closes the dialog without "
"updating the ACLs or groups on the server."));
QHBoxLayout *buttons = new QHBoxLayout;
buttons->addStretch(1);
buttons->addWidget(okButton);
buttons->addWidget(cancelButton);
QVBoxLayout *ml = new QVBoxLayout;
ml->addWidget(qtwTab);
ml->addStretch(1);
ml->addSpacing(12);
ml->addLayout(buttons);
setLayout(ml);
foreach (as, mea->acls) {
asp = new MessageEditACL::ACLStruct(as);
acls << asp;
}
foreach (gs, mea->groups) {
gsp = new MessageEditACL::GroupStruct(gs);
groups << gsp;
}
numInheritACL = 0;
bInheritACL = mea->bInheritACL;
qcbACLInherit->setChecked(bInheritACL);
foreach(asp, acls) {
if (asp->bInherited)
numInheritACL++;
if (asp->iPlayerId != -1)
addQuery(ACLList, asp->iPlayerId);
}
foreach(gsp, groups) {
int id;
foreach(id, gsp->qsAdd)
addQuery(GroupAdd, id);
foreach(id, gsp->qsRemove)
addQuery(GroupRemove, id);
foreach(id, gsp->qsInheritedMembers)
addQuery(GroupInherit, id);
}
refill(GroupAdd);
refill(GroupRemove);
refill(GroupInherit);
refill(ACLList);
doneQuery();
QMetaObject::connectSlotsByName(this);
refillGroupNames();
resize(minimumSize());
ACLEnableCheck();
groupEnableCheck();
addToolTipsWhatsThis();
}
ACLEditor::~ACLEditor() {
MessageEditACL::ACLStruct *asp;
MessageEditACL::GroupStruct *gsp;
foreach(asp, acls) {
delete asp;
}
foreach(gsp, groups) {
delete gsp;
}
}
void ACLEditor::addToolTipsWhatsThis() {
qlwACLs->setToolTip(tr("List of entries"));
qlwACLs->setWhatsThis(tr("This shows all the entries active on this channel. Entries inherited from parent channels will be "
"show in italics."));
qcbACLInherit->setToolTip(tr("Inherit ACL of parent?"));
qcbACLInherit->setWhatsThis(tr("This sets whether or not the ACL up the chain of parent channels are applied to this object. "
"Only those entries that are marked in the parent as \"Apply to Subchannels\" will be inherited."));
qpbACLAdd->setToolTip(tr("Add new entry"));
qpbACLAdd->setWhatsThis(tr("This adds a new entry, initially set with no permissions and applying to all."));
qpbACLRemove->setToolTip(tr("Remove entry"));
qpbACLRemove->setWhatsThis(tr("This removes the currently selected entry."));
qpbACLUp->setToolTip(tr("Move entry up"));
qpbACLUp->setWhatsThis(tr("This moves the entry up in the list. As entries are evaluated in order, this may change "
"the effective permissions of users. You cannot move an entry above an inherited entry, if you "
"really need that you'll have to duplicate the inherited entry."));
qpbACLDown->setToolTip(tr("Move entry down"));
qpbACLDown->setWhatsThis(tr("This moves the entry down in the list. As entries are evaluated in order, this may change "
"the effective permissions of users."));
qcbACLApplyHere->setToolTip(tr("Entry should apply to this channel"));
qcbACLApplyHere->setWhatsThis(tr("This makes the entry apply to this channel."));
qcbACLApplySubs->setToolTip(tr("Entry should apply to subchannels."));
qcbACLApplySubs->setWhatsThis(tr("This makes the entry apply to subchannels of this channel."));
qcbACLGroup->setToolTip(tr("Group this entry applies to"));
qcbACLGroup->setWhatsThis(tr("This control which group of users this entry applies to.<br />Note that the group is evaluated "
"in the context of the channel the entry is used in. For example, the default ACL on the Root "
"channel gives <i>Write</i> permission to the <i>admin</i> group. This entry, if inherited by a "
"channel, will give a user write priviliges if he belongs to the <i>admin</i> group in that channel, "
"even if he doesn't belong to the <i>admin</i> group in the channel where the ACL originated.<br />"
"A few special predefined groups are:<br />"
"<b>all</b> - Everyone will match.<br />"
"<b>auth</b> - All authenticated users will match.<br />"
"<b>in</b> - Users currently in the channel will match.<br />"
"<b>out</b> - Users outside the channel will match.<br />"
"Note that an entry applies to either a user or a group, not both."));
qleACLUser->setToolTip(tr("User this entry applies to"));
qleACLUser->setWhatsThis(tr("This controls which user this entry applies to. Just type in the user name and hit enter "
"to query the server for a match."));
int idx;
int p = 0x1;
for(idx=0;idx<qlACLAllow.count();idx++) {
ChanACL::Perm prm=static_cast<ChanACL::Perm>(p);
QString perm = ChanACL::permName(prm);
qlACLAllow[idx]->setToolTip(tr("Allow %1").arg(perm));
qlACLDeny[idx]->setToolTip(tr("Deny %1").arg(perm));
qlACLAllow[idx]->setWhatsThis(tr("This grants the %1 privilege. If a privilege is both allowed and denied, it is denied.<br />%2").arg(perm).arg(ChanACL::whatsThis(prm)));
qlACLDeny[idx]->setWhatsThis(tr("This revokes the %1 privilege. If a privilege is both allowed and denied, it is denied.<br />%2").arg(perm).arg(ChanACL::whatsThis(prm)));
p = p * 2;
}
qcbGroupList->setToolTip(tr("List of groups"));
qcbGroupList->setWhatsThis(tr("This is all the groups currently defined for the channel. To create a new group, just type in the "
"name and press enter."));
qpbGroupRemove->setToolTip(tr("Remove selected group"));
qpbGroupRemove->setWhatsThis(tr("This removes the currently selected group. If the group was inherited, it will not be removed "
"from the list, but all local information about the group will be cleared."));
qcbGroupInherit->setToolTip(tr("Inherit group members from parent"));
qcbGroupInherit->setWhatsThis(tr("This inherits all the members in the group from the parent, if the group is marked as "
"<i>Inheritable</i> in the parent channel."));
qcbGroupInheritable->setToolTip(tr("Make group inheritable to subchannels"));
qcbGroupInheritable->setWhatsThis(tr("This makes this group inheritable to subchannels. If the group is non-inheritable, "
"subchannels are still free to create a new group with the same name."));
qcbGroupInherited->setToolTip(tr("Group was inherited from parent channel"));
qcbGroupInherited->setWhatsThis(tr("This indicates that the group was inherited from the parent channel. You cannot edit "
"this flag, it's just for information."));
qleGroupAdd->setToolTip(tr("Add member to group"));
qleGroupAdd->setWhatsThis(tr("Type in the name of a player you wish to add to the group and press enter."));
qleGroupRemove->setToolTip(tr("Remove member from group"));
qleGroupRemove->setWhatsThis(tr("Type in the name of a player you wish to remove from the group and press enter."));
}
void ACLEditor::accept() {
MessageEditACL::ACLStruct as;
MessageEditACL::GroupStruct gs;
MessageEditACL::ACLStruct *asp;
MessageEditACL::GroupStruct *gsp;
MessageEditACL mea;
mea.iId = iId;
mea.bQuery = false;
mea.bInheritACL = bInheritACL;
foreach(asp, acls) {
as = *asp;
if (as.bInherited)
continue;
mea.acls << as;
}
foreach(gsp, groups) {
gs = *gsp;
if (gs.bInherited && gs.bInherit && gs.bInheritable && (gs.qsAdd.count() == 0) && (gs.qsRemove.count() == 0))
continue;
gs.qsInheritedMembers.clear();
mea.groups << gs;
}
g.sh->sendMessage(&mea);
QDialog::accept();
}
void ACLEditor::addQuery(WaitID me, int id) {
qhIDWait[id].insert(me);
}
void ACLEditor::addQuery(WaitID me, QString name) {
qhNameWait[name].insert(me);
}
void ACLEditor::doneQuery() {
MessageQueryUsers mqu;
cleanQuery();
foreach(int id, qhIDWait.keys()) {
mqu.qlIds << id;
mqu.qlNames << QString();
}
foreach(QString name, qhNameWait.keys()) {
mqu.qlIds << -1;
mqu.qlNames << name;
}
if (mqu.qlIds.count() > 0)
g.sh->sendMessage(&mqu);
}
void ACLEditor::cleanQuery() {
QSet<WaitID> notify;
foreach(int id, qhIDWait.keys()) {
if (qhNameCache.contains(id)) {
notify = notify.unite(qhIDWait.value(id));
qhIDWait.remove(id);
}
}
foreach(QString name, qhNameWait.keys()) {
if (qhIDCache.contains(name)) {
notify = notify.unite(qhNameWait.value(name));
qhNameWait.remove(name);
}
}
foreach(WaitID wid, notify) {
refill(wid);
}
}
void ACLEditor::returnQuery(const MessageQueryUsers *mqu) {
int i;
for(i=0;i<mqu->qlIds.count();i++) {
int id = mqu->qlIds[i];
QString name = mqu->qlNames[i];
qhIDCache[name] = id;
qhNameCache[id] = name;
}
cleanQuery();
}
void ACLEditor::refill(WaitID wid) {
switch (wid) {
case ACLList:
refillACL();
break;
case GroupInherit:
refillGroupInherit();
break;
case GroupRemove:
refillGroupRemove();
break;
case GroupAdd:
refillGroupAdd();
break;
}
}
QString ACLEditor::userName(int id) {
if (qhNameCache.contains(id))
return qhNameCache.value(id);
else
return QString("#%1").arg(id);
}
void ACLEditor::refillACL() {
MessageEditACL::ACLStruct *as;
foreach(as, qhACLNameWait.keys()) {
if (acls.indexOf(as) >= 0) {
QString name = qhACLNameWait.value(as);
if (qhIDCache.contains(name)) {
int id = qhIDCache.value(name);
if (id != -1) {
as->iPlayerId = id;
as->qsGroup = QString();
}
qhACLNameWait.remove(as);
}
}
}
int idx = qlwACLs->currentRow();
bool previnh = bInheritACL;
bInheritACL = qcbACLInherit->isChecked();
qlwACLs->clear();
foreach(as, acls) {
if (! bInheritACL && as->bInherited)
continue;
QString text;
if (as->iPlayerId == -1)
text=QString("@%1").arg(as->qsGroup);
else
text=userName(as->iPlayerId);
QListWidgetItem *item=new QListWidgetItem(text, qlwACLs);
if (as->bInherited) {
QFont f = item->font();
f.setItalic(true);
item->setFont(f);
}
}
if (bInheritACL && ! previnh)
idx += numInheritACL;
if (! bInheritACL && previnh)
idx -= numInheritACL;
qlwACLs->setCurrentRow(idx);
}
void ACLEditor::refillGroupNames() {
MessageEditACL::GroupStruct *gsp;
QString text = qcbGroupList->currentText().toLower();
QStringList qsl;
foreach(gsp, groups) {
qsl << gsp->qsName;
}
qsl.sort();
qcbGroupList->clear();
foreach(QString name, qsl)
qcbGroupList->addItem(name);
qcbGroupList->setCurrentIndex(qcbGroupList->findText(text, Qt::MatchExactly));
}
MessageEditACL::GroupStruct *ACLEditor::currentGroup() {
QString group = qcbGroupList->currentText().toLower();
MessageEditACL::GroupStruct *gs;
foreach(gs, groups) {
if (gs->qsName == group) {
return gs;
}
}
return NULL;
}
MessageEditACL::ACLStruct *ACLEditor::currentACL() {
int idx = qlwACLs->currentRow();
if (idx == -1)
return NULL;
if (! bInheritACL)
idx += numInheritACL;
return acls[idx];
}
void ACLEditor::refillGroupAdd() {
MessageEditACL::GroupStruct *gs;
foreach(gs, qhAddNameWait.keys()) {
if (groups.indexOf(gs) >= 0) {
QString name = qhAddNameWait.value(gs);
if (qhIDCache.contains(name)) {
int id = qhIDCache.value(name);
if (id != -1) {
gs->qsAdd.insert(id);
}
qhAddNameWait.remove(gs);
}
}
}
gs = currentGroup();
if (! gs)
return;
QStringList qsl;
foreach(int id, gs->qsAdd) {
qsl << userName(id);
}
qsl.sort();
qlwGroupAdd->clear();
foreach(QString name, qsl) {
qlwGroupAdd->addItem(name);
}
}
void ACLEditor::refillGroupRemove() {
MessageEditACL::GroupStruct *gs;
foreach(gs, qhRemoveNameWait.keys()) {
if (groups.indexOf(gs) >= 0) {
QString name = qhRemoveNameWait.value(gs);
if (qhIDCache.contains(name)) {
int id = qhIDCache.value(name);
if (id != -1) {
gs->qsRemove.insert(id);
}
qhRemoveNameWait.remove(gs);
}
}
}
gs = currentGroup();
if (! gs)
return;
QStringList qsl;
foreach(int id, gs->qsRemove) {
qsl << userName(id);
}
qsl.sort();
qlwGroupRemove->clear();
foreach(QString name, qsl) {
qlwGroupRemove->addItem(name);
}
}
void ACLEditor::refillGroupInherit() {
MessageEditACL::GroupStruct *gs = currentGroup();
if (! gs)
return;
QStringList qsl;
foreach(int id, gs->qsInheritedMembers) {
qsl << userName(id);
}
qsl.sort();
qlwGroupInherit->clear();
foreach(QString name, qsl) {
qlwGroupInherit->addItem(name);
}
}
void ACLEditor::groupEnableCheck() {
MessageEditACL::GroupStruct *gs = currentGroup();
bool ena = true;
if (! gs)
ena = false;
else
ena = gs->bInherit;
qlwGroupRemove->setEnabled(ena);
qlwGroupInherit->setEnabled(ena);
qleGroupRemove->setEnabled(ena);
qpbGroupRemoveAdd->setEnabled(ena);
qpbGroupRemoveRemove->setEnabled(ena);
qpbGroupInheritRemove->setEnabled(ena);
ena = (gs != NULL);
qlwGroupAdd->setEnabled(ena);
qpbGroupAddAdd->setEnabled(ena);
qpbGroupAddRemove->setEnabled(ena);
qcbGroupInherit->setEnabled(ena);
qcbGroupInheritable->setEnabled(ena);
if (gs) {
qcbGroupInherit->setChecked(gs->bInherit);
qcbGroupInheritable->setChecked(gs->bInheritable);
qcbGroupInherited->setChecked(gs->bInherited);
}
}
void ACLEditor::ACLEnableCheck() {
MessageEditACL::ACLStruct *as = currentACL();
MessageEditACL::GroupStruct *gs;;
bool ena = true;
if (! as)
ena = false;
else
ena = ! as->bInherited;
qpbACLRemove->setEnabled(ena);
qpbACLUp->setEnabled(ena);
qpbACLDown->setEnabled(ena);
qcbACLApplyHere->setEnabled(ena);
qcbACLApplySubs->setEnabled(ena);
qcbACLGroup->setEnabled(ena);
qleACLUser->setEnabled(ena);
int idx;
for(idx=0;idx<qlACLAllow.count();idx++) {
qlACLAllow[idx]->setEnabled(ena);
qlACLDeny[idx]->setEnabled(ena);
}
if (as) {
qcbACLApplyHere->setChecked(as->bApplyHere);
qcbACLApplySubs->setChecked(as->bApplyHere);
int p = 0x1;
for(idx=0;idx<qlACLAllow.count();idx++) {
qlACLAllow[idx]->setChecked(static_cast<int>(as->pAllow) & p);
qlACLDeny[idx]->setChecked(static_cast<int>(as->pDeny) & p);
p = p * 2;
}
qcbACLGroup->clear();
qcbACLGroup->addItem(QString());
qcbACLGroup->addItem("all");
qcbACLGroup->addItem("auth");
qcbACLGroup->addItem("in");
qcbACLGroup->addItem("out");
foreach(gs, groups)
qcbACLGroup->addItem(gs->qsName);
if (as->iPlayerId == -1) {
qleACLUser->setText(QString());
qcbACLGroup->setCurrentIndex(qcbACLGroup->findText(as->qsGroup, Qt::MatchExactly));
} else {
qleACLUser->setText(userName(as->iPlayerId));
}
}
}
void ACLEditor::on_ACLList_currentRowChanged() {
ACLEnableCheck();
}
void ACLEditor::on_ACLAdd_clicked() {
MessageEditACL::ACLStruct *as = new MessageEditACL::ACLStruct;
as->bApplyHere = true;
as->bApplySubs = true;
as->bInherited = false;
as->qsGroup = "all";
as->iPlayerId = -1;
as->pAllow = ChanACL::None;
as->pDeny = ChanACL::None;
acls << as;
refillACL();
qlwACLs->setCurrentRow(qlwACLs->count() - 1);
}
void ACLEditor::on_ACLRemove_clicked() {
MessageEditACL::ACLStruct *as = currentACL();
if (! as || as->bInherited)
return;
acls.removeAll(as);
delete as;
refillACL();
}
void ACLEditor::on_ACLUp_clicked() {
MessageEditACL::ACLStruct *as = currentACL();
if (! as || as->bInherited)
return;
int idx = acls.indexOf(as);
if (idx <= numInheritACL)
return;
acls.swap(idx - 1, idx);
qlwACLs->setCurrentRow(qlwACLs->currentRow() - 1);
refillACL();
}
void ACLEditor::on_ACLDown_clicked() {
MessageEditACL::ACLStruct *as = currentACL();
if (! as || as->bInherited)
return;
int idx = acls.indexOf(as) + 1;
if (idx >= acls.count())
return;
acls.swap(idx - 1, idx);
qlwACLs->setCurrentRow(qlwACLs->currentRow() + 1);
refillACL();
}
void ACLEditor::on_ACLInherit_clicked(bool checked) {
refillACL();
}
void ACLEditor::on_ACLApplyHere_clicked(bool checked) {
MessageEditACL::ACLStruct *as = currentACL();
if (! as || as->bInherited)
return;
as->bApplyHere = checked;
}
void ACLEditor::on_ACLApplySubs_clicked(bool checked) {
MessageEditACL::ACLStruct *as = currentACL();
if (! as || as->bInherited)
return;
as->bApplySubs = checked;
}
void ACLEditor::on_ACLGroup_activated(const QString &text) {
MessageEditACL::ACLStruct *as = currentACL();
if (! as || as->bInherited)
return;
as->iPlayerId = -1;
if (text.isEmpty()) {
qcbACLGroup->setCurrentIndex(1);
as->qsGroup="all";
} else {
qleACLUser->setText(QString());
as->qsGroup=text;
}
refillACL();
}
void ACLEditor::on_ACLUser_editingFinished() {
QString text = qleACLUser->text();
MessageEditACL::ACLStruct *as = currentACL();
if (! as || as->bInherited)
return;
if (text.isEmpty()) {
as->iPlayerId = -1;
if (qcbACLGroup->currentIndex() == 0) {
qcbACLGroup->setCurrentIndex(1);
as->qsGroup="all";
}
refillACL();
} else {
qcbACLGroup->setCurrentIndex(0);
qhACLNameWait[as] = text;
addQuery(ACLList, text);
doneQuery();
}
}
void ACLEditor::ACLPermissions_clicked() {
MessageEditACL::ACLStruct *as = currentACL();
if (! as || as->bInherited)
return;
int a, d, p, idx;
a = 0;
d = 0;
p = 0x1;
for(idx=0;idx<qlACLAllow.count();idx++) {
if (qlACLAllow[idx]->isChecked())
a |= p;
if (qlACLDeny[idx]->isChecked())
d |= p;
p = p * 2;
}
as->pAllow=static_cast<ChanACL::Permissions>(a);
as->pDeny=static_cast<ChanACL::Permissions>(d);
}
void ACLEditor::on_GroupList_activated(const QString &text) {
MessageEditACL::GroupStruct *gs = currentGroup();
if (text.isEmpty())
return;
if (! gs) {
QString name = text.toLower();
gs = new MessageEditACL::GroupStruct;
gs->bInherited = false;
gs->bInherit = true;
gs->bInheritable = true;
gs->qsName = name;
groups << gs;
}
refillGroupNames();
refillGroupAdd();
refillGroupRemove();
refillGroupInherit();
groupEnableCheck();
}
void ACLEditor::on_GroupRemove_clicked() {
MessageEditACL::GroupStruct *gs = currentGroup();
if (! gs)
return;
if (gs->bInherited) {
gs->bInheritable = true;
gs->bInherit = true;
gs->qsAdd.clear();
gs->qsRemove.clear();
} else {
groups.removeAll(gs);
delete gs;
}
refillGroupNames();
refillGroupAdd();
refillGroupRemove();
refillGroupInherit();
groupEnableCheck();
}
void ACLEditor::on_GroupInherit_clicked(bool checked) {
MessageEditACL::GroupStruct *gs = currentGroup();
if (! gs)
return;
gs->bInherit = checked;
groupEnableCheck();
}
void ACLEditor::on_GroupInheritable_clicked(bool checked) {
MessageEditACL::GroupStruct *gs = currentGroup();
if (! gs)
return;
gs->bInheritable = checked;
}
void ACLEditor::on_GroupAddName_editingFinished() {
QString text = qleGroupAdd->text();
MessageEditACL::GroupStruct *gs = currentGroup();
if (! gs)
return;
if (text.isEmpty())
return;
qhAddNameWait[gs] = text;
addQuery(GroupAdd, text);
doneQuery();
}
void ACLEditor::on_GroupAddAdd_clicked() {
on_GroupAddName_editingFinished();
}
void ACLEditor::on_GroupAddRemove_clicked() {
MessageEditACL::GroupStruct *gs = currentGroup();
if (! gs)
return;
QListWidgetItem *item= qlwGroupAdd->currentItem();
if (! item)
return;
int id = qhIDCache.value(item->text());
gs->qsAdd.remove(id);
refillGroupAdd();
}
void ACLEditor::on_GroupRemoveName_editingFinished() {
QString text = qleGroupRemove->text();
MessageEditACL::GroupStruct *gs = currentGroup();
if (! gs)
return;
if (text.isEmpty())
return;
qhRemoveNameWait[gs] = text;
addQuery(GroupRemove, text);
doneQuery();
}
void ACLEditor::on_GroupRemoveAdd_clicked() {
on_GroupRemoveName_editingFinished();
}
void ACLEditor::on_GroupRemoveRemove_clicked() {
MessageEditACL::GroupStruct *gs = currentGroup();