bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp
changeset 19 43824b19ee35
child 31 a0ea99b6fa53
equal deleted inserted replaced
17:f05641c183ff 19:43824b19ee35
       
     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 
       
    19 #include "btdevicesearchdialogwidget.h"
       
    20 #include <hblabel.h>
       
    21 #include <hblistview.h>
       
    22 #include <hbtoolbar.h>
       
    23 #include <hbpushbutton.h>
       
    24 #include <qstandarditemmodel.h>
       
    25 
       
    26 const char* DOCML_BTDEV_SEARCH_DIALOG = ":/docml/bt-device-search-dialog.docml";
       
    27 
       
    28 
       
    29 BTDeviceSearchDialogWidget::BTDeviceSearchDialogWidget(const QVariantMap &parameters)
       
    30 :HbDialog()
       
    31     {
       
    32     mDeviceLstIdx = 0;
       
    33     mViewByChosen = false;
       
    34     mSelectedType = 0;
       
    35     mDeviceDialogData = 0;
       
    36     constructDialog(parameters);
       
    37     }
       
    38 
       
    39 BTDeviceSearchDialogWidget::~BTDeviceSearchDialogWidget()
       
    40     {
       
    41     delete mLoader;
       
    42     mLoader = NULL;
       
    43     delete mContentItemModel;
       
    44     mContentItemModel = NULL;
       
    45  //   delete mRbl;
       
    46  //   delete mViewByDialog;
       
    47     }
       
    48 
       
    49 bool BTDeviceSearchDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
       
    50     {
       
    51     device newDevice;
       
    52 
       
    53    // newDevice.mDeviceName = parameters.value("deviceName").toString();
       
    54     newDevice.mDeviceName = parameters.value(parameters.keys().at(0)).toString();
       
    55     
       
    56  //   newDevice.mDeviceType = parameters.value("deviceType").toString();
       
    57     newDevice.mDeviceIdx = mDeviceLstIdx;
       
    58     
       
    59     mDeviceList.append(newDevice);
       
    60     mDeviceLstIdx++;
       
    61     
       
    62 
       
    63     QStringList info;
       
    64  //   if(!mViewByChosen)
       
    65         {
       
    66         info.append(newDevice.mDeviceName);
       
    67    //     info.append(newDevice.mDeviceType);
       
    68         QStandardItem* listitem = new QStandardItem();
       
    69         listitem->setData(info, Qt::DisplayRole);
       
    70     
       
    71         listitem->setIcon(icon());
       
    72     
       
    73         mContentItemModel->appendRow(listitem);
       
    74         }
       
    75  /*   else
       
    76         {
       
    77         if(mDeviceTypeList[mSelectedType] == newDevice.mDeviceType)
       
    78             {
       
    79             info.append(newDevice.mDeviceName);
       
    80             info.append(newDevice.mDeviceType);
       
    81             QStandardItem* listitem = new QStandardItem();
       
    82             listitem->setData(info, Qt::DisplayRole);
       
    83 
       
    84             listitem->setIcon(icon(newDevice.mDeviceType));
       
    85 
       
    86             mContentItemModel->appendRow(listitem);
       
    87             }
       
    88         }*/
       
    89                 
       
    90     return true;
       
    91     }
       
    92 
       
    93 int BTDeviceSearchDialogWidget::deviceDialogError() const
       
    94     {
       
    95     return 0;
       
    96     }
       
    97 
       
    98 void BTDeviceSearchDialogWidget::closeDeviceDialog(bool byClient)
       
    99     {
       
   100     Q_UNUSED(byClient);
       
   101     this->close();
       
   102     }
       
   103 
       
   104 HbPopup* BTDeviceSearchDialogWidget::deviceDialogWidget() const
       
   105     {
       
   106     return const_cast<BTDeviceSearchDialogWidget*>(this);
       
   107     }
       
   108 
       
   109 bool BTDeviceSearchDialogWidget::constructDialog(const QVariantMap &parameters)
       
   110     {
       
   111     (void) parameters;
       
   112     mLoader = new HbDocumentLoader();
       
   113     bool ok = false;
       
   114     
       
   115     mLoader->load(DOCML_BTDEV_SEARCH_DIALOG, &ok);
       
   116     if(ok)
       
   117         {
       
   118         HbLabel* label = qobject_cast<HbLabel*>(mLoader->findWidget("heading"));
       
   119         if(label)
       
   120             {
       
   121             label->setTextWrapping(Hb::TextWordWrap);
       
   122             label->setAlignment(Qt::AlignHCenter);
       
   123             label->setPlainText("Bluetooth - Found devices");
       
   124             }
       
   125         this->setHeadingWidget(label);
       
   126         this->setFrameType(HbDialog::Strong);
       
   127         this->setBackgroundFaded(false);
       
   128 
       
   129         HbPushButton* viewBy = qobject_cast<HbPushButton*>(mLoader->findWidget("viewBy"));
       
   130         HbPushButton* stop = qobject_cast<HbPushButton*>(mLoader->findWidget("stop"));
       
   131         HbPushButton* retry = qobject_cast<HbPushButton*>(mLoader->findWidget("retry"));
       
   132         
       
   133         mListView = qobject_cast<HbListView*>(mLoader->findWidget("listView"));
       
   134         mListView->setSelectionMode(HbAbstractItemView::SingleSelection);
       
   135 
       
   136         mContentItemModel = new QStandardItemModel(this);
       
   137         mListView->setModel(mContentItemModel);//, prototype);
       
   138 
       
   139         connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
       
   140         connect(stop, SIGNAL(clicked()), this, SLOT(stopClicked()));
       
   141         connect(retry, SIGNAL(clicked()), this, SLOT(retryClicked()));
       
   142         connect(viewBy, SIGNAL(clicked()), this, SLOT(viewByClicked()));
       
   143         
       
   144         QGraphicsWidget *widget = mLoader->findWidget(QString("container"));
       
   145         this->setContentWidget(widget);
       
   146         }
       
   147     else
       
   148         {
       
   149 
       
   150         }
       
   151 
       
   152     this->setBackgroundFaded(false);
       
   153     setDismissPolicy(HbPopup::TapOutside);
       
   154     setTimeout(HbPopup::NoTimeout);
       
   155     
       
   156  /*   mViewByDialog = new HbDialog();
       
   157     mRbl = new HbRadioButtonList(mViewByDialog);
       
   158     connect(mRbl, SIGNAL(itemSelected(int)), this, SLOT(viewByItemSelected(int)));*/
       
   159     
       
   160     return true;
       
   161     }
       
   162 
       
   163 void BTDeviceSearchDialogWidget::hideEvent(QHideEvent *event)
       
   164     {
       
   165     HbDialog::hideEvent(event);
       
   166     if(mDeviceDialogData == 0)
       
   167         {
       
   168         QVariantMap val;
       
   169         QVariant index(-1);
       
   170         val.insert("selectedindex",index);
       
   171         emit deviceDialogData(val);    
       
   172         }
       
   173     emit deviceDialogClosed();
       
   174     }
       
   175 
       
   176 void BTDeviceSearchDialogWidget::showEvent(QShowEvent *event)
       
   177     {
       
   178     HbDialog::showEvent(event);
       
   179     }
       
   180 
       
   181 void BTDeviceSearchDialogWidget::stopClicked()
       
   182     {
       
   183     QVariantMap val;
       
   184     QVariant index("Stop");
       
   185     val.insert("Stop",index); 
       
   186     emit deviceDialogData(val);
       
   187     }
       
   188 
       
   189 void BTDeviceSearchDialogWidget::retryClicked()
       
   190     {
       
   191     QVariantMap val;
       
   192     QVariant index("Retry");
       
   193     val.insert("Retry",index); 
       
   194     emit deviceDialogData(val);
       
   195     delete mContentItemModel;
       
   196     mContentItemModel = new QStandardItemModel(this);
       
   197     mListView->setModel(mContentItemModel);
       
   198     }
       
   199 
       
   200 //void BTDeviceSearchDialogWidget::viewByClicked()
       
   201 //    {
       
   202 /*    mViewByDialog->setDismissPolicy(HbPopup::NoDismiss);
       
   203     mViewByDialog->setTimeout(HbPopup::NoTimeout);
       
   204 
       
   205     bool foundEntry = false;
       
   206     QStringList st;
       
   207     st << "All";
       
   208     mDeviceTypeList.clear();
       
   209     for(int i = 0; i < mDeviceList.count(); i++)
       
   210         {
       
   211         for(int j = 0; j < mDeviceTypeList.count(); j++)
       
   212             {
       
   213             if(mDeviceTypeList[j] == mDeviceList[i].mDeviceType)
       
   214                 {
       
   215                 foundEntry = true;
       
   216                 break;
       
   217                 }
       
   218             }
       
   219         if(!foundEntry)
       
   220             {
       
   221             mDeviceTypeList.append(mDeviceList[i].mDeviceType);
       
   222             }
       
   223         foundEntry = false;
       
   224         }
       
   225     
       
   226     for(int k = 0; k < mDeviceTypeList.count(); k++)
       
   227         {
       
   228         st << mDeviceTypeList[k];
       
   229         }
       
   230     
       
   231     mRbl->setItems(st);
       
   232     mViewByDialog->setContentWidget(mRbl);
       
   233     mViewByDialog->setMaximumHeight(300);
       
   234     mViewByDialog->setMaximumWidth(500);
       
   235 
       
   236     mViewByDialog->show();*/
       
   237  //   }
       
   238 
       
   239 void BTDeviceSearchDialogWidget::deviceSelected(const QModelIndex& modelIndex)
       
   240     {
       
   241     int row = 0;
       
   242     
       
   243  /*   if(mViewByChosen)
       
   244         {
       
   245         row = mDeviceLstOfType[modelIndex.row()].mDeviceIdx;
       
   246         }
       
   247     
       
   248     else*/
       
   249         {
       
   250         row = modelIndex.row();
       
   251         }
       
   252     
       
   253     QVariantMap val;
       
   254     QVariant index(row);
       
   255     val.insert("selectedindex",index);
       
   256     emit deviceDialogData(val);
       
   257     mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog
       
   258     //emit deviceDialogClosed();
       
   259     this->close();
       
   260     }
       
   261 
       
   262 //void BTDeviceSearchDialogWidget::viewByItemSelected(int index)
       
   263   //  {
       
   264     //  (void) index;
       
   265  /*   if(index == 0)
       
   266         {
       
   267         //Option 'All' selected    
       
   268         mViewByDialog->close();
       
   269         delete mContentItemModel;
       
   270         mContentItemModel = new QStandardItemModel(this);
       
   271         mListView->setModel(mContentItemModel);
       
   272         mViewByChosen = false;
       
   273 
       
   274         for(int i = 0; i < mDeviceList.count(); i++)
       
   275             {        
       
   276             QStandardItem* listitem = new QStandardItem();
       
   277                 
       
   278             QStringList info;
       
   279             info << mDeviceList[i].mDeviceName << mDeviceList[i].mDeviceType ;
       
   280             listitem->setData(info, Qt::DisplayRole);
       
   281     
       
   282             //listitem->setIcon(icon(mDeviceList[i].mDeviceType));
       
   283     
       
   284             mContentItemModel->appendRow(listitem);
       
   285             }
       
   286         }
       
   287     else
       
   288         {
       
   289         index--;
       
   290         mSelectedType = index;
       
   291         mViewByDialog->close();
       
   292         
       
   293         delete mContentItemModel;
       
   294         mContentItemModel = new QStandardItemModel(this);
       
   295         mListView->setModel(mContentItemModel);
       
   296     
       
   297         mDeviceLstOfType.clear();
       
   298         for(int i = 0; i < mDeviceList.count(); i++)
       
   299             {
       
   300             if(mDeviceList[i].mDeviceType == mDeviceTypeList[index])
       
   301                 {
       
   302                 mDeviceLstOfType.append(mDeviceList[i]);
       
   303             
       
   304                 QStandardItem* listitem = new QStandardItem();
       
   305                 
       
   306                 QStringList info;
       
   307                 info << mDeviceList[i].mDeviceName << mDeviceTypeList[index];
       
   308                 listitem->setData(info, Qt::DisplayRole);
       
   309         
       
   310                 //listitem->setIcon(icon(mDeviceTypeList[index]));
       
   311         
       
   312                 mContentItemModel->appendRow(listitem);
       
   313                 }
       
   314             }
       
   315         mViewByChosen = true;
       
   316         }*/
       
   317  //   }
       
   318 
       
   319 QIcon BTDeviceSearchDialogWidget::icon()
       
   320     {
       
   321  /*   if(deviceType == "Audio")
       
   322         {
       
   323         return (QIcon(QString(":/icons/qgn_prop_bt_audio.svg")));
       
   324         }
       
   325     else if(deviceType == "Car-kit")
       
   326         {
       
   327         return (QIcon(QString(":/icons/qgn_prop_bt_car_kit.svg")));
       
   328         }
       
   329     else if(deviceType == "Computer")
       
   330         {
       
   331         return (QIcon(QString(":/icons/qgn_prop_bt_computer.svg")));
       
   332         }
       
   333     else if(deviceType == "Headset")
       
   334         {
       
   335         return (QIcon(QString(":/icons/qgn_prop_bt_headset.svg")));
       
   336         }
       
   337     else if(deviceType == "Keyboard")
       
   338         {
       
   339         return (QIcon(QString(":/icons/qgn_prop_bt_keyboard.svg")));
       
   340         }
       
   341     else if(deviceType == "Mouse")
       
   342         {
       
   343         return (QIcon(QString(":/icons/qgn_prop_bt_mouse.svg")));
       
   344         }
       
   345     else if(deviceType == "Phone")
       
   346         {
       
   347         return (QIcon(QString(":/icons/qgn_prop_bt_phone.svg")));
       
   348         }
       
   349     else if(deviceType == "Printer")
       
   350         {
       
   351         return (QIcon(QString(":/icons/qgn_prop_bt_printer.svg")));
       
   352         }
       
   353     else
       
   354         {
       
   355         return (QIcon(QString(":/icons/qgn_prop_bt_unknown.svg")));
       
   356         }*/
       
   357     return QIcon(QString(":/icons/qgn_prop_sml_bt.svg"));
       
   358     }
       
   359