1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "xqservicelog.h" |
|
23 |
|
24 #include <QGraphicsLinearLayout> |
|
25 #include <hbtoolbar.h> |
|
26 #include <hbaction.h> |
|
27 #include <hblineedit.h> |
|
28 #include <hblabel.h> |
|
29 //#include <hbcheckbox.h> |
|
30 #include <hbmessagebox.h> |
|
31 #include <cntservicescontact.h> |
|
32 |
|
33 |
|
34 #include <QMessageBox> |
|
35 #include <QVariant> |
|
36 |
|
37 #include "hbserviceclientview.h" |
|
38 |
|
39 #include <xqservicerequest.h> |
|
40 |
|
41 #include "../hbserviceprovider/src/hbcontact.h" |
|
42 |
|
43 |
|
44 HbServiceClientView::HbServiceClientView(QGraphicsItem *parent) |
|
45 : HbView(parent) |
|
46 { |
|
47 XQSERVICE_DEBUG_PRINT("HbServiceClientView::HbServiceClientView"); |
|
48 setTitle(tr("HB Service client view")); |
|
49 |
|
50 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical,this); |
|
51 |
|
52 layout->addItem(new HbLabel("Call service",this)); |
|
53 mNumberEdit = new HbLineEdit(this); |
|
54 mNumberEdit->setText("+35850123456789"); |
|
55 layout->addItem(mNumberEdit); |
|
56 |
|
57 mServiceEdit = new HbLineEdit(this); |
|
58 mServiceEdit->setText("com.nokia.services.hbserviceprovider.Dialer"); |
|
59 layout->addItem(mServiceEdit); |
|
60 |
|
61 /* |
|
62 mServiceEmbedded = HbCheckBox("Embedded",this) |
|
63 mServiceEmbedded->setTristate(true); |
|
64 layout->addItem(mServiceEmbedded); |
|
65 */ |
|
66 |
|
67 mRetValue = new HbLineEdit(this); |
|
68 mRetValue->setText("*****"); |
|
69 layout->addItem(mRetValue); |
|
70 |
|
71 layout->addItem(new HbLabel("Map service",this)); |
|
72 mAddressEdit = new HbLineEdit(this); |
|
73 mAddressEdit->setText("Karakaari 13"); |
|
74 layout->addItem(mAddressEdit); |
|
75 |
|
76 mCityEdit = new HbLineEdit(this); |
|
77 mCityEdit->setText("Espoo"); |
|
78 layout->addItem(mCityEdit); |
|
79 |
|
80 mCountryEdit = new HbLineEdit(this); |
|
81 mCountryEdit->setText("Finland"); |
|
82 layout->addItem(mCountryEdit); |
|
83 |
|
84 mServiceMapEdit = new HbLineEdit(this); |
|
85 mServiceMapEdit->setText("com.nokia.services.hbserviceprovider.Map"); |
|
86 layout->addItem(mServiceMapEdit); |
|
87 |
|
88 mRetMapValue = new HbLineEdit(this); |
|
89 mRetMapValue->setText("*****"); |
|
90 layout->addItem(mRetMapValue); |
|
91 |
|
92 setLayout(layout); |
|
93 |
|
94 HbToolBar* toolBar = this->toolBar(); |
|
95 |
|
96 HbAction* callAction = new HbAction("Call"); |
|
97 connect(callAction, SIGNAL(triggered()), this, SLOT(callContact())); |
|
98 |
|
99 HbAction* callEmbeddedAction = new HbAction("Call Embedded"); |
|
100 connect(callEmbeddedAction, SIGNAL(triggered()), this, SLOT(callContactEmbedded())); |
|
101 |
|
102 HbAction* showAddressesAction = new HbAction("Select contacts"); |
|
103 connect(showAddressesAction, SIGNAL(triggered()), this, SLOT(launchContactSelecting())); |
|
104 |
|
105 toolBar->addAction(callAction); |
|
106 toolBar->addAction(callEmbeddedAction); |
|
107 toolBar->addAction(showAddressesAction); |
|
108 sndAsync = NULL; |
|
109 } |
|
110 |
|
111 HbServiceClientView::~HbServiceClientView() |
|
112 { |
|
113 XQSERVICE_DEBUG_PRINT("HbServiceClientView::~HbServiceClientView"); |
|
114 } |
|
115 |
|
116 void HbServiceClientView::callContact() |
|
117 { |
|
118 XQSERVICE_DEBUG_PRINT("HbServiceClientView::callContact"); |
|
119 doCallContact(false); |
|
120 } |
|
121 |
|
122 void HbServiceClientView::callContactEmbedded() |
|
123 { |
|
124 XQSERVICE_DEBUG_PRINT("HbServiceClientView::callContactEmbedded"); |
|
125 doCallContact(true); |
|
126 } |
|
127 |
|
128 void HbServiceClientView::doCallContact(bool isEmbedded) |
|
129 { |
|
130 XQSERVICE_DEBUG_PRINT("HbServiceClientView::doCallContact"); |
|
131 if (isEmbedded) { |
|
132 XQRequestInfo info; // matti |
|
133 info.setEmbedded(isEmbedded); |
|
134 |
|
135 XQServiceRequest snd(mServiceEdit->text(), |
|
136 "dial(QString)",isEmbedded); |
|
137 snd << mNumberEdit->text(); |
|
138 snd.setInfo(info); // matti |
|
139 |
|
140 QVariant retValue; |
|
141 |
|
142 bool res=snd.send(retValue); |
|
143 if (!res) { |
|
144 int returnvalue = snd.latestError(); |
|
145 mRetValue->setText(QString::number(returnvalue)); |
|
146 // mRetValue->setText("send fail!"); |
|
147 } |
|
148 else { |
|
149 if (retValue.isNull() || !retValue.isValid()) |
|
150 mRetValue->setText("ret value null or not valid"); |
|
151 else |
|
152 mRetValue->setText(retValue.toString()); |
|
153 } |
|
154 } |
|
155 else { |
|
156 if (sndAsync) |
|
157 delete sndAsync; |
|
158 sndAsync = new XQServiceRequest(mServiceEdit->text(), |
|
159 "dial(QString)",isEmbedded); |
|
160 connect(sndAsync, SIGNAL(requestCompleted(QVariant)), this, SLOT(requestCompleted(QVariant))); |
|
161 *sndAsync << mNumberEdit->text(); |
|
162 bool res=sndAsync->send(); |
|
163 if (!res) { |
|
164 int returnvalue = sndAsync->latestError(); |
|
165 mRetValue->setText(QString::number(returnvalue)); |
|
166 } |
|
167 else { |
|
168 mRetValue->setText("call on going..."); |
|
169 } |
|
170 } |
|
171 } |
|
172 |
|
173 void HbServiceClientView::requestCompleted(const QVariant& val) |
|
174 { |
|
175 XQSERVICE_DEBUG_PRINT("HbServiceClientView::requestCompleted"); |
|
176 mRetValue->setText(val.toString()); |
|
177 } |
|
178 |
|
179 void HbServiceClientView::showAddresses() |
|
180 { |
|
181 XQSERVICE_DEBUG_PRINT("HbServiceClientView::showAddresses"); |
|
182 XQServiceRequest snd(mServiceMapEdit->text(),"showAddresses(QString,QString,QString)"); |
|
183 snd << mAddressEdit->text(); |
|
184 snd << mCityEdit->text(); |
|
185 snd << mCountryEdit->text(); |
|
186 HbContactList retValue; |
|
187 bool res=snd.send(retValue); |
|
188 if (!res) { |
|
189 mRetMapValue->setText("send fail!"); |
|
190 } |
|
191 else { |
|
192 QString data; |
|
193 int count = 0; |
|
194 foreach (HbContact cnt,retValue) { |
|
195 //HbContact cnt = qVariantValue<HbContact>(v); |
|
196 QString tmp = QString::number(++count) + " : " + cnt.mLabel + " " + cnt.mNumber + "\n"; |
|
197 data.append(tmp) ; |
|
198 } |
|
199 HbMessageBox::information(data); |
|
200 // QMessageBox msgBox; |
|
201 // msgBox.setWindowTitle("Return value"); |
|
202 // msgBox.setText(data); |
|
203 // msgBox.exec(); |
|
204 //mRetMapValue->setText(QString::number(retValue)); |
|
205 } |
|
206 } |
|
207 |
|
208 void HbServiceClientView::launchContactSelecting() |
|
209 { |
|
210 if (sndAsync) |
|
211 delete sndAsync; |
|
212 sndAsync = new XQServiceRequest("com.nokia.services.phonebookservices.Fetch", |
|
213 "fetch(QString,QString,QString)", false); |
|
214 |
|
215 connect(sndAsync, SIGNAL(requestCompleted(QVariant)), |
|
216 this, SLOT(addSelectedRecipients(QVariant))); |
|
217 *sndAsync << "Select contact"; |
|
218 *sndAsync << KCntActionAll; |
|
219 *sndAsync << KCntFilterDisplayAll; |
|
220 |
|
221 bool result = sndAsync->send(); |
|
222 if (!result) { |
|
223 } |
|
224 |
|
225 } |
|
226 |
|
227 void HbServiceClientView::addSelectedRecipients(const QVariant &value) |
|
228 { |
|
229 CntServicesContactList list; |
|
230 if(value.canConvert<CntServicesContactList>()) { |
|
231 list = qVariantValue<CntServicesContactList>(value); |
|
232 } |
|
233 else { |
|
234 ; |
|
235 } |
|
236 |
|
237 if (list.count() == 0) { |
|
238 HbMessageBox::information(tr("Nothing returned")); |
|
239 // note.setTimeout(10000); |
|
240 // "Nothing returned" will be replaced by a hbTrId when it is ready |
|
241 // note.setText(tr("Nothing returned")); |
|
242 // note.information(); |
|
243 } |
|
244 else { |
|
245 QString data; |
|
246 foreach (CntServicesContact cnt, list) |
|
247 { |
|
248 QString recipientName = cnt.mDisplayName; |
|
249 data += recipientName + "\n"; |
|
250 } |
|
251 HbMessageBox::information(data); |
|
252 //HbMessageBox msgBox; |
|
253 //msgBox.setWindowTitle("Returned value"); |
|
254 //msgBox.setText(data); |
|
255 //msgBox.information(); |
|
256 } |
|
257 } |
|
258 |
|
259 Q_IMPLEMENT_USER_METATYPE(HbContact) |
|
260 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(HbContactList) |
|
261 |
|
262 Q_IMPLEMENT_USER_METATYPE(CntServicesContact) |
|
263 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList) |
|