kmail

messageproperty.cpp

00001 /*  Message Property
00002 
00003     This file is part of KMail, the KDE mail client.
00004     Copyright (c) Don Sanders <sanders@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 
00031 #ifdef HAVE_CONFIG_H
00032 #include <config.h>
00033 #endif
00034 
00035 #include "messageproperty.h"
00036 using namespace KMail;
00037 
00038 TQMap<Q_UINT32, TQGuardedPtr<KMFolder> > MessageProperty::sFolders;
00039 TQMap<Q_UINT32, TQGuardedPtr<ActionScheduler> > MessageProperty::sHandlers;
00040 TQMap<Q_UINT32, int > MessageProperty::sTransfers;
00041 TQMap<const KMMsgBase*, long > MessageProperty::sSerialCache;
00042 
00043 bool MessageProperty::filtering( Q_UINT32 serNum )
00044 {
00045   return sFolders.contains( serNum );
00046 }
00047 
00048 void MessageProperty::setFiltering( Q_UINT32 serNum, bool filter )
00049 {
00050   assert(!filtering(serNum) || !filter);
00051   if (filter && !filtering(serNum))
00052     sFolders.replace(serNum, TQGuardedPtr<KMFolder>(0) );
00053   else if (!filter)
00054     sFolders.remove(serNum);
00055 }
00056 
00057 bool MessageProperty::filtering( const KMMsgBase *msgBase )
00058 {
00059   return filtering( msgBase->getMsgSerNum() );
00060 }
00061 
00062 void MessageProperty::setFiltering( const KMMsgBase *msgBase, bool filter )
00063 {
00064   setFiltering( msgBase->getMsgSerNum(), filter );
00065 }
00066 
00067 KMFolder* MessageProperty::filterFolder( Q_UINT32 serNum )
00068 {
00069   TQMap<Q_UINT32, TQGuardedPtr<KMFolder> >::const_iterator it = sFolders.find( serNum );
00070   return it == sFolders.constEnd() ? 0 : (*it).operator->();
00071 }
00072 
00073 void MessageProperty::setFilterFolder( Q_UINT32 serNum, KMFolder* folder )
00074 {
00075   sFolders.insert(serNum, TQGuardedPtr<KMFolder>(folder) );
00076 }
00077 
00078 KMFolder* MessageProperty::filterFolder( const KMMsgBase *msgBase )
00079 {
00080   return filterFolder( msgBase->getMsgSerNum() );
00081 }
00082 
00083 void MessageProperty::setFilterFolder( const KMMsgBase *msgBase, KMFolder* folder )
00084 {
00085   setFilterFolder( msgBase->getMsgSerNum(), folder );
00086 }
00087 
00088 ActionScheduler* MessageProperty::filterHandler( Q_UINT32 serNum )
00089 {
00090   TQMap<Q_UINT32, TQGuardedPtr<ActionScheduler> >::const_iterator it = sHandlers.find( serNum );
00091   return it == sHandlers.constEnd() ? 0 : (*it).operator->();
00092 }
00093 
00094 void MessageProperty::setFilterHandler( Q_UINT32 serNum, ActionScheduler* handler )
00095 {
00096   if (handler)
00097     sHandlers.insert( serNum, TQGuardedPtr<ActionScheduler>(handler) );
00098   else
00099     sHandlers.remove( serNum );
00100 }
00101 
00102 ActionScheduler* MessageProperty::filterHandler( const KMMsgBase *msgBase )
00103 {
00104   return filterHandler( msgBase->getMsgSerNum() );
00105 }
00106 
00107 void MessageProperty::setFilterHandler( const KMMsgBase *msgBase, ActionScheduler* handler )
00108 {
00109   setFilterHandler( msgBase->getMsgSerNum(), handler );
00110 }
00111 
00112 bool MessageProperty::transferInProgress( Q_UINT32 serNum )
00113 {
00114   TQMap<Q_UINT32, int >::const_iterator it = sTransfers.find( serNum );
00115   return it == sTransfers.constEnd() ? false : *it;
00116 }
00117 
00118 void MessageProperty::setTransferInProgress( Q_UINT32 serNum, bool transfer, bool force )
00119 {
00120   int transferInProgress = 0;
00121   TQMap<Q_UINT32, int >::const_iterator it = sTransfers.find( serNum );
00122   if (it != sTransfers.constEnd())
00123     transferInProgress = *it;
00124   if ( force && !transfer )
00125     transferInProgress = 0;
00126   else
00127     transfer ? ++transferInProgress : --transferInProgress;
00128   if ( transferInProgress < 0 )
00129     transferInProgress = 0;
00130   if (transferInProgress)
00131     sTransfers.insert( serNum, transferInProgress );
00132   else
00133     sTransfers.remove( serNum );
00134 }
00135 
00136 bool MessageProperty::transferInProgress( const KMMsgBase *msgBase )
00137 {
00138   return transferInProgress( msgBase->getMsgSerNum() );
00139 }
00140 
00141 void MessageProperty::setTransferInProgress( const KMMsgBase *msgBase, bool transfer, bool force )
00142 {
00143   setTransferInProgress( msgBase->getMsgSerNum(), transfer, force );
00144 }
00145 
00146 Q_UINT32 MessageProperty::serialCache( const KMMsgBase *msgBase )
00147 {
00148   TQMap<const KMMsgBase*, long >::const_iterator it = sSerialCache.find( msgBase );
00149   return it == sSerialCache.constEnd() ? 0 : *it;
00150 }
00151 
00152 void MessageProperty::setSerialCache( const KMMsgBase *msgBase, Q_UINT32 serNum )
00153 {
00154   if (serNum)
00155     sSerialCache.insert( msgBase, serNum );
00156   else
00157     sSerialCache.remove( msgBase );
00158 }
00159 
00160 void MessageProperty::forget( const KMMsgBase *msgBase )
00161 {
00162   Q_UINT32 serNum = serialCache( msgBase );
00163   if (serNum) {
00164     Q_ASSERT( !transferInProgress( serNum ) );
00165     sTransfers.remove( serNum );
00166     sSerialCache.remove( msgBase );
00167   }
00168 }
00169 
00170 #include "messageproperty.moc"