kmail

messageproperty.cpp
1 /* Message Property
2 
3  This file is part of KMail, the KDE mail client.
4  Copyright (c) Don Sanders <sanders@kde.org>
5 
6  KMail is free software; you can redistribute it and/or modify it
7  under the terms of the GNU General Public License, version 2, as
8  published by the Free Software Foundation.
9 
10  KMail is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19  In addition, as a special exception, the copyright holders give
20  permission to link the code of this program with any edition of
21  the TQt library by Trolltech AS, Norway (or with modified versions
22  of TQt that use the same license as TQt), and distribute linked
23  combinations including the two. You must obey the GNU General
24  Public License in all respects for all of the code used other than
25  TQt. If you modify this file, you may extend this exception to
26  your version of the file, but you are not obligated to do so. If
27  you do not wish to do so, delete this exception statement from
28  your version.
29 */
30 
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 
35 #include "messageproperty.h"
36 using namespace KMail;
37 
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;
42 
43 bool MessageProperty::filtering( TQ_UINT32 serNum )
44 {
45  return sFolders.contains( serNum );
46 }
47 
48 void MessageProperty::setFiltering( TQ_UINT32 serNum, bool filter )
49 {
50  assert(!filtering(serNum) || !filter);
51  if (filter && !filtering(serNum))
52  sFolders.replace(serNum, TQGuardedPtr<KMFolder>(0) );
53  else if (!filter)
54  sFolders.remove(serNum);
55 }
56 
57 bool MessageProperty::filtering( const KMMsgBase *msgBase )
58 {
59  return filtering( msgBase->getMsgSerNum() );
60 }
61 
62 void MessageProperty::setFiltering( const KMMsgBase *msgBase, bool filter )
63 {
64  setFiltering( msgBase->getMsgSerNum(), filter );
65 }
66 
67 KMFolder* MessageProperty::filterFolder( TQ_UINT32 serNum )
68 {
69  TQMap<TQ_UINT32, TQGuardedPtr<KMFolder> >::const_iterator it = sFolders.find( serNum );
70  return it == sFolders.constEnd() ? 0 : (*it).operator->();
71 }
72 
73 void MessageProperty::setFilterFolder( TQ_UINT32 serNum, KMFolder* folder )
74 {
75  sFolders.insert(serNum, TQGuardedPtr<KMFolder>(folder) );
76 }
77 
78 KMFolder* MessageProperty::filterFolder( const KMMsgBase *msgBase )
79 {
80  return filterFolder( msgBase->getMsgSerNum() );
81 }
82 
83 void MessageProperty::setFilterFolder( const KMMsgBase *msgBase, KMFolder* folder )
84 {
85  setFilterFolder( msgBase->getMsgSerNum(), folder );
86 }
87 
88 ActionScheduler* MessageProperty::filterHandler( TQ_UINT32 serNum )
89 {
90  TQMap<TQ_UINT32, TQGuardedPtr<ActionScheduler> >::const_iterator it = sHandlers.find( serNum );
91  return it == sHandlers.constEnd() ? 0 : (*it).operator->();
92 }
93 
94 void MessageProperty::setFilterHandler( TQ_UINT32 serNum, ActionScheduler* handler )
95 {
96  if (handler)
97  sHandlers.insert( serNum, TQGuardedPtr<ActionScheduler>(handler) );
98  else
99  sHandlers.remove( serNum );
100 }
101 
102 ActionScheduler* MessageProperty::filterHandler( const KMMsgBase *msgBase )
103 {
104  return filterHandler( msgBase->getMsgSerNum() );
105 }
106 
107 void MessageProperty::setFilterHandler( const KMMsgBase *msgBase, ActionScheduler* handler )
108 {
109  setFilterHandler( msgBase->getMsgSerNum(), handler );
110 }
111 
112 bool MessageProperty::transferInProgress( TQ_UINT32 serNum )
113 {
114  TQMap<TQ_UINT32, int >::const_iterator it = sTransfers.find( serNum );
115  return it == sTransfers.constEnd() ? false : *it;
116 }
117 
118 void MessageProperty::setTransferInProgress( TQ_UINT32 serNum, bool transfer, bool force )
119 {
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;
126  else
127  transfer ? ++transferInProgress : --transferInProgress;
128  if ( transferInProgress < 0 )
129  transferInProgress = 0;
130  if (transferInProgress)
131  sTransfers.insert( serNum, transferInProgress );
132  else
133  sTransfers.remove( serNum );
134 }
135 
136 bool MessageProperty::transferInProgress( const KMMsgBase *msgBase )
137 {
138  return transferInProgress( msgBase->getMsgSerNum() );
139 }
140 
141 void MessageProperty::setTransferInProgress( const KMMsgBase *msgBase, bool transfer, bool force )
142 {
143  setTransferInProgress( msgBase->getMsgSerNum(), transfer, force );
144 }
145 
146 TQ_UINT32 MessageProperty::serialCache( const KMMsgBase *msgBase )
147 {
148  TQMap<const KMMsgBase*, long >::const_iterator it = sSerialCache.find( msgBase );
149  return it == sSerialCache.constEnd() ? 0 : *it;
150 }
151 
152 void MessageProperty::setSerialCache( const KMMsgBase *msgBase, TQ_UINT32 serNum )
153 {
154  if (serNum)
155  sSerialCache.insert( msgBase, serNum );
156  else
157  sSerialCache.remove( msgBase );
158 }
159 
160 void MessageProperty::forget( const KMMsgBase *msgBase )
161 {
162  TQ_UINT32 serNum = serialCache( msgBase );
163  if (serNum) {
164  Q_ASSERT( !transferInProgress( serNum ) );
165  sTransfers.remove( serNum );
166  sSerialCache.remove( msgBase );
167  }
168 }
169 
170 #include "messageproperty.moc"
Mail folder.
Definition: kmfolder.h:69
int find(const KMMsgBase *msg) const
Returns the index of the given message or -1 if not found.
Definition: kmfolder.cpp:435
folderdiaquotatab.h
Definition: aboutdata.cpp:40