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: Handler for scheduled backup
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#define FILE_MANAGER_POWER_SAVING_MODE
|
|
20 |
|
|
21 |
// INCLUDE FILES
|
|
22 |
#include <StringLoader.h>
|
|
23 |
#include <centralrepository.h>
|
|
24 |
#include <avkon.hrh>
|
|
25 |
#include <avkon.rsg>
|
|
26 |
#include <filemanager.rsg>
|
|
27 |
#include <FileManagerDebug.h>
|
|
28 |
#include <FileManagerPrivateCRKeys.h>
|
|
29 |
#include <CFileManagerEngine.h>
|
|
30 |
#include <CFileManagerBackupSettings.h>
|
|
31 |
#include <MFileManagerProcessObserver.h>
|
|
32 |
#include <CFileManagerGlobalDlg.h>
|
|
33 |
#ifdef FILE_MANAGER_POWER_SAVING_MODE
|
|
34 |
#include <psmsrvdomaincrkeys.h>
|
|
35 |
#endif // FILE_MANAGER_POWER_SAVING_MODE
|
|
36 |
#include "CFileManagerSchBackupHandler.h"
|
|
37 |
#include "MFileManagerSchBackupObserver.h"
|
|
38 |
|
|
39 |
|
|
40 |
// ======== MEMBER FUNCTIONS ========
|
|
41 |
|
|
42 |
// ----------------------------------------------------------------------------
|
|
43 |
// CFileManagerSchBackupHandler::CFileManagerSchBackupHandler
|
|
44 |
// ----------------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
CFileManagerSchBackupHandler::CFileManagerSchBackupHandler(
|
|
47 |
CFileManagerEngine& aEngine ) :
|
|
48 |
iEngine( aEngine )
|
|
49 |
{
|
|
50 |
}
|
|
51 |
|
|
52 |
// ----------------------------------------------------------------------------
|
|
53 |
// CFileManagerSchBackupHandler::NewL
|
|
54 |
// ----------------------------------------------------------------------------
|
|
55 |
//
|
|
56 |
CFileManagerSchBackupHandler* CFileManagerSchBackupHandler::NewL(
|
|
57 |
CFileManagerEngine& aEngine )
|
|
58 |
{
|
|
59 |
CFileManagerSchBackupHandler* self =
|
|
60 |
new( ELeave ) CFileManagerSchBackupHandler( aEngine );
|
|
61 |
CleanupStack::PushL( self );
|
|
62 |
self->ConstructL();
|
|
63 |
CleanupStack::Pop( self );
|
|
64 |
return self;
|
|
65 |
}
|
|
66 |
|
|
67 |
// ----------------------------------------------------------------------------
|
|
68 |
// CFileManagerSchBackupHandler::ConstructL
|
|
69 |
// ----------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
void CFileManagerSchBackupHandler::ConstructL()
|
|
72 |
{
|
|
73 |
FUNC_LOG
|
|
74 |
|
|
75 |
iGlobalDlg = CFileManagerGlobalDlg::NewL();
|
|
76 |
iGlobalDlg->SetObserver( this );
|
|
77 |
|
|
78 |
iCenRep = CRepository::NewL( KCRUidFileManagerSettings );
|
|
79 |
}
|
|
80 |
|
|
81 |
// ----------------------------------------------------------------------------
|
|
82 |
// CFileManagerSchBackupHandler::~CFileManagerSchBackupHandler
|
|
83 |
// ----------------------------------------------------------------------------
|
|
84 |
//
|
|
85 |
CFileManagerSchBackupHandler::~CFileManagerSchBackupHandler()
|
|
86 |
{
|
|
87 |
FUNC_LOG
|
|
88 |
|
|
89 |
delete iGlobalDlg;
|
|
90 |
delete iCenRep;
|
|
91 |
}
|
|
92 |
|
|
93 |
// ----------------------------------------------------------------------------
|
|
94 |
// CFileManagerSchBackupHandler::HandleGlobalDlgResult
|
|
95 |
// ----------------------------------------------------------------------------
|
|
96 |
//
|
|
97 |
void CFileManagerSchBackupHandler::HandleGlobalDlgResult(
|
|
98 |
TInt aDlgType,
|
|
99 |
TInt aDlgResult )
|
|
100 |
{
|
|
101 |
INFO_LOG2(
|
|
102 |
"CFileManagerSchBackupHandler::HandleGlobalDlgResult-aDlgType=%d,aDlgResult=%d",
|
|
103 |
aDlgType, aDlgResult )
|
|
104 |
TInt err( KErrNone );
|
|
105 |
switch ( aDlgType )
|
|
106 |
{
|
|
107 |
case CFileManagerGlobalDlg::ECountdownQuery:
|
|
108 |
{
|
|
109 |
if ( aDlgResult == EAknSoftkeyYes )
|
|
110 |
{
|
|
111 |
// Backup was accepted
|
|
112 |
StartBackup();
|
|
113 |
|
|
114 |
err = iCenRep->Set(
|
|
115 |
KFileManagerLastSchBackupStatus,
|
|
116 |
EFileManagerSchBackupStatusInProgress );
|
|
117 |
}
|
|
118 |
else
|
|
119 |
{
|
|
120 |
// Backup was rejected
|
|
121 |
InformObserver( KErrCancel );
|
|
122 |
CancelBackupStarter();
|
|
123 |
}
|
|
124 |
break;
|
|
125 |
}
|
|
126 |
case CFileManagerGlobalDlg::EProgressDialog:
|
|
127 |
{
|
|
128 |
// Backup was canceled
|
|
129 |
iEngine.CancelProcess(
|
|
130 |
MFileManagerProcessObserver::ESchBackupProcess );
|
|
131 |
InformObserver( KErrCancel );
|
|
132 |
CancelBackupStarter();
|
|
133 |
break;
|
|
134 |
}
|
|
135 |
default:
|
|
136 |
{
|
|
137 |
InformObserver( aDlgResult );
|
|
138 |
break;
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
LOG_IF_ERROR1( err,
|
|
143 |
"CFileManagerSchBackupHandler::HandleGlobalDlgResult-err=%d", err )
|
|
144 |
|
|
145 |
}
|
|
146 |
|
|
147 |
// ----------------------------------------------------------------------------
|
|
148 |
// CFileManagerSchBackupHandler::StartBackupWithConfirmL
|
|
149 |
// ----------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
void CFileManagerSchBackupHandler::StartBackupWithConfirmL()
|
|
152 |
{
|
|
153 |
TBool psmOn( EFalse );
|
|
154 |
TRAPD( err, psmOn = IsPowerSavingModeOnL() );
|
|
155 |
if ( psmOn && err == KErrNone )
|
|
156 |
{
|
|
157 |
iGlobalDlg->ShowDialogL(
|
|
158 |
CFileManagerGlobalDlg::EQueryWithInfoIcon,
|
|
159 |
R_QTN_FMGR_SCHEDULED_BACKUP_CANCELLED_PS,
|
|
160 |
R_AVKON_SOFTKEYS_OK_EMPTY );
|
|
161 |
CancelBackupStarter();
|
|
162 |
return;
|
|
163 |
}
|
|
164 |
|
|
165 |
// Show cancelable global confirm countdown before starting backup.
|
|
166 |
// Backup is started only if accepted or countdown has expired.
|
|
167 |
iGlobalDlg->ShowDialogL(
|
|
168 |
CFileManagerGlobalDlg::ECountdownQuery,
|
|
169 |
R_QTN_FMGR_SCHEDULED_BACKUP_QUERY );
|
|
170 |
}
|
|
171 |
|
|
172 |
// ----------------------------------------------------------------------------
|
|
173 |
// CFileManagerSchBackupHandler::StartBackupL
|
|
174 |
// ----------------------------------------------------------------------------
|
|
175 |
//
|
|
176 |
void CFileManagerSchBackupHandler::StartBackupL()
|
|
177 |
{
|
|
178 |
CFileManagerBackupSettings& settings( iEngine.BackupSettingsL() );
|
|
179 |
TFileManagerDriveInfo drvInfo;
|
|
180 |
iEngine.GetDriveInfoL( settings.TargetDrive(), drvInfo );
|
|
181 |
TBool drvAvailable( EFalse );
|
|
182 |
|
|
183 |
if( !IsTargetDriveAvailableL(drvInfo ) )
|
|
184 |
{
|
|
185 |
for( TInt i ( EDriveA ); i <= EDriveZ; i++ )
|
|
186 |
{
|
|
187 |
iEngine.GetDriveInfoL( i , drvInfo );
|
|
188 |
if( ( IsTargetDriveAvailableL( drvInfo ) ) && ( drvInfo.iState & TFileManagerDriveInfo::EDriveEjectable ) )
|
|
189 |
{
|
|
190 |
settings.SetTargetDrive( i );
|
|
191 |
settings.SaveL();
|
|
192 |
drvAvailable = ETrue;
|
|
193 |
break;
|
|
194 |
}
|
|
195 |
}
|
|
196 |
}
|
|
197 |
else
|
|
198 |
{
|
|
199 |
drvAvailable = ETrue;
|
|
200 |
}
|
|
201 |
if ( !drvAvailable )
|
|
202 |
{
|
|
203 |
iGlobalDlg->ShowDialogL(
|
|
204 |
CFileManagerGlobalDlg::EQueryWithWarningIcon,
|
|
205 |
R_QTN_FMGR_SCHEDULED_BACKUP_ERROR,
|
|
206 |
R_AVKON_SOFTKEYS_OK_EMPTY );
|
|
207 |
CancelBackupStarter();
|
|
208 |
return;
|
|
209 |
}
|
|
210 |
|
|
211 |
HBufC* text = StringLoader::LoadLC(
|
|
212 |
R_QTN_FMGR_SCHEDULED_BACKUP_PROGRESS,
|
|
213 |
iEngine.DriveName( settings.TargetDrive() ) );
|
|
214 |
|
|
215 |
iGlobalDlg->ShowDialogL(
|
|
216 |
CFileManagerGlobalDlg::EProgressDialog,
|
|
217 |
*text );
|
|
218 |
|
|
219 |
CleanupStack::PopAndDestroy( text );
|
|
220 |
|
|
221 |
iEngine.StartBackupProcessL(
|
|
222 |
MFileManagerProcessObserver::ESchBackupProcess );
|
|
223 |
}
|
|
224 |
|
|
225 |
// ----------------------------------------------------------------------------
|
|
226 |
// CFileManagerSchBackupHandler::SetObserver
|
|
227 |
// ----------------------------------------------------------------------------
|
|
228 |
//
|
|
229 |
void CFileManagerSchBackupHandler::SetObserver(
|
|
230 |
MFileManagerSchBackupObserver* aObserver )
|
|
231 |
{
|
|
232 |
iObserver = aObserver;
|
|
233 |
}
|
|
234 |
|
|
235 |
// ----------------------------------------------------------------------------
|
|
236 |
// CFileManagerSchBackupHandler::StartBackupWithConfirm
|
|
237 |
// ----------------------------------------------------------------------------
|
|
238 |
//
|
|
239 |
void CFileManagerSchBackupHandler::StartBackupWithConfirm()
|
|
240 |
{
|
|
241 |
FUNC_LOG
|
|
242 |
|
|
243 |
if ( iBackupOngoing )
|
|
244 |
{
|
|
245 |
return;
|
|
246 |
}
|
|
247 |
|
|
248 |
iBackupOngoing = ETrue;
|
|
249 |
|
|
250 |
TRAPD( err, StartBackupWithConfirmL() );
|
|
251 |
if ( err != KErrNone )
|
|
252 |
{
|
|
253 |
InformObserver( err );
|
|
254 |
}
|
|
255 |
else
|
|
256 |
{
|
|
257 |
// Confirm scheduled backup start state
|
|
258 |
TInt err( iCenRep->Set(
|
|
259 |
KFileManagerLastSchBackupStatus,
|
|
260 |
EFileManagerSchBackupStatusInProgress ) );
|
|
261 |
|
|
262 |
LOG_IF_ERROR1( err,
|
|
263 |
"CFileManagerSchBackupHandler::StartBackupWithConfirm-err=%d", err )
|
|
264 |
|
|
265 |
}
|
|
266 |
}
|
|
267 |
|
|
268 |
// ----------------------------------------------------------------------------
|
|
269 |
// CFileManagerSchBackupHandler::StartBackup
|
|
270 |
// ----------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
void CFileManagerSchBackupHandler::StartBackup()
|
|
273 |
{
|
|
274 |
FUNC_LOG
|
|
275 |
|
|
276 |
TRAPD( err, StartBackupL() );
|
|
277 |
if ( err != KErrNone )
|
|
278 |
{
|
|
279 |
InformObserver( err );
|
|
280 |
}
|
|
281 |
}
|
|
282 |
|
|
283 |
// ----------------------------------------------------------------------------
|
|
284 |
// CFileManagerSchBackupHandler::InformObserver
|
|
285 |
// ----------------------------------------------------------------------------
|
|
286 |
//
|
|
287 |
void CFileManagerSchBackupHandler::InformObserver( const TInt aValue )
|
|
288 |
{
|
|
289 |
INFO_LOG1( "CFileManagerSchBackupHandler::InformObserver-aValue=%d", aValue )
|
|
290 |
|
|
291 |
iBackupOngoing = EFalse;
|
|
292 |
if ( iObserver )
|
|
293 |
{
|
|
294 |
TRAP_IGNORE( iObserver->SchBackupFinishedL( aValue ) );
|
|
295 |
}
|
|
296 |
}
|
|
297 |
|
|
298 |
// ----------------------------------------------------------------------------
|
|
299 |
// CFileManagerSchBackupHandler::ProcessFinishedL
|
|
300 |
// ----------------------------------------------------------------------------
|
|
301 |
//
|
|
302 |
void CFileManagerSchBackupHandler::ProcessFinishedL(
|
|
303 |
TInt aError, const TDesC& /*aName*/ )
|
|
304 |
{
|
|
305 |
INFO_LOG1( "CFileManagerSchBackupHandler::ProcessFinishedL-aError=%d",
|
|
306 |
aError )
|
|
307 |
|
|
308 |
iGlobalDlg->CancelDialog();
|
|
309 |
TInt err( KErrNone );
|
|
310 |
if ( aError == KErrCancel )
|
|
311 |
{
|
|
312 |
CancelBackupStarter();
|
|
313 |
}
|
|
314 |
else if ( aError != KErrNone )
|
|
315 |
{
|
|
316 |
iGlobalDlg->ShowDialogL(
|
|
317 |
CFileManagerGlobalDlg::EErrorNote,
|
|
318 |
R_QTN_CRITICAL_ERROR );
|
|
319 |
|
|
320 |
err = iCenRep->Set(
|
|
321 |
KFileManagerLastSchBackupStatus,
|
|
322 |
EFileManagerSchBackupStatusFailed );
|
|
323 |
}
|
|
324 |
else
|
|
325 |
{
|
|
326 |
iGlobalDlg->ShowDialogL(
|
|
327 |
CFileManagerGlobalDlg::EInfoNote,
|
|
328 |
R_QTN_BACKUP_COMPLETED );
|
|
329 |
|
|
330 |
err = iCenRep->Set(
|
|
331 |
KFileManagerLastSchBackupStatus,
|
|
332 |
EFileManagerSchBackupStatusOk );
|
|
333 |
}
|
|
334 |
|
|
335 |
LOG_IF_ERROR1( err,
|
|
336 |
"CFileManagerSchBackupHandler::ProcessFinishedL-err=%d", err )
|
|
337 |
|
|
338 |
InformObserver( aError );
|
|
339 |
|
|
340 |
}
|
|
341 |
|
|
342 |
// ----------------------------------------------------------------------------
|
|
343 |
// CFileManagerSchBackupHandler::ProcessAdvanceL
|
|
344 |
// ----------------------------------------------------------------------------
|
|
345 |
//
|
|
346 |
void CFileManagerSchBackupHandler::ProcessAdvanceL( TInt aValue )
|
|
347 |
{
|
|
348 |
iGlobalDlg->UpdateProgressDialog( aValue );
|
|
349 |
}
|
|
350 |
|
|
351 |
// ----------------------------------------------------------------------------
|
|
352 |
// CFileManagerSchBackupHandler::ProcessStartedL
|
|
353 |
// ----------------------------------------------------------------------------
|
|
354 |
//
|
|
355 |
void CFileManagerSchBackupHandler::ProcessStartedL( TInt aFinalValue )
|
|
356 |
{
|
|
357 |
FUNC_LOG
|
|
358 |
|
|
359 |
iGlobalDlg->UpdateProgressDialog( 0, aFinalValue );
|
|
360 |
}
|
|
361 |
|
|
362 |
// ----------------------------------------------------------------------------
|
|
363 |
// CFileManagerSchBackupHandler::CancelBackupStarter
|
|
364 |
// ----------------------------------------------------------------------------
|
|
365 |
//
|
|
366 |
void CFileManagerSchBackupHandler::CancelBackupStarter()
|
|
367 |
{
|
|
368 |
TInt err( iCenRep->Set(
|
|
369 |
KFileManagerLastSchBackupStatus,
|
|
370 |
EFileManagerSchBackupStatusCanceled ) );
|
|
371 |
LOG_IF_ERROR1( err,
|
|
372 |
"CFileManagerSchBackupHandler::CancelBackupStarter-err=%d", err )
|
|
373 |
}
|
|
374 |
|
|
375 |
// ----------------------------------------------------------------------------
|
|
376 |
// CFileManagerSchBackupHandler::IsPowerSavingModeOnL
|
|
377 |
// ----------------------------------------------------------------------------
|
|
378 |
//
|
|
379 |
TBool CFileManagerSchBackupHandler::IsPowerSavingModeOnL()
|
|
380 |
{
|
|
381 |
TBool ret( EFalse );
|
|
382 |
#ifdef FILE_MANAGER_POWER_SAVING_MODE
|
|
383 |
// Check power saving mode before start
|
|
384 |
CRepository* psmCenRep = CRepository::NewLC( KCRUidPowerSaveMode );
|
|
385 |
TInt psmMode( 0 );
|
|
386 |
User::LeaveIfError( psmCenRep->Get( KPsmCurrentMode, psmMode ) );
|
|
387 |
if ( psmMode )
|
|
388 |
{
|
|
389 |
ERROR_LOG1(
|
|
390 |
"CFileManagerSchBackupHandler::IsPowerSavingModeOnL-PsmMode=%d",
|
|
391 |
psmMode )
|
|
392 |
ret = ETrue;
|
|
393 |
}
|
|
394 |
CleanupStack::PopAndDestroy( psmCenRep );
|
|
395 |
#endif // FILE_MANAGER_POWER_SAVING_MODE
|
|
396 |
return ret;
|
|
397 |
}
|
|
398 |
|
|
399 |
// ----------------------------------------------------------------------------
|
|
400 |
// CFileManagerSchBackupHandler::IsTargetDriveAvailableL
|
|
401 |
// ----------------------------------------------------------------------------
|
|
402 |
//
|
|
403 |
TBool CFileManagerSchBackupHandler::IsTargetDriveAvailableL( const TFileManagerDriveInfo& aDrvInfo )
|
|
404 |
{
|
|
405 |
// Start backup with cancelable global progress dialog
|
|
406 |
|
|
407 |
// Check is target drive available
|
|
408 |
TBool ret( ETrue );
|
|
409 |
if ( !( aDrvInfo.iState & TFileManagerDriveInfo::EDrivePresent ) ||
|
|
410 |
( aDrvInfo.iState &
|
|
411 |
( TFileManagerDriveInfo::EDriveLocked |
|
|
412 |
TFileManagerDriveInfo::EDriveCorrupted |
|
|
413 |
TFileManagerDriveInfo::EDriveWriteProtected ) ) )
|
|
414 |
{
|
|
415 |
ERROR_LOG1(
|
|
416 |
"CFileManagerSchBackupHandler::IsTargetDriveAvailableL-DrvState=%d",
|
|
417 |
aDrvInfo.iState )
|
|
418 |
ret = EFalse;
|
|
419 |
}
|
|
420 |
return ret;
|
|
421 |
}
|
|
422 |
|
|
423 |
// End of File
|