bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp
author hgs
Fri, 06 Aug 2010 16:43:21 +0300
changeset 51 625f43ae9362
parent 47 9e2a905b887f
child 57 5ebadcda06cb
permissions -rw-r--r--
201031_05
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 "btcpuisearchview.h"
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    19
#include "btuiviewutil.h"
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    20
#include <QtGui/QGraphicsLinearLayout>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    21
#include <HbInstance>
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    22
#include <HbDocumentLoader>
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    23
#include <HbDataForm>
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    24
#include <HbPushButton>
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    25
#include <HbLabel>
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    26
#include <HbListView>
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    27
#include <HbMenu>
42
hgs
parents: 31
diff changeset
    28
#include <HbSelectionDialog>
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    29
#include <HbGroupBox>
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    30
#include <QString>
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    31
#include <QStringList>
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    32
#include <QDebug>
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    33
#include <bluetoothuitrace.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    34
#include "btcpuimainview.h"
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    35
#include "btdelegatefactory.h"
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    36
#include "btabstractdelegate.h"
42
hgs
parents: 31
diff changeset
    37
#include "btcpuisearchlistviewitem.h"
hgs
parents: 31
diff changeset
    38
#include "btuidevtypemap.h"
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
// docml to load
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    42
const char* BTUI_SEARCHVIEW_DOCML = ":/docml/bt-search-view.docml";
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    43
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    44
BtCpUiSearchView::BtCpUiSearchView(
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    45
        BtSettingModel &settingModel, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    46
        BtDeviceModel &deviceModel, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    47
        QGraphicsItem *parent) :
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    48
    BtCpUiBaseView(settingModel,deviceModel, parent), mAbstractDelegate(0), mBtuiModelSortFilter(0)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    49
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    50
    bool ret(false);
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    51
    
42
hgs
parents: 31
diff changeset
    52
    mQuery = 0;
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    53
    mLoader = 0;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    54
    mSoftKeyBackAction = 0;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    55
    
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    56
    mMainView = (BtCpUiMainView *) parent;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    57
    mMainWindow = hbInstance->allMainWindows().first();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    58
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    59
    mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    60
    BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiSearchView::BtCpUiSearchView", "can't create back action");
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    61
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    62
    // Create view for the application.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    63
    // Set the name for the view. The name should be same as the view's
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    64
    // name in docml.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    65
    setObjectName("bt_search_view");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    66
42
hgs
parents: 31
diff changeset
    67
    mLoader = new HbDocumentLoader();
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    68
    BTUI_ASSERT_X( mLoader != 0, "BtCpUiSearchView::BtCpUiSearchView", "can't create mLoader" );
42
hgs
parents: 31
diff changeset
    69
    // Pass the view to documentloader. Document loader uses this view
hgs
parents: 31
diff changeset
    70
    // when docml is parsed, instead of creating new view.
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    71
    QObjectList objectList;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    72
    objectList.append(this);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    73
    mLoader->setObjectTree(objectList);
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    74
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    75
    // read view info from docml file
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    76
    bool ok = false;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    77
    mLoader->load( BTUI_SEARCHVIEW_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-search-view", "Invalid docml file" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    80
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    81
    // Set title for the control panel
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    82
    // ToDo:  check if deprecated API
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    83
    setTitle("Control Panel");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    84
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    85
    // assign automatically created widgets to local variables
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    86
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    87
    mDeviceIcon=0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    88
    // can't use qobject_cast since HbIcon is not derived from QObject!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    89
    mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "icon" ) );  
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    90
    BTUI_ASSERT_X( mDeviceIcon != 0, "BtCpUiSearchView::BtCpUiSearchView", "Device Icon not found" );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    91
    
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    92
    mDataForm=0;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    93
    mDataForm = qobject_cast<HbDataForm *>( mLoader->findWidget( "dataForm" ) );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    94
    BTUI_ASSERT_X( mDataForm != 0, "BtCpUiSearchView::BtCpUiSearchView", "dataForm not found" );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    95
    mDataForm->setHeading(hbTrId("txt_bt_subhead_bluetooth_found_devices"));
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    96
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    97
    mLabelSearching=0;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    98
    mLabelSearching = qobject_cast<HbLabel *>( mLoader->findWidget( "label_searching" ) );
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    99
    BTUI_ASSERT_X( mLabelSearching != 0, "BtCpUiSearchView::BtCpUiSearchView", "Searching not found" );
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   100
    mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching"));
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   101
    
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   102
    mDeviceList=0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   103
    mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "deviceList" ) );
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   104
    BTUI_ASSERT_X( mDeviceList != 0, "BtCpUiSearchView::BtCpUiSearchView", "Device List not found" );   
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   105
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   106
    
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   107
    mDeviceList->setSelectionMode( HbAbstractItemView::SingleSelection );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   108
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   109
    // read landscape orientation section from docml file if needed
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   110
    mOrientation = mMainWindow->orientation();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   111
    
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   112
    if (mOrientation == Qt::Horizontal) {
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   113
        mLoader->load(BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok);
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   114
        BTUI_ASSERT_X( ok, "BtCpUiSearchView::BtCpUiSearchView", "Invalid docml file: landscape section problem" );
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   115
    } else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   116
        mLoader->load(BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok);
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   117
        BTUI_ASSERT_X( ok, "BtCpUiSearchView::BtCpUiSearchView", "Invalid docml file: portrait section problem" );        
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   118
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   119
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   120
    // listen for orientation changes
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   121
    ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   122
            this, SLOT(changeOrientation(Qt::Orientation)));
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   123
    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView()", "connect orientationChanged() failed");
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   124
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   125
    // load tool bar actions
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   126
    mViewBy = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) );
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   127
    BTUI_ASSERT_X( mViewBy, "BtCpUiSearchView::BtCpUiSearchView", "view by action missing" ); 
