14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "btmoredevicesdialogwidget.h" |
18 #include "btmoredevicesdialogwidget.h" |
19 #include <hblabel.h> |
|
20 #include <hblistview.h> |
19 #include <hblistview.h> |
21 #include <hbtoolbar.h> |
|
22 #include <hbpushbutton.h> |
|
23 #include <hblistwidget.h> |
|
24 #include <qstandarditemmodel.h> |
|
25 #include <btuidevtypemap.h> |
20 #include <btuidevtypemap.h> |
26 #include <btuiiconutil.h> |
21 #include <btuiiconutil.h> |
27 #include <bluetoothdevicedialogs.h> |
22 #include <bluetoothdevicedialogs.h> |
28 |
23 #include "btdevicedialogpluginerrors.h" |
29 |
|
30 |
24 |
31 const char* DOCML_BT_MORE_DEV_DIALOG = ":/docml/bt-more-devices-dialog.docml"; |
25 const char* DOCML_BT_MORE_DEV_DIALOG = ":/docml/bt-more-devices-dialog.docml"; |
32 |
26 |
33 |
27 |
34 BTMoreDevicesDialogWidget::BTMoreDevicesDialogWidget(const QVariantMap ¶meters) |
28 BTMoreDevicesDialogWidget::BTMoreDevicesDialogWidget(const QVariantMap ¶meters) |
35 { |
29 { |
36 mLoader = 0; |
30 mLoader = 0; |
37 mContentItemModel = 0; |
31 mContentItemModel = 0; |
|
32 mLastError = NoError; |
38 constructDialog(parameters); |
33 constructDialog(parameters); |
39 /* try |
|
40 { |
|
41 //May throws badAlloc on exception |
|
42 constructDialog(parameters); |
|
43 } |
|
44 catch(std::bad_alloc &badAlloc) |
|
45 { |
|
46 //Failure to allocate memory |
|
47 Q_UNUSED(badAlloc); |
|
48 // = UnknownDeviceDialogError; |
|
49 }*/ |
|
50 } |
34 } |
51 |
35 |
52 BTMoreDevicesDialogWidget::~BTMoreDevicesDialogWidget() |
36 BTMoreDevicesDialogWidget::~BTMoreDevicesDialogWidget() |
53 { |
37 { |
54 delete mLoader; |
38 delete mLoader; |
59 { |
43 { |
60 int cod = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)).toInt(); |
44 int cod = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)).toInt(); |
61 int uiMajorDevice; |
45 int uiMajorDevice; |
62 int uiMinorDevice; |
46 int uiMinorDevice; |
63 |
47 |
64 BtuiDevProperty::mapDeiveType(uiMajorDevice, uiMinorDevice, cod); |
48 if(!mLastError) |
65 if ((uiMajorDevice & BtuiDevProperty::Phone)||(uiMajorDevice & BtuiDevProperty::Computer) ) |
|
66 { |
49 { |
67 BtSendDataItem devData; |
50 BtuiDevProperty::mapDeiveType(uiMajorDevice, uiMinorDevice, cod); |
68 //todo Need to create string constant for name as enum EDeviceName has an issue |
51 if ((uiMajorDevice & BtuiDevProperty::Phone)||(uiMajorDevice & BtuiDevProperty::Computer) ) |
69 devData[NameAliasRole] = parameters.value("Name"); |
52 { |
70 devData[ReadableBdaddrRole] = parameters.value(QString::number(TBluetoothDeviceDialog::EAddress)); |
53 BtSendDataItem devData; |
71 devData[CoDRole] = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)); |
54 //todo Need to create string constant for name as enum EDeviceName has an issue |
72 |
55 devData[NameAliasRole] = parameters.value("Name"); |
73 setMajorProperty(devData,BtuiDevProperty::Bonded, |
56 devData[ReadableBdaddrRole] = parameters.value(QString::number(TBluetoothDeviceDialog::EAddress)); |
74 parameters.value("Bonded").toBool()); |
57 devData[CoDRole] = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)); |
75 setMajorProperty(devData,BtuiDevProperty::Blocked, |
58 |
76 parameters.value("Blocked").toBool()); |
59 setMajorProperty(devData,BtuiDevProperty::Bonded, |
77 setMajorProperty(devData,BtuiDevProperty::Trusted, |
60 parameters.value("Bonded").toBool()); |
78 parameters.value("Trusted").toBool()); |
61 setMajorProperty(devData,BtuiDevProperty::Blocked, |
79 setMajorProperty(devData,BtuiDevProperty::Connected, |
62 parameters.value("Blocked").toBool()); |
80 parameters.value("Connected").toBool()); |
63 setMajorProperty(devData,BtuiDevProperty::Trusted, |
81 mData.append(devData); |
64 parameters.value("Trusted").toBool()); |
82 |
65 setMajorProperty(devData,BtuiDevProperty::Connected, |
83 QStandardItem* listitem = new QStandardItem(); |
66 parameters.value("Connected").toBool()); |
84 QStringList info; |
67 mData.append(devData); |
85 info.append(devData[NameAliasRole].toString()); |
68 |
86 |
69 QStandardItem* listitem = new QStandardItem(); |
87 listitem->setData(info, Qt::DisplayRole); |
70 QStringList info; |
88 HbIcon icon = getBadgedDeviceTypeIcon(devData[CoDRole].toInt(), |
71 info.append(devData[NameAliasRole].toString()); |
89 devData[MajorPropertyRole].toInt(), |
72 |
90 BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight); |
73 listitem->setData(info, Qt::DisplayRole); |
91 listitem->setIcon(icon.qicon()); |
74 HbIcon icon = getBadgedDeviceTypeIcon(devData[CoDRole].toInt(), |
92 |
75 devData[MajorPropertyRole].toInt(), |
93 mContentItemModel->appendRow(listitem); |
76 BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight); |
|
77 listitem->setIcon(icon.qicon()); |
|
78 |
|
79 mContentItemModel->appendRow(listitem); |
|
80 } |
|
81 return true; |
94 } |
82 } |
95 return true; |
83 else |
|
84 { |
|
85 return false; |
|
86 } |
96 } |
87 } |
97 |
88 |
98 |
89 |
99 |
90 |
100 |
91 |
101 int BTMoreDevicesDialogWidget::deviceDialogError() const |
92 int BTMoreDevicesDialogWidget::deviceDialogError() const |
102 { |
93 { |
103 return 0; |
94 return mLastError; |
104 } |
95 } |
105 |
96 |
106 void BTMoreDevicesDialogWidget::closeDeviceDialog(bool byClient) |
97 void BTMoreDevicesDialogWidget::closeDeviceDialog(bool byClient) |
107 { |
98 { |
108 mLastUsedDeviceDialog->close(); |
99 mLastUsedDeviceDialog->close(); |
124 QObject* BTMoreDevicesDialogWidget::signalSender() const |
115 QObject* BTMoreDevicesDialogWidget::signalSender() const |
125 { |
116 { |
126 return const_cast<BTMoreDevicesDialogWidget*>(this); |
117 return const_cast<BTMoreDevicesDialogWidget*>(this); |
127 } |
118 } |
128 |
119 |
129 bool BTMoreDevicesDialogWidget::constructDialog(const QVariantMap ¶meters) |
120 void BTMoreDevicesDialogWidget::constructDialog(const QVariantMap ¶meters) |
130 { |
121 { |
131 Q_UNUSED(parameters); |
122 Q_UNUSED(parameters); |
132 mLoader = new HbDocumentLoader(); |
123 mLoader = new HbDocumentLoader(); |
133 bool ok = false; |
124 bool ok = false; |
134 |
125 |
135 mLoader->load(DOCML_BT_MORE_DEV_DIALOG, &ok); |
126 mLoader->load(DOCML_BT_MORE_DEV_DIALOG, &ok); |
136 if(ok) |
127 if(ok) |
137 { |
128 { |
138 mLastUsedDeviceDialog = qobject_cast<HbDialog*>(mLoader->findWidget("lastUsedDevicesDialog")); |
129 mLastUsedDeviceDialog = qobject_cast<HbDialog*>(mLoader->findWidget("lastUsedDevicesDialog")); |
139 |
130 |
140 |
|
141 HbListView* deviceList = qobject_cast<HbListView*>(mLoader->findWidget("deviceList")); |
131 HbListView* deviceList = qobject_cast<HbListView*>(mLoader->findWidget("deviceList")); |
142 deviceList->setSelectionMode(HbAbstractItemView::SingleSelection); |
132 deviceList->setSelectionMode(HbAbstractItemView::SingleSelection); |
143 |
133 |
144 mContentItemModel = new QStandardItemModel(this); |
134 mContentItemModel = new QStandardItemModel(this); |
145 deviceList->setModel(mContentItemModel); |
135 deviceList->setModel(mContentItemModel); |
150 |
140 |
151 mCancelAction = static_cast<HbAction*>( mLoader->findObject( "cancelAction" ) ); |
141 mCancelAction = static_cast<HbAction*>( mLoader->findObject( "cancelAction" ) ); |
152 |
142 |
153 connect(mMoreAction, SIGNAL(triggered()), this, SLOT(moreDevicesClicked())); |
143 connect(mMoreAction, SIGNAL(triggered()), this, SLOT(moreDevicesClicked())); |
154 connect(mCancelAction, SIGNAL(triggered()), this, SLOT(cancelClicked())); |
144 connect(mCancelAction, SIGNAL(triggered()), this, SLOT(cancelClicked())); |
155 |
145 mLastUsedDeviceDialog->setBackgroundFaded(false); |
|
146 mLastUsedDeviceDialog->setDismissPolicy(HbPopup::NoDismiss); |
|
147 mLastUsedDeviceDialog->setTimeout(HbPopup::NoTimeout); |
|
148 mLastUsedDeviceDialog->setAttribute(Qt::WA_DeleteOnClose); |
156 } |
149 } |
157 mLastUsedDeviceDialog->setBackgroundFaded(false); |
150 else |
158 mLastUsedDeviceDialog->setDismissPolicy(HbPopup::NoDismiss); |
151 { |
159 mLastUsedDeviceDialog->setTimeout(HbPopup::NoTimeout); |
152 mLastError = DocMLLoadingError; |
160 mLastUsedDeviceDialog->setAttribute(Qt::WA_DeleteOnClose); |
153 } |
161 return true; |
|
162 } |
154 } |
163 |
155 |
164 |
156 |
165 void BTMoreDevicesDialogWidget::moreDevicesClicked() |
157 void BTMoreDevicesDialogWidget::moreDevicesClicked() |
166 { |
158 { |