1 // Copyright (c) 2008-2010 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 // This file contains the CPlayerApplicationSettings class. |
|
15 // This is used to contain the Player application Setting Attributes |
|
16 // defined by the Bluetooth AVRCP 1.3 specification |
|
17 // |
|
18 // |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent |
|
23 @released |
|
24 */ |
|
25 |
|
26 #include <playerinformationtarget.h> |
|
27 |
|
28 #include "playerapplicationsetting.h" |
|
29 #include "playerinformation.h" |
|
30 |
|
31 CPlayerApplicationSettings* CPlayerApplicationSettings::NewL( TUint aAttributeID, |
|
32 TDesC8& aAttributeText, |
|
33 const RArray<TUint>& aValues, |
|
34 RArray<TPtrC8>& aValueTexts, |
|
35 TUint aInitialValue ) |
|
36 { |
|
37 CPlayerApplicationSettings* self = new(ELeave) CPlayerApplicationSettings(); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL( aAttributeID, aAttributeText, aValues, aValueTexts, aInitialValue); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 |
|
45 CPlayerApplicationSettings::~CPlayerApplicationSettings() |
|
46 { |
|
47 delete iAttributeText; |
|
48 iValues.Close(); |
|
49 iValueText.ResetAndDestroy(); |
|
50 } |
|
51 |
|
52 CPlayerApplicationSettings::CPlayerApplicationSettings( ) |
|
53 { |
|
54 } |
|
55 |
|
56 void CPlayerApplicationSettings::ConstructL(TUint aAttributeID, |
|
57 TDesC8& aAttributeText, |
|
58 const RArray<TUint>& aValues, |
|
59 RArray<TPtrC8>& aValueText, |
|
60 TUint aInitialValue ) |
|
61 { |
|
62 iAttributeID = aAttributeID; |
|
63 |
|
64 // copy the attribute description |
|
65 iAttributeText = aAttributeText.AllocL(); |
|
66 |
|
67 // copy the allowed values |
|
68 for (TInt i=0; i < aValues.Count(); i++ ) |
|
69 { |
|
70 |
|
71 // avoid duplicated defined values |
|
72 if (iValues.Find(aValues[i]) != KErrNotFound) |
|
73 { |
|
74 User::Leave(KErrArgument); |
|
75 } |
|
76 |
|
77 iValues.AppendL( aValues[i] ); |
|
78 |
|
79 // copy the value description into a HBuf and add pointer to iValueTexts |
|
80 HBufC8 * valueText = aValueText[i].AllocL(); |
|
81 CleanupStack::PushL(valueText); |
|
82 iValueText.AppendL(valueText); |
|
83 CleanupStack::Pop(valueText); |
|
84 } |
|
85 |
|
86 TInt error = SetCurrentValue( aInitialValue ); |
|
87 if ( error != KErrNone ) |
|
88 { |
|
89 User::Leave( error ); |
|
90 } |
|
91 } |
|
92 |
|
93 TUint CPlayerApplicationSettings::GetAttributeID() |
|
94 { |
|
95 return( iAttributeID ); |
|
96 } |
|
97 |
|
98 TUint CPlayerApplicationSettings::GetCurrentValue() |
|
99 { |
|
100 return( iCurrentValue ); |
|
101 } |
|
102 |
|
103 TPtrC8 CPlayerApplicationSettings::GetAttributeText() |
|
104 { |
|
105 return( *iAttributeText ); |
|
106 } |
|
107 |
|
108 RArray<TUint>* CPlayerApplicationSettings::GetValues() |
|
109 { |
|
110 return( &iValues ); |
|
111 } |
|
112 |
|
113 RPointerArray<HBufC8>* CPlayerApplicationSettings::GetValuesTexts() |
|
114 { |
|
115 return( &iValueText ); |
|
116 } |
|
117 |
|
118 TInt CPlayerApplicationSettings::SetCurrentValue(TUint aValue) |
|
119 { |
|
120 // Only allow setting already defined values |
|
121 for (TInt i=0; i < iValues.Count(); i++ ) |
|
122 { |
|
123 if ( aValue == iValues[i] ) |
|
124 { |
|
125 iCurrentValue = aValue; |
|
126 return KErrNone; |
|
127 } |
|
128 } |
|
129 |
|
130 // value was not already defined, so return KErrArgument |
|
131 return KErrArgument; |
|
132 } |
|
133 |
|