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 NmUriServiceInterface
|
|
24 |
\brief NMail application service interface which provides an email sending
|
|
25 |
interface for other application using the Qt Highway.
|
|
26 |
*/
|
|
27 |
|
|
28 |
/*!
|
|
29 |
Class constructor.
|
|
30 |
*/
|
|
31 |
NmUriServiceInterface::NmUriServiceInterface(QObject *parent,
|
|
32 |
NmUiEngine &uiEngine,
|
|
33 |
NmApplication *application)
|
|
34 |
: XQServiceProvider(emailServiceName+"."+XQI_URI_VIEW, parent),
|
|
35 |
mApplication(application),
|
|
36 |
mUiEngine(uiEngine),
|
|
37 |
mAsyncReqId(0),
|
|
38 |
mStartParam(NULL),
|
|
39 |
mSelectionDialog(NULL),
|
|
40 |
mCurrentView(NULL)
|
|
41 |
{
|
|
42 |
publishAll();
|
|
43 |
}
|
|
44 |
|
|
45 |
|
|
46 |
/*!
|
|
47 |
Class desctructor.
|
|
48 |
*/
|
|
49 |
NmUriServiceInterface::~NmUriServiceInterface()
|
|
50 |
{
|
|
51 |
NM_FUNCTION;
|
|
52 |
|
|
53 |
delete mStartParam;
|
|
54 |
delete mSelectionDialog;
|
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
/*!
|
|
59 |
Queries the user for a mailbox to use.
|
|
60 |
\param mailboxId Where the ID of the selected mailbox is set.
|
|
61 |
\return True if a mailbox was selected, false otherwise.
|
|
62 |
*/
|
|
63 |
void NmUriServiceInterface::selectionDialogClosed(NmId &mailboxId)
|
|
64 |
{
|
|
65 |
NM_FUNCTION;
|
|
66 |
|
|
67 |
if (mailboxId.id()) { // mailbox selected
|
|
68 |
launchEditorView(mailboxId);
|
|
69 |
}
|
|
70 |
else {
|
|
71 |
cancelService();
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
|
|
76 |
/*!
|
|
77 |
Used from external applications to handle mailto: uri's.
|
|
78 |
|
|
79 |
\param data <mailto:> uri
|
|
80 |
*/
|
|
81 |
bool NmUriServiceInterface::view(const QString& uri)
|
|
82 |
{
|
|
83 |
NM_FUNCTION;
|
47
|
84 |
|
|
85 |
HbMainWindow *mainWindow(NULL);
|
|
86 |
if (mApplication) {
|
|
87 |
// Make sure that nmail stays background if user presses back in editorview
|
|
88 |
mApplication->updateVisibilityState();
|
|
89 |
|
|
90 |
mainWindow = mApplication->mainWindow();
|
|
91 |
if (mainWindow) {
|
|
92 |
mCurrentView = mainWindow->currentView();
|
|
93 |
}
|
|
94 |
}
|
43
|
95 |
|
|
96 |
// Hide the current view.
|
|
97 |
if (mCurrentView) {
|
|
98 |
mCurrentView->hide();
|
|
99 |
}
|
|
100 |
|
|
101 |
// Check the given data.
|
74
|
102 |
NmUriParser uriParser;
|
|
103 |
bool validData = uriParser.extractData(uri);
|
|
104 |
|
43
|
105 |
|
|
106 |
NmMailboxListModel &mailboxListModel = mUiEngine.mailboxListModel();
|
|
107 |
const int count = mailboxListModel.rowCount();
|
|
108 |
NmId mailboxId(0);
|
|
109 |
|
|
110 |
mAsyncReqId = setCurrentRequestAsync();
|
|
111 |
|
|
112 |
if (!validData) {
|
|
113 |
// Failed to extract the data!
|
|
114 |
NM_ERROR(1,"NmUriServiceInterface::view(): failed to process the given data");
|
|
115 |
cancelService();
|
|
116 |
}
|
|
117 |
else if (count == 0) {
|
|
118 |
HbDeviceMessageBox note(hbTrId("txt_mail_dialog_no_mailboxes_defined"),
|
|
119 |
HbMessageBox::MessageTypeInformation);
|
|
120 |
note.setTimeout(HbMessageBox::NoTimeout);
|
|
121 |
note.show();
|
|
122 |
cancelService();
|
|
123 |
}
|
|
124 |
else { // count > 0
|
47
|
125 |
if (mainWindow) {
|
74
|
126 |
mainWindow->show();
|
47
|
127 |
}
|
74
|
128 |
|
|
129 |
// The ownership of these is passed to NmApplication in launchEditorView()
|
|
130 |
QList<NmAddress*> *toAddresses = NmUtilities::qstringListToNmAddressList(uriParser.toAddresses());
|
|
131 |
QList<NmAddress*> *ccAddresses = NmUtilities::qstringListToNmAddressList(uriParser.ccAddresses());
|
|
132 |
QList<NmAddress*> *bccAddresses = NmUtilities::qstringListToNmAddressList(uriParser.bccAddresses());
|
|
133 |
|
|
134 |
QString* subject = new QString(uriParser.subject());
|
|
135 |
QString* bodyText = new QString(uriParser.bodyText());
|
|
136 |
|
43
|
137 |
mStartParam = new NmUiStartParam(
|
|
138 |
NmUiViewMessageEditor,
|
|
139 |
0, // account id
|
|
140 |
0, // folder id
|
|
141 |
0, // message id
|
|
142 |
NmUiEditorMailto, // editor start mode
|
74
|
143 |
toAddresses,
|
68
|
144 |
NULL, // attachment list
|
43
|
145 |
true, // start as service
|
74
|
146 |
subject, // message subject
|
|
147 |
ccAddresses, // list containing cc recipient addresses
|
|
148 |
bccAddresses, // list containing bcc recipient addresses
|
|
149 |
bodyText // body text
|
43
|
150 |
);
|
74
|
151 |
|
43
|
152 |
if (count == 1) {
|
|
153 |
// A single mailbox exists.
|
|
154 |
QModelIndex modelIndex = mailboxListModel.index(0, 0);
|
|
155 |
QVariant mailbox(mailboxListModel.data(modelIndex));
|
|
156 |
NmMailboxMetaData *mailboxMetaData = mailbox.value<NmMailboxMetaData*>();
|
|
157 |
mailboxId = mailboxMetaData->id();
|
|
158 |
launchEditorView(mailboxId);
|
|
159 |
}
|
|
160 |
else { // count > 1
|
|
161 |
if (!mSelectionDialog) {
|
|
162 |
mSelectionDialog =
|
|
163 |
new NmMailboxSelectionDialog(mUiEngine.mailboxListModel());
|
|
164 |
}
|
62
|
165 |
|
|
166 |
if (!XQServiceUtil::isEmbedded()) {
|
|
167 |
XQServiceUtil::toBackground(false);
|
|
168 |
}
|
|
169 |
|
43
|
170 |
connect(mSelectionDialog,SIGNAL(selectionDialogClosed(NmId&)),
|
|
171 |
this,SLOT(selectionDialogClosed(NmId&)));
|
|
172 |
mSelectionDialog->open();
|
|
173 |
|
|
174 |
// launch the editor when the dialog is closed
|
|
175 |
}
|
|
176 |
}
|
|
177 |
return true;
|
|
178 |
}
|
|
179 |
|
|
180 |
/*!
|
|
181 |
Called when mailbox id is known and editor can be opened
|
|
182 |
\param mailboxId mailbox using in editor
|
|
183 |
*/
|
|
184 |
void NmUriServiceInterface::launchEditorView(NmId mailboxId)
|
|
185 |
{
|
|
186 |
NM_FUNCTION;
|
|
187 |
NM_COMMENT(QString("NmUriServiceInterface::launchEditorView(): mailboxId=%1").arg(mailboxId.id()));
|
|
188 |
|
|
189 |
// Make the previous view visible again.
|
|
190 |
if (mCurrentView) {
|
|
191 |
mCurrentView->show();
|
|
192 |
mCurrentView = NULL;
|
|
193 |
}
|
|
194 |
|
|
195 |
if (mStartParam) {
|
62
|
196 |
// Make sure the NMail application is in the foreground
|
|
197 |
if (!XQServiceUtil::isEmbedded()) {
|
|
198 |
XQServiceUtil::toBackground(false);
|
|
199 |
}
|
|
200 |
|
43
|
201 |
mStartParam->setMailboxId(mailboxId);
|
|
202 |
mApplication->enterNmUiView(mStartParam);
|
|
203 |
mStartParam = NULL; // ownership passed
|
|
204 |
}
|
|
205 |
completeRequest(mAsyncReqId, 1);
|
|
206 |
mAsyncReqId = 0;
|
|
207 |
}
|
|
208 |
|
|
209 |
void NmUriServiceInterface::cancelService()
|
|
210 |
{
|
|
211 |
NM_FUNCTION;
|
|
212 |
|
|
213 |
delete mStartParam;
|
|
214 |
mStartParam = NULL;
|
|
215 |
|
|
216 |
// If the service was started as embedded, do not hide the app.
|
|
217 |
if (!XQServiceUtil::isEmbedded()) {
|
|
218 |
XQServiceUtil::toBackground(true);
|
|
219 |
}
|
|
220 |
|
|
221 |
completeRequest(mAsyncReqId, 0);
|
|
222 |
mAsyncReqId = 0;
|
|
223 |
|
|
224 |
// If started as service, the application must be closed now.
|
|
225 |
if (XQServiceUtil::isService()) {
|
|
226 |
connect(this, SIGNAL(returnValueDelivered()),
|
|
227 |
mApplication, SLOT(delayedExitApplication()));
|
|
228 |
}
|
|
229 |
else {
|
|
230 |
// Make the previous view visible again
|
|
231 |
if (mCurrentView) {
|
|
232 |
mCurrentView->show();
|
|
233 |
mCurrentView = NULL;
|
|
234 |
}
|
|
235 |
}
|
|
236 |
}
|
|
237 |
|
|
238 |
// End of file.
|