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());
	}
}
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);
}