|
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 view activation transaction. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2ViewActivationTransaction.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2ViewExplorer.h" |
|
23 #include "CPbk2AppUi.h" |
|
24 #include <CPbk2TabGroupContainer.h> |
|
25 #include <CPbk2ViewGraph.h> |
|
26 |
|
27 // System includes |
|
28 #include <aknnavi.h> |
|
29 #include <aknnavide.h> |
|
30 #include <akntabgrp.h> |
|
31 #include <akntitle.h> |
|
32 #include <akncontext.h> |
|
33 #include <eikimage.h> |
|
34 #include <eikspane.h> |
|
35 #include <AknsUtils.h> |
|
36 |
|
37 // -------------------------------------------------------------------------- |
|
38 // CPbk2ViewActivationTransaction::CPbk2ViewActivationTransaction |
|
39 // -------------------------------------------------------------------------- |
|
40 // |
|
41 CPbk2ViewActivationTransaction::CPbk2ViewActivationTransaction |
|
42 ( CPbk2AppUi& aAppUi, CPbk2ViewExplorer& aViewExplorer, |
|
43 const TUid& aViewId, const TVwsViewId& aPrevViewId, |
|
44 TUint aFlags ) : |
|
45 iAppUi( &aAppUi ), |
|
46 iViewExplorer( aViewExplorer ), |
|
47 iViewId( aViewId ), |
|
48 iPrevViewId( aPrevViewId ), |
|
49 iFlags( aFlags ) |
|
50 { |
|
51 } |
|
52 |
|
53 // -------------------------------------------------------------------------- |
|
54 // CPbk2ViewActivationTransaction::~CPbk2ViewActivationTransaction |
|
55 // -------------------------------------------------------------------------- |
|
56 // |
|
57 CPbk2ViewActivationTransaction::~CPbk2ViewActivationTransaction() |
|
58 { |
|
59 // Rollback previous view (if necessary) |
|
60 Rollback(); |
|
61 } |
|
62 |
|
63 // -------------------------------------------------------------------------- |
|
64 // CPbk2ViewActivationTransaction::NewLC |
|
65 // -------------------------------------------------------------------------- |
|
66 // |
|
67 CPbk2ViewActivationTransaction* CPbk2ViewActivationTransaction::NewLC |
|
68 ( CPbk2AppUi& aAppUi, CPbk2ViewExplorer& aViewExplorer, |
|
69 const TUid& aViewId, const TVwsViewId& aPrevViewId, |
|
70 const TDesC* aTitlePaneText, const CEikImage* aContextPanePicture, |
|
71 TUint aFlags ) |
|
72 { |
|
73 CPbk2ViewActivationTransaction* self = |
|
74 new ( ELeave ) CPbk2ViewActivationTransaction |
|
75 ( aAppUi, aViewExplorer, aViewId, aPrevViewId, aFlags ); |
|
76 CleanupStack::PushL( self); |
|
77 self->ConstructL( aTitlePaneText, aContextPanePicture ); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // -------------------------------------------------------------------------- |
|
82 // CPbk2ViewActivationTransaction::ConstructL |
|
83 // -------------------------------------------------------------------------- |
|
84 // |
|
85 void CPbk2ViewActivationTransaction::ConstructL |
|
86 ( const TDesC* aTitlePaneText, |
|
87 const CEikImage* aContextPanePicture ) |
|
88 { |
|
89 iNaviPane = static_cast<CAknNavigationControlContainer*> |
|
90 ( iAppUi->StatusPane()->ControlL |
|
91 ( TUid::Uid( EEikStatusPaneUidNavi ) ) ); |
|
92 |
|
93 // Make changes to state and save rollback data |
|
94 UpdateViewNavigationState(); |
|
95 |
|
96 if (iFlags & Phonebook2::EUpdateNaviPane) |
|
97 { |
|
98 UpdateNaviPaneL(iViewId); |
|
99 } |
|
100 if (iFlags & Phonebook2::EUpdateTitlePane) |
|
101 { |
|
102 SetTitlePaneTextL(aTitlePaneText); |
|
103 } |
|
104 if (iFlags & Phonebook2::EUpdateContextPane) |
|
105 { |
|
106 SetContextPanePictureL(aContextPanePicture); |
|
107 } |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // CPbk2ViewActivationTransaction::Commit |
|
112 // -------------------------------------------------------------------------- |
|
113 // |
|
114 void CPbk2ViewActivationTransaction::Commit() |
|
115 { |
|
116 // Delete and reset all rollback data |
|
117 delete iSaveContextPanePicture; |
|
118 iSaveContextPanePicture = NULL; |
|
119 delete iSaveTitlePaneText; |
|
120 iSaveTitlePaneText = NULL; |
|
121 iPushedNaviDecorator = NULL; |
|
122 iTabGroup = NULL; |
|
123 iSavePreviousViewNode = NULL; |
|
124 } |
|
125 |
|
126 // -------------------------------------------------------------------------- |
|
127 // CPbk2ViewActivationTransaction::RollbackL |
|
128 // -------------------------------------------------------------------------- |
|
129 // |
|
130 void CPbk2ViewActivationTransaction::RollbackL() |
|
131 { |
|
132 // First rollback as in destructor |
|
133 Rollback(); |
|
134 // Then switch back to previous view |
|
135 iViewExplorer.ActivatePreviousViewL( NULL ); |
|
136 } |
|
137 |
|
138 // -------------------------------------------------------------------------- |
|
139 // CPbk2ViewActivationTransaction::UpdateViewNavigationState |
|
140 // -------------------------------------------------------------------------- |
|
141 // |
|
142 void CPbk2ViewActivationTransaction::UpdateViewNavigationState() |
|
143 { |
|
144 // Reset saved state |
|
145 iSavePreviousViewNode = NULL; |
|
146 |
|
147 // Find activated view node in the graph |
|
148 CPbk2ViewNode* activatedNode = |
|
149 iViewExplorer.ViewGraph().FindNodeWithViewId( iViewId ); |
|
150 |
|
151 if ( activatedNode ) |
|
152 { |
|
153 // Set previous node for the newly activated view |
|
154 if ( iViewExplorer.IsPhonebook2View( iPrevViewId ) ) |
|
155 { |
|
156 // Find the previous view in the graph |
|
157 CPbk2ViewNode* prevNode = |
|
158 iViewExplorer.ViewGraph().FindNodeWithViewId |
|
159 ( iPrevViewId.iViewUid ); |
|
160 while ( prevNode ) |
|
161 { |
|
162 // Get transitions from the new view |
|
163 const TInt count = activatedNode->TransitionCount(); |
|
164 TInt i; |
|
165 for (i = 0; i < count; ++i) |
|
166 { |
|
167 // Set previous view if there is a back transition |
|
168 if ( activatedNode->TransitionAt(i).iEvent == |
|
169 EPbk2ViewTransitionBack && |
|
170 activatedNode->TransitionAt(i).iNode == prevNode ) |
|
171 { |
|
172 iSavePreviousViewNode = |
|
173 activatedNode->PreviousNode(); |
|
174 activatedNode->SetPreviousNode( prevNode ); |
|
175 break; |
|
176 } |
|
177 } |
|
178 if ( i >= count ) |
|
179 { |
|
180 // Matching back transition not found: Move back in |
|
181 // previous view chain |
|
182 prevNode = prevNode->PreviousNode(); |
|
183 } |
|
184 else |
|
185 { |
|
186 // Transition found, exit while loop |
|
187 break; |
|
188 } |
|
189 } |
|
190 } |
|
191 else |
|
192 { |
|
193 iSavePreviousViewNode = activatedNode->PreviousNode(); |
|
194 activatedNode->SetPreviousNode |
|
195 ( activatedNode->DefaultPreviousNode() ); |
|
196 } |
|
197 } |
|
198 } |
|
199 |
|
200 // -------------------------------------------------------------------------- |
|
201 // CPbk2ViewActivationTransaction::UpdateNaviPaneL |
|
202 // -------------------------------------------------------------------------- |
|
203 // |
|
204 void CPbk2ViewActivationTransaction::UpdateNaviPaneL( TUid aViewId ) |
|
205 { |
|
206 // Reset saved state |
|
207 iPushedNaviDecorator = NULL; |
|
208 iTabGroup = NULL; |
|
209 iSaveTabIndex = 0; |
|
210 |
|
211 CAknNavigationDecorator* decorator= |
|
212 iAppUi->TabGroups()->TabGroupFromViewId( aViewId.iUid ); |
|
213 |
|
214 if (decorator) |
|
215 { |
|
216 CAknTabGroup* tabGroup = static_cast<CAknTabGroup*> |
|
217 ( decorator->DecoratedControl() ); |
|
218 if (iNaviPane->Top() != decorator) |
|
219 { |
|
220 iNaviPane->PushL(*decorator); |
|
221 iPushedNaviDecorator = decorator; |
|
222 } |
|
223 iTabGroup = tabGroup; |
|
224 iSaveTabIndex = tabGroup->ActiveTabIndex(); |
|
225 tabGroup->SetActiveTabById( aViewId.iUid ); |
|
226 } |
|
227 } |
|
228 |
|
229 // -------------------------------------------------------------------------- |
|
230 // CPbk2ViewActivationTransaction::SetTitlePaneTextL |
|
231 // -------------------------------------------------------------------------- |
|
232 // |
|
233 void CPbk2ViewActivationTransaction::SetTitlePaneTextL |
|
234 ( const TDesC* aTitlePaneText ) |
|
235 { |
|
236 // Reset saved state |
|
237 delete iSaveTitlePaneText; |
|
238 iSaveTitlePaneText = NULL; |
|
239 |
|
240 CEikStatusPane* statusPane = iAppUi->StatusPane(); |
|
241 if (statusPane) |
|
242 { |
|
243 if (statusPane->PaneCapabilities(TUid::Uid(EEikStatusPaneUidTitle)) |
|
244 .IsPresent()) |
|
245 { |
|
246 iTitlePane = static_cast<CAknTitlePane*> |
|
247 (statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle))); |
|
248 if (iTitlePane->Text()) |
|
249 { |
|
250 iSaveTitlePaneText = iTitlePane->Text()->AllocL(); |
|
251 } |
|
252 if (aTitlePaneText) |
|
253 { |
|
254 iTitlePane->SetTextL(*aTitlePaneText); |
|
255 } |
|
256 else |
|
257 { |
|
258 iTitlePane->SetTextToDefaultL(); |
|
259 } |
|
260 } |
|
261 } |
|
262 } |
|
263 |
|
264 // -------------------------------------------------------------------------- |
|
265 // CPbk2ViewActivationTransaction::SetContextPanePictureL |
|
266 // -------------------------------------------------------------------------- |
|
267 // |
|
268 void CPbk2ViewActivationTransaction::SetContextPanePictureL |
|
269 ( const CEikImage* aContextPanePicture ) |
|
270 { |
|
271 // Reset saved state |
|
272 delete iSaveContextPanePicture; |
|
273 iSaveContextPanePicture = NULL; |
|
274 |
|
275 CEikStatusPane* statusPane = iAppUi->StatusPane(); |
|
276 if (statusPane) |
|
277 { |
|
278 if (statusPane->PaneCapabilities |
|
279 (TUid::Uid(EEikStatusPaneUidContext)) |
|
280 .IsInCurrentLayout()) |
|
281 { |
|
282 iContextPane = static_cast<CAknContextPane*> |
|
283 (statusPane->ControlL(TUid::Uid(EEikStatusPaneUidContext))); |
|
284 iSaveContextPanePicture = CopyImageL( iContextPane->Picture() ); |
|
285 if (aContextPanePicture) |
|
286 { |
|
287 iContextPane->SetPicture |
|
288 ( CopyImageL( *aContextPanePicture) ); |
|
289 } |
|
290 else |
|
291 { |
|
292 iContextPane->SetPictureToDefaultL(); |
|
293 } |
|
294 } |
|
295 } |
|
296 } |
|
297 |
|
298 // -------------------------------------------------------------------------- |
|
299 // CPbk2ViewActivationTransaction::CopyImageL |
|
300 // -------------------------------------------------------------------------- |
|
301 // |
|
302 CEikImage* CPbk2ViewActivationTransaction::CopyImageL |
|
303 ( const CEikImage& aSrc ) |
|
304 { |
|
305 CEikImage* copy = new ( ELeave ) CEikImage; |
|
306 CleanupStack::PushL( copy ); |
|
307 copy->SetPictureOwnedExternally ( EFalse ); |
|
308 CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap; |
|
309 copy->SetBitmap( bitmap ); |
|
310 CFbsBitmap* mask = new ( ELeave ) CFbsBitmap; |
|
311 copy->SetMask( mask ); |
|
312 User::LeaveIfError( bitmap->Duplicate( aSrc.Bitmap()->Handle() ) ); |
|
313 User::LeaveIfError( mask->Duplicate( aSrc.Mask()->Handle() ) ); |
|
314 CleanupStack::Pop( copy ); |
|
315 return copy; |
|
316 } |
|
317 |
|
318 // -------------------------------------------------------------------------- |
|
319 // CPbk2ViewActivationTransaction::Rollback |
|
320 // -------------------------------------------------------------------------- |
|
321 // |
|
322 void CPbk2ViewActivationTransaction::Rollback() |
|
323 { |
|
324 // Undo changes in reverse order |
|
325 if ( iContextPane && iSaveContextPanePicture ) |
|
326 { |
|
327 // iContextPane takes ownership of iSaveContextPanePicture |
|
328 iContextPane->SetPicture( iSaveContextPanePicture ); |
|
329 iSaveContextPanePicture = NULL; |
|
330 } |
|
331 if ( iTitlePane && iSaveTitlePaneText ) |
|
332 { |
|
333 // iTitlePane takes ownership of iSaveTitlePaneText |
|
334 iTitlePane->SetText( iSaveTitlePaneText ); |
|
335 iSaveTitlePaneText = NULL; |
|
336 } |
|
337 if ( iTabGroup && iSaveTabIndex != KErrNotFound ) |
|
338 { |
|
339 iTabGroup->SetActiveTabByIndex( iSaveTabIndex ); |
|
340 iSaveTabIndex = KErrNotFound; |
|
341 iTabGroup = NULL; |
|
342 } |
|
343 if ( iNaviPane && iPushedNaviDecorator ) |
|
344 { |
|
345 iNaviPane->Pop( iPushedNaviDecorator ); |
|
346 iPushedNaviDecorator = NULL; |
|
347 } |
|
348 if ( iSavePreviousViewNode ) |
|
349 { |
|
350 CPbk2ViewNode* activatedNode = |
|
351 iViewExplorer.ViewGraph().FindNodeWithViewId( iViewId ); |
|
352 if ( activatedNode ) |
|
353 { |
|
354 activatedNode->SetPreviousNode( iSavePreviousViewNode ); |
|
355 } |
|
356 iSavePreviousViewNode = NULL; |
|
357 } |
|
358 } |
|
359 |
|
360 // End of File |