bluetoothengine/btui/btcpplugin/btcpuisettingitem.cpp
author hgs
Mon, 12 Jul 2010 18:51:05 +0300
changeset 42 b72428996822
parent 31 a0ea99b6fa53
child 57 5ebadcda06cb
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     1
/*
42
hgs
parents: 31
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     3
 * All rights reserved.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0""
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     8
 *
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     9
 * Initial Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    11
 *
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    12
 * Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    13
 *
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    14
 * Description:  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    15
 *   
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    16
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    17
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    18
#include "btcpuisettingitem.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    19
#include <cpitemdatahelper.h>
42
hgs
parents: 31
diff changeset
    20
#include <bluetoothuitrace.h>
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    21
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    22
#include <HbInstance>
42
hgs
parents: 31
diff changeset
    23
#include <HbTranslator>
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    24
42
hgs
parents: 31
diff changeset
    25
BtCpUiSettingItem::BtCpUiSettingItem(CpItemDataHelper &itemDataHelper) :
hgs
parents: 31
diff changeset
    26
    CpSettingFormEntryItemData(itemDataHelper)
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    27
{
42
hgs
parents: 31
diff changeset
    28
    bool ret(false);
hgs
parents: 31
diff changeset
    29
    loadTranslators();
hgs
parents: 31
diff changeset
    30
    mSettingModel = new BtSettingModel(this);
hgs
parents: 31
diff changeset
    31
    mDeviceModel = new BtDeviceModel(this);
hgs
parents: 31
diff changeset
    32
    
hgs
parents: 31
diff changeset
    33
    ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), 
hgs
parents: 31
diff changeset
    34
            this, SLOT(handleDataChanged(QModelIndex,QModelIndex)));
hgs
parents: 31
diff changeset
    35
    BTUI_ASSERT_X( ret, "BtCpUiSettingItem::BtCpUiSettingItem", "can't connect dataChanged" );
hgs
parents: 31
diff changeset
    36
hgs
parents: 31
diff changeset
    37
    this->setDescription(hbTrId("txt_cp_dblist_bluetooth"));
hgs
parents: 31
diff changeset
    38
    updateStatus();
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    39
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    40
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    41
BtCpUiSettingItem::~BtCpUiSettingItem()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    42
{
42
hgs
parents: 31
diff changeset
    43
    delete mViewTranslator;
hgs
parents: 31
diff changeset
    44
    delete mDialogTranslator;
hgs
parents: 31
diff changeset
    45
}
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    46
42
hgs
parents: 31
diff changeset
    47
void BtCpUiSettingItem::loadTranslators()
hgs
parents: 31
diff changeset
    48
{
hgs
parents: 31
diff changeset
    49
    mViewTranslator = new HbTranslator("btviews");
hgs
parents: 31
diff changeset
    50
    mDialogTranslator = new HbTranslator("btdialogs");
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    51
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    52
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    53
void BtCpUiSettingItem::onLaunchView()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    54
{
42
hgs
parents: 31
diff changeset
    55
  
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    56
    mMainWindow = hbInstance->allMainWindows().first();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    57
    
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    58
    mBtMainView = new BtCpUiMainView(*mSettingModel, *mDeviceModel);
42
hgs
parents: 31
diff changeset
    59
      
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    60
    mCpView = mMainWindow->currentView();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    61
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    62
    mMainWindow->addView(mBtMainView);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    63
    mMainWindow->setCurrentView(mBtMainView);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    64
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    65
    connect(mBtMainView, SIGNAL(aboutToClose()), this, SLOT(handleCloseView()));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    66
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    67
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    68
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    69
void BtCpUiSettingItem::handleCloseView()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    70
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    71
    mBtMainView->deactivateView();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    72
    mMainWindow->setCurrentView(mCpView);
42
hgs
parents: 31
diff changeset
    73
    
hgs
parents: 31
diff changeset
    74
    mMainWindow->removeView(mBtMainView);
hgs
parents: 31
diff changeset
    75
    delete mBtMainView;
hgs
parents: 31
diff changeset
    76
    mBtMainView = 0;
hgs
parents: 31
diff changeset
    77
    
hgs
parents: 31
diff changeset
    78
}
hgs
parents: 31
diff changeset
    79
hgs
parents: 31
diff changeset
    80
/*!
hgs
parents: 31
diff changeset
    81
    Slot for receiving notification of local setting changes from the model.
hgs
parents: 31
diff changeset
    82
    Identify the setting changed and update the corresponding UI item.
hgs
parents: 31
diff changeset
    83
 */
