bluetoothengine/btui/btcpplugin/btcpuisettingitem.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     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 "btcpuisettingitem.h"
       
    19 #include <cpitemdatahelper.h>
       
    20 #include <bluetoothuitrace.h>
       
    21 
       
    22 #include <HbInstance>
       
    23 #include <HbTranslator>
       
    24 
       
    25 BtCpUiSettingItem::BtCpUiSettingItem(CpItemDataHelper &itemDataHelper) :
       
    26     CpSettingFormEntryItemData(itemDataHelper)
       
    27 {
       
    28     bool ret(false);
       
    29     loadTranslators();
       
    30     mSettingModel = new BtSettingModel(this);
       
    31     mDeviceModel = new BtDeviceModel(this);
       
    32     
       
    33     ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), 
       
    34             this, SLOT(handleDataChanged(QModelIndex,QModelIndex)));
       
    35     BTUI_ASSERT_X( ret, "BtCpUiSettingItem::BtCpUiSettingItem", "can't connect dataChanged" );
       
    36 
       
    37     this->setDescription(hbTrId("txt_cp_dblist_bluetooth"));
       
    38     updateStatus();
       
    39 }
       
    40 
       
    41 BtCpUiSettingItem::~BtCpUiSettingItem()
       
    42 {
       
    43     delete mViewTranslator;
       
    44     delete mDialogTranslator;
       
    45 }
       
    46 
       
    47 void BtCpUiSettingItem::loadTranslators()
       
    48 {
       
    49     mViewTranslator = new HbTranslator("btviews");
       
    50     mDialogTranslator = new HbTranslator("btdialogs");
       
    51 }
       
    52 
       
    53 void BtCpUiSettingItem::onLaunchView()
       
    54 {
       
    55   
       
    56     mMainWindow = hbInstance->allMainWindows().first();
       
    57     
       
    58     mBtMainView = new BtCpUiMainView(*mSettingModel, *mDeviceModel);
       
    59       
       
    60     mCpView = mMainWindow->currentView();
       
    61     
       
    62     mMainWindow->addView(mBtMainView);
       
    63     mMainWindow->setCurrentView(mBtMainView);
       
    64     
       
    65     connect(mBtMainView, SIGNAL(aboutToClose()), this, SLOT(handleCloseView()));
       
    66     
       
    67 }
       
    68 
       
    69 void BtCpUiSettingItem::handleCloseView()
       
    70 {
       
    71     mBtMainView->deactivateView();
       
    72     mMainWindow->setCurrentView(mCpView);
       
    73     
       
    74     mMainWindow->removeView(mBtMainView);
       
    75     delete mBtMainView;
       
    76     mBtMainView = 0;
       
    77     
       
    78 }
       
    79 
       
    80 /*!
       
    81     Slot for receiving notification of local setting changes from the model.
       
    82     Identify the setting changed and update the corresponding UI item.
       
    83  */
       
    84 void BtCpUiSettingItem::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
       
    85 {     
       
    86     // update only the part of the view specified by the model's row(s)
       
    87     for (int i=topLeft.row(); i <= bottomRight.row(); i++) {
       
    88         QModelIndex index = mSettingModel->index( i, 0);
       
    89         // Distinguish which setting value is changed.
       
    90         switch ( i ) {
       
    91         case BtSettingModel::PowerStateRow:
       
    92         case BtSettingModel::VisibilityRow:
       
    93             updateStatus();
       
    94             break;
       
    95         }
       
    96     }   
       
    97 }
       
    98 
       
    99 void BtCpUiSettingItem::updateStatus()
       
   100 {
       
   101     QString btStatusText;
       
   102     HbIcon btStatusIcon;
       
   103     
       
   104     //todo: Connection status is not updated right now, which is also required as per UI Spec.
       
   105     PowerStateQtValue btPower = (PowerStateQtValue)mSettingModel->data(mSettingModel->index(
       
   106             BtSettingModel::PowerStateRow, 0),
       
   107             BtSettingModel::SettingValueRole).toInt();
       
   108     
       
   109     if(BtPowerOn == btPower) {
       
   110         VisibilityMode visibilityMode = (VisibilityMode) mSettingModel->data(
       
   111                 mSettingModel->index(BtSettingModel::VisibilityRow, 0),
       
   112                 BtSettingModel::SettingValueRole).toInt();
       
   113         switch(visibilityMode) {
       
   114             case BtHidden:
       
   115                 btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_hidden");
       
   116                 btStatusIcon.setIconName("qtg_large_bluetooth_hide");
       
   117                 break;
       
   118             case BtVisible:
       
   119             case BtTemporary:
       
   120                 btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_visible");
       
   121                 btStatusIcon.setIconName("qtg_large_bluetooth");
       
   122                 break;
       
   123             default:
       
   124                 BTUI_ASSERT_X(false, "BtCpUiSettingItem::updateStatus", "invalid visibility mode");
       
   125         }
       
   126     }
       
   127     else {
       
   128         //Bt is off.
       
   129         btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_off");
       
   130         btStatusIcon.setIconName("qtg_large_bluetooth_off");
       
   131     }
       
   132         
       
   133     this->setDescription(btStatusText);
       
   134     this->setEntryItemIcon(btStatusIcon);
       
   135 }
       
   136 
       
   137 CpBaseSettingView *BtCpUiSettingItem::createSettingView() const
       
   138 {
       
   139 	return 0;
       
   140 }