|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * Item Engine owns the setting items. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "WmlItemEngine.h" // Own |
|
24 #include "WmlBioControl.h" // CWmlBioControl |
|
25 #include "WmlSubItemBase.h" // CWmlSubItemBase |
|
26 #include "WmlFieldParser.h" // CWmlFieldParser |
|
27 #include "WMLBC.hrh" // for panic codes |
|
28 #include "WmlLog.h" |
|
29 #include "WmlBioControl.pan" // for ::Panic() |
|
30 |
|
31 #include <WMLBC.rsg> // resouce identifiers |
|
32 #include <bldvariant.hrh> |
|
33 #include <sysutil.h> |
|
34 #include <eikenv.h> |
|
35 |
|
36 // CONSTANTS |
|
37 const TInt KCheckCurrentSpace = 0; |
|
38 |
|
39 // ================= MEMBER FUNCTIONS ======================= |
|
40 |
|
41 // --------------------------------------------------------- |
|
42 // CWmlItemEngine::NewL |
|
43 // --------------------------------------------------------- |
|
44 CWmlItemEngine* CWmlItemEngine::NewL() |
|
45 { |
|
46 CWmlItemEngine* self = new ( ELeave ) CWmlItemEngine; |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------- |
|
54 // Destructor |
|
55 // --------------------------------------------------------- |
|
56 CWmlItemEngine::~CWmlItemEngine() |
|
57 { |
|
58 //array owns its contents. |
|
59 |
|
60 if ( iBMArray ) |
|
61 { |
|
62 iBMArray->ResetAndDestroy(); |
|
63 delete iBMArray; |
|
64 } |
|
65 |
|
66 // This array only holds pointers to the other arrays. |
|
67 delete iItemArray; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------- |
|
71 // CWmlItemEngine::ConstructL |
|
72 // --------------------------------------------------------- |
|
73 void CWmlItemEngine::ConstructL() |
|
74 { |
|
75 // Precondition is that item array is NULL. |
|
76 __ASSERT_DEBUG( iBMArray == NULL && |
|
77 iItemArray == NULL, |
|
78 Panic( EItemArraysNotNull )); |
|
79 |
|
80 // Create the array for subitems. |
|
81 iBMArray = new (ELeave) CArrayPtrSeg<CWmlSubItemBase>(1); |
|
82 |
|
83 // Collection array, which doesn't own it's items. |
|
84 iItemArray = new (ELeave) CArrayPtrSeg<CWmlSubItemBase>(1); |
|
85 |
|
86 // Postcondition is that item array are created. |
|
87 __ASSERT_DEBUG( iBMArray && |
|
88 iItemArray , |
|
89 Panic( EItemArraysNull )); |
|
90 } |
|
91 |
|
92 void CWmlItemEngine::CheckDiskSpaceL() |
|
93 { |
|
94 RFs& fs = CEikonEnv::Static()->FsSession(); |
|
95 TInt drive = EDriveC; |
|
96 |
|
97 // All the settings go to C-drive |
|
98 if ( SysUtil::DiskSpaceBelowCriticalLevelL(&fs, KCheckCurrentSpace, drive) ) |
|
99 { |
|
100 User::Leave( KErrDiskFull ); |
|
101 } |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------- |
|
105 // CWmlItemEngine::CreateItemArraysL |
|
106 // --------------------------------------------------------- |
|
107 // |
|
108 void CWmlItemEngine::CreateItemArraysL( |
|
109 const CArrayPtrSeg<CParsedField>& aParsedFields ) |
|
110 { |
|
111 // Precondition is that item array don't contain any objects. |
|
112 __ASSERT_DEBUG( iBMArray->Count() == 0, |
|
113 Panic( EItemArraysNotEmpty )); |
|
114 |
|
115 // parse, create iSubItemArray |
|
116 CWmlFieldParser* fieldParser = new (ELeave) CWmlFieldParser; |
|
117 CleanupStack::PushL( fieldParser ); |
|
118 |
|
119 fieldParser->ParseFieldsL( aParsedFields, |
|
120 *iBMArray); |
|
121 CleanupStack::PopAndDestroy( fieldParser ); |
|
122 |
|
123 // Add all the item's to the iItemArray |
|
124 TInt i(0); |
|
125 |
|
126 // Bookmarks |
|
127 for ( i = 0; i < iBMArray->Count(); i++) |
|
128 { |
|
129 iItemArray->AppendL( iBMArray->At( i ) ); |
|
130 } |
|
131 |
|
132 // If we don't have any item's leave now. |
|
133 if ( iItemArray->Count() == 0 ) |
|
134 { |
|
135 User::Leave( KErrMsgBioMessageNotValid ); |
|
136 } |
|
137 |
|
138 // Set the first item initially to current one. |
|
139 SetCurrentItem( 0 ); |
|
140 } |
|
141 |
|
142 |
|
143 // --------------------------------------------------------- |
|
144 // CWmlItemEngine::BookmarkCount() |
|
145 // --------------------------------------------------------- |
|
146 TInt CWmlItemEngine::BookmarkCount() const |
|
147 { |
|
148 return iBMArray->Count(); |
|
149 } |
|
150 |
|
151 |
|
152 // --------------------------------------------------------- |
|
153 // CWmlItemEngine::CurrentItem |
|
154 // --------------------------------------------------------- |
|
155 // |
|
156 CWmlSubItemBase& CWmlItemEngine::CurrentItem() const |
|
157 { |
|
158 __ASSERT_DEBUG( iCurrentItem, Panic( ENoCurrentItemSet )); |
|
159 return *iCurrentItem; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------- |
|
163 // CWmlItemEngine::SetCurrentItem |
|
164 // --------------------------------------------------------- |
|
165 // |
|
166 void CWmlItemEngine::SetCurrentItem( const TInt aIndex ) |
|
167 { |
|
168 __ASSERT_DEBUG( aIndex >= 0 && aIndex < iItemArray->Count(), |
|
169 Panic( EIndexOutOfBounds )); |
|
170 __ASSERT_DEBUG( iItemArray, Panic( EItemArrayNull )); |
|
171 |
|
172 iCurrentItem = iItemArray->At( aIndex ); |
|
173 |
|
174 __ASSERT_DEBUG( iCurrentItem, Panic( ENoCurrentItemSet )); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------- |
|
178 // CWmlBioControl::SaveCurrentItemL |
|
179 // --------------------------------------------------------- |
|
180 // |
|
181 void CWmlItemEngine::SaveCurrentItemL() |
|
182 { |
|
183 __ASSERT_DEBUG( iCurrentItem, Panic( ENoCurrentItemSet )); |
|
184 |
|
185 CheckDiskSpaceL(); |
|
186 |
|
187 iCurrentItem->SaveItemL( ETrue, ETrue, EFalse, ETrue ); |
|
188 } |
|
189 |
|
190 // End of File |
|
191 |