filemanager/src/filemanager/src/backuprestore/fmdeletebackupwidget.cpp
changeset 14 1957042d8c7e
child 21 15299bc55001
child 25 b7bfdea70ca2
equal deleted inserted replaced
1:d1daf54a55b5 14:1957042d8c7e
       
     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 delete backup widget of file manager
       
    17  */
       
    18 #include "fmdeletebackupwidget.h"
       
    19 #include "fmrestoresettings.h"
       
    20 #include "fmrestoreviewitem.h"
       
    21 #include "fmoperationservice.h"
       
    22 #include "fmviewmanager.h"
       
    23 
       
    24 #include "fmbackupconfigloader.h"
       
    25 #include "fmbkupengine.h"
       
    26 #include "fmbackuprestorehandler.h"
       
    27 
       
    28 #include <QGraphicsLinearLayout>
       
    29 #include <QStringListModel>
       
    30 #include <QDateTime>
       
    31 
       
    32 #include <hblistview.h>
       
    33 
       
    34 FmDeleteBackupWidget::FmDeleteBackupWidget(  HbWidget *parent )
       
    35 : HbWidget( parent ), mModel( 0 )
       
    36 {
       
    37     init();
       
    38 }
       
    39 
       
    40 FmDeleteBackupWidget::~FmDeleteBackupWidget()
       
    41 {
       
    42     mListView->setModel( 0 );
       
    43     delete mModel;
       
    44 }
       
    45 
       
    46 void FmDeleteBackupWidget::refresh()
       
    47 {
       
    48     mListView->setModel( 0 );
       
    49     loadData();
       
    50     mListView->setModel( mModel );
       
    51 }
       
    52 QList<int> FmDeleteBackupWidget::selectionIndexes()
       
    53 {
       
    54     QList<int> selectionList;
       
    55 
       
    56     for ( int i=0; i<mModel->rowCount(); i++ ) {
       
    57         FmRestoreViewItem *item = static_cast<FmRestoreViewItem*>( 
       
    58             mListView->itemByIndex( mModel->index( i ) ) );
       
    59         if( item && item->getCheckBoxState() ) {
       
    60             selectionList.push_back( i );
       
    61         }
       
    62     }
       
    63 
       
    64     return selectionList;
       
    65 }
       
    66 
       
    67 void FmDeleteBackupWidget::loadData()
       
    68 {
       
    69     if( !mModel ) {
       
    70         mModel = new QStringListModel();
       
    71     }
       
    72     mModel->removeRows( 0, mModel->rowCount() );
       
    73 
       
    74     mRestoreSettings = FmViewManager::viewManager()->operationService()->backupRestoreHandler()->bkupEngine()->RestoreSettingsL();
       
    75     mBackupConfigLoader = FmViewManager::viewManager()->operationService()->backupRestoreHandler()->backupConfigLoader();
       
    76     mRestoreSettings->load( mBackupConfigLoader->driversAndOperationList() );
       
    77 
       
    78     int index = 0;
       
    79 
       
    80     QList< FmRestoreEntry* > retoreEntryList = mRestoreSettings->restoreEntryList();
       
    81     mModel->insertRows( 0, retoreEntryList.count() );
       
    82 
       
    83     for ( QList< FmRestoreEntry* >::iterator it = retoreEntryList.begin(); 
       
    84          it != retoreEntryList.end(); ++it ){
       
    85              QString string = ( *it )->text();
       
    86              QDateTime datetime = ( *it )->restoreInfo().dateTime();
       
    87              string.append( '\t' );
       
    88              string.append( datetime.toString( "hh:mm ap dd/MM/yyyy") );
       
    89              QVariant variant( string );
       
    90 
       
    91              mModel->setData( mModel->index( index ), variant, Qt::DisplayRole );
       
    92 
       
    93              ++index;
       
    94     }
       
    95 
       
    96 }
       
    97 
       
    98 void FmDeleteBackupWidget::init()
       
    99 {
       
   100     QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout( this );
       
   101     vLayout->setOrientation( Qt::Vertical );
       
   102 
       
   103     mListView = new HbListView( this );
       
   104     connect( mListView, SIGNAL( activated( const QModelIndex & ) ),
       
   105              this, SLOT( on_list_activated( const QModelIndex & ) ) );
       
   106 
       
   107     mListView->setSelectionMode( HbAbstractItemView::MultiSelection );
       
   108 
       
   109     vLayout->addItem( mListView );
       
   110 
       
   111     loadData();
       
   112     mListView->setModel( mModel );
       
   113 
       
   114     mListView->setItemPrototype( new FmRestoreViewItem( this ) );
       
   115 
       
   116 }
       
   117 
       
   118 void FmDeleteBackupWidget::on_list_activated( const QModelIndex &index )
       
   119 {
       
   120     FmRestoreViewItem *restoreViewItem = static_cast< FmRestoreViewItem* >
       
   121                                          ( mListView->itemByIndex( index ) );
       
   122 
       
   123     restoreViewItem->setCheckBoxState();
       
   124 }
       
   125 
       
   126 int FmDeleteBackupWidget::backupDataCount()
       
   127 {
       
   128     return mModel->rowCount();
       
   129 }