|
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: Homescreen widget plugin |
|
15 * |
|
16 */ |
|
17 #include <xqaiwrequest.h> |
|
18 #include <xqappmgr.h> |
|
19 #include <QPointF> |
|
20 #include <HbDocumentLoader> |
|
21 #include <HbWidget> |
|
22 #include <QStringList> |
|
23 |
|
24 #include "contentlayoutgesture.h" |
|
25 #include "calendarwidgetdebug.h" |
|
26 |
|
27 const int KMethodIndex = 2; |
|
28 |
|
29 /* |
|
30 * ContentLayoutGesture::ContentLayoutGesture |
|
31 */ |
|
32 ContentLayoutGesture::ContentLayoutGesture(HbWidget* widget, QList<QString> parameters, QString& layout, QString& gestureType, QString& action, QObject* parent) : QObject(parent) |
|
33 { |
|
34 LOGS("ContentLayoutGesture::ContentLayoutGesture"); |
|
35 this->setObjectName(layout); |
|
36 assignParameters(parameters, gestureType, action); |
|
37 mLayout = widget; |
|
38 mTestID = 0; |
|
39 } |
|
40 |
|
41 /* |
|
42 * ContentLayoutGesture::~ContentLayoutGesture |
|
43 */ |
|
44 ContentLayoutGesture::~ContentLayoutGesture() |
|
45 { |
|
46 LOGS("ContentLayoutGesture::~ContentLayoutGesture"); |
|
47 } |
|
48 |
|
49 /* |
|
50 * ContentLayoutGesture::assignParameter |
|
51 */ |
|
52 void ContentLayoutGesture::assignParameters(QList<QString> parameters, QString& gestureType, QString& action) |
|
53 { |
|
54 LOGS("ContentLayoutGesture::assignParameter"); |
|
55 if (gestureType == "onTap") { |
|
56 mTapParameters = parameters; |
|
57 mTapAction = action; |
|
58 if (mTapAction == "launchApplication") { |
|
59 //Parse the method and extract parameters type |
|
60 parseParameters(gestureType); |
|
61 } |
|
62 } |
|
63 |
|
64 if (gestureType == "onSwipe") { |
|
65 mSwipeParameters = parameters; |
|
66 mSwipeAction = action; |
|
67 } |
|
68 |
|
69 if (gestureType == "onHighlight") { |
|
70 mHighlightParameters = parameters; |
|
71 mHighlightAction = action; |
|
72 } |
|
73 |
|
74 if (gestureType == "onPinch") { |
|
75 mPinchParameters = parameters; |
|
76 mPinchAction = action; |
|
77 } |
|
78 |
|
79 if (gestureType == "onPan") { |
|
80 mPanParameters = parameters; |
|
81 mPanAction = action; |
|
82 } |
|
83 } |
|
84 |
|
85 /* |
|
86 * ContentLayoutGesture::parseParameters() |
|
87 */ |
|
88 void ContentLayoutGesture::parseParameters( QString& gestureType ) |
|
89 { |
|
90 LOGS( "ContentLayoutGesture::parseParameters" ); |
|
91 if (gestureType == "onTap") { |
|
92 int parameterStartIndex = 0; |
|
93 int parameterEndIndex = 0; |
|
94 bool parameterFound = false; |
|
95 int i = 0; |
|
96 while ((mTapParameters.at(KMethodIndex).at(i) != '(') && (i < mTapParameters.at( |
|
97 KMethodIndex).length())) { |
|
98 i++; |
|
99 } |
|
100 parameterStartIndex = i + 1; |
|
101 for (;i < mTapParameters.at(KMethodIndex).length(); i++) { |
|
102 if (mTapParameters.at(KMethodIndex).at(i) == ',' || mTapParameters.at(KMethodIndex).at( |
|
103 i) == ')') { |
|
104 parameterEndIndex = i; |
|
105 parameterFound = true; |
|
106 } |
|
107 |
|
108 if (parameterFound) { |
|
109 QString parameterType = mTapParameters.at(KMethodIndex).mid(parameterStartIndex, |
|
110 parameterEndIndex - parameterStartIndex); |
|
111 mTapParametersType.append(parameterType); |
|
112 //check the next parameter type from the next cycle |
|
113 parameterStartIndex = i + 1; |
|
114 parameterFound = false; |
|
115 } |
|
116 } |
|
117 } |
|
118 } |
|
119 |
|
120 /* |
|
121 * ContentLayoutGesture::addGesture() |
|
122 */ |
|
123 void ContentLayoutGesture::addGesture(QList<QString> parameters, QString& gestureType, QString& action) |
|
124 { |
|
125 LOGS("ContentLayoutGesture::addGesture"); |
|
126 assignParameters(parameters, gestureType, action); |
|
127 } |
|
128 |
|
129 /* |
|
130 * ContentLayoutGesture::onTap |
|
131 */ |
|
132 void ContentLayoutGesture::onTap(QPointF& point) |
|
133 { |
|
134 LOGS("ContentLayoutGesture::launchApplication"); |
|
135 if (mLayout->sceneBoundingRect().contains(point)) { |
|
136 if (mTapAction == "launchApplication") { |
|
137 launchApplication(mTapParameters, mTapParametersType); |
|
138 mTestID = 1; |
|
139 } |
|
140 } |
|
141 } |
|
142 |
|
143 /* |
|
144 * ContentLayoutGesture::launchApplication |
|
145 */ |
|
146 void ContentLayoutGesture::launchApplication( QList<QString> parameters, QList<QString> parametersType ) |
|
147 { |
|
148 LOGS("ContentLayoutGesture::launchApplication"); |
|
149 |
|
150 QString service = parameters.at(0); |
|
151 QString interface = parameters.at(1); |
|
152 QString method = parameters.at(2); |
|
153 |
|
154 XQApplicationManager aiwMgr; |
|
155 //XQAiwRequest request = aiwMgr.create(url); |
|
156 XQAiwRequest* request = aiwMgr.create(service, interface, method, false); |
|
157 if (request == NULL) { |
|
158 return; |
|
159 } |
|
160 |
|
161 // Connect result handling signal |
|
162 connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
|
163 // Connect error handling signal or apply lastError function instead. |
|
164 connect(request, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&))); |
|
165 |
|
166 QList<QVariant> args; |
|
167 |
|
168 for (int i = 3; i < parameters.count(); i++) { |
|
169 if (parameters.at(i) == "CURRENTDATE") { |
|
170 args << mDate; |
|
171 } |
|
172 else { |
|
173 if (parametersType.at(i - KMethodIndex - 1) == "int") { |
|
174 int par = parameters.at(i).toInt(); |
|
175 args << par; |
|
176 } |
|
177 } |
|
178 } |
|
179 |
|
180 // Set function parameters |
|
181 request->setArguments(args); |
|
182 |
|
183 // Send the request |
|
184 bool res = request->send(); |
|
185 if (!res) { |
|
186 // Request failed. |
|
187 int error = request->lastError(); |
|
188 |
|
189 // Handle error |
|
190 } |
|
191 |
|
192 // All done. |
|
193 delete request; |
|
194 } |
|
195 |
|
196 /* |
|
197 * ContentLayoutGesture::handleOk() |
|
198 */ |
|
199 void ContentLayoutGesture::handleOk(const QVariant& var) |
|
200 { |
|
201 Q_UNUSED(var); |
|
202 LOGS("DateIconGesture::handleOk"); |
|
203 mTestID = 0; |
|
204 emit requestComplete(); |
|
205 } |
|
206 |
|
207 /* |
|
208 * ContentLayoutGesture::handleError() |
|
209 */ |
|
210 void ContentLayoutGesture::handleError(int err, const QString& str) |
|
211 { |
|
212 Q_UNUSED(str); |
|
213 Q_UNUSED(err); |
|
214 LOGS("DateIconGesture::handleError"); |
|
215 mTestID = err; |
|
216 emit requestError(); |
|
217 } |
|
218 |
|
219 |
|
220 /* |
|
221 * ContentLayoutGesture::updateDate() |
|
222 */ |
|
223 void ContentLayoutGesture::updateDate(QDateTime& date) |
|
224 { |
|
225 LOGS("ContentLayoutGesture::updateDate"); |
|
226 mDate = date; |
|
227 } |
|
228 |
|
229 //TEST FUNCTIONS |
|
230 |
|
231 /* |
|
232 * ContentLayoutHandler::testId() |
|
233 */ |
|
234 int ContentLayoutGesture::testId() |
|
235 { |
|
236 return mTestID; |
|
237 } |
|
238 |
|
239 /* |
|
240 * ContentLayoutHandler::setTestId() |
|
241 */ |
|
242 void ContentLayoutGesture::setTestId(int testID) |
|
243 { |
|
244 mTestID = testID; |
|
245 } |
|
246 |
|
247 //END OF FILE |
|
248 |