kmail Library API Documentation

antispamwizard.h

00001 /*  -*- mode: C++ -*-
00002     This file is part of KMail.
00003     Copyright (c) 2003 Andreas Gungl <a.gungl@gmx.de>
00004 
00005     KMail is free software; you can redistribute it and/or modify it
00006     under the terms of the GNU General Public License, version 2, as
00007     published by the Free Software Foundation.
00008 
00009     KMail is distributed in the hope that it will be useful, but
00010     WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018     In addition, as a special exception, the copyright holders give
00019     permission to link the code of this program with any edition of
00020     the Qt library by Trolltech AS, Norway (or with modified versions
00021     of Qt that use the same license as Qt), and distribute linked
00022     combinations including the two.  You must obey the GNU General
00023     Public License in all respects for all of the code used other than
00024     Qt.  If you modify this file, you may extend this exception to
00025     your version of the file, but you are not obligated to do so.  If
00026     you do not wish to do so, delete this exception statement from
00027     your version.
00028 */
00029 #ifndef KMAIL_ANTISPAMWIZARD_H
00030 #define KMAIL_ANTISPAMWIZARD_H
00031 
00032 #include "simplefoldertree.h"
00033 
00034 #include <kconfig.h>
00035 #include <kwizard.h>
00036 
00037 #include <qcheckbox.h>
00038 #include <qdict.h>
00039 
00040 class KActionCollection;
00041 class KMFolderTree;
00042 class QLabel;
00043 
00044 namespace KMail {
00045 
00046   class ASWizInfoPage;
00047   class ASWizProgramsPage;
00048   class ASWizSpamRulesPage;
00049   class ASWizVirusRulesPage;
00050 
00051   //---------------------------------------------------------------------------
00094   class AntiSpamWizard : public KWizard
00095   {
00096     Q_OBJECT
00097 
00098     public:
00102       enum WizardMode { AntiSpam, AntiVirus };
00103 
00115       AntiSpamWizard( WizardMode mode,
00116                       QWidget * parent, KMFolderTree * mainFolderTree,
00117                       KActionCollection * collection );
00118 
00119     protected:
00121       void accept();
00123       int checkForProgram( QString executable );
00129       class SpamToolConfig
00130       {
00131         public:
00132           SpamToolConfig() {}
00133           SpamToolConfig( QString toolId, int configVersion,
00134                         QString name, QString exec, QString url, QString filter,
00135                         QString detection, QString spam, QString ham,
00136                         QString header, QString pattern, bool regExp,
00137                         bool bayesFilter, WizardMode type );
00138 
00139           int getVersion() const { return mVersion; }
00140           QString getId()  const { return mId; }
00141           QString getVisibleName()  const { return mVisibleName; }
00142           QString getExecutable() const { return mExecutable; }
00143           QString getWhatsThisText() const { return mWhatsThisText; }
00144           QString getFilterName() const { return mFilterName; }
00145           QString getDetectCmd() const { return mDetectCmd; }
00146           QString getSpamCmd() const { return mSpamCmd; }
00147           QString getHamCmd() const { return mHamCmd; }
00148           QString getDetectionHeader() const { return mDetectionHeader; }
00149           QString getDetectionPattern() const { return mDetectionPattern; }
00150           bool isUseRegExp() const { return mUseRegExp; }
00151           bool useBayesFilter() const { return mSupportsBayesFilter; }
00152           WizardMode getType() const { return mType; }
00153           // convinience methods for types
00154           bool isSpamTool() const { return ( mType == AntiSpam ); }
00155           bool isVirusTool() const { return ( mType == AntiVirus ); }
00156 
00157         private:
00158           // used to identifiy configs for the same tool
00159           QString mId;
00160           // The version of the config data, used for merging and
00161           // detecting newer configs
00162           int mVersion;
00163           // the name as shown by the checkbox in the dialog page
00164           QString mVisibleName;
00165           // the command to check the existance of the tool
00166           QString mExecutable;
00167           // the What's This help text (e.g. url for the tool)
00168           QString mWhatsThisText;
00169           // name for the created filter in the filter list
00170           QString mFilterName;
00171           // pipe through cmd used to detect spam messages
00172           QString mDetectCmd;
00173           // pipe through cmd to let the tool learn a spam message
00174           QString mSpamCmd;
00175           // pipe through cmd to let the tool learn a ham message
00176           QString mHamCmd;
00177           // by which header are messages marked as spam
00178           QString mDetectionHeader;
00179           // what header pattern is used to mark spam messages
00180           QString mDetectionPattern;
00181           // filter searches for the pattern by regExp or contain rule
00182           bool mUseRegExp;
00183           // can the tool learn spam and ham, has it a bayesian algorithm
00184           bool mSupportsBayesFilter;
00185           // Is the tool AntiSpam or AntiVirus
00186           WizardMode mType;
00187       };
00193       class ConfigReader
00194       {
00195         public:
00196           ConfigReader( WizardMode mode,
00197                         QValueList<SpamToolConfig> & configList );
00198 
00199     ~ConfigReader( );
00200           QValueList<SpamToolConfig> & getToolList() { return mToolList; }
00201 
00202           void readAndMergeConfig();
00203 
00204         private:
00205           QValueList<SpamToolConfig> & mToolList;
00206           KConfig *mConfig;
00207           WizardMode mMode;
00208 
00209           SpamToolConfig readToolConfig( KConfigGroup & configGroup );
00210           SpamToolConfig createDummyConfig();
00211 
00212           void mergeToolConfig( SpamToolConfig config );
00213       };
00214 
00215 
00216     protected slots:
00218       void checkProgramsSelections();
00220       void checkSpamRulesSelections();
00222       void checkVirusRulesSelections();
00224       void checkToolAvailability();
00226       void slotHelpClicked();
00227 
00228     private:
00229       /* generic checks if any option in a page is checked */
00230       bool anySpamOptionChecked();
00231       bool anyVirusOptionChecked();
00232 
00233       /* The pages in the wizard */
00234       ASWizInfoPage * mInfoPage;
00235       ASWizProgramsPage * mProgramsPage;
00236       ASWizSpamRulesPage * mSpamRulesPage;
00237       ASWizVirusRulesPage * mVirusRulesPage;
00238 
00239       /* The configured tools and it's settings to be used in the wizard. */
00240       QValueList<SpamToolConfig> mToolList;
00241 
00242       /* The action collection where the filter menu action is searched in */
00243       KActionCollection * mActionCollection;
00244 
00245       /* Are any spam tools selected? */
00246       bool mSpamToolsUsed;
00247       /* Are any virus tools selected? */
00248       bool mVirusToolsUsed;
00249 
00250       WizardMode mMode;
00251   };
00252 
00253 
00254   //---------------------------------------------------------------------------
00255 
00256   //---------------------------------------------------------------------------
00257   class ASWizInfoPage : public QWidget
00258   {
00259     public:
00260       ASWizInfoPage( AntiSpamWizard::WizardMode mode,
00261                      QWidget *parent, const char *name );
00262 
00263       void setScanProgressText( const QString &toolName );
00264 
00265     private:
00266       QLabel *mIntroText;
00267       QLabel *mScanProgressText;
00268   };
00269 
00270   //---------------------------------------------------------------------------
00271   class ASWizProgramsPage : public QWidget
00272   {
00273     Q_OBJECT
00274 
00275     public:
00276       ASWizProgramsPage( QWidget *parent, const char *name,
00277                          QStringList &checkBoxTextList,
00278                          QStringList &checkBoxWhatsThisList );
00279 
00280       bool isProgramSelected( const QString &visibleName );
00281       void setProgramAsFound( const QString &visibleName, bool found );
00282 
00283     private slots:
00284       void processSelectionChange();
00285 
00286     signals:
00287       void selectionChanged();
00288 
00289     private:
00290       QDict<QCheckBox> mProgramDict;
00291   };
00292 
00293   //---------------------------------------------------------------------------
00294   class ASWizSpamRulesPage : public QWidget
00295   {
00296     Q_OBJECT
00297 
00298     public:
00299       ASWizSpamRulesPage( QWidget * parent, const char * name, KMFolderTree * mainFolderTree );
00300 
00301       bool pipeRulesSelected() const;
00302       bool classifyRulesSelected() const;
00303       bool moveRulesSelected() const;
00304       bool markReadRulesSelected() const;
00305 
00306       QString selectedFolderName() const;
00307       void allowClassification( bool enabled );
00308 
00309     private slots:
00310       void processSelectionChange();
00311 
00312     signals:
00313       void selectionChanged();
00314 
00315     private:
00316       QCheckBox * mPipeRules;
00317       QCheckBox * mClassifyRules;
00318       QCheckBox * mMoveRules;
00319       SimpleFolderTree *mFolderTree;
00320       QCheckBox * mMarkRules;
00321   };
00322 
00323   //-------------------------------------------------------------------------
00324   class ASWizVirusRulesPage : public QWidget
00325   {
00326     Q_OBJECT
00327 
00328     public:
00329       ASWizVirusRulesPage( QWidget * parent, const char * name, KMFolderTree * mainFolderTree );
00330 
00331       bool pipeRulesSelected() const;
00332       bool moveRulesSelected() const;
00333       bool markReadRulesSelected() const;
00334 
00335       QString selectedFolderName() const;
00336 
00337     private slots:
00338       void processSelectionChange();
00339     signals:
00340       void selectionChanged();
00341 
00342     private:
00343       QCheckBox * mPipeRules;
00344       QCheckBox * mMoveRules;
00345       SimpleFolderTree *mFolderTree;
00346       QCheckBox * mMarkRules;
00347   };
00348 
00349 
00350 } // namespace KMail
00351 
00352 #endif // KMAIL_ANTISPAMWIZARD_H
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 23 18:21:04 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003