|
1 /* |
|
2 * Copyright (c) 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: This file implements class CIpsSetUi. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <eikfrlb.h> // CEikFormattedCellListBox |
|
21 #include <aknappui.h> // CAknAppUi |
|
22 #include <AknsDrawUtils.h> |
|
23 #include <akntitle.h> // CAknTitlePane |
|
24 #include <hlplch.h> // HlpLauncher |
|
25 #include <eikrted.h> // CEikRichTextEditor |
|
26 #include <ipssossettings.rsg> |
|
27 #include <data_caging_path_literals.hrh> |
|
28 #include <AlwaysOnlineManagerClient.h> |
|
29 |
|
30 #include "ipssetui.h" |
|
31 #include "ipssetuidialog.h" |
|
32 #include "ipssetutilsdisconnectlogic.h" |
|
33 |
|
34 // becuase of RD_IPS_AO_PLUGIN flag, can be removed |
|
35 // when flag is removed |
|
36 #include "ipsplgsosbaseplugin.hrh" |
|
37 |
|
38 const TInt KIpsSetOptionsMenuItemCount = 4; |
|
39 _LIT( KIpsSetUiResourceFile,"z:IpsSosSettings.rsc" ); |
|
40 |
|
41 // ============================ LOCAL FUNCTIONS =============================== |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 // ---------------------------------------------------------------------------- |
|
46 // CIpsSetUi::CIpsSetUi |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 CIpsSetUi::CIpsSetUi( const TMsvId aMailboxId, TBool aFolderSettingView ) //<cmail> |
|
50 : |
|
51 iFlags( 0x00 ), |
|
52 iListBox( NULL ), |
|
53 iSettings( NULL ), |
|
54 iResourceLoader( *iCoeEnv ), |
|
55 iMailboxId( aMailboxId ) |
|
56 , iShowFolderSettings(aFolderSettingView), iIgnoreOneBackKey(ETrue) //<cmail> |
|
57 { |
|
58 FUNC_LOG; |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // CIpsSetUi::NewL() |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 CIpsSetUi* CIpsSetUi::NewL( const TMsvId aMailboxId, TBool aFolderSettingView ) //<cmail> |
|
66 { |
|
67 FUNC_LOG; |
|
68 CIpsSetUi* self = NewLC( aMailboxId, aFolderSettingView ); //<cmail> |
|
69 CleanupStack::Pop( self ); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------------------------------- |
|
75 // CIpsSetUi::NewLC() |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 CIpsSetUi* CIpsSetUi::NewLC( const TMsvId aMailboxId, TBool aFolderSettingView ) //<cmail> |
|
79 { |
|
80 FUNC_LOG; |
|
81 CIpsSetUi* self = new ( ELeave ) CIpsSetUi( aMailboxId, aFolderSettingView ); //<cmail> |
|
82 CleanupStack::PushL( self ); |
|
83 self->ConstructL(); |
|
84 |
|
85 return self; |
|
86 } |
|
87 |
|
88 // ---------------------------------------------------------------------------- |
|
89 // CIpsSetUi::~CIpsSetUi() |
|
90 // ---------------------------------------------------------------------------- |
|
91 // |
|
92 CIpsSetUi::~CIpsSetUi() |
|
93 { |
|
94 FUNC_LOG; |
|
95 iResourceLoader.Close(); |
|
96 delete iSession; |
|
97 delete iSettings; |
|
98 iSettings = NULL; |
|
99 iListBox = NULL; |
|
100 iTextEditor = NULL; |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------------------------------- |
|
104 // CIpsSetUi::ConstructL() |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 void CIpsSetUi::ConstructL() |
|
108 { |
|
109 FUNC_LOG; |
|
110 iResourceMenuBar = R_IPS_SET_MENUBAR; |
|
111 |
|
112 // Call the base ConstructL |
|
113 CAknDialog::ConstructL( iResourceMenuBar ); |
|
114 LoadResourceL(); |
|
115 iSession = CMsvSession::OpenSyncL( *this ); |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------------------------- |
|
119 // CIpsSetUi::OkToExitL |
|
120 // ---------------------------------------------------------------------------- |
|
121 // |
|
122 TBool CIpsSetUi::OkToExitL( TInt aButtonId ) |
|
123 { |
|
124 FUNC_LOG; |
|
125 TBool allowQuit = EFalse; |
|
126 |
|
127 // Exit not issued, forward the call to command processor |
|
128 if ( !( iFlags & EIpsSetUiShouldExit ) && |
|
129 !( iFlags & EIpsSetUiShouldClose ) ) |
|
130 { |
|
131 iSettings->ProcessCommandL( aButtonId ); |
|
132 } |
|
133 else |
|
134 { |
|
135 // Should quit |
|
136 allowQuit = iSettings->OkToExitL( aButtonId ); |
|
137 |
|
138 // Clear the flag after usage |
|
139 iFlags &= ~EIpsSetUiQueryClose; |
|
140 |
|
141 // If quit is allowed, store the settings, otherwise clear the flag |
|
142 if ( allowQuit && iFlags & EIpsSetUiAllowSave ) |
|
143 { |
|
144 iFlags &= ~EIpsSetUiAllowSave; |
|
145 |
|
146 DisconnectIfOnlineL( EFalse ); |
|
147 // Failing to store the settings should cause panic, to prevent |
|
148 // the settings to stop into unwanted errors |
|
149 TRAP_IGNORE( iSettings->StoreSettingsToAccountL() ); |
|
150 |
|
151 // switch ao back on |
|
152 // <cmail> RD_IPS_AO_PLUGIN flag removed |
|
153 RAlwaysOnlineClientSession aosession; |
|
154 TInt err = aosession.Connect(); |
|
155 if ( err == KErrNone ) |
|
156 { |
|
157 TPckgBuf<TMsvId> mboxBuf( iMailboxId ); |
|
158 TRAP( err, aosession.RelayCommandL( |
|
159 EServerAPIEmailTurnOn, |
|
160 mboxBuf ) ); |
|
161 } |
|
162 aosession.Close(); |
|
163 // </cmail> |
|
164 } |
|
165 else |
|
166 { |
|
167 // Clear the flags |
|
168 iFlags &= ~EIpsSetUiShouldExit; |
|
169 iFlags &= ~EIpsSetUiShouldClose; |
|
170 } |
|
171 |
|
172 // Exit, now |
|
173 if ( allowQuit ) |
|
174 { |
|
175 allowQuit = CAknDialog::OkToExitL( EAknSoftkeyCancel ); |
|
176 } |
|
177 } |
|
178 |
|
179 return allowQuit; |
|
180 } |
|
181 |
|
182 // ---------------------------------------------------------------------------- |
|
183 // CIpsSetUi::HandleResourceChange |
|
184 // ---------------------------------------------------------------------------- |
|
185 // |
|
186 void CIpsSetUi::HandleResourceChange( TInt aType ) |
|
187 { |
|
188 FUNC_LOG; |
|
189 CAknDialog::HandleResourceChange( aType ); |
|
190 |
|
191 if ( iTextEditor && aType == KEikDynamicLayoutVariantSwitch ) |
|
192 { |
|
193 TRect rect = Rect(); |
|
194 iTextEditor->SetRect( rect ); |
|
195 iTextEditor->HandleResourceChange( aType ); |
|
196 iListBox->SetRect( rect ); |
|
197 iListBox->HandleResourceChange( aType ); |
|
198 } |
|
199 if ( aType == KAknsMessageSkinChange ) |
|
200 { |
|
201 SetFontAndSkin(); |
|
202 } |
|
203 } |
|
204 |
|
205 // ---------------------------------------------------------------------------- |
|
206 // CIpsSetUi::SetFontAndSkin |
|
207 // ---------------------------------------------------------------------------- |
|
208 // |
|
209 void CIpsSetUi::SetFontAndSkin() |
|
210 { |
|
211 FUNC_LOG; |
|
212 if ( iTextEditor ) |
|
213 { |
|
214 MAknsControlContext* context = |
|
215 AknsDrawUtils::ControlContext( iListBox ); |
|
216 TRAP_IGNORE( |
|
217 iTextEditor->SetSkinBackgroundControlContextL( context ) ); |
|
218 |
|
219 const CFont* font = ControlEnv()->NormalFont(); |
|
220 TFontSpec fontSpec = font->FontSpecInTwips(); |
|
221 |
|
222 TCharFormat charFormat; |
|
223 TCharFormatMask formatMask; |
|
224 charFormat.iFontSpec = fontSpec; |
|
225 |
|
226 formatMask.SetAttrib( EAttFontTypeface ); |
|
227 formatMask.SetAttrib( EAttFontHeight ); |
|
228 formatMask.SetAttrib( EAttFontPosture ); |
|
229 formatMask.SetAttrib( EAttFontStrokeWeight ); |
|
230 |
|
231 TRgb textColor; |
|
232 TInt error = AknsUtils::GetCachedColor( |
|
233 AknsUtils::SkinInstance(), |
|
234 textColor, |
|
235 KAknsIIDQsnTextColors, |
|
236 EAknsCIQsnTextColorsCG7 ); |
|
237 |
|
238 if ( error != KErrNone ) |
|
239 { |
|
240 textColor = AKN_LAF_COLOR_STATIC( 215 ); |
|
241 } |
|
242 |
|
243 charFormat.iFontPresentation.iTextColor = textColor; |
|
244 formatMask.SetAttrib( EAttColor ); |
|
245 |
|
246 CCharFormatLayer* charFormatLayer = NULL; |
|
247 |
|
248 TRAP( error, |
|
249 charFormatLayer = CCharFormatLayer::NewL( charFormat, formatMask ) |
|
250 ); |
|
251 |
|
252 if ( error ) |
|
253 { |
|
254 delete charFormatLayer; |
|
255 } |
|
256 else |
|
257 { |
|
258 iTextEditor->SetCharFormatLayer( charFormatLayer ); |
|
259 } |
|
260 } |
|
261 |
|
262 } |
|
263 |
|
264 // ---------------------------------------------------------------------------- |
|
265 // CIpsSetUi::PreLayoutDynInitL |
|
266 // ---------------------------------------------------------------------------- |
|
267 // |
|
268 void CIpsSetUi::PreLayoutDynInitL() |
|
269 { |
|
270 FUNC_LOG; |
|
271 // Get the pointer to titlepane |
|
272 CEikStatusPane* sp = |
|
273 static_cast<CAknAppUi*>( |
|
274 iEikonEnv->EikAppUi() )->StatusPane(); |
|
275 CAknTitlePane* title = static_cast<CAknTitlePane*>( |
|
276 sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
277 |
|
278 CEikButtonGroupContainer& cba = ButtonGroupContainer(); |
|
279 |
|
280 // check connect state before entering settings |
|
281 DisconnectIfOnlineL(); |
|
282 |
|
283 // <cmail> RD_IPS_AO_PLUGIN flag removed |
|
284 // prevent ao operations during settings edit |
|
285 RAlwaysOnlineClientSession aosession; |
|
286 TInt err = aosession.Connect(); |
|
287 if ( err == KErrNone ) |
|
288 { |
|
289 TPckgBuf<TMsvId> mboxBuf( iMailboxId ); |
|
290 TRAP_IGNORE( aosession.RelayCommandL( |
|
291 EServerAPIEmailTurnOff, |
|
292 mboxBuf ) ); |
|
293 } |
|
294 aosession.Close(); |
|
295 // </cmail> |
|
296 |
|
297 // Prepare the listbox |
|
298 iListBox = static_cast<CEikFormattedCellListBox*>( |
|
299 Control( EIpsSetUiIdListBox ) ); |
|
300 |
|
301 iSettings = CIpsSetUiDialogCtrl::NewL( |
|
302 *this, *iListBox, *title, cba, *iSession, iFlags ); |
|
303 |
|
304 //<cmail> |
|
305 //When settings are launched from folderlist view, we need to go directly to 'what to sync' view |
|
306 if(iShowFolderSettings) |
|
307 { |
|
308 if(iSettings->CountInListBox() > 1) |
|
309 { |
|
310 iListBox->SetCurrentItemIndex(1); |
|
311 iSettings->ProcessCommandL( EAknSoftkeySelect ); |
|
312 if(iSettings->CountInListBox() > 2) |
|
313 { |
|
314 iListBox->SetCurrentItemIndex(2); |
|
315 } |
|
316 } |
|
317 } |
|
318 //</cmail> |
|
319 } |
|
320 |
|
321 // ---------------------------------------------------------------------------- |
|
322 // CIpsSetUi::ProcessCommandL |
|
323 // ---------------------------------------------------------------------------- |
|
324 // |
|
325 void CIpsSetUi::ProcessCommandL( TInt aCommandId ) |
|
326 { |
|
327 FUNC_LOG; |
|
328 // Forward the commands |
|
329 CAknDialog::ProcessCommandL( aCommandId ); |
|
330 |
|
331 // Forward command either to wizard or setting dialog |
|
332 iSettings->ProcessCommandL( aCommandId ); |
|
333 } |
|
334 |
|
335 void CIpsSetUi::LaunchMenuL() |
|
336 { |
|
337 if ( iFlags & EIpsSetUiOpenOptionsMenu ) |
|
338 { |
|
339 iFlags &= ~EIpsSetUiOpenOptionsMenu; |
|
340 TIpsSetUiSettingsType type = iSettings->CurrentItem()->iItemType; |
|
341 //sub-menu |
|
342 if ( type == EIpsSetUiMenuArray ) |
|
343 { |
|
344 iFlags |= EIpsSetUiPositionSubMenu; |
|
345 iFlags &= ~EIpsSetUiSettingsMenuItem; |
|
346 } |
|
347 //settings item |
|
348 else if( type == EIpsSetUiRadioButtonArray || |
|
349 type == EIpsSetUiItemText || |
|
350 type == EIpsSetUiUndefined || |
|
351 type == EIpsSetUiCheckBoxArray ) |
|
352 { |
|
353 iFlags |= EIpsSetUiSettingsMenuItem; |
|
354 iFlags &= ~EIpsSetUiPositionSubMenu; |
|
355 } |
|
356 else |
|
357 { |
|
358 iFlags &= ~EIpsSetUiPositionSubMenu; |
|
359 iFlags &= ~EIpsSetUiSettingsMenuItem; |
|
360 } |
|
361 DisplayMenuL(); |
|
362 } |
|
363 } |
|
364 |
|
365 // ---------------------------------------------------------------------------- |
|
366 // CIpsSetUi::OfferKeyEventL |
|
367 // ---------------------------------------------------------------------------- |
|
368 // |
|
369 TKeyResponse CIpsSetUi::OfferKeyEventL( |
|
370 const TKeyEvent& aKeyEvent, |
|
371 TEventCode aType ) |
|
372 { |
|
373 FUNC_LOG; |
|
374 |
|
375 //<cmail> |
|
376 // When settings are launched from folder list view, we need to show directly 'what to sync' view |
|
377 // this logic is used when coming back from that view |
|
378 if( (aType == EEventKeyUp) && (aKeyEvent.iScanCode == EStdKeyDevice1) |
|
379 && (iShowFolderSettings) && iIgnoreOneBackKey) |
|
380 { |
|
381 iFlags |= EIpsSetUiShouldClose; |
|
382 } |
|
383 iIgnoreOneBackKey = ETrue; |
|
384 //</cmail> |
|
385 |
|
386 // Offer the key event to existing mailbox setting handler |
|
387 TKeyResponse ret = iSettings->OfferKeyEventL( aKeyEvent, aType ); |
|
388 |
|
389 // Improve menu handling here!!! |
|
390 |
|
391 // Show the menu, if asked |
|
392 LaunchMenuL(); |
|
393 |
|
394 // Check if exit has been issued |
|
395 if ( iFlags & EIpsSetUiShouldExit || |
|
396 iFlags & EIpsSetUiShouldClose ) |
|
397 { |
|
398 DoQuitL(); |
|
399 |
|
400 // Quit attempted, so consume the key |
|
401 ret = EKeyWasConsumed; |
|
402 } |
|
403 |
|
404 if ( ret != EKeyWasConsumed ) |
|
405 { |
|
406 ret = CAknDialog::OfferKeyEventL( aKeyEvent, aType ); |
|
407 } |
|
408 |
|
409 return ret; |
|
410 } |
|
411 |
|
412 // ---------------------------------------------------------------------------- |
|
413 // CIpsSetUi::DynInitMenuPaneL() |
|
414 // ---------------------------------------------------------------------------- |
|
415 // |
|
416 void CIpsSetUi::DynInitMenuPaneL( |
|
417 TInt /* aResourceId */, |
|
418 CEikMenuPane* aMenuPane ) |
|
419 { |
|
420 FUNC_LOG; |
|
421 if ( aMenuPane->NumberOfItemsInPane() == KIpsSetOptionsMenuItemCount ) |
|
422 { |
|
423 aMenuPane->SetItemDimmed( |
|
424 EAknSoftkeyOpen, iFlags & EIpsSetUiSettingsMenuItem ); |
|
425 aMenuPane->SetItemDimmed( |
|
426 EAknSoftkeySelect, iFlags & EIpsSetUiPositionSubMenu ); |
|
427 } |
|
428 } |
|
429 |
|
430 // ---------------------------------------------------------------------------- |
|
431 // CIpsSetUi::DoQuitL() |
|
432 // ---------------------------------------------------------------------------- |
|
433 // |
|
434 void CIpsSetUi::DoQuitL() |
|
435 { |
|
436 FUNC_LOG; |
|
437 // Start the exit process, the query is shown during TryExitL call |
|
438 if ( iFlags & EIpsSetUiShouldExit ) |
|
439 { |
|
440 TryExitL( EAknSoftkeyExit ); |
|
441 } |
|
442 else |
|
443 { |
|
444 TryExitL( EAknSoftkeyCancel ); |
|
445 } |
|
446 } |
|
447 |
|
448 |
|
449 // ---------------------------------------------------------------------------- |
|
450 // CIpsSetUi::GetHelpContext() |
|
451 // ---------------------------------------------------------------------------- |
|
452 // |
|
453 void CIpsSetUi::GetHelpContext( TCoeHelpContext& aContext ) const |
|
454 { |
|
455 FUNC_LOG; |
|
456 iSettings->GetHelpContext( aContext ); |
|
457 } |
|
458 |
|
459 // ---------------------------------------------------------------------------- |
|
460 // CIpsSetUi::LaunchHelpL() |
|
461 // ---------------------------------------------------------------------------- |
|
462 // |
|
463 void CIpsSetUi::LaunchHelpL() |
|
464 { |
|
465 FUNC_LOG; |
|
466 CCoeAppUi* appUi = static_cast<CCoeAppUi*>( ControlEnv()->AppUi() ); |
|
467 CArrayFix<TCoeHelpContext>* helpContext = appUi->AppHelpContextL(); |
|
468 HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), helpContext ); |
|
469 } |
|
470 |
|
471 void CIpsSetUi::HandleSessionEventL( |
|
472 TMsvSessionEvent /*aEvent*/, |
|
473 TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
474 { |
|
475 FUNC_LOG; |
|
476 // handle general server events if needed |
|
477 // EMsvCloseSession |
|
478 // EMsvServerReady |
|
479 // EMsvServerFailedToStart |
|
480 // EMsvCorruptedIndexRebuilt |
|
481 // EMsvServerTerminated |
|
482 } |
|
483 |
|
484 // --------------------------------------------------------------------------- |
|
485 // CIpsSetUi::LoadResourceL() |
|
486 // --------------------------------------------------------------------------- |
|
487 // |
|
488 void CIpsSetUi::LoadResourceL() |
|
489 { |
|
490 FUNC_LOG; |
|
491 TFileName fileName; |
|
492 TParse parse; |
|
493 parse.Set( KIpsSetUiResourceFile, &KDC_RESOURCE_FILES_DIR, NULL ); |
|
494 fileName.Copy( parse.FullName() ); |
|
495 |
|
496 // Attempt to load the resource |
|
497 iResourceLoader.OpenL( fileName ); |
|
498 } |
|
499 |
|
500 void CIpsSetUi::DisconnectIfOnlineL( TBool aDoShowQuery ) |
|
501 { |
|
502 FUNC_LOG; |
|
503 CIpsSetUtilsDisconnectLogic* dLogic = CIpsSetUtilsDisconnectLogic::NewL( |
|
504 *iSession, iMailboxId ); |
|
505 CleanupStack::PushL( dLogic ); |
|
506 // check if mailbox is online and disconnect |
|
507 TInt result = KErrNone; |
|
508 // <cmail> |
|
509 TInt error = KErrNone; |
|
510 TRAP( error, result = dLogic->RunDisconnectLogicL( aDoShowQuery ) ); |
|
511 __ASSERT_DEBUG( error == KErrNone, |
|
512 User::Panic( KIpsSetGenPanicLit, error )); |
|
513 // </cmail> |
|
514 |
|
515 if ( result == KErrCancel ) |
|
516 { |
|
517 User::Leave( KErrCancel ); |
|
518 } |
|
519 CleanupStack::PopAndDestroy( dLogic ); |
|
520 } |
|
521 |
|
522 // --------------------------------------------------------------------------- |
|
523 // CIpsSetUi::MailboxId() |
|
524 // --------------------------------------------------------------------------- |
|
525 // |
|
526 TMsvId CIpsSetUi::MailboxId() |
|
527 { |
|
528 FUNC_LOG; |
|
529 return iMailboxId; |
|
530 } |
|
531 |
|
532 //<cmail> |
|
533 // --------------------------------------------------------------------------- |
|
534 // CIpsSetUi::SetIgnoreOneBackKey() |
|
535 // --------------------------------------------------------------------------- |
|
536 // |
|
537 void CIpsSetUi::SetIgnoreOneBackKey(TBool aIgnoreBackKey) |
|
538 { |
|
539 iIgnoreOneBackKey = aIgnoreBackKey; |
|
540 } |
|
541 //</cmail> |
|
542 |
|
543 |
|
544 |
|
545 // End of File |
|
546 |
|
547 |
|
548 |