56
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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 |
* class to manage differnt messaging views.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include "msgurihandlerinterface.h"
|
|
20 |
|
|
21 |
#include <QtGlobal>
|
|
22 |
|
|
23 |
#include <QString>
|
|
24 |
#include <QStringList>
|
|
25 |
#include <QPair>
|
|
26 |
#include <QUrl>
|
|
27 |
#include <convergedmessage.h>
|
|
28 |
#include <convergedmessageaddress.h>
|
|
29 |
|
|
30 |
#include "msgserviceviewmanager.h"
|
|
31 |
#include "debugtraces.h"
|
|
32 |
|
|
33 |
|
|
34 |
MsgUriHandlerInterface::MsgUriHandlerInterface(MsgServiceViewManager* viewManager, QObject* parent)
|
|
35 |
:
|
|
36 |
XQServiceProvider(QLatin1String("messaging.com.nokia.symbian.IUriView"), parent),
|
|
37 |
viewManager(viewManager)
|
|
38 |
{
|
|
39 |
publishAll();
|
|
40 |
}
|
|
41 |
|
|
42 |
MsgUriHandlerInterface::~MsgUriHandlerInterface()
|
|
43 |
{
|
|
44 |
|
|
45 |
}
|
|
46 |
|
|
47 |
bool MsgUriHandlerInterface::view(const QString& uri)
|
|
48 |
{
|
|
49 |
QDEBUG_WRITE_FORMAT("service request for URI:", uri.toLatin1().data());
|
|
50 |
QUrl parsedUri;
|
|
51 |
|
|
52 |
parsedUri.setUrl(uri);
|
|
53 |
normalizeQueryItems(parsedUri);
|
|
54 |
|
|
55 |
QDEBUG_WRITE_FORMAT("scheme: ", parsedUri.scheme().toLatin1().data());
|
|
56 |
QDEBUG_WRITE_FORMAT("path: ", parsedUri.path().toLatin1().data());
|
|
57 |
QDEBUG_WRITE_FORMAT("items count: ", parsedUri.queryItems().size());
|
|
58 |
QDEBUG_WRITE_FORMAT("error: ", parsedUri.errorString());
|
|
59 |
#ifdef _DEBUG_TRACES_
|
|
60 |
QPair<QString,QString> item;
|
|
61 |
foreach (item, parsedUri.queryItems())
|
|
62 |
{
|
|
63 |
int i = 0;
|
|
64 |
QDEBUG_WRITE_FORMAT("MsgUriHandlerInterface::view(): query item # i :", i++);
|
|
65 |
QDEBUG_WRITE_FORMAT("MsgUriHandlerInterface::view(): query item # First Item :", item.first.toLatin1().data());
|
|
66 |
QDEBUG_WRITE_FORMAT("MsgUriHandlerInterface::view(): query item # Second Item :", item.second.toLatin1().data());
|
|
67 |
}
|
|
68 |
#endif
|
|
69 |
|
|
70 |
ConvergedMessage message;
|
|
71 |
|
|
72 |
if (parsedUri.scheme().compare("sms", Qt::CaseInsensitive))
|
|
73 |
{
|
|
74 |
message.setMessageType(ConvergedMessage::Sms);
|
|
75 |
}
|
|
76 |
else if (parsedUri.scheme().compare("mmsto", Qt::CaseInsensitive))
|
|
77 |
{
|
|
78 |
message.setMessageType(ConvergedMessage::Mms);
|
|
79 |
}
|
|
80 |
else
|
|
81 |
{
|
|
82 |
QDEBUG_WRITE_FORMAT("Unsupported scheme:", parsedUri.scheme().toLatin1().data());
|
|
83 |
return false;
|
|
84 |
}
|
|
85 |
|
|
86 |
QString addressLine = parsedUri.path();
|
|
87 |
addRecipients(message, addressLine);
|
|
88 |
|
|
89 |
QString body = parsedUri.queryItemValue("body");
|
|
90 |
message.setBodyText(body);
|
|
91 |
|
|
92 |
/* mms specific query values */
|
|
93 |
|
|
94 |
QString subject = parsedUri.queryItemValue("subject");
|
|
95 |
message.setSubject(subject);
|
|
96 |
|
|
97 |
QString priority = parsedUri.queryItemValue("priority");
|
|
98 |
if (priority.compare("Low", Qt::CaseInsensitive))
|
|
99 |
{
|
|
100 |
message.setPriority(ConvergedMessage::Low);
|
|
101 |
}
|
|
102 |
else if (priority.compare("Normal", Qt::CaseInsensitive))
|
|
103 |
{
|
|
104 |
message.setPriority(ConvergedMessage::Normal);
|
|
105 |
}
|
|
106 |
else if (priority.compare("High", Qt::CaseInsensitive))
|
|
107 |
{
|
|
108 |
message.setPriority(ConvergedMessage::High);
|
|
109 |
}
|
|
110 |
else
|
|
111 |
{
|
|
112 |
QDEBUG_WRITE_FORMAT("MsgUriHandlerInterface::view(): Unknown priority value: ", priority.toLatin1().data());
|
|
113 |
return false;
|
|
114 |
}
|
|
115 |
|
|
116 |
QStringList tos = parsedUri.allQueryItemValues("to");
|
|
117 |
QString to;
|
|
118 |
foreach (to, tos)
|
|
119 |
{
|
|
120 |
addRecipients(message, to);
|
|
121 |
}
|
|
122 |
|
|
123 |
QStringList ccs = parsedUri.allQueryItemValues("cc");
|
|
124 |
QString cc;
|
|
125 |
foreach (cc, ccs)
|
|
126 |
{
|
|
127 |
addRecipients(message, cc);
|
|
128 |
}
|
|
129 |
|
|
130 |
viewManager->send(message);
|
|
131 |
|
|
132 |
return true;
|
|
133 |
}
|
|
134 |
|
|
135 |
void MsgUriHandlerInterface::normalizeQueryItems(QUrl &url)
|
|
136 |
{
|
|
137 |
QList<QPair<QString, QString> > items = url.queryItems();
|
|
138 |
QPair<QString, QString> item;
|
|
139 |
int i = 0;
|
|
140 |
foreach (item, items)
|
|
141 |
{
|
|
142 |
items.replace(i++, QPair<QString,QString >(item.first.toLower(), item.second));
|
|
143 |
}
|
|
144 |
url.setQueryItems(items);
|
|
145 |
}
|
|
146 |
|
|
147 |
|
|
148 |
void MsgUriHandlerInterface::addRecipients(ConvergedMessage &message, const QString &recipientsList)
|
|
149 |
{
|
|
150 |
QStringList addressList = recipientsList.split(",");
|
|
151 |
QString addressEntry;
|
|
152 |
|
|
153 |
foreach (addressEntry, addressList)
|
|
154 |
{
|
|
155 |
addressEntry.trimmed();
|
|
156 |
if (! addressEntry.isEmpty())
|
|
157 |
{
|
|
158 |
ConvergedMessageAddress address;
|
|
159 |
address.setAddress(addressEntry);
|
|
160 |
message.addToRecipient(address);
|
|
161 |
QDEBUG_WRITE_FORMAT("MsgUriHandlerInterface::addRecipients() recipient added: ", addressEntry.toLatin1().data());
|
|
162 |
}
|
|
163 |
}
|
|
164 |
}
|