musichomescreen/src/mpxresource.cpp
changeset 0 ff3acec5bc43
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     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:  This class provide API to read resource from resource file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <barsread.h>
       
    21 #include <mpxuser.h>
       
    22 #include <mpxlog.h>
       
    23 #include "mpxresource.h"
       
    24 
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ==============================
       
    27 
       
    28 // ----------------------------------------------------------------------------
       
    29 // Factory function
       
    30 // ----------------------------------------------------------------------------
       
    31 //
       
    32 CMPXResource* CMPXResource::NewL(const TDesC& aResourceFile)
       
    33     {
       
    34     CMPXResource* resObj = NewLC(aResourceFile);
       
    35     CleanupStack::Pop(resObj);
       
    36     return resObj;
       
    37     }
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // Factory function
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 CMPXResource* CMPXResource::NewLC(const TDesC& aResourceFile)
       
    44     {
       
    45     MPX_DEBUG1("CMPXResource::NewLC");
       
    46     CMPXResource* self = new (ELeave) CMPXResource();
       
    47     CleanupStack::PushL (self);
       
    48     self->ConstructL(aResourceFile);
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // Decrements the reference count, and delete the object if it is 0
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 void CMPXResource::Release()
       
    57     {
       
    58     delete this;
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // C++ default constructor can NOT contain any code, that might leave
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 CMPXResource::CMPXResource()
       
    66     {
       
    67     }
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 // Contruct the object
       
    71 // ----------------------------------------------------------------------------
       
    72 //
       
    73 void CMPXResource::ConstructL(const TDesC& aResourceFile)
       
    74     {
       
    75     // In order to support installation of individual plugin.
       
    76     // aResourceFile must be a final name.
       
    77     // All parse should be done in the plugin side.
       
    78     MPX_DEBUG1("CMPXResource::ConstructL");
       
    79     User::LeaveIfError(iFs.Connect());
       
    80     MPX_DEBUG2("Open resource file %S", &aResourceFile);
       
    81     iResourceFile.OpenL(iFs, aResourceFile);
       
    82     iResourceFile.ConfirmSignatureL(0);
       
    83     MPX_DEBUG1("CMPXResource::ConstructL End");
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------------------------
       
    87 // Destructor
       
    88 // ----------------------------------------------------------------------------
       
    89 //
       
    90 CMPXResource::~CMPXResource()
       
    91     {
       
    92     iResourceFile.Close();
       
    93     iFs.Close();
       
    94     }
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // Read array of descriptors
       
    98 // ----------------------------------------------------------------------------
       
    99 //
       
   100 CDesCArrayFlat* CMPXResource::ReadDesCArrayL(TInt aResourceId)
       
   101     {
       
   102     CDesCArrayFlat* descArray = ReadDesCArrayLC(aResourceId);
       
   103     CleanupStack::Pop(descArray);
       
   104     return descArray;
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // Read array of descriptors, leave on cleanup stack
       
   109 // ----------------------------------------------------------------------------
       
   110 //
       
   111 CDesCArrayFlat* CMPXResource::ReadDesCArrayLC(TInt aResourceId)
       
   112     {
       
   113     //MPX_DEBUG1("CMPXResource::ReadDesCArrayLC");
       
   114     TResourceReader resReader;
       
   115     HBufC8* readBuffer = iResourceFile.AllocReadLC(aResourceId);
       
   116     resReader.SetBuffer(readBuffer);
       
   117     CDesCArrayFlat* descArray = resReader.ReadDesCArrayL();
       
   118     CleanupStack::PopAndDestroy(readBuffer);
       
   119     //MPX_DEBUG1("CMPXResource::ReadDesCArrayLC End");
       
   120     CleanupStack::PushL(descArray);
       
   121     return descArray;
       
   122     }
       
   123 
       
   124 // ----------------------------------------------------------------------------
       
   125 // Get a heap descriptor from the resource file
       
   126 // ----------------------------------------------------------------------------
       
   127 //
       
   128 HBufC* CMPXResource::ReadHBufCL(TInt aResourceId)
       
   129     {
       
   130     //MPX_DEBUG1("CMPXResource::ReadHBufCL");
       
   131     HBufC8* readBuffer = iResourceFile.AllocReadLC(aResourceId);
       
   132     TResourceReader resReader;
       
   133     resReader.SetBuffer(readBuffer);
       
   134     //resource type has to be LBUF
       
   135     HBufC* hbuf = resReader.ReadHBufCL();
       
   136     CleanupStack::PopAndDestroy(readBuffer);
       
   137     return hbuf;
       
   138     }
       
   139 
       
   140 // ----------------------------------------------------------------------------
       
   141 // Read array of menu items
       
   142 // ----------------------------------------------------------------------------
       
   143 //
       
   144 CDesCArrayFlat* CMPXResource::ReadMenuArrayL(TInt aResourceId, RArray<TInt>& aIdArray)
       
   145     {
       
   146     CDesCArrayFlat* menuArray = ReadMenuArrayLC(aResourceId, aIdArray);
       
   147     CleanupStack::Pop(menuArray);
       
   148     return menuArray;
       
   149     }
       
   150 
       
   151 // ----------------------------------------------------------------------------
       
   152 // Read array of menu items, leave on cleanup stack
       
   153 // ----------------------------------------------------------------------------
       
   154 //
       
   155 CDesCArrayFlat* CMPXResource::ReadMenuArrayLC(TInt aResourceId, RArray<TInt>& aIdArray)
       
   156     {
       
   157     //MPX_DEBUG1("CMPXResource::ReadMenuArrayLC");
       
   158     TResourceReader resReader;
       
   159     HBufC8* readBuffer = iResourceFile.AllocReadLC(aResourceId);
       
   160     resReader.SetBuffer(readBuffer);
       
   161     TInt count(resReader.ReadInt16());
       
   162     CDesCArrayFlat* descArray = new (ELeave) CDesCArrayFlat(count); ;
       
   163     for (TInt k = 0; k < count; k++)
       
   164               {
       
   165               aIdArray.AppendL (resReader.ReadInt32());
       
   166               HBufC* hbuf = resReader.ReadHBufCL();
       
   167               CleanupStack::PushL(hbuf);
       
   168               descArray->AppendL (*hbuf);
       
   169               CleanupStack::PopAndDestroy(hbuf);
       
   170         }
       
   171     CleanupStack::PopAndDestroy(readBuffer);
       
   172     //MPX_DEBUG1("CMPXResource::ReadDesCArrayLC End");
       
   173     CleanupStack::PushL(descArray);
       
   174     return descArray;
       
   175     }
       
   176 
       
   177 // End of File