12
|
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 FILES
|
|
23 |
#include <QUrl>
|
|
24 |
#include <QDesktopServices>
|
|
25 |
#include <QStringList>
|
|
26 |
|
|
27 |
#if defined(Q_OS_SYMBIAN)
|
|
28 |
#include <miutset.h> // KUidMsgTypeSMTP
|
|
29 |
#include <sendui.h> // CSendUi
|
|
30 |
#include <cmessagedata.h> // CMessageData
|
|
31 |
//For Rtsp Scheme
|
|
32 |
#include <aiwgenericparam.h>
|
|
33 |
#include <DocumentHandler.h>
|
|
34 |
#include <apparc.h>
|
|
35 |
|
|
36 |
_LIT( KRtspFileName, "c:\\system\\temp\\RtspTemp.ram" );
|
|
37 |
#endif // defined(Q_OS_SYMBIAN)
|
|
38 |
|
|
39 |
#include "SchemeHandlerBr_p.h"
|
|
40 |
#include "SchemeHandlerBrDefault_p.h"
|
|
41 |
|
|
42 |
#define MAILTO_SCHEME "mailto"
|
|
43 |
#define TEL_SCHEME "tel"
|
|
44 |
#define RTSP_SCHEME "rtsp"
|
|
45 |
#define SIP_SCHEME "sip"
|
|
46 |
#define WTAI_SCHEME "wtai"
|
|
47 |
#define WTAI_MC "/mc;"
|
|
48 |
#define WTAI_AP "/ap;"
|
|
49 |
|
|
50 |
namespace WRT {
|
|
51 |
|
|
52 |
|
|
53 |
/*!
|
|
54 |
* HandleUrl
|
|
55 |
* @return true/false
|
|
56 |
*/
|
|
57 |
SchemeHandler::SchemeHandlerError DefSchemeHandlerPrivate::HandleUrl(const QUrl &url, bool confirmDTMF)
|
|
58 |
{
|
|
59 |
return SchemeHandlerPrivate::HandleUrl(url, confirmDTMF);
|
|
60 |
}
|
|
61 |
|
|
62 |
SchemeHandler::SchemeHandlerError DefSchemeHandlerPrivate::HandleScheme(const QUrl &url)
|
|
63 |
{
|
|
64 |
QString scheme = url.scheme().toLower();
|
|
65 |
SchemeHandler::SchemeHandlerError retVal = SchemeHandler::SchemeUnsupported;
|
|
66 |
|
|
67 |
if (scheme == MAILTO_SCHEME) {
|
|
68 |
// launch associated program
|
|
69 |
retVal = HandleMailtoScheme(url);
|
|
70 |
}
|
|
71 |
else if (scheme == RTSP_SCHEME) {
|
|
72 |
// launch associated program
|
|
73 |
retVal = HandleRtspScheme(url);
|
|
74 |
}
|
|
75 |
|
|
76 |
#if defined(Q_OS_SYMBIAN)
|
|
77 |
else if (scheme == TEL_SCHEME) {
|
|
78 |
// launch associated program
|
|
79 |
retVal = HandleTelScheme(url);
|
|
80 |
}
|
|
81 |
else if (scheme == SIP_SCHEME) {
|
|
82 |
// launch associated program
|
|
83 |
retVal = HandleSipScheme(url);
|
|
84 |
}
|
|
85 |
else if (scheme == WTAI_SCHEME) {
|
|
86 |
QString path = url.path();
|
|
87 |
|
|
88 |
if (path.startsWith(WTAI_MC)) {
|
|
89 |
// launch associated program
|
|
90 |
retVal = HandleWtaiMcScheme(url);
|
|
91 |
}
|
|
92 |
}
|
|
93 |
#endif
|
|
94 |
|
|
95 |
return retVal;
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
#if !defined(Q_OS_SYMBIAN)
|
|
100 |
/*
|
|
101 |
* HandleMailtoScheme
|
|
102 |
* @return true/false
|
|
103 |
*/
|
|
104 |
SchemeHandler::SchemeHandlerError DefSchemeHandlerPrivate::HandleMailtoScheme(const QUrl &url)
|
|
105 |
{
|
|
106 |
SchemeHandler::SchemeHandlerError retVal = SchemeHandler::NoError;
|
|
107 |
#ifndef QT_NO_DESKTOPSERVICES
|
|
108 |
if (!QDesktopServices::openUrl(url)) {
|
|
109 |
// Failed to handle scheme
|
|
110 |
retVal = SchemeHandler::LaunchFailed;
|
|
111 |
}
|
|
112 |
#else
|
|
113 |
retVal = SchemeHandler::SchemeUnsupported;
|
|
114 |
#endif
|
|
115 |
|
|
116 |
return (retVal);
|
|
117 |
}
|
|
118 |
#else // Q_OS_SYMBIAN
|
|
119 |
/*
|
|
120 |
* HandleMailtoScheme
|
|
121 |
* @return true/false
|
|
122 |
*/
|
|
123 |
|
|
124 |
SchemeHandler::SchemeHandlerError DefSchemeHandlerPrivate::HandleMailtoScheme(const QUrl &url)
|
|
125 |
{
|
|
126 |
TRAPD(err, HandleMailtoSchemeL(url));
|
|
127 |
return err ? SchemeHandler::LaunchFailed : SchemeHandler::NoError;
|
|
128 |
}
|
|
129 |
void DefSchemeHandlerPrivate::HandleMailtoSchemeL(const QUrl &url)
|
|
130 |
{
|
|
131 |
QString recipient = url.path();
|
|
132 |
QString subject = url.queryItemValue("subject");
|
|
133 |
QString body = url.queryItemValue("body");
|
|
134 |
QString to = url.queryItemValue("to");
|
|
135 |
QString cc = url.queryItemValue("cc");
|
|
136 |
QString bcc = url.queryItemValue("bcc");
|
|
137 |
|
|
138 |
// these fields might have comma separated addresses
|
|
139 |
QStringList recipients = recipient.split(",");
|
|
140 |
QStringList tos = to.split(",");
|
|
141 |
QStringList ccs = cc.split(",");
|
|
142 |
QStringList bccs = bcc.split(",");
|
|
143 |
|
|
144 |
|
|
145 |
CSendUi* sendUi = CSendUi::NewLC();
|
|
146 |
|
|
147 |
// Construct symbian sendUI data holder
|
|
148 |
CMessageData* messageData = CMessageData::NewLC();
|
|
149 |
|
|
150 |
// Subject
|
|
151 |
TPtrC subj( qt_QString2TPtrC(subject) );
|
|
152 |
messageData->SetSubjectL( &subj );
|
|
153 |
|
|
154 |
// Body
|
|
155 |
CParaFormatLayer* paraFormat = CParaFormatLayer::NewL();
|
|
156 |
CleanupStack::PushL( paraFormat );
|
|
157 |
CCharFormatLayer* charFormat = CCharFormatLayer::NewL();
|
|
158 |
CleanupStack::PushL( charFormat );
|
|
159 |
CRichText* bodyRichText = CRichText::NewL( paraFormat, charFormat );
|
|
160 |
CleanupStack::PushL( bodyRichText );
|
|
161 |
|
|
162 |
TPtrC bodyPtr( qt_QString2TPtrC(body) );
|
|
163 |
if( bodyPtr.Length() )
|
|
164 |
bodyRichText->InsertL( 0, bodyPtr );
|
|
165 |
else
|
|
166 |
bodyRichText->InsertL( 0, KNullDesC );
|
|
167 |
|
|
168 |
messageData->SetBodyTextL( bodyRichText );
|
|
169 |
|
|
170 |
// To
|
|
171 |
foreach(QString item, recipients)
|
|
172 |
messageData->AppendToAddressL(qt_QString2TPtrC(item));
|
|
173 |
|
|
174 |
foreach(QString item, tos)
|
|
175 |
messageData->AppendToAddressL(qt_QString2TPtrC(item));
|
|
176 |
|
|
177 |
// Cc
|
|
178 |
foreach(QString item, ccs)
|
|
179 |
messageData->AppendCcAddressL(qt_QString2TPtrC(item));
|
|
180 |
|
|
181 |
// Bcc
|
|
182 |
foreach(QString item, bccs)
|
|
183 |
messageData->AppendBccAddressL(qt_QString2TPtrC(item));
|
|
184 |
|
|
185 |
TRAP_IGNORE(sendUi->CreateAndSendMessageL( KUidMsgTypeSMTP, messageData ));
|
|
186 |
CleanupStack::PopAndDestroy( 5 ); // bodyRichText, charFormat, paraFormat, messageData, sendUi
|
|
187 |
}
|
|
188 |
|
|
189 |
// Returned TPtrC is valid as long as the given parameter is valid and unmodified
|
|
190 |
TPtrC DefSchemeHandlerPrivate::qt_QString2TPtrC( const QString& string )
|
|
191 |
{
|
|
192 |
return reinterpret_cast<const TUint16*>(string.utf16());
|
|
193 |
}
|
|
194 |
#endif // Q_OS_SYMBIAN
|
|
195 |
|
|
196 |
#if !defined(Q_OS_SYMBIAN)
|
|
197 |
/*
|
|
198 |
* HandleRtspScheme
|
|
199 |
* @return true/false
|
|
200 |
*/
|
|
201 |
SchemeHandler::SchemeHandlerError DefSchemeHandlerPrivate::HandleRtspScheme(const QUrl &url)
|
|
202 |
{
|
|
203 |
SchemeHandler::SchemeHandlerError retVal = SchemeHandler::NoError;
|
|
204 |
|
|
205 |
#ifndef QT_NO_DESKTOPSERVICES
|
|
206 |
if (!QDesktopServices::openUrl(url)) {
|
|
207 |
// Failed to handle scheme
|
|
208 |
retVal = SchemeHandler::LaunchFailed;
|
|
209 |
}
|
|
210 |
#else
|
|
211 |
retVal = SchemeHandler::SchemeUnsupported;
|
|
212 |
#endif
|
|
213 |
|
|
214 |
return (retVal);
|
|
215 |
}
|
|
216 |
#else // Q_OS_SYMBIAN
|
|
217 |
|
|
218 |
SchemeHandler::SchemeHandlerError DefSchemeHandlerPrivate::HandleTelScheme(const QUrl &url)
|
|
219 |
{
|
|
220 |
QDesktopServices::openUrl(url);
|
|
221 |
return SchemeHandler::NoError;
|
|
222 |
}
|
|
223 |
|
|
224 |
SchemeHandler::SchemeHandlerError DefSchemeHandlerPrivate::HandleSipScheme(const QUrl &url)
|
|
225 |
{
|
|
226 |
QDesktopServices::openUrl(url);
|
|
227 |
return SchemeHandler::NoError;
|
|
228 |
}
|
|
229 |
|
|
230 |
SchemeHandler::SchemeHandlerError DefSchemeHandlerPrivate::HandleWtaiMcScheme(const QUrl &url)
|
|
231 |
{
|
|
232 |
QString path = url.path();
|
|
233 |
QString number = path.mid(path.indexOf(';') + 1);
|
|
234 |
|
|
235 |
number = "tel:" + number;
|
|
236 |
QUrl dialUrl(number);
|
|
237 |
QDesktopServices::openUrl(dialUrl);
|
|
238 |
return SchemeHandler::NoError;
|
|
239 |
}
|
|
240 |
|
|
241 |
/*
|
|
242 |
* HandleRtspSchemeL
|
|
243 |
* @return true/false
|
|
244 |
*/
|
|
245 |
|
|
246 |
SchemeHandler::SchemeHandlerError DefSchemeHandlerPrivate::HandleRtspScheme(const QUrl &url)
|
|
247 |
{
|
|
248 |
TRAPD(err, HandleRtspSchemeL(url));
|
|
249 |
return (err ? SchemeHandler::LaunchFailed : SchemeHandler::NoError);
|
|
250 |
}
|
|
251 |
void DefSchemeHandlerPrivate::HandleRtspSchemeL(const QUrl &url)
|
|
252 |
{
|
|
253 |
//Launch the appropriate application in embedded mode
|
|
254 |
|
|
255 |
RFs rfs;
|
|
256 |
RFile ramFile;
|
|
257 |
|
|
258 |
HBufC* urlBuf = qt_QString2HBufC(url.toString());
|
|
259 |
CleanupStack::PushL(urlBuf);
|
|
260 |
// 8-bit buffer is required.
|
|
261 |
HBufC8* urlBuf8 = HBufC8::NewLC( urlBuf->Size() );
|
|
262 |
urlBuf8->Des().Copy( *urlBuf );
|
|
263 |
|
|
264 |
// Open the file.
|
|
265 |
User::LeaveIfError(rfs.Connect());
|
|
266 |
CleanupClosePushL(rfs);
|
|
267 |
|
|
268 |
// Replace file if exists or Create file if not exist yet
|
|
269 |
User::LeaveIfError( ramFile.Replace( rfs, KRtspFileName, EFileWrite | EFileShareAny ) );
|
|
270 |
CleanupClosePushL(ramFile);
|
|
271 |
// Write to file
|
|
272 |
User::LeaveIfError( ramFile.Write(*urlBuf8) );
|
|
273 |
ramFile.Flush();
|
|
274 |
|
|
275 |
CleanupStack::PopAndDestroy(/*ramFile*/);
|
|
276 |
CleanupStack::PopAndDestroy(/*rfs*/);
|
|
277 |
CleanupStack::PopAndDestroy( /*urlBuf8*/ );
|
|
278 |
CleanupStack::PopAndDestroy( /*urlBuf*/ );
|
|
279 |
|
|
280 |
RFile ramDocTempFile;
|
|
281 |
CDocumentHandler* docHandler = CDocumentHandler::NewL();
|
|
282 |
docHandler->OpenTempFileL( KRtspFileName, ramDocTempFile );
|
|
283 |
|
|
284 |
CleanupClosePushL( ramDocTempFile );
|
|
285 |
|
|
286 |
TDataType dataType( _L8("audio/x-pn-realaudio-plugin") );
|
|
287 |
CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();
|
|
288 |
TAiwVariant filename( _L8("c:\\system\\temp\\RtspTemp.ram") );
|
|
289 |
TAiwGenericParam param( EGenericParamFile, filename );
|
|
290 |
|
|
291 |
paramList->AppendL( param );
|
|
292 |
|
|
293 |
// Allow save among Options
|
|
294 |
|
|
295 |
TBool allowSave( ETrue );
|
|
296 |
TAiwVariant allowSaveVariant( allowSave );
|
|
297 |
TAiwGenericParam genericParamAllowSave
|
|
298 |
( EGenericParamAllowSave, allowSaveVariant );
|
|
299 |
|
|
300 |
paramList->AppendL( genericParamAllowSave );
|
|
301 |
|
|
302 |
// launch RAM file via DocHandler
|
|
303 |
|
|
304 |
docHandler->OpenFileEmbeddedL( ramDocTempFile, dataType, *paramList );
|
|
305 |
|
|
306 |
CleanupStack::PopAndDestroy( paramList );
|
|
307 |
CleanupStack::PopAndDestroy( &ramDocTempFile );
|
|
308 |
}
|
|
309 |
|
|
310 |
HBufC* DefSchemeHandlerPrivate::qt_QString2HBufC(const QString& string) {
|
|
311 |
TPtrC16 str(reinterpret_cast<const TUint16*>(string.utf16()));
|
|
312 |
return str.Alloc();
|
|
313 |
}
|
|
314 |
#endif // Q_OS_SYMBIAN
|
|
315 |
|
|
316 |
|
|
317 |
} // WRT
|