diff options
author | Benjamin Jemlich <pcgod@users.sourceforge.net> | 2011-01-22 06:52:04 +0300 |
---|---|---|
committer | Benjamin Jemlich <pcgod@users.sourceforge.net> | 2011-01-22 07:11:42 +0300 |
commit | 95d13a5f77909636ab596d1837135c84e18a3919 (patch) | |
tree | 6108095b568f87afe4e2ea44d063d1cfb49097d2 /src/mumble/ACLEditor.cpp | |
parent | 426c41101ebce329931f185d76263aead1a469c0 (diff) |
Style fixes in ACLEditor.cpp
Removed some useless casts to int and changed some variable
names to their unabbreviated form.
Diffstat (limited to 'src/mumble/ACLEditor.cpp')
-rw-r--r-- | src/mumble/ACLEditor.cpp | 182 |
1 files changed, 95 insertions, 87 deletions
diff --git a/src/mumble/ACLEditor.cpp b/src/mumble/ACLEditor.cpp index 2dc79adbc..1e9663883 100644 --- a/src/mumble/ACLEditor.cpp +++ b/src/mumble/ACLEditor.cpp @@ -88,7 +88,8 @@ ACLEditor::ACLEditor(int channelid, const MumbleProto::ACL &mea, QWidget *p) : Q setWindowTitle(tr("Mumble - Edit %1").arg(Channel::get(iId)->qsName)); qleChannelName->setText(pChannel->qsName); - if (channelid == 0) qleChannelName->setEnabled(false); + if (channelid == 0) + qleChannelName->setEnabled(false); rteChannelDescription->setText(pChannel->qsDesc); @@ -97,34 +98,33 @@ ACLEditor::ACLEditor(int channelid, const MumbleProto::ACL &mea, QWidget *p) : Q QGridLayout *grid = new QGridLayout(qgbACLpermissions); - l=new QLabel(tr("Deny"), qgbACLpermissions); - grid->addWidget(l,0,1); - l=new QLabel(tr("Allow"), qgbACLpermissions); - grid->addWidget(l,0,2); + l = new QLabel(tr("Deny"), qgbACLpermissions); + grid->addWidget(l, 0, 1); + l = new QLabel(tr("Allow"), qgbACLpermissions); + grid->addWidget(l, 0, 2); - int idx=1; - for (int i=0;i< ((iId == 0) ? 30 : 16);++i) { + int idx = 1; + for (int i = 0; i < ((iId == 0) ? 30 : 16); ++i) { ChanACL::Perm perm = static_cast<ChanACL::Perm>(1 << i); QString name = ChanACL::permName(perm); if (! name.isEmpty()) { QCheckBox *qcb; l = new QLabel(name, qgbACLpermissions); - grid->addWidget(l,idx,0); - qcb=new QCheckBox(qgbACLpermissions); + grid->addWidget(l, idx, 0); + qcb = new QCheckBox(qgbACLpermissions); qcb->setToolTip(tr("Deny %1").arg(name)); qcb->setWhatsThis(tr("This revokes the %1 privilege. If a privilege is both allowed and denied, it is denied.<br />%2").arg(name).arg(ChanACL::whatsThis(perm))); connect(qcb, SIGNAL(clicked(bool)), this, SLOT(ACLPermissions_clicked())); - grid->addWidget(qcb,idx,1); + grid->addWidget(qcb, idx, 1); qlACLDeny << qcb; - - qcb=new QCheckBox(qgbACLpermissions); + qcb = new QCheckBox(qgbACLpermissions); qcb->setToolTip(tr("Allow %1").arg(name)); qcb->setWhatsThis(tr("This grants the %1 privilege. If a privilege is both allowed and denied, it is denied.<br />%2").arg(name).arg(ChanACL::whatsThis(perm))); connect(qcb, SIGNAL(clicked(bool)), this, SLOT(ACLPermissions_clicked())); - grid->addWidget(qcb,idx,2); + grid->addWidget(qcb, idx, 2); qlACLAllow << qcb; @@ -133,7 +133,7 @@ ACLEditor::ACLEditor(int channelid, const MumbleProto::ACL &mea, QWidget *p) : Q ++idx; } } - QSpacerItem *si = new QSpacerItem(0,0, QSizePolicy::Minimum, QSizePolicy::Expanding); + QSpacerItem *si = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); grid->addItem(si, idx, 0); connect(qcbGroupAdd->lineEdit(), SIGNAL(returnPressed()), qpbGroupAddAdd, SLOT(animateClick())); @@ -158,7 +158,7 @@ ACLEditor::ACLEditor(int channelid, const MumbleProto::ACL &mea, QWidget *p) : Q qlACLs << def; - for (int i=0;i<mea.acls_size();++i) { + for (int i = 0; i < mea.acls_size(); ++i) { const MumbleProto::ACL_ChanACL &as = mea.acls(i); ChanACL *acl = new ChanACL(NULL); @@ -176,18 +176,18 @@ ACLEditor::ACLEditor(int channelid, const MumbleProto::ACL &mea, QWidget *p) : Q qlACLs << acl; } - for (int i=0;i<mea.groups_size();++i) { + for (int i = 0; i < mea.groups_size(); ++i) { const MumbleProto::ACL_ChanGroup &gs = mea.groups(i); ACLGroup *gp = new ACLGroup(u8(gs.name())); gp->bInherit = gs.inherit(); gp->bInherited = gs.inherited(); gp->bInheritable = gs.inheritable(); - for (int j=0;j<gs.add_size();++j) + for (int j = 0; j < gs.add_size(); ++j) gp->qsAdd.insert(gs.add(j)); - for (int j=0;j<gs.remove_size();++j) + for (int j = 0; j < gs.remove_size(); ++j) gp->qsRemove.insert(gs.remove(j)); - for (int j=0;j<gs.inherited_members_size();++j) + for (int j = 0; j < gs.inherited_members_size(); ++j) gp->qsTemporary.insert(gs.inherited_members(j)); qlGroups << gp; @@ -317,9 +317,9 @@ const QString ACLEditor::userName(int pid) { int ACLEditor::id(const QString &uname) { QString name = uname.toLower(); - if (qhIDCache.contains(name)) + if (qhIDCache.contains(name)) { return qhIDCache.value(name); - else { + } else { if (! qhNameWait.contains(name)) { MumbleProto::QueryUsers mpuq; mpuq.add_names(u8(name)); @@ -337,7 +337,7 @@ void ACLEditor::returnQuery(const MumbleProto::QueryUsers &mqu) { if (mqu.names_size() != mqu.ids_size()) return; - for (int i=0;i < mqu.names_size(); ++i) { + for (int i = 0; i < mqu.names_size(); ++i) { int pid = mqu.ids(i); QString name = u8(mqu.names(i)); QString lname = name.toLower(); @@ -401,7 +401,7 @@ void ACLEditor::refillComboBoxes() { void ACLEditor::refillACL() { int idx = qlwACLs->currentRow(); - bool previnh = bInheritACL; + bool previousinherit = bInheritACL; bInheritACL = qcbACLInherit->isChecked(); qlwACLs->clear(); @@ -415,19 +415,19 @@ void ACLEditor::refillACL() { continue; QString text; if (acl->iUserId == -1) - text=QString::fromLatin1("@%1").arg(acl->qsGroup); + text = QString::fromLatin1("@%1").arg(acl->qsGroup); else - text=userName(acl->iUserId); - QListWidgetItem *item=new QListWidgetItem(text, qlwACLs); + text = userName(acl->iUserId); + QListWidgetItem *item = new QListWidgetItem(text, qlwACLs); if (acl->bInherited) { QFont f = item->font(); f.setItalic(true); item->setFont(f); } } - if (bInheritACL && ! previnh && (idx != 0)) + if (bInheritACL && ! previousinherit && (idx != 0)) idx += numInheritACL; - if (! bInheritACL && previnh) + if (! bInheritACL && previousinherit) idx -= numInheritACL; qlwACLs->setCurrentRow(idx); @@ -526,27 +526,26 @@ void ACLEditor::refillGroupInherit() { void ACLEditor::groupEnableCheck() { ACLGroup *gp = currentGroup(); - bool ena = true; - + bool enabled; if (! gp) - ena = false; + enabled = false; else - ena = gp->bInherit; - - qlwGroupRemove->setEnabled(ena); - qlwGroupInherit->setEnabled(ena); - qcbGroupRemove->setEnabled(ena); - qpbGroupRemoveAdd->setEnabled(ena); - qpbGroupRemoveRemove->setEnabled(ena); - qpbGroupInheritRemove->setEnabled(ena); - - ena = (gp != NULL); - qlwGroupAdd->setEnabled(ena); - qcbGroupAdd->setEnabled(ena); - qpbGroupAddAdd->setEnabled(ena); - qpbGroupAddRemove->setEnabled(ena); - qcbGroupInherit->setEnabled(ena); - qcbGroupInheritable->setEnabled(ena); + enabled = gp->bInherit; + + qlwGroupRemove->setEnabled(enabled); + qlwGroupInherit->setEnabled(enabled); + qcbGroupRemove->setEnabled(enabled); + qpbGroupRemoveAdd->setEnabled(enabled); + qpbGroupRemoveRemove->setEnabled(enabled); + qpbGroupInheritRemove->setEnabled(enabled); + + enabled = (gp != NULL); + qlwGroupAdd->setEnabled(enabled); + qcbGroupAdd->setEnabled(enabled); + qpbGroupAddAdd->setEnabled(enabled); + qpbGroupAddRemove->setEnabled(enabled); + qcbGroupInherit->setEnabled(enabled); + qcbGroupInheritable->setEnabled(enabled); if (gp) { qcbGroupInherit->setChecked(gp->bInherit); @@ -558,36 +557,37 @@ void ACLEditor::groupEnableCheck() { void ACLEditor::ACLEnableCheck() { ChanACL *as = currentACL(); - bool ena = true; + bool enabled; if (! as) - ena = false; + enabled = false; else - ena = ! as->bInherited; - - qpbACLRemove->setEnabled(ena); - qpbACLUp->setEnabled(ena); - qpbACLDown->setEnabled(ena); - qcbACLApplyHere->setEnabled(ena); - qcbACLApplySubs->setEnabled(ena); - qcbACLGroup->setEnabled(ena); - qcbACLUser->setEnabled(ena); - - int idx; - for (idx=0;idx<qlACLAllow.count();idx++) { + enabled = ! as->bInherited; + + qpbACLRemove->setEnabled(enabled); + qpbACLUp->setEnabled(enabled); + qpbACLDown->setEnabled(enabled); + qcbACLApplyHere->setEnabled(enabled); + qcbACLApplySubs->setEnabled(enabled); + qcbACLGroup->setEnabled(enabled); + qcbACLUser->setEnabled(enabled); + + for (int idx = 0; idx < qlACLAllow.count(); idx++) { // Only enable other checkboxes if writeacl isn't set - bool enathis = ena && (qlPerms[idx] == ChanACL::Write || !(as && static_cast<int>(as->pAllow) & ChanACL::Write) || qlPerms[idx] == ChanACL::Speak); - qlACLAllow[idx]->setEnabled(enathis); - qlACLDeny[idx]->setEnabled(enathis); + bool enablethis = enabled && (qlPerms[idx] == ChanACL::Write || !(as && (as->pAllow & ChanACL::Write)) || qlPerms[idx] == ChanACL::Speak); + qlACLAllow[idx]->setEnabled(enablethis); + qlACLDeny[idx]->setEnabled(enablethis); } if (as) { qcbACLApplyHere->setChecked(as->bApplyHere); qcbACLApplySubs->setChecked(as->bApplySubs); - for (idx=0;idx<qlACLAllow.count();idx++) { + + for (int idx = 0; idx < qlACLAllow.count(); idx++) { ChanACL::Perm p = qlPerms[idx]; - qlACLAllow[idx]->setChecked(static_cast<int>(as->pAllow) & p); - qlACLDeny[idx]->setChecked(static_cast<int>(as->pDeny) & p); + qlACLAllow[idx]->setChecked(as->pAllow & p); + qlACLDeny[idx]->setChecked(as->pDeny & p); } + qcbACLGroup->clear(); qcbACLGroup->addItem(QString()); qcbACLGroup->addItem(QLatin1String("all")); @@ -598,8 +598,10 @@ void ACLEditor::ACLEnableCheck() { qcbACLGroup->addItem(QLatin1String("~in")); qcbACLGroup->addItem(QLatin1String("~sub")); qcbACLGroup->addItem(QLatin1String("~out")); + foreach(ACLGroup *gs, qlGroups) qcbACLGroup->addItem(gs->qsName); + if (as->iUserId == -1) { qcbACLUser->clearEditText(); qcbACLGroup->addItem(as->qsGroup); @@ -618,9 +620,10 @@ void ACLEditor::ACLEnableCheck() { } void ACLEditor::on_qtwTab_currentChanged(int index) { - if (index == 0) // Switched to property tab, update password field + if (index == 0) { + // Switched to property tab, update password field updatePasswordField(); - else if (index == 2) { + } else if (index == 2) { // Switched to ACL tab, update ACL list updatePasswordACL(); refillACL(); @@ -720,6 +723,7 @@ void ACLEditor::on_qpbACLRemove_clicked() { ChanACL *as = currentACL(); if (! as || as->bInherited) return; + qlACLs.removeAll(as); delete as; refillACL(); @@ -733,6 +737,7 @@ void ACLEditor::on_qpbACLUp_clicked() { int idx = qlACLs.indexOf(as); if (idx <= numInheritACL + 1) return; + qlACLs.swap(idx - 1, idx); qlwACLs->setCurrentRow(qlwACLs->currentRow() - 1); refillACL(); @@ -746,6 +751,7 @@ void ACLEditor::on_qpbACLDown_clicked() { int idx = qlACLs.indexOf(as) + 1; if (idx >= qlACLs.count()) return; + qlACLs.swap(idx - 1, idx); qlwACLs->setCurrentRow(qlwACLs->currentRow() + 1); refillACL(); @@ -780,10 +786,10 @@ void ACLEditor::on_qcbACLGroup_activated(const QString &text) { if (text.isEmpty()) { qcbACLGroup->setCurrentIndex(1); - as->qsGroup=QLatin1String("all"); + as->qsGroup = QLatin1String("all"); } else { qcbACLUser->clearEditText(); - as->qsGroup=text; + as->qsGroup = text; } refillACL(); } @@ -799,7 +805,7 @@ void ACLEditor::on_qcbACLUser_activated() { as->iUserId = -1; if (qcbACLGroup->currentIndex() == 0) { qcbACLGroup->setCurrentIndex(1); - as->qsGroup=QLatin1String("all"); + as->qsGroup = QLatin1String("all"); } refillACL(); } else { @@ -816,12 +822,11 @@ void ACLEditor::ACLPermissions_clicked() { if (! as || as->bInherited) return; - int a, d, idx; - a = 0; - d = 0; + int allowed = 0; + int denied = 0; - bool ena = true; - for (idx=0;idx<qlACLAllow.count();idx++) { + bool enabled = true; + for (int idx = 0; idx < qlACLAllow.count(); idx++) { ChanACL::Perm p = qlPerms[idx]; if (qlACLAllow[idx]->isChecked() && qlACLDeny[idx]->isChecked()) { if (source == qlACLAllow[idx]) @@ -830,20 +835,20 @@ void ACLEditor::ACLPermissions_clicked() { qlACLAllow[idx]->setChecked(false); } - qlACLAllow[idx]->setEnabled(ena || p == ChanACL::Speak); - qlACLDeny[idx]->setEnabled(ena || p == ChanACL::Speak); + qlACLAllow[idx]->setEnabled(enabled || p == ChanACL::Speak); + qlACLDeny[idx]->setEnabled(enabled || p == ChanACL::Speak); if (p == ChanACL::Write && qlACLAllow[idx]->isChecked()) - ena = false; + enabled = false; if (qlACLAllow[idx]->isChecked()) - a |= p; + allowed |= p; if (qlACLDeny[idx]->isChecked()) - d |= p; + denied |= p; } - as->pAllow=static_cast<ChanACL::Permissions>(a); - as->pDeny=static_cast<ChanACL::Permissions>(d); + as->pAllow = static_cast<ChanACL::Permissions>(allowed); + as->pDeny = static_cast<ChanACL::Permissions>(denied); } void ACLEditor::on_qcbGroupList_activated(const QString &text) { @@ -880,6 +885,7 @@ void ACLEditor::on_qpbGroupRemove_clicked() { ACLGroup *gs = currentGroup(); if (! gs) return; + if (gs->bInherited) { gs->bInheritable = true; gs->bInherit = true; @@ -900,6 +906,7 @@ void ACLEditor::on_qcbGroupInherit_clicked(bool checked) { ACLGroup *gs = currentGroup(); if (! gs) return; + gs->bInherit = checked; groupEnableCheck(); } @@ -908,6 +915,7 @@ void ACLEditor::on_qcbGroupInheritable_clicked(bool checked) { ACLGroup *gs = currentGroup(); if (! gs) return; + gs->bInheritable = checked; } @@ -931,7 +939,7 @@ void ACLEditor::on_qpbGroupAddRemove_clicked() { if (! gs) return; - QListWidgetItem *item= qlwGroupAdd->currentItem(); + QListWidgetItem *item = qlwGroupAdd->currentItem(); if (! item) return; @@ -959,7 +967,7 @@ void ACLEditor::on_qpbGroupRemoveRemove_clicked() { if (! gs) return; - QListWidgetItem *item= qlwGroupRemove->currentItem(); + QListWidgetItem *item = qlwGroupRemove->currentItem(); if (! item) return; @@ -972,7 +980,7 @@ void ACLEditor::on_qpbGroupInheritRemove_clicked() { if (! gs) return; - QListWidgetItem *item= qlwGroupInherit->currentItem(); + QListWidgetItem *item = qlwGroupInherit->currentItem(); if (! item) return; |