|
1 /* |
|
2 * Copyright (c) 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: Helper to do delayed processing after application startup |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <eikenv.h> |
|
21 #include"FSDelayedLoader.h" |
|
22 #include"FreestyleEmailUiConstants.h" |
|
23 #include "FreestyleEmailUiContactHandler.h" |
|
24 |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CFsDelayedLoader::InstanceL |
|
28 // |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CFsDelayedLoader* CFsDelayedLoader::InstanceL() |
|
32 { |
|
33 FUNC_LOG; |
|
34 CFsDelayedLoader* instance = static_cast<CFsDelayedLoader*>( CCoeEnv::Static( KDelayedLoaderUid ) ); |
|
35 if ( !instance ) |
|
36 { |
|
37 instance = new ( ELeave ) CFsDelayedLoader; |
|
38 CleanupStack::PushL( instance ); |
|
39 instance->ConstructL(); |
|
40 CleanupStack::Pop(); |
|
41 } |
|
42 return instance; |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CFsDelayedLoader::ConstructL |
|
47 // |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CFsDelayedLoader::ConstructL() |
|
51 { |
|
52 FUNC_LOG; |
|
53 iIdle = CIdle::NewL( CActive::EPriorityIdle ); |
|
54 iIdleCallback = new (ELeave) TCallBack( IdleCallbackFunction, this ); |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CFsDelayedLoader::~CFsDelayedLoader |
|
59 // |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CFsDelayedLoader::~CFsDelayedLoader() |
|
63 { |
|
64 FUNC_LOG; |
|
65 iLoaders.Reset(); |
|
66 |
|
67 delete iContactHandler; |
|
68 |
|
69 delete iIdleCallback; |
|
70 if ( iIdle ) |
|
71 { |
|
72 iIdle->Cancel(); |
|
73 delete iIdle; |
|
74 } |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CFsDelayedLoader::CFsDelayedLoader |
|
79 // |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 CFsDelayedLoader::CFsDelayedLoader(): CCoeStatic( KDelayedLoaderUid ) |
|
83 { |
|
84 FUNC_LOG; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CFsDelayedLoader::Start |
|
89 // |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CFsDelayedLoader::Start() |
|
93 { |
|
94 FUNC_LOG; |
|
95 iLoaderIndex = 0; |
|
96 iIdle->Start( *iIdleCallback ); |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CFsDelayedLoader::GetPbkContactEngineL |
|
101 // |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 CFSEmailUiContactHandler* CFsDelayedLoader::GetContactHandlerL() |
|
105 { |
|
106 FUNC_LOG; |
|
107 |
|
108 if ( !iContactHandler ) |
|
109 { |
|
110 iContactHandler = CFSEmailUiContactHandler::NewL( CEikonEnv::Static()->FsSession() ); |
|
111 } |
|
112 |
|
113 return iContactHandler; |
|
114 } |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CFsDelayedLoader::IdleCallbackFunction |
|
117 // |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 TInt CFsDelayedLoader::IdleCallbackFunction( TAny* aParam ) |
|
121 { |
|
122 FUNC_LOG; |
|
123 // load own items |
|
124 CFsDelayedLoader* self = static_cast< CFsDelayedLoader* >( aParam ); |
|
125 TRAPD( error, self->GetContactHandlerL() ); |
|
126 if ( KErrNone != error ) |
|
127 { |
|
128 //Panic! |
|
129 } |
|
130 |
|
131 // if there are no loaders we can stop the callback |
|
132 if ( self->iLoaders.Count() <= 0 ) |
|
133 { |
|
134 return 0; |
|
135 } |
|
136 |
|
137 // handle loaders |
|
138 TInt r = self->iLoaders[self->iLoaderIndex]->DelayLoadCallback(); |
|
139 |
|
140 if ( r == 0 ) |
|
141 { |
|
142 self->iLoaderIndex++; |
|
143 if ( self->iLoaderIndex >= self->iLoaders.Count() ) |
|
144 { |
|
145 return 0; |
|
146 } |
|
147 } |
|
148 |
|
149 return 1; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CFsDelayedLoader::AppendLoader |
|
154 // |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CFsDelayedLoader::AppendLoader( MFsDelayedLoadingInterface& aLoader ) |
|
158 { |
|
159 FUNC_LOG; |
|
160 iLoaders.Append( &aLoader ); |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CFsDelayedLoader::RemoveLoader |
|
165 // |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CFsDelayedLoader::RemoveLoader( MFsDelayedLoadingInterface& aLoader ) |
|
169 { |
|
170 FUNC_LOG; |
|
171 for ( TInt i=0; i<iLoaders.Count(); i++ ) |
|
172 { |
|
173 if ( iLoaders[i] == &aLoader ) |
|
174 { |
|
175 iLoaders.Remove( i ); |
|
176 return; |
|
177 } |
|
178 } |
|
179 } |
|
180 |