bluetoothengine/btnotif/btdevicedialogplugin/src/btmoredevicesdialogwidget.cpp
changeset 40 997690c3397a
parent 33 837dcc42fd6a
child 41 0b2439c3e397
equal deleted inserted replaced
37:91746b151f97 40:997690c3397a
    27 
    27 
    28 const char* DOCML_BT_MORE_DEV_DIALOG = ":/docml/bt-more-devices-dialog.docml";
    28 const char* DOCML_BT_MORE_DEV_DIALOG = ":/docml/bt-more-devices-dialog.docml";
    29 
    29 
    30 
    30 
    31 BTMoreDevicesDialogWidget::BTMoreDevicesDialogWidget(const QVariantMap &parameters)
    31 BTMoreDevicesDialogWidget::BTMoreDevicesDialogWidget(const QVariantMap &parameters)
    32 :HbDialog()
       
    33     {
    32     {
    34     mDeviceDialogData = 0;
    33     mDeviceDialogData = 0;
       
    34     mLoader = 0;
       
    35     mContentItemModel = 0;
    35     constructDialog(parameters);
    36     constructDialog(parameters);
       
    37 /*    try 
       
    38             {
       
    39             //May throws badAlloc on exception
       
    40             constructDialog(parameters);
       
    41             }
       
    42         catch(std::bad_alloc &badAlloc)
       
    43             {
       
    44             //Failure to allocate memory
       
    45             Q_UNUSED(badAlloc);
       
    46           //   = UnknownDeviceDialogError;
       
    47             }*/
    36     }
    48     }
    37 
    49 
    38 BTMoreDevicesDialogWidget::~BTMoreDevicesDialogWidget()
    50 BTMoreDevicesDialogWidget::~BTMoreDevicesDialogWidget()
    39     {
    51     {
    40     if(mLoader)
    52     delete mLoader;
    41         {
    53     delete mContentItemModel;
    42         delete mLoader;
       
    43         mLoader = NULL;
       
    44         }
       
    45     if(mContentItemModel)
       
    46         {
       
    47         delete mContentItemModel;
       
    48         mContentItemModel =NULL;
       
    49         }
       
    50     }
    54     }
    51 
    55 
    52 bool BTMoreDevicesDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
    56 bool BTMoreDevicesDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
    53     {
    57     {
    54     QStandardItem* listitem = new QStandardItem();
    58     QStandardItem* listitem = new QStandardItem();
    73     }
    77     }
    74 
    78 
    75 void BTMoreDevicesDialogWidget::closeDeviceDialog(bool byClient)
    79 void BTMoreDevicesDialogWidget::closeDeviceDialog(bool byClient)
    76     {
    80     {
    77     Q_UNUSED(byClient);
    81     Q_UNUSED(byClient);
    78     this->close();
    82     // below code is required and written based on the documentation of closeDeviceDialog API
       
    83     mMoreDeviceDialog->close();
       
    84     QVariantMap val;
       
    85     QVariant index(-1);
       
    86     val.insert("selectedindex",index);
       
    87     emit deviceDialogData(val);    
       
    88     //below signal is emitted to make dialog server aware that our dialog is closed
       
    89     emit deviceDialogClosed();
    79     }
    90     }
    80 
    91 
    81 HbPopup* BTMoreDevicesDialogWidget::deviceDialogWidget() const
    92 HbPopup* BTMoreDevicesDialogWidget::deviceDialogWidget() const
       
    93     {
       
    94     return mMoreDeviceDialog;
       
    95     }
       
    96 
       
    97 QObject* BTMoreDevicesDialogWidget::signalSender() const
    82     {
    98     {
    83     return const_cast<BTMoreDevicesDialogWidget*>(this);
    99     return const_cast<BTMoreDevicesDialogWidget*>(this);
    84     }
   100     }
    85 
   101 
    86 bool BTMoreDevicesDialogWidget::constructDialog(const QVariantMap &/*parameters*/)
   102 bool BTMoreDevicesDialogWidget::constructDialog(const QVariantMap &/*parameters*/)
    89     bool ok = false;
   105     bool ok = false;
    90     
   106     
    91     mLoader->load(DOCML_BT_MORE_DEV_DIALOG, &ok);
   107     mLoader->load(DOCML_BT_MORE_DEV_DIALOG, &ok);
    92     if(ok)
   108     if(ok)
    93         {
   109         {
    94         HbLabel* label = qobject_cast<HbLabel*>(mLoader->findWidget("label"));
   110         mMoreDeviceDialog = qobject_cast<HbDialog*>(mLoader->findWidget("lastuseddialog"));
       
   111         mMoreDeviceDialog->setFrameType(HbDialog::Strong);
       
   112         mMoreDeviceDialog->setBackgroundFaded(false);
       
   113 /*        HbLabel* label = qobject_cast<HbLabel*>(mLoader->findWidget("label"));
    95         if(label)
   114         if(label)
    96             {
   115             {
    97             label->setTextWrapping(Hb::TextWordWrap);
   116             label->setTextWrapping(Hb::TextWordWrap);
    98             label->setPlainText("Send to:");
   117             label->setPlainText("Send to:");
    99             }
   118             }
   100         this->setHeadingWidget(label);
   119         this->setHeadingWidget(label);*/
   101         HbPushButton* moreDevices = qobject_cast<HbPushButton*>(mLoader->findWidget("moreDevices"));
   120    //     HbPushButton* moreDevices = qobject_cast<HbPushButton*>(mLoader->findWidget("moreDevices"));
   102         HbPushButton* cancel = qobject_cast<HbPushButton*>(mLoader->findWidget("cancel"));
   121     //    HbPushButton* cancel = qobject_cast<HbPushButton*>(mLoader->findWidget("cancel"));
   103         
   122         
   104         HbListView* listView = qobject_cast<HbListView*>(mLoader->findWidget("listView"));
   123         HbListView* listView = qobject_cast<HbListView*>(mLoader->findWidget("listView"));
   105         listView->setSelectionMode(HbAbstractItemView::SingleSelection);
   124         listView->setSelectionMode(HbAbstractItemView::SingleSelection);
   106 
   125 
   107         mContentItemModel = new QStandardItemModel(this);
   126         mContentItemModel = new QStandardItemModel(this);
   123         
   142         
   124             mContentItemModel->appendRow(listitem);
   143             mContentItemModel->appendRow(listitem);
   125             }*/
   144             }*/
   126         
   145         
   127         connect(listView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
   146         connect(listView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
   128         connect(moreDevices, SIGNAL(clicked()), this, SLOT(moreDevicesClicked()));
   147   //      connect(moreDevices, SIGNAL(clicked()), this, SLOT(moreDevicesClicked()));
   129         connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
   148    //     connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
   130         
   149         mMoreAction = static_cast<HbAction*>( mLoader->findObject( "moreaction" ) );
   131         QGraphicsWidget *widget = mLoader->findWidget(QString("container"));
   150         mMoreAction->disconnect(mMoreDeviceDialog);
   132         this->setContentWidget(widget);
   151         
   133         }
   152         mCancelAction = static_cast<HbAction*>( mLoader->findObject( "cancelaction" ) );
   134 
   153         mCancelAction->disconnect(mMoreDeviceDialog);
   135 
   154 //        QGraphicsWidget *widget = mLoader->findWidget(QString("container"));
   136     this->setBackgroundFaded(false);
   155   //      mMoreDeviceDialog->setContentWidget(widget);
   137     setDismissPolicy(HbPopup::NoDismiss);
   156         
   138     setTimeout(HbPopup::NoTimeout);
   157          connect(mMoreAction, SIGNAL(triggered()), this, SLOT(moreDevicesClicked()));
       
   158          connect(mCancelAction, SIGNAL(triggered()), this, SLOT(cancelClicked()));
       
   159                
       
   160         }
       
   161 
       
   162 
       
   163     mMoreDeviceDialog->setBackgroundFaded(false);
       
   164     mMoreDeviceDialog->setDismissPolicy(HbPopup::NoDismiss);
       
   165     mMoreDeviceDialog->setTimeout(HbPopup::NoTimeout);
   139     return true;
   166     return true;
   140     }
   167     }
   141 
   168 
   142 void BTMoreDevicesDialogWidget::hideEvent(QHideEvent *event)
   169 /*void BTMoreDevicesDialogWidget::hideEvent(QHideEvent *event)
   143     {
   170     {
   144     HbDialog::hideEvent(event);
   171     //HbDialog::hideEvent(event);
       
   172     mMoreDeviceDialog->hideEvent(event);
   145 //    if(mDeviceDialogData == 0)
   173 //    if(mDeviceDialogData == 0)
   146         {
   174         {
   147         QVariantMap val;
   175         QVariantMap val;
   148         QVariant index(-1);
   176         QVariant index(-1);
   149         val.insert("selectedindex",index);
   177         val.insert("selectedindex",index);
   150         emit deviceDialogData(val);    
   178         emit deviceDialogData(val);    
   151         emit deviceDialogClosed();
   179         emit deviceDialogClosed();
   152         }    
   180         }*/    
   153  //   
   181  //   
   154     }
   182    // }
   155 
   183 
   156 void BTMoreDevicesDialogWidget::showEvent(QShowEvent *event)
   184 /*void BTMoreDevicesDialogWidget::showEvent(QShowEvent *event)
   157     {
   185     {
   158     HbDialog::showEvent(event);
   186     //HbDialog::showEvent(event);
   159     }
   187     }*/
   160 
   188 
   161 void BTMoreDevicesDialogWidget::moreDevicesClicked()
   189 void BTMoreDevicesDialogWidget::moreDevicesClicked()
   162     {
   190     {
   163     QVariantMap val;
   191     QVariantMap val;
   164     QVariant index("MoreDevices");
   192     QVariant index("MoreDevices");
   170     }
   198     }
   171 
   199 
   172 void BTMoreDevicesDialogWidget::cancelClicked()
   200 void BTMoreDevicesDialogWidget::cancelClicked()
   173     {
   201     {
   174     // TODO
   202     // TODO
   175     this->close();
   203     mMoreDeviceDialog->close();
       
   204     QVariantMap val;
       
   205     QVariant index(-1);
       
   206     val.insert("selectedindex",index);
       
   207     emit deviceDialogData(val);    
       
   208     emit deviceDialogClosed();
   176     }
   209     }
   177 
   210 
   178 void BTMoreDevicesDialogWidget::deviceSelected(const QModelIndex& modelIndex)
   211 void BTMoreDevicesDialogWidget::deviceSelected(const QModelIndex& modelIndex)
   179     {
   212     {
   180     int row = modelIndex.row();
   213     int row = modelIndex.row();
   181     QVariantMap val;
   214     QVariantMap val;
   182     QVariant index(row);
   215     QVariant index(row);
   183     val.insert("selectedindex",index);
   216     val.insert("selectedindex",index);
   184     
       
   185 
       
   186 
       
   187     
       
   188     emit deviceDialogData(val);
   217     emit deviceDialogData(val);
   189   //  mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog    
   218   //  mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog    
   190    // this->close();
   219    // this->close();
   191 
   220 
   192     }
   221     }