]> code.delx.au - comingnext/blob - ComingNext_SkinFetcher/src/ComingNext_SkinFetcherContainerView.cpp
added first implementation of ComingNext Skin Fetcher app
[comingnext] / ComingNext_SkinFetcher / src / ComingNext_SkinFetcherContainerView.cpp
1 /*
2 ========================================================================
3 Name : ComingNext_SkinFetcherContainerView.cpp
4 Author : Michael Prager
5 Copyright : Licensed under GPLv3
6 Description :
7 ========================================================================
8 */
9 // [[[ begin generated region: do not modify [Generated System Includes]
10 #include <aknviewappui.h>
11 #include <eikmenub.h>
12 #include <avkon.hrh>
13 #include <barsread.h>
14 #include <stringloader.h>
15 #include <eiklabel.h>
16 #include <eikenv.h>
17 #include <akncontext.h>
18 #include <akntitle.h>
19 #include <eikbtgpc.h>
20 #include <aknlistquerydialog.h>
21 #include <akniconarray.h>
22 #include <aknnotewrappers.h>
23 #include <ComingNext_SkinFetcher.rsg>
24 // ]]] end generated region [Generated System Includes]
25
26 // [[[ begin generated region: do not modify [Generated User Includes]
27
28 #include "ComingNext_SkinFetcher.hrh"
29 #include "ComingNext_SkinFetcherContainerView.h"
30 #include "ComingNext_SkinFetcherContainer.hrh"
31 #include "ComingNext_SkinFetcherContainer.h"
32 // ]]] end generated region [Generated User Includes]
33
34 // [[[ begin generated region: do not modify [Generated Constants]
35 // ]]] end generated region [Generated Constants]
36
37 #include "SkinFetcher.h"
38
39 /**
40 * First phase of Symbian two-phase construction. Should not contain any
41 * code that could leave.
42 */
43 CComingNext_SkinFetcherContainerView::CComingNext_SkinFetcherContainerView()
44 {
45 // [[[ begin generated region: do not modify [Generated Contents]
46 iComingNext_SkinFetcherContainer = NULL;
47 // ]]] end generated region [Generated Contents]
48
49 }
50
51 /**
52 * The view's destructor removes the container from the control
53 * stack and destroys it.
54 */
55 CComingNext_SkinFetcherContainerView::~CComingNext_SkinFetcherContainerView()
56 {
57 // [[[ begin generated region: do not modify [Generated Contents]
58 delete iComingNext_SkinFetcherContainer;
59 iComingNext_SkinFetcherContainer = NULL;
60 // ]]] end generated region [Generated Contents]
61
62 }
63
64 /**
65 * Symbian two-phase constructor.
66 * This creates an instance then calls the second-phase constructor
67 * without leaving the instance on the cleanup stack.
68 * @return new instance of CComingNext_SkinFetcherContainerView
69 */
70 CComingNext_SkinFetcherContainerView* CComingNext_SkinFetcherContainerView::NewL()
71 {
72 CComingNext_SkinFetcherContainerView* self =
73 CComingNext_SkinFetcherContainerView::NewLC();
74 CleanupStack::Pop(self);
75 return self;
76 }
77
78 /**
79 * Symbian two-phase constructor.
80 * This creates an instance, pushes it on the cleanup stack,
81 * then calls the second-phase constructor.
82 * @return new instance of CComingNext_SkinFetcherContainerView
83 */
84 CComingNext_SkinFetcherContainerView* CComingNext_SkinFetcherContainerView::NewLC()
85 {
86 CComingNext_SkinFetcherContainerView* self =
87 new (ELeave) CComingNext_SkinFetcherContainerView();
88 CleanupStack::PushL(self);
89 self->ConstructL();
90 return self;
91 }
92
93 /**
94 * Second-phase constructor for view.
95 * Initialize contents from resource.
96 */
97 void CComingNext_SkinFetcherContainerView::ConstructL()
98 {
99 // [[[ begin generated region: do not modify [Generated Code]
100 BaseConstructL( R_COMING_NEXT_SKIN_FETCHER_CONTAINER_COMING_NEXT_SKIN_FETCHER_CONTAINER_VIEW_2 );
101
102 // ]]] end generated region [Generated Code]
103
104 // add your own initialization code here
105
106 }
107
108 /**
109 * @return The UID for this view
110 */
111 TUid CComingNext_SkinFetcherContainerView::Id() const
112 {
113 return TUid::Uid(EComingNext_SkinFetcherContainerViewId);
114 }
115
116 /**
117 * Handle a command for this view (override)
118 * @param aCommand command id to be handled
119 */
120 void CComingNext_SkinFetcherContainerView::HandleCommandL(TInt aCommand)
121 {
122 // [[[ begin generated region: do not modify [Generated Code]
123 TBool commandHandled = EFalse;
124 switch ( aCommand )
125 { // code to dispatch to the AknView's menu and CBA commands is generated here
126
127 case EComingNext_SkinFetcherContainerViewControlPaneLeftId:
128 commandHandled = HandleControlPaneLeftSoftKeyPressedL( aCommand );
129 break;
130
131 case EAknSoftkeyExit:
132 commandHandled = HandleControlPaneRightSoftKeyPressedL( aCommand );
133 break;
134 default:
135 break;
136 }
137
138
139 if ( !commandHandled )
140 {
141
142 if ( aCommand == EAknSoftkeyExit )
143 {
144 AppUi()->HandleCommandL( EEikCmdExit );
145 }
146
147 }
148 // ]]] end generated region [Generated Code]
149
150 }
151
152 /**
153 * Handles user actions during activation of the view,
154 * such as initializing the content.
155 */
156 void CComingNext_SkinFetcherContainerView::DoActivateL(
157 const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/,
158 const TDesC8& /*aCustomMessage*/)
159 {
160 // [[[ begin generated region: do not modify [Generated Contents]
161 SetupStatusPaneL();
162
163
164
165
166 if ( iComingNext_SkinFetcherContainer == NULL )
167 {
168 iComingNext_SkinFetcherContainer = CreateContainerL();
169 iComingNext_SkinFetcherContainer->SetMopParent( this );
170 AppUi()->AddToStackL( *this, iComingNext_SkinFetcherContainer );
171 }
172 // ]]] end generated region [Generated Contents]
173
174 }
175
176 /**
177 */
178 void CComingNext_SkinFetcherContainerView::DoDeactivate()
179 {
180 // [[[ begin generated region: do not modify [Generated Contents]
181 CleanupStatusPane();
182
183 if ( iComingNext_SkinFetcherContainer != NULL )
184 {
185 AppUi()->RemoveFromViewStack( *this, iComingNext_SkinFetcherContainer );
186 delete iComingNext_SkinFetcherContainer;
187 iComingNext_SkinFetcherContainer = NULL;
188 }
189 // ]]] end generated region [Generated Contents]
190
191 }
192
193 /**
194 * Handle status pane size change for this view (override)
195 */
196 void CComingNext_SkinFetcherContainerView::HandleStatusPaneSizeChange()
197 {
198 CAknView::HandleStatusPaneSizeChange();
199
200 // this may fail, but we're not able to propagate exceptions here
201 TVwsViewId view;
202 AppUi()->GetActiveViewId(view);
203 if (view.iViewUid == Id())
204 {
205 TInt result;
206 TRAP( result, SetupStatusPaneL() );
207 }
208
209 // [[[ begin generated region: do not modify [Generated Code]
210 // ]]] end generated region [Generated Code]
211
212 }
213
214 // [[[ begin generated function: do not modify
215 void CComingNext_SkinFetcherContainerView::SetupStatusPaneL()
216 {
217 // reset the context pane
218 TUid contextPaneUid = TUid::Uid( EEikStatusPaneUidContext );
219 CEikStatusPaneBase::TPaneCapabilities subPaneContext =
220 StatusPane()->PaneCapabilities( contextPaneUid );
221 if ( subPaneContext.IsPresent() && subPaneContext.IsAppOwned() )
222 {
223 CAknContextPane* context = static_cast< CAknContextPane* > (
224 StatusPane()->ControlL( contextPaneUid ) );
225 context->SetPictureToDefaultL();
226 }
227
228 // setup the title pane
229 TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
230 CEikStatusPaneBase::TPaneCapabilities subPaneTitle =
231 StatusPane()->PaneCapabilities( titlePaneUid );
232 if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
233 {
234 CAknTitlePane* title = static_cast< CAknTitlePane* >(
235 StatusPane()->ControlL( titlePaneUid ) );
236 TResourceReader reader;
237 iEikonEnv->CreateResourceReaderLC( reader, R_COMING_NEXT_SKIN_FETCHER_CONTAINER_TITLE_RESOURCE_2 );
238 title->SetFromResourceL( reader );
239 CleanupStack::PopAndDestroy(); // reader internal state
240 }
241
242 }
243
244 // ]]] end generated function
245
246 // [[[ begin generated function: do not modify
247 void CComingNext_SkinFetcherContainerView::CleanupStatusPane()
248 {
249 }
250
251 // ]]] end generated function
252
253 /**
254 * Creates the top-level container for the view. You may modify this method's
255 * contents and the CComingNext_SkinFetcherContainer::NewL() signature as needed to initialize the
256 * container, but the signature for this method is fixed.
257 * @return new initialized instance of CComingNext_SkinFetcherContainer
258 */
259 CComingNext_SkinFetcherContainer* CComingNext_SkinFetcherContainerView::CreateContainerL()
260 {
261 return CComingNext_SkinFetcherContainer::NewL(ClientRect(), NULL, this);
262 }
263
264 /**
265 * Handle the leftSoftKeyPressed event.
266 * @return ETrue if the command was handled, EFalse if not
267 */
268 TBool CComingNext_SkinFetcherContainerView::HandleControlPaneLeftSoftKeyPressedL(
269 TInt aCommand)
270 {
271 TInt pos = RunListQuery1L(NULL, NULL, NULL);
272 if (pos != -1)
273 {
274 CSkinFetcher::GenerateBackgroundImage(pos,
275 CAknViewAppUi::EAppUiOrientationPortrait);
276 CSkinFetcher::GenerateBackgroundImage(pos,
277 CAknViewAppUi::EAppUiOrientationLandscape);
278 RunNote1L();
279 }
280 return ETrue;
281 }
282
283 /**
284 * Handle the rightSoftKeyPressed event.
285 * @return ETrue if the command was handled, EFalse if not
286 */
287 TBool CComingNext_SkinFetcherContainerView::HandleControlPaneRightSoftKeyPressedL(
288 TInt aCommand)
289 {
290 iAvkonAppUi->Exit();
291 return ETrue;
292 }
293
294 // [[[ begin generated function: do not modify
295 /**
296 * Create a list box item with the given column values.
297 */
298 void CComingNext_SkinFetcherContainerView::CreateListQuery1ItemL(
299 TDes& aBuffer,
300
301 const TDesC& aMainText )
302 {
303 _LIT ( KStringHeader, "%S" );
304
305 aBuffer.Format( KStringHeader(), &aMainText );
306 }
307 // ]]] end generated function
308
309 // [[[ begin generated function: do not modify
310 /**
311 * Add an item to the list by reading the text items from resource
312 * and setting a single image property (if available) from an index
313 * in the list box's icon array.
314 * @param aResourceId id of an ARRAY resource containing the textual
315 * items in the columns
316 *
317 */
318 void CComingNext_SkinFetcherContainerView::CreateListQuery1ResourceArrayItemL(
319 TDes& aBuffer,
320 TInt aResourceId )
321 {
322 CDesCArray* array = CCoeEnv::Static()->ReadDesCArrayResourceL( aResourceId );
323 CleanupStack::PushL( array );
324 CreateListQuery1ItemL( aBuffer, ( *array ) [ 0 ] );
325 CleanupStack::PopAndDestroy( array );
326 }
327 // ]]] end generated function
328
329 // [[[ begin generated function: do not modify
330 /**
331 * Initialize contents of the popup item list. This constructs the array
332 * and pushes it on the cleanup stack.
333 * @return item array, never null
334 */
335 CDesCArray* CComingNext_SkinFetcherContainerView::InitializeListQuery1LC()
336 {
337 const int KNumItems = 5;
338 CDesCArray* itemArray = new ( ELeave ) CDesCArrayFlat( KNumItems ? KNumItems : 1 );
339 CleanupStack::PushL( itemArray );
340
341 // This is intended to be large enough, but if you get
342 // a USER 11 panic, consider reducing string sizes.
343 TBuf< 512 > des;
344 CreateListQuery1ResourceArrayItemL(
345 des, R_COMING_NEXT_SKIN_FETCHER_CONTAINER_LISTBOX_ITEM1 );
346 itemArray->AppendL( des );
347 CreateListQuery1ResourceArrayItemL(
348 des, R_COMING_NEXT_SKIN_FETCHER_CONTAINER_LISTBOX_ITEM2 );
349 itemArray->AppendL( des );
350 CreateListQuery1ResourceArrayItemL(
351 des, R_COMING_NEXT_SKIN_FETCHER_CONTAINER_LISTBOX_ITEM3 );
352 itemArray->AppendL( des );
353 CreateListQuery1ResourceArrayItemL(
354 des, R_COMING_NEXT_SKIN_FETCHER_CONTAINER_LISTBOX_ITEM4 );
355 itemArray->AppendL( des );
356 CreateListQuery1ResourceArrayItemL(
357 des, R_COMING_NEXT_SKIN_FETCHER_CONTAINER_LISTBOX_ITEM5 );
358 itemArray->AppendL( des );
359 return itemArray;
360 }
361 // ]]] end generated function
362
363 // [[[ begin generated function: do not modify
364 /**
365 * Set up the list query's icon array. If any icons are used, allocates an
366 * icon array, and places it on the cleanup stack.
367 * @return icon array, or NULL
368 */
369 CArrayPtr< CGulIcon >* CComingNext_SkinFetcherContainerView::SetupListQuery1IconsLC()
370 {
371 CArrayPtr< CGulIcon >* icons = NULL;
372 return icons;
373 }
374
375 // ]]] end generated function
376
377 // [[[ begin generated function: do not modify
378 /**
379 * Show the popup list query dialog for listQuery1.
380 * <p>
381 * You may override the designer-specified items or icons, though generally
382 * both should be overridden together.
383 * @param aOverrideText optional override text
384 * @param aOverrideItemArray if not NULL, the array of formatted list items to display (passes ownership)
385 * @param aOverrideIconArray if not NULL, the array of icons to display (passes ownership)
386 * @return selected index (>=0) or -1 for Cancel
387 */
388 TInt CComingNext_SkinFetcherContainerView::RunListQuery1L(
389 const TDesC* aOverrideText,
390 CDesCArray* aOverrideItemArray,
391 CArrayPtr< CGulIcon >* aOverrideIconArray )
392 {
393 TInt index = 0;
394 CAknListQueryDialog* queryDialog = NULL;
395 queryDialog = new ( ELeave ) CAknListQueryDialog( &index );
396 CleanupStack::PushL( queryDialog );
397
398 queryDialog->PrepareLC( R_COMING_NEXT_SKIN_FETCHER_CONTAINER_LIST_QUERY1 );
399 if ( aOverrideText != NULL )
400 {
401 queryDialog->SetHeaderTextL( *aOverrideText );
402 }
403
404 // initialize list items
405 CDesCArray* itemArray = NULL;
406
407 if ( aOverrideItemArray != NULL )
408 {
409 CleanupStack::PushL( aOverrideItemArray );
410 itemArray = aOverrideItemArray;
411 }
412 else
413 {
414 itemArray = InitializeListQuery1LC();
415 }
416
417 queryDialog->SetItemTextArray( itemArray );
418 queryDialog->SetOwnershipType( ELbmOwnsItemArray );
419 CleanupStack::Pop( itemArray );
420
421 // initialize list icons
422 CArrayPtr< CGulIcon >* iconArray = NULL;
423
424 if ( aOverrideIconArray != NULL )
425 {
426 CleanupStack::PushL( aOverrideIconArray );
427 iconArray = aOverrideIconArray;
428 }
429 else
430 {
431 iconArray = SetupListQuery1IconsLC();
432 }
433
434 if ( iconArray != NULL )
435 {
436 queryDialog->SetIconArrayL( iconArray ); // passes ownership
437 CleanupStack::Pop( iconArray );
438 }
439
440 // run dialog
441 TInt result = queryDialog->RunLD();
442
443 // clean up
444 CleanupStack::Pop( queryDialog );
445
446 return result == 0 ? -1 : index;
447 }
448
449 // ]]] end generated function
450
451 // [[[ begin generated function: do not modify
452 /**
453 * Show the popup note for note1
454 * @param aOverrideText optional override text
455 */
456 void CComingNext_SkinFetcherContainerView::RunNote1L( const TDesC* aOverrideText )
457 {
458 CAknConfirmationNote* note = new ( ELeave ) CAknConfirmationNote();
459 if ( aOverrideText == NULL )
460 {
461 HBufC* noteText = StringLoader::LoadLC( R_COMING_NEXT_SKIN_FETCHER_CONTAINER_NOTE1 );
462 note->ExecuteLD( *noteText );
463 CleanupStack::PopAndDestroy( noteText );
464 }
465 else
466 {
467 note->ExecuteLD( *aOverrideText );
468 }
469 }
470 // ]]] end generated function
471