|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Phonebook 2 command store. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2CommandStore.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include <MPbk2Command.h> |
|
24 #include <MPbk2MenuCommandObserver.h> |
|
25 |
|
26 // -------------------------------------------------------------------------- |
|
27 // CPbk2CommandStore::CPbk2CommandStore |
|
28 // -------------------------------------------------------------------------- |
|
29 // |
|
30 inline CPbk2CommandStore::CPbk2CommandStore() : |
|
31 iInputBlocker( NULL ) |
|
32 { |
|
33 } |
|
34 |
|
35 // -------------------------------------------------------------------------- |
|
36 // CPbk2CommandStore::~CPbk2CommandStore |
|
37 // -------------------------------------------------------------------------- |
|
38 // |
|
39 CPbk2CommandStore::~CPbk2CommandStore() |
|
40 { |
|
41 iIdleDestructableCommands.Reset(); |
|
42 iIdleDestructableCommands.Close(); |
|
43 iCommandObservers.Reset(); |
|
44 iCommandObservers.Close(); |
|
45 iCommandArray.ResetAndDestroy(); |
|
46 iCommandArray.Close(); |
|
47 delete iIdleDestroyer; |
|
48 delete iInputBlocker; |
|
49 } |
|
50 |
|
51 // -------------------------------------------------------------------------- |
|
52 // CPbk2CommandStore::NewL |
|
53 // -------------------------------------------------------------------------- |
|
54 // |
|
55 EXPORT_C CPbk2CommandStore* CPbk2CommandStore::NewL() |
|
56 { |
|
57 CPbk2CommandStore* self = new ( ELeave ) CPbk2CommandStore; |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop( self ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // -------------------------------------------------------------------------- |
|
65 // CPbk2CommandStore::ConstructL |
|
66 // -------------------------------------------------------------------------- |
|
67 // |
|
68 inline void CPbk2CommandStore::ConstructL() |
|
69 { |
|
70 iIdleDestroyer = CIdle::NewL( CActive::EPriorityIdle ); |
|
71 } |
|
72 |
|
73 // -------------------------------------------------------------------------- |
|
74 // CPbk2CommandStore::AddMenuCommandObserver |
|
75 // -------------------------------------------------------------------------- |
|
76 // |
|
77 void CPbk2CommandStore::AddMenuCommandObserver |
|
78 ( MPbk2MenuCommandObserver& aObserver ) |
|
79 { |
|
80 TRAP_IGNORE( iCommandObservers.AppendL( &aObserver ) ); |
|
81 } |
|
82 |
|
83 |
|
84 // -------------------------------------------------------------------------- |
|
85 // CPbk2CommandStore::RemoveMenuCommandObserver |
|
86 // -------------------------------------------------------------------------- |
|
87 // |
|
88 void CPbk2CommandStore::RemoveMenuCommandObserver |
|
89 ( MPbk2MenuCommandObserver& aObserver ) |
|
90 { |
|
91 TInt index = iCommandObservers.Find( &aObserver ); |
|
92 if ( index > KErrNotFound ) |
|
93 { |
|
94 iCommandObservers.Remove( index ); |
|
95 } |
|
96 } |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 // CPbk2CommandStore::AddAndExecuteCommandL |
|
100 // -------------------------------------------------------------------------- |
|
101 // |
|
102 EXPORT_C void CPbk2CommandStore::AddAndExecuteCommandL |
|
103 ( MPbk2Command* aCommand ) |
|
104 { |
|
105 const TInt KEmpty( 0 ); |
|
106 if ( aCommand ) |
|
107 { |
|
108 // If command array is empty, execute command. |
|
109 // Otherwise delete command to avoid overlapping commands. |
|
110 if ( iCommandArray.Count() == KEmpty ) |
|
111 { |
|
112 // Avoid user input during command execution |
|
113 if( iInputBlocker ) |
|
114 { |
|
115 iInputBlocker->Cancel(); |
|
116 } |
|
117 iInputBlocker = CAknInputBlock::NewCancelHandlerLC( this ); |
|
118 CleanupStack::Pop( iInputBlocker ); |
|
119 iInputBlocker->SetCancelDelete( iInputBlocker ); |
|
120 |
|
121 // notify all command observers |
|
122 for ( TInt i = 0; i < iCommandObservers.Count(); ++i ) |
|
123 { |
|
124 iCommandObservers[i]->PreCommandExecutionL( *aCommand ); |
|
125 } |
|
126 aCommand->AddObserver( *this ); |
|
127 |
|
128 // Some command observers needs always postcommand call, |
|
129 // if ExecuteLD leaves |
|
130 TRAPD( err, aCommand->ExecuteLD() ); |
|
131 if ( err != KErrNone ) |
|
132 { |
|
133 for (TInt i = 0; i < iCommandObservers.Count(); ++i) |
|
134 { |
|
135 // ignore leave, we are leaving anyway after this |
|
136 TRAP_IGNORE |
|
137 ( iCommandObservers[i]->PostCommandExecutionL( *aCommand ) ); |
|
138 } |
|
139 |
|
140 // stop user input blocker |
|
141 if( iInputBlocker ) |
|
142 { |
|
143 iInputBlocker->Cancel(); |
|
144 } |
|
145 |
|
146 User::Leave( err ); |
|
147 } |
|
148 User::LeaveIfError( iCommandArray.Append( aCommand ) ); |
|
149 } |
|
150 else |
|
151 { |
|
152 delete aCommand; |
|
153 aCommand = NULL; |
|
154 } |
|
155 } |
|
156 } |
|
157 |
|
158 // -------------------------------------------------------------------------- |
|
159 // CPbk2CommandStore::CommandFinished |
|
160 // -------------------------------------------------------------------------- |
|
161 // |
|
162 void CPbk2CommandStore::CommandFinished( const MPbk2Command& aCommand ) |
|
163 { |
|
164 // notify all command observers |
|
165 for (TInt i = 0; i < iCommandObservers.Count(); ++i) |
|
166 { |
|
167 TRAP_IGNORE |
|
168 ( iCommandObservers[i]->PostCommandExecutionL( aCommand ) ); |
|
169 } |
|
170 |
|
171 // stop user input blocker |
|
172 if( iInputBlocker ) |
|
173 { |
|
174 iInputBlocker->Cancel(); |
|
175 } |
|
176 |
|
177 // Add command to the list of idle destroyable objects |
|
178 iIdleDestructableCommands.Append( &aCommand ); |
|
179 // Cancel any outstanding before starting new one. |
|
180 iIdleDestroyer->Cancel(); |
|
181 // Request idle destruction. If the append above failed, |
|
182 // it doesn't matter. The command gets destructed then |
|
183 // at the Phonebook exit, when this objects destructor |
|
184 // deletes also commands in iCommandArray. |
|
185 iIdleDestroyer->Start( TCallBack( |
|
186 ( &CPbk2CommandStore::IdleDestructorCallback ),this ) ); |
|
187 } |
|
188 |
|
189 // -------------------------------------------------------------------------- |
|
190 // CPbk2CommandStore::AknInputBlockCancel |
|
191 // -------------------------------------------------------------------------- |
|
192 // |
|
193 void CPbk2CommandStore::AknInputBlockCancel() |
|
194 { |
|
195 iInputBlocker = NULL; |
|
196 } |
|
197 |
|
198 |
|
199 // -------------------------------------------------------------------------- |
|
200 // CPbk2CommandStore::IdleDestructorCallback |
|
201 // -------------------------------------------------------------------------- |
|
202 // |
|
203 TInt CPbk2CommandStore::IdleDestructorCallback( TAny* aSelf ) |
|
204 { |
|
205 CPbk2CommandStore* self = static_cast<CPbk2CommandStore*>( aSelf ); |
|
206 self->IdleDestructor(); |
|
207 return EFalse; |
|
208 } |
|
209 |
|
210 // -------------------------------------------------------------------------- |
|
211 // CPbk2CommandStore::IdleDestructor |
|
212 // -------------------------------------------------------------------------- |
|
213 // |
|
214 void CPbk2CommandStore::IdleDestructor() |
|
215 { |
|
216 // Delete objects in idle destroyable array |
|
217 for (TInt i = 0; i < iIdleDestructableCommands.Count(); ++i) |
|
218 { |
|
219 MPbk2Command* idleDestCmd = iIdleDestructableCommands[i]; |
|
220 for (TInt j = iCommandArray.Count()-1; j >= 0; --j) |
|
221 { |
|
222 MPbk2Command* arrayCmd = iCommandArray[j]; |
|
223 if (idleDestCmd == arrayCmd) |
|
224 { |
|
225 // Remove from command array |
|
226 iCommandArray.Remove(j); |
|
227 iIdleDestructableCommands.Remove(i); |
|
228 delete idleDestCmd; |
|
229 idleDestCmd = NULL; |
|
230 } |
|
231 } |
|
232 } |
|
233 } |
|
234 |
|
235 |
|
236 // -------------------------------------------------------------------------- |
|
237 // CPbk2CommandStore::DestroyAllCommands |
|
238 // -------------------------------------------------------------------------- |
|
239 // |
|
240 void CPbk2CommandStore::DestroyAllCommands() |
|
241 { |
|
242 // Delete objects in idle commands array using CommandFinished |
|
243 for (TInt i = 0; i < iCommandArray.Count(); ++i) |
|
244 { |
|
245 MPbk2Command* destCmd = iCommandArray[i]; |
|
246 CommandFinished ( *destCmd ); |
|
247 } |
|
248 } |
|
249 // End of File |