filemanager/src/filemanager/src/backuprestore/fmrestorewidget.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 header file of the restore widget of file manager
       
    17  */
       
    18 #include "fmrestorewidget.h"
       
    19 #include "fmrestoresettings.h"
       
    20 #include "fmbackupsettings.h"
       
    21 #include "fmrestoreviewitem.h"
       
    22 #include "fmoperationservice.h"
       
    23 #include "fmviewmanager.h"
       
    24 
       
    25 #include "fmbackupconfigloader.h"
       
    26 #include "fmbkupengine.h"
       
    27 #include "fmbackuprestorehandler.h"
       
    28 
       
    29 #include <QGraphicsLinearLayout>
       
    30 #include <QStringListModel>
       
    31 #include <QDateTime>
       
    32 
       
    33 #include <hblistview.h>
       
    34 
       
    35 
       
    36 
       
    37 FmRestoreWigdet::FmRestoreWigdet(  QGraphicsItem *parent )
       
    38 : HbWidget( parent )
       
    39 {
       
    40     init();
       
    41 }
       
    42 
       
    43 FmRestoreWigdet::~FmRestoreWigdet()
       
    44 {
       
    45 }
       
    46 
       
    47 QList<int> FmRestoreWigdet::selectionIndexes()
       
    48 {
       
    49     QList<int> selectionList;
       
    50 
       
    51     for ( int i=0; i<mModel->rowCount(); i++ ) {
       
    52         FmRestoreViewItem *item = static_cast<FmRestoreViewItem*>( 
       
    53             mListView->itemByIndex( mModel->index( i ) ) );
       
    54         if( item && item->getCheckBoxState() ) {
       
    55             selectionList.push_back( i );
       
    56         }
       
    57     }
       
    58 
       
    59     return selectionList;
       
    60 }
       
    61 
       
    62 void FmRestoreWigdet::init()
       
    63 {
       
    64     QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout( this );
       
    65     vLayout->setOrientation( Qt::Vertical );
       
    66 
       
    67     mListView = new HbListView( this );
       
    68     connect( mListView, SIGNAL( activated( const QModelIndex & ) ),
       
    69              this, SLOT( on_list_activated( const QModelIndex & ) ) );
       
    70 
       
    71     mListView->setSelectionMode( HbAbstractItemView::MultiSelection );
       
    72 
       
    73     vLayout->addItem( mListView );
       
    74 
       
    75     mModel = new QStringListModel();
       
    76     mListView->setModel( mModel );    
       
    77     mRestoreSettings = FmViewManager::viewManager()->operationService()->backupRestoreHandler()->bkupEngine()->RestoreSettingsL();
       
    78     mBackupConfigLoader = FmViewManager::viewManager()->operationService()->backupRestoreHandler()->backupConfigLoader();
       
    79     
       
    80     // load backup settings to refresh default target drive
       
    81     FmViewManager::viewManager()->operationService()->backupRestoreHandler()->bkupEngine()->BackupSettingsL()->load();
       
    82     mRestoreSettings->load( mBackupConfigLoader->driversAndOperationList() );
       
    83 
       
    84     int index = 0;
       
    85 
       
    86     QList< FmRestoreEntry* > retoreEntryList = mRestoreSettings->restoreEntryList();
       
    87     mModel->insertRows( 0, retoreEntryList.count() );
       
    88 
       
    89     for ( QList< FmRestoreEntry* >::iterator it = retoreEntryList.begin(); 
       
    90          it != retoreEntryList.end(); ++it ){
       
    91              QString string = ( *it )->text();
       
    92              QDateTime datetime = ( *it )->restoreInfo().dateTime();
       
    93              string.append( '\t' );
       
    94              string.append( datetime.toString( "hh:mm ap dd/MM/yyyy") );
       
    95              QString drive = ( *it )->restoreInfo().drive();             
       
    96              string.append( '\t' );
       
    97              string.append( drive );
       
    98              QVariant variant( string );
       
    99 
       
   100              mModel->setData( mModel->index( index ), variant, Qt::DisplayRole );
       
   101 
       
   102              ++index;
       
   103     }
       
   104 
       
   105     mListView->setItemPrototype( new FmRestoreViewItem(this) );
       
   106 }
       
   107 
       
   108 void FmRestoreWigdet::on_list_activated( const QModelIndex &index )
       
   109 {
       
   110     FmRestoreViewItem *restoreViewItem = static_cast< FmRestoreViewItem* >
       
   111                                          ( mListView->itemByIndex( index ) );
       
   112 
       
   113     restoreViewItem->setCheckBoxState();    
       
   114 }
       
   115 
       
   116 int FmRestoreWigdet::backupDataCount()
       
   117 {
       
   118     return mModel->rowCount();
       
   119 }
       
   120 
       
   121 void FmRestoreWigdet::refresh()
       
   122 {
       
   123     mListView->setModel( 0 );
       
   124     if( !mModel ) {
       
   125             mModel = new QStringListModel();
       
   126         }
       
   127     mModel->removeRows( 0, mModel->rowCount() );
       
   128 
       
   129     mRestoreSettings = FmViewManager::viewManager()->operationService()->backupRestoreHandler()->bkupEngine()->RestoreSettingsL();
       
   130     mBackupConfigLoader = FmViewManager::viewManager()->operationService()->backupRestoreHandler()->backupConfigLoader();
       
   131     mRestoreSettings->load( mBackupConfigLoader->driversAndOperationList() );
       
   132 
       
   133     int index = 0;
       
   134     QList< FmRestoreEntry* > retoreEntryList = mRestoreSettings->restoreEntryList();
       
   135     mModel->insertRows( 0, retoreEntryList.count() );
       
   136     for ( QList< FmRestoreEntry* >::iterator it = retoreEntryList.begin(); 
       
   137         it != retoreEntryList.end(); ++it ){
       
   138             QString string = ( *it )->text();
       
   139             QDateTime datetime = ( *it )->restoreInfo().dateTime();
       
   140             QString drive = ( *it )->restoreInfo().drive();
       
   141             string.append( '\t' );
       
   142             string.append( datetime.toString( "hh:mm ap dd/MM/yyyy") );
       
   143             string.append( '\t' );
       
   144             string.append( drive );
       
   145             QVariant variant( string );             
       
   146             mModel->setData( mModel->index( index ), variant, Qt::DisplayRole );
       
   147             ++index;
       
   148         }   
       
   149     mListView->setModel( mModel );   
       
   150     mListView->setItemPrototype( new FmRestoreViewItem( this ) );
       
   151       
       
   152     for (int i = 0; i < mModel->rowCount(); ++i) {
       
   153         QModelIndex index = mModel->index(i);
       
   154         FmRestoreViewItem* restoreViewItem = static_cast< FmRestoreViewItem* >
       
   155                                                  (mListView->itemByIndex(index));
       
   156         connect(restoreViewItem, SIGNAL(stateChanged(int)), this, SIGNAL(stateChanged(int)));               
       
   157     }
       
   158     emit stateChanged(0);
       
   159     
       
   160 }