Пример #1
0
void KviNickServRuleSet::copyFrom(const KviNickServRuleSet &src)
{
    if(src.m_pRules)
    {
        if(m_pRules)m_pRules->clear();
        else {
            m_pRules = new KviPointerList<KviNickServRule>;
            m_pRules->setAutoDelete(true);
        }
        for(KviNickServRule * r = src.m_pRules->first(); r; r = src.m_pRules->next())
        {
            KviNickServRule * c = new KviNickServRule();
            c->copyFrom(*r);
            m_pRules->append(c);
        }
        if(m_pRules->isEmpty())
        {
            m_bEnabled = false;
            delete m_pRules;
            m_pRules = 0;
        } else {
            m_bEnabled = src.m_bEnabled;
        }
    } else {
        m_bEnabled = false;
        if(m_pRules)
        {
            delete m_pRules;
            m_pRules = 0;
        }
    }
}
Пример #2
0
bool KviNickServRuleSet::loadPrivate(KviConfigurationFile * pCfg, const QString & szPrefix, unsigned int uEntries)
{
    if(m_pRules)
        m_pRules->clear();
    else {
        m_pRules = new KviPointerList<KviNickServRule>;
        m_pRules->setAutoDelete(true);
    }

    if(uEntries != 0)
    {
        QString szTmp;
        szTmp = QString("%1NSEnabled").arg(szPrefix);
        m_bEnabled = pCfg->readBoolEntry(szTmp,false);
        for(unsigned int u=0; u < uEntries; u++)
        {
            szTmp = QString("%1NSRule%2_").arg(szPrefix).arg(u);
            KviNickServRule * pRule = new KviNickServRule();
            if(!pRule->load(pCfg,szTmp))
                delete pRule;
            else m_pRules->append(pRule);
        }
    }

    if(m_pRules->isEmpty())
    {
        m_bEnabled = false;
        delete m_pRules;
        m_pRules = 0;
        return false;
    }
    return true;
}
Пример #3
0
void KviNickServRuleSet::save(KviConfigurationFile * pCfg, const QString & szPrefix)
{
    if(!m_pRules)
        return; // nothing to save
    if(m_pRules->isEmpty())
        return; // should never happen anyway
    QString szTmp;
    if(m_bEnabled)
    {
        szTmp = QString("%1NSEnabled").arg(szPrefix);
        pCfg->writeEntry(szTmp,m_bEnabled);
    }
    szTmp = QString("%1NSRules").arg(szPrefix);
    pCfg->writeEntry(szTmp,m_pRules->count());
    int i = 0;
    for(KviNickServRule * pRule = m_pRules->first(); pRule; pRule = m_pRules->next())
    {
        szTmp = QString("%1NSRule%2_").arg(szPrefix).arg(i);
        pRule->save(pCfg,szTmp);
        i++;
    }
}
Пример #4
0
KviNickServRule * KviNickServRuleSet::matchRule(const QString & szNick, const KviIrcMask * pNickServ, const QString & szMsg, const QString & szServer)
{
    if(!m_pRules) return 0;

    for(KviNickServRule *r = m_pRules->first(); r; r = m_pRules->next())
    {
        if(!KviQString::matchString(r->registeredNick(),szNick,false,true))
            continue;

        if(!szServer.isEmpty())
        {
            QRegExp res(r->serverMask(),Qt::CaseInsensitive,QRegExp::Wildcard);
            if(!res.exactMatch(szServer))
                continue;
        }
        if(!pNickServ->matchedBy(KviIrcMask(r->nickServMask())))
            continue;
        QRegExp re(r->messageRegexp(),Qt::CaseInsensitive,QRegExp::Wildcard);
        if(re.exactMatch(szMsg)) return r;
    }
    return 0;
}
Пример #5
0
void OptionsWidget_nickServ::addNickServRule()
{
	KviNickServRule r;
	NickServRuleEditor ed(this,true);
	if(ed.editRule(&r))
	{
		QTreeWidgetItem* it = new QTreeWidgetItem(m_pNickServTreeWidget);
		it->setText(0,r.registeredNick());
		it->setText(1,r.serverMask());
		it->setText(2,r.nickServMask());
		it->setText(3,r.messageRegexp());
		it->setText(4,r.identifyCommand());
	}
}
Пример #6
0
OptionsWidget_nickServ::OptionsWidget_nickServ(QWidget * parent)
: KviOptionsWidget(parent)
{
	createLayout();
	setObjectName("nickserv_options_widget");

	QGridLayout * gl = layout();

	KviNickServRuleSet * rs = g_pNickServRuleSet;
	bool bNickServEnabled = rs ? (rs->isEnabled() && !rs->isEmpty()) : false;

	m_pNickServCheck = new QCheckBox(__tr2qs_ctx("Enable NickServ identification","options"),this);
	gl->addWidget(m_pNickServCheck,0,0,1,3);
//	gl->addMultiCellWidget(m_pNickServCheck,0,0,0,2);
	KviTalToolTip::add(m_pNickServCheck,__tr2qs_ctx("This check enables the automatic identification with NickServ","options"));
	m_pNickServCheck->setChecked(bNickServEnabled);

	m_pNickServTreeWidget = new QTreeWidget(this);
	m_pNickServTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
	m_pNickServTreeWidget->setAllColumnsShowFocus(true);
	QStringList columnLabels;

	columnLabels.append(__tr2qs_ctx("Nickname","options"));
	columnLabels.append(__tr2qs_ctx("Server Mask","options"));
	columnLabels.append(__tr2qs_ctx("NickServ Mask","options"));
	columnLabels.append(__tr2qs_ctx("NickServ Request Mask","options"));
	columnLabels.append(__tr2qs_ctx("Identify Command","options"));
	m_pNickServTreeWidget->setHeaderLabels(columnLabels);
	connect(m_pNickServTreeWidget,SIGNAL(itemSelectionChanged()),this,SLOT(enableDisableNickServControls()));

	gl->addWidget(m_pNickServTreeWidget,1,0,1,3);
//	gl->addMultiCellWidget(m_pNickServTreeWidget,1,1,0,2);
	KviTalToolTip::add(m_pNickServTreeWidget,\
		__tr2qs_ctx("This is a list of NickServ identification rules. " \
			"KVIrc will use them to model its automatic interaction with NickServ on all the networks.<br>" \
			"Please be aware that this feature can cause your NickServ passwords to be stolen " \
			"if used improperly. Make sure that you fully understand the NickServ authentication protocol.<br>" \
			"In other words, be sure to know what you're doing.<br>" \
			"Also note that the password that you provide is stored as <b>PLAIN TEXT</b>.<br>" \
			"KVIrc supports also per-network NickServ authentication rules that can be " \
			"created in the \"Advanced...\" network options (accessible from the servers dialog)."
			"","options"));

	m_pAddRuleButton = new QPushButton(__tr2qs_ctx("Add Rule","options"),this);
	connect(m_pAddRuleButton,SIGNAL(clicked()),this,SLOT(addNickServRule()));
	gl->addWidget(m_pAddRuleButton,2,0);

	m_pEditRuleButton = new QPushButton(__tr2qs_ctx("Edit Rule","options"),this);
	connect(m_pEditRuleButton,SIGNAL(clicked()),this,SLOT(editNickServRule()));
	gl->addWidget(m_pEditRuleButton,2,1);

	m_pDelRuleButton = new QPushButton(__tr2qs_ctx("Delete Rule","options"),this);
	connect(m_pDelRuleButton,SIGNAL(clicked()),this,SLOT(delNickServRule()));
	gl->addWidget(m_pDelRuleButton,2,2);

	connect(m_pNickServCheck,SIGNAL(toggled(bool)),this,SLOT(enableDisableNickServControls()));

	if(rs && rs->rules())
	{
		QTreeWidgetItem *it;
		KviPointerList<KviNickServRule> * ll = rs->rules();
		for(KviNickServRule * rule = ll->first();rule;rule = ll->next())
		{
			it = new QTreeWidgetItem(m_pNickServTreeWidget);
			it->setText(0,rule->registeredNick());
			it->setText(1,rule->serverMask());
			it->setText(2,rule->nickServMask());
			it->setText(3,rule->messageRegexp());
			it->setText(4,rule->identifyCommand());
		}
	}

	enableDisableNickServControls();

	gl->setRowStretch(1,1);
}