|
1 /* |
|
2 * Copyright (c) 2005 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: SmilPlayerVolumeIndicatorController implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "SmilPlayerVolumeIndicatorController.h" |
|
22 |
|
23 #include <AknVolumePopup.h> |
|
24 #include <avkon.rsg> |
|
25 |
|
26 #include <centralrepository.h> // Central Repository |
|
27 #include <messaginginternalcrkeys.h>// for Central Repository keys |
|
28 #include <ProfileEngineSDKCRKeys.h> |
|
29 #include <Profile.hrh> |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 const TInt KVolumeControlMinValue = 1; |
|
34 const TInt KVolumeControlMaxValue = 10; |
|
35 const TInt KVolumeDefault = 4; |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // CSmilPlayerVolumeIndicatorController::CSmilPlayerVolumeIndicatorController |
|
41 // C++ default constructor. |
|
42 // ---------------------------------------------------------------------------- |
|
43 // |
|
44 CSmilPlayerVolumeIndicatorController::CSmilPlayerVolumeIndicatorController() |
|
45 { |
|
46 } |
|
47 |
|
48 // ---------------------------------------------------------------------------- |
|
49 // CSmilPlayerVolumeIndicatorController::ConstructL |
|
50 // Symbian 2nd phase constructor. Initializes initial volume level. |
|
51 // After this arrow icons are created. |
|
52 // Then AVKON provided volume control is created and volume timer that updates volume |
|
53 // control visibility when needed. |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 void CSmilPlayerVolumeIndicatorController::ConstructL( const CCoeControl* aParent ) |
|
57 { |
|
58 SetContainerWindowL( *aParent ); |
|
59 |
|
60 iRepository = CRepository::NewL( KCRUidSmilui ); |
|
61 iInitialVolumeLevel = InitialVolumeLevelL(); |
|
62 |
|
63 iVolumePopup = CAknVolumePopup::NewL( NULL, ETrue ); |
|
64 iVolumePopup->SetValue( iInitialVolumeLevel ); |
|
65 iVolumePopup->SetObserver( this ); |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CSmilPlayerVolumeIndicatorController::NewL |
|
70 // EPOC two phased constructor |
|
71 // --------------------------------------------------------- |
|
72 // |
|
73 CSmilPlayerVolumeIndicatorController* CSmilPlayerVolumeIndicatorController::NewL( const CCoeControl* aParent ) |
|
74 { |
|
75 CSmilPlayerVolumeIndicatorController* self = new(ELeave) CSmilPlayerVolumeIndicatorController(); |
|
76 |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL( aParent ); |
|
79 CleanupStack::Pop( self ); |
|
80 |
|
81 return self; |
|
82 } |
|
83 |
|
84 // ---------------------------------------------------------------------------- |
|
85 // CSmilPlayerVolumeIndicatorController::~CSmilPlayerVolumeIndicatorController |
|
86 // Destructor. |
|
87 // ---------------------------------------------------------------------------- |
|
88 // |
|
89 CSmilPlayerVolumeIndicatorController::~CSmilPlayerVolumeIndicatorController() |
|
90 { |
|
91 StoreAudioVolume(); |
|
92 |
|
93 delete iRepository; |
|
94 |
|
95 delete iVolumePopup; |
|
96 } |
|
97 |
|
98 // ---------------------------------------------------------------------------- |
|
99 // CSmilPlayerVolumeControl::OfferKeyEventL |
|
100 // Handles the volume key event. Offers key to volume control which contains |
|
101 // information about minimum, current and maximum volume levels. If volume control |
|
102 // consumed volume key event sets volume control visible. |
|
103 // ---------------------------------------------------------------------------- |
|
104 // |
|
105 TKeyResponse CSmilPlayerVolumeIndicatorController::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
106 TEventCode aType ) |
|
107 { |
|
108 TKeyResponse response = EKeyWasNotConsumed; |
|
109 if ( aKeyEvent.iCode == EKeyRightArrow || aKeyEvent.iCode == EKeyUpArrow ) |
|
110 { |
|
111 iVolumePopup->ShowVolumePopupL(); |
|
112 TInt maxValue; |
|
113 TInt minValue; |
|
114 iVolumePopup->GetRange( minValue, maxValue ); |
|
115 TInt value = iVolumePopup->Value() + 1; |
|
116 value = value > maxValue ? maxValue : value; |
|
117 iVolumePopup->SetValue( value ); |
|
118 response = EKeyWasConsumed; |
|
119 } |
|
120 else if ( aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyDownArrow ) |
|
121 { |
|
122 iVolumePopup->ShowVolumePopupL(); |
|
123 TInt maxValue; |
|
124 TInt minValue; |
|
125 iVolumePopup->GetRange( minValue, maxValue ); |
|
126 TInt value = iVolumePopup->Value() - 1; |
|
127 value = value < minValue ? minValue : value; |
|
128 iVolumePopup->SetValue( value ); |
|
129 response = EKeyWasConsumed; |
|
130 } |
|
131 |
|
132 return response; |
|
133 } |
|
134 |
|
135 // ---------------------------------------------------------------------------- |
|
136 // CSmilPlayerVolumeIndicatorController::HandleControlEventL |
|
137 // |
|
138 // Handles control events from volume control. Events are used to control visibility |
|
139 // of left and right arrow. Volume level changes are also communicated to |
|
140 // observer with state change event. |
|
141 // ---------------------------------------------------------------------------- |
|
142 // |
|
143 void CSmilPlayerVolumeIndicatorController::HandleControlEventL( CCoeControl* aControl, |
|
144 TCoeEvent aEventType ) |
|
145 { |
|
146 if ( aControl == iVolumePopup && |
|
147 aEventType == MCoeControlObserver::EEventStateChanged ) |
|
148 { |
|
149 ReportEventL( MCoeControlObserver::EEventStateChanged ); |
|
150 } |
|
151 } |
|
152 |
|
153 // ---------------------------------------------------------------------------- |
|
154 // CSmilPlayerVolumeControl::VolumeValue |
|
155 // Returns current volume level. |
|
156 // ---------------------------------------------------------------------------- |
|
157 // |
|
158 TInt CSmilPlayerVolumeIndicatorController::VolumeValue() const |
|
159 { |
|
160 return iVolumePopup->Value(); |
|
161 } |
|
162 |
|
163 |
|
164 // ---------------------------------------------------------------------------- |
|
165 // CSmilPlayerVolumeIndicatorController::InitialVolumeLevelL |
|
166 // Returns correct initial volume level. Uses central repository to query used ringing tone |
|
167 // type and if it is set to silent then returns zero (=muted). |
|
168 // Otherwise queries last used volume level from central repository and returns this. |
|
169 // ---------------------------------------------------------------------------- |
|
170 // |
|
171 TInt CSmilPlayerVolumeIndicatorController::InitialVolumeLevelL() const |
|
172 { |
|
173 TInt result( 0 ); |
|
174 CRepository* repository = CRepository::NewLC( KCRUidProfileEngine ); |
|
175 |
|
176 TInt ringType( EProfileRingingTypeRinging ); |
|
177 User::LeaveIfError( repository->Get( KProEngActiveRingingType, ringType ) ); |
|
178 |
|
179 if ( ringType != EProfileRingingTypeSilent ) |
|
180 { |
|
181 result = KVolumeDefault; |
|
182 iRepository->Get( KSmilPlayerVolume, result ); |
|
183 } |
|
184 |
|
185 CleanupStack::PopAndDestroy( repository ); |
|
186 |
|
187 return result; |
|
188 } |
|
189 |
|
190 // ---------------------------------------------------------------------------- |
|
191 // CSmilPlayerVolumeIndicatorController::StoreAudioVolume |
|
192 // Stores the changed volume level to central repository so that |
|
193 // volume is always between KVolumeControlMinValue and KVolumeControlMaxValue. |
|
194 // Volume level is only stored if it has been changed. |
|
195 // ---------------------------------------------------------------------------- |
|
196 // |
|
197 void CSmilPlayerVolumeIndicatorController::StoreAudioVolume() |
|
198 { |
|
199 if ( iRepository ) |
|
200 { |
|
201 TInt currVolume = VolumeValue(); |
|
202 |
|
203 if ( currVolume != iInitialVolumeLevel ) |
|
204 { |
|
205 //calculate the changed value (current + 1) or (currentvalue - 1) |
|
206 TInt storedVolume = Max( KVolumeControlMinValue, Min( KVolumeControlMaxValue, currVolume ) ); |
|
207 |
|
208 iRepository->Set( KSmilPlayerVolume, storedVolume ); |
|
209 } |
|
210 } |
|
211 } |
|
212 |
|
213 // End of File |
|
214 |