|
1 /* |
|
2 * Copyright (c) 2006-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: Background task for creating views. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "pslnidletaskcreateviews.h" |
|
20 #include "PslnUi.h" |
|
21 #include "PslnConst.h" |
|
22 #include "PslnModel.h" |
|
23 |
|
24 // First step is to create tabgroup. |
|
25 const TInt KPslnCreateTabs = 0; |
|
26 // Second step is to create parts of the model. |
|
27 const TInt KPslnFullUpdateModel = 1; |
|
28 // Third step is to create general theme view. |
|
29 const TInt KPslnCreateGeneralView = 2; |
|
30 // Fourth step is to create wallpaper view. |
|
31 const TInt KPslnCreateWallpaperView = 3; |
|
32 // Fifth (and final) step is to create screensaver view. |
|
33 const TInt KPslnCreateScreensaverView = 4; |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // C++ constructor can NOT contain any code, that might leave. |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CPslnIdleTaskCreateViews::CPslnIdleTaskCreateViews( CPslnUi* aPslnUi ) : |
|
40 iPslnUi( aPslnUi ), iDone( EFalse ), iIdleStep( KPslnCreateTabs ) |
|
41 { |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // Two-phased constructor. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CPslnIdleTaskCreateViews* CPslnIdleTaskCreateViews::NewL( CPslnUi* aPslnUi ) |
|
49 { |
|
50 CPslnIdleTaskCreateViews* self = |
|
51 new( ELeave ) CPslnIdleTaskCreateViews( aPslnUi ); |
|
52 |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // Symbian 2nd phase constructor can leave. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CPslnIdleTaskCreateViews::ConstructL() |
|
64 { |
|
65 iIdleTask = CIdle::NewL( CActive::EPriorityIdle ); |
|
66 iIdleTask->Start( TCallBack( DoHandleIdleTimeL, this ) ); |
|
67 } |
|
68 |
|
69 // Destructor |
|
70 CPslnIdleTaskCreateViews::~CPslnIdleTaskCreateViews() |
|
71 { |
|
72 if ( iIdleTask ) |
|
73 { |
|
74 iIdleTask->Cancel(); |
|
75 } |
|
76 delete iIdleTask; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // Informs when task is finished. |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 TBool CPslnIdleTaskCreateViews::IsFinished() const |
|
84 { |
|
85 return iDone; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // Callback function when application is idle. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 TInt CPslnIdleTaskCreateViews::DoHandleIdleTimeL( TAny* aAny ) |
|
93 { |
|
94 static_cast< CPslnIdleTaskCreateViews* >( aAny )->HandleIdleTimeL(); |
|
95 return KErrNone; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // Handles idle time. With each step a new view is created. |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CPslnIdleTaskCreateViews::HandleIdleTimeL() |
|
103 { |
|
104 if ( !IsFinished() ) |
|
105 { |
|
106 TUid viewToCreate = KPslnGeneralView; //just initialise |
|
107 switch( iIdleStep ) |
|
108 { |
|
109 case KPslnCreateTabs: |
|
110 iPslnUi->ConstructTabGroupL(); |
|
111 break; |
|
112 case KPslnFullUpdateModel: |
|
113 if ( iPslnUi->Model() && |
|
114 iPslnUi->Model()->ActiveSkinIndex() == KErrNotFound ) |
|
115 { |
|
116 iPslnUi->Model()->PerformCompleteUpdateL(); |
|
117 } |
|
118 break; |
|
119 case KPslnCreateGeneralView: |
|
120 viewToCreate = KPslnGeneralView; |
|
121 break; |
|
122 case KPslnCreateWallpaperView: |
|
123 viewToCreate = KPslnWallpaperView; |
|
124 break; |
|
125 case KPslnCreateScreensaverView: |
|
126 viewToCreate = KPslnScreenSaverView; |
|
127 iDone = ETrue; |
|
128 break; |
|
129 default: |
|
130 User::Leave( KErrArgument ); |
|
131 break; |
|
132 } |
|
133 if ( iIdleStep != KPslnCreateTabs && iIdleStep != KPslnFullUpdateModel ) |
|
134 { |
|
135 iPslnUi->CreateViewL( viewToCreate ); |
|
136 } |
|
137 iIdleStep++; |
|
138 if ( !iDone ) |
|
139 { |
|
140 if ( iIdleTask && !iIdleTask->IsActive() ) |
|
141 { |
|
142 iIdleTask->Start( TCallBack( DoHandleIdleTimeL, this ) ); |
|
143 } |
|
144 } |
|
145 } |
|
146 } |
|
147 |
|
148 // End of file |