25
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: ESMR policy implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
//<cmail>
|
|
20 |
#include "emailtrace.h"
|
|
21 |
#include "cesmrpolicy.h"
|
|
22 |
|
|
23 |
#include <e32base.h>
|
|
24 |
#include <coemain.h>
|
|
25 |
#include <barsread.h>
|
|
26 |
|
|
27 |
#include "esmrdef.h"
|
|
28 |
//</cmail>
|
|
29 |
#include "tesmrentryfield.h"
|
|
30 |
|
|
31 |
/// Unnamed namespace for local definitions
|
|
32 |
namespace {
|
|
33 |
|
|
34 |
// Definition for flag position
|
|
35 |
const TInt KFlagPosition = 1;
|
|
36 |
|
|
37 |
#ifdef _DEBUG
|
|
38 |
|
|
39 |
// Definition for min flag position
|
|
40 |
const TInt KMinFlagPosition = 0;
|
|
41 |
|
|
42 |
// Definition for policy panic string
|
|
43 |
_LIT( KESMRPolicy, "ESMRPolicy" );
|
|
44 |
|
|
45 |
// Policy panic codes
|
|
46 |
enum TESMRPolicyPanic
|
|
47 |
{
|
|
48 |
EESMRPolicyInvalidCommand = 1, // Invalid command
|
|
49 |
EESMRPolicyInvalidRole // Invalid role
|
|
50 |
};
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Raises policy panic.
|
|
54 |
*
|
|
55 |
* @param aPanic Panic code.
|
|
56 |
*/
|
|
57 |
void Panic( TESMRPolicyPanic aPanic )
|
|
58 |
{
|
|
59 |
|
|
60 |
User::Panic( KESMRPolicy, aPanic );
|
|
61 |
}
|
|
62 |
|
|
63 |
#endif
|
|
64 |
|
|
65 |
/**
|
|
66 |
* Reads ESMR field table from resource.
|
|
67 |
*
|
|
68 |
* @param aReader Reference to resource reader.
|
|
69 |
* @param aFieldTable Reference to field table.
|
|
70 |
*/
|
|
71 |
void ReadESMRFieldTableL(
|
|
72 |
TResourceReader& aReader,
|
|
73 |
RArray<TESMREntryField>& aFieldTable )
|
|
74 |
{
|
|
75 |
// The first WORD contains the number
|
|
76 |
// of DATA structs within the resource
|
|
77 |
TInt numOfFields = aReader.ReadInt16();
|
|
78 |
|
|
79 |
for (TInt i(0); i < numOfFields; i++ )
|
|
80 |
{
|
|
81 |
TESMREntryField field;
|
|
82 |
|
|
83 |
field.iFieldId =
|
|
84 |
static_cast<TESMREntryFieldId>( aReader.ReadInt16() );
|
|
85 |
|
|
86 |
field.iFieldViewMode =
|
|
87 |
static_cast<TESMRFieldType>( aReader.ReadInt16() );
|
|
88 |
|
|
89 |
field.iFieldMode =
|
|
90 |
static_cast<TESMRFieldMode>( aReader.ReadInt16() );
|
|
91 |
|
|
92 |
aFieldTable.AppendL(field);
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
|
96 |
/**
|
|
97 |
* Reads ESMR command table from resource.
|
|
98 |
*
|
|
99 |
* @param aReader Reference to resource reader.
|
|
100 |
* @param aCommandTable Reference to command table.
|
|
101 |
*/
|
|
102 |
void ReadESMRCommandTableL(
|
|
103 |
TResourceReader& aReader,
|
|
104 |
RArray<TESMRCommand>& aCommandTable )
|
|
105 |
{
|
|
106 |
// The first WORD contains the number
|
|
107 |
// of DATA structs within the resource
|
|
108 |
TInt numOfFields = aReader.ReadInt16();
|
|
109 |
for (TInt i(0); i < numOfFields; i++ )
|
|
110 |
{
|
|
111 |
TESMRCommand command =
|
|
112 |
static_cast<TESMRCommand>( aReader.ReadInt32());
|
|
113 |
aCommandTable.AppendL(command);
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
/**
|
|
118 |
* Compares entry fields by id.
|
|
119 |
*
|
|
120 |
* @param @aLhs Reference to left hand side object
|
|
121 |
* @param @aRhs Reference to right hand side object
|
|
122 |
*/
|
|
123 |
TBool MatchesById(
|
|
124 |
const TESMREntryField &aLhs,
|
|
125 |
const TESMREntryField &aRhs )
|
|
126 |
{
|
|
127 |
return aLhs.iFieldId == aRhs.iFieldId;
|
|
128 |
}
|
|
129 |
|
|
130 |
} // namespace
|
|
131 |
|
|
132 |
// ======== MEMBER FUNCTIONS ========
|
|
133 |
|
|
134 |
// ---------------------------------------------------------------------------
|
|
135 |
// CESMRPolicy::CESMRPolicy
|
|
136 |
// ---------------------------------------------------------------------------
|
|
137 |
//
|
|
138 |
inline CESMRPolicy::CESMRPolicy()
|
|
139 |
: iPolicyId(EESMRPolicyUnspecified),
|
|
140 |
iViewMode(EESMRViewUndef)
|
|
141 |
{
|
|
142 |
FUNC_LOG;
|
|
143 |
}
|
|
144 |
|
|
145 |
// ---------------------------------------------------------------------------
|
|
146 |
// CESMRPolicy::~CESMRPolicy
|
|
147 |
// ---------------------------------------------------------------------------
|
|
148 |
//
|
|
149 |
EXPORT_C CESMRPolicy::~CESMRPolicy()
|
|
150 |
{
|
|
151 |
FUNC_LOG;
|
|
152 |
iMRFields.Reset();
|
|
153 |
iDefaultCommands.Reset();
|
|
154 |
iAdditionalCommands.Reset();
|
|
155 |
}
|
|
156 |
|
|
157 |
// ---------------------------------------------------------------------------
|
|
158 |
// CESMRPolicy::NewL
|
|
159 |
// ---------------------------------------------------------------------------
|
|
160 |
//
|
|
161 |
EXPORT_C CESMRPolicy* CESMRPolicy::NewL()
|
|
162 |
{
|
|
163 |
FUNC_LOG;
|
|
164 |
|
|
165 |
CESMRPolicy* self = new (ELeave) CESMRPolicy();
|
|
166 |
|
|
167 |
return self;
|
|
168 |
}
|
|
169 |
|
|
170 |
// ---------------------------------------------------------------------------
|
|
171 |
// CESMRPolicy::NewL
|
|
172 |
// ---------------------------------------------------------------------------
|
|
173 |
//
|
|
174 |
EXPORT_C CESMRPolicy* CESMRPolicy::NewL(
|
|
175 |
RResourceFile& aRFile,
|
|
176 |
TResourceReader& aReader )
|
|
177 |
{
|
|
178 |
FUNC_LOG;
|
|
179 |
|
|
180 |
CESMRPolicy* self = new (ELeave) CESMRPolicy();
|
|
181 |
CleanupStack::PushL( self );
|
|
182 |
self->ConstructL( aRFile, aReader );
|
|
183 |
CleanupStack::Pop(self);
|
|
184 |
|
|
185 |
|
|
186 |
return self;
|
|
187 |
}
|
|
188 |
|
|
189 |
// ---------------------------------------------------------------------------
|
|
190 |
// CESMRPolicy::ConstructL
|
|
191 |
// ---------------------------------------------------------------------------
|
|
192 |
//
|
|
193 |
void CESMRPolicy::ConstructL(
|
|
194 |
RResourceFile& aRFile,
|
|
195 |
TResourceReader& aReader )
|
|
196 |
{
|
|
197 |
FUNC_LOG;
|
|
198 |
|
|
199 |
ReadFromResourceL( aRFile, aReader );
|
|
200 |
|
|
201 |
}
|
|
202 |
|
|
203 |
// ---------------------------------------------------------------------------
|
|
204 |
// CESMRPolicy::ReadFromResourceL
|
|
205 |
// ---------------------------------------------------------------------------
|
|
206 |
//
|
|
207 |
void CESMRPolicy::ReadFromResourceL(
|
|
208 |
RResourceFile& aRFile,
|
|
209 |
TResourceReader& aReader )
|
|
210 |
{
|
|
211 |
FUNC_LOG;
|
|
212 |
|
|
213 |
iEventType = static_cast<TESMRCalendarEventType>(aReader.ReadInt16() );
|
|
214 |
iPolicyId = static_cast<TESMRPolicyID>( aReader.ReadInt16() );
|
|
215 |
iViewMode = static_cast<TESMRViewMode>( aReader.ReadInt16() );
|
|
216 |
iRoleFlags.iFlags = aReader.ReadInt16();
|
|
217 |
iAllowedApp = static_cast<TESMRUsingApp>( aReader.ReadInt16() );
|
|
218 |
|
|
219 |
TInt defaultFieldIdLink = aReader.ReadInt32();
|
|
220 |
TInt defaultCommandLink = aReader.ReadInt32();
|
|
221 |
TInt additionalCommandLink = aReader.ReadInt32();
|
|
222 |
|
|
223 |
HBufC8* resourceBuffer = NULL;
|
|
224 |
|
|
225 |
iMRFields.Reset();
|
|
226 |
if ( defaultFieldIdLink )
|
|
227 |
{
|
|
228 |
resourceBuffer = aRFile.AllocReadLC(defaultFieldIdLink);
|
|
229 |
aReader.SetBuffer(resourceBuffer);
|
|
230 |
ReadESMRFieldTableL( aReader, iMRFields );
|
|
231 |
CleanupStack::PopAndDestroy( resourceBuffer );
|
|
232 |
resourceBuffer = NULL;
|
|
233 |
}
|
|
234 |
|
|
235 |
iDefaultCommands.Reset();
|
|
236 |
if ( defaultCommandLink )
|
|
237 |
{
|
|
238 |
resourceBuffer = aRFile.AllocReadLC(defaultCommandLink);
|
|
239 |
aReader.SetBuffer(resourceBuffer);
|
|
240 |
ReadESMRCommandTableL( aReader, iDefaultCommands );
|
|
241 |
CleanupStack::PopAndDestroy( resourceBuffer );
|
|
242 |
resourceBuffer = NULL;
|
|
243 |
}
|
|
244 |
|
|
245 |
iAdditionalCommands.Reset();
|
|
246 |
if ( additionalCommandLink )
|
|
247 |
{
|
|
248 |
resourceBuffer = aRFile.AllocReadLC(additionalCommandLink);
|
|
249 |
aReader.SetBuffer(resourceBuffer);
|
|
250 |
ReadESMRCommandTableL( aReader, iAdditionalCommands );
|
|
251 |
CleanupStack::PopAndDestroy( resourceBuffer );
|
|
252 |
resourceBuffer = NULL;
|
|
253 |
}
|
|
254 |
|
|
255 |
}
|
|
256 |
|
|
257 |
// ---------------------------------------------------------------------------
|
|
258 |
// CESMRPolicy::IsFieldIncluded
|
|
259 |
// ---------------------------------------------------------------------------
|
|
260 |
//
|
|
261 |
EXPORT_C TBool CESMRPolicy::IsFieldIncluded(
|
|
262 |
TESMREntryFieldId aFieldId ) const
|
|
263 |
{
|
|
264 |
FUNC_LOG;
|
|
265 |
|
|
266 |
TESMREntryField field;
|
|
267 |
field.iFieldId = aFieldId;
|
|
268 |
|
|
269 |
TInt index = iMRFields.Find( field, MatchesById );
|
|
270 |
|
|
271 |
|
|
272 |
return index != KErrNotFound;
|
|
273 |
}
|
|
274 |
|
|
275 |
|
|
276 |
// ---------------------------------------------------------------------------
|
|
277 |
// CESMRPolicy::FieldL
|
|
278 |
// ---------------------------------------------------------------------------
|
|
279 |
//
|
|
280 |
EXPORT_C const TESMREntryField& CESMRPolicy::FieldL(
|
|
281 |
TESMREntryFieldId aFieldId ) const
|
|
282 |
{
|
|
283 |
FUNC_LOG;
|
|
284 |
|
|
285 |
TESMREntryField field;
|
|
286 |
field.iFieldId = aFieldId;
|
|
287 |
|
|
288 |
TInt index = iMRFields.Find( field, MatchesById );
|
|
289 |
if ( KErrNotFound == index )
|
|
290 |
{
|
|
291 |
|
|
292 |
User::Leave( KErrNotFound );
|
|
293 |
}
|
|
294 |
|
|
295 |
|
|
296 |
return iMRFields[index];
|
|
297 |
}
|
|
298 |
|
|
299 |
// ---------------------------------------------------------------------------
|
|
300 |
// CESMRPolicy::IsDefaultCommand
|
|
301 |
// ---------------------------------------------------------------------------
|
|
302 |
//
|
|
303 |
EXPORT_C TBool CESMRPolicy::IsDefaultCommand( TInt aCommand ) const
|
|
304 |
{
|
|
305 |
FUNC_LOG;
|
|
306 |
|
|
307 |
__ASSERT_DEBUG( aCommand >= EESMRCmdAcceptMR,
|
|
308 |
Panic(EESMRPolicyInvalidCommand) );
|
|
309 |
|
|
310 |
TESMRCommand command =
|
|
311 |
static_cast<TESMRCommand>( aCommand );
|
|
312 |
|
|
313 |
TInt commandFound( iDefaultCommands.Find( command ) );
|
|
314 |
|
|
315 |
|
|
316 |
return KErrNotFound != commandFound;
|
|
317 |
}
|
|
318 |
|
|
319 |
// ---------------------------------------------------------------------------
|
|
320 |
// CESMRPolicy::IsAdditionalCommand
|
|
321 |
// ---------------------------------------------------------------------------
|
|
322 |
//
|
|
323 |
EXPORT_C TBool CESMRPolicy::IsAdditionalCommand( TInt aCommand ) const
|
|
324 |
{
|
|
325 |
FUNC_LOG;
|
|
326 |
|
|
327 |
__ASSERT_DEBUG( aCommand > EESMRCmdAcceptMR &&
|
|
328 |
aCommand <= EESMRCmdDeleteMR,
|
|
329 |
Panic(EESMRPolicyInvalidCommand) );
|
|
330 |
|
|
331 |
TESMRCommand command =
|
|
332 |
static_cast<TESMRCommand>( aCommand );
|
|
333 |
|
|
334 |
TInt commandFound( iAdditionalCommands.Find( command ) );
|
|
335 |
|
|
336 |
|
|
337 |
return KErrNotFound != commandFound;
|
|
338 |
}
|
|
339 |
|
|
340 |
|
|
341 |
// -----------------------------------------------------------------------------
|
|
342 |
// CESMRPolicy::IsRoleIncluded
|
|
343 |
// -----------------------------------------------------------------------------
|
|
344 |
//
|
|
345 |
EXPORT_C TBool CESMRPolicy::IsRoleIncluded( TESMRRole aRole ) const
|
|
346 |
{
|
|
347 |
FUNC_LOG;
|
|
348 |
|
|
349 |
TInt flagPosition = static_cast<TInt>(aRole) - KFlagPosition;
|
|
350 |
__ASSERT_DEBUG( aRole >= KMinFlagPosition, Panic(EESMRPolicyInvalidRole) );
|
|
351 |
|
|
352 |
|
|
353 |
return iRoleFlags.IsSet( flagPosition );
|
|
354 |
}
|
|
355 |
|
|
356 |
// -----------------------------------------------------------------------------
|
|
357 |
// CESMRPolicy::EventType
|
|
358 |
// -----------------------------------------------------------------------------
|
|
359 |
//
|
|
360 |
EXPORT_C TESMRCalendarEventType CESMRPolicy::EventType() const
|
|
361 |
{
|
|
362 |
FUNC_LOG;
|
|
363 |
return iEventType;
|
|
364 |
}
|
|
365 |
|
|
366 |
// -----------------------------------------------------------------------------
|
|
367 |
// CESMRPolicy::PolicyId
|
|
368 |
// -----------------------------------------------------------------------------
|
|
369 |
//
|
|
370 |
EXPORT_C TESMRPolicyID CESMRPolicy::PolicyId() const
|
|
371 |
{
|
|
372 |
return iPolicyId;
|
|
373 |
}
|
|
374 |
|
|
375 |
// -----------------------------------------------------------------------------
|
|
376 |
// CESMRPolicy::ViewMode
|
|
377 |
// -----------------------------------------------------------------------------
|
|
378 |
//
|
|
379 |
EXPORT_C TESMRViewMode CESMRPolicy::ViewMode() const
|
|
380 |
{
|
|
381 |
return iViewMode;
|
|
382 |
}
|
|
383 |
|
|
384 |
// -----------------------------------------------------------------------------
|
|
385 |
// CESMRPolicy::Fields
|
|
386 |
// -----------------------------------------------------------------------------
|
|
387 |
//
|
|
388 |
EXPORT_C const RArray<TESMREntryField>& CESMRPolicy::Fields() const
|
|
389 |
{
|
|
390 |
return iMRFields;
|
|
391 |
}
|
|
392 |
|
|
393 |
// -----------------------------------------------------------------------------
|
|
394 |
// CESMRPolicy::AllowedApp
|
|
395 |
// -----------------------------------------------------------------------------
|
|
396 |
//
|
|
397 |
EXPORT_C TESMRUsingApp CESMRPolicy::AllowedApp() const
|
|
398 |
{
|
|
399 |
return iAllowedApp;
|
|
400 |
}
|
|
401 |
|
|
402 |
// EOF
|
|
403 |
|