|
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: Photos image handling client. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "hsimagehandlingclient.h" |
|
20 |
|
21 #include <QDir> |
|
22 #include <QDebug> |
|
23 #include <QVariant> |
|
24 #ifdef Q_OS_SYMBIAN |
|
25 #include <xqaiwinterfacedescriptor.h> |
|
26 #include <xqaiwdecl.h> |
|
27 #endif // Q_OS_SYMBIAN |
|
28 #ifdef FF_IMAGE_EDITOR |
|
29 #include <photoeditor_highway.hrh> |
|
30 #endif //FF_IMAGE_EDITOR |
|
31 |
|
32 #ifdef COVERAGE_MEASUREMENT |
|
33 #pragma CTC SKIP |
|
34 #endif //COVERAGE_MEASUREMENT |
|
35 |
|
36 |
|
37 /*! |
|
38 \class HsImageHandlingClient |
|
39 \ingroup group_hsutils |
|
40 \brief |
|
41 */ |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 #ifdef Q_OS_SYMBIAN |
|
47 HsImageHandlingClient::HsImageHandlingClient(QObject *parent) |
|
48 : QObject(parent), |
|
49 mReq(0) |
|
50 { |
|
51 } |
|
52 #else |
|
53 HsImageHandlingClient::HsImageHandlingClient(QObject *parent) |
|
54 : QObject(parent) |
|
55 { |
|
56 } |
|
57 #endif // Q_OS_SYMBIAN |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 HsImageHandlingClient::~HsImageHandlingClient() |
|
63 { |
|
64 #ifdef Q_OS_SYMBIAN |
|
65 delete mReq; |
|
66 #endif // Q_OS_SYMBIAN |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 void HsImageHandlingClient::fetch() |
|
73 { |
|
74 #ifdef Q_OS_SYMBIAN |
|
75 qDebug() << "HsImageHandlingClient::fetch START"; |
|
76 |
|
77 if (mReq) { |
|
78 delete mReq; |
|
79 mReq = 0; |
|
80 } |
|
81 |
|
82 mReq = mAppMgr.create(XQI_IMAGE_FETCH, XQOP_IMAGE_FETCH, false); |
|
83 if (mReq) { |
|
84 connect(mReq, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
|
85 connect(mReq, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&))); |
|
86 } else { |
|
87 qCritical() << "HsImageHandlingClient::fetch -> Create request failed"; |
|
88 return; |
|
89 } |
|
90 |
|
91 if (!(mReq)->send()) { |
|
92 qCritical() << "HsImageHandlingClient::fetch -> Send failed" << mReq->lastErrorMessage();; |
|
93 } |
|
94 |
|
95 qDebug() << "HsImageHandlingClient::fetch END"; |
|
96 #endif // Q_OS_SYMBIAN |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 void HsImageHandlingClient::edit(const QString &imagePath) |
|
103 { |
|
104 #ifdef Q_OS_SYMBIAN |
|
105 qDebug() << "HsImageHandlingClient::edit START"; |
|
106 |
|
107 const QString service = QLatin1String("PhotoEditor"); |
|
108 const QString interface = QLatin1String("com.nokia.symbian.imageeditor"); |
|
109 const QString operation = QLatin1String("view(QString,int)"); |
|
110 |
|
111 //Connect to service provider |
|
112 if(mReq == NULL){ |
|
113 mReq = mAppMgr.create(service, interface, operation, true); |
|
114 mReq->setEmbedded(true); |
|
115 mReq->setSynchronous(false); |
|
116 } |
|
117 |
|
118 if(mReq == NULL){ |
|
119 return; |
|
120 } |
|
121 |
|
122 if (mReq) { |
|
123 connect(mReq, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleEditorOk(const QVariant&))); |
|
124 connect(mReq, SIGNAL(requestError(int,const QString&)), this, SLOT(handleEditorError(int,const QString&))); |
|
125 } else { |
|
126 qCritical() << "HsImageHandlingClient::edit -> Create request failed"; |
|
127 return; |
|
128 } |
|
129 QList<QVariant> args; |
|
130 args << imagePath; |
|
131 args << EEditorHighwayWallpaperCrop; |
|
132 mReq->setArguments(args); |
|
133 if (!(mReq)->send()) { |
|
134 qCritical() << "HsImageHandlingClient::edit -> Send failed" << mReq->lastErrorMessage();; |
|
135 } |
|
136 |
|
137 qDebug() << "HsImageHandlingClient::edit END"; |
|
138 #endif // Q_OS_SYMBIAN |
|
139 } |
|
140 |
|
141 // Aiw request responses |
|
142 void HsImageHandlingClient::handleOk(const QVariant &result) |
|
143 { |
|
144 #ifdef Q_OS_SYMBIAN |
|
145 // disconnect error signal as it will give -4999 (EConnectionClosed) error afterwards even though image |
|
146 // is fetched successfully |
|
147 disconnect(mReq, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&))); |
|
148 |
|
149 XQAiwRequest *request = static_cast<XQAiwRequest *>(sender()); |
|
150 int implementationId=-1; |
|
151 implementationId = (request->descriptor().property(XQAiwInterfaceDescriptor::ImplementationId)).toInt(); |
|
152 |
|
153 if (result.canConvert<QString>()) { |
|
154 qDebug("HsImageHandlingClient::%x:handleOk result=%s,%s", |
|
155 implementationId, |
|
156 result.typeName(), |
|
157 qPrintable(result.value<QString>())); |
|
158 |
|
159 emit fetchCompleted(result.value<QString>()); |
|
160 } else if (result.canConvert<QStringList>()) { |
|
161 QStringList resultList = result.value<QStringList>(); |
|
162 if (resultList.size() > 0) { |
|
163 //for debug |
|
164 QString msg = QString("HsImageHandlingClient::handleOk, size=")+QString::number( resultList.size() )+QString("\n"); |
|
165 for (int i(0), size(resultList.size()); i < size; ++i) { |
|
166 msg += QString::number(i) + QString(":") + resultList[i] + QString("\n"); |
|
167 } |
|
168 qDebug()<<msg; |
|
169 } |
|
170 emit fetchCompleted(resultList[0]); |
|
171 } else { |
|
172 qCritical("AppMgrClient::%x:handleOk result=%s. Not displayable", |
|
173 implementationId, |
|
174 result.typeName()); |
|
175 emit fetchFailed(-1, QString()); |
|
176 } |
|
177 #else |
|
178 Q_UNUSED(result) |
|
179 #endif // Q_OS_SYMBIAN |
|
180 } |
|
181 |
|
182 void HsImageHandlingClient::handleError(int errorCode, const QString &errorMessage) |
|
183 { |
|
184 #ifdef Q_OS_SYMBIAN |
|
185 XQAiwRequest *request = static_cast<XQAiwRequest *>(sender()); |
|
186 int implementationId = -1; |
|
187 implementationId = (request->descriptor().property(XQAiwInterfaceDescriptor::ImplementationId)).toInt(); |
|
188 |
|
189 qCritical("HsImageHandlingClient::%x:handleError code=%d, errorMessage:%s", |
|
190 implementationId, errorCode, qPrintable(errorMessage)); |
|
191 emit fetchFailed(errorCode, errorMessage); |
|
192 #else |
|
193 Q_UNUSED(errorCode) |
|
194 Q_UNUSED(errorMessage) |
|
195 #endif // Q_OS_SYMBIAN |
|
196 } |
|
197 |
|
198 void HsImageHandlingClient::handleEditorOk(const QVariant& result) |
|
199 { |
|
200 Q_UNUSED(result) |
|
201 emit editorCompleted(); |
|
202 } |
|
203 |
|
204 void HsImageHandlingClient::handleEditorError(int errorCode, |
|
205 const QString& errorMessage) |
|
206 { |
|
207 emit editorFailed(errorCode, errorMessage); |
|
208 } |
|
209 #ifdef COVERAGE_MEASUREMENT |
|
210 #pragma CTC ENDSKIP |
|
211 #endif //COVERAGE_MEASUREMENT |