예제 #1
0
void KviIrcConnectionRequestQueue::timerSlot()
{
	if(m_channels.isEmpty())
	{
		m_timer.stop();
	} else {
		KviChannelWindow * pChan = m_channels.head();
		QByteArray encodedChan = pChan->connection()->encodeText(pChan->target()).data();
		/* The following switch will let the execution flow pass-through if any request type
		 * is currently disabled (or not available on the server). Channel's "MODE" request is
		 * the only mandatory request.
		 */
		switch(m_curType)
		{
			case BanException:
				if(pChan->serverInfo()->supportedListModes().contains('e') &&
					!KVI_OPTION_BOOL(KviOption_boolDisableBanExceptionListRequestOnJoin) &&
					!(	pChan->serverInfo()->getNeedsOpToListModeseI() &&
						!pChan->isMeOp()
					 )
				)
				{
					if(!pChan->connection()->sendFmtData("MODE %s e",encodedChan.data()))
						clearAll(); // disconnected
					else pChan->setSentListRequest('e');
					m_curType = Invite;
					break;
				}
			case Invite:
				if(pChan->serverInfo()->supportedListModes().contains('I') &&
					!KVI_OPTION_BOOL(KviOption_boolDisableInviteListRequestOnJoin) &&
					!(	pChan->serverInfo()->getNeedsOpToListModeseI() &&
						!pChan->isMeOp()
					 )
				)
				{
					if(!pChan->connection()->sendFmtData("MODE %s I",encodedChan.data()))
						clearAll(); // disconnected
					else pChan->setSentListRequest('I');
					m_curType = QuietBan;
					break;
				}
			case QuietBan:
				if(pChan->serverInfo()->supportedListModes().contains('q') &&
					!KVI_OPTION_BOOL(KviOption_boolDisableQuietBanListRequestOnJoin))
				{
					if(!pChan->connection()->sendFmtData("MODE %s q",encodedChan.data()))
						clearAll(); // disconnected
					else pChan->setSentListRequest('q');
					m_curType = Who;
					break;
				}
			case Who:
				if(!KVI_OPTION_BOOL(KviOption_boolDisableWhoRequestOnJoin))
				{
					// TODO: cleanup
					pChan->connection()->stateData()->setLastSentChannelWhoRequest(kvi_unixTime());
					if(pChan->connection()->lagMeter())
					{
						KviCString tmp;
						if(pChan->serverInfo()->supportsWhox())
							tmp.sprintf("WHO %s %acdfhlnrsu",encodedChan.data());
						else
							tmp.sprintf("WHO %s",encodedChan.data());
						pChan->connection()->lagMeter()->lagCheckRegister(tmp.ptr(),60);
					}
					if(pChan->serverInfo()->supportsWhox())
					{
						if(!pChan->connection()->sendFmtData("WHO %s %acdfhlnrsu",encodedChan.data()))
							clearAll(); // disconnected
						else pChan->setSentWhoRequest();
					} else {
						if(!pChan->connection()->sendFmtData("WHO %s",encodedChan.data()))
							clearAll(); // disconnected
						else pChan->setSentWhoRequest();
					}
					m_curType = Ban;
					break;
				}
			case Ban:
				if(!KVI_OPTION_BOOL(KviOption_boolDisableBanListRequestOnJoin))
				{
					if(!pChan->connection()->sendFmtData("MODE %s b",encodedChan.data()))
					{
						clearAll(); // disconnected
					} else {
						pChan->setSentListRequest('b');
						m_channels.dequeue();
					}
					m_curType = Mode;
					break;
				}
			default:
				// we're at the end of the list
				m_channels.dequeue();
				pChan->checkChannelSync();
				m_curType = Mode;
				if(m_channels.isEmpty())
				{
					m_timer.stop();
					return;
				}
				pChan = m_channels.head();
				encodedChan = pChan->connection()->encodeText(pChan->target());
			case Mode:
				if(!pChan->connection()->sendFmtData("MODE %s",encodedChan.data()))
				{
					clearAll(); // disconnected
					break;
				}
				m_curType = BanException;
				break;
		}
	}
}
예제 #2
0
void KviTopicWidget::switchMode()
{
    int iMaxLen=-1;
    QObject * w = parent();
    QString szModes;
    bool bCanEdit = true;
    while(w)
    {
        if(w->inherits("KviChannelWindow"))
        {
            KviChannelWindow *chan = ((KviChannelWindow *)w);
            iMaxLen = chan->connection()->serverInfo()->maxTopicLen();
            chan->getChannelModeString(szModes);
            if(chan->plainChannelMode().contains('t') &&
                    !( chan->isMeHalfOp() ||
                       chan->isMeOp() ||
                       chan->isMeChanOwner() ||
                       chan->isMeChanAdmin() ||
                       chan->connection()->userInfo()->hasUserMode('o') ||
                       chan->connection()->userInfo()->hasUserMode('O')
                     )
              )
            {
                bCanEdit=false;
            }
            break;
        }
        w = w->parent();
    }
    if(m_pInput == 0)
    {
        m_pInput = new KviInputEditor(this,m_pKviChannelWindow);
        m_pInput->setObjectName("topicw_inputeditor");
        m_pInput->setReadOnly(!bCanEdit);
        if(iMaxLen>0)
            m_pInput->setMaxBufferSize(iMaxLen);
        m_pInput->setGeometry(0,0,width() - (height() << 2)+height(),height());
        m_pInput->setText(m_szTopic);
        connect(m_pInput,SIGNAL(enterPressed()),this,SLOT(acceptClicked()));
        connect(m_pInput,SIGNAL(escapePressed()),this,SLOT(discardClicked()));
        m_pInput->installEventFilter(this);

        m_pHistory = new QPushButton(this);
        m_pHistory->setObjectName("topicw_historybutton");
        m_pHistory->setIcon(QIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Time))));
        m_pHistory->setGeometry(width() - (height() << 2)+height(),0,height(),height());
        KviTalToolTip::add(m_pHistory,__tr2qs("History"));
        m_pHistory->show();
        connect(m_pHistory,SIGNAL(clicked()),this,SLOT(historyClicked()));

        m_pAccept = new QPushButton(this);
        m_pAccept->setObjectName("topicw_acceptbutton");
        m_pAccept->setIcon(QIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Accept))));
        m_pAccept->setGeometry(width() - (height() << 1),0,height(),height());
        m_pAccept->setEnabled(bCanEdit);
        m_pAccept->show();
        KviTalToolTip::add(m_pAccept,__tr2qs("Commit Changes"));
        connect(m_pAccept,SIGNAL(clicked()),this,SLOT(acceptClicked()));

        m_pDiscard = new QPushButton(this);
        m_pDiscard->setObjectName("topicw_discardbutton");
        m_pDiscard->setIcon(QIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Discard))));
        m_pDiscard->setGeometry(width() - height(),0,height(),height());
        KviTalToolTip::add(m_pDiscard,__tr2qs("Discard Changes"));
        m_pDiscard->show();
        connect(m_pDiscard,SIGNAL(clicked()),this,SLOT(discardClicked()));

        m_pInput->home();
        m_pInput->show();
        m_pInput->setFocus();

        m_pLabel->hide();
    } else {
        deactivate();
    }
}