inline bool KviModeWidget::modeNeedsParameterOnlyWhenSet(char cMode) { KviIrcConnectionServerInfo * pServerInfo = 0; if(m_pChannel) pServerInfo = m_pChannel->serverInfo(); if(pServerInfo) return pServerInfo->supportedParameterWhenSetModes().contains(cMode); return false; }
KviModeEditor::KviModeEditor(QWidget * par, KviWindowToolPageButton * button, const char * name, KviChannelWindow * pChan) : KviWindowToolWidget(par, button) { setObjectName(name); m_pChannel = pChan; QGridLayout * pMasterLayout = new QGridLayout(this); setFocusPolicy(Qt::ClickFocus); QScrollArea * pScrollArea = new QScrollArea(this); pScrollArea->viewport()->setBackgroundRole(QPalette::Background); pMasterLayout->addWidget(pScrollArea, 0, 0); pMasterLayout->setRowStretch(1, 1); m_pButton = new QPushButton("", this); pMasterLayout->addWidget(m_pButton, 1, 0); connect(m_pButton, SIGNAL(clicked()), this, SLOT(commit())); if(!m_pChannel || !m_pChannel->connection()) m_pButton->setText(__tr2qs("Close")); QWidget * pBackground = new QWidget(pScrollArea->viewport()); QGridLayout * g = new QGridLayout(pBackground); QLabel * l = new QLabel("", pBackground); l->setPixmap(*(g_pIconManager->getSmallIcon(KviIconManager::Mode))); g->addWidget(l, 0, 0); l = new QLabel(__tr2qs("Channel modes"), pBackground); g->addWidget(l, 0, 1, 1, 1); QFrame * f = new QFrame(pBackground); f->setFrameStyle(QFrame::HLine | QFrame::Sunken); g->addWidget(f, 1, 0, 1, 3); QCheckBox * pCheckBox = nullptr; QLineEdit * pLineEdit = nullptr; int iRow = 1; QString szTmp; QString cDesc; char cMode = 0; //NOTE: this is a fallback is for some reason we don't have a serverInfo() struct available fot this connection // The connection is dead and the context was destroyed, don't guess on what was there if(!m_pChannel || !m_pChannel->connection()) return; // first, the basic checkable modes pstnmi QString szModes = "pstnmi"; while(!szModes.isEmpty()) { cMode = szModes[0].unicode(); szModes.remove(0, 1); szTmp = QString("%1: %2").arg(cMode).arg(*(getModeDescription(cMode))); pCheckBox = new QCheckBox(szTmp, pBackground); m_pCheckBoxes.insert(cMode, pCheckBox); if(pChan) pCheckBox->setChecked(pChan->plainChannelMode().contains(cMode)); iRow++; g->addWidget(pCheckBox, iRow, 0, 1, 3); } // second, che basic modes with parameter lk szModes = "lk"; while(!szModes.isEmpty()) { cMode = szModes[0].unicode(); szModes.remove(0, 1); szTmp = QString("%1: %2").arg(cMode).arg(*(getModeDescription(cMode))); pCheckBox = new QCheckBox(szTmp, pBackground); m_pCheckBoxes.insert(cMode, pCheckBox); iRow++; g->addWidget(pCheckBox, iRow, 0, 1, 3); connect(pCheckBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled(bool))); pLineEdit = new QLineEdit(pBackground); m_pLineEdits.insert(cMode, pLineEdit); iRow++; g->addWidget(pLineEdit, iRow, 1, 1, 2); if(pChan) { if(pChan->hasChannelMode(cMode)) { pCheckBox->setChecked(true); pLineEdit->setText(pChan->channelModeParam(cMode)); } else { pLineEdit->setEnabled(false); } } } // third, check if the we have any info about other modes supported by the server KviIrcConnectionServerInfo * pServerInfo = nullptr; if(m_pChannel) pServerInfo = m_pChannel->serverInfo(); if(!pServerInfo) { g->setRowStretch(++iRow, 1); g->setColumnStretch(2, 1); pScrollArea->setWidget(pBackground); return; } // 4th, more plain modes supported by the server szModes = pServerInfo->supportedPlainModes(); // remove modes that we already implemented szModes.remove("p"); szModes.remove("s"); szModes.remove("t"); szModes.remove("n"); szModes.remove("m"); szModes.remove("i"); while(!szModes.isEmpty()) { cMode = szModes[0].unicode(); szModes.remove(0, 1); cDesc = *(getModeDescription(cMode)); szTmp = QString("%1: %2").arg(cMode).arg(!cDesc.isEmpty() ? cDesc : "Unknown"); pCheckBox = new QCheckBox(szTmp, pBackground); m_pCheckBoxes.insert(cMode, pCheckBox); if(pChan) pCheckBox->setChecked(pChan->plainChannelMode().contains(cMode)); iRow++; g->addWidget(pCheckBox, iRow, 0, 1, 3); } iRow++; // parameterized modes szModes = pServerInfo->supportedParameterModes(); szModes.append(pServerInfo->supportedParameterWhenSetModes()); // remove modes that we already implemented szModes.remove("k"); szModes.remove("l"); while(!szModes.isEmpty()) { cMode = szModes[0].unicode(); szModes.remove(0, 1); cDesc = *(getModeDescription(cMode)); szTmp = QString("%1: %2").arg(cMode).arg(!cDesc.isEmpty() ? cDesc : "Unknown"); pCheckBox = new QCheckBox(szTmp, pBackground); m_pCheckBoxes.insert(cMode, pCheckBox); iRow++; g->addWidget(pCheckBox, iRow, 0, 1, 3); connect(pCheckBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled(bool))); pLineEdit = new QLineEdit(pBackground); m_pLineEdits.insert(cMode, pLineEdit); iRow++; g->addWidget(pLineEdit, iRow, 1, 1, 2); if(pChan->hasChannelMode(cMode)) { pCheckBox->setChecked(true); pLineEdit->setText(pChan->channelModeParam(cMode)); } else { pLineEdit->setEnabled(false); } } g->setRowStretch(++iRow, 1); g->setColumnStretch(2, 1); pScrollArea->setWidget(pBackground); updateOpStatus(); if(m_pChannel) connect(m_pChannel, SIGNAL(opStatusChanged()), this, SLOT(updateOpStatus())); }