bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp
changeset 42 b72428996822
parent 31 a0ea99b6fa53
child 47 9e2a905b887f
equal deleted inserted replaced
32:19bd632b5100 42:b72428996822
    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(aboutToClose()), this, SLOT(searchDialogClosed()));
       
   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);
       
   210     mSearchDevicesDialog->setAttribute(Qt::WA_DeleteOnClose);
   180     
   211     
   181  /*   mViewByDialog = new HbDialog();
   212  /*   mViewByDialog = new HbDialog();
   182     mRbl = new HbRadioButtonList(mViewByDialog);
   213     mRbl = new HbRadioButtonList(mViewByDialog);
   183     connect(mRbl, SIGNAL(itemSelected(int)), this, SLOT(viewByItemSelected(int)));*/
   214     connect(mRbl, SIGNAL(itemSelected(int)), this, SLOT(viewByItemSelected(int)));*/
   184     
   215     
   185     return true;
   216     return true;
   186     }
   217     }
   187 
   218 
   188 void BTDeviceSearchDialogWidget::hideEvent(QHideEvent *event)
   219 /*void BTDeviceSearchDialogWidget::hideEvent(QHideEvent *event)
   189     {
   220     {
   190     HbDialog::hideEvent(event);
   221  //   HbDialog::hideEvent(event);
   191     QVariantMap val;
   222     QVariantMap val;
   192     QVariant index(-1);
   223     QVariant index(-1);
   193     val.insert("selectedindex",index);
   224     val.insert("selectedindex",index);
   194     emit deviceDialogData(val);    
   225     emit deviceDialogData(val);    
   195     emit deviceDialogClosed();
   226     emit deviceDialogClosed();
   196     }
   227     }
   197 
   228 
   198 void BTDeviceSearchDialogWidget::showEvent(QShowEvent *event)
   229 void BTDeviceSearchDialogWidget::showEvent(QShowEvent *event)
   199     {
   230     {
   200     HbDialog::showEvent(event);
   231  //   HbDialog::showEvent(event);
   201     }
   232     }*/
   202 
   233 
   203 void BTDeviceSearchDialogWidget::stopRetryClicked()
   234 void BTDeviceSearchDialogWidget::stopRetryClicked()
   204     {
   235     {
   205     QVariantMap val;
   236     QVariantMap val;
   206     if(mStopRetryBtn->text().compare("Retry")==0)
   237     if(mStopRetryFlag == 1)//mStopRetryAction->text().compare(LOC_SEARCH_RETRY)==0
   207         {
   238         {
       
   239         mStopRetryFlag = 0; // Stop 
   208         QVariant index("Retry");
   240         QVariant index("Retry");
   209         val.insert("Retry",index); 
   241         val.insert("Retry",index); 
   210         emit deviceDialogData(val);
   242         emit deviceDialogData(val);
   211         delete mContentItemModel;
   243         delete mContentItemModel;
   212         mContentItemModel = new QStandardItemModel(this);
   244         mContentItemModel = new QStandardItemModel(this);
   213         mListView->setModel(mContentItemModel);
   245         mListView->setModel(mContentItemModel);
   214         mStopRetryBtn->setText("Stop");
   246         mStopRetryAction->setText(LOC_SEARCH_STOP);
   215         
   247         
   216         mSearchLabel->setTextWrapping(Hb::TextWordWrap);
   248         mSearchLabel->setTextWrapping(Hb::TextWordWrap);
   217         mSearchLabel->setAlignment(Qt::AlignHCenter);
   249         mSearchLabel->setAlignment(Qt::AlignHCenter);
   218         mSearchLabel->setPlainText("Searching...");
   250         mSearchLabel->setPlainText(LOC_SEARCHING_DEVICE);
   219         
   251         
   220         mSearchIconLabel->setIcon(icon());     
   252         mSearchIconLabel->setIcon(icon());     
   221         mSearchLabel->show();
   253         mSearchLabel->show();
   222         
   254         
   223         mSearchIconLabel->show();
   255         mSearchIconLabel->show();
   224         
   256         
   225         mSearchDoneLabel->hide();
   257         mSearchDoneLabel->hide();
   226         }
   258         }
   227     else
   259     else
   228         {
   260         {
   229         mStopRetryBtn->setText("Retry");
   261         mStopRetryFlag = 1; //Retry 
       
   262         mStopRetryAction->setText(LOC_SEARCH_RETRY);
   230         
   263         
   231         mSearchLabel->hide();
   264         mSearchLabel->hide();
   232         
   265         
   233         mSearchIconLabel->hide();
   266         mSearchIconLabel->hide();
   234         
   267         
   235         mSearchDoneLabel->show();
   268         mSearchDoneLabel->show();
   236         mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap);
   269         mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap);
   237         mSearchDoneLabel->setAlignment(Qt::AlignLeft);
   270         mSearchDoneLabel->setAlignment(Qt::AlignLeft);
   238         mSearchDoneLabel->setPlainText("Search Done");        
   271         mSearchDoneLabel->setPlainText(LOC_SEARCH_DONE);        
   239         
   272         
   240         QVariantMap val;
   273         QVariantMap val;
   241         QVariant index("Stop");
   274         QVariant index("Stop");
   242         val.insert("Stop",index); 
   275         val.insert("Stop",index); 
   243         emit deviceDialogData(val);    
   276         emit deviceDialogData(val);    
   311     mViewByDialog->setMaximumWidth(500);
   344     mViewByDialog->setMaximumWidth(500);
   312 
   345 
   313     mViewByDialog->show();*/
   346     mViewByDialog->show();*/
   314     }
   347     }
   315 
   348 
       
   349 void BTDeviceSearchDialogWidget::searchDialogClosed() 
       
   350     {
       
   351     QVariantMap val;
       
   352     QVariant index(-1);
       
   353     val.insert("selectedindex",index);
       
   354     emit deviceDialogData(val);    
       
   355     emit deviceDialogClosed();
       
   356     }
       
   357 
   316 void BTDeviceSearchDialogWidget::selectionDialogClosed(HbAction* action)
   358 void BTDeviceSearchDialogWidget::selectionDialogClosed(HbAction* action)
   317     {
   359     {
   318     Q_UNUSED(action);
   360     Q_UNUSED(action);
   319 
   361 
   320  /*   HbSelectionDialog *dlg = (HbSelectionDialog*)(sender());
   362  /*   HbSelectionDialog *dlg = (HbSelectionDialog*)(sender());