|
1 /* |
|
2 * Copyright (c) 2003-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: Management UI Container |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <eikclbd.h> |
|
20 #include <AknQueryDialog.h> |
|
21 #include <aknnotewrappers.h> |
|
22 #include <ErrorUI.h> |
|
23 #include <sysutil.h> |
|
24 #include <vpnmanagementuirsc.rsg> |
|
25 #include "vpnuiloader.h" |
|
26 #include "vpnmanagementuiservercontainer.h" |
|
27 #include "vpnmanagementuidefs.h" |
|
28 #include "vpnmanagementui.hrh" |
|
29 #include "log_vpnmanagementui.h" |
|
30 |
|
31 #ifdef __SERIES60_HELP |
|
32 #include <csxhelp/vpn.hlp.hrh> // for help context of VPN Management UI |
|
33 #endif //__SERIES60_HELP |
|
34 |
|
35 // ================= MEMBER FUNCTIONS ======================= |
|
36 |
|
37 // --------------------------------------------------------- |
|
38 // CVpnManagementUiServerContainer::CVpnManagementUiServerContainer( |
|
39 // CVpnManagementUiServerView& aParent, CVpnUiLoader& aLoader) |
|
40 // Constructor with parent |
|
41 // --------------------------------------------------------- |
|
42 // |
|
43 CVpnManagementUiServerContainer::CVpnManagementUiServerContainer( |
|
44 CVpnManagementUiServerView& aParent, CVpnUiLoader& aLoader ) : |
|
45 iParent ( aParent ), iLoader ( aLoader ) |
|
46 { |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // CVpnManagementUiServerContainer::~CVpnManagementUiServerContainer() |
|
51 // Destructor |
|
52 // --------------------------------------------------------- |
|
53 // |
|
54 CVpnManagementUiServerContainer::~CVpnManagementUiServerContainer() |
|
55 { |
|
56 delete iListBox; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------- |
|
60 // CVpnManagementUiServerContainer::ConstructL( |
|
61 // const TRect& aRect, TInt& aCurrentPosition, TInt& aTopItem) |
|
62 // EPOC two phased constructor |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 void CVpnManagementUiServerContainer::ConstructL( |
|
66 const TRect& aRect, TInt& /*aCurrentPosition*/, TInt& /*aTopItem*/ ) |
|
67 { |
|
68 CreateWindowL(); |
|
69 CreateListBoxL(); |
|
70 ShowServersL(); |
|
71 if ((iListItemCount == 0) && (!iLoader.iBackFromServerDefinition)) |
|
72 { |
|
73 iLoader.iShowDefineQuery = ETrue; |
|
74 } |
|
75 iLoader.iBackFromServerDefinition = EFalse; |
|
76 |
|
77 SetRect( aRect ); |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CVpnManagementUiServerContainer::ActivateL() |
|
82 // called after the dialog is shown |
|
83 // used to handle empty list - query |
|
84 // --------------------------------------------------------- |
|
85 // |
|
86 void CVpnManagementUiServerContainer::ActivateL() |
|
87 { |
|
88 CCoeControl::ActivateL(); |
|
89 // put empty list checking & required actions here. |
|
90 if ((iListItemCount == 0) && (iLoader.iShowDefineQuery)) |
|
91 { |
|
92 HBufC* temp; |
|
93 temp = StringLoader::LoadLC( R_VPN_QUEST_DEFINE_NEW_SERVER ); |
|
94 CAknQueryDialog* query = CAknQueryDialog::NewL( |
|
95 CAknQueryDialog::EConfirmationTone ); |
|
96 TInt retval = query->ExecuteLD( R_CONFIRMATION_QUERY, *temp ); |
|
97 CleanupStack::PopAndDestroy(); // temp |
|
98 iLoader.iShowDefineQuery = EFalse; |
|
99 if ( retval ) |
|
100 { |
|
101 if (!SysUtil::FFSSpaceBelowCriticalLevelL(0, 0)) |
|
102 { |
|
103 iLoader.ChangeViewL(KChangeViewSettings); |
|
104 } |
|
105 else |
|
106 { |
|
107 CErrorUI* errorUi = CErrorUI::NewLC( *(CCoeEnv::Static()) ); |
|
108 errorUi->ShowGlobalErrorNoteL( KErrDiskFull ); |
|
109 CleanupStack::PopAndDestroy(); // errorUi |
|
110 iLoader.iShowDefineQuery = EFalse; |
|
111 iLoader.iNewServerDefinition = EFalse; |
|
112 } |
|
113 } |
|
114 } |
|
115 |
|
116 } |
|
117 |
|
118 |
|
119 // --------------------------------------------------------- |
|
120 // CVpnManagementUiServerContainer::SizeChanged() |
|
121 // Called by framework when the view size is changed |
|
122 // --------------------------------------------------------- |
|
123 // |
|
124 void CVpnManagementUiServerContainer::SizeChanged() |
|
125 { |
|
126 iListBox->SetRect(Rect()); |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------- |
|
130 // CVpnManagementUiServerContainer::FocusChanged(TDrawNow aDrawNow) |
|
131 // --------------------------------------------------------- |
|
132 // |
|
133 void CVpnManagementUiServerContainer::FocusChanged(TDrawNow aDrawNow) |
|
134 { |
|
135 if ( iListBox ) |
|
136 { |
|
137 iListBox->SetFocus( IsFocused(), aDrawNow ); |
|
138 } |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------- |
|
142 // CVpnManagementUiServerContainer::HandleResourceChange |
|
143 // --------------------------------------------------------- |
|
144 // |
|
145 void CVpnManagementUiServerContainer::HandleResourceChange( TInt aType ) |
|
146 { |
|
147 CCoeControl::HandleResourceChange(aType); |
|
148 |
|
149 //Handle change in layout orientation |
|
150 if (aType == KEikDynamicLayoutVariantSwitch || aType == KAknsMessageSkinChange ) |
|
151 { |
|
152 iListBox->HandleResourceChange(aType); |
|
153 TRect mainPaneRect; |
|
154 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect); |
|
155 SetRect(mainPaneRect); |
|
156 DrawNow(); |
|
157 } |
|
158 } |
|
159 |
|
160 enum { EListBoxControl, ENumberOfControls }; |
|
161 |
|
162 // --------------------------------------------------------- |
|
163 // CVpnManagementUiServerContainer::CountComponentControls() const |
|
164 // --------------------------------------------------------- |
|
165 // |
|
166 TInt CVpnManagementUiServerContainer::CountComponentControls() const |
|
167 { |
|
168 // return number of controls inside this container |
|
169 return ENumberOfControls; // return nbr of controls inside this container |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------- |
|
173 // CVpnManagementUiServerContainer::ComponentControl(TInt aIndex) const |
|
174 // --------------------------------------------------------- |
|
175 // |
|
176 CCoeControl* CVpnManagementUiServerContainer::ComponentControl(TInt aIndex) const |
|
177 { |
|
178 switch ( aIndex ) |
|
179 { |
|
180 case 0: |
|
181 return iListBox; |
|
182 default: |
|
183 return NULL; |
|
184 } |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------- |
|
188 // CVpnManagementUiServerContainer::HandleControlEventL( |
|
189 // CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) |
|
190 // Cannot be changed to non-leaving function. |
|
191 // L-function is required by the class definition, even if empty. |
|
192 // --------------------------------------------------------- |
|
193 // |
|
194 void CVpnManagementUiServerContainer::HandleControlEventL( |
|
195 CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) |
|
196 { |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------- |
|
200 // CVpnManagementUiServerContainer::OfferKeyEventL( |
|
201 // const TKeyEvent& aKeyEvent, TEventCode aType) |
|
202 // Handles the key events OK button, arrow keys, delete key. |
|
203 // OK button functionality is different depending on the number of marked items |
|
204 // in the list; zero marked -> show details view, one or more marked -> show |
|
205 // OKOptions list, list empty -> OK inactive. |
|
206 // Delete active only if list not empty. |
|
207 // --------------------------------------------------------- |
|
208 // |
|
209 TKeyResponse CVpnManagementUiServerContainer::OfferKeyEventL( |
|
210 const TKeyEvent& aKeyEvent, TEventCode aType) |
|
211 { |
|
212 TKeyResponse retval = EKeyWasNotConsumed; |
|
213 if ( aType==EEventKey ) |
|
214 { |
|
215 if ( (aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter) && //select or enter |
|
216 iListBox->CurrentItemIndex() > -1 ) //This is for empty list |
|
217 { |
|
218 // Selection key pressed |
|
219 iParent.HandleCommandL( EVpnUiCmdEditServer ); |
|
220 retval = EKeyWasConsumed; |
|
221 } |
|
222 |
|
223 else if ( aKeyEvent.iCode == EKeyDelete |
|
224 || aKeyEvent.iCode == EKeyBackspace ) |
|
225 { |
|
226 if ( iListBox->CurrentItemIndex() > -1 ) |
|
227 { |
|
228 iParent.HandleCommandL( EVpnUiCmdDeleteServer ); |
|
229 retval = EKeyWasConsumed; |
|
230 } |
|
231 } |
|
232 else |
|
233 { |
|
234 retval = iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
235 } |
|
236 } |
|
237 else |
|
238 { |
|
239 retval = iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
240 } |
|
241 return retval; |
|
242 } |
|
243 |
|
244 // --------------------------------------------------------- |
|
245 // CVpnManagementUiServerContainer::CreateListBoxL() |
|
246 // Creates listbox, sets empty listbox text. |
|
247 // --------------------------------------------------------- |
|
248 // |
|
249 void CVpnManagementUiServerContainer::CreateListBoxL() |
|
250 { |
|
251 iListBox = new( ELeave ) CAknSingleStyleListBox; |
|
252 iListBox->SetContainerWindowL( *this ); |
|
253 iListBox->ConstructL( this, EAknListBoxMarkableList ); |
|
254 iListBox->CreateScrollBarFrameL( ETrue ); |
|
255 iListBox->ScrollBarFrame()-> |
|
256 SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto ); |
|
257 |
|
258 HBufC* stringHolder = StringLoader::LoadLC( R_VPN_POLICY_SERVERS_EMPTY ); |
|
259 iListBox->View()->SetListEmptyTextL( *stringHolder ); |
|
260 CleanupStack::PopAndDestroy(); // stringHolder |
|
261 |
|
262 iListBox->SetListBoxObserver (this); |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------- |
|
266 // CVpnManagementUiServerContainer::DrawListBoxL(TInt aCurrentPosition, TInt aTopItem) |
|
267 // Draws listbox, fetches graphic icons for markable list |
|
268 // --------------------------------------------------------- |
|
269 // |
|
270 void CVpnManagementUiServerContainer::DrawListBoxL( TInt aCurrentPosition, TInt aTopItem ) |
|
271 { |
|
272 if (aCurrentPosition >= 0) |
|
273 { |
|
274 iListBox->SetTopItemIndex( aTopItem ); |
|
275 iListBox->SetCurrentItemIndex( aCurrentPosition ); |
|
276 } |
|
277 |
|
278 ActivateL(); |
|
279 DrawNow(); |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------- |
|
283 // CVpnManagementUiServerContainer::UpdateListBoxL(TInt& aCurrentPosition) |
|
284 // Refresh listbox after VPN policy server deletion. |
|
285 // --------------------------------------------------------- |
|
286 // |
|
287 void CVpnManagementUiServerContainer::UpdateListBoxL(TInt& aCurrentPosition) |
|
288 { |
|
289 MDesCArray* itemList = iListBox->Model()->ItemTextArray(); |
|
290 CDesCArray* itemArray = ( CDesCArray* )itemList; |
|
291 |
|
292 itemArray->Delete(aCurrentPosition); |
|
293 itemArray->Compress(); |
|
294 |
|
295 iListBox->HandleItemRemovalL(); |
|
296 if(aCurrentPosition > 0) |
|
297 { |
|
298 iListBox->SetCurrentItemIndexAndDraw(aCurrentPosition-1); |
|
299 } |
|
300 if(aCurrentPosition == 0 ) |
|
301 { |
|
302 if (iListItemCount > 1 ) |
|
303 { |
|
304 iListBox->SetCurrentItemIndexAndDraw(aCurrentPosition); |
|
305 } |
|
306 else |
|
307 { |
|
308 HBufC* stringHolder = StringLoader::LoadLC( R_VPN_POLICY_SERVERS_EMPTY ); |
|
309 iListBox->View()->SetListEmptyTextL( *stringHolder ); |
|
310 CleanupStack::PopAndDestroy(); // stringHolder |
|
311 } |
|
312 } |
|
313 iListItemCount = iListItemCount -1; |
|
314 iParent.SetMiddleSoftKeyL(ETrue); |
|
315 DrawNow(); |
|
316 } |
|
317 |
|
318 |
|
319 void CVpnManagementUiServerContainer::ShowServersL() |
|
320 { |
|
321 |
|
322 TAgileProvisionApiServerListElem& serverList = iLoader.VpnApiWrapperL().ServerListL(); |
|
323 |
|
324 CDesCArrayFlat* itemTextArray = static_cast<CDesCArrayFlat*>(iListBox->Model()->ItemTextArray()); |
|
325 |
|
326 itemTextArray->Reset(); |
|
327 iListBox->Reset(); |
|
328 |
|
329 if ( serverList.iServerUrl.Length()>0 ) |
|
330 { |
|
331 iListItemCount = 1; |
|
332 TBuf<KMaxProvisionServerNameLength+2> serverName; |
|
333 serverName.Append(_L("\t")); |
|
334 serverName.Append(serverList.iServerNameLocal); |
|
335 itemTextArray->AppendL(serverName); |
|
336 } |
|
337 |
|
338 iListBox->HandleItemAdditionL(); |
|
339 |
|
340 } |
|
341 |
|
342 |
|
343 void CVpnManagementUiServerContainer::DeleteServerL(TInt /* aIndex */) |
|
344 { |
|
345 LOG(Log::Printf(_L("CVpnManagementUiServerContainer::DeleteServerL\n"))); |
|
346 |
|
347 TAgileProvisionApiServerListElem& serverList = iLoader.VpnApiWrapperL().ServerListL(); |
|
348 TBuf<KMaxProvisionServerNameLength> serverName; |
|
349 serverName.Append(serverList.iServerNameLocal); |
|
350 |
|
351 HBufC* temp = StringLoader::LoadLC( R_VPN_QUEST_DELETE_SERVER, serverName ); |
|
352 |
|
353 CAknQueryDialog* query = CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone ); |
|
354 TInt retval = query->ExecuteLD( R_CONFIRMATION_QUERY, *temp ); |
|
355 CleanupStack::PopAndDestroy(); // temp |
|
356 if ( retval ) |
|
357 { |
|
358 TInt ret = iLoader.VpnApiWrapperL().DeleteServer(); |
|
359 TInt ind = 0; |
|
360 if(ret == KErrNone) |
|
361 { |
|
362 //Update listbox |
|
363 UpdateListBoxL( ind ); |
|
364 |
|
365 //Update iServerList |
|
366 iLoader.VpnApiWrapperL().ServerListL(); |
|
367 |
|
368 //Set iNewServerDefinition to false |
|
369 iLoader.iNewServerDefinition = EFalse; |
|
370 } |
|
371 else if (ret == KErrServerBusy) |
|
372 { |
|
373 //Show an information note that server is currently in use |
|
374 HBufC* noteText; |
|
375 noteText = StringLoader::LoadLC( R_VPN_INFO_POLICY_SERVER_IN_USE ); |
|
376 CAknInformationNote* note = new(ELeave)CAknInformationNote(ETrue); |
|
377 note->SetTimeout(CAknNoteDialog::ELongTimeout); //3sec |
|
378 note->ExecuteLD(noteText->Des()); |
|
379 CleanupStack::PopAndDestroy(); // noteText |
|
380 } |
|
381 } |
|
382 |
|
383 } |
|
384 |
|
385 void CVpnManagementUiServerContainer::SynchroniseServerL() |
|
386 { |
|
387 LOG_("CVpnManagementUiServerContainer::SynchroniseServerL"); |
|
388 |
|
389 // Get selection name for connecting via note |
|
390 // and save it to the member variable of iLoader |
|
391 iLoader.GetSelectionNameL( iLoader.iSelectionName ); |
|
392 //Show wait dialog |
|
393 iLoader.ShowWaitNoteL(); |
|
394 |
|
395 iLoader.VpnApiWrapperL().SynchroniseServerL( this ); |
|
396 |
|
397 |
|
398 //Set iNewServerDefinition to false, because when |
|
399 //we go to the policy view we don't want to show note |
|
400 //"new server defined synchronise now" |
|
401 iLoader.iNewServerDefinition = EFalse; |
|
402 |
|
403 } |
|
404 |
|
405 |
|
406 |
|
407 void CVpnManagementUiServerContainer::NotifySynchroniseServerCompleteL(TInt aResult) |
|
408 { |
|
409 LOG(Log::Printf(_L("CVpnManagementUiServerContainer::NotifySynchroniseServerCompleteL - Result %d\n"), aResult)); |
|
410 |
|
411 if ( iLoader.iWaitDialog ) |
|
412 { |
|
413 iLoader.DeleteWaitNoteL();//// deletes the wait dialog |
|
414 } |
|
415 |
|
416 |
|
417 if (aResult == KErrNone) |
|
418 { |
|
419 //Confirmation note |
|
420 HBufC* string = StringLoader::LoadLC( R_VPN_CONF_POLICY_SERVER_SYNC_OK ); |
|
421 CAknConfirmationNote* note = new ( ELeave ) CAknConfirmationNote( ETrue ); |
|
422 note->ExecuteLD( *string ); |
|
423 CleanupStack::PopAndDestroy( string ); |
|
424 } |
|
425 |
|
426 else if (aResult == KErrDiskFull) |
|
427 { |
|
428 CErrorUI* errorUi = CErrorUI::NewLC( *(CCoeEnv::Static()) ); |
|
429 errorUi->ShowGlobalErrorNoteL( KErrDiskFull ); |
|
430 CleanupStack::PopAndDestroy(); // errorUi |
|
431 } |
|
432 else if (aResult == KErrCancel) |
|
433 { |
|
434 // No operation, i.e. don't show anything |
|
435 } |
|
436 else |
|
437 { |
|
438 //Show an information note |
|
439 HBufC* noteText; |
|
440 noteText = StringLoader::LoadLC( R_VPN_INFO_POLICY_SERVER_SYNC_ERROR ); |
|
441 CAknInformationNote* note = new(ELeave)CAknInformationNote(ETrue); |
|
442 note->SetTimeout(CAknNoteDialog::ELongTimeout); //3sec |
|
443 note->ExecuteLD(noteText->Des()); |
|
444 CleanupStack::PopAndDestroy(); // noteText |
|
445 } |
|
446 |
|
447 iParent.SetMiddleSoftKeyL(ETrue); |
|
448 |
|
449 } |
|
450 |
|
451 |
|
452 void CVpnManagementUiServerContainer::HandleListBoxEventL (CEikListBox* /*aListBox*/, |
|
453 TListBoxEvent aEventType) |
|
454 { |
|
455 switch(aEventType) |
|
456 { |
|
457 case EEventEnterKeyPressed: |
|
458 case EEventItemSingleClicked: |
|
459 iParent.HandleCommandL(EVpnUiCmdEditServer); |
|
460 break; |
|
461 default: |
|
462 //Do nothing |
|
463 break; |
|
464 } |
|
465 } |
|
466 |
|
467 |
|
468 // --------------------------------------------------------- |
|
469 // CVpnManagementUiServerContainer::GetHelpContext |
|
470 // This function is called when Help application is launched. |
|
471 // (other items were commented in a header). |
|
472 // --------------------------------------------------------- |
|
473 // |
|
474 #ifdef __SERIES60_HELP |
|
475 void CVpnManagementUiServerContainer::GetHelpContext( |
|
476 TCoeHelpContext& aContext ) const |
|
477 { |
|
478 aContext.iMajor = KUidVpnManagementUi; |
|
479 aContext.iContext = KSET_HLP_VPN_POLICY_SERVERS; |
|
480 } |
|
481 #endif //__SERIES60_HELP |
|
482 |
|
483 // End of File |