|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Touch Toolbar |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <centralrepository.h> |
|
20 #include <akntoolbar.h> |
|
21 #include <aknbutton.h> |
|
22 #include <AknsUtils.h> |
|
23 #include <gulicon.h> |
|
24 #include <e32property.h> |
|
25 #include <aknappui.h> |
|
26 |
|
27 // User includes |
|
28 #include <hscontentpublisher.h> |
|
29 #include <hspublisherinfo.h> |
|
30 #include "aitoolbarrenderer.h" |
|
31 #include "aifweventhandler.h" |
|
32 #include "aicontentobserver.h" |
|
33 #include "activeidle2domaincrkeys.h" |
|
34 #include "activeidle2domainpskeys.h" |
|
35 #include "aiscutplugindomaincrkeys.h" |
|
36 |
|
37 #include "ainativeuiplugins.h" |
|
38 |
|
39 #include <AiNativeUi.rsg> |
|
40 #include "debug.h" |
|
41 |
|
42 using namespace AiNativeUiController; |
|
43 |
|
44 // Constants |
|
45 // Action to send to framework |
|
46 _LIT( KOpenAppByIndex, "Shortcut/LaunchByIndex(%d)" ); |
|
47 _LIT( KOpenAppByIndexAlternate, "Shortcut/LaunchByIndexAlternate(%d)"); |
|
48 |
|
49 const TInt KOpenAppByIndexParameterLength = 2; |
|
50 |
|
51 const TInt KFirstButton = 0; |
|
52 const TInt KSecondButton = 1; |
|
53 const TInt KThirdButton = 2; |
|
54 |
|
55 const TInt KRadix = 10; |
|
56 |
|
57 // ======== LOCAL FUNCTIONS ======== |
|
58 // ---------------------------------------------------------------------------- |
|
59 // IndexLength() |
|
60 // |
|
61 // ---------------------------------------------------------------------------- |
|
62 // |
|
63 static TInt IndexLength( TInt aIndex ) |
|
64 { |
|
65 TInt length = 0; |
|
66 |
|
67 if ( aIndex < 0 ) |
|
68 { |
|
69 ++length; |
|
70 } |
|
71 |
|
72 do |
|
73 { |
|
74 aIndex /= KRadix; |
|
75 ++length; |
|
76 } |
|
77 while ( aIndex != 0 ); |
|
78 |
|
79 return length; |
|
80 } |
|
81 |
|
82 // ---------------------------------------------------------------------------- |
|
83 // CreateEventStringL() |
|
84 // |
|
85 // ---------------------------------------------------------------------------- |
|
86 // |
|
87 static HBufC* CreateEventStringL( const TDesC& aFrom, TInt aEventIndex ) |
|
88 { |
|
89 HBufC* buffer = NULL; |
|
90 |
|
91 TInt bufferLength = aFrom.Length() - |
|
92 KOpenAppByIndexParameterLength + |
|
93 IndexLength( aEventIndex ); |
|
94 |
|
95 buffer = HBufC::NewL(bufferLength); |
|
96 |
|
97 TPtr bufferPtr = buffer->Des(); |
|
98 bufferPtr.Format( aFrom, aEventIndex ); |
|
99 |
|
100 return buffer; |
|
101 } |
|
102 |
|
103 // ======== MEMBER FUNCTIONS ======== |
|
104 // ---------------------------------------------------------------------------- |
|
105 // CAiToolbarRenderer::CAiToolbarRenderer() |
|
106 // |
|
107 // ---------------------------------------------------------------------------- |
|
108 // |
|
109 CAiToolbarRenderer::CAiToolbarRenderer( MAiFwEventHandler& aAiFwEventHandler, |
|
110 CAknToolbar& aToolbar ) |
|
111 : iToolbar( aToolbar ), |
|
112 iAiFwEventHandler( aAiFwEventHandler ) |
|
113 { |
|
114 // no implementation required |
|
115 } |
|
116 |
|
117 // ---------------------------------------------------------------------------- |
|
118 // CAiToolbarRenderer::ConstructL() |
|
119 // |
|
120 // ---------------------------------------------------------------------------- |
|
121 // |
|
122 void CAiToolbarRenderer::ConstructL( ) |
|
123 { |
|
124 iToolbarEnabled = EFalse; |
|
125 |
|
126 TInt err = KErrNone; |
|
127 |
|
128 CRepository *cr = CRepository::NewLC( TUid::Uid( KCRUidActiveIdleLV ) ); |
|
129 err = cr->Get( KAITouchToolbarVisible, iToolbarEnabled ); |
|
130 CleanupStack::PopAndDestroy( cr ); |
|
131 __PRINT (__DBG_FORMAT("XAI: Toolbar value in cenrep %d err = %d"), iToolbarEnabled , err); |
|
132 |
|
133 // Hide the toolbar because it is disabled via cenrep |
|
134 if ( err != KErrNone || !iToolbarEnabled ) |
|
135 { |
|
136 iToolbar.SetToolbarObserver( NULL ); |
|
137 iToolbar.SetToolbarVisibility( EFalse, EFalse ); |
|
138 } |
|
139 else |
|
140 { |
|
141 iToolbar.SetToolbarObserver( this ); |
|
142 iToolbar.SetToolbarVisibility( ETrue, EFalse ); |
|
143 } |
|
144 } |
|
145 |
|
146 // ---------------------------------------------------------------------------- |
|
147 // CAiToolbarRenderer::NewLC() |
|
148 // |
|
149 // ---------------------------------------------------------------------------- |
|
150 // |
|
151 CAiToolbarRenderer* CAiToolbarRenderer::NewLC( |
|
152 MAiFwEventHandler& aAiFwEventHandler, CAknToolbar& aToolbar ) |
|
153 { |
|
154 CAiToolbarRenderer* self = |
|
155 new ( ELeave ) CAiToolbarRenderer( aAiFwEventHandler, aToolbar ); |
|
156 CleanupStack::PushL( self ); |
|
157 self->ConstructL(); |
|
158 return self; |
|
159 } |
|
160 |
|
161 // ---------------------------------------------------------------------------- |
|
162 // CAiToolbarRenderer::NewL() |
|
163 // |
|
164 // ---------------------------------------------------------------------------- |
|
165 // |
|
166 CAiToolbarRenderer* CAiToolbarRenderer::NewL( |
|
167 MAiFwEventHandler& aAiFwEventHandler, CAknToolbar& aToolbar ) |
|
168 { |
|
169 CAiToolbarRenderer* self = |
|
170 CAiToolbarRenderer::NewLC( aAiFwEventHandler, aToolbar ); |
|
171 CleanupStack::Pop(); // self |
|
172 return self; |
|
173 } |
|
174 |
|
175 // ---------------------------------------------------------------------------- |
|
176 // CAiToolbarRenderer::~CAiToolbarRenderer() |
|
177 // |
|
178 // ---------------------------------------------------------------------------- |
|
179 // |
|
180 CAiToolbarRenderer::~CAiToolbarRenderer() |
|
181 { |
|
182 // We don't want anymore events from toolbar |
|
183 iToolbar.SetToolbarObserver( NULL ); |
|
184 iButtons.ResetAndDestroy(); |
|
185 } |
|
186 |
|
187 // ---------------------------------------------------------------------------- |
|
188 // CAiToolbarRenderer::DynInitToolbarL() |
|
189 // |
|
190 // ---------------------------------------------------------------------------- |
|
191 // |
|
192 void CAiToolbarRenderer::DynInitToolbarL( TInt /*aResourceId*/, |
|
193 CAknToolbar* /*aToolbar*/ ) |
|
194 { |
|
195 // do nothing |
|
196 } |
|
197 |
|
198 // ---------------------------------------------------------------------------- |
|
199 // CAiToolbarRenderer::OfferToolbarEventL() |
|
200 // |
|
201 // ---------------------------------------------------------------------------- |
|
202 // |
|
203 void CAiToolbarRenderer::OfferToolbarEventL( TInt aCommand ) |
|
204 { |
|
205 TInt modifiers = iToolbar.EventModifiers(); |
|
206 |
|
207 if ( aCommand >= 0 && aCommand < iButtons.Count()) |
|
208 { |
|
209 CAiToolbarButton* button = iButtons[aCommand]; |
|
210 |
|
211 if ( button ) |
|
212 { |
|
213 HBufC *event = NULL; |
|
214 |
|
215 if ( modifiers == CAknToolbar::ELongPress ) |
|
216 { |
|
217 event = CreateEventStringL( |
|
218 KOpenAppByIndexAlternate, button->ShortcutId() ); |
|
219 |
|
220 CleanupStack::PushL( event ); |
|
221 } |
|
222 else |
|
223 { |
|
224 event = CreateEventStringL( |
|
225 KOpenAppByIndex, button->ShortcutId() ); |
|
226 |
|
227 CleanupStack::PushL( event ); |
|
228 } |
|
229 |
|
230 iAiFwEventHandler.HandlePluginEvent( *event ); |
|
231 CleanupStack::PopAndDestroy( event ); |
|
232 } |
|
233 } |
|
234 } |
|
235 |
|
236 // ---------------------------------------------------------------------------- |
|
237 // CAiToolbarRenderer::DoPublishL() |
|
238 // |
|
239 // ---------------------------------------------------------------------------- |
|
240 // |
|
241 void CAiToolbarRenderer::DoPublishL( CHsContentPublisher& aPlugin, |
|
242 TInt aContent, const TDesC16& aText, TInt aIndex ) |
|
243 { |
|
244 const THsPublisherInfo& info( aPlugin.PublisherInfo() ); |
|
245 |
|
246 // Only interested on certain publish events |
|
247 if ( info.Uid() == KShortcutPluginUid && |
|
248 aContent == EAiScutContentShortcutToolbarCaption && |
|
249 ( aIndex == EAiScutToolbarFirst || |
|
250 aIndex == EAiScutToolbarSecond || |
|
251 aIndex == EAiScutToolbarThird ) |
|
252 ) |
|
253 { |
|
254 CAiToolbarButton* button = ButtonL( aIndex ); |
|
255 if ( button ) |
|
256 { |
|
257 button->SetTooltipL(aText); |
|
258 iCommitted = EFalse; |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 // ---------------------------------------------------------------------------- |
|
264 // CAiToolbarRenderer::DoPublishL() |
|
265 // |
|
266 // ---------------------------------------------------------------------------- |
|
267 // |
|
268 void CAiToolbarRenderer::DoPublishL( CHsContentPublisher& aPlugin, |
|
269 TInt aContent, const TDesC8& aBuf, TInt aIndex ) |
|
270 { |
|
271 const THsPublisherInfo& info( aPlugin.PublisherInfo() ); |
|
272 |
|
273 // Only interested on certain publish events |
|
274 if ( info.Uid() == KShortcutPluginUid && |
|
275 aContent == EAiScutContentShortcutToolbarIcon && |
|
276 ( aIndex == EAiScutToolbarFirst || |
|
277 aIndex == EAiScutToolbarSecond || |
|
278 aIndex == EAiScutToolbarThird ) |
|
279 ) |
|
280 { |
|
281 CGulIcon* icon = MAiContentObserver::UnpackPtr<CGulIcon>( aBuf ); |
|
282 CAiToolbarButton* button = NULL; |
|
283 if ( !icon ) |
|
284 { |
|
285 User::Leave(KErrArgument); |
|
286 } |
|
287 // Replace the old button with a new button |
|
288 button = ButtonL( aIndex ); |
|
289 if ( button ) |
|
290 { |
|
291 button->SetIcon(icon); |
|
292 iCommitted = EFalse; |
|
293 } |
|
294 // icons ownership is transferred to us |
|
295 // so we need to delete the icon in error situations |
|
296 else |
|
297 { |
|
298 delete icon; |
|
299 } |
|
300 } |
|
301 else |
|
302 { |
|
303 // We have received stuff we cannot publish. |
|
304 User::Leave(KErrNotFound); |
|
305 } |
|
306 } |
|
307 |
|
308 // ---------------------------------------------------------------------------- |
|
309 // CAiToolbarRenderer::ButtonL() |
|
310 // |
|
311 // ---------------------------------------------------------------------------- |
|
312 // |
|
313 CAiToolbarButton* CAiToolbarRenderer::ButtonL( TInt aShortcutId ) |
|
314 { |
|
315 TInt index = KErrNotFound; |
|
316 CAiToolbarButton *button = NULL; |
|
317 switch ( aShortcutId ) |
|
318 { |
|
319 case EAiScutToolbarFirst: |
|
320 index = KFirstButton; |
|
321 break; |
|
322 case EAiScutToolbarSecond: |
|
323 index = KSecondButton; |
|
324 break; |
|
325 case EAiScutToolbarThird: |
|
326 index = KThirdButton; |
|
327 break; |
|
328 default: |
|
329 break; |
|
330 } |
|
331 |
|
332 if ( index == KErrNotFound ) |
|
333 { |
|
334 User::Leave(KErrNotFound); |
|
335 } |
|
336 // No button yet => Create new |
|
337 if ( index >= iButtons.Count() ) |
|
338 { |
|
339 button = CAiToolbarButton::NewL(); |
|
340 button->SetShortcutId( aShortcutId ); |
|
341 iButtons.Append( button ); |
|
342 } |
|
343 |
|
344 // Use the old button |
|
345 else if( index >= KFirstButton && index < iButtons.Count() ) |
|
346 { |
|
347 button = iButtons[index]; |
|
348 button->SetShortcutId( aShortcutId ); |
|
349 } |
|
350 return button; |
|
351 } |
|
352 |
|
353 // ---------------------------------------------------------------------------- |
|
354 // CAiToolbarRenderer::TransactionCommittedL() |
|
355 // |
|
356 // ---------------------------------------------------------------------------- |
|
357 // |
|
358 void CAiToolbarRenderer::TransactionCommittedL() |
|
359 { |
|
360 if ( !iCommitted ) |
|
361 { |
|
362 for ( TInt i = 0; i < iButtons.Count(); i++ ) |
|
363 { |
|
364 CAiToolbarButton *button = iButtons[i]; |
|
365 if ( button && button->Icon()) |
|
366 { |
|
367 // remove the old button |
|
368 iToolbar.RemoveItem(i); |
|
369 // and add new one |
|
370 // transfers ownership of button->ButtonL() to toolbar |
|
371 iToolbar.AddItemL( button->ButtonL(), EAknCtButton, i, 0, i ); |
|
372 } |
|
373 } |
|
374 iCommitted = ETrue; |
|
375 } |
|
376 } |
|
377 |
|
378 // End of File. |