42
hgs
parents: 31
diff changeset
   128
    ret = connect(mViewBy, SIGNAL(triggered()), this, SLOT(viewByDeviceTypeDialog()));
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   129
    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "viewByAction can't connect" ); 
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   130
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   131
    mStop = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) );
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   132
    BTUI_ASSERT_X( mStop, "BtCpUiSearchView::BtCpUiSearchView", "stopAction missing" ); 
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   133
    ret = connect(mStop, SIGNAL(triggered()), this, SLOT(stopSearching()));
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   134
    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "stopAction can't connect" ); 
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   135
    mStop->setEnabled(true);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   136
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   137
    mRetry = static_cast<HbAction*>( mLoader->findObject( "retryAction" ) );
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   138
    BTUI_ASSERT_X( mRetry, "BtCpUiSearchView::BtCpUiSearchView", "retryAction missing" ); 
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   139
    ret = connect(mRetry, SIGNAL(triggered()), this, SLOT(retrySearch()));
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   140
    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "retryAction can't connect" ); 
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   141
    // Disable for initial search
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   142
    mRetry->setEnabled(false);
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   143
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   144
    // load menu
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   145
    HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   146
    BTUI_ASSERT_X( optionsMenu != 0, "BtCpUiSearchView::BtCpUiSearchView", "Options menu not found" );   
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   147
    this->setMenu(optionsMenu);      
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   148
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   149
    ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   150
    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "deviceSelected can't connect" ); 
42
hgs
parents: 31
diff changeset
   151
    
hgs
parents: 31
diff changeset
   152
    // initialize device type list for "view by" option
hgs
parents: 31
diff changeset
   153
    // Note:  this list needs to be in the same order as enum devTypeSelectionList
hgs
parents: 31
diff changeset
   154
    mDevTypeList << hbTrId("txt_bt_list_audio_devices")
hgs
parents: 31
diff changeset
   155
            << hbTrId("txt_bt_list_computers") 
hgs
parents: 31
diff changeset
   156
            << hbTrId("txt_bt_list_input_devices") 
hgs
parents: 31
diff changeset
   157
            << hbTrId("txt_bt_list_phones") 
hgs
parents: 31
diff changeset
   158
            << hbTrId("txt_bt_list_other_devices");
hgs
parents: 31
diff changeset
   159
    
hgs
parents: 31
diff changeset
   160
    // initialize sort model & create
hgs
parents: 31
diff changeset
   161
    // inquiry delegate
hgs
parents: 31
diff changeset
   162
    // Sort is set to dynamic sort filter = true in the class, will sort automatically
hgs
parents: 31
diff changeset
   163
    mBtuiModelSortFilter = new BtuiModelSortFilter(this);
hgs
parents: 31
diff changeset
   164
    mBtuiModelSortFilter->setSourceModel(mDeviceModel);
hgs
parents: 31
diff changeset
   165
    mBtuiModelSortFilter->addDeviceMajorFilter(
hgs
parents: 31
diff changeset
   166
            BtuiDevProperty::InRange, BtuiModelSortFilter::AtLeastMatch);
hgs
parents: 31
diff changeset
   167
    mDeviceList->setModel(mBtuiModelSortFilter);
hgs
parents: 31
diff changeset
   168
    // add sort order to show devices in the order they are found
