|
1 /* |
|
2 * Copyright (c) 2008-2009 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: Command object factory |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <glxtracer.h> |
|
22 #include <COEMAIN.H> |
|
23 #include <ipvideo/ViaPlayerMediaKeyObserver.h> // CViaPlayerMediaKeyObserver |
|
24 #include <e32Keys.h> |
|
25 #include <e32event.h> |
|
26 |
|
27 #include "glxmediakeyutility.h" |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // Constructor |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CGlxMediaKeyUtility::CGlxMediaKeyUtility() |
|
34 { |
|
35 TRACER("CGlxMediaKeyUtility::CGlxMediaKeyUtility()"); |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // Destructor. Remove itself as a listner from the MediaKeyObserver |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CGlxMediaKeyUtility::~CGlxMediaKeyUtility() |
|
43 { |
|
44 TRACER("CGlxMediaKeyUtility::~CGlxMediaKeyUtility()"); |
|
45 TRAP_IGNORE( CViaPlayerMediaKeyObserver::StaticL().RemoveListener( this ); ); |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // NewLC - Standard two phase constructor placing itself on the cleanup stack |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CGlxMediaKeyUtility* CGlxMediaKeyUtility::NewLC() |
|
53 { |
|
54 TRACER("CGlxMediaKeyUtility::NewLC()"); |
|
55 CGlxMediaKeyUtility* self = new (ELeave) CGlxMediaKeyUtility(); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // NewL - Standard two phase constructor |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CGlxMediaKeyUtility* CGlxMediaKeyUtility::NewL() |
|
66 { |
|
67 TRACER("CGlxMediaKeyUtility::NewL()"); |
|
68 CGlxMediaKeyUtility* self = CGlxMediaKeyUtility::NewLC(); |
|
69 CleanupStack::Pop(self); |
|
70 return self; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // ConstructL - Adds itsself as a media key listener |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 void CGlxMediaKeyUtility::ConstructL() |
|
78 { |
|
79 TRACER("CGlxMediaKeyUtility::ConstructL()"); |
|
80 CViaPlayerMediaKeyObserver::StaticL().AddListenerL( this ); |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // MediaKeyEventL - The ViaPlayerMediaKeyObserver sends all RemCon key events |
|
85 // here, where they get translated and dispatched |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void CGlxMediaKeyUtility::MediaKeyEventL(TRemConCoreApiOperationId aOperationId, |
|
89 TRemConCoreApiButtonAction aButtonAct ) |
|
90 { |
|
91 TRACER("CGlxMediaKeyUtility::MediaKeyEventL()"); |
|
92 TStdScanCode scanCode = TranslateKeyEvent(aOperationId); |
|
93 DispatchKeyEvent(aButtonAct, scanCode); |
|
94 } |
|
95 |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // DoSimulateKeyEvent - Add key event to application queue |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CGlxMediaKeyUtility::DoSimulateKeyEvent(TRawEvent::TType aKeyCode, TStdScanCode aScanCode ) |
|
102 { |
|
103 TRACER("CGlxMediaKeyUtility::DoSimulateKeyEvent()"); |
|
104 TRawEvent rawEvent; |
|
105 rawEvent.Set(aKeyCode, aScanCode); |
|
106 UserSvr::AddEvent(rawEvent); |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // TranslateKeyEvent - Translates RemCon keys into standard scan codes |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 TStdScanCode CGlxMediaKeyUtility::TranslateKeyEvent(TRemConCoreApiOperationId aOperationId) |
|
114 { |
|
115 TRACER("CGlxMediaKeyUtility::TranslateKeyEvent()"); |
|
116 |
|
117 TStdScanCode scanCode = EStdKeyNull; |
|
118 |
|
119 switch (aOperationId) |
|
120 { |
|
121 case ERemConCoreApiVolumeUp: |
|
122 scanCode = EStdKeyIncVolume; |
|
123 break; |
|
124 |
|
125 case ERemConCoreApiVolumeDown: |
|
126 scanCode = EStdKeyDecVolume; |
|
127 |
|
128 break; |
|
129 |
|
130 default: |
|
131 break; |
|
132 } |
|
133 |
|
134 return scanCode; |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // DispatchKeyEvent - Interperets the button action and acts accordingly |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CGlxMediaKeyUtility::DispatchKeyEvent(TRemConCoreApiButtonAction aButtonAct, TStdScanCode aScanCode) |
|
142 { |
|
143 TRACER("CGlxMediaKeyUtility::DispatchKeyEvent()"); |
|
144 |
|
145 if (EStdKeyNull == aScanCode) |
|
146 { |
|
147 return; |
|
148 } |
|
149 |
|
150 switch (aButtonAct) |
|
151 { |
|
152 case ERemConCoreApiButtonPress: |
|
153 DoSimulateKeyEvent(TRawEvent::EKeyDown, aScanCode); |
|
154 break; |
|
155 |
|
156 case ERemConCoreApiButtonRelease: |
|
157 DoSimulateKeyEvent(TRawEvent::EKeyUp, aScanCode); |
|
158 break; |
|
159 |
|
160 case ERemConCoreApiButtonClick: |
|
161 DoSimulateKeyEvent(TRawEvent::EKeyDown, aScanCode); |
|
162 DoSimulateKeyEvent(TRawEvent::EKeyUp, aScanCode); |
|
163 break; |
|
164 } |
|
165 } |
|
166 |