kmail

antispamwizard.h

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  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 <kconfig.h>
00033 #include <klistbox.h>
00034 #include <kwizard.h>
00035 
00036 #include <qcheckbox.h>
00037 #include <qdict.h>
00038 #include <qlayout.h>
00039 
00040 class KActionCollection;
00041 class KMFolder;
00042 class KMFolderTree;
00043 class QLabel;
00044 
00045 namespace KMail {
00046 
00047   class SimpleFolderTree;
00048   class FolderRequester;
00049 
00050   class ASWizInfoPage;
00051   class ASWizSpamRulesPage;
00052   class ASWizVirusRulesPage;
00053   class ASWizSummaryPage;
00054 
00055   //---------------------------------------------------------------------------
00103   class AntiSpamWizard : public KWizard
00104   {
00105     Q_OBJECT
00106 
00107     public:
00111       enum WizardMode { AntiSpam, AntiVirus };
00112 
00121       AntiSpamWizard( WizardMode mode,
00122                       QWidget * parent, KMFolderTree * mainFolderTree );
00123 
00124     protected:
00130       class SpamToolConfig
00131       {
00132         public:
00133           SpamToolConfig() {}
00134           SpamToolConfig( QString toolId, int configVersion, int prio,
00135                         QString name, QString exec, QString url, QString filter,
00136                         QString detection, QString spam, QString ham,
00137                         QString header, QString pattern, QString pattern2,
00138                         QString serverPattern,
00139                         bool detectionOnly, bool regExp, bool bayesFilter, 
00140                         bool tristateDetection, WizardMode type );
00141 
00142           int getVersion() const { return mVersion; }
00143           int getPrio() const { return mPrio; }
00144           QString getId()  const { return mId; }
00145           QString getVisibleName()  const { return mVisibleName; }
00146           QString getExecutable() const { return mExecutable; }
00147           QString getWhatsThisText() const { return mWhatsThisText; }
00148           QString getFilterName() const { return mFilterName; }
00149           QString getDetectCmd() const { return mDetectCmd; }
00150           QString getSpamCmd() const { return mSpamCmd; }
00151           QString getHamCmd() const { return mHamCmd; }
00152           QString getDetectionHeader() const { return mDetectionHeader; }
00153           QString getDetectionPattern() const { return mDetectionPattern; }
00154           QString getDetectionPattern2() const { return mDetectionPattern2; }
00155           QString getServerPattern() const { return mServerPattern; }
00156           bool isServerBased() const;
00157           bool isDetectionOnly() const { return mDetectionOnly; }
00158           bool isUseRegExp() const { return mUseRegExp; }
00159           bool useBayesFilter() const { return mSupportsBayesFilter; }
00160           bool hasTristateDetection() const { return mSupportsUnsure; }
00161           WizardMode getType() const { return mType; }
00162           // convinience methods for types
00163           bool isSpamTool() const { return ( mType == AntiSpam ); }
00164           bool isVirusTool() const { return ( mType == AntiVirus ); }
00165 
00166         private:
00167           // used to identifiy configs for the same tool
00168           QString mId;
00169           // The version of the config data, used for merging and
00170           // detecting newer configs
00171           int mVersion;
00172           // the priority of the tool in the list presented to the user
00173           int mPrio;
00174           // the name as shown by the checkbox in the dialog page
00175           QString mVisibleName;
00176           // the command to check the existance of the tool
00177           QString mExecutable;
00178           // the What's This help text (e.g. url for the tool)
00179           QString mWhatsThisText;
00180           // name for the created filter in the filter list
00181           QString mFilterName;
00182           // pipe through cmd used to detect spam messages
00183           QString mDetectCmd;
00184           // pipe through cmd to let the tool learn a spam message
00185           QString mSpamCmd;
00186           // pipe through cmd to let the tool learn a ham message
00187           QString mHamCmd;
00188           // by which header are messages marked as spam
00189           QString mDetectionHeader;
00190           // what header pattern is used to mark spam messages
00191           QString mDetectionPattern;
00192           // what header pattern is used to mark unsure messages
00193           QString mDetectionPattern2;
00194           // what header pattern is used in the account to check for a certain server
00195           QString mServerPattern;
00196           // filter cannot search actively but relies on pattern by regExp or contain rule
00197           bool mDetectionOnly;
00198           // filter searches for the pattern by regExp or contain rule
00199           bool mUseRegExp;
00200           // can the tool learn spam and ham, has it a bayesian algorithm
00201           bool mSupportsBayesFilter;
00202           // differentiate between ham, spam and a third "unsure" state
00203           bool mSupportsUnsure;
00204           // Is the tool AntiSpam or AntiVirus
00205           WizardMode mType;
00206       };
00207 
00213       class ConfigReader
00214       {
00215         public:
00216           ConfigReader( WizardMode mode,
00217                         QValueList<SpamToolConfig> & configList );
00218           ~ConfigReader( );
00219 
00220           QValueList<SpamToolConfig> & getToolList() { return mToolList; }
00221 
00222           void readAndMergeConfig();
00223 
00224         private:
00225           QValueList<SpamToolConfig> & mToolList;
00226           KConfig *mConfig;
00227           WizardMode mMode;
00228 
00229           SpamToolConfig readToolConfig( KConfigGroup & configGroup );
00230           SpamToolConfig createDummyConfig();
00231 
00232           void mergeToolConfig( SpamToolConfig config );
00233           void sortToolList();
00234       };
00235 
00237       void accept();
00238 
00239     protected slots:
00241       void checkProgramsSelections();
00243       void checkVirusRulesSelections();
00245       void checkToolAvailability();
00247       void slotHelpClicked();
00249       void slotBuildSummary();
00250 
00251     private:
00252       /* Check for the availability of an executible along the PATH */
00253       int checkForProgram( const QString &executable );
00254       /* generic checks if any option in a page is checked */
00255       bool anyVirusOptionChecked();
00256       /* convenience method calling the appropriate filter manager method */
00257       const QString uniqueNameFor( const QString & name );
00258       /* convenience method to sort out new and existing filters */
00259       void sortFilterOnExistance( const QString & intendedFilterName,
00260                                   QString & newFilters, 
00261                                   QString & replaceFilters );
00262 
00263       /* The pages in the wizard */
00264       ASWizInfoPage * mInfoPage;
00265       ASWizSpamRulesPage * mSpamRulesPage;
00266       ASWizVirusRulesPage * mVirusRulesPage;
00267       ASWizSummaryPage * mSummaryPage;
00268 
00269       /* The configured tools and it's settings to be used in the wizard. */
00270       QValueList<SpamToolConfig> mToolList;
00271 
00272       /* Are any spam tools selected? */
00273       bool mSpamToolsUsed;
00274       /* Are any virus tools selected? */
00275       bool mVirusToolsUsed;
00276 
00277       WizardMode mMode;
00278   };
00279 
00280 
00281   //---------------------------------------------------------------------------
00282   class ASWizPage : public QWidget
00283   {
00284     public:
00285       ASWizPage( QWidget *parent, const char *name, 
00286                  const QString *bannerName = 0);
00287 
00288     protected:
00289       QBoxLayout *mLayout;
00290 
00291     private:
00292       QPixmap *mPixmap;
00293       QLabel *mBannerLabel;
00294   };
00295 
00296 
00297   //---------------------------------------------------------------------------
00298   class ASWizInfoPage : public ASWizPage
00299   {
00300     Q_OBJECT
00301 
00302     public:
00303       ASWizInfoPage( AntiSpamWizard::WizardMode mode,
00304                      QWidget *parent, const char *name );
00305 
00306       void setScanProgressText( const QString &toolName );
00307       void addAvailableTool( const QString &visibleName );
00308       bool isProgramSelected( const QString &visibleName );
00309 
00310     private slots:
00311       void processSelectionChange();
00312 
00313     signals:
00314       void selectionChanged();
00315 
00316     private:
00317       QLabel *mIntroText;
00318       QLabel *mScanProgressText;
00319       QLabel *mSelectionHint;
00320       KListBox *mToolsList;
00321   };
00322 
00323   //---------------------------------------------------------------------------
00324   class ASWizSpamRulesPage : public ASWizPage
00325   {
00326     Q_OBJECT
00327 
00328     public:
00329       ASWizSpamRulesPage( QWidget * parent, const char * name, KMFolderTree * mainFolderTree );
00330 
00331       bool markAsReadSelected() const;
00332       bool moveSpamSelected() const;
00333       bool moveUnsureSelected() const;
00334 
00335       QString selectedSpamFolderName() const;
00336       QString selectedUnsureFolderName() const;
00337 
00338       void allowUnsureFolderSelection( bool enabled );
00339 
00340     private slots:
00341       void processSelectionChange();
00342       void processSelectionChange( KMFolder* );
00343 
00344     signals:
00345       void selectionChanged();
00346 
00347     private:
00348       QCheckBox * mMarkRules;
00349       QCheckBox * mMoveSpamRules;
00350       QCheckBox * mMoveUnsureRules;
00351       FolderRequester *mFolderReqForSpamFolder;
00352       FolderRequester *mFolderReqForUnsureFolder;
00353   };
00354 
00355   //-------------------------------------------------------------------------
00356   class ASWizVirusRulesPage : public ASWizPage
00357   {
00358     Q_OBJECT
00359 
00360     public:
00361       ASWizVirusRulesPage( QWidget * parent, const char * name, KMFolderTree * mainFolderTree );
00362 
00363       bool pipeRulesSelected() const;
00364       bool moveRulesSelected() const;
00365       bool markReadRulesSelected() const;
00366 
00367       QString selectedFolderName() const;
00368 
00369     private slots:
00370       void processSelectionChange();
00371     signals:
00372       void selectionChanged();
00373 
00374     private:
00375       QCheckBox * mPipeRules;
00376       QCheckBox * mMoveRules;
00377       SimpleFolderTree *mFolderTree;
00378       QCheckBox * mMarkRules;
00379   };
00380 
00381   //---------------------------------------------------------------------------
00382   class ASWizSummaryPage : public ASWizPage
00383   {
00384     Q_OBJECT
00385 
00386     public:
00387       ASWizSummaryPage( QWidget * parent, const char * name );
00388 
00389       void setSummaryText( const QString & text );
00390 
00391     private:
00392       QLabel * mSummaryText;
00393   };
00394 
00395 
00396 } // namespace KMail
00397 
00398 #endif // KMAIL_ANTISPAMWIZARD_H