|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <hblabel.h> |
|
20 #include <hblistview.h> |
|
21 #include <hbtoolbar.h> |
|
22 #include <hbpushbutton.h> |
|
23 #include <hblistwidget.h> |
|
24 #include <qstandarditemmodel.h> |
|
25 #include "btmoredevicesdialogwidget.h" |
|
26 |
|
27 |
|
28 const char* DOCML_BT_MORE_DEV_DIALOG = ":/docml/bt-more-devices-dialog.docml"; |
|
29 |
|
30 |
|
31 BTMoreDevicesDialogWidget::BTMoreDevicesDialogWidget(const QVariantMap ¶meters) |
|
32 :HbDialog() |
|
33 { |
|
34 mDeviceDialogData = 0; |
|
35 constructDialog(parameters); |
|
36 } |
|
37 |
|
38 BTMoreDevicesDialogWidget::~BTMoreDevicesDialogWidget() |
|
39 { |
|
40 if(mLoader) |
|
41 { |
|
42 delete mLoader; |
|
43 mLoader = NULL; |
|
44 } |
|
45 if(mContentItemModel) |
|
46 { |
|
47 delete mContentItemModel; |
|
48 mContentItemModel =NULL; |
|
49 } |
|
50 } |
|
51 |
|
52 bool BTMoreDevicesDialogWidget::setDeviceDialogParameters(const QVariantMap ¶meters) |
|
53 { |
|
54 QStandardItem* listitem = new QStandardItem(); |
|
55 QStringList info; |
|
56 // info.append(parameters.value("deviceName").toString()); |
|
57 //info.append(parameters.value("deviceType").toString()); |
|
58 info.append(parameters.value(parameters.keys().at(0)).toString()); |
|
59 |
|
60 |
|
61 listitem->setData(info, Qt::DisplayRole); |
|
62 listitem->setIcon(icon()); |
|
63 // listitem->setIcon(icon(parameters.value("deviceType").toString())); |
|
64 |
|
65 mContentItemModel->appendRow(listitem); |
|
66 |
|
67 return true; |
|
68 } |
|
69 |
|
70 int BTMoreDevicesDialogWidget::deviceDialogError() const |
|
71 { |
|
72 return 0; |
|
73 } |
|
74 |
|
75 void BTMoreDevicesDialogWidget::closeDeviceDialog(bool byClient) |
|
76 { |
|
77 Q_UNUSED(byClient); |
|
78 this->close(); |
|
79 } |
|
80 |
|
81 HbPopup* BTMoreDevicesDialogWidget::deviceDialogWidget() const |
|
82 { |
|
83 return const_cast<BTMoreDevicesDialogWidget*>(this); |
|
84 } |
|
85 |
|
86 bool BTMoreDevicesDialogWidget::constructDialog(const QVariantMap &/*parameters*/) |
|
87 { |
|
88 mLoader = new HbDocumentLoader(); |
|
89 bool ok = false; |
|
90 |
|
91 mLoader->load(DOCML_BT_MORE_DEV_DIALOG, &ok); |
|
92 if(ok) |
|
93 { |
|
94 HbLabel* label = qobject_cast<HbLabel*>(mLoader->findWidget("label")); |
|
95 if(label) |
|
96 { |
|
97 label->setTextWrapping(Hb::TextWordWrap); |
|
98 label->setPlainText("Send to:"); |
|
99 } |
|
100 this->setHeadingWidget(label); |
|
101 HbPushButton* moreDevices = qobject_cast<HbPushButton*>(mLoader->findWidget("moreDevices")); |
|
102 HbPushButton* cancel = qobject_cast<HbPushButton*>(mLoader->findWidget("cancel")); |
|
103 |
|
104 HbListView* listView = qobject_cast<HbListView*>(mLoader->findWidget("listView")); |
|
105 listView->setSelectionMode(HbAbstractItemView::SingleSelection); |
|
106 |
|
107 mContentItemModel = new QStandardItemModel(this); |
|
108 listView->setModel(mContentItemModel);//, prototype); |
|
109 |
|
110 // QList<QVariant> values = parameters.values(); |
|
111 |
|
112 /* for(int i=0;i < values.count();i++) |
|
113 { |
|
114 QStandardItem* listitem = new QStandardItem(); |
|
115 // parameters. |
|
116 // QString string = values.at(i).toString(); |
|
117 |
|
118 listitem->setData(values.at(i).toString(), Qt::DisplayRole); |
|
119 // listitem->setData(QString("search"), Qt::DisplayRole); |
|
120 //Todo - Insert icons based on the device class |
|
121 QIcon icon(QString(":/qgn_prop_sml_bt.svg")); |
|
122 listitem->setIcon(icon); |
|
123 |
|
124 mContentItemModel->appendRow(listitem); |
|
125 }*/ |
|
126 |
|
127 connect(listView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); |
|
128 connect(moreDevices, SIGNAL(clicked()), this, SLOT(moreDevicesClicked())); |
|
129 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); |
|
130 |
|
131 QGraphicsWidget *widget = mLoader->findWidget(QString("container")); |
|
132 this->setContentWidget(widget); |
|
133 } |
|
134 |
|
135 |
|
136 this->setBackgroundFaded(false); |
|
137 setDismissPolicy(HbPopup::NoDismiss); |
|
138 setTimeout(HbPopup::NoTimeout); |
|
139 return true; |
|
140 } |
|
141 |
|
142 void BTMoreDevicesDialogWidget::hideEvent(QHideEvent *event) |
|
143 { |
|
144 HbDialog::hideEvent(event); |
|
145 // if(mDeviceDialogData == 0) |
|
146 { |
|
147 QVariantMap val; |
|
148 QVariant index(-1); |
|
149 val.insert("selectedindex",index); |
|
150 emit deviceDialogData(val); |
|
151 emit deviceDialogClosed(); |
|
152 } |
|
153 // |
|
154 } |
|
155 |
|
156 void BTMoreDevicesDialogWidget::showEvent(QShowEvent *event) |
|
157 { |
|
158 HbDialog::showEvent(event); |
|
159 } |
|
160 |
|
161 void BTMoreDevicesDialogWidget::moreDevicesClicked() |
|
162 { |
|
163 QVariantMap val; |
|
164 QVariant index("MoreDevices"); |
|
165 val.insert("MoreDevices",index); |
|
166 emit deviceDialogData(val); |
|
167 // mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog |
|
168 // this->close(); |
|
169 // TODO |
|
170 } |
|
171 |
|
172 void BTMoreDevicesDialogWidget::cancelClicked() |
|
173 { |
|
174 // TODO |
|
175 this->close(); |
|
176 } |
|
177 |
|
178 void BTMoreDevicesDialogWidget::deviceSelected(const QModelIndex& modelIndex) |
|
179 { |
|
180 int row = modelIndex.row(); |
|
181 QVariantMap val; |
|
182 QVariant index(row); |
|
183 val.insert("selectedindex",index); |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 emit deviceDialogData(val); |
|
189 // mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog |
|
190 // this->close(); |
|
191 |
|
192 } |
|
193 |
|
194 QIcon BTMoreDevicesDialogWidget::icon(/*QString deviceType*/) |
|
195 { |
|
196 /* if(deviceType == "Audio") |
|
197 { |
|
198 return (QIcon(QString(":/qgn_prop_bt_audio.svg"))); |
|
199 } |
|
200 else if(deviceType == "Car-kit") |
|
201 { |
|
202 return (QIcon(QString(":/qgn_prop_bt_car_kit.svg"))); |
|
203 } |
|
204 else if(deviceType == "Computer") |
|
205 { |
|
206 return (QIcon(QString(":/qgn_prop_bt_computer.svg"))); |
|
207 } |
|
208 else if(deviceType == "Headset") |
|
209 { |
|
210 return (QIcon(QString(":/qgn_prop_bt_headset.svg"))); |
|
211 } |
|
212 else if(deviceType == "Keyboard") |
|
213 { |
|
214 return (QIcon(QString(":/qgn_prop_bt_keyboard.svg"))); |
|
215 } |
|
216 else if(deviceType == "Mouse") |
|
217 { |
|
218 return (QIcon(QString(":/qgn_prop_bt_mouse.svg"))); |
|
219 } |
|
220 else if(deviceType == "Phone") |
|
221 { |
|
222 return (QIcon(QString(":/qgn_prop_bt_phone.svg"))); |
|
223 } |
|
224 else if(deviceType == "Printer") |
|
225 { |
|
226 return (QIcon(QString(":/qgn_prop_bt_printer.svg"))); |
|
227 } |
|
228 else |
|
229 { |
|
230 return (QIcon(QString(":/qgn_prop_bt_unknown.svg"))); |
|
231 }*/ |
|
232 return QIcon(QString(":/icons/qtg_large_bluetooth.svg")); |
|
233 } |
|
234 |