coreapplicationuis/Rfs/Plugins/cprfsplugin/src/cprfssettingsform.cpp
branchRCL_3
changeset 20 c2c61fdca848
parent 19 924385140d98
child 21 9af619316cbf
equal deleted inserted replaced
19:924385140d98 20:c2c61fdca848
     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:  Creates the view for "Reset" and "Delete Data and Resore" and activates the RFS operation based on the user selection.
       
    15  *   
       
    16  */
       
    17 
       
    18 #include "cprfssettingsform.h"
       
    19 #include "cprfssettingsdataformcustomitem.h"
       
    20 
       
    21 
       
    22 #include <hbdataformmodelitem.h>
       
    23 #include <hbdataformmodel.h>
       
    24 #include <hbpushbutton.h>
       
    25 #include <rfsHandler.h>
       
    26 
       
    27 CpRfsSettingsForm::CpRfsSettingsForm(QGraphicsItem *parent) :
       
    28     HbDataForm(parent),mTrans("control_panel")
       
    29     {
       
    30     this->setHeading(hbTrId("txt_cp_subhead_reset"));
       
    31 
       
    32     //initialize the form model
       
    33     initRfsSettingModel();
       
    34 
       
    35     connect(this, SIGNAL(itemShown(QModelIndex)),this, SLOT(onItemActivated(QModelIndex)));
       
    36     }
       
    37 
       
    38 CpRfsSettingsForm::~CpRfsSettingsForm()
       
    39     {
       
    40     
       
    41     }
       
    42 
       
    43 void CpRfsSettingsForm::initRfsSettingModel()
       
    44     {
       
    45     HbDataFormModel *model = new HbDataFormModel(0);
       
    46 
       
    47 		// Create the custom items because HbPushButton cannot be added to the HbDataFormModelItem
       
    48     HbDataFormModelItem::DataItemType customItem1 = static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase + 1);
       
    49     
       
    50     mNormalRfs = model->appendDataFormItem(customItem1, QString(), model->invisibleRootItem());
       
    51     mNormalRfs->setLabel(hbTrId("txt_cp_setlabel_settings_reset"));
       
    52     mNormalRfs->setDescription(hbTrId("txt_cp_info_original_settings_will_be_restored_no"));
       
    53     HbDataFormModelItem::DataItemType customItem2 = static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase + 2);
       
    54                
       
    55     mDeepRfs = model->appendDataFormItem(customItem2, QString(), model->invisibleRootItem());
       
    56     mDeepRfs->setLabel(hbTrId("txt_cp_setlabel_device_reset"));
       
    57     mDeepRfs->setDescription(hbTrId("txt_cp_info_all_data_will_be_deleted_and_factory_s")); 
       
    58     this->setModel(model);
       
    59     }
       
    60 
       
    61 // On Item activated
       
    62 void CpRfsSettingsForm::onItemActivated(const QModelIndex &index)
       
    63     {
       
    64     HbDataFormModelItem *itemData = static_cast<HbDataFormModelItem *> (index.internalPointer());
       
    65     // to deal with orbit change temparialy
       
    66     if (itemData->type() > HbDataFormModelItem::GroupPageItem)
       
    67         {
       
    68         //get the widget of setting item
       
    69         HbAbstractViewItem* viewitem  = static_cast<HbAbstractItemView*>(this)->itemByIndex(index);
       
    70         HbWidget* widget =static_cast<HbDataFormViewItem*>(viewitem)->dataItemContentWidget(); 
       
    71 		if (itemData == mNormalRfs)
       
    72             {
       
    73             activateNormalRfs(widget);
       
    74             }
       
    75 		if (itemData == mDeepRfs)
       
    76             {
       
    77             activateDeepRfs(widget);
       
    78             }
       
    79         }
       
    80     }
       
    81 
       
    82 void CpRfsSettingsForm::activateNormalRfs(HbWidget* widget)
       
    83     {
       
    84     HbPushButton *advanced = qobject_cast<HbPushButton *> (widget);
       
    85     
       
    86     if(advanced)
       
    87         {
       
    88         //TODO Issue in DataForm Calling the itemActivated twice
       
    89         disconnect( advanced, SIGNAL(clicked()), this, SLOT(onPressedNormalRfs()) );
       
    90 
       
    91         connect( advanced, SIGNAL(clicked()), this, SLOT(onPressedNormalRfs()) );
       
    92         }
       
    93     }
       
    94 
       
    95 void CpRfsSettingsForm::activateDeepRfs(HbWidget* widget)
       
    96     {
       
    97     HbPushButton *advanced = qobject_cast<HbPushButton *> (widget);
       
    98     
       
    99     if(advanced)
       
   100         {
       
   101         //TODO Issue in DataForm Calling the itemActivated twice
       
   102         disconnect( advanced, SIGNAL(clicked()), this, SLOT(onPressedDeepRfs()) );
       
   103 
       
   104         connect( advanced, SIGNAL(clicked()), this, SLOT(onPressedDeepRfs()) );
       
   105         }
       
   106     }
       
   107 
       
   108 void CpRfsSettingsForm::onPressedNormalRfs()
       
   109     {
       
   110     CRfsHandler* rfsHandler = new ( ELeave ) CRfsHandler;
       
   111     CleanupStack :: PushL(rfsHandler);
       
   112     
       
   113     //activate the Normal RFS
       
   114     rfsHandler->ActivateRfsL( ERfsNormal );
       
   115     
       
   116     CleanupStack :: PopAndDestroy(rfsHandler);
       
   117 
       
   118     }
       
   119 
       
   120 void CpRfsSettingsForm::onPressedDeepRfs()
       
   121     {
       
   122     CRfsHandler* rfsHandler = new ( ELeave ) CRfsHandler;
       
   123     CleanupStack :: PushL(rfsHandler);
       
   124     
       
   125     //activate the Deep RFS
       
   126     rfsHandler->ActivateRfsL( ERfsDeep );
       
   127     
       
   128     CleanupStack :: PopAndDestroy(rfsHandler);
       
   129     }