|
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: Asynchronous refresher for refreshing the CGflmNavigatorModel |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CFileManagerRefresher.h" |
|
22 #include "MFileManagerProcessObserver.h" |
|
23 #include "CGflmNavigatorModel.h" |
|
24 #include "FileManagerDebug.h" |
|
25 #include <e32std.h> |
|
26 |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CFileManagerRefresher::CFileManagerRefresher |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CFileManagerRefresher::CFileManagerRefresher( CGflmNavigatorModel& aModel ) : |
|
37 CActive( CActive::EPriorityStandard ), |
|
38 iModel( aModel ) |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CFileManagerRefresher::ConstructL |
|
44 // Symbian 2nd phase constructor can leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CFileManagerRefresher::ConstructL() |
|
48 { |
|
49 CActiveScheduler::Add( this ); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CFileManagerRefresher::NewL |
|
54 // Two-phased constructor. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CFileManagerRefresher* CFileManagerRefresher::NewL( CGflmNavigatorModel& aModel ) |
|
58 { |
|
59 CFileManagerRefresher* self = |
|
60 new( ELeave ) CFileManagerRefresher( aModel ); |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL(); |
|
63 CleanupStack::Pop( self ); |
|
64 |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CFileManagerRefresher::~CFileManagerRefresher() |
|
70 // |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CFileManagerRefresher::~CFileManagerRefresher() |
|
74 { |
|
75 Cancel(); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CFileManagerRefresher::RunL |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void CFileManagerRefresher::RunL() |
|
83 { |
|
84 FUNC_LOG |
|
85 |
|
86 TInt err( iStatus.Int() ); |
|
87 |
|
88 LOG_IF_ERROR1( err, "CFileManagerRefresher::RunL()-err=%d", err ) |
|
89 |
|
90 if( iObserver ) |
|
91 { |
|
92 iObserver->RefreshStoppedL(); |
|
93 if ( err == KErrCancel ) |
|
94 { |
|
95 // For going back to parent folder |
|
96 iObserver->Error( KErrPathNotFound ); |
|
97 } |
|
98 } |
|
99 |
|
100 // Forward OOM, suppress other errors |
|
101 if ( err == KErrNoMemory ) |
|
102 { |
|
103 User::Leave( err ); |
|
104 } |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CFileManagerRefresher::RunError |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 TInt CFileManagerRefresher::RunError( TInt aError ) |
|
112 { |
|
113 ERROR_LOG1( "CFileManagerRefresher::RunError()-err=%d", aError ) |
|
114 return aError; |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CFileManagerRefresher::DoCancel |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void CFileManagerRefresher::DoCancel() |
|
122 { |
|
123 FUNC_LOG |
|
124 |
|
125 iModel.CancelRefresh(); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CFileManagerRefresher::Refresh |
|
130 // Initiates the model refreshing |
|
131 // (other items were commented in a header). |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CFileManagerRefresher::Refresh( TGflmRefreshMode aRefreshMode ) |
|
135 { |
|
136 FUNC_LOG |
|
137 |
|
138 // If already active, return |
|
139 if( IsActive() ) |
|
140 { |
|
141 ERROR_LOG( "CFileManagerRefresher::Refresh()-Already active" ) |
|
142 return; |
|
143 } |
|
144 |
|
145 TInt err( KErrNone ); |
|
146 if ( iObserver ) |
|
147 { |
|
148 TRAP( err, iObserver->RefreshStartedL() ); |
|
149 } |
|
150 |
|
151 if ( err ) |
|
152 { |
|
153 ERROR_LOG1( "CFileManagerRefresher::Refresh()-Before err=%d", err ) |
|
154 return; |
|
155 } |
|
156 |
|
157 // Try to start the refresh operation |
|
158 TRAP( err, iModel.RefreshListL( iStatus, aRefreshMode ) ); |
|
159 |
|
160 // If refreshing couldn't be started, notify observer and return |
|
161 if ( err ) |
|
162 { |
|
163 ERROR_LOG1( "CFileManagerRefresher::Refresh()-After err=%d", err ) |
|
164 if( iObserver ) |
|
165 { |
|
166 TRAP_IGNORE( iObserver->RefreshStoppedL() ); |
|
167 } |
|
168 return; |
|
169 } |
|
170 |
|
171 // Refreshing was started, set active and wait for asynchronous |
|
172 // request to complete |
|
173 SetActive(); |
|
174 } |
|
175 |
|
176 // ------------------------------------------------------------------------------ |
|
177 // CFileManagerRefresher::SetObserver |
|
178 // ------------------------------------------------------------------------------ |
|
179 // |
|
180 void CFileManagerRefresher::SetObserver( MFileManagerProcessObserver* aObserver ) |
|
181 { |
|
182 // Set the observer if not active |
|
183 if( !IsActive() ) |
|
184 { |
|
185 iObserver = aObserver; |
|
186 } |
|
187 } |
|
188 |
|
189 // ------------------------------------------------------------------------------ |
|
190 // CFileManagerRefresher::CancelRefresh |
|
191 // ------------------------------------------------------------------------------ |
|
192 // |
|
193 TBool CFileManagerRefresher::CancelRefresh() |
|
194 { |
|
195 FUNC_LOG |
|
196 |
|
197 TBool ret( IsActive() ); |
|
198 Cancel(); |
|
199 return ret; |
|
200 } |
|
201 |
|
202 // End of File |