bluetoothengine/btnotif/btdevicedialogplugin/src/btmoredevicesdialogwidget.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     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 "btmoredevicesdialogwidget.h"
       
    19 #include <hblabel.h>
       
    20 #include <hblistview.h>
       
    21 #include <hbtoolbar.h>
       
    22 #include <hbpushbutton.h>
       
    23 #include <hblistwidget.h>
       
    24 #include <qstandarditemmodel.h>
       
    25 #include <btuidevtypemap.h>
       
    26 #include <btuiiconutil.h>
       
    27 #include <bluetoothdevicedialogs.h>
       
    28 
       
    29 
       
    30 
       
    31 const char* DOCML_BT_MORE_DEV_DIALOG = ":/docml/bt-more-devices-dialog.docml";
       
    32 
       
    33 
       
    34 BTMoreDevicesDialogWidget::BTMoreDevicesDialogWidget(const QVariantMap &parameters)
       
    35     {
       
    36     mDeviceDialogData = 0;
       
    37     mLoader = 0;
       
    38     mContentItemModel = 0;
       
    39     constructDialog(parameters);
       
    40 /*    try 
       
    41             {
       
    42             //May throws badAlloc on exception
       
    43             constructDialog(parameters);
       
    44             }
       
    45         catch(std::bad_alloc &badAlloc)
       
    46             {
       
    47             //Failure to allocate memory
       
    48             Q_UNUSED(badAlloc);
       
    49           //   = UnknownDeviceDialogError;
       
    50             }*/
       
    51     }
       
    52 
       
    53 BTMoreDevicesDialogWidget::~BTMoreDevicesDialogWidget()
       
    54     {
       
    55     delete mLoader;
       
    56     delete mContentItemModel;
       
    57     }
       
    58 
       
    59 bool BTMoreDevicesDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
       
    60     {
       
    61     double cod  = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)).toDouble();
       
    62     int uiMajorDevice;
       
    63     int uiMinorDevice;
       
    64 
       
    65     BtuiDevProperty::mapDeiveType(uiMajorDevice, uiMinorDevice, cod);
       
    66     if ((uiMajorDevice & BtuiDevProperty::Phone)||(uiMajorDevice & BtuiDevProperty::Computer) )
       
    67         {
       
    68         BtSendDataItem devData;
       
    69         devData[NameAliasRole] = QVariant(parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceName)).toString());
       
    70         devData[ReadableBdaddrRole] = QVariant(parameters.value(QString::number(TBluetoothDialogParams::EAddress)).toString());
       
    71         devData[CoDRole] = QVariant(cod);
       
    72         
       
    73         setMajorProperty(devData,BtuiDevProperty::Bonded,
       
    74                 parameters.value("Bonded").toBool());
       
    75         setMajorProperty(devData,BtuiDevProperty::Blocked,
       
    76                 parameters.value("Blocked").toBool());
       
    77         setMajorProperty(devData,BtuiDevProperty::Trusted,
       
    78                 parameters.value("Trusted").toBool());
       
    79         setMajorProperty(devData,BtuiDevProperty::Connected,
       
    80                 parameters.value("Connected").toBool());
       
    81         mData.append(devData);
       
    82         
       
    83         QStandardItem* listitem = new QStandardItem();
       
    84         QStringList info;
       
    85         info.append(devData[NameAliasRole].toString());
       
    86 
       
    87         listitem->setData(info, Qt::DisplayRole);
       
    88         HbIcon icon =  getBadgedDeviceTypeIcon(devData[CoDRole].toDouble(),
       
    89                 devData[MajorPropertyRole].toInt(),
       
    90                 BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight);        
       
    91         listitem->setIcon(icon.qicon());
       
    92      //   listitem->setIcon(icon(parameters.value("deviceType").toString()));
       
    93         
       
    94         mContentItemModel->appendRow(listitem);        
       
    95         }
       
    96     return true;
       
    97     }
       
    98 
       
    99 
       
   100 
       
   101 
       
   102 int BTMoreDevicesDialogWidget::deviceDialogError() const
       
   103     {
       
   104     return 0;
       
   105     }
       
   106 
       
   107 void BTMoreDevicesDialogWidget::closeDeviceDialog(bool byClient)
       
   108     {
       
   109     Q_UNUSED(byClient);
       
   110     // below code is required and written based on the documentation of closeDeviceDialog API
       
   111     mMoreDeviceDialog->close();
       
   112     QVariantMap val;
       
   113     QVariant index(-1);
       
   114     val.insert("selectedindex",index);
       
   115     emit deviceDialogData(val);    
       
   116     //below signal is emitted to make dialog server aware that our dialog is closed
       
   117     emit deviceDialogClosed();
       
   118     }
       
   119 
       
   120 HbPopup* BTMoreDevicesDialogWidget::deviceDialogWidget() const
       
   121     {
       
   122     return mMoreDeviceDialog;
       
   123     }
       
   124 
       
   125 QObject* BTMoreDevicesDialogWidget::signalSender() const
       
   126     {
       
   127     return const_cast<BTMoreDevicesDialogWidget*>(this);
       
   128     }
       
   129 
       
   130 bool BTMoreDevicesDialogWidget::constructDialog(const QVariantMap &/*parameters*/)
       
   131     {
       
   132     mLoader = new HbDocumentLoader();
       
   133     bool ok = false;
       
   134     
       
   135     mLoader->load(DOCML_BT_MORE_DEV_DIALOG, &ok);
       
   136     if(ok)
       
   137         {
       
   138         mMoreDeviceDialog = qobject_cast<HbDialog*>(mLoader->findWidget("lastuseddialog"));
       
   139         mMoreDeviceDialog->setFrameType(HbDialog::Strong);
       
   140         mMoreDeviceDialog->setBackgroundFaded(false);
       
   141 /*        HbLabel* label = qobject_cast<HbLabel*>(mLoader->findWidget("label"));
       
   142         if(label)
       
   143             {
       
   144             label->setTextWrapping(Hb::TextWordWrap);
       
   145             label->setPlainText("Send to:");
       
   146             }
       
   147         this->setHeadingWidget(label);*/
       
   148    //     HbPushButton* moreDevices = qobject_cast<HbPushButton*>(mLoader->findWidget("moreDevices"));
       
   149     //    HbPushButton* cancel = qobject_cast<HbPushButton*>(mLoader->findWidget("cancel"));
       
   150         
       
   151         HbListView* listView = qobject_cast<HbListView*>(mLoader->findWidget("listView"));
       
   152         listView->setSelectionMode(HbAbstractItemView::SingleSelection);
       
   153 
       
   154         mContentItemModel = new QStandardItemModel(this);
       
   155         listView->setModel(mContentItemModel);//, prototype);
       
   156         
       
   157  //       QList<QVariant> values = parameters.values();
       
   158         
       
   159  /*       for(int i=0;i < values.count();i++)
       
   160             {
       
   161             QStandardItem* listitem = new QStandardItem();
       
   162             // parameters.
       
   163       //      QString string = values.at(i).toString();
       
   164                         
       
   165             listitem->setData(values.at(i).toString(), Qt::DisplayRole);
       
   166    //         listitem->setData(QString("search"), Qt::DisplayRole);
       
   167             //Todo - Insert icons based on the device class        
       
   168             QIcon icon(QString(":/qgn_prop_sml_bt.svg"));
       
   169             listitem->setIcon(icon);
       
   170         
       
   171             mContentItemModel->appendRow(listitem);
       
   172             }*/
       
   173         
       
   174         connect(listView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
       
   175   //      connect(moreDevices, SIGNAL(clicked()), this, SLOT(moreDevicesClicked()));
       
   176    //     connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
       
   177         mMoreAction = static_cast<HbAction*>( mLoader->findObject( "moreaction" ) );
       
   178         mMoreAction->disconnect(mMoreDeviceDialog);
       
   179         
       
   180         mCancelAction = static_cast<HbAction*>( mLoader->findObject( "cancelaction" ) );
       
   181         mCancelAction->disconnect(mMoreDeviceDialog);
       
   182 //        QGraphicsWidget *widget = mLoader->findWidget(QString("container"));
       
   183   //      mMoreDeviceDialog->setContentWidget(widget);
       
   184         
       
   185          connect(mMoreAction, SIGNAL(triggered()), this, SLOT(moreDevicesClicked()));
       
   186          connect(mCancelAction, SIGNAL(triggered()), this, SLOT(cancelClicked()));
       
   187                
       
   188         }
       
   189 
       
   190 
       
   191     mMoreDeviceDialog->setBackgroundFaded(false);
       
   192     mMoreDeviceDialog->setDismissPolicy(HbPopup::NoDismiss);
       
   193     mMoreDeviceDialog->setTimeout(HbPopup::NoTimeout);
       
   194     mMoreDeviceDialog->setAttribute(Qt::WA_DeleteOnClose);
       
   195     return true;
       
   196     }
       
   197 
       
   198 /*void BTMoreDevicesDialogWidget::hideEvent(QHideEvent *event)
       
   199     {
       
   200     //HbDialog::hideEvent(event);
       
   201     mMoreDeviceDialog->hideEvent(event);
       
   202 //    if(mDeviceDialogData == 0)
       
   203         {
       
   204         QVariantMap val;
       
   205         QVariant index(-1);
       
   206         val.insert("selectedindex",index);
       
   207         emit deviceDialogData(val);    
       
   208         emit deviceDialogClosed();
       
   209         }*/    
       
   210  //   
       
   211    // }
       
   212 
       
   213 /*void BTMoreDevicesDialogWidget::showEvent(QShowEvent *event)
       
   214     {
       
   215     //HbDialog::showEvent(event);
       
   216     }*/
       
   217 
       
   218 void BTMoreDevicesDialogWidget::moreDevicesClicked()
       
   219     {
       
   220     QVariantMap val;
       
   221     QVariant index("MoreDevices");
       
   222     val.insert("MoreDevices",index);    
       
   223     emit deviceDialogData(val);
       
   224  //   mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog
       
   225    // this->close();
       
   226     // TODO
       
   227     }
       
   228 
       
   229 void BTMoreDevicesDialogWidget::cancelClicked()
       
   230     {
       
   231     // TODO
       
   232     mMoreDeviceDialog->close();
       
   233     QVariantMap val;
       
   234     QVariant index(-1);
       
   235     val.insert("selectedindex",index);
       
   236     emit deviceDialogData(val);    
       
   237     emit deviceDialogClosed();
       
   238     }
       
   239 
       
   240 void BTMoreDevicesDialogWidget::deviceSelected(const QModelIndex& modelIndex)
       
   241     {
       
   242     int row = modelIndex.row();
       
   243     QVariantMap val;
       
   244 //    QVariant index(row);
       
   245     const BtSendDataItem& qtdev = mData.at(row);
       
   246     val.insert("selectedindex",QVariant(row));
       
   247     val.insert("devicename",QVariant(qtdev[NameAliasRole]));
       
   248     val.insert("deviceaddress",QVariant(qtdev[ReadableBdaddrRole]));
       
   249     val.insert("deviceclass",QVariant(qtdev[CoDRole]));
       
   250     emit deviceDialogData(val);
       
   251   //  mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog    
       
   252    // this->close();
       
   253 
       
   254     }
       
   255   
       
   256 QIcon BTMoreDevicesDialogWidget::icon(/*QString deviceType*/)
       
   257     {
       
   258  /*   if(deviceType == "Audio")
       
   259         {
       
   260         return (QIcon(QString(":/qgn_prop_bt_audio.svg")));
       
   261         }
       
   262     else if(deviceType == "Car-kit")
       
   263         {
       
   264         return (QIcon(QString(":/qgn_prop_bt_car_kit.svg")));
       
   265         }
       
   266     else if(deviceType == "Computer")
       
   267         {
       
   268         return (QIcon(QString(":/qgn_prop_bt_computer.svg")));
       
   269         }
       
   270     else if(deviceType == "Headset")
       
   271         {
       
   272         return (QIcon(QString(":/qgn_prop_bt_headset.svg")));
       
   273         }
       
   274     else if(deviceType == "Keyboard")
       
   275         {
       
   276         return (QIcon(QString(":/qgn_prop_bt_keyboard.svg")));
       
   277         }
       
   278     else if(deviceType == "Mouse")
       
   279         {
       
   280         return (QIcon(QString(":/qgn_prop_bt_mouse.svg")));
       
   281         }
       
   282     else if(deviceType == "Phone")
       
   283         {
       
   284         return (QIcon(QString(":/qgn_prop_bt_phone.svg")));
       
   285         }
       
   286     else if(deviceType == "Printer")
       
   287         {
       
   288         return (QIcon(QString(":/qgn_prop_bt_printer.svg")));
       
   289         }
       
   290     else
       
   291         {
       
   292         return (QIcon(QString(":/qgn_prop_bt_unknown.svg")));
       
   293         }*/
       
   294     return QIcon(QString(":/icons/qtg_large_bluetooth.svg"));
       
   295     }
       
   296