|
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: Utility class for univiewer. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "univiewerutils.h" |
|
19 |
|
20 // SYSTEM INCLUDES |
|
21 #include <xqaiwrequest.h> |
|
22 #include <xqrequestinfo.h> |
|
23 #include <xqappmgr.h> |
|
24 #include <hbglobal.h> |
|
25 |
|
26 // USER INCLUDES |
|
27 #include "msgcontactsutil.h" |
|
28 |
|
29 // LOCAL CONSTANTS |
|
30 #define LOC_TITLE hbTrId("txt_messaging_title_messaging") |
|
31 |
|
32 const QString IMAGE_MIMETYPE("image"); |
|
33 const QString AUDIO_MIMETYPE("audio"); |
|
34 const QString VCARD_MIMETYPE("text/X-vCard"); |
|
35 const QString VIDEO_MIMETYPE("video"); |
|
36 |
|
37 //--------------------------------------------------------------- |
|
38 // UniViewerUtils::UniViewerUtils |
|
39 // @see header file |
|
40 //--------------------------------------------------------------- |
|
41 UniViewerUtils::UniViewerUtils(QObject *parent) : |
|
42 QObject(parent) |
|
43 { |
|
44 } |
|
45 |
|
46 //--------------------------------------------------------------- |
|
47 // UniViewerUtils::~UniViewerUtils |
|
48 // @see header file |
|
49 //--------------------------------------------------------------- |
|
50 UniViewerUtils::~UniViewerUtils() |
|
51 { |
|
52 } |
|
53 |
|
54 //--------------------------------------------------------------- |
|
55 // UniViewerUtils::addAttachmentWidget |
|
56 // @see header file |
|
57 //--------------------------------------------------------------- |
|
58 void UniViewerUtils::launchContentViewer(const QString &mimeType, const QString &filePath) |
|
59 { |
|
60 if (mimeType.contains(IMAGE_MIMETYPE) || mimeType.contains(AUDIO_MIMETYPE) || |
|
61 mimeType.contains(VIDEO_MIMETYPE)) { |
|
62 launchViaSharableFile(filePath); |
|
63 } |
|
64 else if (mimeType.contains(VCARD_MIMETYPE, Qt::CaseInsensitive)) { |
|
65 MsgContactsUtil::launchVCardViewer(filePath); |
|
66 } |
|
67 } |
|
68 |
|
69 //--------------------------------------------------------------- |
|
70 // UniViewerUtils::handleOk |
|
71 // @see header file |
|
72 //--------------------------------------------------------------- |
|
73 void UniViewerUtils::handleOk(const QVariant& result) |
|
74 { |
|
75 emit requestOk(result); |
|
76 } |
|
77 |
|
78 //--------------------------------------------------------------- |
|
79 // UniViewerUtils::handleError |
|
80 // @see header file |
|
81 //--------------------------------------------------------------- |
|
82 void UniViewerUtils::handleError(int errorCode, const QString& errorMessage) |
|
83 { |
|
84 emit requestError(errorCode, errorMessage); |
|
85 } |
|
86 |
|
87 //--------------------------------------------------------------- |
|
88 // UniViewerUtils::launchViaSharableFile |
|
89 // @see header file |
|
90 //--------------------------------------------------------------- |
|
91 void UniViewerUtils::launchViaSharableFile(const QString &filePath) |
|
92 { |
|
93 XQSharableFile sf; |
|
94 XQAiwRequest* request = 0; |
|
95 |
|
96 if (!sf.open(filePath)) { |
|
97 return; |
|
98 } |
|
99 |
|
100 // Get handlers |
|
101 XQApplicationManager appManager; |
|
102 QList<XQAiwInterfaceDescriptor> fileHandlers = appManager.list(sf); |
|
103 if (fileHandlers.count() > 0) { |
|
104 XQAiwInterfaceDescriptor d = fileHandlers.first(); |
|
105 request = appManager.create(sf, d); |
|
106 |
|
107 if (!request) { |
|
108 sf.close(); |
|
109 return; |
|
110 } |
|
111 } |
|
112 else { |
|
113 sf.close(); |
|
114 return; |
|
115 } |
|
116 |
|
117 // Result handlers |
|
118 connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)), |
|
119 Qt::UniqueConnection); |
|
120 connect(request, SIGNAL(requestError(int,const QString&)), this, |
|
121 SLOT(handleError(int,const QString&)), Qt::UniqueConnection); |
|
122 |
|
123 request->setEmbedded(true); |
|
124 request->setSynchronous(true); |
|
125 |
|
126 // Fill args |
|
127 QList<QVariant> args; |
|
128 args << qVariantFromValue(sf); |
|
129 request->setArguments(args); |
|
130 |
|
131 // Fill headers |
|
132 QString key("WindowTitle"); |
|
133 QVariant value(QString(LOC_TITLE)); |
|
134 XQRequestInfo info; |
|
135 info.setInfo(key, value); |
|
136 request->setInfo(info); |
|
137 |
|
138 request->send(); |
|
139 |
|
140 // Cleanup |
|
141 sf.close(); |
|
142 delete request; |
|
143 } |
|
144 |
|
145 //EOF |