homescreenapp/hsdomainmodel/src/hsbackuprestoreobserver.cpp
changeset 51 4785f57bf3d4
child 55 03646e8da489
equal deleted inserted replaced
46:23b5d6a29cce 51:4785f57bf3d4
       
     1 /*
       
     2 * Copyright (c) 2010 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:  Home screen Backup/Restore observer.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "hsdatabase.h"
       
    20 #include "hsbackuprestoreobserver.h"
       
    21 #ifdef Q_OS_SYMBIAN
       
    22 #include <connect/sbdefs.h>
       
    23 #include <e32property.h>
       
    24 #include <XQSettingsManager>
       
    25 #include "hsbackuprestoreactivecallback.h"
       
    26 #include "hsbackuprestoreobserver_p.h"
       
    27 
       
    28 /*!
       
    29     Constructs a new observer with the given \a parent object.
       
    30 */
       
    31 HsBackupRestoreObserverPrivate::HsBackupRestoreObserverPrivate(HsBackupRestoreObserver *observer,
       
    32                                                                QObject *parent):
       
    33     QObject(parent),
       
    34     mQ(observer),
       
    35     mCallBack(NULL),
       
    36     mActiveBackupClient(NULL),
       
    37     mLastType(conn::EBURNormal)
       
    38 {
       
    39     XQPublishAndSubscribeSettingsKey backupRestoreKey(KUidSystemCategory.iUid, KUidBackupRestoreKey);
       
    40     XQSettingsManager *sm = new XQSettingsManager(this);
       
    41     
       
    42     connect(sm,SIGNAL(valueChanged(XQSettingsKey, const QVariant &)), this,
       
    43 			          SLOT(handleKeyChange(XQSettingsKey, const QVariant &)));
       
    44     sm->startMonitoring(backupRestoreKey);
       
    45 }
       
    46 
       
    47 /*!
       
    48     Destructor.
       
    49 */
       
    50 HsBackupRestoreObserverPrivate::~HsBackupRestoreObserverPrivate()
       
    51 {   
       
    52     disconnect(sender(), SIGNAL(valueChanged(XQSettingsKey, const QVariant &)),
       
    53 			   this, SLOT(handleKeyChange(XQSettingsKey, const QVariant&)));
       
    54     delete mCallBack;
       
    55     delete mActiveBackupClient;
       
    56 }
       
    57 
       
    58 /*!
       
    59     Informs active backup client, when Home screen is ready for backup/restore.
       
    60 */
       
    61 void HsBackupRestoreObserverPrivate::readyForBUR()
       
    62 {
       
    63 	mActiveBackupClient->ConfirmReadyForBURL( KErrNone );
       
    64 }
       
    65 
       
    66 /*!
       
    67     \fn HsBackupRestoreObserverPrivate::handleKeyChange()
       
    68 
       
    69     Handles the key change. Creates active backup client and 
       
    70     informs client about backup/restore state change.
       
    71 */
       
    72 
       
    73 void HsBackupRestoreObserverPrivate::handleKeyChange(XQSettingsKey key, const QVariant &value)
       
    74 {    
       
    75     conn::TBURPartType type = static_cast< conn::TBURPartType >
       
    76         ( value.toInt() & conn::KBURPartTypeMask );
       
    77 		
       
    78 	// Test if the device is going into backup or restore mode, and we are
       
    79     // required to participate.
       
    80     if ( key.key() == KUidBackupRestoreKey && 
       
    81          (( type == conn::EBURBackupFull || type == conn::EBURRestoreFull ) ||
       
    82          ( type == conn::EBURBackupPartial || type == conn::EBURRestorePartial )) )
       
    83     {
       
    84         if ( !mCallBack )
       
    85         {
       
    86             mCallBack = CHsBURActiveCallback::NewL(mQ);
       
    87         }
       
    88 
       
    89         if ( !mActiveBackupClient )
       
    90         {
       
    91             mActiveBackupClient = conn::CActiveBackupClient::NewL( mCallBack );
       
    92 
       
    93             if ( ( type == conn::EBURBackupPartial || 
       
    94                    type == conn::EBURRestorePartial ) &&
       
    95                  !mActiveBackupClient->DoesPartialBURAffectMeL() )
       
    96             {
       
    97                 delete mCallBack;
       
    98                 mCallBack = NULL;
       
    99                 delete mActiveBackupClient;
       
   100                 mActiveBackupClient = NULL;
       
   101                 return;
       
   102             }           
       
   103             mQ->backupRestoreStarted();            
       
   104         }        
       
   105     }
       
   106     else
       
   107     {
       
   108         if ( key.key() == KUidBackupRestoreKey && type == conn::EBURNormal )
       
   109         {
       
   110             if ( (mLastType == conn::EBURBackupFull || mLastType == conn::EBURBackupPartial) ||
       
   111             	 (mLastType == conn::EBURRestorePartial || mLastType == conn::EBURRestoreFull) )
       
   112             {                
       
   113                 mQ->backupRestoreComplited();
       
   114             }         
       
   115             // delete once back to normal.
       
   116             delete mCallBack;
       
   117             mCallBack = NULL;
       
   118             delete mActiveBackupClient;
       
   119             mActiveBackupClient = NULL;            
       
   120         }
       
   121     }
       
   122 
       
   123     mLastType = type;
       
   124 }
       
   125 #endif //Q_OS_SYMBIAN
       
   126 
       
   127 /*!
       
   128     Singleton. 
       
   129 */
       
   130 HsBackupRestoreObserver *HsBackupRestoreObserver::instance()
       
   131 {
       
   132     if (!mInstance) {
       
   133         mInstance.reset(new HsBackupRestoreObserver);
       
   134     }
       
   135     return mInstance.data();
       
   136 }
       
   137 
       
   138 /*!
       
   139     Constructs a new observer with the given \a parent object.
       
   140 */
       
   141 HsBackupRestoreObserver::HsBackupRestoreObserver(QObject *parent)
       
   142  : QObject(parent),
       
   143    mBUROngoing(false)
       
   144 {
       
   145 #ifdef Q_OS_SYMBIAN
       
   146     mD = new HsBackupRestoreObserverPrivate(this);
       
   147 #endif //Q_OS_SYMBIAN
       
   148 }
       
   149 
       
   150 /*!
       
   151     Destructor.
       
   152 */
       
   153 HsBackupRestoreObserver::~HsBackupRestoreObserver()
       
   154 {
       
   155 #ifdef Q_OS_SYMBIAN
       
   156     delete mD;
       
   157 #endif //Q_OS_SYMBIAN
       
   158 }
       
   159 
       
   160 /*!
       
   161     Called when backup/restore is started.
       
   162 */
       
   163 void HsBackupRestoreObserver::backupRestoreStarted()
       
   164 {
       
   165 	mBUROngoing = true;
       
   166 	emit event_backupRestoreStarted();
       
   167 }
       
   168 
       
   169 /*!
       
   170     Called when backup/restore is completed.
       
   171 */
       
   172 void HsBackupRestoreObserver::backupRestoreComplited()
       
   173 {
       
   174 	mBUROngoing = false;
       
   175 	emit event_backupRestoreComplited();
       
   176 }
       
   177 
       
   178 /*!
       
   179     Called when Home screen is ready for backup/restore.
       
   180 */
       
   181 void HsBackupRestoreObserver::readyForBUR()
       
   182 {
       
   183 #ifdef Q_OS_SYMBIAN
       
   184     mD->readyForBUR();
       
   185 #endif //Q_OS_SYMBIAN
       
   186 }
       
   187 
       
   188 /*!
       
   189     Returns true if bacup/restore is ongoing.
       
   190 */
       
   191 bool HsBackupRestoreObserver::checkBUR()
       
   192 {
       
   193 	return mBUROngoing;
       
   194 }
       
   195 /*!
       
   196     Points to the observer instance.
       
   197 */
       
   198 QScopedPointer<HsBackupRestoreObserver> HsBackupRestoreObserver::mInstance(0);
       
   199 
       
   200 // End of File