hgs
parents: 31
diff changeset
   169
    mBtuiModelSortFilter->setSortRole(BtDeviceModel::SeqNumRole);
hgs
parents: 31
diff changeset
   170
    // Sort according to the first column (and the only column) in the listview - sorted according SeqNumRole
hgs
parents: 31
diff changeset
   171
    mBtuiModelSortFilter->sort(0, Qt::AscendingOrder);
hgs
parents: 31
diff changeset
   172
hgs
parents: 31
diff changeset
   173
    BtCpUiSearchListViewItem *prototype = new BtCpUiSearchListViewItem(mDeviceList);
hgs
parents: 31
diff changeset
   174
    prototype->setModelSortFilter(mBtuiModelSortFilter);
hgs
parents: 31
diff changeset
   175
    mDeviceList->setItemPrototype(prototype);
hgs
parents: 31
diff changeset
   176
hgs
parents: 31
diff changeset
   177
    // Create the inquiry delegate.
hgs
parents: 31
diff changeset
   178
    mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Inquiry, mSettingModel, mDeviceModel );
hgs
parents: 31
diff changeset
   179
    
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   180
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   181
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   182
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   183
BtCpUiSearchView::~BtCpUiSearchView()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   184
{
42
hgs
parents: 31
diff changeset
   185
    delete mLoader; // Also deletes all widgets that it constructed.
hgs
parents: 31
diff changeset
   186
    
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   187
    setNavigationAction(0);
42
hgs
parents: 31
diff changeset
   188
    disconnect( mSoftKeyBackAction );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   189
    delete mSoftKeyBackAction;
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   190
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   191
    if(mAbstractDelegate) {
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   192
        disconnect(mAbstractDelegate);   
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   193
        delete mAbstractDelegate;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   194
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   195
    if(mBtuiModelSortFilter) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   196
        delete mBtuiModelSortFilter;
42
hgs
parents: 31
diff changeset
   197
    }
hgs
parents: 31
diff changeset
   198
    if ( mQuery ) {
hgs
parents: 31
diff changeset
   199
        delete mQuery;
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   200
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   201
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   202
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   203
void BtCpUiSearchView::changeOrientation( Qt::Orientation orientation )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   204
{
42
hgs
parents: 31
diff changeset
   205
    // ToDo:  this does not handle redrawing list view items differently for portrait/landscape
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   206
    bool ok = false;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   207
    mOrientation = orientation;
42
hgs
parents: 31
diff changeset
   208
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   209
    if( orientation == Qt::Vertical ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   210
        // load "portrait" section
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   211
        mLoader->load( BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok );
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   212
        BTUI_ASSERT_X( ok, "BtCpUiSearchView::changeOrientation", "Invalid docml file: portrait section problem" );
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   213
    } else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   214
        // load "landscape" section
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   215
        mLoader->load( BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok );
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   216
        BTUI_ASSERT_X( ok, "BtCpUiSearchView::changeOrientation", "Invalid docml file: landscape section problem" );
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   217
    }
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   218
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   219
42
hgs
parents: 31
diff changeset
   220
hgs
parents: 31
diff changeset
   221
void BtCpUiSearchView::viewByDeviceTypeDialog()
hgs
parents: 31
diff changeset
   222
{
hgs
parents: 31
diff changeset
   223
    if ( !mQuery ) {
hgs
parents: 31
diff changeset
   224
        mQuery = new HbSelectionDialog;
hgs
parents: 31
diff changeset
   225
        mQuery->setStringItems(mDevTypeList, 0);
hgs
parents: 31
diff changeset
   226
        mQuery->setSelectionMode(HbAbstractItemView::MultiSelection);
hgs
parents: 31
diff changeset
   227
    
hgs
parents: 31
diff changeset
   228
        QList<QVariant> current;
hgs
parents: 31
diff changeset
   229
        current.append(QVariant(0));
hgs
parents: 31
diff changeset
   230
        mQuery->setSelectedItems(current);
hgs
parents: 31
diff changeset
   231
    
hgs
parents: 31
diff changeset
   232
        // Set the heading for the dialog.
hgs
parents: 31
diff changeset
   233
        HbLabel *headingLabel = new HbLabel(hbTrId("txt_bt_title_show"), mQuery);
hgs
parents: 31
diff changeset
   234
        mQuery->setHeadingWidget(headingLabel);
hgs
parents: 31
diff changeset
   235
    }
hgs
parents: 31
diff changeset
   236
    mQuery->open(this,SLOT(viewByDialogClosed(HbAction*)));
hgs
parents: 31
diff changeset
   237
}
hgs
parents: 31
diff changeset
   238
/*!
hgs
parents: 31
diff changeset
   239
   Callback for HbSelectionDialog closing
hgs
parents: 31
diff changeset
   240
hgs
parents: 31
diff changeset
   241
 */
hgs
parents: 31
diff changeset
   242
void BtCpUiSearchView::viewByDialogClosed(HbAction* action)
hgs
parents: 31
diff changeset
   243
{
hgs
parents: 31
diff changeset
   244
    disconnect( mQuery );  // remove slot
hgs
parents: 31
diff changeset
   245
    if (action == mQuery->actions().first()) {  // user pressed "Ok"
hgs
parents: 31
diff changeset
   246
        // Get selected items.
hgs
parents: 31
diff changeset
   247
        QList<QVariant> selections;
hgs
parents: 31
diff changeset
   248
        selections = mQuery->selectedItems();
hgs
parents: 31
diff changeset
   249
        
hgs
parents: 31
diff changeset
   250
        int devTypesWanted = 0;
hgs
parents: 31
diff changeset
   251
        
hgs
parents: 31
diff changeset
   252
        for (int i=0; i < selections.count(); i++) {
hgs
parents: 31
diff changeset
   253
            switch (selections.at(i).toInt()) {
hgs
parents: 31
diff changeset
   254
            case BtUiDevAudioDevice:
hgs
parents: 31
diff changeset
   255
                devTypesWanted |= BtuiDevProperty::AVDev;
hgs
parents: 31
diff changeset
   256
                break;
hgs
parents: 31
diff changeset
   257
            case BtUiDevComputer:
hgs
parents: 31
diff changeset
   258
                devTypesWanted |= BtuiDevProperty::Computer;
hgs
parents: 31
diff changeset
   259
                break;
hgs
parents: 31
diff changeset
   260
            case BtUiDevInputDevice:
hgs
parents: 31
diff changeset
   261
                devTypesWanted |= BtuiDevProperty::Peripheral;
hgs
parents: 31
diff changeset
   262
                break;
hgs
parents: 31
diff changeset
   263
            case BtUiDevPhone:
hgs
parents: 31
diff changeset
   264
                devTypesWanted |= BtuiDevProperty::Phone;
hgs
parents: 31
diff changeset
   265
                break;
hgs
parents: 31
diff changeset
   266
            case BtUiDevOtherDevice:
hgs
parents: 31
diff changeset
   267
                devTypesWanted |= (BtuiDevProperty::LANAccessDev |
hgs
parents: 31
diff changeset
   268
                        BtuiDevProperty::Toy |
hgs
parents: 31
diff changeset
   269
                        BtuiDevProperty::WearableDev |
hgs
parents: 31
diff changeset
   270
                        BtuiDevProperty::ImagingDev |
hgs
parents: 31
diff changeset
   271
                        BtuiDevProperty::HealthDev |
hgs
parents: 31
diff changeset
   272
                        BtuiDevProperty::UncategorizedDev);
hgs
parents: 31
diff changeset
   273
                break;
hgs
parents: 31
diff changeset
   274
            default:
hgs
parents: 31
diff changeset
   275
                // should never get here
hgs
parents: 31
diff changeset
   276
                BTUI_ASSERT_X(false, "BtCpUiSearchView::viewByDialogClosed()", 
hgs
parents: 31
diff changeset
   277
                        "wrong device type in viewBy dialog!");
hgs
parents: 31
diff changeset
   278
            }
hgs
parents: 31
diff changeset
   279
        }
hgs
parents: 31
diff changeset
   280
        if (devTypesWanted) {
hgs
parents: 31
diff changeset
   281
            mBtuiModelSortFilter->clearDeviceMajorFilters();
hgs
parents: 31
diff changeset
   282
            mBtuiModelSortFilter->addDeviceMajorFilter(BtuiDevProperty::InRange,
hgs
parents: 31
diff changeset
   283
                            BtuiModelSortFilter::AtLeastMatch);   // device must be in range
hgs
parents: 31
diff changeset
   284
            mBtuiModelSortFilter->addDeviceMajorFilter(devTypesWanted,
hgs
parents: 31
diff changeset
   285
                    BtuiModelSortFilter::RoughMatch);             // device can be any one of selected ones
hgs
parents: 31
diff changeset
   286
        }
hgs
parents: 31
diff changeset
   287
    }
hgs
parents: 31
diff changeset
   288
}
hgs
parents: 31
diff changeset
   289
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   290
void BtCpUiSearchView::stopSearching()
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   291
{
42
hgs
parents: 31
diff changeset
   292
    // Stop searching
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   293
42
hgs
parents: 31
diff changeset
   294
    // Stop search delegate
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   295
    mAbstractDelegate->cancel();
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   296
    // reset view 
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   297
    deviceSearchCompleted(KErrNone);      
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   298
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   299
42
hgs
parents: 31
diff changeset
   300
void BtCpUiSearchView::startSearchDelegate ()
hgs
parents: 31
diff changeset
   301
{
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   302
    bool ret = false;
42
hgs
parents: 31
diff changeset
   303
    
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   304
    // Connect to the signal from the BtDelegateInquiry for completion of the search request
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   305
    ret = connect(mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(searchDelegateCompleted(int)));
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   306
    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "searchDelegateCompleted can't connect" );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   307
    
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   308
    // Connect to the signal from the BtuiModel when the search has been completed.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   309
    ret = connect(mDeviceModel, SIGNAL(deviceSearchCompleted(int)), this, SLOT(deviceSearchCompleted(int)));
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   310
    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "deviceSearchCompleted can't connect" );     
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   311
42
hgs
parents: 31
diff changeset
   312
    mAbstractDelegate->exec(QVariant());
hgs
parents: 31
diff changeset
   313
}
hgs
parents: 31
diff changeset
   314
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   315
void BtCpUiSearchView::retrySearch()
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   316
{
42
hgs
parents: 31
diff changeset
   317
    // Retry search
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   318
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   319
    // Change label and buttons to reflect status
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   320
    mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching"));
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   321
    mRetry->setEnabled(false);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   322
    mStop->setEnabled(true);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   323
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   324
    // Make use of the delegate and start the search.
42
hgs
parents: 31
diff changeset
   325
    startSearchDelegate ();
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   326
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   327
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   328
void BtCpUiSearchView::setSoftkeyBack()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   329
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   330
    if (navigationAction() != mSoftKeyBackAction) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   331
        setNavigationAction(mSoftKeyBackAction);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   332
        connect( mSoftKeyBackAction, SIGNAL(triggered()), this, SLOT(switchToPreviousView()) );
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
void BtCpUiSearchView::switchToPreviousView()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   337
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   338
    BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView");
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   339
    mMainView->switchToPreviousView();
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   340
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   341
42
hgs
parents: 31
diff changeset
   342
void BtCpUiSearchView::activateView( const QVariant& value, bool fromBackButton )
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   343
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   344
    Q_UNUSED(value);
42
hgs
parents: 31
diff changeset
   345
hgs
parents: 31
diff changeset
   346
    // ToDo:  consider whether orientation should be updated here rather than when orientation really changes;
hgs
parents: 31
diff changeset
   347
    // advantage:  if orientation changes temporarily in another view, but returns to previous setting before
hgs
parents: 31
diff changeset
   348
    // search is reactived, there is no processing overhead
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   349
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   350
    setSoftkeyBack();
42
hgs
parents: 31
diff changeset
   351
            
hgs
parents: 31
diff changeset
   352
    if ( !fromBackButton ) {
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   353
        // Sets the label and toolbar buttons
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   354
        retrySearch();
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   355
    }
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   356
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   357
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   358
void BtCpUiSearchView::deactivateView()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   359
{
42
hgs
parents: 31
diff changeset
   360
    mAbstractDelegate->cancel();          // Stop searching when leaving view
hgs
parents: 31
diff changeset
   361
    deviceSearchCompleted(KErrNone);      // reset view 
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   362
}
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   363
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   364
void BtCpUiSearchView::searchDelegateCompleted(int error)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   365
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   366
    Q_UNUSED(error);
42
hgs
parents: 31
diff changeset
   367
    
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   368
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   369
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   370
void BtCpUiSearchView::deviceSearchCompleted(int error)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   371
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   372
    //TODO - handle error.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   373
    Q_UNUSED(error);
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   374
    
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   375
    mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done"));
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   376
    mRetry->setEnabled(true);
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   377
    mStop->setEnabled(false);
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   378
    
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   379
    // disconnect signals
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   380
    disconnect(mAbstractDelegate);
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   381
    disconnect(mDeviceModel);
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   382
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   383
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   384
void BtCpUiSearchView::deviceSelected(const QModelIndex& modelIndex)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   385
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   386
    QModelIndex index = mBtuiModelSortFilter->mapToSource(modelIndex);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   387
    static_cast<BtCpUiMainView*>(mMainView)->goToDeviceView(index);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   388
}