Sun Apr  1 02:00:28 Środkowoeuropejski czas stand. 2007  Maciej Niedzielski <machekku@uaznia.net>
  * XEP-0076 scanner
diff -rN old-psi1a/options/default.xml new-psi1a/options/default.xml
52a53,55
> 		<anti-evil comment="Anti-evil protection">
> 			<enable comment="Enable AntiEvil scanner" type="bool">true</enable>
> 		</anti-evil>
diff -rN old-psi1a/src/antievil.cpp new-psi1a/src/antievil.cpp
0a1,74
> /*
>  * antievil.cpp - anti evil scanner task
>  * Copyright (C) 2007-04-01  Maciej Niedzielski
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public
>  * License as published by the Free Software Foundation; either
>  * version 2 of the License, or (at your option) any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>  * Lesser General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public
>  * License along with this library; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
>  *
>  */
> 
> #include "antievil.h"
> #include "psioptions.h"
> #include "xmpp_xmlcommon.h"
> 
> using namespace XMPP;
> 
> 
> /**
>  * \class AntiEvil
>  * \brief XEP-0076 implementation
>  *
>  * This tasks protects from evil
>  */
> 
> 
> AntiEvil::Stats AntiEvil::s;
> 
> AntiEvil::AntiEvil(Task *parent)
> :Task(parent)
> {
> }
> 
> AntiEvil::~AntiEvil()
> {
> }
> 
> bool AntiEvil::take(const QDomElement &e)
> {
> 	if (!PsiOptions::instance()->getOption("options.anti-evil.enable").toBool())
> 		return false;
> 
> 	bool evil = false;
> 	for (QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
> 		QDomElement i = n.toElement();
> 		if (!i.isNull() && i.tagName() == "evil" && i.attribute("xmlns") == "http://jabber.org/protocol/evil") {
> 			//qDebug("evil stanza received");
> 			evil = true;
> 			break;
> 		}
> 	}
> 
> 	++s.scanned;
> 	emit s.scannedNext(s.scanned);
> 
> 	if (!evil)
> 		return false;
> 
> 	++s.blocked;
> 	s.lastBlockedFrom = e.attribute("from");
> 	s.lastBlockedTime = QDateTime::currentDateTime();
> 	emit s.blockedNext(s.blocked, s.lastBlockedFrom, s.lastBlockedTime);
> 
> 	return true;
> }
diff -rN old-psi1a/src/antievil.h new-psi1a/src/antievil.h
0a1,59
> /*
>  * antievil.h - anti evil scanner task
>  * Copyright (C) 2007-04-01  Maciej Niedzielski
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public
>  * License as published by the Free Software Foundation; either
>  * version 2 of the License, or (at your option) any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>  * Lesser General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public
>  * License along with this library; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
>  *
>  */
> 
> #ifndef ANTIEVIL_H
> #define ANTIEVIL_H
> 
> #include "xmpp_task.h"
> #include <QDateTime>
> 
> class AntiEvil : public XMPP::Task
> {
> public:
> 	AntiEvil(Task *);
> 	~AntiEvil();
> 	bool take(const QDomElement &);
> 
> 	class Stats;
> 	static const Stats* stats() { return &s; }
> 
> private:
> 	static Stats s;
> 
> };
> 
> class AntiEvil::Stats : public QObject
> {
> 	Q_OBJECT
> public:
> 	int scanned;
> 	int blocked;
> 
> 	QString lastBlockedFrom;
> 	QDateTime lastBlockedTime;
> 
> signals:
> 	void scannedNext(int);
> 	void blockedNext(int, const QString&, const QDateTime&);
> 
> 	friend AntiEvil;
> };
> 
> #endif
diff -rN old-psi1a/src/options/opt_antievil.cpp new-psi1a/src/options/opt_antievil.cpp
0a1,80
> #include "opt_antievil.h"
> 
> #include "antievil.h"
> #include "psioptions.h"
> #include "ui_opt_antievil.h"
> 
> #include <QWidget>
> #include <QWhatsThis>
> 
> class OptAntiEvilUI : public QWidget, public Ui::OptAntiEvil
> {
> public:
> 	OptAntiEvilUI() : QWidget() { setupUi(this); }
> };
> 
> //----------------------------------------------------------------------------
> // OptionsTabAntiEvil
> //----------------------------------------------------------------------------
> 
> OptionsTabAntiEvil::OptionsTabAntiEvil(QObject *parent)
> : OptionsTab(parent, "antievil", "", tr("AntiEvil"), tr("Anti evil scanner"), "psi/advanced")
> {
> 	w = 0;
> }
> 
> OptionsTabAntiEvil::~OptionsTabAntiEvil()
> {
> }
> 
> QWidget *OptionsTabAntiEvil::widget()
> {
> 	if ( w )
> 		return 0;
> 
> 	w = new OptAntiEvilUI();
> 	OptAntiEvilUI *d = (OptAntiEvilUI *)w;
> 
> 	QWhatsThis::add(d->ck_enable,
> 		tr("Check this option to protect you Psi from evil stanzas."));
> 
> 
> 	const AntiEvil::Stats *s = AntiEvil::stats();
> 	d->lb_statsScanned->setNum(s->scanned);
> 	if (s->blocked) {
> 		blockedNext(s->blocked, s->lastBlockedFrom, s->lastBlockedTime)
> 	}
> 
> 	connect(AntiEvil::stats(), SIGNAL(scannedNext(int)), d->lb_statsScanned, SLOT(setNum(int)));
> 	connect(AntiEvil::stats(), SIGNAL(blockedNext(int, QString, QDateTime)), this, SLOT(blockedNext(int, QString, QDateTime)));
> 
> 	return w;
> }
> 
> void OptionsTabAntiEvil::applyOptions(Options *opt)
> {
> 	if ( !w )
> 		return;
> 
> 	OptAntiEvilUI *d = (OptAntiEvilUI *)w;
> 
> 	PsiOptions::instance()->setOption("options.anti-evil.enable" ,d->ck_enable->isChecked());
> }
> 
> void OptionsTabAntiEvil::restoreOptions(const Options *opt)
> {
> 	if ( !w )
> 		return;
> 
> 	OptAntiEvilUI *d = (OptAntiEvilUI *)w;
> 
> 	d->ck_enable->setChecked(PsiOptions::instance()->getOption("options.anti-evil.enable").toBool());
> }
> 
> void OptionsTabAntiEvil::blockedNext(int n, const QString &j, const QDateTime &dt)
> {
> 	OptAntiEvilUI *d = (OptAntiEvilUI *)w;
> 	d->lb_statsBlocked->setNum(n);
> 	d->lb_lastFrom->setText(j);
> 	d->lb_lastTime->setText(dt.toString(Qt::TextDate));
> }
diff -rN old-psi1a/src/options/opt_antievil.h new-psi1a/src/options/opt_antievil.h
0a1,28
> #ifndef OPT_ANTIEVIL_H
> #define OPT_ANTIEVIL_H
> 
> #include "optionstab.h"
> #include <QDateTime>
> 
> class QWidget;
> struct Options;
> 
> class OptionsTabAntiEvil : public OptionsTab
> {
> 	Q_OBJECT
> public:
> 	OptionsTabAntiEvil(QObject *parent);
> 	~OptionsTabAntiEvil();
> 
> 	QWidget *widget();
> 	void applyOptions(Options *opt);
> 	void restoreOptions(const Options *opt);
> 
> private:
> 	QWidget *w;
> 
> private slots:
> 	void blockedNext(int, const QString&, const QDateTime&);
> };
> 
> #endif
diff -rN old-psi1a/src/options/opt_antievil.ui new-psi1a/src/options/opt_antievil.ui
0a1,135
> <ui version="4.0" >
>  <class>OptAntiEvil</class>
>  <widget class="QWidget" name="OptAntiEvil" >
>   <property name="geometry" >
>    <rect>
>     <x>0</x>
>     <y>0</y>
>     <width>295</width>
>     <height>255</height>
>    </rect>
>   </property>
>   <property name="windowTitle" >
>    <string>OptAntiEvil</string>
>   </property>
>   <layout class="QVBoxLayout" >
>    <property name="margin" >
>     <number>9</number>
>    </property>
>    <property name="spacing" >
>     <number>6</number>
>    </property>
>    <item>
>     <widget class="QCheckBox" name="ck_enable" >
>      <property name="text" >
>       <string>Protect me from evil</string>
>      </property>
>     </widget>
>    </item>
>    <item>
>     <widget class="QGroupBox" name="groupBox_3" >
>      <property name="title" >
>       <string>Stats</string>
>      </property>
>      <layout class="QGridLayout" >
>       <property name="margin" >
>        <number>9</number>
>       </property>
>       <property name="spacing" >
>        <number>6</number>
>       </property>
>       <item row="1" column="1" >
>        <widget class="QLabel" name="lb_statsBlocked" >
>         <property name="text" >
>          <string>0</string>
>         </property>
>        </widget>
>       </item>
>       <item row="0" column="1" >
>        <widget class="QLabel" name="lb_statsScanned" >
>         <property name="text" >
>          <string>0</string>
>         </property>
>        </widget>
>       </item>
>       <item row="1" column="0" >
>        <widget class="QLabel" name="label_14" >
>         <property name="text" >
>          <string>Evil stanzas blocked:</string>
>         </property>
>        </widget>
>       </item>
>       <item row="0" column="0" >
>        <widget class="QLabel" name="label_13" >
>         <property name="text" >
>          <string>Stanzas scanned:</string>
>         </property>
>        </widget>
>       </item>
>      </layout>
>     </widget>
>    </item>
>    <item>
>     <widget class="QGroupBox" name="groupBox_2" >
>      <property name="title" >
>       <string>Last evil stanza</string>
>      </property>
>      <layout class="QGridLayout" >
>       <property name="margin" >
>        <number>9</number>
>       </property>
>       <property name="spacing" >
>        <number>6</number>
>       </property>
>       <item row="1" column="1" >
>        <widget class="QLabel" name="lb_lastTime" >
>         <property name="text" >
>          <string>-</string>
>         </property>
>        </widget>
>       </item>
>       <item row="0" column="1" >
>        <widget class="QLabel" name="lb_lastFrom" >
>         <property name="text" >
>          <string>-</string>
>         </property>
>        </widget>
>       </item>
>       <item row="1" column="0" >
>        <widget class="QLabel" name="label_8" >
>         <property name="text" >
>          <string>Time:</string>
>         </property>
>        </widget>
>       </item>
>       <item row="0" column="0" >
>        <widget class="QLabel" name="label_7" >
>         <property name="text" >
>          <string>From:</string>
>         </property>
>        </widget>
>       </item>
>      </layout>
>     </widget>
>    </item>
>    <item>
>     <spacer>
>      <property name="orientation" >
>       <enum>Qt::Vertical</enum>
>      </property>
>      <property name="sizeHint" >
>       <size>
>        <width>20</width>
>        <height>40</height>
>       </size>
>      </property>
>     </spacer>
>    </item>
>   </layout>
>  </widget>
>  <tabstops>
>   <tabstop>ck_enable</tabstop>
>  </tabstops>
>  <resources/>
>  <connections/>
> </ui>
diff -rN old-psi1a/src/options/options.pri new-psi1a/src/options/options.pri
63a64,69
> psi_antievil {
> 	INTERFACES += $$PWD/opt_antievil.ui
> 	SOURCES += $$PWD/opt_antievil.cpp
> 	HEADERS += $$PWD/opt_antievil.h
> }
> 
diff -rN old-psi1a/src/options/optionsdlg.cpp new-psi1a/src/options/optionsdlg.cpp
36a37,40
> #ifdef PSI_ANTIEVIL
> #include "opt_antievil.h"
> #endif
> 
329a334,336
> #ifdef PSI_ANTIEVIL
> 	tabs.append( new OptionsTabAntiEvil(this) );
> #endif
diff -rN old-psi1a/src/psiaccount.cpp new-psi1a/src/psiaccount.cpp
123a124,127
> #ifdef PSI_ANTIEVIL
> #include "antievil.h"
> #endif
> 
512a517,520
> #ifdef PSI_ANTIEVIL
> 	new AntiEvil(d->client->rootTask());
> #endif
> 
diff -rN old-psi1a/src/src.pri new-psi1a/src/src.pri
397a398,405
> # AntiEvil
> CONFIG += psi_antievil
> psi_antievil {
> 	DEFINES += PSI_ANTIEVIL
> 	HEADERS += $$PWD/antievil.h
> 	SOURCES += $$PWD/antievil.cpp
> }
> 

