|
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 fetcher client. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "hsimagefetcherclient.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 |
|
29 #ifdef COVERAGE_MEASUREMENT |
|
30 #pragma CTC SKIP |
|
31 #endif //COVERAGE_MEASUREMENT |
|
32 |
|
33 |
|
34 /*! |
|
35 \class HsImageFetcherClient |
|
36 \ingroup group_hsutils |
|
37 \brief |
|
38 */ |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 #ifdef Q_OS_SYMBIAN |
|
44 HsImageFetcherClient::HsImageFetcherClient(QObject *parent) |
|
45 : QObject(parent), |
|
46 mReq(0) |
|
47 { |
|
48 } |
|
49 #else |
|
50 HsImageFetcherClient::HsImageFetcherClient(QObject *parent) |
|
51 : QObject(parent) |
|
52 { |
|
53 } |
|
54 #endif // Q_OS_SYMBIAN |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 HsImageFetcherClient::~HsImageFetcherClient() |
|
60 { |
|
61 #ifdef Q_OS_SYMBIAN |
|
62 delete mReq; |
|
63 #endif // Q_OS_SYMBIAN |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 void HsImageFetcherClient::fetch() |
|
70 { |
|
71 #ifdef Q_OS_SYMBIAN |
|
72 qDebug() << "HsImageFetcherClient::fetch START"; |
|
73 |
|
74 if (mReq) { |
|
75 delete mReq; |
|
76 mReq = 0; |
|
77 } |
|
78 |
|
79 mReq = mAppMgr.create(XQI_IMAGE_FETCH, XQOP_IMAGE_FETCH, false); |
|
80 if (mReq) { |
|
81 connect(mReq, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
|
82 connect(mReq, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&))); |
|
83 } else { |
|
84 qCritical() << "HsImageFetcherClient::fetch -> Create request failed"; |
|
85 return; |
|
86 } |
|
87 |
|
88 if (!(mReq)->send()) { |
|
89 qCritical() << "HsImageFetcherClient::fetch -> Send failed" << mReq->lastErrorMessage();; |
|
90 } |
|
91 |
|
92 qDebug() << "HsImageFetcherClient::fetch END"; |
|
93 #endif // Q_OS_SYMBIAN |
|
94 } |
|
95 |
|
96 |
|
97 |
|
98 // Aiw request responses |
|
99 void HsImageFetcherClient::handleOk(const QVariant &result) |
|
100 { |
|
101 #ifdef Q_OS_SYMBIAN |
|
102 // disconnect error signal as it will give -4999 (EConnectionClosed) error afterwards even though image |
|
103 // is fetched successfully |
|
104 disconnect(mReq, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&))); |
|
105 |
|
106 XQAiwRequest *request = static_cast<XQAiwRequest *>(sender()); |
|
107 int implementationId=-1; |
|
108 implementationId = (request->descriptor().property(XQAiwInterfaceDescriptor::ImplementationId)).toInt(); |
|
109 |
|
110 if (result.canConvert<QString>()) { |
|
111 qDebug("HsImageFetcherClient::%x:handleOk result=%s,%s", |
|
112 implementationId, |
|
113 result.typeName(), |
|
114 qPrintable(result.value<QString>())); |
|
115 |
|
116 emit fetchCompleted(result.value<QString>()); |
|
117 } else if (result.canConvert<QStringList>()) { |
|
118 QStringList resultList = result.value<QStringList>(); |
|
119 if (resultList.size() > 0) { |
|
120 //for debug |
|
121 QString msg = QString("HsImageFetcherClient::handleOk, size=")+QString::number( resultList.size() )+QString("\n"); |
|
122 for (int i(0), size(resultList.size()); i < size; ++i) { |
|
123 msg += QString::number(i) + QString(":") + resultList[i] + QString("\n"); |
|
124 } |
|
125 qDebug()<<msg; |
|
126 } |
|
127 emit fetchCompleted(resultList[0]); |
|
128 } else { |
|
129 qCritical("AppMgrClient::%x:handleOk result=%s. Not displayable", |
|
130 implementationId, |
|
131 result.typeName()); |
|
132 emit fetchFailed(-1, QString()); |
|
133 } |
|
134 #else |
|
135 Q_UNUSED(result) |
|
136 #endif // Q_OS_SYMBIAN |
|
137 } |
|
138 |
|
139 void HsImageFetcherClient::handleError(int errorCode, const QString &errorMessage) |
|
140 { |
|
141 #ifdef Q_OS_SYMBIAN |
|
142 XQAiwRequest *request = static_cast<XQAiwRequest *>(sender()); |
|
143 int implementationId = -1; |
|
144 implementationId = (request->descriptor().property(XQAiwInterfaceDescriptor::ImplementationId)).toInt(); |
|
145 |
|
146 qCritical("HsImageFetcherClient::%x:handleError code=%d, errorMessage:%s", |
|
147 implementationId, errorCode, qPrintable(errorMessage)); |
|
148 emit fetchFailed(errorCode, errorMessage); |
|
149 #else |
|
150 Q_UNUSED(errorCode) |
|
151 Q_UNUSED(errorMessage) |
|
152 #endif // Q_OS_SYMBIAN |
|
153 } |
|
154 |
|
155 #ifdef COVERAGE_MEASUREMENT |
|
156 #pragma CTC ENDSKIP |
|
157 #endif //COVERAGE_MEASUREMENT |