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 * The source file for tone service test. |
|
16 * |
|
17 */ |
|
18 #include "tonetestapp.h" |
|
19 #include <xqaiwrequest.h> |
|
20 #include <QGraphicsLinearLayout> |
|
21 #include <hbpushbutton.h> |
|
22 #include <hblineedit.h> |
|
23 #include <hblabel.h> |
|
24 #include <qdebug> |
|
25 #include <xqservicerequest.h> |
|
26 |
|
27 ToneTestApp::ToneTestApp(QGraphicsItem *parent) : |
|
28 HbView(parent), |
|
29 mReq(0), |
|
30 mResultEdit(0), |
|
31 mErrorCodeEdit(0), |
|
32 mErrorEdit(0) |
|
33 { |
|
34 qDebug() << "ToneTestApp::ToneTestApp("; |
|
35 createLayout(); |
|
36 } |
|
37 |
|
38 ToneTestApp::~ToneTestApp() |
|
39 { |
|
40 qDebug() << "ToneTestApp::~ToneTestApp"; |
|
41 delete mReq; |
|
42 } |
|
43 |
|
44 void ToneTestApp::handleOk(const QVariant &result) |
|
45 { |
|
46 qDebug() << "ToneTestApp::handleOk"; |
|
47 |
|
48 if (!result.canConvert<QString>()) |
|
49 { |
|
50 mErrorEdit->setText("Corrupt result"); |
|
51 } |
|
52 else |
|
53 { |
|
54 mResultEdit->setText(result.value<QString>()); |
|
55 qDebug() << "ToneTestApp::handleOk" << ": result=" << result.value<QString>(); |
|
56 } |
|
57 |
|
58 } |
|
59 |
|
60 void ToneTestApp::handleError(int errorCode, const QString& errorMessage) |
|
61 { |
|
62 qDebug() << "ToneTestApp::handleError" << ": errorCode=" << errorCode << ", msg:" << errorMessage; |
|
63 mErrorEdit->setText(errorMessage); |
|
64 mErrorCodeEdit->setText(QString::number(errorCode)); |
|
65 } |
|
66 |
|
67 void ToneTestApp::createLayout() |
|
68 { |
|
69 qDebug() << "ToneTestApp::createLayout"; |
|
70 |
|
71 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical); |
|
72 |
|
73 if (layout) |
|
74 { |
|
75 QGraphicsLinearLayout *topLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
76 |
|
77 if (topLayout) |
|
78 { |
|
79 topLayout->addStretch(5); |
|
80 |
|
81 mResultEdit = new HbLineEdit; |
|
82 HbLabel* label = new HbLabel("Result:"); |
|
83 if (mResultEdit && label) |
|
84 { |
|
85 topLayout->addItem(label); |
|
86 mResultEdit->setMaxRows(5); |
|
87 topLayout->addItem(mResultEdit); |
|
88 } |
|
89 |
|
90 mErrorCodeEdit = new HbLineEdit; |
|
91 label = new HbLabel("Error code:"); |
|
92 if (mErrorCodeEdit && label) |
|
93 { |
|
94 topLayout->addItem(label); |
|
95 topLayout->addItem(mErrorCodeEdit); |
|
96 } |
|
97 |
|
98 mErrorEdit = new HbLineEdit; |
|
99 label = new HbLabel("Error description:"); |
|
100 if (mErrorEdit && label) |
|
101 { |
|
102 topLayout->addItem(label); |
|
103 mErrorEdit->setMaxRows(5); |
|
104 topLayout->addItem(mErrorEdit); |
|
105 } |
|
106 |
|
107 layout->addItem(topLayout); |
|
108 layout->setStretchFactor(topLayout, 5); |
|
109 } |
|
110 |
|
111 QGraphicsLinearLayout *bottomLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
112 |
|
113 if (bottomLayout) |
|
114 { |
|
115 bottomLayout->addStretch(); |
|
116 HbPushButton* button = new HbPushButton("Fetch tone"); |
|
117 if (button) |
|
118 { |
|
119 connect(button, SIGNAL(clicked()), this, SLOT(fetchTone())); |
|
120 bottomLayout->addItem(button); |
|
121 } |
|
122 layout->addItem(bottomLayout); |
|
123 } |
|
124 |
|
125 setLayout(layout); // Takes ownership of layout |
|
126 } |
|
127 } |
|
128 |
|
129 void ToneTestApp::fetchTone() |
|
130 { |
|
131 qDebug() << "ToneTestApp::fetchSong START"; |
|
132 |
|
133 mResultEdit->setText(""); |
|
134 mErrorEdit->setText(""); |
|
135 mErrorCodeEdit->setText(""); |
|
136 |
|
137 if (!mReq) |
|
138 { |
|
139 mReq = mAppMgr.create("com.nokia.symbian.IToneFetch", "fetch()", true); |
|
140 // XQServiceRequest snd("com.nokia.services.toneserviceprovider.tone", "queryTone()", true); |
|
141 // QVariant retValue; |
|
142 |
|
143 /* bool res = snd.send(retValue); |
|
144 if (!res) |
|
145 { |
|
146 int returnvalue = snd.latestError(); |
|
147 mErrorEdit->setText(QString::number(returnvalue)); |
|
148 // mRetValue->setText("send fail!"); |
|
149 }*/ |
|
150 |
|
151 if (!mReq) |
|
152 { |
|
153 mErrorEdit->setText("Failed to create REQ"); |
|
154 return; |
|
155 } |
|
156 else |
|
157 { |
|
158 connect(mReq, SIGNAL(requestOk(const QVariant&)), SLOT(handleOk(const QVariant&))); |
|
159 connect(mReq, SIGNAL(requestError(int,const QString&)), SLOT(handleError(int,const QString&))); |
|
160 } |
|
161 } |
|
162 |
|
163 // Set arguments for request (application title) |
|
164 QList<QVariant> args; |
|
165 args << QVariant(QString("<app_name>")); |
|
166 mReq->setArguments(args); |
|
167 |
|
168 // Make the request |
|
169 if (!mReq->send()) |
|
170 { |
|
171 mErrorEdit->setText("Failed to send REQ"); |
|
172 } |
|
173 } |
|
174 |
|