bluetoothengine/btui/btcpplugin/btcpuimainview.cpp
author hgs
Mon, 17 May 2010 11:06:23 +0300
changeset 31 a0ea99b6fa53
parent 29 48ae3789ce00
child 40 997690c3397a
child 42 b72428996822
permissions -rw-r--r--
201019_1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     1
/*
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
     2
* Copyright (c) 2009-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:  BtCpUiMainView implementation
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 "btcpuimainview.h"
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    19
#include "btuiviewutil.h"
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    20
#include <QtGlobal>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    21
#include <QGraphicsLinearLayout>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    22
#include <HbInstance>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    23
#include <hbdocumentloader.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    24
#include <hbnotificationdialog.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    25
#include <hbgridview.h>
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    26
#include <hblistview.h>
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    27
#include <hbpushbutton.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    28
#include <hblabel.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    29
#include <hbicon.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    30
#include <hblineedit.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    31
#include <hbtooltip.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    32
#include <btengconstants.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    33
#include <hbmenu.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    34
#include <hbaction.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    35
#include <hbcombobox.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    36
#include "btcpuisearchview.h"
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    37
#include "btcpuideviceview.h"
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    38
#include <bluetoothuitrace.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    39
#include <btdelegatefactory.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    40
#include <btabstractdelegate.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    41
#include "btqtconstants.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    42
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    43
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    44
// docml to load
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    45
const char* BTUI_MAINVIEW_DOCML = ":/docml/bt-main-view.docml";
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    46
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    47
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    48
    Constructs a new BtUiMainView using HBDocumentLoader.  Docml (basically xml) file
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    49
    has been generated using Application Designer.   
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    50
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    51
 */
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    52
BtCpUiMainView::BtCpUiMainView(        
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    53
        BtSettingModel &settingModel, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    54
        BtDeviceModel &deviceModel, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    55
        QGraphicsItem *parent )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    56
    : BtCpUiBaseView( settingModel, deviceModel, parent ),
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    57
      mAbstractDelegate(0), mMainFilterModel(0)
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    58
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    59
    bool ret(false);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    60
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    61
    mMainWindow = hbInstance->allMainWindows().first();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    62
    mMainView = this;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    63
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    64
    // Create view for the application.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    65
    // Set the name for the view. The name should be same as the view's
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    66
    // name in docml.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    67
    setObjectName("view");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    68
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    69
    QObjectList objectList;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    70
    objectList.append(this);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    71
    // Pass the view to documentloader. Document loader uses this view
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    72
    // when docml is parsed, instead of creating new view.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    73
    mLoader = new HbDocumentLoader();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    74
    mLoader->setObjectTree(objectList);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    75
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    76
    bool ok = false;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    77
    mLoader->load( BTUI_MAINVIEW_DOCML, &ok );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    78
    // Exit if the file format is invalid
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    79
    BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    80
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    81
    mOrientation = mMainWindow->orientation();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    82
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    83
    if (mOrientation == Qt::Horizontal) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    84
        mLoader->load(BTUI_MAINVIEW_DOCML, "landscape", &ok);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    85
        BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: landscape section problem" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    86
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    87
    else {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    88
        mLoader->load(BTUI_MAINVIEW_DOCML, "portrait", &ok);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    89
        BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: landscape section problem" );        
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    90
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    91
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    92
    mDeviceNameEdit=0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    93
    mDeviceNameEdit = qobject_cast<HbLineEdit *>( mLoader->findWidget( "lineEdit" ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    94
    BTUI_ASSERT_X( mDeviceNameEdit != 0, "bt-main-view", "Device Name not found" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    95
    ret =  connect(mDeviceNameEdit, SIGNAL(editingFinished ()), this, SLOT(changeBtLocalName()));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    96
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    97
    mPowerButton=0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    98
    mPowerButton = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton" ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    99
    BTUI_ASSERT_X( mPowerButton != 0, "bt-main-view", "power button not found" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   100
    ret =  connect(mPowerButton, SIGNAL(clicked()), this, SLOT(changePowerState()));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   101
    BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect power button" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   102
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   103
    mVisibilityMode=0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   104
    mVisibilityMode = qobject_cast<HbComboBox *>( mLoader->findWidget( "combobox" ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   105
    BTUI_ASSERT_X( mVisibilityMode != 0, "bt-main-view", "visibility combobox not found" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   106
        
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   107
    mDeviceList=0;
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   108
    mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "listView" ) );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   109
    BTUI_ASSERT_X( mDeviceList != 0, "bt-main-view", "Device List (grid view) not found" );   
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   110
    
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   111
    ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   112
    BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" ); 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   113
    
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   114
    // listen for orientation changes
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   115
    ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   116
            this, SLOT(changeOrientation(Qt::Orientation)));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   117
    BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView()", "connect orientationChanged() failed");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   118
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   119
    // load tool bar actions
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   120
    HbAction *discoverAction = static_cast<HbAction*>( mLoader->findObject( "discoverAction" ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   121
    BTUI_ASSERT_X( discoverAction, "bt-main-view", "discover action missing" ); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   122
    ret = connect(discoverAction, SIGNAL(triggered()), this, SLOT(goToDiscoveryView()));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   123
    BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" ); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   124
    
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   125
    //*********************Testing device view START****************************//
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   126
    HbAction *removePairedDevices = static_cast<HbAction*>( mLoader->findObject( "removePairedDevices" ) );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   127
    BTUI_ASSERT_X( removePairedDevices, "bt-main-view", "remove action missing" ); 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   128
    //ret = connect(removePairedDevices, SIGNAL(triggered()), this, SLOT(goToDeviceView()));
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   129
    //BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" ); 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   130
        
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   131
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   132
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   133
    //*********************Testing device view END****************************//
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   134
        
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   135
    // load menu
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   136
    HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   137
    BTUI_ASSERT_X( optionsMenu != 0, "bt-main-view", "Options menu not found" );   
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   138
    this->setMenu(optionsMenu);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   139
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   140
    // update display when setting data changed
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   141
    ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), 
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   142
            this, SLOT(updateSettingItems(QModelIndex,QModelIndex)));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   143
    BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect dataChanged" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   144
    
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   145
    QModelIndex top = mSettingModel->index( BtSettingModel::LocalBtNameRow, 0 );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   146
    QModelIndex bottom = mSettingModel->index( BtSettingModel::AllowedInOfflineRow, 0 );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   147
    // update name, power and visibility rows
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   148
    updateSettingItems( top, bottom );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   149
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   150
    //Handle Visibility Change User Interaction
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   151
    ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   152
            this, SLOT(visibilityChanged (int)));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   153
    // create other views
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   154
    createViews();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   155
    mCurrentView = this;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   156
    mCurrentViewId = MainView;
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   157
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   158
    mMainFilterModel = new BtuiModelSortFilter(this);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   159
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   160
    mMainFilterModel->setSourceModel( mDeviceModel );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   161
    // filter to match only InRegistry devices
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   162
    mMainFilterModel->addDeviceMajorFilter(
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   163
            BtDeviceModel::InRegistry, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   164
            BtuiModelSortFilter::AtLeastMatch);
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   165
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   166
    mDeviceList->setModel(mMainFilterModel);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   167
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   168
    
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   169
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   170
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   171
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   172
    Destructs the BtCpUiMainView.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   173
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   174
BtCpUiMainView::~BtCpUiMainView()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   175
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   176
    delete mLoader; // Also deletes all widgets that it constructed.
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   177
    
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   178
    mMainWindow->removeView(mSearchView);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   179
    delete mSearchView;
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   180
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   181
    mMainWindow->removeView(mDeviceView);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   182
    delete mDeviceView;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   183
        
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   184
	if (mAbstractDelegate) {
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   185
        delete mAbstractDelegate;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   186
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   187
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   188
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   189
/*! 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   190
    from base class, initialize the view
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   191
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   192
void BtCpUiMainView::activateView(const QVariant& value, int cmdId )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   193
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   194
    Q_UNUSED(value);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   195
    Q_UNUSED(cmdId);
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   196
    
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   197
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   198
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   199
/*! 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   200
    From base class. Handle resource before the current view is deactivated.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   201
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   202
void BtCpUiMainView::deactivateView()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   203
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   204
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   205
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   206
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   207
void BtCpUiMainView::itemActivated(QModelIndex index)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   208
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   209
    Q_UNUSED(index);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   210
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   211
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   212
void BtCpUiMainView::goToDiscoveryView()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   213
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   214
    changeView( SearchView, false, 0 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   215
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   216
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   217
void BtCpUiMainView::goToDeviceView(const QModelIndex& modelIndex)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   218
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   219
    //the QModelIndex of the selected device should be given as parameter here 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   220
    QVariant params;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   221
    params.setValue(modelIndex);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   222
    changeView( DeviceView, false, 0, params );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   223
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   224
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   225
Qt::Orientation BtCpUiMainView::orientation()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   226
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   227
    return mOrientation;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   228
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   229
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   230
void BtCpUiMainView::changeBtLocalName()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   231
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   232
    //Error handling has to be done.  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   233
    if (!mAbstractDelegate) {
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   234
        mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   235
                mSettingModel, mDeviceModel); 
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   236
        connect( mAbstractDelegate, SIGNAL(commandCompleted(int,QVariant)), this, SLOT(btNameDelegateCompleted(int,QVariant)) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   237
        mAbstractDelegate->exec(mDeviceNameEdit->text ());
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   238
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   239
    else {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   240
        setPrevBtLocalName();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   241
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   242
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   243
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   244
void BtCpUiMainView::setPrevBtLocalName()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   245
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   246
    //Should we notify user this as Error...?
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   247
    HbNotificationDialog::launchDialog(hbTrId("Error"));
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   248
    QModelIndex index = mSettingModel->index( BtSettingModel::LocalBtNameRow,0 );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   249
    
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   250
    mDeviceNameEdit->setText( mSettingModel->data(
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   251
            index,BtSettingModel::settingDisplayRole).toString() );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   252
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   253
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   254
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   255
void BtCpUiMainView::btNameDelegateCompleted(int status, QVariant param)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   256
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   257
    if(KErrNone == status) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   258
        mDeviceNameEdit->setText(param.toString());
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   259
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   260
    else {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   261
        setPrevBtLocalName();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   262
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   263
    //Error handling has to be done.    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   264
    if (mAbstractDelegate)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   265
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   266
        disconnect(mAbstractDelegate);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   267
        delete mAbstractDelegate;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   268
        mAbstractDelegate = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   269
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   270
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   271
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   272
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   273
void BtCpUiMainView::visibilityChanged (int index)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   274
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   275
    QList<QVariant> list;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   276
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   277
    VisibilityMode mode = indexToVisibilityMode(index);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   278
    list.append(QVariant((int)mode));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   279
    if(BtTemporary == VisibilityMode(mode)) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   280
        //Right now hardcoded to 5 Mins.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   281
        list.append(QVariant(5));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   282
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   283
    //Error handling has to be done.    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   284
    if (!mAbstractDelegate) {
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   285
        mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Visibility, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   286
                mSettingModel, mDeviceModel); 
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   287
        connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(visibilityDelegateCompleted(int)) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   288
        mAbstractDelegate->exec(list);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   289
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   290
    else {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   291
        setPrevVisibilityMode();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   292
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   293
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   294
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   295
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   296
void BtCpUiMainView::setPrevVisibilityMode()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   297
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   298
    bool ret(false);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   299
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   300
    //Should we notify this error to user..?
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   301
    HbNotificationDialog::launchDialog(hbTrId("Error"));
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   302
    QModelIndex index = mSettingModel->index( BtSettingModel::VisibilityRow, 0 );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   303
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   304
    ret = disconnect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   305
                    this, SLOT(visibilityChanged (int)));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   306
    BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't disconnect signal" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   307
    
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   308
    mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   309
                mSettingModel->data(index,BtSettingModel::SettingValueRole).toInt()) );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   310
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   311
    //Handle Visibility Change User Interaction
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   312
    ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   313
            this, SLOT(visibilityChanged (int)));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   314
    BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't connect signal" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   315
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   316
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   317
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   318
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   319
void BtCpUiMainView::visibilityDelegateCompleted(int status)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   320
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   321
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   322
    //This should be mapped to Qt error
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   323
    if(KErrNone != status) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   324
        setPrevVisibilityMode();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   325
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   326
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   327
    //Error handling has to be done.    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   328
    if (mAbstractDelegate)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   329
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   330
        disconnect(mAbstractDelegate);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   331
        delete mAbstractDelegate;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   332
        mAbstractDelegate = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   333
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   334
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   335
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   336
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   337
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   338
// called due to real orientation change event coming from main window
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   339
void BtCpUiMainView::changeOrientation( Qt::Orientation orientation )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   340
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   341
    bool ok = false;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   342
    mOrientation = orientation;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   343
    if( orientation == Qt::Vertical ) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   344
        // load "portrait" section
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   345
        mLoader->load( BTUI_MAINVIEW_DOCML, "portrait", &ok );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   346
        BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: portrait section problem" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   347
    } else {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   348
        // load "landscape" section
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   349
        mLoader->load( BTUI_MAINVIEW_DOCML, "landscape", &ok );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   350
        BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: landscape section problem" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   351
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   352
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   353
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   354
void BtCpUiMainView::commandCompleted( int cmdId, int err, const QString &diagnostic )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   355
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   356
    Q_UNUSED(cmdId);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   357
    Q_UNUSED(err);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   358
    Q_UNUSED(diagnostic);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   359
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   360
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   361
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   362
/*!
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   363
    Slot for receiving notification of local setting changes from the model.
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   364
    Identify the setting changed and update the corresponding UI item.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   365
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   366
void BtCpUiMainView::updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   367
{   
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   368
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   369
    // update only the part of the view specified by the model's row(s)
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   370
    for (int i=topLeft.row(); i <= bottomRight.row(); i++) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   371
        QModelIndex index = mSettingModel->index( i, 0);
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   372
        // Distinguish which setting value is changed.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   373
        switch ( i ) {
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   374
        case BtSettingModel::LocalBtNameRow :
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   375
            mDeviceNameEdit->setText( 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   376
                    mSettingModel->data(index,BtSettingModel::settingDisplayRole).toString() );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   377
            break;
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   378
        case BtSettingModel::PowerStateRow:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   379
            mPowerButton->setText( mSettingModel->data(index,
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   380
                    BtSettingModel::settingDisplayRole).toString() );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   381
            break;
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   382
        case BtSettingModel::VisibilityRow:
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   383
            mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode)
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   384
                    mSettingModel->data(index,BtSettingModel::SettingValueRole).toInt()) );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   385
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   386
        }
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   387
    }   
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   388
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   389
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   390
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   391
    Slot for receiving notification for user interaction on power state.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   392
    Manually update model data since HbPushButton is not linked to model directly.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   393
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   394
void BtCpUiMainView::changePowerState()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   395
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   396
    
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   397
    QModelIndex index = mSettingModel->index(BtSettingModel::PowerStateRow, 0);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   398
    QVariant powerState = mSettingModel->data(index, Qt::EditRole);
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   399
    if (!mAbstractDelegate)//if there is no other delegate running
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   400
    { 
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   401
        mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   402
                mSettingModel, mDeviceModel ); 
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   403
        connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   404
        mAbstractDelegate->exec(powerState);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   405
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   406
   
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   407
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   408
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   409
void BtCpUiMainView::powerDelegateCompleted(int status)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   410
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   411
    Q_UNUSED(status);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   412
    //ToDo: Error handling here 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   413
    if (mAbstractDelegate)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   414
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   415
        disconnect(mAbstractDelegate);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   416
        delete mAbstractDelegate;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   417
        mAbstractDelegate = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   418
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   419
    //BTUI_ASSERT_X( status, "bt-main-view", "error in delegate complete" );  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   420
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   421
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   422
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   423
 * Mapping from visibility mode UI row to VisibilityMode
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   424
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   425
VisibilityMode BtCpUiMainView::indexToVisibilityMode(int index)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   426
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   427
    VisibilityMode mode; 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   428
    switch(index) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   429
    case UiRowBtHidden:  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   430
        mode = BtHidden;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   431
        break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   432
    case UiRowBtVisible:  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   433
        mode = BtVisible;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   434
        break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   435
    case UiRowBtTemporary:  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   436
        mode = BtTemporary;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   437
        break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   438
    default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   439
        mode = BtUnknown;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   440
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   441
    return mode;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   442
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   443
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   444
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   445
 * Mapping from VisibilityMode to visibility mode UI row  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   446
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   447
int BtCpUiMainView::visibilityModeToIndex(VisibilityMode mode)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   448
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   449
    int uiRow;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   450
    switch(mode) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   451
    case BtHidden:  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   452
        uiRow = UiRowBtHidden;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   453
        break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   454
    case BtVisible:  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   455
        uiRow = UiRowBtVisible;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   456
        break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   457
    case BtTemporary:  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   458
        uiRow = UiRowBtTemporary;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   459
        break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   460
    default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   461
        uiRow = -1;  // error
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   462
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   463
    return uiRow;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   464
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   465
//////////////////////
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   466
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   467
// from view manager
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   468
// 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   469
//////////////////////
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   470
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   471
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   472
    Create views(main view, device view and search view).
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   473
    Add them to MainWindow.  All views are long-lived and are deleted only when exiting the application 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   474
    (or when main view is deleted).
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   475
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   476
void BtCpUiMainView::createViews()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   477
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   478
    Qt::Orientation orientation = mMainWindow->orientation();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   479
    // Create other views
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   480
    mSearchView = new BtCpUiSearchView( *mSettingModel, *mDeviceModel, this );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   481
    mMainWindow->addView(mSearchView);
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   482
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   483
    mDeviceView = new BtCpUiDeviceView( *mSettingModel, *mDeviceModel, this );  
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   484
    mMainWindow->addView(mDeviceView);
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   485
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   486
    mCurrentView = this;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   487
    mCurrentViewId = MainView;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   488
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   489
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   490
    // QList<int> stores the previous view ids for each view.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   491
    for( int i=0; i < LastView; i++ ) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   492
        mPreviousViewIds.append( 0 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   493
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   494
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   495
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   496
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   497
    Switch between the views.  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   498
    Parameter cmdId is used for automatically executing command.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   499
    Parameter "value" is optional except for GadgetView, 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   500
    which needs the BT address (QString)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   501
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   502
void BtCpUiMainView::changeView(int targetViewId, bool fromBackButton, 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   503
        int cmdId, const QVariant& value )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   504
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   505
    mCurrentView->deactivateView();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   506
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   507
    // update the previous view Id in QList<int> 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   508
    // If launching the target view from back softkey, 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   509
    // the previous viewId of target view should not be changed. 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   510
    // Otherwise, loop happens between two views.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   511
    if(!fromBackButton) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   512
        if ((targetViewId == DeviceView) && (mCurrentViewId == SearchView)) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   513
            // we don't want to return to search view after e.g. pairing a new device
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   514
            mPreviousViewIds[ targetViewId ] = MainView;  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   515
        } 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   516
        else {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   517
            // normal case:  return to previous view
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   518
            mPreviousViewIds[ targetViewId ] = mCurrentViewId;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   519
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   520
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   521
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   522
    // set the new current view 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   523
    mCurrentView = idToView(targetViewId);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   524
    mCurrentViewId = targetViewId;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   525
    mMainWindow->setCurrentView( mCurrentView );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   526
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   527
    // do preparation or some actions when new view is activated 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   528
    mCurrentView->activateView( value, cmdId );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   529
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   530
 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   531
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   532
void BtCpUiMainView::deviceSelected(const QModelIndex& modelIndex)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   533
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   534
    QModelIndex index = mMainFilterModel->mapToSource(modelIndex);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   535
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   536
    QVariant params;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   537
    params.setValue(index);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   538
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   539
    changeView( DeviceView, false, 0, params );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   540
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   541
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   542
BtCpUiBaseView * BtCpUiMainView::idToView(int targetViewId)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   543
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   544
    switch (targetViewId) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   545
    case MainView:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   546
        return mMainView;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   547
    case SearchView:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   548
        return mSearchView;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   549
    case DeviceView:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   550
        return mDeviceView;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   551
    default :
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   552
        BTUI_ASSERT_X(false, "BtCpUiMainView::idToView", "invalid view id");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   553
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   554
    return 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   555
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   556
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   557
/*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   558
   Jump to previous view.  This function is used when back button is pressed.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   559
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   560
void BtCpUiMainView::switchToPreviousViewReally()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   561
{  
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   562
//    // jump to previous view of current view.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   563
//    if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   564
//        changeView( mPreviousViewIds[mCurrentViewId], true, 0 );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   565
//    } 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   566
//    else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   567
//        BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousViewReally", "invalid view id");
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   568
//    }
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   569
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   570
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   571
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   572
void BtCpUiMainView::setSoftkeyBack()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   573
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   574
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   575
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   576
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   577
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   578
   Jump to previous view.  This function is used when back button is pressed.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   579
   semantics slightly different than in other views, since this is called by other
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   580
   views when a view switch is needed
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   581
 */
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   582
void BtCpUiMainView::switchToPreviousView()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   583
{
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   584
    // jump to previous view of current view.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   585
    if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   586
        changeView( mPreviousViewIds[mCurrentViewId], true, 0 );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   587
    } 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   588
    else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   589
        BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousView", "invalid view id");
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   590
    }      
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   591
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   592