1 /* |
|
2 * Copyright (c) 2009 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "btmsgviewer.h" |
|
20 #include "apmstd.h" |
|
21 #include <xqaiwrequest.h> |
|
22 #include <xqconversions.h> |
|
23 #include <apgcli.h> |
|
24 #include <QFileInfo> |
|
25 #include <QDir> |
|
26 #include <QFile> |
|
27 #include <hbapplication.h> |
|
28 |
|
29 const QString KMimeTypeVCard("text/X-vCard"); |
|
30 |
|
31 |
|
32 BTMsgViewer::BTMsgViewer(QObject* parent) |
|
33 : XQServiceProvider("com.nokia.services.btmsgdispservices.displaymsg", parent), mCurrentRequestIndex(0) |
|
34 { |
|
35 publishAll(); |
|
36 connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit())); |
|
37 } |
|
38 |
|
39 BTMsgViewer::~BTMsgViewer () |
|
40 { |
|
41 |
|
42 } |
|
43 |
|
44 void BTMsgViewer::displaymsg( int messageId ) |
|
45 { |
|
46 mCurrentRequestIndex = setCurrentRequestAsync(); |
|
47 CBtMsgViewerUtils* btViewerUtils = 0; |
|
48 |
|
49 TRAPD(error, btViewerUtils = CBtMsgViewerUtils::NewL()); |
|
50 if(isError(error)) |
|
51 { |
|
52 if(btViewerUtils) |
|
53 delete btViewerUtils; |
|
54 |
|
55 QVariant retVal(error); |
|
56 completeRequest(mCurrentRequestIndex, retVal); |
|
57 return; |
|
58 } |
|
59 |
|
60 HBufC* fileName = 0; |
|
61 fileName = btViewerUtils->GetMessagePath(messageId, error); |
|
62 if(isError(error)) |
|
63 { |
|
64 if(fileName) |
|
65 delete fileName; |
|
66 |
|
67 delete btViewerUtils; |
|
68 |
|
69 QVariant retVal(error); |
|
70 completeRequest(mCurrentRequestIndex, retVal); |
|
71 return; |
|
72 } |
|
73 |
|
74 QString attachmentFName = XQConversions::s60DescToQString(fileName->Des()); |
|
75 QString mimeType = XQConversions::s60Desc8ToQString(btViewerUtils->GetMimeType()->Des()); |
|
76 delete fileName; |
|
77 delete btViewerUtils; |
|
78 |
|
79 if(mimeType == KMimeTypeVCard) |
|
80 { |
|
81 int error = KErrGeneral; |
|
82 |
|
83 /*todo: copyVCardToTemp() has to be removed when phonebook updates it's capabilites to |
|
84 access messages from private folder*/ |
|
85 QString newfilepath = copyVCardToTemp(attachmentFName); |
|
86 |
|
87 QString service("com.nokia.services.phonebookservices"); |
|
88 QString interface("Fetch"); |
|
89 QString operation("editCreateNew(QString)"); |
|
90 XQApplicationManager appManager; |
|
91 XQAiwRequest* request = appManager.create(service, interface, operation, true); //embedded |
|
92 if(request) |
|
93 { |
|
94 QList<QVariant> args; |
|
95 args << newfilepath; |
|
96 request->setArguments(args); |
|
97 QVariant retValue; |
|
98 bool res = request->send(retValue); |
|
99 if (!res) |
|
100 { |
|
101 error = request->lastError(); |
|
102 } |
|
103 else |
|
104 { |
|
105 error = retValue.toInt(); |
|
106 } |
|
107 |
|
108 delete request; |
|
109 } |
|
110 |
|
111 /*todo: copyVCardToTemp() has to be removed when phonebook updates it's capabilites to |
|
112 access messages from private folder*/ |
|
113 deleteVCardFromTemp(newfilepath); |
|
114 |
|
115 QVariant retVal(error); |
|
116 completeRequest(mCurrentRequestIndex, retVal); |
|
117 return; |
|
118 } |
|
119 |
|
120 XQSharableFile sf; |
|
121 XQAiwRequest* request = 0; |
|
122 |
|
123 if (!sf.open(attachmentFName)) { |
|
124 QVariant retVal(KErrGeneral); |
|
125 completeRequest(mCurrentRequestIndex, retVal); |
|
126 return; |
|
127 } |
|
128 |
|
129 // Get handlers |
|
130 XQApplicationManager appManager; |
|
131 QList<XQAiwInterfaceDescriptor> fileHandlers = appManager.list(sf); |
|
132 if (fileHandlers.count() > 0) { |
|
133 XQAiwInterfaceDescriptor d = fileHandlers.first(); |
|
134 request = appManager.create(sf, d); |
|
135 |
|
136 if (!request) { |
|
137 sf.close(); |
|
138 |
|
139 QVariant retVal(KErrGeneral); |
|
140 completeRequest(mCurrentRequestIndex, retVal); |
|
141 return; |
|
142 } |
|
143 } |
|
144 else { |
|
145 sf.close(); |
|
146 |
|
147 QVariant retVal(KErrGeneral); |
|
148 completeRequest(mCurrentRequestIndex, retVal); |
|
149 return; |
|
150 } |
|
151 |
|
152 request->setEmbedded(true); |
|
153 request->setSynchronous(true); |
|
154 |
|
155 // Fill args |
|
156 QList<QVariant> args; |
|
157 args << qVariantFromValue(sf); |
|
158 request->setArguments(args); |
|
159 |
|
160 int err = KErrNone; |
|
161 bool res = request->send(); |
|
162 if (!res) |
|
163 { |
|
164 err = request->lastError(); |
|
165 } |
|
166 |
|
167 // Cleanup |
|
168 sf.close(); |
|
169 delete request; |
|
170 |
|
171 QVariant retVal(err); |
|
172 completeRequest(mCurrentRequestIndex, retVal); |
|
173 return; |
|
174 } |
|
175 |
|
176 bool BTMsgViewer::isError(int aError) |
|
177 { |
|
178 return ((aError < KErrNone)?true:false); |
|
179 } |
|
180 |
|
181 QString BTMsgViewer::copyVCardToTemp(const QString& filepath) |
|
182 { |
|
183 QDir tempDir; |
|
184 QString tempFilePath(QDir::toNativeSeparators(tempDir.tempPath())); |
|
185 tempFilePath.append(QDir::separator()); |
|
186 QFileInfo fInfo(filepath); |
|
187 tempFilePath.append(fInfo.fileName()); |
|
188 QFile::copy(filepath, tempFilePath); |
|
189 return tempFilePath; |
|
190 } |
|
191 |
|
192 void BTMsgViewer::deleteVCardFromTemp(const QString& filepath) |
|
193 { |
|
194 QFile::remove(filepath); |
|
195 } |
|