bluetoothappprofiles/avrcp/playerinformation/src/settingsresource.cpp
changeset 70 f5508c13dfe0
parent 67 16e4b9007960
child 71 083fd884d7dd
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @publishedAll
       
    19  @released
       
    20 */
       
    21 
       
    22 #include <playerinformationtargetobserver.h>
       
    23 #include <barsread2.h>
       
    24 #include <barsc2.h>
       
    25 
       
    26 
       
    27 // AVRCP resource files must only contain one top level resource.
       
    28 static const int KAVRCPResourceId = 1;
       
    29 static const TInt KAVRCPFormatVersion = 1;
       
    30 
       
    31 
       
    32 EXPORT_C void PlayerApplicationSettingsResourceInit::DefineAttributesL(MPlayerApplicationSettingsObserver& aSettings,
       
    33 																CResourceFile& aResourceFile)
       
    34 	{
       
    35 	// Read the settings from the resource file
       
    36 	RResourceReader reader;
       
    37 	reader.OpenLC(&aResourceFile, KAVRCPResourceId);
       
    38 	
       
    39 	// Check the version of this resource file
       
    40 	TUint16 formatVersion = reader.ReadUint16L();
       
    41 	if (formatVersion != KAVRCPFormatVersion)
       
    42 		{
       
    43 		reader.Close();
       
    44 		User::Leave(KErrCorrupt);
       
    45 		}
       
    46 	
       
    47 	// Find out how many settings this resource file contains
       
    48 	TInt settingsCount = reader.ReadUint16L();
       
    49 	if (settingsCount < 0)
       
    50 		{
       
    51 		reader.Close();
       
    52 		User::Leave(KErrCorrupt);
       
    53 		}
       
    54 
       
    55 	// read the settings from aResource
       
    56 	RArray<TUint> values;
       
    57 	RArray<TPtrC8> valueTexts;
       
    58 	CleanupClosePushL(values);
       
    59  	CleanupClosePushL(valueTexts);
       
    60 
       
    61 	// Read each AVRCP attribute setting in turn
       
    62 	for (int i = 0; i < settingsCount; i++)
       
    63 		{
       
    64 		values.Reset();
       
    65 		valueTexts.Reset();
       
    66 		
       
    67 		// Read attribute, description text, initial value and defined values
       
    68 		TUint attributeID(reader.ReadUint8L());
       
    69 		TUint initialValue(reader.ReadUint8L());
       
    70 		TPtrC8 attributeText(reader.ReadTPtrC8L());
       
    71 		TInt valuesCount(reader.ReadUint16L());
       
    72 
       
    73 		for (int j = 0; j < valuesCount; j++)
       
    74 			{
       
    75 			TUint thisValue = reader.ReadUint8L();
       
    76 			TPtrC8 thisDescription = reader.ReadTPtrC8L();
       
    77 			
       
    78 			values.AppendL(thisValue);
       
    79 			valueTexts.AppendL(thisDescription);
       
    80 			}
       
    81 		
       
    82 		// Now define this attribute, then continue to next attribute
       
    83 		aSettings.DefineAttributeL(attributeID, attributeText, values, valueTexts, initialValue);
       
    84 		}
       
    85 	// cleaning up values and valueTexts
       
    86 	 CleanupStack::PopAndDestroy(3); // values, valueTexts, reader
       
    87 	}
       
    88