bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp
changeset 29 48ae3789ce00
child 31 a0ea99b6fa53
equal deleted inserted replaced
28:7e2761e776bd 29:48ae3789ce00
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0""
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  
       
    15  *
       
    16  */
       
    17 
       
    18 #include "btcpuisearchview.h"
       
    19 #include <QtGui/QGraphicsLinearLayout>
       
    20 #include <HbInstance>
       
    21 #include <hbdocumentloader.h>
       
    22 #include <hbdataform.h>
       
    23 #include <hbpushbutton.h>
       
    24 #include <hblabel.h>
       
    25 #include <hblistview.h>
       
    26 #include <hbmenu.h>
       
    27 #include <qstringlist>
       
    28 #include <qdebug>
       
    29 #include <bluetoothuitrace.h>
       
    30 #include "btcpuimainview.h"
       
    31 
       
    32 
       
    33 
       
    34 // docml to load
       
    35 const char* BTUI_SEARCHVIEW_DOCML = ":/docml/bt-search-view.docml";
       
    36 
       
    37 BtCpUiSearchView::BtCpUiSearchView(BtuiModel &model, QGraphicsItem *parent) :
       
    38     BtCpUiBaseView(model,parent)
       
    39 /*{
       
    40     mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
       
    41     BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action");
       
    42 
       
    43     QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout( Qt::Vertical, this );
       
    44     // create button
       
    45     HbPushButton *button = new HbPushButton(this);
       
    46     button->setText("Press Me");
       
    47     button->setMaximumSize(150,50);
       
    48     mainLayout->addItem(button);  
       
    49 
       
    50 //    (void) connect(button, SIGNAL(clicked()), this, SLOT(changePowerState()));  
       
    51     
       
    52     setLayout(mainLayout);
       
    53     
       
    54     // create dummy options menu
       
    55     HbMenu *optionsMenu = new HbMenu();
       
    56     HbAction *openGadgetGallery = optionsMenu->addAction("Open Device Gallery");
       
    57 //    connect(openGadgetGallery, SIGNAL(triggered()), this, SLOT(openGadgetGalleryView()));
       
    58     HbAction *openNewMainView = optionsMenu->addAction("Open new Main View");   
       
    59 //    connect(openNewMainView, SIGNAL(triggered()), this, SLOT(openNewMainView()));   
       
    60     setMenu(optionsMenu);
       
    61 
       
    62 }*/
       
    63     
       
    64 {
       
    65     //bool ret(false);
       
    66     
       
    67     mSearchView = this;
       
    68     mMainView = (BtCpUiMainView *) parent;
       
    69     
       
    70     mMainWindow = hbInstance->allMainWindows().first();
       
    71     
       
    72     mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
       
    73     BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action");
       
    74     
       
    75 
       
    76     // read view info from docml file
       
    77 
       
    78 
       
    79     // Create view for the application.
       
    80     // Set the name for the view. The name should be same as the view's
       
    81     // name in docml.
       
    82     setObjectName("bt_search_view");
       
    83 
       
    84     QObjectList objectList;
       
    85     objectList.append(this);
       
    86     // Pass the view to documentloader. Document loader uses this view
       
    87     // when docml is parsed, instead of creating new view.
       
    88     mLoader = new HbDocumentLoader();
       
    89     mLoader->setObjectTree(objectList);
       
    90 
       
    91     bool ok = false;
       
    92     mLoader->load( BTUI_SEARCHVIEW_DOCML, &ok );
       
    93     // Exit if the file format is invalid
       
    94     BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file" );
       
    95     
       
    96     // Set title for the control panel
       
    97     // ToDo:  check if deprecated API
       
    98     setTitle("Control Panel");
       
    99 
       
   100     // assign automatically created widgets to local variables
       
   101 
       
   102     mDeviceIcon=0;
       
   103     // can't use qobject_cast since HbIcon is not derived from QObject!
       
   104     mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "icon" ) );  
       
   105     BTUI_ASSERT_X( mDeviceIcon != 0, "bt-search-view", "Device Icon not found" );
       
   106     
       
   107     mDeviceName=0;
       
   108     mDeviceName = qobject_cast<HbLabel *>( mLoader->findWidget( "label_found_devices" ) );
       
   109     BTUI_ASSERT_X( mDeviceName != 0, "bt-search-view", "Device Name not found" );
       
   110         
       
   111     mDeviceList=0;
       
   112     mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "deviceList" ) );
       
   113     BTUI_ASSERT_X( mDeviceList != 0, "bt-search-view", "Device List not found" );   
       
   114     
       
   115     
       
   116 //    // set model to list view
       
   117 //    mDeviceList->setModel( mFilterProxy );
       
   118 //    // define settings for list view
       
   119 //    mDeviceList->setSelectionMode(HbAbstractItemView::SingleSelection);
       
   120 //    // set prototype item for list view
       
   121 //    BtUiDevListGridItem *item = new BtUiDevListGridItem( mDeviceList ); 
       
   122 //    mDeviceList->setItemPrototype(item);
       
   123 //    // connect to list view pressed signal
       
   124 //    ret = connect( mDeviceList, SIGNAL(pressed(QModelIndex)),this, SLOT(itemActivated(QModelIndex)) );
       
   125 //    BTUI_ASSERT_X( ret, "bt-search-view", "device list can't connect" ); 
       
   126     
       
   127     // read landscape orientation section from docml file if needed
       
   128 //    mOrientation = ((BTUIViewManager*)parent)->orientation();
       
   129     mOrientation = Qt::Vertical;
       
   130     if (mOrientation == Qt::Horizontal) {
       
   131         mLoader->load(BTUI_SEARCHVIEW_DOCML, "landscape", &ok);
       
   132         BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" );
       
   133     }
       
   134 
       
   135     
       
   136     // load tool bar actions
       
   137     HbAction *viewByAction = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) );
       
   138     BTUI_ASSERT_X( viewByAction, "bt-search-view", "view by action missing" ); 
       
   139 //    ret = connect(viewByAction, SIGNAL(triggered()), this, SLOT(noOp()));
       
   140 //    BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); 
       
   141 
       
   142     HbAction *stopAction = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) );
       
   143     BTUI_ASSERT_X( stopAction, "bt-search-view", "view by action missing" ); 
       
   144 //    ret = connect(stopAction, SIGNAL(triggered()), this, SLOT(noOp()));
       
   145 //    BTUI_ASSERT_X( ret, "bt-search-view", "stopAction can't connect" ); 
       
   146 
       
   147     HbAction *retryAction = static_cast<HbAction*>( mLoader->findObject( "retryAction" ) );
       
   148     BTUI_ASSERT_X( retryAction, "bt-search-view", "view by action missing" ); 
       
   149 //    ret = connect(retryAction, SIGNAL(triggered()), this, SLOT(noOp()));
       
   150 //    BTUI_ASSERT_X( ret, "bt-search-view", "retryAction can't connect" ); 
       
   151 
       
   152     
       
   153     // load menu
       
   154     HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
       
   155     BTUI_ASSERT_X( optionsMenu != 0, "bt-search-view", "Options menu not found" );   
       
   156     this->setMenu(optionsMenu);
       
   157         
       
   158     
       
   159     // update display when setting data changed
       
   160 //    ret = connect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), 
       
   161 //            this, SLOT(updateSettingItems(QModelIndex,QModelIndex)));
       
   162 //    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "can't connect dataChanged" );
       
   163     
       
   164 //    QModelIndex top = mModel->index( Btuim::LocalDeviceName, KDefaultColumn );
       
   165 //    QModelIndex bottom = mModel->index( Btuim::Visibility, KDefaultColumn );
       
   166 //    // update name, power and visibility rows
       
   167 //    updateSettingItems( top, bottom );
       
   168 
       
   169  
       
   170 }
       
   171 
       
   172 BtCpUiSearchView::~BtCpUiSearchView()
       
   173 {
       
   174     setNavigationAction(0);
       
   175     delete mSoftKeyBackAction;
       
   176 }
       
   177 
       
   178 void BtCpUiSearchView::deviceSelected(const QModelIndex& modelIndex)
       
   179 {
       
   180     int row = modelIndex.row();
       
   181 }
       
   182 
       
   183 void BtCpUiSearchView::setSoftkeyBack()
       
   184 {
       
   185     if (navigationAction() != mSoftKeyBackAction) {
       
   186         setNavigationAction(mSoftKeyBackAction);
       
   187         connect( mSoftKeyBackAction, SIGNAL(triggered()), this, SLOT(switchToPreviousView()) );
       
   188     }
       
   189 }
       
   190 
       
   191 void BtCpUiSearchView::switchToPreviousView()
       
   192 {
       
   193     BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView");
       
   194     // jump to previous view of current view.
       
   195     mSearchView->deactivateView();
       
   196     
       
   197     // set the new current view 
       
   198     mMainWindow->setCurrentView( mMainView );
       
   199 
       
   200     // do preparation or some actions when new view is activated 
       
   201     mMainView->activateView( 0, 0 );
       
   202 
       
   203 }
       
   204 
       
   205 void BtCpUiSearchView::activateView( const QVariant& value, int cmdId )
       
   206 {
       
   207     Q_UNUSED(value);
       
   208     Q_UNUSED(cmdId);  
       
   209     
       
   210     setSoftkeyBack();
       
   211 }
       
   212 
       
   213 void BtCpUiSearchView::deactivateView()
       
   214 {
       
   215 }