|
1 /* |
|
2 * Copyright (c) 2002-2009 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: Application UI class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "UssdAppUi.h" |
|
21 #include "UssdContainer.h" |
|
22 #include "UssdComms.h" |
|
23 #include <ussd.rsg> |
|
24 #include <avkon.rsg> |
|
25 #include "ussd.hrh" |
|
26 #include <eikmenub.h> |
|
27 #include <eikedwin.h> |
|
28 #include <avkon.hrh> |
|
29 #include <bldvariant.hrh> |
|
30 #include <featmgr.h> |
|
31 |
|
32 #include <AknDef.h> |
|
33 #include <hlplch.h> // For HlpLauncher |
|
34 |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CUssdAppUi::ConstructL |
|
40 // Creates all members |
|
41 // ----------------------------------------------------------------------------- |
|
42 void CUssdAppUi::ConstructL() |
|
43 { |
|
44 // Sets up TLS, must be done before FeatureManager is used in USSD. |
|
45 FeatureManager::InitializeLibL(); |
|
46 |
|
47 BaseConstructL( |
|
48 EAknEnableSkin | EAknEnableMSK |
|
49 ); |
|
50 |
|
51 // Softkeys at start: |
|
52 // With HELP: Options-Exit (defined in the resource file, default) |
|
53 // Without HELP: <empty>-Exit |
|
54 if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
55 { |
|
56 // Feature not supported, set correct softkeys. |
|
57 Cba()->SetCommandSetL( R_AVKON_SOFTKEYS_EXIT ); |
|
58 iCbaResource = R_AVKON_SOFTKEYS_EXIT; |
|
59 Cba()->DrawNow(); |
|
60 } |
|
61 |
|
62 iComms = CUssdComms::NewL(); |
|
63 |
|
64 iAppContainer = new( ELeave ) CUssdContainer( *this ); |
|
65 iAppContainer->SetMopParent( this ); |
|
66 iAppContainer->ConstructL( ClientRect() ); |
|
67 AddToStackL( iAppContainer ); |
|
68 iIsAddedToStack = ETrue; |
|
69 } |
|
70 |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CUssdAppUi::~CUssdAppUi |
|
74 // Destructor |
|
75 // Frees reserved resources |
|
76 // ----------------------------------------------------------------------------- |
|
77 CUssdAppUi::~CUssdAppUi() |
|
78 { |
|
79 if ( iIsAddedToStack ) |
|
80 { |
|
81 RemoveFromStack( iAppContainer ); |
|
82 } |
|
83 |
|
84 delete iAppContainer; |
|
85 iAppContainer = NULL; |
|
86 |
|
87 delete iComms; |
|
88 iComms = NULL; |
|
89 |
|
90 // Frees the TLS! Must be done after FeatureManager is used. |
|
91 FeatureManager::UnInitializeLib(); |
|
92 } |
|
93 |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CUssdAppUi::HandleCommandL |
|
97 // Handle commands from the user. |
|
98 // ----------------------------------------------------------------------------- |
|
99 void CUssdAppUi::HandleCommandL( TInt aCommand ) |
|
100 { |
|
101 switch ( aCommand ) |
|
102 { |
|
103 case EAknCmdExit: |
|
104 case EEikCmdExit: |
|
105 case EAknSoftkeyExit: |
|
106 case EAknSoftkeyBack: |
|
107 { |
|
108 iComms->InformExitReason( EPhCltUserExit ); |
|
109 Exit(); |
|
110 break; |
|
111 } |
|
112 |
|
113 case EUssdMenuItemSend: |
|
114 case EUssdSoftkeySend: |
|
115 { |
|
116 // Send string and exit the application |
|
117 HBufC* buffer = iAppContainer->Editor().GetTextInHBufL(); |
|
118 __ASSERT_DEBUG( |
|
119 buffer->Length() <= KUssdEditorMaxLenght , |
|
120 User::Invariant() ); |
|
121 |
|
122 if ( buffer->Length() && |
|
123 buffer->Length() <= KUssdEditorMaxLenght && |
|
124 KErrNone == iComms->SendString( buffer->Des() ) ) |
|
125 { |
|
126 iComms->InformExitReason( EPhCltSendCompleted ); |
|
127 Exit(); |
|
128 } |
|
129 |
|
130 delete buffer; |
|
131 break; |
|
132 } |
|
133 |
|
134 case EAknCmdHelp: |
|
135 { |
|
136 if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
137 { |
|
138 // Feature supported, launch the help application. |
|
139 HlpLauncher::LaunchHelpApplicationL( |
|
140 iEikonEnv->WsSession(), AppHelpContextL() ); |
|
141 } |
|
142 break; |
|
143 } |
|
144 |
|
145 default: |
|
146 break; |
|
147 } |
|
148 } |
|
149 |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CUssdAppUi::HandleResourceChangeL |
|
153 // ----------------------------------------------------------------------------- |
|
154 void CUssdAppUi::HandleResourceChangeL( TInt aType ) |
|
155 { |
|
156 CAknAppUi::HandleResourceChangeL( aType ); |
|
157 |
|
158 if( aType == KEikDynamicLayoutVariantSwitch ) |
|
159 { |
|
160 iAppContainer->SetRect( ClientRect() ); |
|
161 } |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CUssdAppUi::HandleForegroundEventL |
|
166 // Handle foreground event. |
|
167 // ----------------------------------------------------------------------------- |
|
168 void CUssdAppUi::HandleForegroundEventL( TBool aForeground ) |
|
169 { |
|
170 if ( iComms ) |
|
171 { |
|
172 if ( aForeground ) |
|
173 { |
|
174 // If app comes to foreground, we must know is the |
|
175 // editor needs clearing. |
|
176 if ( iComms->InformAppForeground() ) // ret ETrue if needs clearing |
|
177 { |
|
178 if ( iAppContainer ) |
|
179 { |
|
180 iAppContainer->Editor().SetCursorPosL( 0, EFalse ); |
|
181 iAppContainer->Editor().Text()->Reset(); |
|
182 iAppContainer->Editor().HandleTextChangedL(); |
|
183 |
|
184 if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
185 { |
|
186 SetSoftkeySendVisibleL( EFalse ); |
|
187 } |
|
188 |
|
189 } |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 iComms->InformAppBackground(); |
|
195 } |
|
196 } |
|
197 |
|
198 // Refresh message character counter |
|
199 if( aForeground && iAppContainer ) |
|
200 { |
|
201 iAppContainer->UpdateNavipaneMsgLengthL(); |
|
202 } |
|
203 |
|
204 CAknAppUi::HandleForegroundEventL( aForeground ); |
|
205 } |
|
206 |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CUssdAppUi::DynInitMenuPaneL |
|
210 // Set's Send option visible. |
|
211 // |
|
212 // If HELP is defined, the Options menu item 'Send' is removed if |
|
213 // the editor is empty. If it is not defined, the left softkey is 'Send' or |
|
214 // <empty>. |
|
215 // ----------------------------------------------------------------------------- |
|
216 void CUssdAppUi::DynInitMenuPaneL( |
|
217 TInt aResourceId, |
|
218 CEikMenuPane* aMenuPane ) |
|
219 { |
|
220 if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
221 { |
|
222 if ( aResourceId == R_USSD_MENU ) |
|
223 { |
|
224 if ( aMenuPane ) |
|
225 { |
|
226 aMenuPane->SetItemDimmed( |
|
227 EUssdMenuItemSend, |
|
228 iAppContainer->Editor().TextLength() == 0 ); |
|
229 } |
|
230 // If aMenuPane == NULL, do nothing. |
|
231 } |
|
232 |
|
233 // If aResourceId != R_USSD_MENU, do nothing |
|
234 } |
|
235 |
|
236 // If help not defined, do nothing |
|
237 } |
|
238 |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CUssdAppUi::SetSofkeySendVisibleL |
|
242 // Sets Send softkey (in)visible. |
|
243 // ----------------------------------------------------------------------------- |
|
244 void CUssdAppUi::SetSoftkeySendVisibleL( |
|
245 TBool aVisible ) |
|
246 { |
|
247 if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
248 { |
|
249 // Help not defined |
|
250 TInt newResource; |
|
251 |
|
252 if ( aVisible ) |
|
253 { |
|
254 if ( iCbaResource == R_USSD_SOFTKEYS_SEND_EXIT ) |
|
255 { |
|
256 return; // Send is already visible |
|
257 } |
|
258 newResource = R_USSD_SOFTKEYS_SEND_EXIT; // change it |
|
259 } |
|
260 else |
|
261 { |
|
262 if ( iCbaResource == R_AVKON_SOFTKEYS_EXIT ) |
|
263 { |
|
264 return; // Send is already invisible |
|
265 } |
|
266 newResource = R_AVKON_SOFTKEYS_EXIT; // change it. |
|
267 } |
|
268 |
|
269 // Update Softkeys |
|
270 Cba()->SetCommandSetL( newResource ); |
|
271 iCbaResource = newResource; |
|
272 Cba()->DrawNow(); |
|
273 } |
|
274 |
|
275 // If help defined, do nothing. |
|
276 } |
|
277 |
|
278 // End of File |