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