wvuing/wvcommandutils/Src/CCACommandSettingSapExtCmd.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Implementation for Settings Interface for getting/setting tonefilename etc
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <PathInfo.h>
       
    23 #include <bautils.h>
       
    24 #include <eikenv.h>
       
    25 #include <cimpspresenceconnectionuing.h>
       
    26 #include <CIMPSSAPSettingsStore.h>
       
    27 #include <CIMPSSAPSettings.h>
       
    28 #include <CIMPSSAPSettingsList.h>
       
    29 #include <CPEngNWSessionSlotID2.h>
       
    30 
       
    31 
       
    32 #include "ChatDefinitions.h"
       
    33 #include "ChatDebugPrint.h"
       
    34 #include "CCACommandSettingSapExtCmd.h"
       
    35 
       
    36 
       
    37 
       
    38 //----------------------------------------------------------------------------
       
    39 // .CCACommandSettingSapExtCmd::NewLC
       
    40 // (other items were commented in a header).
       
    41 //----------------------------------------------------------------------------
       
    42 
       
    43 CCACommandSettingSapExtCmd* CCACommandSettingSapExtCmd::NewLC(
       
    44     MCASettingsPC* aSettingsPC,
       
    45     TBool aPreserveSessionIdInExit,/*= EFalse*/
       
    46     CIMPSSAPSettings* aSAPSettings /*= NULL*/ )
       
    47     {
       
    48     CCACommandSettingSapExtCmd* self = new( ELeave ) CCACommandSettingSapExtCmd(
       
    49         aPreserveSessionIdInExit,
       
    50         aSettingsPC );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL( aSAPSettings );
       
    53     return self;
       
    54     }
       
    55 
       
    56 
       
    57 //----------------------------------------------------------------------------
       
    58 // CCACommandSettingSapExtCmd::NewL()
       
    59 // Two-phased constructor.
       
    60 //----------------------------------------------------------------------------
       
    61 
       
    62 CCACommandSettingSapExtCmd* CCACommandSettingSapExtCmd::NewL(
       
    63     MCASettingsPC* aSettingsPC,
       
    64     TBool aPreserveSessionIdInExit,/*= EFalse*/
       
    65     CIMPSSAPSettings* aSAPSettings /*= NULL*/ )
       
    66     {
       
    67     CCACommandSettingSapExtCmd* self =
       
    68         CCACommandSettingSapExtCmd::NewLC( aSettingsPC,
       
    69                                            aPreserveSessionIdInExit,
       
    70                                            aSAPSettings );
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74 
       
    75 
       
    76 //----------------------------------------------------------------------------
       
    77 // CCACommandSettingSapExtCmd::ConstructL()
       
    78 // Symbian 2nd phase constructor can leave.
       
    79 //----------------------------------------------------------------------------
       
    80 
       
    81 void CCACommandSettingSapExtCmd::ConstructL( CIMPSSAPSettings* aSAPSettings )
       
    82     {
       
    83     iSAPSettings = aSAPSettings;
       
    84     iConnectionUI = CIMPSPresenceConnectionUi::NewL( EIMPSConnClientIM );
       
    85     iSAPSettingsStore = CIMPSSAPSettingsStore::NewL();
       
    86 
       
    87     }
       
    88 
       
    89 //----------------------------------------------------------------------------
       
    90 // CCACommandSettingSapExtCmd::CCACommandSettingSapExtCmd
       
    91 // C++ default constructor can NOT contain any code, that
       
    92 // might leave.
       
    93 //----------------------------------------------------------------------------
       
    94 
       
    95 
       
    96 CCACommandSettingSapExtCmd::CCACommandSettingSapExtCmd(
       
    97     TBool aPreserveSessionIdInExit,
       
    98     MCASettingsPC* aSettingsPC )
       
    99         : iSettingsPC( aSettingsPC ),
       
   100         iPreserveSessionIdInExit( aPreserveSessionIdInExit )
       
   101     {
       
   102 
       
   103     }
       
   104 
       
   105 //----------------------------------------------------------------------------
       
   106 // CCACommandSettingSapExtCmd::~CCACommandSettingSapExtCmd
       
   107 // Destructor
       
   108 //----------------------------------------------------------------------------
       
   109 
       
   110 CCACommandSettingSapExtCmd::~CCACommandSettingSapExtCmd()
       
   111     {
       
   112     if ( iPreserveSessionIdInExit && iConnectionUI )
       
   113         {
       
   114         TRAPD( err,
       
   115             {
       
   116             // this class was invoked from IM Launcher call chain,
       
   117             // when Always Online is active. now make sure the IMPSCUI
       
   118             // Session Id is given to an instance existing in Always Online
       
   119             // (otherwise it'll be deleted and logout will happen)
       
   120             CPEngNWSessionSlotID2* sessionSlotID =
       
   121             iConnectionUI->GetActiveNWSessionSlotIDL(
       
   122                 EIMPSConnClientIM );
       
   123             CleanupStack::PushL( sessionSlotID );
       
   124             iConnectionUI->HandleApplicationExitL( EIMPSConnClientIM,
       
   125                                                    EIMPSLeaveSessionOpenExit,
       
   126                                                    *sessionSlotID );
       
   127             CleanupStack::PopAndDestroy( sessionSlotID );
       
   128             } );    // TRAPD
       
   129 
       
   130         if ( err != KErrNone )
       
   131             {
       
   132             CActiveScheduler::Current()->Error( err );
       
   133             }
       
   134         // now it's safe to exit even in Always Online case
       
   135         }
       
   136     if ( iConnectionUI )
       
   137         {
       
   138         delete iConnectionUI;
       
   139         }
       
   140 
       
   141     if ( iSAPSettingsStore )
       
   142         {
       
   143         delete iSAPSettingsStore;
       
   144         }
       
   145 
       
   146 
       
   147     }
       
   148 
       
   149 
       
   150 //----------------------------------------------------------------------------
       
   151 // CCACommandSettingSapExtCmd::SetIntValueL
       
   152 // Sets int value to SAP settings
       
   153 // (other items were commented in a header).
       
   154 //----------------------------------------------------------------------------
       
   155 
       
   156 void CCACommandSettingSapExtCmd::SetIntValueL( const TDesC& aKey,
       
   157                                                TInt aValue )
       
   158     {
       
   159     CHAT_DP_TXT( "CCAAppSettingsSAPExt::SetIntValueL" );
       
   160     CIMPSSAPSettings* sapSettings = NULL;
       
   161     if ( !iSAPSettings )
       
   162         {
       
   163         sapSettings = StoredSAPLC();
       
   164         }
       
   165     else
       
   166         {
       
   167         sapSettings = iSAPSettings;
       
   168         }
       
   169     if ( sapSettings )
       
   170         {
       
   171         TInt id( sapSettings->Uid() );
       
   172         CHAT_DP( D_CHAT_LIT( "found sap (%d), setting value %d" ), id, aValue );
       
   173         sapSettings->SetOpaqueInt( aKey, aValue );
       
   174 
       
   175         // update sapSettings
       
   176         iSAPSettingsStore->UpdateOldSAPL( sapSettings, id );
       
   177         if ( !iSAPSettings )
       
   178             {
       
   179             CleanupStack::PopAndDestroy( sapSettings );
       
   180             }
       
   181         }
       
   182     }
       
   183 
       
   184 //----------------------------------------------------------------------------
       
   185 //  CCACommandSettingSapExtCmd::IntValueL
       
   186 // Gets int value from SAP settings
       
   187 // (other items were commented in a header).
       
   188 //----------------------------------------------------------------------------
       
   189 
       
   190 TInt CCACommandSettingSapExtCmd::IntValueL( const TDesC& aKey )
       
   191     {
       
   192     CHAT_DP_TXT( "CCAAppSettingsSAPExt::IntValueL" );
       
   193     TInt returnCode( KErrNotFound );
       
   194     CIMPSSAPSettings* sapSettings = NULL;
       
   195     if ( !iSAPSettings )
       
   196         {
       
   197         sapSettings = StoredSAPLC();
       
   198         }
       
   199     else
       
   200         {
       
   201         sapSettings = iSAPSettings;
       
   202         }
       
   203     if ( sapSettings )
       
   204         {
       
   205 #ifdef _DEBUG
       
   206         TInt id( sapSettings->Uid() );
       
   207         CHAT_DP( D_CHAT_LIT( "found sap (%d), getting value.." ), id );
       
   208 #endif//_DEBUG 
       
   209         sapSettings->GetOpaqueInt( aKey, returnCode );
       
   210         if ( !iSAPSettings )
       
   211             {
       
   212             CleanupStack::PopAndDestroy( sapSettings );
       
   213             }
       
   214         }
       
   215     CHAT_DP( D_CHAT_LIT( "value %d" ), returnCode );
       
   216     return returnCode;
       
   217     }
       
   218 
       
   219 
       
   220 //----------------------------------------------------------------------------
       
   221 //  CCACommandSettingSapExtCmd::SetToneFileNameL
       
   222 // (other items were commented in a header).
       
   223 //----------------------------------------------------------------------------
       
   224 
       
   225 void CCACommandSettingSapExtCmd::SetToneFileNameL( const TDesC& aToneFileName )
       
   226     {
       
   227     CIMPSSAPSettings* sapSettings = NULL;
       
   228     if ( !iSAPSettings )
       
   229         {
       
   230         sapSettings = StoredSAPLC();
       
   231         }
       
   232     else
       
   233         {
       
   234         sapSettings = iSAPSettings;
       
   235         }
       
   236 
       
   237     // populate the list of sapSettings
       
   238     CIMPSSAPSettingsList* sapList = CIMPSSAPSettingsList::NewLC();
       
   239     iSAPSettingsStore->PopulateSAPSettingsListL( *sapList, EIMPSIMAccessGroup );
       
   240 
       
   241     // and find our sapSettings.. because logged in SAP has UID of zero, we must
       
   242     // find the correct UID manually from list
       
   243     TInt index( KErrNotFound );
       
   244     sapList->FindNameL( sapSettings->SAPName(), index );
       
   245 
       
   246     if ( index != KErrNotFound )
       
   247         {
       
   248         // found it, update the correct sap
       
   249         CIMPSSAPSettings* storedSAPSettings = CIMPSSAPSettings::NewLC();
       
   250 
       
   251         TUint32 sapUid = sapList->UidForIndex( index );
       
   252         iSAPSettingsStore->GetSAPL( sapUid, storedSAPSettings );
       
   253         storedSAPSettings->SetOpaqueDesC16( KIMAlertTonePath(), aToneFileName );
       
   254         iSAPSettingsStore->UpdateOldSAPL( storedSAPSettings, sapUid );
       
   255         CleanupStack::PopAndDestroy( storedSAPSettings );
       
   256         }
       
   257     if ( !iSAPSettings )
       
   258         {
       
   259         CleanupStack::PopAndDestroy( 2, sapSettings );
       
   260         }
       
   261     else
       
   262         {
       
   263         CleanupStack::PopAndDestroy( sapList );
       
   264         }
       
   265     }
       
   266 
       
   267 
       
   268 //----------------------------------------------------------------------------
       
   269 //  CCACommandSettingSapExtCmd::GetToneFileNameL
       
   270 // (other items were commented in a header).
       
   271 //----------------------------------------------------------------------------
       
   272 
       
   273 void CCACommandSettingSapExtCmd::GetToneFileNameL( TDes& aToneFileName )
       
   274     {
       
   275     CIMPSSAPSettings* sapSettings = NULL;
       
   276     if ( !iSAPSettings )
       
   277         {
       
   278         sapSettings = StoredSAPLC();
       
   279         }
       
   280     else
       
   281         {
       
   282         sapSettings = iSAPSettings;
       
   283         }
       
   284 
       
   285     // populate the list of sapsettings
       
   286     CIMPSSAPSettingsList* sapList = CIMPSSAPSettingsList::NewLC();
       
   287     iSAPSettingsStore->PopulateSAPSettingsListL( *sapList, EIMPSIMAccessGroup );
       
   288 
       
   289     // and find our sap.. because logged in SAP has UID of zero, we must
       
   290     // find the correct UID manually from list
       
   291     TInt index( KErrNotFound );
       
   292     sapList->FindNameL( sapSettings->SAPName(), index );
       
   293 
       
   294     if ( index != KErrNotFound )
       
   295         {
       
   296         // found it, update the correct sap
       
   297         CIMPSSAPSettings* storedSAPSettings = CIMPSSAPSettings::NewLC();
       
   298         iSAPSettingsStore->GetSAPL( sapList->UidForIndex( index ),
       
   299                                     storedSAPSettings );
       
   300 
       
   301         TPtrC audioPath;
       
   302         storedSAPSettings->GetOpaqueDesC16( KIMAlertTonePath(),
       
   303                                             audioPath );
       
   304         
       
   305         if ( BaflUtils::FileExists( CEikonEnv::Static()->FsSession(), audioPath ) )
       
   306         	{
       
   307         aToneFileName.Copy( audioPath );
       
   308         	}
       
   309         else
       
   310         	{
       
   311         	aToneFileName.Copy( KNullDesC() );
       
   312         	}
       
   313         
       
   314         CleanupStack::PopAndDestroy( storedSAPSettings );
       
   315         }
       
   316     else
       
   317         {
       
   318         aToneFileName.Copy( KNullDesC() );
       
   319         }
       
   320 
       
   321     if ( !iSAPSettings )
       
   322         {
       
   323         CleanupStack::PopAndDestroy( 2, sapSettings );
       
   324         }
       
   325     else
       
   326         {
       
   327         CleanupStack::PopAndDestroy( sapList );
       
   328         }
       
   329     }
       
   330 
       
   331 
       
   332 //----------------------------------------------------------------------------
       
   333 // CCACommandSettingSapExtCmd::StoredSAPLC
       
   334 // Gets editable stored SAP
       
   335 // (other items were commented in a header).
       
   336 //----------------------------------------------------------------------------
       
   337 
       
   338 CIMPSSAPSettings* CCACommandSettingSapExtCmd::StoredSAPLC()
       
   339     {
       
   340     CIMPSSAPSettings* sapSettings = CIMPSSAPSettings::NewLC();
       
   341 
       
   342     TBool isLoggedIn( EFalse );
       
   343     if ( iConnectionUI )
       
   344         {
       
   345         TInt err;
       
   346         TRAP( err, isLoggedIn = iConnectionUI->LoggedInL( EIMPSConnClientIM ) );
       
   347         }
       
   348 
       
   349     if ( isLoggedIn )
       
   350         {
       
   351         CPEngNWSessionSlotID2* sessionSlotId =
       
   352             iConnectionUI->GetActiveNWSessionSlotIDL( EIMPSConnClientIM );
       
   353         CleanupStack::PushL( sessionSlotId );
       
   354         iConnectionUI->GetLoggedInSapL( *sessionSlotId, *sapSettings );
       
   355 
       
   356         // populate the list of sapsettings
       
   357         CIMPSSAPSettingsList* sapList = CIMPSSAPSettingsList::NewLC();
       
   358         iSAPSettingsStore->PopulateSAPSettingsListL( *sapList,
       
   359                                                      EIMPSIMAccessGroup );
       
   360 
       
   361         // and find our sap.. because logged in SAP has UID of zero, we must
       
   362         // find the correct UID manually from list
       
   363         TInt index( KErrNotFound );
       
   364         TPtrC name( sapSettings->SAPName() );
       
   365         CHAT_DP( D_CHAT_LIT( "logged to to %S, trying to find sapSettings" ),
       
   366                  &name );
       
   367         sapList->FindNameL( name, index );
       
   368 
       
   369         if ( index != KErrNotFound )
       
   370             {
       
   371             CHAT_DP( D_CHAT_LIT( "found it in index %d" ), index );
       
   372             // found it, update the correct sap
       
   373             CIMPSSAPSettings* storedSAPSettings = CIMPSSAPSettings::NewLC();
       
   374             iSAPSettingsStore->GetSAPL( sapList->UidForIndex( index ),
       
   375                                         storedSAPSettings );
       
   376             CleanupStack::Pop( storedSAPSettings );
       
   377             CleanupStack::PopAndDestroy( 3, sapSettings );
       
   378             // sapList, sessionslot, sapSettings
       
   379             CleanupStack::PushL( storedSAPSettings );
       
   380             sapSettings = storedSAPSettings;
       
   381             }
       
   382         else
       
   383             {
       
   384             CHAT_DP( D_CHAT_LIT( "not found" ) );
       
   385             CleanupStack::PopAndDestroy( 3, sapSettings );
       
   386             // sapList, sessionSlotId, sapSettings
       
   387             return NULL;
       
   388             }
       
   389         }
       
   390     else if ( iSAPSettingsStore )
       
   391         {
       
   392         iSAPSettingsStore->GetDefaultL( sapSettings, EIMPSIMAccessGroup );
       
   393         }
       
   394 
       
   395     return sapSettings;
       
   396     }
       
   397 
       
   398 
       
   399 //----------------------------------------------------------------------------
       
   400 // CCACommandSettingSapExtCmd::CurrentSAPLC
       
   401 // (other items were commented in a header).
       
   402 //----------------------------------------------------------------------------
       
   403 
       
   404 CIMPSSAPSettings* CCACommandSettingSapExtCmd::CurrentSAPLC()
       
   405     {
       
   406     CIMPSSAPSettings* sapSettings = CIMPSSAPSettings::NewLC();
       
   407 
       
   408     TBool isLoggedIn( EFalse );
       
   409     TInt err;
       
   410     TRAP( err, isLoggedIn = iConnectionUI->LoggedInL( EIMPSConnClientIM ) );
       
   411 
       
   412     if ( isLoggedIn )
       
   413         {
       
   414         CPEngNWSessionSlotID2* sessionSlotId =
       
   415             iConnectionUI->GetActiveNWSessionSlotIDL( EIMPSConnClientIM );
       
   416         CleanupStack::PushL( sessionSlotId );
       
   417         iConnectionUI->GetLoggedInSapL( *sessionSlotId, *sapSettings );
       
   418         CleanupStack::PopAndDestroy( sessionSlotId );
       
   419         }
       
   420     else
       
   421         {
       
   422         iSAPSettingsStore->GetDefaultL( sapSettings, EIMPSIMAccessGroup );
       
   423         }
       
   424     return sapSettings;
       
   425     }
       
   426