filemanager/src/filemanager/src/backuprestore/fmbackuprestorehandler.cpp
branchRCL_3
changeset 21 65326cf895ed
parent 20 491b3ed49290
child 22 f5c50b8af68c
equal deleted inserted replaced
20:491b3ed49290 21:65326cf895ed
     1 /*
       
     2  * Copyright (c) 2009 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  * 
       
    15  * Description:
       
    16  *     The source file of backup and restore handler of file manager
       
    17  */
       
    18 
       
    19 #include "fmbackuprestorehandler.h"
       
    20 #include "fmbackupsettings.h"
       
    21 #include "fmrestoresettings.h"
       
    22 #include "fmoperationservice.h"
       
    23 #include "fmbackupconfigloader.h"
       
    24 #include "fmbkupengine.h"
       
    25 #include "fmoperationbase.h"
       
    26 #include "fmcommon.h"
       
    27 #include "fmdlgutils.h"
       
    28 
       
    29 FmBackupRestoreHandler::FmBackupRestoreHandler( QObject *parent ) : QObject( parent ), mBackupConfigLoader( 0 )
       
    30 {
       
    31     mBkupEngine = new FmBkupEngine( this );
       
    32 
       
    33     mCurrentProcess = ProcessNone;
       
    34 
       
    35     connect( mBkupEngine, SIGNAL( notifyPreparing( bool ) ), this, SLOT( onNotifyPreparing( bool ) ), Qt::QueuedConnection );
       
    36     connect( mBkupEngine, SIGNAL( notifyStart( bool, int) ), this, SLOT( onNotifyStart( bool, int ) ), Qt::QueuedConnection );
       
    37     connect( mBkupEngine, SIGNAL( notifyUpdate(int) ), this, SLOT( onNotifyUpdate(int) ), Qt::QueuedConnection );
       
    38     connect( mBkupEngine, SIGNAL( notifyFinish(int) ), 
       
    39         this, SLOT( onNotifyFinish(int) ), Qt::DirectConnection );
       
    40     connect( mBkupEngine, SIGNAL( notifyMemoryLow(int, int& ) ), 
       
    41         this, SLOT( onNotifyMemoryLow(int, int&) ) );
       
    42     connect( mBkupEngine, SIGNAL( notifyBackupFilesExist( bool& )), this, SLOT( onNotifyBackupFilesExist( bool& )));
       
    43     
       
    44 }
       
    45 FmBackupRestoreHandler::~FmBackupRestoreHandler()
       
    46 {
       
    47     delete mBkupEngine;
       
    48     delete mBackupConfigLoader;
       
    49 }
       
    50 
       
    51 FmBkupEngine *FmBackupRestoreHandler::bkupEngine()
       
    52 {
       
    53     return mBkupEngine;
       
    54 }
       
    55 
       
    56 FmBackupConfigLoader *FmBackupRestoreHandler::backupConfigLoader()
       
    57 {
       
    58     if( !mBackupConfigLoader ) {
       
    59         mBackupConfigLoader = new FmBackupConfigLoader();
       
    60     }
       
    61     return mBackupConfigLoader;
       
    62 }
       
    63 
       
    64 int FmBackupRestoreHandler::error()
       
    65 {
       
    66     return mBkupEngine->error();
       
    67 }
       
    68 
       
    69 bool FmBackupRestoreHandler::startBackup( FmOperationBackup *operationBackup )
       
    70 {
       
    71     Q_UNUSED( operationBackup );
       
    72     mCurrentProcess = ProcessBackup;
       
    73     bool ret = mBkupEngine->startBackup( backupConfigLoader()->driversAndOperationList(),
       
    74         backupConfigLoader()->backupCategoryList(), 
       
    75         operationBackup->targetDrive(), // targetDrive is stored in FmOperationBackup
       
    76         operationBackup->content() );   // content     is stored in FmOperationBackup
       
    77 
       
    78     if( !ret ) {
       
    79         mCurrentProcess = ProcessNone;
       
    80         }
       
    81     return ret;
       
    82 }
       
    83 void FmBackupRestoreHandler::cancelBackup()
       
    84 {
       
    85     mBkupEngine->cancelBackup();
       
    86 }
       
    87 bool FmBackupRestoreHandler::startRestore( FmOperationRestore *operationRestore )
       
    88 {
       
    89     mCurrentProcess = ProcessRestore;
       
    90     mBkupEngine->RestoreSettingsL()->SetSelection( operationRestore->selection() );
       
    91     bool ret = mBkupEngine->startRestore( backupConfigLoader()->driversAndOperationList() );
       
    92     if( !ret ) {
       
    93         mCurrentProcess = ProcessNone;
       
    94         }
       
    95     return ret;
       
    96 }
       
    97 
       
    98 int FmBackupRestoreHandler::deleteBackup( quint64 selection )
       
    99 {
       
   100     mBkupEngine->RestoreSettingsL()->SetSelection( selection );
       
   101     mBkupEngine->deleteBackup( backupConfigLoader()->driversAndOperationList() );
       
   102     return FmErrNone;
       
   103 }
       
   104 
       
   105 void FmBackupRestoreHandler::onNotifyMemoryLow( int memoryValue, int &userError )
       
   106 {
       
   107     userError = FmErrNone;
       
   108     if( memoryValue < FmEstimateLowerLimit ) {
       
   109         userError = FmErrDiskFull;
       
   110     } else if( memoryValue < FmEstimateUpperLimit ) {
       
   111         if ( !FmDlgUtils::question( "memory low, continue?" ) ){
       
   112             userError = FmErrCancel;
       
   113         }
       
   114     }
       
   115 }
       
   116 void FmBackupRestoreHandler::onNotifyBackupFilesExist( bool &isContinue )
       
   117     {
       
   118     if ( FmDlgUtils::question( "some backup files exist, continue?" ) )
       
   119         {
       
   120         isContinue = true;
       
   121         }
       
   122     else
       
   123         {
       
   124         isContinue = false;
       
   125         }
       
   126     }
       
   127 
       
   128 
       
   129 void FmBackupRestoreHandler::onNotifyPreparing( bool cancelable )
       
   130 {
       
   131     emit notifyPreparing(  cancelable );
       
   132 }
       
   133 void FmBackupRestoreHandler::onNotifyStart( bool cancelable, int maxSteps )
       
   134 {
       
   135     emit notifyStart( cancelable, maxSteps );
       
   136 }
       
   137 void FmBackupRestoreHandler::onNotifyUpdate( int currentStep )
       
   138 {
       
   139     emit notifyProgress( currentStep );
       
   140 }
       
   141 void FmBackupRestoreHandler::onNotifyFinish( int err )
       
   142 {
       
   143     if( err == FmErrNone ) {
       
   144         emit notifyFinish();
       
   145     } else if( err == FmErrCancel ){
       
   146         emit notifyCanceled();
       
   147     } else {
       
   148         emit notifyError( err, QString("") );
       
   149     }
       
   150 }
       
   151 
       
   152 void FmBackupRestoreHandler::getBackupDriveList( QStringList &driveList )
       
   153 {
       
   154     mBkupEngine->getBackupDriveList( driveList );
       
   155 }