kmail

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