bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp
changeset 31 a0ea99b6fa53
parent 29 48ae3789ce00
child 40 997690c3397a
child 42 b72428996822
equal deleted inserted replaced
30:df7a93ede42e 31:a0ea99b6fa53
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 
    18 
    19 #include "btdevicesearchdialogwidget.h"
    19 #include "btdevicesearchdialogwidget.h"
    20 #include <hblabel.h>
    20 
    21 #include <hblistview.h>
    21 #include <hblistview.h>
    22 #include <hbtoolbar.h>
    22 #include <hbtoolbar.h>
    23 #include <hbpushbutton.h>
    23 #include <hbselectiondialog.h>
       
    24 
    24 #include <qstandarditemmodel.h>
    25 #include <qstandarditemmodel.h>
       
    26 #include <hbaction.h>
    25 
    27 
    26 const char* DOCML_BTDEV_SEARCH_DIALOG = ":/docml/bt-device-search-dialog.docml";
    28 const char* DOCML_BTDEV_SEARCH_DIALOG = ":/docml/bt-device-search-dialog.docml";
    27 
    29 
    28 
    30 
    29 BTDeviceSearchDialogWidget::BTDeviceSearchDialogWidget(const QVariantMap &parameters)
    31 BTDeviceSearchDialogWidget::BTDeviceSearchDialogWidget(const QVariantMap &parameters)
    36     constructDialog(parameters);
    38     constructDialog(parameters);
    37     }
    39     }
    38 
    40 
    39 BTDeviceSearchDialogWidget::~BTDeviceSearchDialogWidget()
    41 BTDeviceSearchDialogWidget::~BTDeviceSearchDialogWidget()
    40     {
    42     {
    41     delete mLoader;
    43     if(mLoader)
    42     mLoader = NULL;
    44         {
    43     delete mContentItemModel;
    45         delete mLoader;
    44     mContentItemModel = NULL;
    46         mLoader = NULL;
       
    47         }
       
    48     if(mContentItemModel)
       
    49         {
       
    50         delete mContentItemModel;
       
    51         mContentItemModel = NULL;
       
    52         }
    45  //   delete mRbl;
    53  //   delete mRbl;
    46  //   delete mViewByDialog;
    54  //   delete mViewByDialog;
    47     }
    55     }
    48 
    56 
    49 bool BTDeviceSearchDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
    57 bool BTDeviceSearchDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
    50     {
    58     {
    51     device newDevice;
    59     if(parameters.keys().at(0).compare("Search Completed")==0)
    52 
    60         {
    53    // newDevice.mDeviceName = parameters.value("deviceName").toString();
    61         mSearchLabel->hide();
    54     newDevice.mDeviceName = parameters.value(parameters.keys().at(0)).toString();
    62         
    55     
    63         mSearchIconLabel->hide();
    56  //   newDevice.mDeviceType = parameters.value("deviceType").toString();
    64         
    57     newDevice.mDeviceIdx = mDeviceLstIdx;
    65         mSearchDoneLabel->show();
    58     
    66         mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap);
    59     mDeviceList.append(newDevice);
    67         mSearchDoneLabel->setAlignment(Qt::AlignLeft);
    60     mDeviceLstIdx++;
    68         mSearchDoneLabel->setPlainText("Search Done");
    61     
    69         
    62 
    70         mStopRetryBtn->setText("Retry");
    63     QStringList info;
    71         }
    64  //   if(!mViewByChosen)
    72     else
    65         {
    73         {
    66         info.append(newDevice.mDeviceName);
    74         device newDevice;
    67    //     info.append(newDevice.mDeviceType);
    75     
    68         QStandardItem* listitem = new QStandardItem();
    76        // newDevice.mDeviceName = parameters.value("deviceName").toString();
    69         listitem->setData(info, Qt::DisplayRole);
    77         newDevice.mDeviceName = parameters.value(parameters.keys().at(0)).toString();
    70     
    78         
    71         listitem->setIcon(icon());
    79      //   newDevice.mDeviceType = parameters.value("deviceType").toString();
    72     
    80         newDevice.mDeviceIdx = mDeviceLstIdx;
    73         mContentItemModel->appendRow(listitem);
    81         
    74         }
    82         mDeviceList.append(newDevice);
    75  /*   else
    83         mDeviceLstIdx++;
    76         {
    84     
    77         if(mDeviceTypeList[mSelectedType] == newDevice.mDeviceType)
    85         QStringList info;
       
    86      //   if(!mViewByChosen)
    78             {
    87             {
    79             info.append(newDevice.mDeviceName);
    88             info.append(newDevice.mDeviceName);
    80             info.append(newDevice.mDeviceType);
    89        //     info.append(newDevice.mDeviceType);
    81             QStandardItem* listitem = new QStandardItem();
    90             QStandardItem* listitem = new QStandardItem();
    82             listitem->setData(info, Qt::DisplayRole);
    91             listitem->setData(info, Qt::DisplayRole);
    83 
    92         
    84             listitem->setIcon(icon(newDevice.mDeviceType));
    93             listitem->setIcon(icon());
    85 
    94         
    86             mContentItemModel->appendRow(listitem);
    95             mContentItemModel->appendRow(listitem);
    87             }
    96             }
    88         }*/
    97      /*   else
       
    98             {
       
    99             if(mDeviceTypeList[mSelectedType] == newDevice.mDeviceType)
       
   100                 {
       
   101                 info.append(newDevice.mDeviceName);
       
   102                 info.append(newDevice.mDeviceType);
       
   103                 QStandardItem* listitem = new QStandardItem();
       
   104                 listitem->setData(info, Qt::DisplayRole);
       
   105     
       
   106                 listitem->setIcon(icon(newDevice.mDeviceType));
       
   107     
       
   108                 mContentItemModel->appendRow(listitem);
       
   109                 }
       
   110             }*/
       
   111         }
    89                 
   112                 
    90     return true;
   113     return true;
    91     }
   114     }
    92 
   115 
    93 int BTDeviceSearchDialogWidget::deviceDialogError() const
   116 int BTDeviceSearchDialogWidget::deviceDialogError() const
   113     bool ok = false;
   136     bool ok = false;
   114     
   137     
   115     mLoader->load(DOCML_BTDEV_SEARCH_DIALOG, &ok);
   138     mLoader->load(DOCML_BTDEV_SEARCH_DIALOG, &ok);
   116     if(ok)
   139     if(ok)
   117         {
   140         {
   118         HbLabel* label = qobject_cast<HbLabel*>(mLoader->findWidget("heading"));
   141         HbLabel* heading = qobject_cast<HbLabel*>(mLoader->findWidget("heading"));
   119         if(label)
   142         heading->setTextWrapping(Hb::TextWordWrap);
   120             {
   143         heading->setAlignment(Qt::AlignHCenter);
   121             label->setTextWrapping(Hb::TextWordWrap);
   144         heading->setPlainText("Bluetooth - Found devices");
   122             label->setAlignment(Qt::AlignHCenter);
   145         setHeadingWidget(heading);
   123             label->setPlainText("Bluetooth - Found devices");
   146         
   124             }
   147         mSearchLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchLabel"));
   125         this->setHeadingWidget(label);
   148         mSearchLabel->setTextWrapping(Hb::TextWordWrap);
   126         this->setFrameType(HbDialog::Strong);
   149         mSearchLabel->setAlignment(Qt::AlignHCenter);
   127         this->setBackgroundFaded(false);
   150         mSearchLabel->setPlainText("Searching...");
   128 
   151  
   129         HbPushButton* viewBy = qobject_cast<HbPushButton*>(mLoader->findWidget("viewBy"));
   152         mSearchIconLabel = qobject_cast<HbLabel*>(mLoader->findWidget("iconLabel"));
   130         HbPushButton* stop = qobject_cast<HbPushButton*>(mLoader->findWidget("stop"));
   153         mSearchIconLabel->setIcon(icon());
   131         HbPushButton* retry = qobject_cast<HbPushButton*>(mLoader->findWidget("retry"));
   154 
       
   155         mSearchDoneLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchDoneLabel"));
       
   156         mSearchDoneLabel->hide();
       
   157         
       
   158         setFrameType(HbDialog::Strong);
       
   159         setBackgroundFaded(false);
       
   160 
       
   161         mViewByBtn = qobject_cast<HbPushButton*>(mLoader->findWidget("viewby"));
       
   162         mStopRetryBtn = qobject_cast<HbPushButton*>(mLoader->findWidget("stop"));
   132         
   163         
   133         mListView = qobject_cast<HbListView*>(mLoader->findWidget("listView"));
   164         mListView = qobject_cast<HbListView*>(mLoader->findWidget("listView"));
   134         mListView->setSelectionMode(HbAbstractItemView::SingleSelection);
   165         mListView->setSelectionMode(HbAbstractItemView::SingleSelection);
   135 
   166 
   136         mContentItemModel = new QStandardItemModel(this);
   167         mContentItemModel = new QStandardItemModel(this);
   137         mListView->setModel(mContentItemModel);//, prototype);
   168         mListView->setModel(mContentItemModel);//, prototype);
   138 
   169 
   139         connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
   170         connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
   140         connect(stop, SIGNAL(clicked()), this, SLOT(stopClicked()));
   171         connect(mStopRetryBtn, SIGNAL(clicked()), this, SLOT(stopRetryClicked()));
   141         connect(retry, SIGNAL(clicked()), this, SLOT(retryClicked()));
   172         connect(mViewByBtn, SIGNAL(clicked()), this, SLOT(viewByClicked()));
   142         connect(viewBy, SIGNAL(clicked()), this, SLOT(viewByClicked()));
       
   143         
   173         
   144         QGraphicsWidget *widget = mLoader->findWidget(QString("container"));
   174         QGraphicsWidget *widget = mLoader->findWidget(QString("container"));
   145         this->setContentWidget(widget);
   175         setContentWidget(widget);
   146         }
   176         }
   147     else
   177     setBackgroundFaded(false);
   148         {
       
   149 
       
   150         }
       
   151 
       
   152     this->setBackgroundFaded(false);
       
   153     setDismissPolicy(HbPopup::TapOutside);
   178     setDismissPolicy(HbPopup::TapOutside);
   154     setTimeout(HbPopup::NoTimeout);
   179     setTimeout(HbPopup::NoTimeout);
   155     
   180     
   156  /*   mViewByDialog = new HbDialog();
   181  /*   mViewByDialog = new HbDialog();
   157     mRbl = new HbRadioButtonList(mViewByDialog);
   182     mRbl = new HbRadioButtonList(mViewByDialog);
   161     }
   186     }
   162 
   187 
   163 void BTDeviceSearchDialogWidget::hideEvent(QHideEvent *event)
   188 void BTDeviceSearchDialogWidget::hideEvent(QHideEvent *event)
   164     {
   189     {
   165     HbDialog::hideEvent(event);
   190     HbDialog::hideEvent(event);
   166     if(mDeviceDialogData == 0)
   191     QVariantMap val;
   167         {
   192     QVariant index(-1);
       
   193     val.insert("selectedindex",index);
       
   194     emit deviceDialogData(val);    
       
   195     emit deviceDialogClosed();
       
   196     }
       
   197 
       
   198 void BTDeviceSearchDialogWidget::showEvent(QShowEvent *event)
       
   199     {
       
   200     HbDialog::showEvent(event);
       
   201     }
       
   202 
       
   203 void BTDeviceSearchDialogWidget::stopRetryClicked()
       
   204     {
       
   205     QVariantMap val;
       
   206     if(mStopRetryBtn->text().compare("Retry")==0)
       
   207         {
       
   208         QVariant index("Retry");
       
   209         val.insert("Retry",index); 
       
   210         emit deviceDialogData(val);
       
   211         delete mContentItemModel;
       
   212         mContentItemModel = new QStandardItemModel(this);
       
   213         mListView->setModel(mContentItemModel);
       
   214         mStopRetryBtn->setText("Stop");
       
   215         
       
   216         mSearchLabel->setTextWrapping(Hb::TextWordWrap);
       
   217         mSearchLabel->setAlignment(Qt::AlignHCenter);
       
   218         mSearchLabel->setPlainText("Searching...");
       
   219         
       
   220         mSearchIconLabel->setIcon(icon());     
       
   221         mSearchLabel->show();
       
   222         
       
   223         mSearchIconLabel->show();
       
   224         
       
   225         mSearchDoneLabel->hide();
       
   226         }
       
   227     else
       
   228         {
       
   229         mStopRetryBtn->setText("Retry");
       
   230         
       
   231         mSearchLabel->hide();
       
   232         
       
   233         mSearchIconLabel->hide();
       
   234         
       
   235         mSearchDoneLabel->show();
       
   236         mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap);
       
   237         mSearchDoneLabel->setAlignment(Qt::AlignLeft);
       
   238         mSearchDoneLabel->setPlainText("Search Done");        
       
   239         
   168         QVariantMap val;
   240         QVariantMap val;
   169         QVariant index(-1);
   241         QVariant index("Stop");
   170         val.insert("selectedindex",index);
   242         val.insert("Stop",index); 
   171         emit deviceDialogData(val);    
   243         emit deviceDialogData(val);    
   172         }
   244         }
   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     }
   245     }
   188 
   246 
   189 void BTDeviceSearchDialogWidget::retryClicked()
   247 void BTDeviceSearchDialogWidget::retryClicked()
   190     {
   248     {
   191     QVariantMap val;
   249     QVariantMap val;
   193     val.insert("Retry",index); 
   251     val.insert("Retry",index); 
   194     emit deviceDialogData(val);
   252     emit deviceDialogData(val);
   195     delete mContentItemModel;
   253     delete mContentItemModel;
   196     mContentItemModel = new QStandardItemModel(this);
   254     mContentItemModel = new QStandardItemModel(this);
   197     mListView->setModel(mContentItemModel);
   255     mListView->setModel(mContentItemModel);
   198     }
   256     
   199 
   257 
   200 //void BTDeviceSearchDialogWidget::viewByClicked()
   258     }
   201 //    {
   259 
       
   260 void BTDeviceSearchDialogWidget::viewByClicked()
       
   261     {
       
   262     QStringList list;
       
   263     list << "Select all" << "Audio devices" << "Computers" << "Input devices" << "Phones" << "Other devices";
       
   264 
       
   265     HbSelectionDialog *query = new HbSelectionDialog;
       
   266     query->setStringItems(list);
       
   267     query->setSelectionMode(HbAbstractItemView::MultiSelection);
       
   268 
       
   269     QList<QVariant> current;
       
   270     current.append(QVariant(0));
       
   271     query->setSelectedItems(current);
       
   272 
       
   273     query->setAttribute(Qt::WA_DeleteOnClose);
       
   274 
       
   275     query->open(this,SLOT(selectionDialogClosed(HbAction*)));
       
   276     
       
   277     //connect(query, SIGNAL(finished(HbAction*)), this, SLOT(selectionDialogClosed(HbAction*)));
       
   278     
   202 /*    mViewByDialog->setDismissPolicy(HbPopup::NoDismiss);
   279 /*    mViewByDialog->setDismissPolicy(HbPopup::NoDismiss);
   203     mViewByDialog->setTimeout(HbPopup::NoTimeout);
   280     mViewByDialog->setTimeout(HbPopup::NoTimeout);
   204 
   281 
   205     bool foundEntry = false;
   282     bool foundEntry = false;
   206     QStringList st;
   283     QStringList st;
   232     mViewByDialog->setContentWidget(mRbl);
   309     mViewByDialog->setContentWidget(mRbl);
   233     mViewByDialog->setMaximumHeight(300);
   310     mViewByDialog->setMaximumHeight(300);
   234     mViewByDialog->setMaximumWidth(500);
   311     mViewByDialog->setMaximumWidth(500);
   235 
   312 
   236     mViewByDialog->show();*/
   313     mViewByDialog->show();*/
   237  //   }
   314     }
       
   315 
       
   316 void BTDeviceSearchDialogWidget::selectionDialogClosed(HbAction* action)
       
   317     {
       
   318     Q_UNUSED(action);
       
   319 
       
   320  /*   HbSelectionDialog *dlg = (HbSelectionDialog*)(sender());
       
   321     if(dlg->actions().first() == action) {
       
   322 
       
   323      } 
       
   324     else if(dlg->actions().at(1) == action) {
       
   325      }*/
       
   326     }
   238 
   327 
   239 void BTDeviceSearchDialogWidget::deviceSelected(const QModelIndex& modelIndex)
   328 void BTDeviceSearchDialogWidget::deviceSelected(const QModelIndex& modelIndex)
   240     {
   329     {
   241     int row = 0;
   330     int row = 0;
   242     
   331     
   252     
   341     
   253     QVariantMap val;
   342     QVariantMap val;
   254     QVariant index(row);
   343     QVariant index(row);
   255     val.insert("selectedindex",index);
   344     val.insert("selectedindex",index);
   256     emit deviceDialogData(val);
   345     emit deviceDialogData(val);
   257     mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog
   346 //    mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog
   258     //emit deviceDialogClosed();
   347     //emit deviceDialogClosed();
   259     this->close();
   348   //  this->close();
   260     }
   349     }
   261 
   350 
   262 //void BTDeviceSearchDialogWidget::viewByItemSelected(int index)
   351 //void BTDeviceSearchDialogWidget::viewByItemSelected(int index)
   263   //  {
   352   //  {
   264     //  (void) index;
   353     //  (void) index;
   352         }
   441         }
   353     else
   442     else
   354         {
   443         {
   355         return (QIcon(QString(":/icons/qgn_prop_bt_unknown.svg")));
   444         return (QIcon(QString(":/icons/qgn_prop_bt_unknown.svg")));
   356         }*/
   445         }*/
   357     return QIcon(QString(":/icons/qgn_prop_sml_bt.svg"));
   446     return QIcon(QString(":/icons/qtg_large_bluetooth.svg"));
   358     }
   447     }
   359 
   448