bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp
changeset 40 997690c3397a
parent 33 837dcc42fd6a
child 41 0b2439c3e397
equal deleted inserted replaced
37:91746b151f97 40:997690c3397a
    22 #include <hbtoolbar.h>
    22 #include <hbtoolbar.h>
    23 #include <hbselectiondialog.h>
    23 #include <hbselectiondialog.h>
    24 
    24 
    25 #include <qstandarditemmodel.h>
    25 #include <qstandarditemmodel.h>
    26 #include <hbaction.h>
    26 #include <hbaction.h>
       
    27 #include <xqconversions.h>
       
    28 #include <qtranslator.h>
       
    29 #include <qcoreapplication.h>
    27 
    30 
    28 const char* DOCML_BTDEV_SEARCH_DIALOG = ":/docml/bt-device-search-dialog.docml";
    31 const char* DOCML_BTDEV_SEARCH_DIALOG = ":/docml/bt-device-search-dialog.docml";
    29 
    32 
    30 
    33 
       
    34 #define LOC_SEARCHING_DEVICE hbTrId("txt_bt_subhead_searching")
       
    35 #define LOC_SEARCH_DONE hbTrId("txt_bt_subhead_search_done")
       
    36 #define LOC_SEARCH_STOP hbTrId("txt_common_button_stop")
       
    37 #define LOC_SEARCH_RETRY hbTrId("txt_common_button_retry")
       
    38 
       
    39 
    31 BTDeviceSearchDialogWidget::BTDeviceSearchDialogWidget(const QVariantMap &parameters)
    40 BTDeviceSearchDialogWidget::BTDeviceSearchDialogWidget(const QVariantMap &parameters)
    32 :HbDialog()
       
    33     {
    41     {
    34     mDeviceLstIdx = 0;
    42     mDeviceLstIdx = 0;
    35     mViewByChosen = false;
    43     mViewByChosen = false;
    36     mSelectedType = 0;
    44     mSelectedType = 0;
    37     mDeviceDialogData = 0;
    45     mDeviceDialogData = 0;
       
    46     mLoader = 0;
       
    47     mContentItemModel = 0;
       
    48     mStopRetryFlag = 0; // Stop 
    38     constructDialog(parameters);
    49     constructDialog(parameters);
    39     }
    50     }
    40 
    51 
    41 BTDeviceSearchDialogWidget::~BTDeviceSearchDialogWidget()
    52 BTDeviceSearchDialogWidget::~BTDeviceSearchDialogWidget()
    42     {
    53     {
    43     if(mLoader)
    54     delete mLoader;
    44         {
    55     delete mContentItemModel;
    45         delete mLoader;
    56     
    46         mLoader = NULL;
       
    47         }
       
    48     if(mContentItemModel)
       
    49         {
       
    50         delete mContentItemModel;
       
    51         mContentItemModel = NULL;
       
    52         }
       
    53  //   delete mRbl;
    57  //   delete mRbl;
    54  //   delete mViewByDialog;
    58  //   delete mViewByDialog;
    55     }
    59     }
    56 
    60 
    57 bool BTDeviceSearchDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
    61 bool BTDeviceSearchDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
    63         mSearchIconLabel->hide();
    67         mSearchIconLabel->hide();
    64         
    68         
    65         mSearchDoneLabel->show();
    69         mSearchDoneLabel->show();
    66         mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap);
    70         mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap);
    67         mSearchDoneLabel->setAlignment(Qt::AlignLeft);
    71         mSearchDoneLabel->setAlignment(Qt::AlignLeft);
    68         mSearchDoneLabel->setPlainText("Search Done");
    72         mSearchDoneLabel->setPlainText(LOC_SEARCH_DONE);
    69         
    73         
    70         mStopRetryBtn->setText("Retry");
    74         mStopRetryAction->setText(LOC_SEARCH_RETRY);
    71         }
    75         }
    72     else
    76     else
    73         {
    77         {
    74         device newDevice;
    78         device newDevice;
    75     
    79     
   119     }
   123     }
   120 
   124 
   121 void BTDeviceSearchDialogWidget::closeDeviceDialog(bool byClient)
   125 void BTDeviceSearchDialogWidget::closeDeviceDialog(bool byClient)
   122     {
   126     {
   123     Q_UNUSED(byClient);
   127     Q_UNUSED(byClient);
   124     this->close();
   128     mSearchDevicesDialog->close();
       
   129     //@ TODO to check below code is required which is written based on the documentation of closeDeviceDialog API
       
   130     
       
   131  /*   QVariantMap val;
       
   132     QVariant index(-1);
       
   133     val.insert("selectedindex",index);
       
   134     emit deviceDialogData(val);    
       
   135     emit deviceDialogClosed();*/
   125     }
   136     }
   126 
   137 
   127 HbPopup* BTDeviceSearchDialogWidget::deviceDialogWidget() const
   138 HbPopup* BTDeviceSearchDialogWidget::deviceDialogWidget() const
   128     {
   139     {
       
   140     return mSearchDevicesDialog;
       
   141     }
       
   142 
       
   143 QObject* BTDeviceSearchDialogWidget::signalSender() const
       
   144     {
   129     return const_cast<BTDeviceSearchDialogWidget*>(this);
   145     return const_cast<BTDeviceSearchDialogWidget*>(this);
   130     }
   146     }
   131 
   147 
   132 bool BTDeviceSearchDialogWidget::constructDialog(const QVariantMap &parameters)
   148 bool BTDeviceSearchDialogWidget::constructDialog(const QVariantMap &parameters)
   133     {
   149     {
   134     (void) parameters;
   150     (void) parameters;
       
   151     bool ok = false;
       
   152     
   135     mLoader = new HbDocumentLoader();
   153     mLoader = new HbDocumentLoader();
   136     bool ok = false;
       
   137     
       
   138     mLoader->load(DOCML_BTDEV_SEARCH_DIALOG, &ok);
   154     mLoader->load(DOCML_BTDEV_SEARCH_DIALOG, &ok);
   139     if(ok)
   155     if(ok)
   140         {
   156         {
   141         HbLabel* heading = qobject_cast<HbLabel*>(mLoader->findWidget("heading"));
   157         mSearchDevicesDialog = qobject_cast<HbDialog*>(mLoader->findWidget("searchdialog"));
       
   158 
       
   159  /*       HbLabel* heading = qobject_cast<HbLabel*>(mLoader->findWidget("heading"));
   142         heading->setTextWrapping(Hb::TextWordWrap);
   160         heading->setTextWrapping(Hb::TextWordWrap);
   143         heading->setAlignment(Qt::AlignHCenter);
   161         heading->setAlignment(Qt::AlignHCenter);
   144         heading->setPlainText("Bluetooth - Found devices");
   162         heading->setPlainText("Bluetooth - Found devices");
   145         setHeadingWidget(heading);
   163         setHeadingWidget(heading);*/
   146         
   164         
   147         mSearchLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchLabel"));
   165         mSearchLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchLabel"));
   148         mSearchLabel->setTextWrapping(Hb::TextWordWrap);
   166         mSearchLabel->setTextWrapping(Hb::TextWordWrap);
   149         mSearchLabel->setAlignment(Qt::AlignHCenter);
   167         mSearchLabel->setAlignment(Qt::AlignHCenter);
   150         mSearchLabel->setPlainText("Searching...");
   168         mSearchLabel->setPlainText(LOC_SEARCHING_DEVICE);
   151  
   169  
   152         mSearchIconLabel = qobject_cast<HbLabel*>(mLoader->findWidget("iconLabel"));
   170         mSearchIconLabel = qobject_cast<HbLabel*>(mLoader->findWidget("iconLabel"));
   153         mSearchIconLabel->setIcon(icon());
   171         mSearchIconLabel->setIcon(icon());
   154 
   172 
   155         mSearchDoneLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchDoneLabel"));
   173         mSearchDoneLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchDoneLabel"));
   156         mSearchDoneLabel->hide();
   174         mSearchDoneLabel->hide();
   157         
   175         
   158         setFrameType(HbDialog::Strong);
   176         
   159         setBackgroundFaded(false);
   177         mSearchDevicesDialog->setFrameType(HbDialog::Strong);
   160 
   178         mSearchDevicesDialog->setBackgroundFaded(false);
   161         mViewByBtn = qobject_cast<HbPushButton*>(mLoader->findWidget("viewby"));
   179 
   162         mStopRetryBtn = qobject_cast<HbPushButton*>(mLoader->findWidget("stop"));
   180  //       mViewByBtn = qobject_cast<HbPushButton*>(mLoader->findWidget("viewby"));
       
   181   //      mStopRetryBtn = qobject_cast<HbPushButton*>(mLoader->findWidget("stop"));
   163         
   182         
   164         mListView = qobject_cast<HbListView*>(mLoader->findWidget("listView"));
   183         mListView = qobject_cast<HbListView*>(mLoader->findWidget("listView"));
   165         mListView->setSelectionMode(HbAbstractItemView::SingleSelection);
   184         mListView->setSelectionMode(HbAbstractItemView::SingleSelection);
   166 
   185 
   167         mContentItemModel = new QStandardItemModel(this);
   186         mContentItemModel = new QStandardItemModel(this);
   168         mListView->setModel(mContentItemModel);//, prototype);
   187         mListView->setModel(mContentItemModel);//, prototype);
   169 
   188 
   170         connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
   189         connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
   171         connect(mStopRetryBtn, SIGNAL(clicked()), this, SLOT(stopRetryClicked()));
   190  //       connect(mStopRetryBtn, SIGNAL(clicked()), this, SLOT(stopRetryClicked()));
   172         connect(mViewByBtn, SIGNAL(clicked()), this, SLOT(viewByClicked()));
   191  //       connect(mViewByBtn, SIGNAL(clicked()), this, SLOT(viewByClicked()));
   173         
   192         
   174         QGraphicsWidget *widget = mLoader->findWidget(QString("container"));
   193         mViewByAction = static_cast<HbAction*>( mLoader->findObject( "viewaction" ) );
   175         setContentWidget(widget);
   194         mViewByAction->disconnect(mSearchDevicesDialog);
   176         }
   195         
   177     setBackgroundFaded(false);
   196         mStopRetryAction = static_cast<HbAction*>( mLoader->findObject( "stopretryaction" ) );
   178     setDismissPolicy(HbPopup::TapOutside);
   197         mStopRetryAction->disconnect(mSearchDevicesDialog);
   179     setTimeout(HbPopup::NoTimeout);
   198         
       
   199         connect(mViewByAction, SIGNAL(triggered()), this, SLOT(viewByClicked()));
       
   200         connect(mStopRetryAction, SIGNAL(triggered()), this, SLOT(stopRetryClicked()));
       
   201 
       
   202         connect(mSearchDevicesDialog, SIGNAL(finished(HbAction*)), this, SLOT(searchDialogClosed(HbAction*)));
       
   203         
       
   204 //        QGraphicsWidget *widget = mLoader->findWidget(QString("container"));
       
   205         //setContentWidget(widget);
       
   206         }
       
   207     mSearchDevicesDialog->setBackgroundFaded(false);
       
   208     mSearchDevicesDialog->setDismissPolicy(HbPopup::TapOutside);
       
   209     mSearchDevicesDialog->setTimeout(HbPopup::NoTimeout);
   180     
   210     
   181  /*   mViewByDialog = new HbDialog();
   211  /*   mViewByDialog = new HbDialog();
   182     mRbl = new HbRadioButtonList(mViewByDialog);
   212     mRbl = new HbRadioButtonList(mViewByDialog);
   183     connect(mRbl, SIGNAL(itemSelected(int)), this, SLOT(viewByItemSelected(int)));*/
   213     connect(mRbl, SIGNAL(itemSelected(int)), this, SLOT(viewByItemSelected(int)));*/
   184     
   214     
   185     return true;
   215     return true;
   186     }
   216     }
   187 
   217 
   188 void BTDeviceSearchDialogWidget::hideEvent(QHideEvent *event)
   218 /*void BTDeviceSearchDialogWidget::hideEvent(QHideEvent *event)
   189     {
   219     {
   190     HbDialog::hideEvent(event);
   220  //   HbDialog::hideEvent(event);
   191     QVariantMap val;
   221     QVariantMap val;
   192     QVariant index(-1);
   222     QVariant index(-1);
   193     val.insert("selectedindex",index);
   223     val.insert("selectedindex",index);
   194     emit deviceDialogData(val);    
   224     emit deviceDialogData(val);    
   195     emit deviceDialogClosed();
   225     emit deviceDialogClosed();
   196     }
   226     }
   197 
   227 
   198 void BTDeviceSearchDialogWidget::showEvent(QShowEvent *event)
   228 void BTDeviceSearchDialogWidget::showEvent(QShowEvent *event)
   199     {
   229     {
   200     HbDialog::showEvent(event);
   230  //   HbDialog::showEvent(event);
   201     }
   231     }*/
   202 
   232 
   203 void BTDeviceSearchDialogWidget::stopRetryClicked()
   233 void BTDeviceSearchDialogWidget::stopRetryClicked()
   204     {
   234     {
   205     QVariantMap val;
   235     QVariantMap val;
   206     if(mStopRetryBtn->text().compare("Retry")==0)
   236     if(mStopRetryFlag == 1)//mStopRetryAction->text().compare(LOC_SEARCH_RETRY)==0
   207         {
   237         {
       
   238         mStopRetryFlag = 0; // Stop 
   208         QVariant index("Retry");
   239         QVariant index("Retry");
   209         val.insert("Retry",index); 
   240         val.insert("Retry",index); 
   210         emit deviceDialogData(val);
   241         emit deviceDialogData(val);
   211         delete mContentItemModel;
   242         delete mContentItemModel;
   212         mContentItemModel = new QStandardItemModel(this);
   243         mContentItemModel = new QStandardItemModel(this);
   213         mListView->setModel(mContentItemModel);
   244         mListView->setModel(mContentItemModel);
   214         mStopRetryBtn->setText("Stop");
   245         mStopRetryAction->setText(LOC_SEARCH_STOP);
   215         
   246         
   216         mSearchLabel->setTextWrapping(Hb::TextWordWrap);
   247         mSearchLabel->setTextWrapping(Hb::TextWordWrap);
   217         mSearchLabel->setAlignment(Qt::AlignHCenter);
   248         mSearchLabel->setAlignment(Qt::AlignHCenter);
   218         mSearchLabel->setPlainText("Searching...");
   249         mSearchLabel->setPlainText(LOC_SEARCHING_DEVICE);
   219         
   250         
   220         mSearchIconLabel->setIcon(icon());     
   251         mSearchIconLabel->setIcon(icon());     
   221         mSearchLabel->show();
   252         mSearchLabel->show();
   222         
   253         
   223         mSearchIconLabel->show();
   254         mSearchIconLabel->show();
   224         
   255         
   225         mSearchDoneLabel->hide();
   256         mSearchDoneLabel->hide();
   226         }
   257         }
   227     else
   258     else
   228         {
   259         {
   229         mStopRetryBtn->setText("Retry");
   260         mStopRetryFlag = 1; //Retry 
       
   261         mStopRetryAction->setText(LOC_SEARCH_RETRY);
   230         
   262         
   231         mSearchLabel->hide();
   263         mSearchLabel->hide();
   232         
   264         
   233         mSearchIconLabel->hide();
   265         mSearchIconLabel->hide();
   234         
   266         
   235         mSearchDoneLabel->show();
   267         mSearchDoneLabel->show();
   236         mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap);
   268         mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap);
   237         mSearchDoneLabel->setAlignment(Qt::AlignLeft);
   269         mSearchDoneLabel->setAlignment(Qt::AlignLeft);
   238         mSearchDoneLabel->setPlainText("Search Done");        
   270         mSearchDoneLabel->setPlainText(LOC_SEARCH_DONE);        
   239         
   271         
   240         QVariantMap val;
   272         QVariantMap val;
   241         QVariant index("Stop");
   273         QVariant index("Stop");
   242         val.insert("Stop",index); 
   274         val.insert("Stop",index); 
   243         emit deviceDialogData(val);    
   275         emit deviceDialogData(val);    
   311     mViewByDialog->setMaximumWidth(500);
   343     mViewByDialog->setMaximumWidth(500);
   312 
   344 
   313     mViewByDialog->show();*/
   345     mViewByDialog->show();*/
   314     }
   346     }
   315 
   347 
       
   348 void BTDeviceSearchDialogWidget::searchDialogClosed(HbAction* action)
       
   349     {
       
   350     HbDialog *dlg=static_cast<HbDialog*>(sender());
       
   351      if(dlg->actions().first() == action) {
       
   352      } 
       
   353      else if(dlg->actions().at(1) == action) {
       
   354        }
       
   355      else
       
   356         {
       
   357         QVariantMap val;
       
   358         QVariant index(-1);
       
   359         val.insert("selectedindex",index);
       
   360         emit deviceDialogData(val);    
       
   361         emit deviceDialogClosed();
       
   362         }
       
   363     }
       
   364 
   316 void BTDeviceSearchDialogWidget::selectionDialogClosed(HbAction* action)
   365 void BTDeviceSearchDialogWidget::selectionDialogClosed(HbAction* action)
   317     {
   366     {
   318     Q_UNUSED(action);
   367     Q_UNUSED(action);
   319 
   368 
   320  /*   HbSelectionDialog *dlg = (HbSelectionDialog*)(sender());
   369  /*   HbSelectionDialog *dlg = (HbSelectionDialog*)(sender());