bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp
changeset 70 f5508c13dfe0
parent 57 5ebadcda06cb
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
     1 /*
     1 /*
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved.
     3  * All rights reserved.
     4  * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5  * under the terms of "Eclipse Public License v1.0""
     5  * under the terms of "Eclipse Public License v1.0""
     6  * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    28 #include <qtranslator.h>
    28 #include <qtranslator.h>
    29 #include <qcoreapplication.h>
    29 #include <qcoreapplication.h>
    30 #include <bluetoothdevicedialogs.h>
    30 #include <bluetoothdevicedialogs.h>
    31 #include <btuidevtypemap.h>
    31 #include <btuidevtypemap.h>
    32 #include <btuiiconutil.h>
    32 #include <btuiiconutil.h>
       
    33 #include "btdevicedialogpluginerrors.h"
    33 
    34 
    34 const char* DOCML_BTDEV_SEARCH_DIALOG = ":/docml/bt-device-search-dialog.docml";
    35 const char* DOCML_BTDEV_SEARCH_DIALOG = ":/docml/bt-device-search-dialog.docml";
    35 
    36 
    36 
    37 
    37 #define LOC_SEARCHING_DEVICE hbTrId("txt_bt_subhead_searching")
    38 #define LOC_SEARCHING_DEVICE hbTrId("txt_bt_subhead_searching")
    46     mSelectedDeviceType = 0;
    47     mSelectedDeviceType = 0;
    47     mLoader = 0;
    48     mLoader = 0;
    48     mContentItemModel = 0;
    49     mContentItemModel = 0;
    49     mStopRetryFlag = 0; // Stop 
    50     mStopRetryFlag = 0; // Stop 
    50     mQuery = 0;
    51     mQuery = 0;
       
    52     mLastError = NoError;
    51     mSelectedDeviceType |= (BtuiDevProperty::AVDev | BtuiDevProperty::Computer |
    53     mSelectedDeviceType |= (BtuiDevProperty::AVDev | BtuiDevProperty::Computer |
    52             BtuiDevProperty::Phone | BtuiDevProperty::Peripheral |
    54             BtuiDevProperty::Phone | BtuiDevProperty::Peripheral |
    53             BtuiDevProperty::LANAccessDev | BtuiDevProperty::Toy |
    55             BtuiDevProperty::LANAccessDev | BtuiDevProperty::Toy |
    54             BtuiDevProperty::WearableDev | BtuiDevProperty::ImagingDev |
    56             BtuiDevProperty::WearableDev | BtuiDevProperty::ImagingDev |
    55             BtuiDevProperty::HealthDev | BtuiDevProperty::UncategorizedDev);       
    57             BtuiDevProperty::HealthDev | BtuiDevProperty::UncategorizedDev);       
    66     }
    68     }
    67 }
    69 }
    68 
    70 
    69 bool BTDeviceSearchDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
    71 bool BTDeviceSearchDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
    70 {
    72 {
    71     if(parameters.keys().contains("Search Completed"))
    73     if(!mLastError)
    72     {
    74     {
    73         mStopRetryFlag = 1; // Retry 
    75         if(parameters.keys().contains("Search Completed"))
    74         mSearchLabel->hide();
    76         {
    75         
    77             mStopRetryFlag = 1; // Retry 
    76         mSearchIconLabel->hide();
    78             mSearchLabel->hide();
    77         
    79             
    78         mSearchDoneLabel->show();
    80             mSearchIconLabel->hide();
    79         mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap);
    81             
    80         mSearchDoneLabel->setAlignment(Qt::AlignLeft);
    82             mSearchDoneLabel->show();
    81         mSearchDoneLabel->setPlainText(LOC_SEARCH_DONE);
    83             mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap);
    82         
    84             mSearchDoneLabel->setAlignment(Qt::AlignLeft);
    83         mStopRetryAction->setText(LOC_SEARCH_RETRY);
    85             mSearchDoneLabel->setPlainText(LOC_SEARCH_DONE);
       
    86             
       
    87             mStopRetryAction->setText(LOC_SEARCH_RETRY);
       
    88         }
       
    89         else
       
    90         {
       
    91             int cod  = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)).toInt();
       
    92             int uiMajorDevice;
       
    93             int uiMinorDevice;
       
    94         
       
    95             BtuiDevProperty::mapDeiveType(uiMajorDevice, uiMinorDevice, cod);
       
    96     
       
    97             BtSendDataItem devData;
       
    98             //TODO Need to create string constant for Name as enum EDeviceName is not working for this
       
    99             devData[NameAliasRole] =parameters.value("Name").toString();
       
   100             devData[ReadableBdaddrRole] = parameters.value(QString::number(TBluetoothDeviceDialog::EAddress));
       
   101             devData[CoDRole] = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass));
       
   102             devData[DeviceTypeRole] = QVariant(uiMajorDevice);
       
   103             setMajorProperty(devData,BtuiDevProperty::Bonded,
       
   104                     parameters.value("Bonded").toBool());
       
   105             setMajorProperty(devData,BtuiDevProperty::Blocked,
       
   106                     parameters.value("Blocked").toBool());
       
   107             setMajorProperty(devData,BtuiDevProperty::Trusted,
       
   108                     parameters.value("Trusted").toBool());
       
   109             setMajorProperty(devData,BtuiDevProperty::Connected,
       
   110                     parameters.value("Connected").toBool());
       
   111             mData.append(devData);
       
   112             
       
   113             if(mSelectedDeviceType & devData[DeviceTypeRole].toInt())
       
   114             {
       
   115                 QStandardItem* listitem = new QStandardItem();
       
   116                 QStringList info;
       
   117                 info.append(devData[NameAliasRole].toString());
       
   118                 listitem->setData(info, Qt::DisplayRole);
       
   119                 HbIcon icon =  getBadgedDeviceTypeIcon(devData[CoDRole].toInt(),
       
   120                         devData[MajorPropertyRole].toInt(),
       
   121                         BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight);
       
   122                 listitem->setIcon(icon.qicon());
       
   123                 mContentItemModel->appendRow(listitem);    
       
   124                 mSelectedData.append(devData);
       
   125             }
       
   126         }
       
   127         return true;
    84     }
   128     }
    85     else
   129     else
    86     {
   130     {
    87         int cod  = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)).toInt();
   131         return false;
    88         int uiMajorDevice;
   132     }
    89         int uiMinorDevice;
       
    90     
       
    91         BtuiDevProperty::mapDeiveType(uiMajorDevice, uiMinorDevice, cod);
       
    92 
       
    93         BtSendDataItem devData;
       
    94         //TODO Need to create string constant for Name as enum EDeviceName is not working for this
       
    95         devData[NameAliasRole] =parameters.value("Name").toString();
       
    96         devData[ReadableBdaddrRole] = parameters.value(QString::number(TBluetoothDeviceDialog::EAddress));
       
    97         devData[CoDRole] = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass));
       
    98         devData[DeviceTypeRole] = QVariant(uiMajorDevice);
       
    99         setMajorProperty(devData,BtuiDevProperty::Bonded,
       
   100                 parameters.value("Bonded").toBool());
       
   101         setMajorProperty(devData,BtuiDevProperty::Blocked,
       
   102                 parameters.value("Blocked").toBool());
       
   103         setMajorProperty(devData,BtuiDevProperty::Trusted,
       
   104                 parameters.value("Trusted").toBool());
       
   105         setMajorProperty(devData,BtuiDevProperty::Connected,
       
   106                 parameters.value("Connected").toBool());
       
   107         mData.append(devData);
       
   108         
       
   109         if(mSelectedDeviceType & devData[DeviceTypeRole].toInt())
       
   110         {
       
   111             QStandardItem* listitem = new QStandardItem();
       
   112             QStringList info;
       
   113             info.append(devData[NameAliasRole].toString());
       
   114             listitem->setData(info, Qt::DisplayRole);
       
   115             HbIcon icon =  getBadgedDeviceTypeIcon(devData[CoDRole].toInt(),
       
   116                     devData[MajorPropertyRole].toInt(),
       
   117                     BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight);
       
   118             listitem->setIcon(icon.qicon());
       
   119             mContentItemModel->appendRow(listitem);    
       
   120             mSelectedData.append(devData);
       
   121         }
       
   122     }
       
   123                 
       
   124     return true;
       
   125 }
   133 }
   126 
   134 
   127 int BTDeviceSearchDialogWidget::deviceDialogError() const
   135 int BTDeviceSearchDialogWidget::deviceDialogError() const
   128 {
   136 {
   129     return 0;
   137     return mLastError;
   130 }
   138 }
   131 
   139 
   132 void BTDeviceSearchDialogWidget::closeDeviceDialog(bool byClient)
   140 void BTDeviceSearchDialogWidget::closeDeviceDialog(bool byClient)
   133 {
   141 {
   134     Q_UNUSED(byClient);
   142     Q_UNUSED(byClient);
   151 QObject* BTDeviceSearchDialogWidget::signalSender() const
   159 QObject* BTDeviceSearchDialogWidget::signalSender() const
   152 {
   160 {
   153     return const_cast<BTDeviceSearchDialogWidget*>(this);
   161     return const_cast<BTDeviceSearchDialogWidget*>(this);
   154 }
   162 }
   155 
   163 
   156 bool BTDeviceSearchDialogWidget::constructDialog(const QVariantMap &parameters)
   164 void BTDeviceSearchDialogWidget::constructDialog(const QVariantMap &parameters)
   157 {
   165 {
   158     (void) parameters;
   166     Q_UNUSED(parameters);
   159     bool ok = false;
   167     bool ok = false;
   160     
   168     
   161     mLoader = new HbDocumentLoader();
   169     mLoader = new HbDocumentLoader();
   162     mLoader->load(DOCML_BTDEV_SEARCH_DIALOG, &ok);
   170     mLoader->load(DOCML_BTDEV_SEARCH_DIALOG, &ok);
   163     if(ok)
   171     if(ok)
   194         
   202         
   195         connect(mShowAction, SIGNAL(triggered()), this, SLOT(viewByClicked()));
   203         connect(mShowAction, SIGNAL(triggered()), this, SLOT(viewByClicked()));
   196         connect(mStopRetryAction, SIGNAL(triggered()), this, SLOT(stopRetryClicked()));
   204         connect(mStopRetryAction, SIGNAL(triggered()), this, SLOT(stopRetryClicked()));
   197 
   205 
   198         connect(mSearchDevicesDialog, SIGNAL(aboutToClose()), this, SLOT(searchDialogClosed()));
   206         connect(mSearchDevicesDialog, SIGNAL(aboutToClose()), this, SLOT(searchDialogClosed()));
   199     }
   207         mSearchDevicesDialog->setBackgroundFaded(false);
   200     mSearchDevicesDialog->setBackgroundFaded(false);
   208         mSearchDevicesDialog->setDismissPolicy(HbPopup::NoDismiss);
   201     mSearchDevicesDialog->setDismissPolicy(HbPopup::NoDismiss);
   209         mSearchDevicesDialog->setTimeout(HbPopup::NoTimeout);
   202     mSearchDevicesDialog->setTimeout(HbPopup::NoTimeout);
   210         mSearchDevicesDialog->setAttribute(Qt::WA_DeleteOnClose);
   203     mSearchDevicesDialog->setAttribute(Qt::WA_DeleteOnClose);
   211         
   204     
   212         mDevTypeList << hbTrId("txt_bt_list_audio_devices")
   205     mDevTypeList << hbTrId("txt_bt_list_audio_devices")
   213                 << hbTrId("txt_bt_list_computers") 
   206             << hbTrId("txt_bt_list_computers") 
   214                 << hbTrId("txt_bt_list_input_devices") 
   207             << hbTrId("txt_bt_list_input_devices") 
   215                 << hbTrId("txt_bt_list_phones") 
   208             << hbTrId("txt_bt_list_phones") 
   216                 << hbTrId("txt_bt_list_other_devices");
   209             << hbTrId("txt_bt_list_other_devices");
   217     }
   210     
   218     else
   211     return true;
   219     {
       
   220         mLastError = DocMLLoadingError;			    		    		
       
   221     }
       
   222 
   212 }
   223 }
   213 
   224 
   214 
   225 
   215 void BTDeviceSearchDialogWidget::stopRetryClicked()
   226 void BTDeviceSearchDialogWidget::stopRetryClicked()
   216 {
   227 {