author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:57:31 +0300 | |
branch | RCL_3 |
changeset 22 | f5c50b8af68c |
parent 21 | 65326cf895ed |
permissions | -rw-r--r-- |
21 | 1 |
/* |
2 |
* Copyright (c) 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: Memory state popup implementation |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
// SYSTEM INCLUDES |
|
20 |
#include <e32std.h> |
|
21 |
#include <AknProgressDialog.h> |
|
22 |
#include <aknlists.h> |
|
23 |
#include <ConeResLoader.h> |
|
24 |
#include <bautils.h> |
|
25 |
#include <StringLoader.h> |
|
26 |
#include <aknPopup.h> |
|
27 |
#include <memstatepopup.rsg> |
|
28 |
#include <f32file.h> |
|
29 |
#include <data_caging_path_literals.hrh> |
|
30 |
||
31 |
// USER INCLUDES |
|
32 |
#include "msputil.h" |
|
33 |
#include "cmemstatepopup.h" |
|
34 |
#include "cmemstatepopupimpl.h" |
|
35 |
#include "cmemscaneventreceiver.h" |
|
36 |
||
37 |
// CONSTANTS |
|
38 |
_LIT( KDirAndFile,"Z:MemStatePopup.RSC" ); |
|
39 |
_LIT( KMemListSeparator, "\t" ); |
|
40 |
||
41 |
// Max length of a list row |
|
42 |
// Has to be big enough to hold "%N %U" |
|
43 |
const TInt KListItemMaxLength = 32; |
|
44 |
||
45 |
// --------------------------------------------------------------------------- |
|
46 |
||
47 |
CMemStatePopupImpl::~CMemStatePopupImpl( ) |
|
48 |
{ |
|
49 |
Cancel(); |
|
50 |
// Close the resource |
|
51 |
iResLoader.Close( ); |
|
52 |
||
53 |
if( iWaitDialog ) |
|
54 |
{ |
|
55 |
iWaitDialog->SetObserver( NULL ); |
|
56 |
delete iWaitDialog; |
|
57 |
} |
|
58 |
||
59 |
delete iEventReceiver; // deletes also scan engine and server |
|
60 |
||
61 |
delete iGroupNames; |
|
62 |
delete iListModel; |
|
63 |
delete iListBox; |
|
64 |
delete iScanResults; |
|
65 |
||
66 |
||
67 |
if( iOwnsUtil ) |
|
68 |
{ |
|
69 |
// Delete only if the actual dialog was launched |
|
70 |
delete iUtil; |
|
71 |
} |
|
72 |
||
73 |
// Try to delete also iPopup in case of leave |
|
74 |
// Must call CBase's destructor |
|
75 |
// because CAknPopupList destructor is protected |
|
76 |
delete ( CBase* ) iPopup; |
|
77 |
} |
|
78 |
||
79 |
// --------------------------------------------------------------------------- |
|
80 |
||
81 |
CMemStatePopupImpl::CMemStatePopupImpl( TDriveNumber aDrive, const TDesC& aTitle ) : |
|
82 |
CActive(EPriorityStandard), |
|
83 |
iFinished( EFalse ), |
|
84 |
iDrive( aDrive ), |
|
85 |
iTitle( const_cast<TDesC*> (&aTitle) ), |
|
86 |
iCoeEnv( *CCoeEnv::Static( ) ), |
|
87 |
iResLoader( iCoeEnv ), |
|
88 |
iOwnsUtil( ETrue ) |
|
89 |
{ |
|
90 |
CActiveScheduler::Add(this); |
|
91 |
} |
|
92 |
||
93 |
// --------------------------------------------------------------------------- |
|
94 |
||
95 |
// Used by GetUtilL |
|
96 |
CMemStatePopupImpl::CMemStatePopupImpl( ) : |
|
97 |
CActive(EPriorityStandard), |
|
98 |
iFinished( EFalse ), |
|
99 |
iDrive( EDriveC ), |
|
100 |
iCoeEnv( *CCoeEnv::Static( ) ), |
|
101 |
iResLoader( iCoeEnv ), |
|
102 |
iOwnsUtil( EFalse ) |
|
103 |
{ |
|
104 |
} |
|
105 |
||
106 |
// --------------------------------------------------------------------------- |
|
107 |
||
108 |
void CMemStatePopupImpl::ConstructL( ) |
|
109 |
{ |
|
110 |
OpenResourceAndReadArrayL( ); |
|
111 |
||
112 |
// Instantiate event receiver, memory scan engine and server |
|
113 |
iEventReceiver = CMemScanEventReceiver::NewL( *this ); |
|
114 |
||
115 |
// Get data group names from engine |
|
116 |
iGroupNames = iEventReceiver->DataGroupsL( ); |
|
117 |
||
118 |
// Create popup |
|
119 |
ConstructPopupL( ); |
|
120 |
||
121 |
// Create wait dialog |
|
122 |
iWaitDialog = new( ELeave ) CAknWaitDialog( |
|
123 |
reinterpret_cast< CEikDialog** >( &iWaitDialog ) ); |
|
124 |
iWaitDialog->SetCallback( this ); |
|
125 |
iWaitDialog->PrepareLC( R_MEMSTATE_WAIT_NOTE ); |
|
126 |
||
127 |
StartObserver(); |
|
128 |
} |
|
129 |
||
130 |
// --------------------------------------------------------------------------- |
|
131 |
||
132 |
void CMemStatePopupImpl::RunLD( TDriveNumber aDrive, const TDesC& aTitle ) |
|
133 |
{ |
|
134 |
CMemStatePopupImpl* self = new( ELeave ) CMemStatePopupImpl( aDrive, aTitle ); |
|
135 |
CleanupStack::PushL( self ); |
|
136 |
self->ConstructL( ); |
|
137 |
||
138 |
// Run the actual process |
|
139 |
self->ExecuteL( ); |
|
140 |
||
141 |
CleanupStack::PopAndDestroy( self ); |
|
142 |
} |
|
143 |
||
144 |
||
145 |
// --------------------------------------------------------------------------- |
|
146 |
||
147 |
void CMemStatePopupImpl::GetUtilL( CMSPUtil*& aUtil ) |
|
148 |
{ |
|
149 |
CMemStatePopupImpl* self = new( ELeave ) CMemStatePopupImpl; |
|
150 |
CleanupStack::PushL( self ); |
|
151 |
||
152 |
// Read the unit array from resource |
|
153 |
self->OpenResourceAndReadArrayL( ); |
|
154 |
aUtil = self->iUtil; // iUtil is not deleted |
|
155 |
||
156 |
CleanupStack::PopAndDestroy( self ); |
|
157 |
} |
|
158 |
||
159 |
// --------------------------------------------------------------------------- |
|
160 |
||
161 |
void CMemStatePopupImpl::StartL( ) |
|
162 |
{ |
|
163 |
#ifdef _DEBUG |
|
164 |
RDebug::Print( _L( "Scanning started!" ) ); |
|
165 |
#endif |
|
166 |
} |
|
167 |
||
168 |
// --------------------------------------------------------------------------- |
|
169 |
||
170 |
void CMemStatePopupImpl::QuitL( TInt /*aReason*/ ) |
|
171 |
{ |
|
172 |
#ifdef _DEBUG |
|
173 |
RDebug::Print( _L( "Scanning ended!" ) ); |
|
174 |
#endif |
|
175 |
if( !iFinished ) |
|
176 |
{ |
|
177 |
// Tell waitdialog that it can quit now |
|
178 |
iWaitDialog->ProcessFinishedL( ); |
|
179 |
iFinished = ETrue; |
|
180 |
} |
|
181 |
} |
|
182 |
||
183 |
// --------------------------------------------------------------------------- |
|
184 |
||
185 |
void CMemStatePopupImpl::ErrorL( TInt aError ) |
|
186 |
{ |
|
187 |
#ifdef _DEBUG |
|
188 |
RDebug::Print( _L( "Error scanning memory: %d" ), aError ); |
|
189 |
#endif |
|
190 |
||
191 |
// getting rid of UREL compiler warning |
|
192 |
if( !aError ) |
|
193 |
{ |
|
194 |
aError = KErrNone; |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
// --------------------------------------------------------------------------- |
|
199 |
||
200 |
void CMemStatePopupImpl::DialogDismissedL( TInt aButtonId ) |
|
201 |
{ |
|
202 |
||
203 |
// Cancel is pressed while scanning is in progress |
|
204 |
if( iEventReceiver->ScanInProgress( ) ) |
|
205 |
{ |
|
206 |
iFinished = ETrue; |
|
207 |
iEventReceiver->Cancel( ); // Stop scanning |
|
208 |
} |
|
209 |
||
210 |
// Cancel is pressed while wait note is on screen (scanning may be completed) |
|
211 |
if( aButtonId == EAknSoftkeyCancel ) // instead of EAknSoftkeyDone |
|
212 |
{ |
|
213 |
iPopup->CancelPopup( ); // Remove memory state popup from screen |
|
214 |
return; |
|
215 |
} |
|
216 |
||
217 |
// Get the new result array |
|
218 |
delete iScanResults; |
|
219 |
iScanResults = NULL; |
|
220 |
TRAPD( err, iScanResults = iEventReceiver->ScanResultL( ) ); |
|
221 |
if( err != KErrNone ) |
|
222 |
{ |
|
223 |
iPopup->CancelPopup( ); // Remove memory state popup from screen |
|
224 |
return; |
|
225 |
} |
|
226 |
RefreshL( ); |
|
227 |
} |
|
228 |
||
229 |
// --------------------------------------------------------------------------- |
|
230 |
||
231 |
void CMemStatePopupImpl::ConstructPopupL( ) |
|
232 |
{ |
|
233 |
iListBox = new( ELeave ) CMemStateListBox( ); |
|
234 |
||
235 |
iPopup = CAknPopupList::NewL( iListBox, R_AVKON_SOFTKEYS_OK_EMPTY, |
|
236 |
AknPopupLayouts::EMenuGraphicHeadingWindow ); |
|
237 |
iPopup->SetTitleL( *iTitle ); |
|
238 |
||
239 |
// Set up listbox |
|
240 |
iListBox->ConstructL( iPopup, EAknListBoxViewerFlags ); |
|
241 |
||
242 |
// Create listbox model and give the model to the listbox |
|
243 |
iListModel = new( ELeave ) CDesCArraySeg( iGroupNames->Count( ) ); |
|
244 |
||
245 |
// Create scroll indicator |
|
246 |
iListBox->CreateScrollBarFrameL( ETrue ); |
|
247 |
iListBox->ScrollBarFrame( )->SetScrollBarVisibilityL( |
|
248 |
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
249 |
iListBox->Model( )->SetItemTextArray( iListModel ); |
|
250 |
iListBox->Model( )->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
251 |
iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue ); |
|
22
f5c50b8af68c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
252 |
iListBox->ItemDrawer()->ClearFlags( CListItemDrawer::ESingleClickDisabledHighlight ); |
21 | 253 |
} |
254 |
||
255 |
// --------------------------------------------------------------------------- |
|
256 |
||
257 |
void CMemStatePopupImpl::ExecuteL( ) |
|
258 |
{ |
|
259 |
// Show wait dialog |
|
260 |
iWaitDialog->RunLD( ); |
|
261 |
||
262 |
// Start the scanning |
|
263 |
User::LeaveIfError(iEventReceiver->ScanL( iDrive )); |
|
264 |
||
265 |
// Get the result array |
|
266 |
iScanResults = iEventReceiver->ScanResultL( ); |
|
267 |
||
268 |
// Set all results zero, so that no actual results are shown |
|
269 |
// before the scan is done. |
|
270 |
NullifyResults( ); |
|
271 |
||
272 |
// Update the list with initial values (0's) |
|
273 |
RefreshL( ); |
|
274 |
||
275 |
// Show popup |
|
276 |
iPopup->ExecuteLD( ); |
|
277 |
iPopup = NULL; // Has to be set NULL because deleted in destructor |
|
278 |
} |
|
279 |
||
280 |
// --------------------------------------------------------------------------- |
|
281 |
||
282 |
void CMemStatePopupImpl::RefreshL( ) |
|
283 |
{ |
|
284 |
//TBuf< KListItemMaxLength > result; |
|
285 |
TBuf< KListItemMaxLength > unitText; |
|
286 |
TBuf< KListItemMaxLength > tempText; |
|
287 |
TPtrC unit; |
|
288 |
TInt64 res64( 0 ); |
|
289 |
TInt count( iScanResults ? iScanResults->Count( ) : 0 ); |
|
290 |
TInt maxGroupName(0); |
|
291 |
||
292 |
for( TInt i = 0; i < iGroupNames->Count(); i++ ) |
|
293 |
{ |
|
294 |
if( maxGroupName < ( *iGroupNames )[ i ].Length() ) |
|
295 |
{ |
|
296 |
maxGroupName = ( *iGroupNames )[ i ].Length(); |
|
297 |
} |
|
298 |
} |
|
299 |
||
300 |
// Allocate memory for size, unit text and actual group name |
|
301 |
HBufC* result = HBufC::NewLC( maxGroupName + 2*KListItemMaxLength ); |
|
302 |
TPtr resultPtr( result->Des() ); |
|
303 |
HBufC* unitFormatter = StringLoader::LoadLC( R_UNIT_FORMATTER, &iCoeEnv ); |
|
304 |
||
305 |
iListModel->Reset( ); |
|
306 |
||
307 |
// Go through the result array and append to the model as text |
|
308 |
for( TInt i = 0; i < count; i++ ) |
|
309 |
{ |
|
310 |
res64 = ( *iScanResults )[ i ]; |
|
311 |
||
312 |
unit.Set( iUtil->SolveUnitAndSize( res64 ) ); |
|
313 |
StringLoader::Format( tempText, *unitFormatter, 0, I64INT( res64 ) ); |
|
314 |
StringLoader::Format( unitText, tempText, 1, unit ); |
|
315 |
resultPtr.Zero( ); |
|
316 |
||
317 |
// The actual listbox row is constructed here |
|
318 |
// iListModel is just an array of descriptors |
|
319 |
if ( User::Language() == ELangArabic ) |
|
320 |
{ |
|
321 |
resultPtr.Append( KRightToLeftMark ); |
|
322 |
} |
|
323 |
resultPtr.Append( unitText ); |
|
324 |
resultPtr.Append( KMemListSeparator ); |
|
325 |
if( i < iGroupNames->Count() ) |
|
326 |
{ |
|
327 |
resultPtr.Append( ( *iGroupNames )[ i ] ); |
|
328 |
} |
|
329 |
else |
|
330 |
{ |
|
331 |
resultPtr.Append( ( *iGroupNames )[ 0 ] ); |
|
332 |
} |
|
333 |
iListModel->AppendL( resultPtr ); |
|
334 |
} |
|
335 |
||
336 |
CleanupStack::PopAndDestroy( unitFormatter ); |
|
337 |
CleanupStack::PopAndDestroy( result ); |
|
338 |
||
339 |
// Update the listbox |
|
340 |
iListBox->HandleItemAdditionL( ); |
|
341 |
} |
|
342 |
||
343 |
// --------------------------------------------------------------------------- |
|
344 |
||
345 |
void CMemStatePopupImpl::NullifyResults( ) |
|
346 |
{ |
|
347 |
// Set all results to zero |
|
348 |
if( iScanResults ) |
|
349 |
{ |
|
350 |
TInt count( iScanResults->Count( ) ); |
|
351 |
for( TInt t = 0; t < count; t++ ) |
|
352 |
{ |
|
353 |
( *iScanResults )[ t ] = 0; |
|
354 |
} |
|
355 |
} |
|
356 |
} |
|
357 |
||
358 |
// --------------------------------------------------------------------------- |
|
359 |
||
360 |
void CMemStatePopupImpl::OpenResourceAndReadArrayL( ) |
|
361 |
{ |
|
362 |
// Open dll resource |
|
363 |
||
364 |
TParse* fp = new(ELeave) TParse(); |
|
365 |
fp->Set(KDirAndFile, &KDC_RESOURCE_FILES_DIR, NULL); |
|
366 |
TFileName fileName( fp->FullName() ); |
|
367 |
delete fp; |
|
368 |
||
369 |
BaflUtils::NearestLanguageFile( iCoeEnv.FsSession( ), |
|
370 |
fileName ); |
|
371 |
iResLoader.OpenL( fileName ); |
|
372 |
||
373 |
// Read localised unit texts from resource |
|
374 |
TResourceReader reader; |
|
375 |
iCoeEnv.CreateResourceReaderLC( reader, R_ARRAY_UNITS ); |
|
376 |
CDesCArrayFlat* units = reader.ReadDesCArrayL( ); |
|
377 |
CleanupStack::PushL( units ); |
|
378 |
iUtil = CMSPUtil::NewL( units ); // Give the array to the util class |
|
379 |
CleanupStack::Pop( units ); |
|
380 |
CleanupStack::PopAndDestroy(); // Private HBufC8* variable |
|
381 |
// of CreateResourceReaderLC() |
|
382 |
} |
|
383 |
||
384 |
// --------------------------------------------------------------------------- |
|
385 |
void CMemStatePopupImpl::RunL() |
|
386 |
{ |
|
387 |
TVolumeInfo volInfo; |
|
388 |
TInt err = iCoeEnv.FsSession().Volume( volInfo, iDrive ); |
|
389 |
if(err != KErrNone) |
|
390 |
{ |
|
391 |
iPopup->CancelPopup( ); |
|
392 |
} |
|
393 |
else |
|
394 |
{ |
|
395 |
StartObserver(); |
|
396 |
} |
|
397 |
} |
|
398 |
||
399 |
// --------------------------------------------------------------------------- |
|
400 |
void CMemStatePopupImpl::DoCancel() |
|
401 |
{ |
|
402 |
iCoeEnv.FsSession().NotifyChangeCancel(); |
|
403 |
} |
|
404 |
||
405 |
// --------------------------------------------------------------------------- |
|
406 |
void CMemStatePopupImpl::StartObserver() |
|
407 |
{ |
|
408 |
if ( IsActive() ) |
|
409 |
{ |
|
410 |
Cancel(); |
|
411 |
} |
|
412 |
iCoeEnv.FsSession().NotifyChange( ENotifyDisk, iStatus ); |
|
413 |
SetActive(); |
|
414 |
} |
|
415 |
||
416 |
// End of File |