|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @publishedAll |
|
19 @released |
|
20 */ |
|
21 |
|
22 #include "ViewObserver.h" |
|
23 |
|
24 CViewObserver* CViewObserver::NewLC(const CContactViewTest &aTest, |
|
25 void (CContactViewTest::*aFunc)()) |
|
26 { |
|
27 CViewObserver *self = new(ELeave) CViewObserver(aTest, aFunc); |
|
28 CleanupStack::PushL(self); |
|
29 return self; |
|
30 } |
|
31 |
|
32 CViewObserver::~CViewObserver() |
|
33 { |
|
34 CleanView(); |
|
35 } |
|
36 |
|
37 CViewObserver::CViewObserver( const CContactViewTest &aTest, |
|
38 void (CContactViewTest::*aFunc)()) : |
|
39 CActive(EPriorityStandard), |
|
40 iMainFunc( aFunc ), |
|
41 iTest( const_cast<CContactViewTest &>(aTest) ) |
|
42 { |
|
43 CActiveScheduler::Add(this); |
|
44 } |
|
45 |
|
46 |
|
47 void CViewObserver::RunL() |
|
48 { |
|
49 |
|
50 if(iMainFunc) |
|
51 { |
|
52 (iTest.*iMainFunc)(); |
|
53 } |
|
54 else |
|
55 { |
|
56 (iTest.*iDoFunc)(*iLocalView); |
|
57 } |
|
58 |
|
59 if( !iDoFunc && !iMainFunc ) |
|
60 { |
|
61 CActiveScheduler::Stop(); |
|
62 } |
|
63 } |
|
64 |
|
65 void CViewObserver::DoCancel() |
|
66 { |
|
67 } |
|
68 |
|
69 TInt CViewObserver::RunError(TInt aError) |
|
70 { |
|
71 _LIT(KViewError,"ViewObserver:: Error in doTest runL: %d"); |
|
72 iTest.ERR_PRINTF2(KViewError , aError ); |
|
73 return aError; |
|
74 } |
|
75 |
|
76 void CViewObserver::Activate() |
|
77 { |
|
78 if (!IsActive()) |
|
79 { |
|
80 TRequestStatus *pS=&iStatus; |
|
81 User::RequestComplete(pS,KErrNone); |
|
82 SetActive(); |
|
83 } |
|
84 } |
|
85 |
|
86 |
|
87 void CViewObserver::HandleContactViewEvent( const CContactViewBase& aView, |
|
88 const TContactViewEvent& aEvent) |
|
89 { |
|
90 if (&aView==iLocalView) |
|
91 { |
|
92 switch(aEvent.iEventType) |
|
93 { |
|
94 case TContactViewEvent::EReady: |
|
95 { |
|
96 Activate(); |
|
97 break; |
|
98 } |
|
99 case TContactViewEvent::EItemAdded: |
|
100 case TContactViewEvent::EItemRemoved: |
|
101 case TContactViewEvent::EGroupChanged: |
|
102 case TContactViewEvent::ESortOrderChanged: |
|
103 case TContactViewEvent::EUnavailable: |
|
104 { |
|
105 break; |
|
106 } |
|
107 default: |
|
108 { |
|
109 _LIT(KViewError,"CViewObserver::HandleContactViewEvent, non ready event: %d and error: %d"); |
|
110 iTest.ERR_PRINTF3(KViewError , aEvent.iEventType, aEvent.iInt ); |
|
111 RDebug::Print(KViewError , aEvent.iEventType, aEvent.iInt ); |
|
112 iEvent = TContactViewEvent(aEvent.iEventType, aEvent.iInt, aEvent.iContactId); |
|
113 Activate(); |
|
114 break; |
|
115 } |
|
116 } |
|
117 } |
|
118 } |
|
119 |
|
120 void CViewObserver::CleanView() |
|
121 { |
|
122 if(iLocalView) |
|
123 { |
|
124 iLocalView->Close(*this); |
|
125 iLocalView = NULL; |
|
126 } |
|
127 } |
|
128 |
|
129 void CViewObserver::SetView(const CContactViewBase *aLocalView) |
|
130 { |
|
131 CleanView(); |
|
132 iLocalView = const_cast<CContactViewBase *>(aLocalView); |
|
133 } |
|
134 |