kmail

compactionjob.h
00001 /*
00002  * Copyright (c) 2004 David Faure <faure@kde.org>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; version 2 of the License
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00016  *
00017  *  In addition, as a special exception, the copyright holders give
00018  *  permission to link the code of this program with any edition of
00019  *  the TQt library by Trolltech AS, Norway (or with modified versions
00020  *  of TQt that use the same license as TQt), and distribute linked
00021  *  combinations including the two.  You must obey the GNU General
00022  *  Public License in all respects for all of the code used other than
00023  *  TQt.  If you modify this file, you may extend this exception to
00024  *  your version of the file, but you are not obligated to do so.  If
00025  *  you do not wish to do so, delete this exception statement from
00026  *  your version.
00027  */
00028 #ifndef COMPACTIONJOB_H
00029 #define COMPACTIONJOB_H
00030 
00031 #include "jobscheduler.h"
00032 #include <tqstringlist.h>
00033 
00034 namespace KMail {
00035 
00039 class MboxCompactionJob : public ScheduledJob
00040 {
00041   Q_OBJECT
00042   
00043 public:
00045   MboxCompactionJob( KMFolder* folder, bool immediate );
00046   virtual ~MboxCompactionJob();
00047 
00048   int executeNow( bool silent );
00049   virtual void execute() { executeNow( false ); }
00050   virtual void kill();
00051 
00052 private slots:
00053   void slotDoWork();
00054 
00055 private:
00056   // Real folder location, != location in case of symlinks
00057   TQString realLocation() const;
00058   void done( int rc );
00059 
00060 private:
00061   TQTimer mTimer;
00062   TQString mTempName;
00063   FILE *mTmpFile;
00064   off_t mOffset;
00065   int mCurrentIndex;
00066   bool mFolderOpen;
00067   bool mSilent;
00068 };
00069 
00073 class MaildirCompactionJob : public ScheduledJob
00074 {
00075   Q_OBJECT
00076   
00077 public:
00079   MaildirCompactionJob( KMFolder* folder, bool immediate );
00080   virtual ~MaildirCompactionJob();
00081 
00082   int executeNow( bool silent );
00083   virtual void execute() { executeNow( false ); }
00084   virtual void kill();
00085 
00086 private slots:
00087   void slotDoWork();
00088 
00089 private:
00090   void done( int rc );
00091 
00092 private:
00093   TQTimer mTimer;
00094   TQStringList mEntryList;
00095   int mCurrentIndex;
00096   bool mFolderOpen;
00097   bool mSilent;
00098 };
00099 
00101 class ScheduledCompactionTask : public ScheduledTask
00102 {
00103 public:
00106   ScheduledCompactionTask( KMFolder* folder, bool immediate )
00107     : ScheduledTask( folder, immediate ) {}
00108   virtual ~ScheduledCompactionTask() {}
00109   virtual ScheduledJob* run();
00110   virtual int taskTypeId() const { return 2; }
00111 };
00112 
00113 } // namespace
00114 
00115 #endif /* COMPACTIONJOB_H */
00116