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 <QObject> |
|
23 #include <qglobal.h> |
|
24 #include <QDesktopServices> |
|
25 #include <QLatin1String> |
|
26 |
|
27 #include <xqaiwdecl.h> |
|
28 #include "xqserviceglobal.h" |
|
29 #include "xqservicelog.h" |
|
30 #include "xqaiwuridriver.h" |
|
31 #include <qservicemanager.h> // Integrate to activity manager |
|
32 |
|
33 using namespace QtMobility; |
|
34 |
|
35 XQAiwUriDriver::XQAiwUriDriver(const QUrl &uri, const XQAiwInterfaceDescriptor& descriptor, const QString &operation) |
|
36 : XQAiwRequestDriver(), |
|
37 mUtilities(NULL) |
|
38 { |
|
39 |
|
40 mErrorMsg = ""; |
|
41 mDescr = descriptor; |
|
42 mUri = uri; |
|
43 mOperation = operation; |
|
44 |
|
45 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::XQAiwUriDriver: %s", |
|
46 qPrintable(mUri.toString())); |
|
47 |
|
48 } |
|
49 |
|
50 XQAiwUriDriver::~XQAiwUriDriver() |
|
51 { |
|
52 XQSERVICE_DEBUG_PRINT("~XQAiwUriDriver::XQAiwUriDriver"); |
|
53 delete mUtilities; |
|
54 |
|
55 } |
|
56 |
|
57 QAction *XQAiwUriDriver::createAction() |
|
58 { |
|
59 return NULL; // Not supported |
|
60 } |
|
61 |
|
62 void XQAiwUriDriver::setArguments(const QList<QVariant> &arguments) |
|
63 { |
|
64 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::setArguments"); |
|
65 mArguments = arguments; |
|
66 } |
|
67 |
|
68 |
|
69 bool XQAiwUriDriver::send(QVariant& retValue) |
|
70 { |
|
71 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::send %s", qPrintable(mUri.toString())); |
|
72 |
|
73 mErrorCode = XQService::ENoError; |
|
74 |
|
75 // Browser URI |
|
76 if (mUri.scheme().compare("http", Qt::CaseInsensitive) == 0 || |
|
77 mUri.scheme().compare("https", Qt::CaseInsensitive) == 0) |
|
78 { |
|
79 XQSERVICE_DEBUG_PRINT("Apply QDesktopServices::openUrl"); |
|
80 bool b = QDesktopServices::openUrl(mUri); |
|
81 if (!b) |
|
82 { |
|
83 mErrorCode = XQService::EConnectionError; |
|
84 mErrorMsg = XQAiwUtils::createErrorMessage(mErrorCode, "QDesktopServices::openUrl", mUri.toString()); |
|
85 } |
|
86 return b; |
|
87 } |
|
88 |
|
89 // "appto" URI |
|
90 if (mUri.scheme().compare(XQURI_SCHEME_ACTIVITY,Qt::CaseInsensitive) == 0) |
|
91 { |
|
92 return handleApptoUri(mUri); |
|
93 } |
|
94 |
|
95 // |
|
96 // The rest |
|
97 // |
|
98 mErrorCode = XQService::EArgumentError; |
|
99 mErrorMsg = XQAiwUtils::createErrorMessage(mErrorCode, "XQAiwUriDriver:Not custom handler for", mUri.toString()); |
|
100 |
|
101 return false; |
|
102 |
|
103 } |
|
104 |
|
105 const QString& XQAiwUriDriver::lastErrorMessage() const |
|
106 { |
|
107 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::lastErrorMessage: %s", qPrintable(mErrorMsg)); |
|
108 return mErrorMsg; |
|
109 } |
|
110 |
|
111 int XQAiwUriDriver::lastError() const |
|
112 { |
|
113 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::lastError %d", mErrorCode); |
|
114 return mErrorCode; |
|
115 } |
|
116 |
|
117 const XQAiwInterfaceDescriptor &XQAiwUriDriver::descriptor() const |
|
118 { |
|
119 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::descriptor"); |
|
120 return mDescr; |
|
121 } |
|
122 |
|
123 void XQAiwUriDriver::setEmbedded(bool embedded) |
|
124 { |
|
125 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::setEmbedded"); |
|
126 mEmbedded = embedded; |
|
127 } |
|
128 bool XQAiwUriDriver::isEmbedded() const |
|
129 { |
|
130 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::isEmbedded"); |
|
131 return mEmbedded; |
|
132 } |
|
133 |
|
134 void XQAiwUriDriver::setOperation(const QString &operation) |
|
135 { |
|
136 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::setOperation"); |
|
137 mOperation = operation; |
|
138 } |
|
139 const QString &XQAiwUriDriver::operation() const |
|
140 { |
|
141 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::operation"); |
|
142 return mOperation; |
|
143 } |
|
144 |
|
145 void XQAiwUriDriver::setSynchronous(bool synchronous) |
|
146 { |
|
147 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::setSynchronous"); |
|
148 mSynchronous = synchronous; |
|
149 } |
|
150 bool XQAiwUriDriver::isSynchronous() const |
|
151 { |
|
152 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::isSynchronous"); |
|
153 return mSynchronous; |
|
154 } |
|
155 |
|
156 // |
|
157 // Check if we can handle the URI |
|
158 // |
|
159 bool XQAiwUriDriver::hasCustomHandler(const QUrl &uri) |
|
160 { |
|
161 QString scheme = uri.scheme(); |
|
162 return (scheme.compare(XQURI_SCHEME_ACTIVITY,Qt::CaseInsensitive) == 0 || |
|
163 scheme.compare(XQURI_SCHEME_HTTP,Qt::CaseInsensitive) == 0 || |
|
164 scheme.compare(XQURI_SCHEME_HTTPS,Qt::CaseInsensitive) == 0); |
|
165 } |
|
166 |
|
167 |
|
168 void XQAiwUriDriver::handleAsyncResponse(const QVariant& value) |
|
169 { |
|
170 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::handleAsyncResponse"); |
|
171 emit requestOk(value); |
|
172 } |
|
173 |
|
174 void XQAiwUriDriver::handleAsyncError(int err) |
|
175 { |
|
176 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::handleAsyncError"); |
|
177 |
|
178 mErrorCode = err; |
|
179 mErrorMsg = XQAiwUtils::createErrorMessage(mErrorCode,"XQAiwUriDriver", "async send"); |
|
180 emit requestError(mErrorCode, mErrorMsg); |
|
181 } |
|
182 |
|
183 void XQAiwUriDriver::setBackground(bool background ) |
|
184 { |
|
185 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::setBackground"); |
|
186 mBackground = background; |
|
187 } |
|
188 bool XQAiwUriDriver::isBackground() const |
|
189 { |
|
190 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::isBackground"); |
|
191 return mBackground; |
|
192 } |
|
193 |
|
194 bool XQAiwUriDriver::handleApptoUri(const QUrl &uri) |
|
195 { |
|
196 // |
|
197 // Use Qt service framework errors as is (they are in different range than XQ errors) |
|
198 // |
|
199 QLatin1String xml("Z:/resource/activity/activityserviceplugin.xml"); |
|
200 mErrorCode = QServiceManager::NoError; |
|
201 |
|
202 QtMobility::QServiceManager serviceManager; |
|
203 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::handleApptoUri"); |
|
204 |
|
205 bool b = serviceManager.addService(xml); |
|
206 mErrorCode = serviceManager.error(); |
|
207 XQSERVICE_DEBUG_PRINT("\taddService=%d", mErrorCode); |
|
208 switch (mErrorCode) |
|
209 { |
|
210 case QServiceManager::NoError: |
|
211 case QServiceManager::ServiceAlreadyExists: |
|
212 case QServiceManager::ImplementationAlreadyExists: |
|
213 // These are OK cases. |
|
214 mErrorCode = QServiceManager::NoError; |
|
215 break; |
|
216 default: |
|
217 return false; |
|
218 } |
|
219 |
|
220 QObject* activityManager = serviceManager.loadInterface("com.nokia.qt.activities.ActivityManager"); |
|
221 mErrorCode = serviceManager.error(); |
|
222 XQSERVICE_DEBUG_PRINT("\tloadInterface %s=%d", "com.nokia.qt.activities.ActivityManager", mErrorCode); |
|
223 if (!activityManager) |
|
224 { |
|
225 mErrorCode = serviceManager.error(); |
|
226 return false; |
|
227 } |
|
228 |
|
229 QMetaObject::invokeMethod(activityManager, "launchActivity", Q_ARG(QUrl,uri)); |
|
230 mErrorCode = serviceManager.error(); |
|
231 |
|
232 XQSERVICE_DEBUG_PRINT("\tinvokeMethod=%d", mErrorCode); |
|
233 delete activityManager; |
|
234 |
|
235 XQSERVICE_DEBUG_PRINT("XQAiwUriDriver::handleApptoUri done"); |
|
236 |
|
237 return mErrorCode == QServiceManager::NoError; |
|
238 } |
|