~ubuntu-branches/ubuntu/vivid/kdepim/vivid

« back to all changes in this revision

Viewing changes to mailcommon/filter/filterimporter/filterimporterbalsa.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Jonathan Riddell, Rohan Garg, Scott Kitterman
  • Date: 2012-11-21 13:12:36 UTC
  • mfrom: (0.2.33)
  • Revision ID: package-import@ubuntu.com-20121121131236-32ijw9a2txrar80k
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Rohan Garg ]
* Add nepomuk-core-dev to build-deps

[ Scott Kitterman ]
* Add new package, libpimcommon4
  - Add libpimcommon4.install
  - Add to debian/control, including kdepim-dbg and kdepim-dev depends
  - Add to kdepim-dev.install
* Remove usr/bin/backupmail and related files from kmail.install as they are
  not provided by upstream anymore
* Add usr/bin/pimsettingexporter and related files to kmail.install
* Add libnepomukwidgets-dev to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2012 Montel Laurent <montel@kde.org>
 
3
 
 
4
  This program is free software; you can redistribute it and/or modify it
 
5
  under the terms of the GNU General Public License, version 2, as
 
6
  published by the Free Software Foundation.
 
7
 
 
8
  This program is distributed in the hope that it will be useful, but
 
9
  WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
  General Public License for more details.
 
12
 
 
13
  You should have received a copy of the GNU General Public License along
 
14
  with this program; if not, write to the Free Software Foundation, Inc.,
 
15
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
16
*/
 
17
 
 
18
#include "filterimporterbalsa_p.h"
 
19
#include "filtermanager.h"
 
20
#include "mailfilter.h"
 
21
 
 
22
#include <KConfig>
 
23
#include <KConfigGroup>
 
24
 
 
25
#include <KDebug>
 
26
 
 
27
#include <QFile>
 
28
 
 
29
using namespace MailCommon;
 
30
 
 
31
FilterImporterBalsa::FilterImporterBalsa( QFile *file )
 
32
  :FilterImporterAbstract()
 
33
{
 
34
  KConfig config( file->fileName() );
 
35
  const QStringList filterList = config.groupList().filter( QRegExp( "filter-\\d+" ) );
 
36
  Q_FOREACH(const QString &filter, filterList) {
 
37
    KConfigGroup grp = config.group(filter);
 
38
    addFilter(grp);
 
39
  }
 
40
}
 
41
 
 
42
FilterImporterBalsa::~FilterImporterBalsa()
 
43
{
 
44
}
 
45
 
 
46
QString FilterImporterBalsa::defaultFiltersSettingsPath()
 
47
{
 
48
  return QString::fromLatin1( "%1/.balsa/config" ).arg( QDir::homePath() );
 
49
}
 
50
 
 
51
 
 
52
void FilterImporterBalsa::addFilter(const KConfigGroup &grp)
 
53
{
 
54
  MailCommon::MailFilter *filter = new MailCommon::MailFilter();
 
55
  const QString name = grp.readEntry(QLatin1String("Name"));
 
56
  filter->pattern()->setName( name );
 
57
  filter->setToolbarName( name );
 
58
 
 
59
  //TODO
 
60
  const QString popupText = grp.readEntry(QLatin1String("Popup-text"));
 
61
 
 
62
 
 
63
  const QString sound = grp.readEntry(QLatin1String("Sound"));
 
64
  if(!sound.isEmpty()) {
 
65
    const QString actionName = QLatin1String( "play sound" );
 
66
    createFilterAction( filter, actionName, sound );
 
67
  }
 
68
 
 
69
  const int actionType = grp.readEntry(QLatin1String("Action-type"),-1);
 
70
  const QString actionStr = grp.readEntry(QLatin1String("Action-string"));
 
71
  parseAction(actionType,actionStr,filter);
 
72
 
 
73
  const QString condition = grp.readEntry(QLatin1String("Condition"));
 
74
  parseCondition(condition,filter);
 
75
 
 
76
  appendFilter(filter);
 
77
}
 
78
 
 
79
void FilterImporterBalsa::parseCondition(const QString& condition,MailCommon::MailFilter *filter )
 
80
{
 
81
    QStringList conditionList;
 
82
    if(condition.startsWith(QLatin1String("OR "))) {
 
83
        conditionList = condition.split(QLatin1String("OR"));
 
84
        filter->pattern()->setOp( SearchPattern::OpOr );
 
85
    } else if(condition.startsWith(QLatin1String("AND "))) {
 
86
        conditionList = condition.split(QLatin1String("AND"));
 
87
        filter->pattern()->setOp( SearchPattern::OpAnd );
 
88
    } else {
 
89
        //no multi condition
 
90
        conditionList<< condition;
 
91
    }
 
92
    Q_FOREACH(QString cond, conditionList) {
 
93
        cond = cond.trimmed();
 
94
        bool negative = false;
 
95
        if(cond.startsWith(QLatin1String("NOT"))) {
 
96
            cond = cond.right(cond.length()-3);
 
97
            negative = true;
 
98
            cond = cond.trimmed();
 
99
        }
 
100
        qDebug()<<" cond"<<cond;
 
101
 
 
102
        //Date between
 
103
        QByteArray fieldName;
 
104
        if(cond.startsWith(QLatin1String("DATE"))) {
 
105
            fieldName = "<date>";
 
106
            cond = cond.right(cond.length()-4);
 
107
            cond = cond.trimmed();
 
108
            QStringList splitDate = cond.split(QLatin1Char(' '));
 
109
            qDebug()<<" splitDate "<<splitDate;
 
110
        } else if(cond.startsWith(QLatin1String("FLAG"))) {
 
111
            qDebug()<<" FLAG :";
 
112
        } else if(cond.startsWith(QLatin1String("STRING"))) {
 
113
            qDebug()<<" STRING";
 
114
        } else {
 
115
            qDebug()<<" condition not implemented :"<<cond;
 
116
        }
 
117
 
 
118
        //SearchRule::Ptr rule = SearchRule::createInstance( fieldName, functionName, line );
 
119
        //filter->pattern()->append( rule );
 
120
    }
 
121
}
 
122
 
 
123
void FilterImporterBalsa::parseAction(int actionType, const QString& action,MailCommon::MailFilter *filter)
 
124
{
 
125
  QString actionName;
 
126
  QString actionStr(action);
 
127
  switch(actionType) {
 
128
  case 0:
 
129
    break;
 
130
  case 1:
 
131
      //Copy
 
132
      actionName = QLatin1String( "copy" );
 
133
    break;
 
134
  case 2:
 
135
      //Move
 
136
      actionName = QLatin1String( "transfer" );
 
137
    break;
 
138
  case 3:
 
139
      //Print
 
140
    break;
 
141
  case 4:
 
142
      //Execute
 
143
      actionName = QLatin1String( "execute" );
 
144
    break;
 
145
  case 5:
 
146
      //Move to trash
 
147
      actionName = QLatin1String( "transfer" );
 
148
      //Special !
 
149
    break;
 
150
  case 6:
 
151
      //Put color
 
152
    break;
 
153
  default:
 
154
    qDebug()<<" unknown parse action type "<<actionType;
 
155
    break;
 
156
  }
 
157
  if(!actionName.isEmpty()) {
 
158
      //TODO adapt actionStr
 
159
    createFilterAction( filter, actionName, actionStr );
 
160
  }
 
161
}