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