psln/Src/PslnSoundActivator.cpp
branchRCL_3
changeset 56 d48ab3b357f1
equal deleted inserted replaced
55:aecbbf00d063 56:d48ab3b357f1
       
     1 /*
       
     2 * Copyright (c) 2004-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:  Activates sound content, if part of the skin.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <AknsUtils.h>
       
    21 #include <AknsSrvClient.h>
       
    22 #include <pathinfo.h>
       
    23 #include <driveinfo.h>
       
    24 #include <eikenv.h>
       
    25 
       
    26 // Psln specific.
       
    27 #include "pslnprofilesettingsloader.h"
       
    28 #include "PslnSoundActivator.h"
       
    29 #include "PslnConst.h"
       
    30 #include "PslnDebug.h"
       
    31 
       
    32 
       
    33 // CONSTANTS
       
    34 // Path and filename of wrapper dll.
       
    35 _LIT( KPslnProfilesSettingsLoaderName,
       
    36     "\\system\\libs\\PslnProfileSettingsLoader.dll");
       
    37 
       
    38 // TYPE DEFINITIONS
       
    39 // Profiles tone setter.
       
    40 typedef TAny* (*NewProfilesSetterL)();
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // C++ default constructor can NOT contain any code, that might leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CPslnSoundActivator::CPslnSoundActivator()
       
    49     {
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // Two-phased constructor.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CPslnSoundActivator* CPslnSoundActivator::NewLC()
       
    57     {
       
    58     CPslnSoundActivator* self = new( ELeave ) CPslnSoundActivator;
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // Symbian 2nd phase constructor can leave.
       
    66 // ---------------------------------------------------------------------------
       
    67 void CPslnSoundActivator::ConstructL()
       
    68     {
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // Destructor.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CPslnSoundActivator::~CPslnSoundActivator()
       
    76     {
       
    77     delete iProfilesSetter;
       
    78     if( iProfilesDllLoaded )
       
    79         {
       
    80         iProfilesDll.Close();
       
    81         }
       
    82     iSoundArray.Reset();
       
    83     iSoundArray.Close();
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CPslnSoundActivator::CollectSoundsL
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CPslnSoundActivator::CollectSoundsL( const TDesC& aSkinPath, TInt& aCount )
       
    91     {
       
    92     PSLN_TRACE_DEBUG("CPslnSoundActivator::CollectSoundsL BEGIN");
       
    93     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
    94     if ( !skin )
       
    95         {
       
    96         return;
       
    97         }
       
    98     iSoundArray.Reset();
       
    99 
       
   100     TInt i = KErrNotFound;
       
   101     while( KPslnSoundItems[++i] != KAknsIIDNone )
       
   102         {
       
   103         CAknsStringItemData* data =
       
   104             static_cast<CAknsStringItemData*>(
       
   105             skin->CreateUncachedItemDataL(
       
   106                 KPslnSoundItems[i],
       
   107                 EAknsITString ) );
       
   108         if ( data )
       
   109             {
       
   110             CleanupStack::PushL( data );
       
   111 
       
   112             PSLN_TRACE_DEBUG("CPslnSoundActivator::CollectSoundsL skin item found");
       
   113             HBufC* fullName = HBufC::NewLC( KMaxFileName );
       
   114             TPtr fullNamePtr = fullName->Des();
       
   115 
       
   116             if ( aSkinPath.Length() > 0 )
       
   117                 {
       
   118                 FindSoundFile( fullNamePtr, data->String(), aSkinPath );
       
   119                 }
       
   120             else
       
   121                 {
       
   122                 PSLN_TRACE_DEBUG("CPslnSoundActivator::CollectSoundsL empty path" );
       
   123                 // @todo - start going through all the drives available.
       
   124                 }
       
   125 
       
   126             if( fullNamePtr.Length() > 0 )
       
   127                 {
       
   128                 PSLN_TRACE_DEBUG("CPslnSoundActivator::CollectSoundsL file found");
       
   129                 TPslnSoundActivatorEntry entry;
       
   130                 entry.iFullName = fullNamePtr;
       
   131                 entry.iID = KPslnSoundItems[i];
       
   132                 iSoundArray.AppendL( entry );
       
   133                 }
       
   134 
       
   135             CleanupStack::PopAndDestroy( 2, data ); // data, fullName
       
   136             }
       
   137         }
       
   138     aCount = iSoundArray.Count();
       
   139     PSLN_TRACE_DEBUG("CPslnSoundActivator::CollectSoundsL END");
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CPslnSoundActivator::ActivateToProfilesL
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CPslnSoundActivator::ActivateToProfilesL()
       
   147     {
       
   148     PSLN_TRACE_DEBUG("CPslnSoundActivator::ActivateToProfilesL BEGIN");
       
   149 
       
   150     // Profiles tone setter dll loading.
       
   151     if( !iProfilesDllLoaded )
       
   152         {
       
   153         PSLN_TRACE_DEBUG("CPslnSoundActivator::ActivateToProfilesL about load");
       
   154         if( iProfilesDll.Load( KPslnProfilesSettingsLoaderName ) == KErrNone )
       
   155             {
       
   156             PSLN_TRACE_DEBUG("CPslnSoundActivator::ActivateToProfilesL loaded");
       
   157             iProfilesDllLoaded = ETrue;
       
   158             // Request the entry function
       
   159             NewProfilesSetterL profilesSetter =
       
   160                 (NewProfilesSetterL) iProfilesDll.Lookup( KPslnDllEntryPoint );
       
   161             if( profilesSetter )
       
   162                 {
       
   163                 PSLN_TRACE_DEBUG("CPslnSoundActivator::ActivateToProfilesL create");
       
   164                 // Create the class
       
   165                 iProfilesSetter =
       
   166                     (CPslnProfileSettingsLoader*) (*profilesSetter)();
       
   167                 }
       
   168             }
       
   169         }
       
   170     // The wrapper failed to load.
       
   171     if ( !iProfilesSetter )
       
   172         {
       
   173         User::Leave( KErrNotFound );
       
   174         }
       
   175 
       
   176     MoveSoundFilesL();
       
   177 
       
   178     // Activate all tones to all profiles.
       
   179     for( TInt i = 0; i < iSoundArray.Count(); i++ )
       
   180         {
       
   181         TPslnSoundActivatorEntry entry = iSoundArray[i];
       
   182         PSLN_TRACE_DEBUG1("CPslnSoundActivator::ActivateToProfilesL tone %d", i);
       
   183         PSLN_TRACE_DEBUG1("CPslnSoundActivator::ActivateToProfilesL minor ID %d", entry.iID.iMinor);
       
   184         PSLN_TRACE_DEBUG1("CPslnSoundActivator::ActivateToProfilesL name lenght %d ", iSoundArray[i].iFullName.Length() );
       
   185         iProfilesSetter->SetToneForProfilesL(
       
   186             entry.iID.iMinor,
       
   187             entry.iFullName );
       
   188         }
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CPslnSoundActivator::FindSoundFile
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CPslnSoundActivator::FindSoundFile(
       
   196     TDes& aFullName, const TDesC& aSoundFile, const TDesC& aSkinPath )
       
   197     {
       
   198     aFullName.Copy( aSkinPath );
       
   199     aFullName.Append( aSoundFile );
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CPslnSoundActivator::MoveSoundFilesL
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CPslnSoundActivator::MoveSoundFilesL()
       
   207     {
       
   208     RAknsSrvSession skinsrv;
       
   209     User::LeaveIfError( skinsrv.Connect() );
       
   210     CleanupClosePushL( skinsrv );
       
   211 
       
   212     RFs& fs = CEikonEnv::Static()->FsSession();
       
   213 
       
   214     for( TInt i = 0; i < iSoundArray.Count(); i++ )
       
   215         {
       
   216         TPslnSoundActivatorEntry entry = iSoundArray[i];
       
   217 
       
   218         HBufC* targetPath = NULL;
       
   219         TFileName filename;
       
   220        
       
   221         // Sort out path to which store the sound file.
       
   222         TInt driveId;
       
   223         User::LeaveIfError( 
       
   224             RFs::CharToDrive( entry.iFullName[0], driveId ) );
       
   225 
       
   226         TUint driveStatus;
       
   227         User::LeaveIfError( 
       
   228             DriveInfo::GetDriveStatus( fs, driveId, driveStatus ) );
       
   229 
       
   230         if ( driveStatus & DriveInfo::EDriveReadOnly )
       
   231             {
       
   232             // If ROM, then let's store to phone memory.
       
   233             User::LeaveIfError(
       
   234                 DriveInfo::GetDefaultDrive( 
       
   235                     DriveInfo::EDefaultPhoneMemory, 
       
   236                     driveId ) );
       
   237             }
       
   238 
       
   239         User::LeaveIfError( 
       
   240             PathInfo::GetRootPath( filename, driveId ) );       
       
   241         filename.Append( PathInfo::SoundsPath() );
       
   242         targetPath = filename.AllocLC();
       
   243 
       
   244         TParsePtrC parse( entry.iFullName );
       
   245         TFileName* targetFile = new (ELeave) TFileName;
       
   246         CleanupStack::PushL( targetFile );
       
   247         targetFile->Copy( *targetPath );
       
   248         targetFile->Append( parse.NameAndExt() );
       
   249 
       
   250         skinsrv.CopySoundFile( entry.iFullName, *targetFile );
       
   251         if ( iProfilesSetter )
       
   252             {
       
   253             PSLN_TRACE_DEBUG("CPslnSoundActivator::MoveSoundFilesL indicate to mgx");
       
   254             PSLN_TRACE_DEBUG1("CPslnSoundActivator: Move to \"%S\" ", targetFile );
       
   255 
       
   256             iProfilesSetter->IndicateFileUpdationL( *targetFile );
       
   257             }
       
   258         iSoundArray[i].iFullName = *targetFile;
       
   259         PSLN_TRACE_DEBUG1("CPslnSoundActivator: Move2 lenght %d ", iSoundArray[i].iFullName.Length() );
       
   260         CleanupStack::PopAndDestroy( 2, targetPath );
       
   261         }
       
   262     CleanupStack::PopAndDestroy(); //skinsrv
       
   263     }
       
   264 
       
   265 //  End of File