Commit a596ef39 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

clean up code and start to add unittest

parent 31c9660d
/*
Copyright (c) 2012 Montel Laurent <montel@kde.org>
Copyright (c) 2012, 2013 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
......@@ -35,61 +35,61 @@ FilterImporterAbstract::~FilterImporterAbstract()
QList<MailFilter*> FilterImporterAbstract::importFilter() const
{
return mListMailFilter;
return mListMailFilter;
}
QStringList FilterImporterAbstract::emptyFilter() const
{
return mEmptyFilter;
return mEmptyFilter;
}
void FilterImporterAbstract::appendFilter( MailCommon::MailFilter *filter )
{
if ( !filter )
return;
filter->purify();
if ( !filter->isEmpty() ) {
// the filter is valid:
mListMailFilter << filter;
} else {
mEmptyFilter << filter->name();
// the filter is invalid:
delete filter;
}
if ( !filter )
return;
filter->purify();
if ( !filter->isEmpty() ) {
// the filter is valid:
mListMailFilter << filter;
} else {
mEmptyFilter << filter->name();
// the filter is invalid:
delete filter;
}
}
void FilterImporterAbstract::createFilterAction( MailCommon::MailFilter *filter,
const QString &actionName,
const QString &value )
{
if ( !actionName.isEmpty() ) {
FilterActionDesc *desc = MailCommon::FilterManager::filterActionDict()->value( actionName );
if ( desc ) {
FilterAction *fa = desc->create();
//...create an instance...
fa->argsFromStringInteractive( value, filter->name() );
//...check if it's empty and...
if ( !fa->isEmpty() ) {
//...append it if it's not and...
filter->actions()->append( fa );
} else {
//...delete is else.
delete fa;
}
if ( !actionName.isEmpty() ) {
FilterActionDesc *desc = MailCommon::FilterManager::filterActionDict()->value( actionName );
if ( desc ) {
FilterAction *fa = desc->create();
//...create an instance...
fa->argsFromStringInteractive( value, filter->name() );
//...check if it's empty and...
if ( !fa->isEmpty() ) {
//...append it if it's not and...
filter->actions()->append( fa );
} else {
//...delete is else.
delete fa;
}
}
}
}
}
bool FilterImporterAbstract::loadDomElement( QDomDocument &doc, QFile *file )
{
QString errorMsg;
int errorRow;
int errorCol;
if ( !doc.setContent( file, &errorMsg, &errorRow, &errorCol ) ) {
kDebug() << "Unable to load document.Parse error in line " << errorRow
<< ", col " << errorCol << ": " << errorMsg;
return false;
}
return true;
QString errorMsg;
int errorRow;
int errorCol;
if ( !doc.setContent( file, &errorMsg, &errorRow, &errorCol ) ) {
kDebug() << "Unable to load document.Parse error in line " << errorRow
<< ", col " << errorCol << ": " << errorMsg;
return false;
}
return true;
}
/*
Copyright (c) 2012 Montel Laurent <montel@kde.org>
Copyright (c) 2012, 2013 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
......@@ -31,13 +31,13 @@ class MailFilter;
class FilterImporterAbstract
{
public:
public:
explicit FilterImporterAbstract();
~FilterImporterAbstract();
QList<MailFilter*> importFilter() const;
QStringList emptyFilter() const;
protected:
protected:
void appendFilter( MailCommon::MailFilter *filter );
void createFilterAction( MailCommon::MailFilter *filter,
const QString &actionName, const QString &value );
......
......@@ -48,6 +48,11 @@ FilterImporterClawsMails::FilterImporterClawsMails( QFile *file )
appendFilter(filter);
}
FilterImporterClawsMails::FilterImporterClawsMails()
:FilterImporterAbstract()
{
}
FilterImporterClawsMails::~FilterImporterClawsMails()
{
}
......@@ -59,8 +64,7 @@ QString FilterImporterClawsMails::defaultFiltersSettingsPath()
MailFilter * FilterImporterClawsMails::parseLine(const QString& line, MailFilter *filter)
{
if (filter)
appendFilter(filter);
appendFilter(filter);
filter = new MailFilter();
QString tmp = line;
//Enabled ?
......@@ -83,11 +87,16 @@ MailFilter * FilterImporterClawsMails::parseLine(const QString& line, MailFilter
tmp = extractConditions( tmp, filter);
tmp = extractActions(tmp, filter);
//TODO
return filter;
}
QString FilterImporterClawsMails::extractActions( const QString &line,MailFilter *filter)
{
return line;
}
QString FilterImporterClawsMails::extractConditions( const QString &line,MailFilter *filter)
{
QByteArray fieldName;
......
......@@ -33,12 +33,17 @@ class FilterImporterClawsMails : public FilterImporterAbstract
{
public:
explicit FilterImporterClawsMails( QFile *file );
//Use for unittests
FilterImporterClawsMails();
~FilterImporterClawsMails();
static QString defaultFiltersSettingsPath();
private:
MailFilter * parseLine(const QString& line, MailFilter *filter);
private:
QString extractString( const QString & tmp, int & pos);
QString extractConditions( const QString &line,MailFilter *filter);
QString extractActions( const QString &line,MailFilter *filter);
};
}
......
/*
Copyright (c) 2013 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "filterimportclawmailtest.h"
#include <qtest_kde.h>
QTEST_KDEMAIN( FilterImportClawMailtest, NoGUI )
void FilterImportClawMailtest::testImportFilters()
{
//TODO
}
/*
Copyright (c) 2013 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef FILTERIMPORTCLAWMAILTEST_H
#define FILTERIMPORTCLAWMAILTEST_H
#include <QObject>
class FilterImportClawMailtest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testImportFilters();
};
#endif // FILTERIMPORTCLAWMAILTEST_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment