mmshplugins/mmshsettingsuiplugin/src/mussettingsmodel.cpp
changeset 15 ccd8e69b5392
parent 2 b31261fd4e04
child 20 e8be2c2e049d
child 22 496ad160a278
equal deleted inserted replaced
2:b31261fd4e04 15:ccd8e69b5392
     1 /*
       
     2 * Copyright (c) 2006-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:  Document model class for MUSSettingsPlugin.
       
    15 *  Version     : %version: 17 % << Don't touch! Updated by Synergy at check-out.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include    "mussettingsmodel.h"
       
    21 #include    "muslogger.h"
       
    22 #include    "mussipprofilemodel.h"
       
    23 #include    "mussettings.h"
       
    24 #include    "mmussipprofilehandler.h"
       
    25 
       
    26 #include    <escapeutils.h>
       
    27 #include    <centralrepository.h>
       
    28 #include    <CAknMemorySelectionDialogMultiDrive.h>
       
    29 #include    <AknCommonDialogsDynMem.h>
       
    30 #include    <mussettingsuirsc.rsg> // GUI Resource
       
    31 
       
    32 
       
    33 
       
    34 const TInt CMusSettingsModel::KVsSipProfileDefault      = 0;
       
    35 const TInt CMusSettingsModel::KVsSipProfileSelect       = 1;
       
    36 const TInt CMusSettingsModel::KVsSipProfileSelectNone   = 2;
       
    37 const TInt KSIPGranularity = 5;
       
    38 
       
    39 
       
    40 // ======== MEMBER FUNCTIONS ========
       
    41 
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CMusSettingsModel* CMusSettingsModel::NewL( MMusSIPProfileHandler& aHandler )
       
    48     {
       
    49     MUS_LOG( "[MUSSET] -> CMusSettingsModel::NewL()" )
       
    50     CMusSettingsModel* self = new( ELeave ) CMusSettingsModel( aHandler );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53 
       
    54     CleanupStack::Pop( self );
       
    55     MUS_LOG( "[MUSSET] <- CMusSettingsModel::NewL()" )
       
    56     return self;
       
    57     }
       
    58 
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CMusSettingsModel::CMusSettingsModel( MMusSIPProfileHandler& aHandler )
       
    65     : iHandler( aHandler )
       
    66     {
       
    67     MUS_LOG( "[MUSSET] <- CMusSettingsModel::CMusSettingsModel()" )
       
    68     }
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CMusSettingsModel::ConstructL()
       
    76     {
       
    77     MUS_LOG( "[MUSSET] -> CMusSettingsModel::ConstructL()" )
       
    78     InitializeProfileEnablerL();
       
    79     static_cast<CMusSIPProfileModel*> (&iHandler)->SetCMusSettingsModel(this);
       
    80     MUS_LOG( "[MUSSET] <- CMusSettingsModel::ConstructL()" )
       
    81     }
       
    82 
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CMusSettingsModel::~CMusSettingsModel()
       
    89     {
       
    90     MUS_LOG( "[MUSSET] -> CMusSettingsModel::~CMusSettingsModel()" )
       
    91     MUS_LOG( "[MUSSET] <- CMusSettingsModel::~CMusSettingsModel()" )
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // Returns recorded video saving mode.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TInt CMusSettingsModel::VSSettingsRecordedVideoSavingL()
       
    99     {
       
   100     MUS_LOG( "[MUSSET] -> CMusSettingsModel::VSSettingsRecordedVideoSavingL()" )
       
   101     TInt vsVideoLocationMode = MultimediaSharingSettings::VideoLocationSettingL();
       
   102     MUS_LOG1(
       
   103     "[MUSSET] <- CMusSettingsContainer::VSSettingsRecordedVideoSavingL()( %d )",
       
   104         vsVideoLocationMode )
       
   105     return vsVideoLocationMode;
       
   106     }
       
   107 
       
   108 // ----------------------------------------------------------------------------
       
   109 // Change Activation.
       
   110 // ----------------------------------------------------------------------------
       
   111 //
       
   112 void CMusSettingsModel::SetActivationItem( TBool aActive )
       
   113     {
       
   114     MUS_LOG( "[MUSSET] -> CMusSettingsContainer::SetActivationItem()" )
       
   115     MUS_LOG1( "            Profile disabled? ( %d )", aActive )
       
   116     iProfileDisabled = aActive;
       
   117     MUS_LOG( "[MUSSET] <- CMusSettingsContainer::SetActivationItem()" )
       
   118     }
       
   119 
       
   120 // ----------------------------------------------------------------------------
       
   121 // Get Activation item.
       
   122 // ----------------------------------------------------------------------------
       
   123 //
       
   124 TBool CMusSettingsModel::ActivationItem()
       
   125     {
       
   126     MUS_LOG( "[MUSSET] -> CMusSettingsContainer::SetActivationItem()" )
       
   127     MUS_LOG( "[MUSSET] <- CMusSettingsContainer::SetActivationItem()" )
       
   128     return iProfileDisabled;
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // Returns the list of profile names
       
   133 // -----------------------------------------------------------------------------
       
   134 CDesCArray* CMusSettingsModel::ListOfProfileNamesL()
       
   135     {
       
   136     MUS_LOG( "[MUSSET] -> CMusSettingsModel::ListOfProfileNamesL()" )
       
   137     RPointerArray<CSIPProfile>& list = iHandler.ProfileArrayL();
       
   138 
       
   139     CDesCArray* array = new ( ELeave ) CDesCArrayFlat( KSIPGranularity );
       
   140     CleanupStack::PushL( array );
       
   141 
       
   142     for ( TInt i = 0; i < list.Count(); i++ )
       
   143         {
       
   144         const TDesC8* providerName = 0;
       
   145         User::LeaveIfError(
       
   146             list[i]->GetParameter( KSIPProviderName, providerName ) );
       
   147 
       
   148         HBufC8* decodedProvider =
       
   149             EscapeUtils::EscapeDecodeL( *providerName );
       
   150         CleanupStack::PushL( decodedProvider );
       
   151 
       
   152         HBufC* providerName16 =
       
   153             EscapeUtils::ConvertToUnicodeFromUtf8L( decodedProvider->Des() );
       
   154         CleanupStack::PushL( providerName16 );
       
   155 
       
   156         array->AppendL( providerName16->Des() );
       
   157 
       
   158         CleanupStack::PopAndDestroy( providerName16 );
       
   159         CleanupStack::PopAndDestroy( decodedProvider );
       
   160         }
       
   161 
       
   162     CleanupStack::Pop( array );
       
   163     MUS_LOG( "[MUSSET] <- CMusSettingsModel::ListOfProfileNamesL()" )
       
   164     return array;
       
   165     }
       
   166 
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // Returns the SIP profile name. Returns NULL buffer if no profile is found.
       
   170 // -----------------------------------------------------------------------------
       
   171 HBufC* CMusSettingsModel::ProfileNameL( TInt aId )
       
   172     {
       
   173     MUS_LOG1(
       
   174     "[MUSSET] -> CMusSettingsContainer::ProfileNameL()( %d )",
       
   175         aId )
       
   176     const TDesC8* providerName = 0;
       
   177     TInt index = ProfileIndexByIdL( aId );
       
   178     HBufC* buf = NULL;
       
   179 
       
   180     if ( index >= 0 )
       
   181         {
       
   182         if ( KErrNone == iHandler.ProfileArrayL()[index]->
       
   183                 GetParameter( KSIPProviderName, providerName ) )
       
   184             {
       
   185             HBufC8* decodedProvider =
       
   186                 EscapeUtils::EscapeDecodeL( *providerName );
       
   187             CleanupStack::PushL( decodedProvider );
       
   188             buf = EscapeUtils::ConvertToUnicodeFromUtf8L( *providerName );
       
   189             CleanupStack::PopAndDestroy( decodedProvider );
       
   190             }
       
   191         }
       
   192 
       
   193     if ( buf )
       
   194         {
       
   195         MUS_LOG_TDESC( "[MUSSET] <- CMusSettingsModel::ProfileNameL(): Profile name: ", buf->Des() )
       
   196         }
       
   197     else
       
   198         {
       
   199         MUS_LOG( "[MUSSET] <- CMusSettingsModel::ProfileNameL(): No profile found! " )
       
   200         }
       
   201     return buf;
       
   202     }
       
   203 
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // Returns default SIP profile index.
       
   207 // -----------------------------------------------------------------------------
       
   208 TInt CMusSettingsModel::DefaultProfileIndex()
       
   209     {
       
   210     MUS_LOG( "[MUSSET] <- CMusSettingsModel::DefaultProfileIndex()" )
       
   211     return iHandler.DefaultProfileIndex();
       
   212     }
       
   213 
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // Returns id of default SIP profile.
       
   217 // -----------------------------------------------------------------------------
       
   218 TUint32 CMusSettingsModel::DefaultProfileId()
       
   219     {
       
   220     MUS_LOG( "[MUSSET] <- CMusSettingsModel::DefaultProfileId()" )
       
   221     return iHandler.DefaultProfileId();
       
   222     }
       
   223 
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // Returns SIP profile index based on the Id of SIP profile.
       
   227 // -----------------------------------------------------------------------------
       
   228 TInt CMusSettingsModel::ProfileIndexByIdL( TUint32 aId )
       
   229     {
       
   230     MUS_LOG( "[MUSSET] <- CMusSettingsModel::ProfileIndexByIdL()" )
       
   231     return iHandler.ProfileIndexByIdL( aId );
       
   232     }
       
   233 
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // Returns SIP profile Id based on the index of SIP profile.
       
   237 // -----------------------------------------------------------------------------
       
   238 TUint32 CMusSettingsModel::ProfileIdByIndex( TUint aIndex )
       
   239     {
       
   240     MUS_LOG( "[MUSSET] <- CMusSettingsModel::ProfileIdByIndex()" )
       
   241     return iHandler.ProfileIdByIndex( aIndex );
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // Initialize SIP profile enabler data.
       
   246 // -----------------------------------------------------------------------------
       
   247 void CMusSettingsModel::InitializeProfileEnablerL() 
       
   248     {
       
   249     MUS_LOG( "[MUSSET] -> CMusSettingsModel::InitializeProfileEnabler()" )
       
   250     if ( MultimediaSharingSettings::OperatorVariantSettingL() ==
       
   251                MusSettingsKeys::EOperatorSpecific )
       
   252        {
       
   253        TBool enabled(EFalse);
       
   254        
       
   255        CMusSIPProfileModel& handler = 
       
   256            static_cast<CMusSIPProfileModel&>( iHandler );
       
   257        TRAPD( error, enabled = handler.ProfileEnabledL());
       
   258        if ( error != KErrNone )
       
   259            {
       
   260            MUS_LOG( "Error returned" )
       
   261            // Problems with re-reading profiles; use existing array
       
   262            SetActivationItem( EFalse );
       
   263            }
       
   264        else
       
   265            {
       
   266            MUS_LOG1("SIP registration service( %d )",
       
   267            enabled )
       
   268            if( enabled )
       
   269                {
       
   270                SetActivationItem( enabled );
       
   271                }
       
   272            else
       
   273                {
       
   274                SetActivationItem( enabled);
       
   275                }
       
   276            }
       
   277        }
       
   278     MUS_LOG( "[MUSSET] <- CMusSettingsModel::InitializeProfileEnabler()" )
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // Returns memory selction dialog pointer.
       
   283 // -----------------------------------------------------------------------------
       
   284 CAknMemorySelectionDialogMultiDrive* CMusSettingsModel::MemorySelectionDialogLC()
       
   285     {
       
   286     MUS_LOG( "[MUSSET] -> CMusSettingsModel::MemorySelectionDialogLC()" )
       
   287     TInt supportedMemTypes( AknCommonDialogsDynMem::EMemoryTypePhone|
       
   288                         AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage|
       
   289                         AknCommonDialogsDynMem::EMemoryTypeMMCExternal|
       
   290                         AknCommonDialogsDynMem::EMemoryTypeRemote );    
       
   291     CAknMemorySelectionDialogMultiDrive* dlg = 
       
   292                                CAknMemorySelectionDialogMultiDrive::NewL(
       
   293                                     ECFDDialogTypeNormal,
       
   294                                     R_VS_RECORDED_VIDEO_SAVING_SETTING_PAGE,
       
   295                                     ETrue,
       
   296                                     supportedMemTypes );
       
   297     CleanupStack::PushL( dlg );
       
   298     MUS_LOG( "[MUSSET] <- CMusSettingsModel::MemorySelectionDialogLC()" )
       
   299     return dlg;
       
   300     }
       
   301