kmail

messageproperty.cpp

Go to the documentation of this file.
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 QMap<Q_UINT32, QGuardedPtr<KMFolder> > MessageProperty::sFolders;
00039 QMap<Q_UINT32, QGuardedPtr<ActionScheduler> > MessageProperty::sHandlers;
00040 QMap<Q_UINT32, int > MessageProperty::sTransfers;
00041 QMap<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, QGuardedPtr<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   if (sFolders.contains(serNum))
00070     return sFolders[serNum].operator->();
00071   return 0;
00072 }
00073 
00074 void MessageProperty::setFilterFolder( Q_UINT32 serNum, KMFolder* folder )
00075 {
00076   sFolders.replace(serNum, QGuardedPtr<KMFolder>(folder) );
00077 }
00078 
00079 KMFolder* MessageProperty::filterFolder( const KMMsgBase *msgBase )
00080 {
00081   return filterFolder( msgBase->getMsgSerNum() );
00082 }
00083 
00084 void MessageProperty::setFilterFolder( const KMMsgBase *msgBase, KMFolder* folder )
00085 {
00086   setFilterFolder( msgBase->getMsgSerNum(), folder );
00087 }
00088 
00089 ActionScheduler* MessageProperty::filterHandler( Q_UINT32 serNum )
00090 {
00091   if ( sHandlers.contains( serNum ))
00092     return sHandlers[serNum].operator->();
00093   return 0;
00094 }
00095 
00096 void MessageProperty::setFilterHandler( Q_UINT32 serNum, ActionScheduler* handler )
00097 {
00098   if (handler)
00099     sHandlers.replace( serNum, QGuardedPtr<ActionScheduler>(handler) );
00100   else
00101     sHandlers.remove( serNum );
00102 }
00103 
00104 ActionScheduler* MessageProperty::filterHandler( const KMMsgBase *msgBase )
00105 {
00106   return filterHandler( msgBase->getMsgSerNum() );
00107 }
00108 
00109 void MessageProperty::setFilterHandler( const KMMsgBase *msgBase, ActionScheduler* handler )
00110 {
00111   setFilterHandler( msgBase->getMsgSerNum(), handler );
00112 }
00113 
00114 bool MessageProperty::transferInProgress( Q_UINT32 serNum )
00115 {
00116   if (sTransfers.contains(serNum))
00117     return sTransfers[serNum];
00118   return false;
00119 }
00120 
00121 void MessageProperty::setTransferInProgress( Q_UINT32 serNum, bool transfer, bool force )
00122 {
00123   int transferInProgress = 0;
00124   if (sTransfers.contains(serNum))
00125     transferInProgress = sTransfers[serNum];
00126   if ( force && !transfer )
00127     transferInProgress = 0;
00128   else
00129     transfer ? ++transferInProgress : --transferInProgress;
00130   if ( transferInProgress < 0 )
00131     transferInProgress = 0;
00132   if (transferInProgress)
00133     sTransfers.replace( serNum, transferInProgress );
00134   else
00135     sTransfers.remove( serNum );
00136 }
00137 
00138 bool MessageProperty::transferInProgress( const KMMsgBase *msgBase )
00139 {
00140   return transferInProgress( msgBase->getMsgSerNum() );
00141 }
00142 
00143 void MessageProperty::setTransferInProgress( const KMMsgBase *msgBase, bool transfer, bool force )
00144 {
00145   setTransferInProgress( msgBase->getMsgSerNum(), transfer, force );
00146 }
00147 
00148 Q_UINT32 MessageProperty::serialCache( const KMMsgBase *msgBase )
00149 {
00150   if (sSerialCache.contains( msgBase ))
00151     return sSerialCache[msgBase];
00152   return 0;
00153 }
00154 
00155 void MessageProperty::setSerialCache( const KMMsgBase *msgBase, Q_UINT32 serNum )
00156 {
00157   if (serNum)
00158     sSerialCache.replace( msgBase, serNum );
00159   else
00160     sSerialCache.remove( msgBase );
00161 }
00162 
00163 void MessageProperty::forget( const KMMsgBase *msgBase )
00164 {
00165   Q_UINT32 serNum = serialCache( msgBase );
00166   if (serNum) {
00167     Q_ASSERT( !transferInProgress( serNum ) );
00168     sTransfers.remove( serNum );
00169     sSerialCache.remove( msgBase );
00170   }
00171 }
00172 
00173 #include "messageproperty.moc"