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 <QApplication> |
|
25 #include <QKeyEvent> |
|
26 #include <QLabel> |
|
27 #include <QVBoxLayout> |
|
28 #include <QStackedWidget> |
|
29 #include <QImageReader> |
|
30 #include <QDebug> |
|
31 #include <QTimer> |
|
32 #include <QPushButton> |
|
33 #include <QLineEdit> |
|
34 #include <QListView> |
|
35 #include <QMessageBox> |
|
36 #include <xqsharablefile.h> |
|
37 |
|
38 #include "testservicedata.h" |
|
39 #include "serviceapp.h" |
|
40 #include <xqserviceutil.h> |
|
41 |
|
42 ServiceApp::ServiceApp(QWidget *parent, Qt::WFlags f) |
|
43 : QWidget(parent, f), |
|
44 mDialService(NULL), |
|
45 mUriService(NULL), |
|
46 mFileService(NULL), |
|
47 mNewDialService(NULL), |
|
48 mNewFileService(NULL), |
|
49 mNewUriService(NULL) |
|
50 { |
|
51 XQSERVICE_DEBUG_PRINT("ServiceApp::ServiceApp"); |
|
52 if (XQServiceUtil::isService()) |
|
53 { |
|
54 mDialService = new DialerService(this); |
|
55 mUriService = new UriService(this); |
|
56 mFileService = new FileService(this); |
|
57 mNewDialService = new NewDialerService(this); |
|
58 mNewUriService = new NewUriService(this); |
|
59 mNewFileService = new NewFileService(this); |
|
60 } |
|
61 /* Adjust the palette */ |
|
62 #if defined(Q_WS_S60) |
|
63 QPalette p = qApp->palette(); |
|
64 QColor color(192,192,192); |
|
65 QColor bg(201,250,250); |
|
66 p.setColor(QPalette::Highlight, color.lighter(200)); |
|
67 p.setColor(QPalette::Text, Qt::black); |
|
68 p.setColor(QPalette::Base, bg); |
|
69 p.setColor(QPalette::WindowText, Qt::black); |
|
70 p.setColor(QPalette::Window, bg); |
|
71 p.setColor(QPalette::ButtonText, Qt::black); |
|
72 p.setColor(QPalette::Button, color.lighter(150)); |
|
73 p.setColor(QPalette::Link, QColor(240,40,40)); |
|
74 |
|
75 qApp->setPalette(p); |
|
76 #endif |
|
77 |
|
78 QPushButton *quitButton = new QPushButton(tr("Quit")); |
|
79 QPushButton *answerButtonDial = new QPushButton(tr("Dial answer")); |
|
80 QPushButton *answerButtonUri = new QPushButton(tr("Uri answer")); |
|
81 QPushButton *answerButtonFile = new QPushButton(tr("File answer")); |
|
82 connect(quitButton, SIGNAL(clicked()), this, SLOT(quit())); |
|
83 connect(answerButtonDial, SIGNAL(clicked()), this, SLOT(answerDial())); |
|
84 connect(answerButtonUri, SIGNAL(clicked()), this, SLOT(answerUri())); |
|
85 connect(answerButtonFile, SIGNAL(clicked()), this, SLOT(answerFile())); |
|
86 |
|
87 /* |
|
88 mEndCallButton = new QPushButton(tr("End Call")); |
|
89 mEndCallButton->setEnabled(false); |
|
90 connect(mEndCallButton, SIGNAL(clicked()), this, SLOT(endCall())); |
|
91 */ |
|
92 bool isService = XQServiceUtil::isService(); |
|
93 QString interface = XQServiceUtil::interfaceName(); |
|
94 QString operation = XQServiceUtil::operationName(); |
|
95 |
|
96 QString t = "SERVICEAPP:\n"; |
|
97 t = t + (isService ? " Service launch\n" : " Normal launch\n"); |
|
98 t = t + (XQServiceUtil::isEmbedded() ? " Embedded\n" : " Not embedded\n"); |
|
99 t = t + (" Interface=" + interface + "\n"); |
|
100 t = t + (" Operation=" + operation + "\n"); |
|
101 |
|
102 QLabel *title = new QLabel(t); |
|
103 |
|
104 mLabel = new QLabel(""); |
|
105 mNumber = new QLineEdit(""); |
|
106 |
|
107 QVBoxLayout *vl = new QVBoxLayout; |
|
108 vl->setMargin(0); |
|
109 vl->setSpacing(0); |
|
110 |
|
111 vl->addWidget(quitButton); |
|
112 vl->addWidget(answerButtonDial); |
|
113 vl->addWidget(answerButtonUri); |
|
114 vl->addWidget(answerButtonFile); |
|
115 vl->addWidget(title); |
|
116 vl->addWidget(mLabel); |
|
117 vl->addWidget(mNumber); |
|
118 |
|
119 setLayout(vl); |
|
120 |
|
121 #if defined(Q_WS_X11) || defined(Q_WS_WIN) |
|
122 setFixedSize(QSize(360,640)); // nHD |
|
123 #elif defined(Q_WS_S60) |
|
124 // showMaximized(); |
|
125 showFullScreen(); |
|
126 #endif |
|
127 // new DialerService(this); |
|
128 } |
|
129 |
|
130 |
|
131 ServiceApp::~ServiceApp() |
|
132 { |
|
133 XQSERVICE_DEBUG_PRINT("ServiceApp::~ServiceApp"); |
|
134 delete mDialService; |
|
135 delete mUriService; |
|
136 delete mFileService; |
|
137 } |
|
138 |
|
139 void ServiceApp::quit() |
|
140 { |
|
141 XQSERVICE_DEBUG_PRINT("ServiceApp::quit"); |
|
142 qApp->quit(); |
|
143 } |
|
144 |
|
145 void ServiceApp::answerDial() |
|
146 { |
|
147 XQSERVICE_DEBUG_PRINT("ServiceApp::answerDial"); |
|
148 if (mDialService && mDialService->asyncAnswer()) |
|
149 { |
|
150 mDialService->complete(mNumber->text()); |
|
151 } |
|
152 if (mNewDialService && mNewDialService->asyncAnswer()) |
|
153 { |
|
154 mNewDialService->complete(mNumber->text()); |
|
155 } |
|
156 } |
|
157 |
|
158 |
|
159 void ServiceApp::answerUri() |
|
160 { |
|
161 XQSERVICE_DEBUG_PRINT("ServiceApp::answerUri"); |
|
162 if (mUriService && mUriService->asyncAnswer()) |
|
163 { |
|
164 mUriService->complete(true); |
|
165 } |
|
166 if (mNewUriService && mNewUriService->asyncAnswer()) |
|
167 { |
|
168 mNewUriService->complete(true); |
|
169 } |
|
170 } |
|
171 |
|
172 void ServiceApp::answerFile() |
|
173 { |
|
174 XQSERVICE_DEBUG_PRINT("ServiceApp::answerFile"); |
|
175 if (mFileService && mFileService->asyncAnswer()) |
|
176 { |
|
177 mFileService->complete(true); |
|
178 } |
|
179 if (mNewFileService && mNewFileService->asyncAnswer()) |
|
180 { |
|
181 mNewFileService->complete(true); |
|
182 } |
|
183 } |
|
184 |
|
185 |
|
186 |
|
187 void ServiceApp::endCall() |
|
188 { |
|
189 XQSERVICE_DEBUG_PRINT("ServiceApp::endCall"); |
|
190 //QVBoxLayout *vl = qobject_cast<QVBoxLayout *>(layout()) ; |
|
191 //vl->removeWidget(mEndCallButton); |
|
192 |
|
193 //XQServiceUtil::toBackground(true); |
|
194 } |
|
195 |
|
196 void ServiceApp::setLabelNumber(QString label,QString number) |
|
197 { |
|
198 XQSERVICE_DEBUG_PRINT("ServiceApp::setLabelNumber"); |
|
199 mLabel->setText(label); |
|
200 mNumber->setText(number); |
|
201 } |
|
202 |
|
203 // ----------DialerService--------------- |
|
204 |
|
205 DialerService::DialerService(ServiceApp* parent) |
|
206 : XQServiceProvider(QLatin1String("com.nokia.services.serviceapp.Dialer"),parent), |
|
207 mServiceApp(parent) |
|
208 { |
|
209 XQSERVICE_DEBUG_PRINT("DialerService::DialerService"); |
|
210 publishAll(); |
|
211 } |
|
212 |
|
213 DialerService::~DialerService() |
|
214 { |
|
215 XQSERVICE_DEBUG_PRINT("DialerService::~DialerService"); |
|
216 } |
|
217 |
|
218 void DialerService::complete(QString number) |
|
219 { |
|
220 XQSERVICE_DEBUG_PRINT("DialerService::complete"); |
|
221 |
|
222 // Complete all IDs |
|
223 foreach (quint32 reqId, mAsyncReqIds) |
|
224 { |
|
225 XQSERVICE_DEBUG_PRINT("DialerService::complete %d", reqId); |
|
226 completeRequest(reqId, number.toInt()); |
|
227 } |
|
228 } |
|
229 |
|
230 int DialerService::dial(const QString& number, bool asyncAnswer) |
|
231 { |
|
232 Q_UNUSED(asyncAnswer); |
|
233 |
|
234 XQRequestInfo info = requestInfo(); |
|
235 QString testCase = (info.info(TESTCASE_INFO_KEY)).toString(); |
|
236 XQSERVICE_DEBUG_PRINT("XQTESTER serviceapp,%s,DialerService::dial", qPrintable(testCase)); |
|
237 |
|
238 XQSERVICE_DEBUG_PRINT("\tRequest info: id=%d,sid=%X,vid=%X", info.id(), info.clientSecureId(), info.clientVendorId()); |
|
239 QSet<int> caps = info.clientCapabilities(); |
|
240 QSetIterator<int> i(caps); |
|
241 while (i.hasNext()) |
|
242 qDebug() << "Has capability " << i.next(); |
|
243 XQSERVICE_DEBUG_PRINT("\tRequest info: embed=%d,sync=%d", info.isEmbedded(), info.isSynchronous()); |
|
244 |
|
245 bool isAsync = !info.isSynchronous(); |
|
246 QString label = "Dialer::dial:\n"; |
|
247 label += QString("number=%1\n").arg(number); |
|
248 label += QString("async=%1\n").arg(isAsync); |
|
249 |
|
250 connect(this, SIGNAL(returnValueDelivered()), this, SLOT(handleAnswerDelivered())); |
|
251 |
|
252 mNumber = number ; |
|
253 mServiceApp->setLabelNumber(label, number); |
|
254 int ret = 0; |
|
255 if (isAsync) |
|
256 { |
|
257 mAsyncReqIds.insertMulti(info.clientSecureId(), setCurrentRequestAsync()); |
|
258 connect(this, SIGNAL(clientDisconnected()), this, SLOT(handleClientDisconnect())); |
|
259 } |
|
260 else |
|
261 { |
|
262 ret = number.toInt(); |
|
263 } |
|
264 return ret; |
|
265 } |
|
266 |
|
267 CntServicesContactList DialerService::testContactList(CntServicesContactList list) |
|
268 { |
|
269 XQSERVICE_DEBUG_PRINT("DialerService::testContactList"); |
|
270 showRecipients(list); |
|
271 |
|
272 // Create output |
|
273 CntServicesContact cnt1; |
|
274 cnt1.mDisplayName = "Test1-Return"; |
|
275 cnt1.mPhoneNumber = "060-1111111"; |
|
276 cnt1.mEmailAddress = "test1.return@nokia.com"; |
|
277 |
|
278 CntServicesContact cnt2; |
|
279 cnt2.mDisplayName = "Test1-Return"; |
|
280 cnt2.mPhoneNumber = "060-2222222"; |
|
281 cnt2.mEmailAddress = "test2.return@nokia.com"; |
|
282 |
|
283 CntServicesContactList ret; |
|
284 ret.append(cnt1); |
|
285 ret.append(cnt2); |
|
286 |
|
287 return ret; |
|
288 |
|
289 } |
|
290 |
|
291 QVariant DialerService::testVariant(QVariant variant) |
|
292 { |
|
293 XQRequestInfo info = requestInfo(); |
|
294 QString testCase = (info.info(TESTCASE_INFO_KEY)).toString(); |
|
295 XQSERVICE_DEBUG_PRINT("XQTESTER serviceapp,%s,DialerService::testVariant", qPrintable(testCase)); |
|
296 |
|
297 XQSERVICE_DEBUG_PRINT("DialerService::testVariant::variant(%d,%d,%s)", |
|
298 variant.type(), variant.userType(), variant.typeName()); |
|
299 XQSERVICE_DEBUG_PRINT("DialerService::testVariant::variant value=%s", qPrintable(variant.toString())); |
|
300 |
|
301 if (variant.typeName() == QLatin1String("QStringList")) |
|
302 { |
|
303 qDebug() << "DialerService::testVariant QStringList"; |
|
304 QStringList ret = variant.toStringList(); |
|
305 return qVariantFromValue(ret); |
|
306 } |
|
307 else if (variant.typeName() == QLatin1String("XQShabarableFile")) |
|
308 { |
|
309 qDebug() << "DialerService::testVariant XQShabarableFile"; |
|
310 XQSharableFile sf = variant.value<XQSharableFile>(); |
|
311 |
|
312 RFile file; |
|
313 bool ok = sf.getHandle( file ); |
|
314 if (ok) |
|
315 { |
|
316 HBufC8* data = HBufC8::NewL(100); |
|
317 TPtr8 ptr = data->Des(); |
|
318 TInt err = file.Read( ptr ); |
|
319 QString text = QString::fromUtf8((const char *)(data->Ptr()), data->Length()); |
|
320 XQSERVICE_DEBUG_PRINT("DialerService::testVariant ::file content,%d,%s", err, qPrintable(text)); |
|
321 sf.close(); |
|
322 delete data; |
|
323 } |
|
324 |
|
325 return QVariant(ok); |
|
326 |
|
327 } |
|
328 else if (variant.typeName() == QLatin1String("XQRequestInfo")) |
|
329 { |
|
330 qDebug() << "DialerService::testVariant XQRequestInfo"; |
|
331 XQRequestInfo info = variant.value<XQRequestInfo>(); |
|
332 QStringList keys = info.infoKeys(); |
|
333 foreach (QString key, keys) |
|
334 { |
|
335 XQSERVICE_DEBUG_PRINT("DialerService::testVariant: info %s=%s", |
|
336 qPrintable(key), |
|
337 qPrintable(info.info(key).toString())); |
|
338 } |
|
339 |
|
340 return qVariantFromValue(info); |
|
341 |
|
342 } |
|
343 else if (variant.typeName() == QLatin1String("CntServicesContactList")) |
|
344 { |
|
345 qDebug() << "DialerService::testVariant CntServicesContactList"; |
|
346 // Show input |
|
347 showRecipients(variant); |
|
348 |
|
349 // Create output |
|
350 CntServicesContact cnt1; |
|
351 cnt1.mDisplayName = "Test1-Return"; |
|
352 cnt1.mPhoneNumber = "060-1111111"; |
|
353 cnt1.mEmailAddress = "test1.return@nokia.com"; |
|
354 |
|
355 CntServicesContact cnt2; |
|
356 cnt2.mDisplayName = "Test1-Return"; |
|
357 cnt2.mPhoneNumber = "060-2222222"; |
|
358 cnt2.mEmailAddress = "test2.return@nokia.com"; |
|
359 |
|
360 CntServicesContactList list; |
|
361 list.append(cnt1); |
|
362 list.append(cnt2); |
|
363 |
|
364 // Return contact list back |
|
365 return qVariantFromValue(list); |
|
366 } |
|
367 else |
|
368 { |
|
369 return variant.toString(); |
|
370 } |
|
371 } |
|
372 |
|
373 void DialerService::handleClientDisconnect() |
|
374 { |
|
375 XQSERVICE_DEBUG_PRINT("DialerService::handleClientDisconnect"); |
|
376 |
|
377 // Get the info of the cancelled request |
|
378 XQRequestInfo info = requestInfo(); |
|
379 XQSERVICE_DEBUG_PRINT("\tDisconnected request info: id=%d,sid=%X,vid=%X", info.id(),info.clientSecureId(), info.clientVendorId()); |
|
380 |
|
381 // Just quit service application if client ends |
|
382 mServiceApp->quit(); |
|
383 } |
|
384 |
|
385 void DialerService::handleAnswerDelivered() |
|
386 { |
|
387 XQSERVICE_DEBUG_PRINT("DialerService::handleAnswerDelivered"); |
|
388 XQRequestInfo info = requestInfo(); |
|
389 XQSERVICE_DEBUG_PRINT("\tRequest info: sid=%X,vid=%X", info.clientSecureId(), info.clientVendorId()); |
|
390 // Done |
|
391 mAsyncReqIds.remove(info.clientSecureId()); |
|
392 } |
|
393 |
|
394 |
|
395 |
|
396 void DialerService::showRecipients(QVariant &value) |
|
397 { |
|
398 CntServicesContactList list; |
|
399 if(value.canConvert<CntServicesContactList>()) |
|
400 { |
|
401 qDebug() << "DialerService::showRecipients: canConvert"; |
|
402 list = qVariantValue<CntServicesContactList>(value); |
|
403 } |
|
404 else |
|
405 { |
|
406 qDebug() << "DialerService::showRecipients: canConvert NOK"; |
|
407 return; |
|
408 } |
|
409 |
|
410 showRecipients(list); |
|
411 } |
|
412 |
|
413 void DialerService::showRecipients(CntServicesContactList &list) |
|
414 { |
|
415 if (list.count() == 0) |
|
416 { |
|
417 qDebug() << "DialerService::showRecipients(2): Count==0"; |
|
418 } |
|
419 else |
|
420 { |
|
421 for (int i = 0; i < list.count(); ++i) |
|
422 { |
|
423 qDebug() << "DialerService::showRecipients(2)[" << i << "]=" << list[i].mDisplayName; |
|
424 qDebug() << "DialerService::showRecipients(2)[" << i << "]=" << list[i].mPhoneNumber; |
|
425 qDebug() << "DialerService::showRecipients(2)[" << i << "]=" << list[i].mEmailAddress; |
|
426 } |
|
427 } |
|
428 } |
|
429 |
|
430 |
|
431 // ----------New dialler service--------------- |
|
432 |
|
433 NewDialerService::NewDialerService(ServiceApp* parent) |
|
434 : XQServiceProvider(QLatin1String("serviceapp.Dialer"),parent), |
|
435 mServiceApp(parent) |
|
436 { |
|
437 XQSERVICE_DEBUG_PRINT("NewDialerService::NewDialerService"); |
|
438 publishAll(); |
|
439 } |
|
440 |
|
441 NewDialerService::~NewDialerService() |
|
442 { |
|
443 XQSERVICE_DEBUG_PRINT("NewDialerService::~NewDialerService"); |
|
444 } |
|
445 |
|
446 void NewDialerService::complete(QString number) |
|
447 { |
|
448 XQSERVICE_DEBUG_PRINT("NewDialerService::complete"); |
|
449 |
|
450 // Complete all IDs |
|
451 foreach (quint32 reqId, mAsyncReqIds) |
|
452 { |
|
453 XQSERVICE_DEBUG_PRINT("NewDialerService::complete %d", reqId); |
|
454 completeRequest(reqId, number.toInt()); |
|
455 } |
|
456 } |
|
457 |
|
458 int NewDialerService::dial(const QString& number, bool asyncAnswer) |
|
459 { |
|
460 Q_UNUSED(asyncAnswer); |
|
461 |
|
462 XQRequestInfo info = requestInfo(); |
|
463 QString testCase = (info.info(TESTCASE_INFO_KEY)).toString(); |
|
464 XQSERVICE_DEBUG_PRINT("XQTESTER serviceapp,%s,NewDialerService::dial", qPrintable(testCase)); |
|
465 |
|
466 XQSERVICE_DEBUG_PRINT("\tRequest info: id=%d,sid=%X,vid=%X", info.id(), info.clientSecureId(), info.clientVendorId()); |
|
467 QSet<int> caps = info.clientCapabilities(); |
|
468 QSetIterator<int> i(caps); |
|
469 while (i.hasNext()) |
|
470 qDebug() << "Has capability " << i.next(); |
|
471 XQSERVICE_DEBUG_PRINT("\tRequest info: embed=%d,sync=%d", info.isEmbedded(), info.isSynchronous()); |
|
472 |
|
473 bool isAsync = !info.isSynchronous(); |
|
474 |
|
475 QString label = "NewDialer::dial:\n"; |
|
476 label += QString("number=%1\n").arg(number); |
|
477 label += QString("async=%1\n").arg(isAsync); |
|
478 |
|
479 connect(this, SIGNAL(returnValueDelivered()), this, SLOT(handleAnswerDelivered())); |
|
480 |
|
481 mNumber = number ; |
|
482 mServiceApp->setLabelNumber(label, number); |
|
483 int ret = 0; |
|
484 if (isAsync) |
|
485 { |
|
486 mAsyncReqIds.insertMulti(info.clientSecureId(), setCurrentRequestAsync()); |
|
487 connect(this, SIGNAL(clientDisconnected()), this, SLOT(handleClientDisconnect())); |
|
488 } |
|
489 else |
|
490 { |
|
491 ret = number.toInt(); |
|
492 } |
|
493 return ret; |
|
494 } |
|
495 |
|
496 CntServicesContactList NewDialerService::testContactList(CntServicesContactList list) |
|
497 { |
|
498 XQSERVICE_DEBUG_PRINT("NewDialerService::testContactList"); |
|
499 showRecipients(list); |
|
500 |
|
501 // Create output |
|
502 CntServicesContact cnt1; |
|
503 cnt1.mDisplayName = "Test1-Return"; |
|
504 cnt1.mPhoneNumber = "060-1111111"; |
|
505 cnt1.mEmailAddress = "test1.return@nokia.com"; |
|
506 |
|
507 CntServicesContact cnt2; |
|
508 cnt2.mDisplayName = "Test1-Return"; |
|
509 cnt2.mPhoneNumber = "060-2222222"; |
|
510 cnt2.mEmailAddress = "test2.return@nokia.com"; |
|
511 |
|
512 CntServicesContactList ret; |
|
513 ret.append(cnt1); |
|
514 ret.append(cnt2); |
|
515 |
|
516 return ret; |
|
517 |
|
518 } |
|
519 |
|
520 QVariant NewDialerService::testVariant(QVariant variant) |
|
521 { |
|
522 XQRequestInfo info = requestInfo(); |
|
523 QString testCase = (info.info(TESTCASE_INFO_KEY)).toString(); |
|
524 XQSERVICE_DEBUG_PRINT("XQTESTER serviceapp,%s,NewDialerService::testVariant", qPrintable(testCase)); |
|
525 |
|
526 XQSERVICE_DEBUG_PRINT("NewDialerService::testVariant::variant(%d,%d,%s)", |
|
527 variant.type(), variant.userType(), variant.typeName()); |
|
528 XQSERVICE_DEBUG_PRINT("NewDialerService::testVariant::variant value=%s", qPrintable(variant.toString())); |
|
529 |
|
530 if (variant.typeName() == QLatin1String("QStringList")) |
|
531 { |
|
532 QStringList ret = variant.toStringList(); |
|
533 return qVariantFromValue(ret); |
|
534 } |
|
535 else if (variant.typeName() == QLatin1String("TestServiceDataList")) |
|
536 { |
|
537 qDebug() << "DialerService::testVariant TestServiceDataList"; |
|
538 TestServiceDataList list; |
|
539 if(variant.canConvert<TestServiceDataList>()) |
|
540 { |
|
541 qDebug() << "DialerService::TestServiceDataList: canConvert OK"; |
|
542 list = qVariantValue<TestServiceDataList>(variant); |
|
543 for (int i = 0; i < list.count(); ++i) |
|
544 { |
|
545 qDebug() << "DialerService::TestServiceDataList[" << i << "]=" << list[i].mType; |
|
546 qDebug() << "DialerService::TestServiceDataList[" << i << "]=" << list[i].mData.toString(); |
|
547 } |
|
548 } |
|
549 else |
|
550 { |
|
551 qDebug() << "DialerService::TestServiceDataList: canConvert NOK"; |
|
552 } |
|
553 |
|
554 TestServiceDataList resultList; |
|
555 QVariant v1; |
|
556 QVariant v2; |
|
557 QVariant v3; |
|
558 v1.setValue((int)99); |
|
559 v2.setValue((bool)false); |
|
560 v3.setValue(QString("Variant3 return")); |
|
561 TestServiceData data1(1, v1); |
|
562 TestServiceData data2(2, v2); |
|
563 TestServiceData data3(3, v3); |
|
564 resultList.append(data1); |
|
565 resultList.append(data2); |
|
566 resultList.append(data3); |
|
567 |
|
568 // Return some data back |
|
569 return qVariantFromValue(resultList); |
|
570 } |
|
571 else if (variant.typeName() == QLatin1String("XQShabarableFile")) |
|
572 { |
|
573 XQSharableFile sf = variant.value<XQSharableFile>(); |
|
574 |
|
575 RFile file; |
|
576 bool ok = sf.getHandle( file ); |
|
577 if (ok) |
|
578 { |
|
579 HBufC8* data = HBufC8::NewL(100); |
|
580 TPtr8 ptr = data->Des(); |
|
581 TInt err = file.Read( ptr ); |
|
582 QString text = QString::fromUtf8((const char *)(data->Ptr()), data->Length()); |
|
583 XQSERVICE_DEBUG_PRINT("NewDialerService::testVariant ::file content,%d,%s", err, qPrintable(text)); |
|
584 sf.close(); |
|
585 delete data; |
|
586 } |
|
587 |
|
588 return QVariant(ok); |
|
589 |
|
590 } |
|
591 else if (variant.typeName() == QLatin1String("XQRequestInfo")) |
|
592 { |
|
593 XQRequestInfo info = variant.value<XQRequestInfo>(); |
|
594 QStringList keys = info.infoKeys(); |
|
595 foreach (QString key, keys) |
|
596 { |
|
597 XQSERVICE_DEBUG_PRINT("NewDialerService::testVariant: info %s=%s", |
|
598 qPrintable(key), |
|
599 qPrintable(info.info(key).toString())); |
|
600 } |
|
601 |
|
602 return qVariantFromValue(info); |
|
603 |
|
604 } |
|
605 else if (variant.typeName() == QLatin1String("CntServicesContactList")) |
|
606 { |
|
607 // Show input |
|
608 showRecipients(variant); |
|
609 |
|
610 // Create output |
|
611 CntServicesContact cnt1; |
|
612 cnt1.mDisplayName = "Test1-Return"; |
|
613 cnt1.mPhoneNumber = "060-1111111"; |
|
614 cnt1.mEmailAddress = "test1.return@nokia.com"; |
|
615 |
|
616 CntServicesContact cnt2; |
|
617 cnt2.mDisplayName = "Test1-Return"; |
|
618 cnt2.mPhoneNumber = "060-2222222"; |
|
619 cnt2.mEmailAddress = "test2.return@nokia.com"; |
|
620 |
|
621 CntServicesContactList list; |
|
622 list.append(cnt1); |
|
623 list.append(cnt2); |
|
624 |
|
625 // Return contact list back |
|
626 return qVariantFromValue(list); |
|
627 } |
|
628 else if (variant.typeName() == QLatin1String("QByteArray")) |
|
629 { |
|
630 QByteArray val = variant.value<QByteArray>(); |
|
631 qDebug() << "DialerService::QByteArray size=" << val.size(); |
|
632 return qVariantFromValue(val); |
|
633 } |
|
634 else |
|
635 { |
|
636 return variant.toString(); |
|
637 } |
|
638 } |
|
639 |
|
640 void NewDialerService::handleClientDisconnect() |
|
641 { |
|
642 XQSERVICE_DEBUG_PRINT("NewDialerService::handleClientDisconnect"); |
|
643 |
|
644 // Get the info of the cancelled request |
|
645 XQRequestInfo info = requestInfo(); |
|
646 XQSERVICE_DEBUG_PRINT("\tDisconnected request info: id=%d,sid=%X,vid=%X", info.id(),info.clientSecureId(), info.clientVendorId()); |
|
647 |
|
648 // Just quit service application if client ends |
|
649 mServiceApp->quit(); |
|
650 } |
|
651 |
|
652 void NewDialerService::handleAnswerDelivered() |
|
653 { |
|
654 XQSERVICE_DEBUG_PRINT("NewDialerService::handleAnswerDelivered"); |
|
655 XQRequestInfo info = requestInfo(); |
|
656 XQSERVICE_DEBUG_PRINT("\tRequest info: sid=%X,vid=%X", info.clientSecureId(), info.clientVendorId()); |
|
657 // Done |
|
658 mAsyncReqIds.remove(info.clientSecureId()); |
|
659 } |
|
660 |
|
661 |
|
662 |
|
663 void NewDialerService::showRecipients(QVariant &value) |
|
664 { |
|
665 CntServicesContactList list; |
|
666 if(value.canConvert<CntServicesContactList>()) |
|
667 { |
|
668 qDebug() << "NewDialerService::showRecipients: canConvert"; |
|
669 list = qVariantValue<CntServicesContactList>(value); |
|
670 } |
|
671 else |
|
672 { |
|
673 qDebug() << "NewDialerService::showRecipients: canConvert NOK"; |
|
674 return; |
|
675 } |
|
676 |
|
677 showRecipients(list); |
|
678 } |
|
679 |
|
680 void NewDialerService::showRecipients(CntServicesContactList &list) |
|
681 { |
|
682 if (list.count() == 0) |
|
683 { |
|
684 qDebug() << "NewDialerService::showRecipients(2): Count==0"; |
|
685 } |
|
686 else |
|
687 { |
|
688 for (int i = 0; i < list.count(); ++i) |
|
689 { |
|
690 qDebug() << "NewDialerService::showRecipients(2)[" << i << "]=" << list[i].mDisplayName; |
|
691 qDebug() << "NewDialerService::showRecipients(2)[" << i << "]=" << list[i].mPhoneNumber; |
|
692 qDebug() << "NewDialerService::showRecipients(2)[" << i << "]=" << list[i].mEmailAddress; |
|
693 } |
|
694 } |
|
695 } |
|
696 |
|
697 |
|
698 |
|
699 Q_IMPLEMENT_USER_METATYPE(CntServicesContact) |
|
700 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList) |
|
701 |
|
702 Q_IMPLEMENT_USER_METATYPE(TestServiceData) |
|
703 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(TestServiceDataList) |
|
704 |
|
705 // ----------UriService--------------- |
|
706 |
|
707 UriService::UriService(ServiceApp* parent) |
|
708 : XQServiceProvider(QLatin1String("com.nokia.services.serviceapp.com.nokia.symbian.IUriView"),parent), |
|
709 mServiceApp(parent) |
|
710 |
|
711 { |
|
712 XQSERVICE_DEBUG_PRINT("UriService::UriService"); |
|
713 publishAll(); |
|
714 } |
|
715 |
|
716 UriService::~UriService() |
|
717 { |
|
718 XQSERVICE_DEBUG_PRINT("UriService::~UriService"); |
|
719 } |
|
720 |
|
721 void UriService::complete(bool ok) |
|
722 { |
|
723 Q_UNUSED(ok) |
|
724 XQSERVICE_DEBUG_PRINT("UriService::complete"); |
|
725 // Complete all IDs |
|
726 foreach (quint32 reqId, mAsyncReqIds) |
|
727 { |
|
728 XQSERVICE_DEBUG_PRINT("UriService::complete %d", reqId); |
|
729 completeRequest(reqId, QVariant(mRetValue)); |
|
730 } |
|
731 } |
|
732 |
|
733 bool UriService::view(const QString& uri) |
|
734 { |
|
735 XQSERVICE_DEBUG_PRINT("UriService::view(1)"); |
|
736 return view(uri, true); |
|
737 } |
|
738 |
|
739 bool UriService::view(const QString& uri, bool retValue) |
|
740 { |
|
741 XQRequestInfo info = requestInfo(); |
|
742 QString testCase = (info.info(TESTCASE_INFO_KEY)).toString(); |
|
743 XQSERVICE_DEBUG_PRINT("XQTESTER serviceapp,%s,UriService::view", qPrintable(testCase)); |
|
744 |
|
745 QString label = "IUriView::view\n:"; |
|
746 label += QString ("Uri=%1\n").arg(uri); |
|
747 label += QString ("retValue=%1\n").arg(retValue); |
|
748 QString param = QString ("retValue=%1\n").arg(retValue); |
|
749 |
|
750 bool isAsync = !info.isSynchronous();; |
|
751 connect(this, SIGNAL(returnValueDelivered()), this, SLOT(handleAnswerDelivered())); |
|
752 |
|
753 mRetValue = retValue; |
|
754 mServiceApp->setLabelNumber(label,param); |
|
755 if (isAsync) |
|
756 { |
|
757 mAsyncReqIds.insertMulti(info.clientSecureId(), setCurrentRequestAsync()); |
|
758 connect(this, SIGNAL(clientDisconnected()), this, SLOT(handleClientDisconnect())); |
|
759 } |
|
760 |
|
761 return retValue; |
|
762 } |
|
763 |
|
764 void UriService::handleClientDisconnect() |
|
765 { |
|
766 XQSERVICE_DEBUG_PRINT("UriService::handleClientDisconnect"); |
|
767 XQRequestInfo info = requestInfo(); |
|
768 XQSERVICE_DEBUG_PRINT("\tRequest info: id=%d,sid=%X,vid=%X", info.id(),info.clientSecureId(), info.clientVendorId()); |
|
769 |
|
770 mAsyncReqIds.remove(info.clientSecureId()); |
|
771 mServiceApp->quit(); |
|
772 } |
|
773 |
|
774 void UriService::handleAnswerDelivered() |
|
775 { |
|
776 XQSERVICE_DEBUG_PRINT("UriService::handleAnswerDelivered"); |
|
777 XQRequestInfo info = requestInfo(); |
|
778 XQSERVICE_DEBUG_PRINT("\tRequest info: sid=%X,vid=%X", info.clientSecureId(), info.clientVendorId()); |
|
779 // Done |
|
780 mAsyncReqIds.remove(info.clientSecureId()); |
|
781 |
|
782 } |
|
783 |
|
784 // ----------NewUriService--------------- |
|
785 |
|
786 NewUriService::NewUriService(ServiceApp* parent) |
|
787 : XQServiceProvider(QLatin1String("serviceapp.com.nokia.symbian.IUriView"),parent), |
|
788 mServiceApp(parent) |
|
789 |
|
790 { |
|
791 XQSERVICE_DEBUG_PRINT("NewUriService::NewUriService"); |
|
792 publishAll(); |
|
793 } |
|
794 |
|
795 NewUriService::~NewUriService() |
|
796 { |
|
797 XQSERVICE_DEBUG_PRINT("NewUriService::~NewUriService"); |
|
798 } |
|
799 |
|
800 void NewUriService::complete(bool ok) |
|
801 { |
|
802 Q_UNUSED(ok); |
|
803 XQSERVICE_DEBUG_PRINT("NewUriService::complete"); |
|
804 // Complete all IDs |
|
805 foreach (quint32 reqId, mAsyncReqIds) |
|
806 { |
|
807 XQSERVICE_DEBUG_PRINT("NewUriService::complete %d", reqId); |
|
808 completeRequest(reqId, QVariant(mRetValue)); |
|
809 } |
|
810 } |
|
811 |
|
812 bool NewUriService::view(const QString& uri) |
|
813 { |
|
814 XQSERVICE_DEBUG_PRINT("NewUriService::view(1)"); |
|
815 return view(uri, true); |
|
816 } |
|
817 |
|
818 bool NewUriService::view(const QString& uri, bool retValue) |
|
819 { |
|
820 XQRequestInfo info = requestInfo(); |
|
821 QString testCase = (info.info(TESTCASE_INFO_KEY)).toString(); |
|
822 XQSERVICE_DEBUG_PRINT("XQTESTER serviceapp,%s,NewUriService::view", qPrintable(testCase)); |
|
823 |
|
824 QString label = "New IUriView::view\n:"; |
|
825 label += QString ("Uri=%1\n").arg(uri); |
|
826 label += QString ("retValue=%1\n").arg(retValue); |
|
827 QString param = QString ("retValue=%1\n").arg(retValue); |
|
828 |
|
829 bool isAsync = !info.isSynchronous();; |
|
830 connect(this, SIGNAL(returnValueDelivered()), this, SLOT(handleAnswerDelivered())); |
|
831 |
|
832 mRetValue = retValue; |
|
833 mServiceApp->setLabelNumber(label,param); |
|
834 if (isAsync) |
|
835 { |
|
836 mAsyncReqIds.insertMulti(info.clientSecureId(), setCurrentRequestAsync()); |
|
837 connect(this, SIGNAL(clientDisconnected()), this, SLOT(handleClientDisconnect())); |
|
838 } |
|
839 |
|
840 return retValue; |
|
841 } |
|
842 |
|
843 void NewUriService::handleClientDisconnect() |
|
844 { |
|
845 XQSERVICE_DEBUG_PRINT("NewUriService::handleClientDisconnect"); |
|
846 XQRequestInfo info = requestInfo(); |
|
847 XQSERVICE_DEBUG_PRINT("\tRequest info: id=%d,sid=%X,vid=%X", info.id(),info.clientSecureId(), info.clientVendorId()); |
|
848 |
|
849 mAsyncReqIds.remove(info.clientSecureId()); |
|
850 mServiceApp->quit(); |
|
851 } |
|
852 |
|
853 void NewUriService::handleAnswerDelivered() |
|
854 { |
|
855 XQSERVICE_DEBUG_PRINT("NewUriService::handleAnswerDelivered"); |
|
856 XQRequestInfo info = requestInfo(); |
|
857 XQSERVICE_DEBUG_PRINT("\tRequest info: sid=%X,vid=%X", info.clientSecureId(), info.clientVendorId()); |
|
858 // Done |
|
859 mAsyncReqIds.remove(info.clientSecureId()); |
|
860 |
|
861 } |
|
862 |
|
863 |
|
864 // ----------FileService--------------- |
|
865 |
|
866 FileService::FileService(ServiceApp* parent) |
|
867 : XQServiceProvider(QLatin1String("com.nokia.services.serviceapp.com.nokia.symbian.IFileView"),parent), |
|
868 mServiceApp(parent) |
|
869 |
|
870 { |
|
871 XQSERVICE_DEBUG_PRINT("FileService::FileService"); |
|
872 publishAll(); |
|
873 } |
|
874 |
|
875 FileService::~FileService() |
|
876 { |
|
877 XQSERVICE_DEBUG_PRINT("FileService::~FileService"); |
|
878 } |
|
879 |
|
880 void FileService::complete(bool ok) |
|
881 { |
|
882 XQSERVICE_DEBUG_PRINT("FileService::complete"); |
|
883 // Complete all |
|
884 foreach (quint32 reqId, mAsyncReqIds) |
|
885 { |
|
886 XQSERVICE_DEBUG_PRINT("FileService::complete %d", reqId); |
|
887 completeRequest(reqId, QVariant(ok)); |
|
888 } |
|
889 } |
|
890 |
|
891 bool FileService::view(QString file) |
|
892 { |
|
893 XQRequestInfo info = requestInfo(); |
|
894 QString testCase = (info.info(TESTCASE_INFO_KEY)).toString(); |
|
895 XQSERVICE_DEBUG_PRINT("XQTESTER serviceapp,%s,FileService::view", qPrintable(testCase)); |
|
896 |
|
897 QString label = "IFileView::view\n:"; |
|
898 QString param = QString ("File=%1\n").arg(file); |
|
899 |
|
900 bool isAsync = !info.isSynchronous();; |
|
901 connect(this, SIGNAL(returnValueDelivered()), this, SLOT(handleAnswerDelivered())); |
|
902 |
|
903 mServiceApp->setLabelNumber(label,param); |
|
904 if (isAsync) |
|
905 { |
|
906 mAsyncReqIds.insertMulti(info.clientSecureId(), setCurrentRequestAsync()); |
|
907 connect(this, SIGNAL(clientDisconnected()), this, SLOT(handleClientDisconnect())); |
|
908 } |
|
909 |
|
910 return true; |
|
911 } |
|
912 |
|
913 |
|
914 bool FileService::view(XQSharableFile sf) |
|
915 { |
|
916 XQSERVICE_DEBUG_PRINT("FileService::view(XQSharebleFile)"); |
|
917 QString label = "IFile::view\n:"; |
|
918 QString param = QString ("File=%1\n").arg(sf.fileName()); |
|
919 |
|
920 RFile file; |
|
921 bool ok = sf.getHandle( file ); |
|
922 if (ok) |
|
923 { |
|
924 HBufC8* data = HBufC8::NewL(100); |
|
925 TPtr8 ptr = data->Des(); |
|
926 TInt err = file.Read( ptr ); |
|
927 QString text = QString::fromUtf8((const char *)(data->Ptr()), data->Length()); |
|
928 XQSERVICE_DEBUG_PRINT("FileService::file read,%d,%s", err, qPrintable(text)); |
|
929 sf.close(); |
|
930 delete data; |
|
931 } |
|
932 |
|
933 XQRequestInfo info = requestInfo(); |
|
934 bool isAsync = !info.isSynchronous();; |
|
935 |
|
936 mServiceApp->setLabelNumber(label,param); |
|
937 if (isAsync) |
|
938 { |
|
939 mAsyncReqIds.insertMulti(info.clientSecureId(), setCurrentRequestAsync()); |
|
940 connect(this, SIGNAL(clientDisconnected()), this, SLOT(handleClientDisconnect())); |
|
941 } |
|
942 return true; |
|
943 } |
|
944 |
|
945 |
|
946 void FileService::handleClientDisconnect() |
|
947 { |
|
948 XQSERVICE_DEBUG_PRINT("FileService::handleClientDisconnect"); |
|
949 XQRequestInfo info = requestInfo(); |
|
950 XQSERVICE_DEBUG_PRINT("\tRequest info: id=%d,sid=%X,vid=%X", info.id(),info.clientSecureId(), info.clientVendorId()); |
|
951 |
|
952 mAsyncReqIds.remove(info.clientSecureId()); |
|
953 mServiceApp->quit(); |
|
954 } |
|
955 |
|
956 |
|
957 void FileService::handleAnswerDelivered() |
|
958 { |
|
959 XQSERVICE_DEBUG_PRINT("FileService::handleAnswerDelivered"); |
|
960 XQRequestInfo info = requestInfo(); |
|
961 XQSERVICE_DEBUG_PRINT("\tRequest info: sid=%X,vid=%X", info.clientSecureId(), info.clientVendorId()); |
|
962 // Done |
|
963 mAsyncReqIds.remove(info.clientSecureId()); |
|
964 |
|
965 } |
|
966 |
|
967 |
|
968 // ----------NewFileService--------------- |
|
969 |
|
970 NewFileService::NewFileService(ServiceApp* parent) |
|
971 : XQServiceProvider(QLatin1String("serviceapp.com.nokia.symbian.IFileView"),parent), |
|
972 mServiceApp(parent) |
|
973 |
|
974 { |
|
975 XQSERVICE_DEBUG_PRINT("NewFileService::NewFileService"); |
|
976 publishAll(); |
|
977 } |
|
978 |
|
979 NewFileService::~NewFileService() |
|
980 { |
|
981 XQSERVICE_DEBUG_PRINT("NewFileService::~NewFileService"); |
|
982 } |
|
983 |
|
984 void NewFileService::complete(bool ok) |
|
985 { |
|
986 XQSERVICE_DEBUG_PRINT("NewFileService::complete"); |
|
987 // Complete all |
|
988 foreach (quint32 reqId, mAsyncReqIds) |
|
989 { |
|
990 XQSERVICE_DEBUG_PRINT("NewFileService::complete %d", reqId); |
|
991 completeRequest(reqId, QVariant(ok)); |
|
992 } |
|
993 } |
|
994 |
|
995 bool NewFileService::view(QString file) |
|
996 { |
|
997 XQRequestInfo info = requestInfo(); |
|
998 QString testCase = (info.info(TESTCASE_INFO_KEY)).toString(); |
|
999 XQSERVICE_DEBUG_PRINT("XQTESTER serviceapp,%s,NewFileService::view", qPrintable(testCase)); |
|
1000 |
|
1001 QString label = "New IFileView::view\n:"; |
|
1002 QString param = QString ("File=%1\n").arg(file); |
|
1003 |
|
1004 bool isAsync = !info.isSynchronous();; |
|
1005 connect(this, SIGNAL(returnValueDelivered()), this, SLOT(handleAnswerDelivered())); |
|
1006 |
|
1007 mServiceApp->setLabelNumber(label,param); |
|
1008 if (isAsync) |
|
1009 { |
|
1010 mAsyncReqIds.insertMulti(info.clientSecureId(), setCurrentRequestAsync()); |
|
1011 connect(this, SIGNAL(clientDisconnected()), this, SLOT(handleClientDisconnect())); |
|
1012 } |
|
1013 |
|
1014 return true; |
|
1015 } |
|
1016 |
|
1017 |
|
1018 bool NewFileService::view(XQSharableFile sf) |
|
1019 { |
|
1020 XQSERVICE_DEBUG_PRINT("NewFileService::view(XQSharebleFile)"); |
|
1021 QString label = "IFile::view\n:"; |
|
1022 QString param = QString ("File=%1\n").arg(sf.fileName()); |
|
1023 |
|
1024 RFile file; |
|
1025 bool ok = sf.getHandle( file ); |
|
1026 if (ok) |
|
1027 { |
|
1028 HBufC8* data = HBufC8::NewL(100); |
|
1029 TPtr8 ptr = data->Des(); |
|
1030 TInt err = file.Read( ptr ); |
|
1031 QString text = QString::fromUtf8((const char *)(data->Ptr()), data->Length()); |
|
1032 XQSERVICE_DEBUG_PRINT("NewFileService::file read,%d,%s", err, qPrintable(text)); |
|
1033 sf.close(); |
|
1034 delete data; |
|
1035 } |
|
1036 |
|
1037 XQRequestInfo info = requestInfo(); |
|
1038 bool isAsync = !info.isSynchronous();; |
|
1039 |
|
1040 mServiceApp->setLabelNumber(label,param); |
|
1041 if (isAsync) |
|
1042 { |
|
1043 mAsyncReqIds.insertMulti(info.clientSecureId(), setCurrentRequestAsync()); |
|
1044 connect(this, SIGNAL(clientDisconnected()), this, SLOT(handleClientDisconnect())); |
|
1045 } |
|
1046 return true; |
|
1047 } |
|
1048 |
|
1049 |
|
1050 void NewFileService::handleClientDisconnect() |
|
1051 { |
|
1052 XQSERVICE_DEBUG_PRINT("NewFileService::handleClientDisconnect"); |
|
1053 XQRequestInfo info = requestInfo(); |
|
1054 XQSERVICE_DEBUG_PRINT("\tRequest info: id=%d,sid=%X,vid=%X", info.id(),info.clientSecureId(), info.clientVendorId()); |
|
1055 |
|
1056 mAsyncReqIds.remove(info.clientSecureId()); |
|
1057 mServiceApp->quit(); |
|
1058 } |
|
1059 |
|
1060 |
|
1061 void NewFileService::handleAnswerDelivered() |
|
1062 { |
|
1063 XQSERVICE_DEBUG_PRINT("NewFileService::handleAnswerDelivered"); |
|
1064 XQRequestInfo info = requestInfo(); |
|
1065 XQSERVICE_DEBUG_PRINT("\tRequest info: sid=%X,vid=%X", info.clientSecureId(), info.clientVendorId()); |
|
1066 // Done |
|
1067 mAsyncReqIds.remove(info.clientSecureId()); |
|
1068 |
|
1069 } |
|
1070 |
|