1 /* |
|
2 * Copyright (c) 2002 - 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: Class that observer remote controller framework events |
|
15 * and forwards them as key events to observe |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include <w32std.h> |
|
23 #include <remconcoreapitarget.h> |
|
24 #include <remconinterfaceselector.h> |
|
25 #include <AknDef.h> |
|
26 #include <aknconsts.h> |
|
27 |
|
28 #include "MVRVolumeEventObserver.h" |
|
29 #include "CVRRemConObserver.h" |
|
30 |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS ============================== |
|
33 |
|
34 // ---------------------------------------------------------------------------- |
|
35 // CVRRemConObserver::CVRRemConObserver |
|
36 // C++ default constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // ---------------------------------------------------------------------------- |
|
39 // |
|
40 CVRRemConObserver::CVRRemConObserver( MVRVolumeEventObserver* aObserver ) |
|
41 : iObserver( aObserver ) |
|
42 { |
|
43 } |
|
44 |
|
45 // ---------------------------------------------------------------------------- |
|
46 // CVRRemConObserver::ConstructL |
|
47 // Symbian 2nd phase constructor can leave. |
|
48 // ---------------------------------------------------------------------------- |
|
49 // |
|
50 void CVRRemConObserver::ConstructL() |
|
51 { |
|
52 iInterfaceSelector = CRemConInterfaceSelector::NewL(); |
|
53 |
|
54 iCoreTarget = CRemConCoreApiTarget::NewL( *iInterfaceSelector, *this ); |
|
55 |
|
56 iInterfaceSelector->OpenTargetL(); |
|
57 |
|
58 iVolumeRepeatTimer = CPeriodic::NewL( CActive::EPriorityHigh ); |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // CVRRemConObserver::NewL |
|
63 // Two-phased constructor. |
|
64 // ---------------------------------------------------------------------------- |
|
65 // |
|
66 CVRRemConObserver* CVRRemConObserver::NewL( MVRVolumeEventObserver* aObserver ) |
|
67 { |
|
68 CVRRemConObserver* self = new( ELeave ) CVRRemConObserver( aObserver ); |
|
69 |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop(); |
|
73 |
|
74 return self; |
|
75 } |
|
76 |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // CVRRemConObserver::~CVRRemConObserver |
|
80 // Destructor |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 CVRRemConObserver::~CVRRemConObserver() |
|
84 { |
|
85 delete iInterfaceSelector; // it internally deletes iCoreTarget |
|
86 |
|
87 if( iVolumeRepeatTimer->IsActive() ) |
|
88 { |
|
89 iVolumeRepeatTimer->Cancel(); |
|
90 } |
|
91 delete iVolumeRepeatTimer; |
|
92 } |
|
93 |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CVRRemConObserver::MrccatoCommand |
|
97 // |
|
98 // ---------------------------------------------------------------------------- |
|
99 // |
|
100 EXPORT_C void CVRRemConObserver::MrccatoCommand( |
|
101 TRemConCoreApiOperationId aOperationId, |
|
102 TRemConCoreApiButtonAction aButtonAct ) |
|
103 { |
|
104 TKeyEvent myEvent; |
|
105 |
|
106 if( iVolumeRepeatTimer->IsActive()) |
|
107 { |
|
108 iVolumeRepeatTimer->Cancel(); |
|
109 } |
|
110 |
|
111 switch( aOperationId ) |
|
112 { |
|
113 case ERemConCoreApiVolumeUp: |
|
114 { |
|
115 // Simulate a "right button event" for CAknVolumeControl |
|
116 myEvent.iCode = EKeyRightArrow; |
|
117 break; |
|
118 } |
|
119 case ERemConCoreApiVolumeDown: |
|
120 { |
|
121 // Simulate a "left button event" for CAknVolumeControl |
|
122 myEvent.iCode = EKeyLeftArrow; |
|
123 break; |
|
124 } |
|
125 default: |
|
126 { |
|
127 // Ignore other commands |
|
128 return; |
|
129 } |
|
130 } |
|
131 |
|
132 // Convert the remote control event to a button click and send it to |
|
133 // volume control |
|
134 switch( aButtonAct ) |
|
135 { |
|
136 case ERemConCoreApiButtonClick: |
|
137 { |
|
138 TRAP_IGNORE( iObserver->HandleVolumeChangeL( myEvent, |
|
139 EEventKey ) ); |
|
140 break; |
|
141 } |
|
142 case ERemConCoreApiButtonPress: |
|
143 { |
|
144 // Start repeat |
|
145 iVolumeChange = myEvent; |
|
146 iVolumeRepeatTimer->Cancel(); |
|
147 iVolumeRepeatTimer->Start( |
|
148 KAknStandardKeyboardRepeatRate, |
|
149 KAknStandardKeyboardRepeatRate, |
|
150 TCallBack( DoHandleVolumeRepeatL, this ) ); |
|
151 break; |
|
152 } |
|
153 case ERemConCoreApiButtonRelease: |
|
154 { |
|
155 iVolumeChange.iCode = 0; |
|
156 break; |
|
157 } |
|
158 default: |
|
159 { |
|
160 break; |
|
161 } |
|
162 } |
|
163 |
|
164 } |
|
165 |
|
166 |
|
167 // ---------------------------------------------------------------------------- |
|
168 // CVRRemConObserver::DoHandleVolumeRepeatL |
|
169 // |
|
170 // ---------------------------------------------------------------------------- |
|
171 // |
|
172 TInt CVRRemConObserver::DoHandleVolumeRepeatL( TAny* aAny ) |
|
173 { |
|
174 // Repeat last keypress |
|
175 CVRRemConObserver* self = reinterpret_cast< CVRRemConObserver* >( aAny ); |
|
176 if ( self->iObserver->HandleVolumeChangeL( self->iVolumeChange, EEventKey ) |
|
177 != KErrNone ) |
|
178 { |
|
179 self->iVolumeChange.iCode = 0; |
|
180 self->iVolumeRepeatTimer->Cancel(); |
|
181 } |
|
182 return KErrNone; |
|
183 } |
|
184 |
|
185 // End of File |
|