homescreenapp/stateplugins/hshomescreenstateplugin/src/hsbackuprestorestate.cpp
changeset 51 4785f57bf3d4
child 60 30f14686fb04
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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QStateMachine>
       
    19 #include <QScopedPointer>
       
    20 #include <HbMainWindow>
       
    21 #include <HbView>
       
    22 #include <HbAction>
       
    23 #include "hsdatabase.h"
       
    24 #include "hsscene.h"
       
    25 #include "hsbackuprestoreobserver.h"
       
    26 #include "hsbackuprestorestate.h"
       
    27 #include "hsscene.h"
       
    28 #include "hsgui.h"
       
    29 
       
    30 /*!
       
    31     \class HsBackupRestoreState
       
    32     \ingroup group_hshomescreenstateplugin
       
    33     \brief Home screen Bacup/Restore state.
       
    34 
       
    35     Releases all Home screen data, which will be backed up or restored.
       
    36 */
       
    37 
       
    38 /*!
       
    39     Constructs a new backup/restore state with the given \a parent.
       
    40 */
       
    41 HsBackupRestoreState::HsBackupRestoreState(QState *parent)
       
    42     : QState(parent)      
       
    43 {	
       
    44     connect(this, SIGNAL(entered()), SLOT(action_startListenBURStatus()));
       
    45     connect(this, SIGNAL(exited()), SLOT(action_stopListenBURStatus()));
       
    46 }
       
    47 
       
    48 /*!
       
    49     Destroys this backup/restore state.
       
    50 */
       
    51 HsBackupRestoreState::~HsBackupRestoreState()
       
    52 {
       
    53 }
       
    54 
       
    55 /*!
       
    56     Starts listen backup/restore status and releases Home screen data.
       
    57 */
       
    58 void HsBackupRestoreState::action_startListenBURStatus()
       
    59 {
       
    60     HsBackupRestoreObserver *backupRestoreObserver = 
       
    61         HsBackupRestoreObserver::instance();
       
    62     
       
    63     connect(backupRestoreObserver, 
       
    64             SIGNAL(event_backupRestoreComplited()),
       
    65             SIGNAL(event_loadScene()));
       
    66     
       
    67     // Close database
       
    68     mDatabase.reset(HsDatabase::takeInstance());
       
    69     mDatabase->close();        
       
    70     
       
    71     deleteIdleView();        
       
    72 
       
    73     // Delete scene
       
    74     HsScene *scene = HsScene::instance();    
       
    75     delete scene;
       
    76 
       
    77     backupRestoreObserver->readyForBUR();
       
    78 }
       
    79 
       
    80 /*!
       
    81     Stops listen backup/restore status.
       
    82 */
       
    83 void HsBackupRestoreState::action_stopListenBURStatus()
       
    84 {
       
    85     HsBackupRestoreObserver::instance()->disconnect(this);    
       
    86     
       
    87     // Open database
       
    88     HsDatabase::setInstance(mDatabase.data());
       
    89     mDatabase.take();
       
    90     HsDatabase::instance()->open();
       
    91 }
       
    92 
       
    93 /*!
       
    94    Deletes idle view
       
    95 */
       
    96 void HsBackupRestoreState::deleteIdleView()
       
    97 {
       
    98     // Delete idle view
       
    99     QScopedPointer<HbView> idleView(HsGui::takeIdleView());
       
   100 
       
   101     if (idleView){
       
   102         idleView->setNavigationAction(0);
       
   103         HsScene::mainWindow()->removeView(idleView.data());
       
   104     }
       
   105 }