kmail

folderjob.cpp

Go to the documentation of this file.
00001 /*  -*- mode: C++; c-file-style: "gnu" -*-
00002  *
00003  *  This file is part of KMail, the KDE mail client.
00004  *  Copyright (c) 2003 Zack Rusin <zack@kde.org>
00005  *
00006  *  KMail is free software; you can redistribute it and/or modify it
00007  *  under the terms of the GNU General Public License, version 2, as
00008  *  published by the Free Software Foundation.
00009  *
00010  *  KMail is distributed in the hope that it will be useful, but
00011  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018  *
00019  *  In addition, as a special exception, the copyright holders give
00020  *  permission to link the code of this program with any edition of
00021  *  the Qt library by Trolltech AS, Norway (or with modified versions
00022  *  of Qt that use the same license as Qt), and distribute linked
00023  *  combinations including the two.  You must obey the GNU General
00024  *  Public License in all respects for all of the code used other than
00025  *  Qt.  If you modify this file, you may extend this exception to
00026  *  your version of the file, but you are not obligated to do so.  If
00027  *  you do not wish to do so, delete this exception statement from
00028  *  your version.
00029  */
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include "folderjob.h"
00035 
00036 #include "kmfolder.h"
00037 #include "globalsettings.h"
00038 #include "folderstorage.h"
00039 
00040 #include <kdebug.h>
00041 #include <kio/global.h>
00042 
00043 namespace KMail {
00044 
00045 //----------------------------------------------------------------------------
00046 FolderJob::FolderJob( KMMessage *msg, JobType jt, KMFolder* folder,
00047                           QString partSpecifier )
00048   : mType( jt ), mSrcFolder( 0 ), mDestFolder( folder ), mPartSpecifier( partSpecifier ),
00049     mErrorCode( 0 ),
00050     mPassiveDestructor( false ), mStarted( false )
00051 {
00052   if ( msg ) {
00053     mMsgList.append(msg);
00054     mSets = msg->headerField("X-UID");
00055   }
00056   init();
00057 }
00058 
00059 //----------------------------------------------------------------------------
00060 FolderJob::FolderJob( const QPtrList<KMMessage>& msgList, const QString& sets,
00061                           JobType jt, KMFolder *folder )
00062   : mMsgList( msgList ),mType( jt ),
00063     mSets( sets ), mSrcFolder( 0 ), mDestFolder( folder ),
00064     mErrorCode( 0 ),
00065     mPassiveDestructor( false ), mStarted( false )
00066 {
00067   init();
00068 }
00069 
00070 //----------------------------------------------------------------------------
00071 FolderJob::FolderJob( JobType jt )
00072   : mType( jt ),
00073     mErrorCode( 0 ),
00074     mPassiveDestructor( false ), mStarted( false )
00075 {
00076   init();
00077 }
00078 
00079 //----------------------------------------------------------------------------
00080 void FolderJob::init()
00081 {
00082   switch ( mType ) {
00083   case tListMessages:
00084   case tGetFolder:
00085   case tGetMessage:
00086   case tCheckUidValidity:
00087     mCancellable = true;
00088     break;
00089   default:
00090     mCancellable = false;
00091   }
00092 }
00093 
00094 //----------------------------------------------------------------------------
00095 FolderJob::~FolderJob()
00096 {
00097   if( !mPassiveDestructor ) {
00098     emit result( this );
00099     emit finished();
00100   }
00101 }
00102 
00103 //----------------------------------------------------------------------------
00104 void
00105 FolderJob::start()
00106 {
00107   if (!mStarted)
00108   {
00109     mStarted = true;
00110     execute();
00111   }
00112 }
00113 
00114 //----------------------------------------------------------------------------
00115 void FolderJob::kill()
00116 {
00117   mErrorCode = KIO::ERR_USER_CANCELED;
00118   delete this;
00119 }
00120 
00121 //----------------------------------------------------------------------------
00122 QPtrList<KMMessage>
00123 FolderJob::msgList() const
00124 {
00125   return mMsgList;
00126 }
00127 
00128 }
00129 
00130 #include "folderjob.moc"