|
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: It completes on a change in the volume property. Used for |
|
15 * the new Central Repository Server. Used in EKA2 builds only |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <eikapp.h> |
|
21 #include <aknconsts.h> |
|
22 #include <browseruisdkcrkeys.h> |
|
23 |
|
24 #include "VolumeKeyListener.h" |
|
25 #include "MRepositoryVolumeObserver.h" |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KFirstTimerExpiryInterval = 1; // Expire immediately |
|
29 const TInt KTimerExpiryInterval = KAknStandardKeyboardRepeatRate; |
|
30 |
|
31 const TInt KMinVolume = 0; // Minimum volume level(Mute) |
|
32 const TInt KMaxVolume = 10; // Maximum volume level |
|
33 |
|
34 // ---------------------------------------------------- |
|
35 // CVolumeKeyListener::NewL |
|
36 // Description: static constructor. |
|
37 // Output: none |
|
38 // Return: CVolumeKeyListener object |
|
39 // ---------------------------------------------------- |
|
40 CVolumeKeyListener* CVolumeKeyListener::NewL( MRepositoryVolumeObserver* aObserver ) |
|
41 { |
|
42 CVolumeKeyListener* self = new(ELeave) CVolumeKeyListener( |
|
43 aObserver); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ---------------------------------------------------- |
|
51 // CVolumeKeyListener::CVolumeKeyListener |
|
52 // Description: constructor. |
|
53 // Output: none |
|
54 // Return: none |
|
55 // ---------------------------------------------------- |
|
56 CVolumeKeyListener::CVolumeKeyListener( MRepositoryVolumeObserver* aObserver ): |
|
57 iInterfaceSelector(NULL), |
|
58 iSelector(NULL), |
|
59 iCenRepos(NULL), |
|
60 iObserver(aObserver) |
|
61 { |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------- |
|
65 // CVolumeKeyListener::ConstructL |
|
66 // Description: second phase constructor. |
|
67 // Input: aObserver: link to the calling object |
|
68 // Output: none |
|
69 // Return: none |
|
70 // ---------------------------------------------------- |
|
71 void CVolumeKeyListener::ConstructL() |
|
72 { |
|
73 // |
|
74 // Open a connection to receive Volume Key events. |
|
75 iSelector = CRemConInterfaceSelector::NewL(); |
|
76 iInterfaceSelector = CRemConCoreApiTarget::NewL(*iSelector,*this); |
|
77 TRAP_IGNORE(iSelector->OpenTargetL()); |
|
78 // Timer for implementing repeat |
|
79 iTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
|
80 |
|
81 // |
|
82 // Open a connection to the Central Repository... |
|
83 iCenRepos = CRepository::NewL(KCRUidBrowser); |
|
84 // iObservers=new(ELeave)CArrayFixSeg<MVolumePropertyWatchObserver*> |
|
85 // (KVolumeObserversArrayGranularity); |
|
86 } |
|
87 |
|
88 // ---------------------------------------------------- |
|
89 // CVolumeKeyListener::~CVolumeKeyListener |
|
90 // Description: destructor. |
|
91 // Input: none |
|
92 // Output: none |
|
93 // ---------------------------------------------------- |
|
94 CVolumeKeyListener::~CVolumeKeyListener() |
|
95 { |
|
96 if(iSelector) |
|
97 { |
|
98 delete iSelector; |
|
99 iInterfaceSelector=NULL; |
|
100 iSelector=NULL; //iSelector has been deleted by "delete iInterfaceSelector" |
|
101 } |
|
102 |
|
103 if(iTimer) |
|
104 { |
|
105 iTimer->Cancel(); |
|
106 delete iTimer; |
|
107 } |
|
108 |
|
109 if(iCenRepos) |
|
110 { |
|
111 delete iCenRepos; |
|
112 } |
|
113 } |
|
114 |
|
115 // ---------------------------------------------------- |
|
116 // CVolumeKeyListener::SetObserver |
|
117 // Description: Used to set an observer |
|
118 // Input: aObserver: Point to observer |
|
119 // Output: none |
|
120 // Return: none |
|
121 // ---------------------------------------------------- |
|
122 void CVolumeKeyListener::SetObserver( MRepositoryVolumeObserver* aObserver) |
|
123 { |
|
124 iObserver = aObserver; |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------- |
|
128 // CVolumeKeyListener::GetCurrentVolume |
|
129 // Description: gets the current volume level from the |
|
130 // central directory. |
|
131 // Input: none |
|
132 // Output: none |
|
133 // Return: volume level |
|
134 // ---------------------------------------------------- |
|
135 TInt CVolumeKeyListener::GetCurrentVolume() |
|
136 { |
|
137 TInt currentVolume = 0; |
|
138 // |
|
139 // Get the current volume |
|
140 if(iCenRepos) |
|
141 iCenRepos->Get(KBrowserMediaVolumeControl, currentVolume); |
|
142 |
|
143 /* |
|
144 #if defined(__WINSCW__) //offset required on the emulator |
|
145 currentVolume += WINS_DEFAULT_VOLUME; |
|
146 #endif |
|
147 */ |
|
148 return currentVolume; |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------- |
|
152 // CVolumeKeyListener::MrccatoCommand |
|
153 // Description: A Volume key command has been received |
|
154 // (from MRemConCoreApiTargetObserver) |
|
155 // Input:aOperationId The operation ID of the command |
|
156 // aButtonAct The button action associated with the command. |
|
157 // Output: none |
|
158 // Return: none |
|
159 // ---------------------------------------------------- |
|
160 void CVolumeKeyListener::MrccatoCommand(TRemConCoreApiOperationId aOperationId, |
|
161 TRemConCoreApiButtonAction aButtonAct ) |
|
162 { |
|
163 |
|
164 switch(aOperationId) |
|
165 { |
|
166 case ERemConCoreApiVolumeUp: |
|
167 { |
|
168 switch (aButtonAct) |
|
169 { |
|
170 case ERemConCoreApiButtonPress: |
|
171 { |
|
172 //Start Timer |
|
173 if (!iTimer->IsActive()) |
|
174 { |
|
175 iCommandId = EVolumeControlCmdVolumeUpByOne; |
|
176 iTimer->Start(KFirstTimerExpiryInterval, |
|
177 KTimerExpiryInterval, |
|
178 TCallBack(TimerCallback, this)); |
|
179 } |
|
180 break; |
|
181 } |
|
182 case ERemConCoreApiButtonRelease: |
|
183 { |
|
184 iTimer->Cancel(); |
|
185 break; |
|
186 } |
|
187 case ERemConCoreApiButtonClick: |
|
188 { |
|
189 FilterAndSendCommand(EVolumeControlCmdVolumeUpByOne); |
|
190 break; |
|
191 } |
|
192 default: |
|
193 { |
|
194 break; |
|
195 } |
|
196 } |
|
197 break; |
|
198 } |
|
199 case ERemConCoreApiVolumeDown: |
|
200 { |
|
201 switch (aButtonAct) |
|
202 { |
|
203 case ERemConCoreApiButtonPress: |
|
204 { |
|
205 //Start Timer |
|
206 iCommandId = EVolumeControlCmdVolumeDownByOne; |
|
207 if (!iTimer->IsActive()) |
|
208 { |
|
209 iTimer->Start(KFirstTimerExpiryInterval, |
|
210 KTimerExpiryInterval, |
|
211 TCallBack(TimerCallback, this)); |
|
212 } |
|
213 break; |
|
214 } |
|
215 case ERemConCoreApiButtonRelease: |
|
216 { |
|
217 iTimer->Cancel(); |
|
218 break; |
|
219 } |
|
220 case ERemConCoreApiButtonClick: |
|
221 { |
|
222 FilterAndSendCommand(EVolumeControlCmdVolumeDownByOne); |
|
223 break; |
|
224 } |
|
225 default: |
|
226 { |
|
227 break; |
|
228 } |
|
229 } |
|
230 break; |
|
231 } |
|
232 default: |
|
233 { |
|
234 break; |
|
235 } |
|
236 } |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------- |
|
240 // CVolumeKeyListener::HandleRepeatEvent |
|
241 // ----------------------------------------------------------------------- |
|
242 // |
|
243 void CVolumeKeyListener::HandleRepeatEvent() |
|
244 { |
|
245 FilterAndSendCommand(iCommandId); |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------- |
|
249 // CVolumeKeyListener::TimerCallback |
|
250 // ----------------------------------------------------------------------- |
|
251 // |
|
252 TInt CVolumeKeyListener::TimerCallback(TAny* aPtr) |
|
253 { |
|
254 static_cast<CVolumeKeyListener*>(aPtr)->HandleRepeatEvent(); |
|
255 return KErrNone; |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------- |
|
259 // CVolumeKeyListener::FilterAndSendCommand |
|
260 // ----------------------------------------------------------------------- |
|
261 // |
|
262 void CVolumeKeyListener::FilterAndSendCommand(TInt aCommandId) |
|
263 { |
|
264 TInt currentVolume = 0; |
|
265 |
|
266 iCenRepos->Get(KBrowserMediaVolumeControl,currentVolume); |
|
267 switch(aCommandId) |
|
268 { |
|
269 case EVolumeControlCmdVolumeUpByOne: |
|
270 currentVolume=(currentVolume< KMaxVolume)? ++currentVolume : KMaxVolume; |
|
271 break; |
|
272 case EVolumeControlCmdVolumeDownByOne: |
|
273 currentVolume=(currentVolume> KMinVolume)? --currentVolume : KMinVolume; |
|
274 break; |
|
275 default: |
|
276 break; |
|
277 } |
|
278 |
|
279 iCenRepos->Set(KBrowserMediaVolumeControl,currentVolume); |
|
280 |
|
281 #if defined(__WINS__) //offset required on the emulator |
|
282 currentVolume += WINS_DEFAULT_VOLUME; |
|
283 #endif |
|
284 |
|
285 if(iObserver) |
|
286 iObserver->VolumeChanged(currentVolume); |
|
287 } |
|
288 |
|
289 // End of File |