35 #include "messageproperty.h"
36 using namespace KMail;
38 TQMap<TQ_UINT32, TQGuardedPtr<KMFolder> > MessageProperty::sFolders;
39 TQMap<TQ_UINT32, TQGuardedPtr<ActionScheduler> > MessageProperty::sHandlers;
40 TQMap<TQ_UINT32, int > MessageProperty::sTransfers;
41 TQMap<const KMMsgBase*, long > MessageProperty::sSerialCache;
43 bool MessageProperty::filtering( TQ_UINT32 serNum )
45 return sFolders.contains( serNum );
48 void MessageProperty::setFiltering( TQ_UINT32 serNum,
bool filter )
50 assert(!filtering(serNum) || !filter);
51 if (filter && !filtering(serNum))
52 sFolders.replace(serNum, TQGuardedPtr<KMFolder>(0) );
54 sFolders.remove(serNum);
57 bool MessageProperty::filtering(
const KMMsgBase *msgBase )
59 return filtering( msgBase->getMsgSerNum() );
62 void MessageProperty::setFiltering(
const KMMsgBase *msgBase,
bool filter )
64 setFiltering( msgBase->getMsgSerNum(), filter );
67 KMFolder* MessageProperty::filterFolder( TQ_UINT32 serNum )
69 TQMap<TQ_UINT32, TQGuardedPtr<KMFolder> >::const_iterator it = sFolders.
find( serNum );
70 return it == sFolders.constEnd() ? 0 : (*it).operator->();
73 void MessageProperty::setFilterFolder( TQ_UINT32 serNum,
KMFolder* folder )
75 sFolders.insert(serNum, TQGuardedPtr<KMFolder>(folder) );
78 KMFolder* MessageProperty::filterFolder(
const KMMsgBase *msgBase )
80 return filterFolder( msgBase->getMsgSerNum() );
83 void MessageProperty::setFilterFolder(
const KMMsgBase *msgBase,
KMFolder* folder )
85 setFilterFolder( msgBase->getMsgSerNum(), folder );
88 ActionScheduler* MessageProperty::filterHandler( TQ_UINT32 serNum )
90 TQMap<TQ_UINT32, TQGuardedPtr<ActionScheduler> >::const_iterator it = sHandlers.find( serNum );
91 return it == sHandlers.constEnd() ? 0 : (*it).operator->();
94 void MessageProperty::setFilterHandler( TQ_UINT32 serNum, ActionScheduler* handler )
97 sHandlers.insert( serNum, TQGuardedPtr<ActionScheduler>(handler) );
99 sHandlers.remove( serNum );
102 ActionScheduler* MessageProperty::filterHandler(
const KMMsgBase *msgBase )
104 return filterHandler( msgBase->getMsgSerNum() );
107 void MessageProperty::setFilterHandler(
const KMMsgBase *msgBase, ActionScheduler* handler )
109 setFilterHandler( msgBase->getMsgSerNum(), handler );
112 bool MessageProperty::transferInProgress( TQ_UINT32 serNum )
114 TQMap<TQ_UINT32, int >::const_iterator it = sTransfers.find( serNum );
115 return it == sTransfers.constEnd() ? false : *it;
118 void MessageProperty::setTransferInProgress( TQ_UINT32 serNum,
bool transfer,
bool force )
120 int transferInProgress = 0;
121 TQMap<TQ_UINT32, int >::const_iterator it = sTransfers.find( serNum );
122 if (it != sTransfers.constEnd())
123 transferInProgress = *it;
124 if ( force && !transfer )
125 transferInProgress = 0;
127 transfer ? ++transferInProgress : --transferInProgress;
128 if ( transferInProgress < 0 )
129 transferInProgress = 0;
130 if (transferInProgress)
131 sTransfers.insert( serNum, transferInProgress );
133 sTransfers.remove( serNum );
136 bool MessageProperty::transferInProgress(
const KMMsgBase *msgBase )
138 return transferInProgress( msgBase->getMsgSerNum() );
141 void MessageProperty::setTransferInProgress(
const KMMsgBase *msgBase,
bool transfer,
bool force )
143 setTransferInProgress( msgBase->getMsgSerNum(), transfer, force );
146 TQ_UINT32 MessageProperty::serialCache(
const KMMsgBase *msgBase )
148 TQMap<const KMMsgBase*, long >::const_iterator it = sSerialCache.find( msgBase );
149 return it == sSerialCache.constEnd() ? 0 : *it;
152 void MessageProperty::setSerialCache(
const KMMsgBase *msgBase, TQ_UINT32 serNum )
155 sSerialCache.insert( msgBase, serNum );
157 sSerialCache.remove( msgBase );
160 void MessageProperty::forget(
const KMMsgBase *msgBase )
162 TQ_UINT32 serNum = serialCache( msgBase );
164 Q_ASSERT( !transferInProgress( serNum ) );
165 sTransfers.remove( serNum );
166 sSerialCache.remove( msgBase );
170 #include "messageproperty.moc"
int find(const KMMsgBase *msg) const
Returns the index of the given message or -1 if not found.