wvuing/IMPSServiceSettingsUI/Src/CWVSettingsUISettingItemEditor.cpp
branchRCL_3
changeset 17 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
16:6ca72c0fe49a 17:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 2003 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:  Setting item editor
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CWVSettingsUISettingItemEditor.h"
       
    21 #include "CWVSettingsUIDialogImp.h"
       
    22 #include "WVSettingsUIPanics.h"
       
    23 #include "CWVSettingsUIDefs.h"
       
    24 #include "WVSettingsSharedDataNG.h"
       
    25 #include "CWVSettingsUICheckboxSettingPage.h"
       
    26 
       
    27 #include	<cwvsettingsUING.rsg>
       
    28 #include	<aknsettingitemlist.h>
       
    29 #include	<aknsettingpage.h>
       
    30 #include	<cimpssapsettings.h>
       
    31 #include	<cimpssapsettingsstore.h>
       
    32 #include	<stringloader.h>
       
    33 #include	<aknnotewrappers.h>
       
    34 #include	<AknCheckBoxSettingPage.h>
       
    35 #include	<aknpopupsettingpage.h>
       
    36 
       
    37 #include    <cimpspresenceconnectionuing.h>
       
    38 #include    <cpengnwsessionslotid2.h>
       
    39 
       
    40 // Defines whether first login to server has been done
       
    41 _LIT( KIMFirstLoginToServer, "IMFirstLoginToServer" );
       
    42 
       
    43 // ================= MEMBER FUNCTIONS =======================
       
    44 
       
    45 // ---------------------------------------------------------
       
    46 // CWVSettingsUISettingItemEditor::EditSettingItemL()
       
    47 //
       
    48 // (other items were commented in a header).
       
    49 // ---------------------------------------------------------
       
    50 //
       
    51 void CWVSettingsUISettingItemEditor::EditSettingItemL( TBool aIsPopUp,
       
    52                                                        TInt aListBoxIndex,
       
    53                                                        CAknSettingItemArray& aSettingItemList,
       
    54                                                        CIMPSSAPSettingsStore& aSAPSettingsStore,
       
    55                                                        TInt& aIMLoginType,
       
    56                                                        TBool& aIMLoginTypeEdited,
       
    57                                                        CSelectionItemList* aSelectedDaysIM,
       
    58                                                        TInt& aConnectHoursIMInt,
       
    59                                                        TBool& aIMConnHoursEdited,
       
    60                                                        TBool& aCancelled,
       
    61                                                        TInt aSettingItem,
       
    62                                                        CIMPSPresenceConnectionUi* aConnectionUI, /*= NULL */
       
    63                                                        TBool* aForcedLoginMade /*= NULL */ )
       
    64     {
       
    65     iSettingItemArray = &aSettingItemList;
       
    66     iSAPSettingsStore = &aSAPSettingsStore;
       
    67 
       
    68     if ( aConnectionUI )
       
    69         {
       
    70         iConnectionUI = aConnectionUI;
       
    71         }
       
    72     if ( aForcedLoginMade )
       
    73         {
       
    74         iForcedLoginMade = aForcedLoginMade;
       
    75         }
       
    76 
       
    77     switch ( aSettingItem )
       
    78         {
       
    79         case CWVSettingsUIDialogImp::EWVSettingsIMLoginType:
       
    80             {
       
    81             EditLoginTypeL( aIsPopUp,
       
    82                             aListBoxIndex,
       
    83                             aSettingItemList,
       
    84                             aSAPSettingsStore,
       
    85                             aIMLoginType,
       
    86                             aIMLoginTypeEdited,
       
    87                             aSelectedDaysIM,
       
    88                             aConnectHoursIMInt,
       
    89                             aIMConnHoursEdited,
       
    90                             aCancelled,
       
    91                             aSettingItem );
       
    92             break;
       
    93             }
       
    94         case CWVSettingsUIDialogImp::EWVSettingsIMConnDays:
       
    95             {
       
    96             // this is IM Connection days
       
    97             EditConnectedDaysL( aSelectedDaysIM, aCancelled );
       
    98             break;
       
    99             }
       
   100         case CWVSettingsUIDialogImp::EWVSettingsIMConnHours:
       
   101             {
       
   102             // this is IM connection hours
       
   103             EditConnectedHoursL( aConnectHoursIMInt, aCancelled );
       
   104             aIMConnHoursEdited = ETrue;
       
   105             break;
       
   106             }
       
   107         default:
       
   108             {
       
   109             break;
       
   110             }
       
   111         }
       
   112 
       
   113     iSettingItemArray->At( aListBoxIndex )->StoreL();
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------
       
   117 // CWVSettingsUISettingItemEditor::ShowMissingInfoErrorNoteL()
       
   118 //
       
   119 // (other items were commented in a header).
       
   120 // ---------------------------------------------------------
       
   121 //
       
   122 
       
   123 void CWVSettingsUISettingItemEditor::ShowMissingInfoErrorNoteL()
       
   124     {
       
   125     // load the note text
       
   126     HBufC* prompt = StringLoader::LoadLC( R_WVSETTINGSVIEW_ERROR_INFORMATION_MISSING );
       
   127     // Code scanner warning neglected to put variable on cleanup stack (Id: 35)
       
   128     // PrepareLC of the dialog pushes the dialog into cleanupstack
       
   129     CAknNoteDialog* dlg = new ( ELeave ) CAknNoteDialog( // CSI: 35 # See above
       
   130         CAknNoteDialog::EErrorTone , CAknNoteDialog::ELongTimeout );
       
   131     dlg->PrepareLC( R_WVSETTINGSVIEW_ERROR_NOTE_TEMPLATE );
       
   132     dlg->SetTextL( *prompt );
       
   133     // run the note
       
   134     dlg->RunLD();
       
   135     CleanupStack::PopAndDestroy( prompt );
       
   136     }
       
   137 
       
   138 
       
   139 // ---------------------------------------------------------
       
   140 // CWVSettingsUISettingItemEditor::EditConnectedDaysL()
       
   141 //
       
   142 // (other items were commented in a header).
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 void CWVSettingsUISettingItemEditor::EditConnectedDaysL( CSelectionItemList* aSelectionItemList,
       
   146                                                          TBool& aCancelled )
       
   147     {
       
   148     if ( aSelectionItemList )
       
   149         {
       
   150         CWVSettingsUICheckboxSettingPage* dlg = CWVSettingsUICheckboxSettingPage::NewL(
       
   151                                                     R_WVSETTINGSVIEW_SET_SCHEDULING, aSelectionItemList );
       
   152         aCancelled = !dlg->ExecuteLD();
       
   153         }
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------
       
   157 // CWVSettingsUISettingItemEditor::EditConnectedHoursL()
       
   158 //
       
   159 // (other items were commented in a header).
       
   160 // ---------------------------------------------------------
       
   161 //
       
   162 void CWVSettingsUISettingItemEditor::EditConnectedHoursL( TInt& aConnectHoursInt,
       
   163                                                           TBool& aCancelled )
       
   164     {
       
   165     aCancelled = EFalse;
       
   166     aConnectHoursInt = CWVSettingsUIDialogImp::EWVSettingsBetweenHours;
       
   167     }
       
   168 
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CWVSettingsUISettingItemEditor::HandleSettingPageEventL()
       
   172 //
       
   173 // (other items were commented in a header).
       
   174 // ---------------------------------------------------------
       
   175 //
       
   176 void CWVSettingsUISettingItemEditor::HandleSettingPageEventL( CAknSettingPage* /*aSettingPage*/,
       
   177                                                               TAknSettingPageEvent /*aEventType*/ )
       
   178     {
       
   179     // no need to do anything here
       
   180     }
       
   181 
       
   182 
       
   183 // ---------------------------------------------------------
       
   184 // CWVSettingsUISettingItemEditor::EditLoginTypeL()
       
   185 //
       
   186 // (other items were commented in a header).
       
   187 // ---------------------------------------------------------
       
   188 //
       
   189 void CWVSettingsUISettingItemEditor::EditLoginTypeL( TBool aIsPopUp,
       
   190                                                      TInt aListBoxIndex,
       
   191                                                      CAknSettingItemArray& aSettingItemList,
       
   192                                                      CIMPSSAPSettingsStore& aSAPSettingsStore,
       
   193                                                      TInt& aIMLoginType,
       
   194                                                      TBool& aIMLoginTypeEdited,
       
   195                                                      CSelectionItemList* aSelectedDaysIM,
       
   196                                                      TInt& aConnectHoursIMInt,
       
   197                                                      TBool& aIMConnHoursEdited,
       
   198                                                      TBool& aCancelled,
       
   199                                                      TInt aSettingItem )
       
   200     {
       
   201     HBufC* userId = NULL;
       
   202     HBufC* password = NULL;
       
   203     CIMPSSAPSettings* sapSettings = CIMPSSAPSettings::NewLC();
       
   204 
       
   205     TRAPD( err, iSAPSettingsStore->GetDefaultL( sapSettings, EIMPSIMAccessGroup ) );
       
   206 
       
   207     if ( err == KErrNone )
       
   208         {
       
   209         userId = sapSettings->SAPUserId().AllocLC();
       
   210         password = sapSettings->SAPUserPassword().AllocLC();
       
   211         }
       
   212     else if ( err == KErrNotFound )
       
   213         {
       
   214         // we do not want to leave if there is no default SAP
       
   215         }
       
   216     else
       
   217         {
       
   218         User::Leave( err );
       
   219         }
       
   220 
       
   221     TInt oldIMLoginType = aIMLoginType;
       
   222     iSettingItemArray->At( aListBoxIndex )->EditItemL( aIsPopUp );
       
   223     iSettingItemArray->At( aListBoxIndex )->StoreL();
       
   224     aIMLoginTypeEdited = ETrue;
       
   225 
       
   226     // check if the login type is automatic
       
   227     if ( ( aIMLoginType == EWVSettingsChatLoginAutoAlways ) ||
       
   228          ( aIMLoginType == EWVSettingsChatLoginAutoInHomeNW ) ||
       
   229          ( aIMLoginType == EWVSettingsChatLoginApplicationLaunch ) )
       
   230         {
       
   231         // check if the userid and password are defined
       
   232         if ( !userId || !password )
       
   233             {
       
   234             // show a note about the missing items return to editing
       
   235             aIMLoginType = oldIMLoginType;
       
   236             iSettingItemArray->At( aListBoxIndex )->LoadL();
       
   237             ShowMissingInfoErrorNoteL();
       
   238 
       
   239             EditSettingItemL ( aIsPopUp,
       
   240                                aListBoxIndex,
       
   241                                aSettingItemList,
       
   242                                aSAPSettingsStore,
       
   243                                aIMLoginType,
       
   244                                aIMLoginTypeEdited,
       
   245                                aSelectedDaysIM,
       
   246                                aConnectHoursIMInt,
       
   247                                aIMConnHoursEdited,
       
   248                                aCancelled,
       
   249                                aSettingItem );
       
   250             }
       
   251         // check that user id has some data
       
   252         else
       
   253             {
       
   254             TBool errorShown( EFalse );
       
   255             if ( userId )
       
   256                 {
       
   257                 if ( 0 == userId->Length() )
       
   258                     {
       
   259                     // show a note about the missing items return to editing
       
   260                     aIMLoginType = oldIMLoginType;
       
   261                     iSettingItemArray->At( aListBoxIndex )->LoadL();
       
   262                     ShowMissingInfoErrorNoteL();
       
   263                     errorShown = ETrue;
       
   264 
       
   265                     EditSettingItemL ( aIsPopUp,
       
   266                                        aListBoxIndex,
       
   267                                        aSettingItemList,
       
   268                                        aSAPSettingsStore,
       
   269                                        aIMLoginType,
       
   270                                        aIMLoginTypeEdited,
       
   271                                        aSelectedDaysIM,
       
   272                                        aConnectHoursIMInt,
       
   273                                        aIMConnHoursEdited,
       
   274                                        aCancelled,
       
   275                                        aSettingItem );
       
   276                     }
       
   277                 }
       
   278             // check that password has some data
       
   279             if ( password )
       
   280                 {
       
   281                 if ( !errorShown )
       
   282                     {
       
   283                     // no need to check for password if user id already failed
       
   284                     if ( 0 == password->Length() )
       
   285                         {
       
   286                         // show a note about the missing items return to editing
       
   287                         aIMLoginType = oldIMLoginType;
       
   288                         iSettingItemArray->At( aListBoxIndex )->LoadL();
       
   289                         ShowMissingInfoErrorNoteL();
       
   290                         errorShown = ETrue;
       
   291 
       
   292                         EditSettingItemL ( aIsPopUp,
       
   293                                            aListBoxIndex,
       
   294                                            aSettingItemList,
       
   295                                            aSAPSettingsStore,
       
   296                                            aIMLoginType,
       
   297                                            aIMLoginTypeEdited,
       
   298                                            aSelectedDaysIM,
       
   299                                            aConnectHoursIMInt,
       
   300                                            aIMConnHoursEdited,
       
   301                                            aCancelled,
       
   302                                            aSettingItem );
       
   303                         }
       
   304                     }
       
   305                 }
       
   306 
       
   307             // UserId and password ok, force login before activating
       
   308             // automatic login type if user has not logged in
       
   309             // to current server before
       
   310             if ( !errorShown )
       
   311                 {
       
   312                 if ( !ForceLoginL( *sapSettings ) )
       
   313                     {
       
   314                     // Query not accepted or login failed, restore old login type
       
   315                     aIMLoginType = oldIMLoginType;
       
   316                     iSettingItemArray->At( aListBoxIndex )->LoadL();
       
   317 
       
   318                     EditSettingItemL ( aIsPopUp,
       
   319                                        aListBoxIndex,
       
   320                                        aSettingItemList,
       
   321                                        aSAPSettingsStore,
       
   322                                        aIMLoginType,
       
   323                                        aIMLoginTypeEdited,
       
   324                                        aSelectedDaysIM,
       
   325                                        aConnectHoursIMInt,
       
   326                                        aIMConnHoursEdited,
       
   327                                        aCancelled,
       
   328                                        aSettingItem );
       
   329                     }
       
   330                 }
       
   331             }
       
   332         }
       
   333 
       
   334     if ( password )
       
   335         {
       
   336         CleanupStack::PopAndDestroy( password ); // password
       
   337         }
       
   338     if ( userId )
       
   339         {
       
   340         CleanupStack::PopAndDestroy( userId ); //
       
   341         }
       
   342     CleanupStack::PopAndDestroy( sapSettings ); // sapSettings
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CWVSettingsUISettingItemEditor::ForceLoginL
       
   347 //
       
   348 // (other items were commented in a header).
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 TBool CWVSettingsUISettingItemEditor::ForceLoginL( CIMPSSAPSettings& aSapSettings )
       
   352     {
       
   353     TInt firstLogin = 0;
       
   354     TInt sapError = -1;
       
   355     sapError = aSapSettings.GetOpaqueInt( KIMFirstLoginToServer, firstLogin );
       
   356 
       
   357     if ( sapError != KErrNotFound )
       
   358         {
       
   359         User::LeaveIfError( sapError );
       
   360         }
       
   361 
       
   362     // First login
       
   363     if ( firstLogin == 0 )
       
   364         {
       
   365         // Init to EFalse
       
   366         *iForcedLoginMade = EFalse;
       
   367 
       
   368         // Ask confirmation about logging out
       
   369         CAknQueryDialog* dlg = new ( ELeave ) CAknQueryDialog(
       
   370             CAknQueryDialog::ENoTone );
       
   371         CleanupStack::PushL( dlg );
       
   372 
       
   373         HBufC* text = StringLoader::LoadLC(
       
   374                           R_WVSETTINGSVIEW_CANNOT_ACTIVATE_QUERY,
       
   375                           aSapSettings.SAPName(),
       
   376                           CEikonEnv::Static() );
       
   377 
       
   378         dlg->SetPromptL( *text );
       
   379         CleanupStack::PopAndDestroy( text );
       
   380         CleanupStack::Pop( dlg );
       
   381 
       
   382         TInt ret = dlg->ExecuteLD( R_FORCE_LOGIN_CONFIRMATION_QUERY );
       
   383 
       
   384         if ( ( ret == EAknSoftkeyOk ) || ( ret == EAknSoftkeyYes ) )
       
   385             {
       
   386             CPEngNWSessionSlotID2* sessionSlotID =
       
   387                 CPEngNWSessionSlotID2::NewL();
       
   388             CleanupStack::PushL( sessionSlotID );
       
   389 
       
   390             TInt loginError = iConnectionUI->LoginL( EIMPSConnClientIM,
       
   391                                                      EIMPSApplicationLaunch,
       
   392                                                      *sessionSlotID );
       
   393 
       
   394             CleanupStack::PopAndDestroy( sessionSlotID );
       
   395 
       
   396             // Login failed
       
   397             if ( loginError != KErrNone )
       
   398                 {
       
   399                 return EFalse;
       
   400                 }
       
   401 
       
   402             *iForcedLoginMade = ETrue;
       
   403             }
       
   404         else
       
   405             {
       
   406             // User cancelled force login query
       
   407             return EFalse;
       
   408             }
       
   409         }
       
   410     else
       
   411         {
       
   412         *iForcedLoginMade = EFalse;
       
   413         }
       
   414 
       
   415     // Query accepted, login completed
       
   416     return ETrue;
       
   417     }
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // CWVSettingsUISettingItemEditor::CWVSettingsUISettingItemEditor
       
   421 // C++ default constructor can NOT contain any code, that
       
   422 // might leave.
       
   423 // -----------------------------------------------------------------------------
       
   424 //
       
   425 CWVSettingsUISettingItemEditor::CWVSettingsUISettingItemEditor()
       
   426     {
       
   427     }
       
   428 
       
   429 // Destructor
       
   430 CWVSettingsUISettingItemEditor::~CWVSettingsUISettingItemEditor()
       
   431     {
       
   432     }
       
   433 
       
   434 //  End of File