bluetoothengine/btui/btcpplugin/btcpuisettingitem.cpp
changeset 63 bcf742120177
parent 41 0b2439c3e397
equal deleted inserted replaced
52:4545c04e61e1 63:bcf742120177
    16  */
    16  */
    17 
    17 
    18 #include "btcpuisettingitem.h"
    18 #include "btcpuisettingitem.h"
    19 #include <cpitemdatahelper.h>
    19 #include <cpitemdatahelper.h>
    20 #include <bluetoothuitrace.h>
    20 #include <bluetoothuitrace.h>
    21 
    21 #include <btsettingmodel.h>
       
    22 #include <btdevicemodel.h>
    22 #include <HbInstance>
    23 #include <HbInstance>
    23 #include <HbTranslator>
    24 #include <HbTranslator>
       
    25 #include <HbView>
       
    26 #include "btcpuimainview.h"
    24 
    27 
    25 BtCpUiSettingItem::BtCpUiSettingItem(CpItemDataHelper &itemDataHelper) :
    28 BtcpuiSettingItem::BtcpuiSettingItem(CpItemDataHelper &itemDataHelper) :
    26     CpSettingFormEntryItemData(itemDataHelper)
    29     CpSettingFormEntryItemData(itemDataHelper), mMainView(0)
    27 {
    30 {
    28     bool ret(false);
    31     bool ret(false);
    29     loadTranslators();
    32     loadTranslators();
    30     mSettingModel = new BtSettingModel(this);
    33     mSettingModel = new BtSettingModel(this);
    31     mDeviceModel = new BtDeviceModel(this);
    34     mDeviceModel = new BtDeviceModel(this);
    32     
    35     mMainWindow = hbInstance->allMainWindows().first();
    33     ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), 
    36     ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), 
    34             this, SLOT(handleDataChanged(QModelIndex,QModelIndex)));
    37             this, SLOT(handleDataChanged(QModelIndex,QModelIndex)));
    35     BTUI_ASSERT_X( ret, "BtCpUiSettingItem::BtCpUiSettingItem", "can't connect dataChanged" );
    38     BTUI_ASSERT_X( ret, "BtcpuiSettingItem::BtcpuiSettingItem", "can't connect dataChanged" );
    36 
    39 
    37     this->setDescription(hbTrId("txt_cp_dblist_bluetooth"));
    40     this->setDescription(hbTrId("txt_cp_dblist_bluetooth"));
    38     updateStatus();
    41     updateStatus();
    39 }
    42 }
    40 
    43 
    41 BtCpUiSettingItem::~BtCpUiSettingItem()
    44 BtcpuiSettingItem::~BtcpuiSettingItem()
    42 {
    45 {
       
    46     delete mMainView;
    43     delete mViewTranslator;
    47     delete mViewTranslator;
    44     delete mDialogTranslator;
    48     delete mDialogTranslator;
    45 }
    49 }
    46 
    50 
    47 void BtCpUiSettingItem::loadTranslators()
    51 void BtcpuiSettingItem::onLaunchView()
    48 {
    52 {
    49     mViewTranslator = new HbTranslator("btviews");
    53     // Main view will be launched when the user clicked the Bluetooth setting item in CP.
    50     mDialogTranslator = new HbTranslator("btdialogs");
    54 
       
    55     // We need to save the pointer of the view from which the main view is launched, 
       
    56     // for navigating back to CP when the main view is closed.
       
    57     mCpView = mMainWindow->currentView();
       
    58     mMainView = new BtcpuiMainView(*mSettingModel, *mDeviceModel);
       
    59     mMainWindow->addView(mMainView);
       
    60     connect(mMainView, SIGNAL(aboutToClose()), this, SLOT(handleCloseMainView()));
       
    61     mMainWindow->setCurrentView(mMainView);
    51 }
    62 }
    52 
    63 
    53 void BtCpUiSettingItem::onLaunchView()
    64 void BtcpuiSettingItem::handleCloseMainView()
    54 {
    65 {
    55   
    66     if (mMainView) {
    56     mMainWindow = hbInstance->allMainWindows().first();
    67         mMainWindow->removeView(mMainView);
    57     
    68         delete mMainView;
    58     mBtMainView = new BtCpUiMainView(*mSettingModel, *mDeviceModel);
    69         mMainView = 0;
    59       
    70     }
    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);
    71     mMainWindow->setCurrentView(mCpView);
    73     
       
    74     mMainWindow->removeView(mBtMainView);
       
    75     delete mBtMainView;
       
    76     mBtMainView = 0;
       
    77     
       
    78 }
    72 }
    79 
    73 
    80 /*!
    74 /*!
    81     Slot for receiving notification of local setting changes from the model.
    75     Slot for receiving notification of local setting changes from the model.
    82     Identify the setting changed and update the corresponding UI item.
    76     Identify the setting changed and update the corresponding UI item.
    83  */
    77  */
    84 void BtCpUiSettingItem::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
    78 void BtcpuiSettingItem::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
    85 {     
    79 {     
    86     // update only the part of the view specified by the model's row(s)
    80     // update only the part of the view specified by the model's row(s)
    87     for (int i=topLeft.row(); i <= bottomRight.row(); i++) {
    81     for (int i=topLeft.row(); i <= bottomRight.row(); i++) {
    88         QModelIndex index = mSettingModel->index( i, 0);
    82         QModelIndex index = mSettingModel->index( i, 0);
    89         // Distinguish which setting value is changed.
    83         // Distinguish which setting value is changed.
    94             break;
    88             break;
    95         }
    89         }
    96     }   
    90     }   
    97 }
    91 }
    98 
    92 
    99 void BtCpUiSettingItem::updateStatus()
    93 CpBaseSettingView *BtcpuiSettingItem::createSettingView() const
       
    94 {
       
    95     return 0;
       
    96 }
       
    97 
       
    98 void BtcpuiSettingItem::updateStatus()
   100 {
    99 {
   101     QString btStatusText;
   100     QString btStatusText;
   102     HbIcon btStatusIcon;
   101     HbIcon btStatusIcon;
   103     
   102     
   104     //todo: Connection status is not updated right now, which is also required as per UI Spec.
   103     //todo: Connection status is not updated right now, which is also required as per UI Spec.
   119             case BtTemporary:
   118             case BtTemporary:
   120                 btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_visible");
   119                 btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_visible");
   121                 btStatusIcon.setIconName("qtg_large_bluetooth");
   120                 btStatusIcon.setIconName("qtg_large_bluetooth");
   122                 break;
   121                 break;
   123             default:
   122             default:
   124                 BTUI_ASSERT_X(false, "BtCpUiSettingItem::updateStatus", "invalid visibility mode");
   123                 BTUI_ASSERT_X(false, "BtcpuiSettingItem::updateStatus", "invalid visibility mode");
   125         }
   124         }
   126     }
   125     }
   127     else {
   126     else {
   128         //Bt is off.
   127         //Bt is off.
   129         btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_off");
   128         btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_off");
   130         btStatusIcon.setIconName("qtg_large_bluetooth_off");
   129         btStatusIcon.setIconName("qtg_large_bluetooth_off");
   131     }
   130     }
   132         
       
   133     this->setDescription(btStatusText);
   131     this->setDescription(btStatusText);
   134     this->setEntryItemIcon(btStatusIcon);
   132     this->setEntryItemIcon(btStatusIcon);
   135 }
   133 }
   136 
   134 
   137 CpBaseSettingView *BtCpUiSettingItem::createSettingView() const
   135 
       
   136 void BtcpuiSettingItem::loadTranslators()
   138 {
   137 {
   139 	return 0;
   138     mViewTranslator = new HbTranslator("btviews");
       
   139     mDialogTranslator = new HbTranslator("btdialogs");
   140 }
   140 }
       
   141