|
1 /* |
|
2 * Copyright (c) 2007-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: Takes a command and executes it if predefined |
|
15 * condition is met |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cpbk2commandactivator.h" |
|
22 |
|
23 // pbk2 |
|
24 #include <MPbk2ContactUiControl.h> |
|
25 #include "cpbk2storestatechecker.h" |
|
26 |
|
27 // vpbk |
|
28 #include <MVPbkStoreContact.h> |
|
29 |
|
30 // system |
|
31 #include <coemain.h> |
|
32 |
|
33 |
|
34 // ============================ LOCAL FUNCTIONS ============================= |
|
35 namespace |
|
36 { |
|
37 |
|
38 #ifdef _DEBUG |
|
39 |
|
40 enum TPanicCode |
|
41 { |
|
42 EPanicObserverNotSet = 1 |
|
43 }; |
|
44 |
|
45 void Panic(TPanicCode aReason) |
|
46 { |
|
47 _LIT( KPanicText, "CPbk2CommandActivator" ); |
|
48 User::Panic(KPanicText,aReason); |
|
49 } |
|
50 |
|
51 #endif // _DEBUG |
|
52 |
|
53 } |
|
54 |
|
55 // ============================ MEMBER FUNCTIONS ============================ |
|
56 |
|
57 // -------------------------------------------------------------------------- |
|
58 // CPbk2CommandActivator::CPbk2CommandActivator |
|
59 // C++ default constructor can NOT contain any code, that |
|
60 // might leave. |
|
61 // -------------------------------------------------------------------------- |
|
62 // |
|
63 CPbk2CommandActivator::CPbk2CommandActivator( |
|
64 MPbk2Command* aCommand, |
|
65 const MPbk2ContactUiControl& aUiControl ) : |
|
66 iCommand( aCommand ), |
|
67 iUiControl( aUiControl ) |
|
68 { |
|
69 // Do nothing |
|
70 } |
|
71 |
|
72 // -------------------------------------------------------------------------- |
|
73 // CPbk2CommandActivator::CPbk2CommandActivator |
|
74 // -------------------------------------------------------------------------- |
|
75 // |
|
76 EXPORT_C CPbk2CommandActivator::~CPbk2CommandActivator() |
|
77 { |
|
78 delete iCommand; |
|
79 delete iStoreStateChecker; |
|
80 } |
|
81 |
|
82 // -------------------------------------------------------------------------- |
|
83 // CPbk2CommandActivator::NewL |
|
84 // Two-phased constructor. |
|
85 // -------------------------------------------------------------------------- |
|
86 // |
|
87 EXPORT_C CPbk2CommandActivator* CPbk2CommandActivator::NewL( |
|
88 MPbk2Command* aCommand, |
|
89 const MPbk2ContactUiControl& aUiControl ) |
|
90 { |
|
91 return new( ELeave ) CPbk2CommandActivator |
|
92 ( aCommand, aUiControl ); |
|
93 } |
|
94 |
|
95 // -------------------------------------------------------------------------- |
|
96 // CPbk2CommandActivator::ExecuteLD |
|
97 // -------------------------------------------------------------------------- |
|
98 // |
|
99 void CPbk2CommandActivator::ExecuteLD() |
|
100 { |
|
101 __ASSERT_DEBUG( iObserver, Panic( EPanicObserverNotSet ) ); |
|
102 const MVPbkStoreContact* storeContact = iUiControl.FocusedStoreContact(); |
|
103 if ( storeContact ) |
|
104 { |
|
105 // Check is store available of current contact |
|
106 // and if it is not, show note and skip command execution |
|
107 MVPbkContactStore& contactStore = storeContact->ParentStore(); |
|
108 delete iStoreStateChecker; |
|
109 iStoreStateChecker = NULL; |
|
110 iStoreStateChecker = |
|
111 CPbk2StoreStateChecker::NewL( contactStore, *this ); |
|
112 } |
|
113 else |
|
114 { |
|
115 iCommand->ExecuteLD(); |
|
116 } |
|
117 } |
|
118 |
|
119 // -------------------------------------------------------------------------- |
|
120 // CPbk2CommandActivator::ResetUiControl |
|
121 // -------------------------------------------------------------------------- |
|
122 // |
|
123 void CPbk2CommandActivator::ResetUiControl( |
|
124 MPbk2ContactUiControl& aUiControl) |
|
125 { |
|
126 iCommand->ResetUiControl( aUiControl ); |
|
127 } |
|
128 |
|
129 // -------------------------------------------------------------------------- |
|
130 // CPbk2CommandActivator::AddObserver |
|
131 // -------------------------------------------------------------------------- |
|
132 // |
|
133 void CPbk2CommandActivator::AddObserver( MPbk2CommandObserver& aObserver ) |
|
134 { |
|
135 iObserver = &aObserver; |
|
136 iCommand->AddObserver( *this ); |
|
137 } |
|
138 |
|
139 // -------------------------------------------------------------------------- |
|
140 // CPbk2CommandActivator::StoreState |
|
141 // -------------------------------------------------------------------------- |
|
142 // |
|
143 void CPbk2CommandActivator::StoreState( |
|
144 MPbk2StoreStateCheckerObserver::TState aState ) |
|
145 { |
|
146 if ( aState == MPbk2StoreStateCheckerObserver::EStoreAvailable ) |
|
147 { |
|
148 TRAPD( err, iCommand->ExecuteLD() ); |
|
149 if ( err != KErrNone ) |
|
150 { |
|
151 CCoeEnv::Static()->HandleError( err ); |
|
152 if ( iObserver ) |
|
153 { |
|
154 iObserver->CommandFinished( *this ); |
|
155 } |
|
156 else |
|
157 { |
|
158 // No observer set so ExecuteLD is a real one here |
|
159 iCommand = NULL; |
|
160 delete this; |
|
161 } |
|
162 } |
|
163 } |
|
164 else |
|
165 { |
|
166 // It is not fatal error if information note is not shown |
|
167 TRAP_IGNORE( iStoreStateChecker->ShowUnavailableNoteL() ); |
|
168 if ( iObserver ) |
|
169 { |
|
170 iObserver->CommandFinished( *this ); |
|
171 } |
|
172 else |
|
173 { |
|
174 // No observer so this means that command should destroy itself |
|
175 // without help of command handler |
|
176 delete this; |
|
177 } |
|
178 } |
|
179 } |
|
180 |
|
181 // -------------------------------------------------------------------------- |
|
182 // CPbk2CommandActivator::CommandFinished |
|
183 // -------------------------------------------------------------------------- |
|
184 // |
|
185 void CPbk2CommandActivator::CommandFinished( const MPbk2Command& /*aCommand*/ ) |
|
186 { |
|
187 // If this is called, it means that observer is set |
|
188 iObserver->CommandFinished( *this ); |
|
189 } |
|
190 |
|
191 // -------------------------------------------------------------------------- |
|
192 // CPbk2CommandActivator::CommandExtension |
|
193 // -------------------------------------------------------------------------- |
|
194 // |
|
195 TAny* CPbk2CommandActivator::CommandExtension(TUid aExtensionUid ) |
|
196 { |
|
197 if( iCommand ) |
|
198 { |
|
199 return iCommand->CommandExtension(aExtensionUid); |
|
200 } |
|
201 else |
|
202 { |
|
203 return NULL; |
|
204 } |
|
205 } |
|
206 |
|
207 // End of File |