hgs
parents: 31
diff changeset
    84
void BtCpUiSettingItem::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
hgs
parents: 31
diff changeset
    85
{     
hgs
parents: 31
diff changeset
    86
    // update only the part of the view specified by the model's row(s)
hgs
parents: 31
diff changeset
    87
    for (int i=topLeft.row(); i <= bottomRight.row(); i++) {
hgs
parents: 31
diff changeset
    88
        QModelIndex index = mSettingModel->index( i, 0);
hgs
parents: 31
diff changeset
    89
        // Distinguish which setting value is changed.
hgs
parents: 31
diff changeset
    90
        switch ( i ) {
hgs
parents: 31
diff changeset
    91
        case BtSettingModel::PowerStateRow:
hgs
parents: 31
diff changeset
    92
        case BtSettingModel::VisibilityRow:
hgs
parents: 31
diff changeset
    93
            updateStatus();
hgs
parents: 31
diff changeset
    94
            break;
hgs
parents: 31
diff changeset
    95
        }
hgs
parents: 31
diff changeset
    96
    }   
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    97
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    98
42
hgs
parents: 31
diff changeset
    99
void BtCpUiSettingItem::updateStatus()
hgs
parents: 31
diff changeset
   100
{
hgs
parents: 31
diff changeset
   101
    QString btStatusText;
hgs
parents: 31
diff changeset
   102
    HbIcon btStatusIcon;
hgs
parents: 31
diff changeset
   103
    
hgs
parents: 31
diff changeset
   104
    //todo: Connection status is not updated right now, which is also required as per UI Spec.
hgs
parents: 31
diff changeset
   105
    PowerStateQtValue btPower = (PowerStateQtValue)mSettingModel->data(mSettingModel->index(
hgs
parents: 31
diff changeset
   106
            BtSettingModel::PowerStateRow, 0),
hgs
parents: 31
diff changeset
   107
            BtSettingModel::SettingValueRole).toInt();
hgs
parents: 31
diff changeset
   108
    
hgs
parents: 31
diff changeset
   109
    if(BtPowerOn == btPower) {
hgs
parents: 31
diff changeset
   110
        VisibilityMode visibilityMode = (VisibilityMode) mSettingModel->data(
hgs
parents: 31
diff changeset
   111
                mSettingModel->index(BtSettingModel::VisibilityRow, 0),
hgs
parents: 31
diff changeset
   112
                BtSettingModel::SettingValueRole).toInt();
hgs
parents: 31
diff changeset
   113
        switch(visibilityMode) {
hgs
parents: 31
diff changeset
   114
            case BtHidden:
hgs
parents: 31
diff changeset
   115
                btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_hidden");
hgs
parents: 31
diff changeset
   116
                btStatusIcon.setIconName("qtg_large_bluetooth_hide");
hgs
parents: 31
diff changeset
   117
                break;
hgs
parents: 31
diff changeset
   118
            case BtVisible:
hgs
parents: 31
diff changeset
   119
            case BtTemporary:
hgs
parents: 31
diff changeset
   120
                btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_on_and_visible");
hgs
parents: 31
diff changeset
   121
                btStatusIcon.setIconName("qtg_large_bluetooth");
hgs
parents: 31
diff changeset
   122
                break;
hgs
parents: 31
diff changeset
   123
            default:
hgs
parents: 31
diff changeset
   124
                BTUI_ASSERT_X(false, "BtCpUiSettingItem::updateStatus", "invalid visibility mode");
hgs
parents: 31
diff changeset
   125
        }
hgs
parents: 31
diff changeset
   126
    }
hgs
parents: 31
diff changeset
   127
    else {
hgs
parents: 31
diff changeset
   128
        //Bt is off.
hgs
parents: 31
diff changeset
   129
        btStatusText = hbTrId("txt_cp_dblist_bluetooth_val_off");
hgs
parents: 31
diff changeset
   130
        btStatusIcon.setIconName("qtg_large_bluetooth_off");
hgs
parents: 31
diff changeset
   131
    }
hgs
parents: 31
diff changeset
   132
        
hgs
parents: 31
diff changeset
   133
    this->setDescription(btStatusText);
hgs
parents: 31
diff changeset
   134
    this->setEntryItemIcon(btStatusIcon);
hgs
parents: 31
diff changeset
   135
}
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   136
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   137
CpBaseSettingView *BtCpUiSettingItem::createSettingView() const
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   138
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   139
	return 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   140
}