43
|
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: NMail Application Launcher interface used for interfacing between
|
|
15 |
* QT highway and other applications
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
// INCLUDES
|
|
20 |
#include "nmuiheaders.h"
|
|
21 |
|
|
22 |
/*!
|
|
23 |
\class NmStartParamDataHelper
|
|
24 |
\brief A helper class for processing the data given to the actual service.
|
|
25 |
*/
|
|
26 |
class NmStartParamDataHelper
|
|
27 |
{
|
|
28 |
public:
|
|
29 |
|
|
30 |
/*!
|
|
31 |
Class constructor.
|
|
32 |
*/
|
|
33 |
inline NmStartParamDataHelper()
|
47
|
34 |
: mSubject(NULL),
|
|
35 |
mToAddresses(NULL),
|
|
36 |
mCcAddresses(NULL),
|
|
37 |
mBccAddresses(NULL)
|
43
|
38 |
{
|
|
39 |
NM_FUNCTION;
|
|
40 |
}
|
|
41 |
|
|
42 |
/*!
|
|
43 |
Class destructor.
|
|
44 |
*/
|
|
45 |
inline ~NmStartParamDataHelper()
|
|
46 |
{
|
|
47 |
NM_FUNCTION;
|
|
48 |
}
|
|
49 |
|
|
50 |
/*!
|
|
51 |
Extracts the data from the given QString into the class members.
|
|
52 |
\param data QString containing the data.
|
|
53 |
\return True if success, false otherwise.
|
|
54 |
*/
|
|
55 |
inline bool extractData(const QString &data)
|
|
56 |
{
|
|
57 |
NM_FUNCTION;
|
|
58 |
|
47
|
59 |
bool success(false);
|
43
|
60 |
|
|
61 |
QUrl uri(data);
|
|
62 |
|
|
63 |
if (uri.isValid()) {
|
|
64 |
|
|
65 |
mSubject = new QString(uri.queryItemValue(emailSendSubjectKey));
|
|
66 |
QString to = uri.path();
|
|
67 |
QString cc = uri.queryItemValue(emailSendCcKey);
|
|
68 |
QString bcc = uri.queryItemValue(emailSendBccKey);
|
|
69 |
|
|
70 |
addAddressesToList(to, &mToAddresses);
|
|
71 |
addAddressesToList(cc, &mCcAddresses);
|
|
72 |
addAddressesToList(bcc, &mBccAddresses);
|
|
73 |
|
|
74 |
success = true;
|
|
75 |
}
|
|
76 |
|
|
77 |
return success;
|
|
78 |
}
|
|
79 |
|
|
80 |
/*!
|
|
81 |
Appends the given addresses into the given list.
|
|
82 |
\param address The addresses to append.
|
|
83 |
\param list The list where the addresses are appended to.
|
|
84 |
*/
|
|
85 |
inline void addAddressesToList(QString &addresses,
|
|
86 |
QList<NmAddress*> **list)
|
|
87 |
{
|
|
88 |
NM_FUNCTION;
|
|
89 |
|
|
90 |
if (!addresses.isEmpty()) {
|
|
91 |
|
|
92 |
QList<NmAddress*> foundAddresses;
|
|
93 |
|
|
94 |
// Process multiple addresses.
|
|
95 |
if (addresses.contains(",")) {
|
|
96 |
QString str;
|
|
97 |
while (addresses.contains(",")) {
|
|
98 |
str = addresses.section(",", 0, 0); // Get the occurance.
|
|
99 |
addresses.remove(0, (addresses.indexOf(",")+1)); // Remove the occurance.
|
|
100 |
if (!str.isEmpty()) { // In case str would be empty on some error data.
|
|
101 |
NmAddress *address = new NmAddress(str);
|
|
102 |
foundAddresses.append(address);
|
|
103 |
}
|
|
104 |
}
|
|
105 |
}
|
|
106 |
if (!addresses.isEmpty()) { // In case addresses would be empty on some error data.
|
|
107 |
// Last one or single address.
|
|
108 |
NmAddress *address = new NmAddress(addresses);
|
|
109 |
foundAddresses.append(address);
|
|
110 |
}
|
|
111 |
// Append the found addresses into the given list.
|
|
112 |
*list = new QList<NmAddress*>();
|
|
113 |
(*list)->append(foundAddresses);
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
/*!
|
|
118 |
Deletes the class members. Must be used if NmUiStartParam does not
|
|
119 |
take ownership of the members.
|
|
120 |
*/
|
|
121 |
inline void deleteData()
|
|
122 |
{
|
|
123 |
NM_FUNCTION;
|
|
124 |
|
|
125 |
delete mSubject;
|
|
126 |
mSubject = 0;
|
|
127 |
|
|
128 |
if (mToAddresses) {
|
|
129 |
qDeleteAll(*mToAddresses);
|
|
130 |
delete mToAddresses;
|
|
131 |
mToAddresses = 0;
|
|
132 |
}
|
|
133 |
|
|
134 |
if (mCcAddresses) {
|
|
135 |
qDeleteAll(*mCcAddresses);
|
|
136 |
delete mCcAddresses;
|
|
137 |
mCcAddresses = 0;
|
|
138 |
}
|
|
139 |
|
|
140 |
if (mBccAddresses) {
|
|
141 |
qDeleteAll(*mBccAddresses);
|
|
142 |
delete mBccAddresses;
|
|
143 |
mBccAddresses = 0;
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
public: // Data
|
|
148 |
|
|
149 |
QString *mSubject; // Not owned.
|
|
150 |
QList<NmAddress*> *mToAddresses; // Not owned.
|
|
151 |
QList<NmAddress*> *mCcAddresses; // Not owned.
|
|
152 |
QList<NmAddress*> *mBccAddresses; // Not owned.
|
|
153 |
};
|
|
154 |
|
|
155 |
/*!
|
|
156 |
\class NmUriServiceInterface
|
|
157 |
\brief NMail application service interface which provides an email sending
|
|
158 |
interface for other application using the Qt Highway.
|
|
159 |
*/
|
|
160 |
|
|
161 |
/*!
|
|
162 |
Class constructor.
|
|
163 |
*/
|
|
164 |
NmUriServiceInterface::NmUriServiceInterface(QObject *parent,
|
|
165 |
NmUiEngine &uiEngine,
|
|
166 |
NmApplication *application)
|
|
167 |
: XQServiceProvider(emailServiceName+"."+XQI_URI_VIEW, parent),
|
|
168 |
mApplication(application),
|
|
169 |
mUiEngine(uiEngine),
|
|
170 |
mAsyncReqId(0),
|
|
171 |
mStartParam(NULL),
|
|
172 |
mSelectionDialog(NULL),
|
|
173 |
mCurrentView(NULL)
|
|
174 |
{
|
|
175 |
publishAll();
|
|
176 |
}
|
|
177 |
|
|
178 |
|
|
179 |
/*!
|
|
180 |
Class desctructor.
|
|
181 |
*/
|
|
182 |
NmUriServiceInterface::~NmUriServiceInterface()
|
|
183 |
{
|
|
184 |
NM_FUNCTION;
|
|
185 |
|
|
186 |
delete mStartParam;
|
|
187 |
delete mSelectionDialog;
|
|
188 |
}
|
|
189 |
|
|
190 |
|
|
191 |
/*!
|
|
192 |
Queries the user for a mailbox to use.
|
|
193 |
\param mailboxId Where the ID of the selected mailbox is set.
|
|
194 |
\return True if a mailbox was selected, false otherwise.
|
|
195 |
*/
|
|
196 |
void NmUriServiceInterface::selectionDialogClosed(NmId &mailboxId)
|
|
197 |
{
|
|
198 |
NM_FUNCTION;
|
|
199 |
|
|
200 |
if (mailboxId.id()) { // mailbox selected
|
|
201 |
launchEditorView(mailboxId);
|
|
202 |
}
|
|
203 |
else {
|
|
204 |
cancelService();
|
|
205 |
}
|
|
206 |
}
|
|
207 |
|
|
208 |
|
|
209 |
/*!
|
|
210 |
Used from external applications to handle mailto: uri's.
|
|
211 |
|
|
212 |
\param data <mailto:> uri
|
|
213 |
*/
|
|
214 |
bool NmUriServiceInterface::view(const QString& uri)
|
|
215 |
{
|
|
216 |
NM_FUNCTION;
|
47
|
217 |
|
|
218 |
HbMainWindow *mainWindow(NULL);
|
|
219 |
if (mApplication) {
|
|
220 |
// Make sure that nmail stays background if user presses back in editorview
|
|
221 |
mApplication->updateVisibilityState();
|
|
222 |
|
|
223 |
mainWindow = mApplication->mainWindow();
|
|
224 |
if (mainWindow) {
|
|
225 |
mCurrentView = mainWindow->currentView();
|
|
226 |
}
|
|
227 |
}
|
43
|
228 |
|
|
229 |
// Hide the current view.
|
|
230 |
if (mCurrentView) {
|
|
231 |
mCurrentView->hide();
|
|
232 |
}
|
|
233 |
|
|
234 |
// Check the given data.
|
|
235 |
NmStartParamDataHelper dataHelper;
|
|
236 |
bool validData = dataHelper.extractData(uri);
|
|
237 |
|
|
238 |
NmMailboxListModel &mailboxListModel = mUiEngine.mailboxListModel();
|
|
239 |
const int count = mailboxListModel.rowCount();
|
|
240 |
NmId mailboxId(0);
|
|
241 |
|
|
242 |
mAsyncReqId = setCurrentRequestAsync();
|
|
243 |
|
|
244 |
if (!validData) {
|
|
245 |
// Failed to extract the data!
|
|
246 |
NM_ERROR(1,"NmUriServiceInterface::view(): failed to process the given data");
|
|
247 |
cancelService();
|
|
248 |
}
|
|
249 |
else if (count == 0) {
|
|
250 |
HbDeviceMessageBox note(hbTrId("txt_mail_dialog_no_mailboxes_defined"),
|
|
251 |
HbMessageBox::MessageTypeInformation);
|
|
252 |
note.setTimeout(HbMessageBox::NoTimeout);
|
|
253 |
note.show();
|
|
254 |
cancelService();
|
|
255 |
}
|
|
256 |
else { // count > 0
|
47
|
257 |
if (mainWindow) {
|
|
258 |
mainWindow->show();
|
|
259 |
}
|
43
|
260 |
|
|
261 |
mStartParam = new NmUiStartParam(
|
|
262 |
NmUiViewMessageEditor,
|
|
263 |
0, // account id
|
|
264 |
0, // folder id
|
|
265 |
0, // message id
|
|
266 |
NmUiEditorMailto, // editor start mode
|
|
267 |
dataHelper.mToAddresses, // address list
|
|
268 |
0, // attachment list
|
|
269 |
true, // start as service
|
|
270 |
dataHelper.mSubject, // message subject
|
|
271 |
dataHelper.mCcAddresses, // list containing cc recipient addresses
|
|
272 |
dataHelper.mBccAddresses // list containing bcc recipient addresses
|
|
273 |
);
|
|
274 |
|
|
275 |
if (count == 1) {
|
|
276 |
// A single mailbox exists.
|
|
277 |
QModelIndex modelIndex = mailboxListModel.index(0, 0);
|
|
278 |
QVariant mailbox(mailboxListModel.data(modelIndex));
|
|
279 |
NmMailboxMetaData *mailboxMetaData = mailbox.value<NmMailboxMetaData*>();
|
|
280 |
mailboxId = mailboxMetaData->id();
|
|
281 |
launchEditorView(mailboxId);
|
|
282 |
}
|
|
283 |
else { // count > 1
|
|
284 |
if (!mSelectionDialog) {
|
|
285 |
mSelectionDialog =
|
|
286 |
new NmMailboxSelectionDialog(mUiEngine.mailboxListModel());
|
|
287 |
}
|
62
|
288 |
|
|
289 |
if (!XQServiceUtil::isEmbedded()) {
|
|
290 |
XQServiceUtil::toBackground(false);
|
|
291 |
}
|
|
292 |
|
43
|
293 |
connect(mSelectionDialog,SIGNAL(selectionDialogClosed(NmId&)),
|
|
294 |
this,SLOT(selectionDialogClosed(NmId&)));
|
|
295 |
mSelectionDialog->open();
|
|
296 |
|
|
297 |
// launch the editor when the dialog is closed
|
|
298 |
}
|
|
299 |
}
|
|
300 |
|
|
301 |
return true;
|
|
302 |
}
|
|
303 |
|
|
304 |
/*!
|
|
305 |
Called when mailbox id is known and editor can be opened
|
|
306 |
\param mailboxId mailbox using in editor
|
|
307 |
*/
|
|
308 |
void NmUriServiceInterface::launchEditorView(NmId mailboxId)
|
|
309 |
{
|
|
310 |
NM_FUNCTION;
|
|
311 |
NM_COMMENT(QString("NmUriServiceInterface::launchEditorView(): mailboxId=%1").arg(mailboxId.id()));
|
|
312 |
|
|
313 |
// Make the previous view visible again.
|
|
314 |
if (mCurrentView) {
|
|
315 |
mCurrentView->show();
|
|
316 |
mCurrentView = NULL;
|
|
317 |
}
|
|
318 |
|
|
319 |
if (mStartParam) {
|
62
|
320 |
// Make sure the NMail application is in the foreground
|
|
321 |
if (!XQServiceUtil::isEmbedded()) {
|
|
322 |
XQServiceUtil::toBackground(false);
|
|
323 |
}
|
|
324 |
|
43
|
325 |
mStartParam->setMailboxId(mailboxId);
|
|
326 |
mApplication->enterNmUiView(mStartParam);
|
|
327 |
mStartParam = NULL; // ownership passed
|
|
328 |
}
|
|
329 |
completeRequest(mAsyncReqId, 1);
|
|
330 |
mAsyncReqId = 0;
|
|
331 |
}
|
|
332 |
|
|
333 |
void NmUriServiceInterface::cancelService()
|
|
334 |
{
|
|
335 |
NM_FUNCTION;
|
|
336 |
|
|
337 |
delete mStartParam;
|
|
338 |
mStartParam = NULL;
|
|
339 |
|
|
340 |
// If the service was started as embedded, do not hide the app.
|
|
341 |
if (!XQServiceUtil::isEmbedded()) {
|
|
342 |
XQServiceUtil::toBackground(true);
|
|
343 |
}
|
|
344 |
|
|
345 |
completeRequest(mAsyncReqId, 0);
|
|
346 |
mAsyncReqId = 0;
|
|
347 |
|
|
348 |
// If started as service, the application must be closed now.
|
|
349 |
if (XQServiceUtil::isService()) {
|
|
350 |
connect(this, SIGNAL(returnValueDelivered()),
|
|
351 |
mApplication, SLOT(delayedExitApplication()));
|
|
352 |
}
|
|
353 |
else {
|
|
354 |
// Make the previous view visible again
|
|
355 |
if (mCurrentView) {
|
|
356 |
mCurrentView->show();
|
|
357 |
mCurrentView = NULL;
|
|
358 |
}
|
|
359 |
}
|
|
360 |
}
|
|
361 |
|
|
362 |
// End of file.
|