18 #include "cntimageeditorview.h" |
18 #include "cntimageeditorview.h" |
19 #include "cntimageutility.h" |
19 #include "cntimageutility.h" |
20 |
20 |
21 #include <hblabel.h> |
21 #include <hblabel.h> |
22 #include <xqaiwrequest.h> |
22 #include <xqaiwrequest.h> |
|
23 #include <xqaiwdecl.h> |
|
24 |
|
25 #include "cntdebug.h" |
|
26 |
23 #include <thumbnailmanager_qt.h> |
27 #include <thumbnailmanager_qt.h> |
24 #include <hbaction.h> |
28 #include <hbaction.h> |
25 #include <hbview.h> |
29 #include <hbview.h> |
26 #include <hbmainwindow.h> |
30 #include <hbmainwindow.h> |
27 #include <hblistview.h> |
31 #include <hblistview.h> |
29 #include <hbframebackground.h> |
33 #include <hbframebackground.h> |
30 |
34 |
31 #include <QStandardItemModel> |
35 #include <QStandardItemModel> |
32 |
36 |
33 const char *CNT_IMAGE_XML = ":/xml/contacts_if.docml"; |
37 const char *CNT_IMAGE_XML = ":/xml/contacts_if.docml"; |
34 |
|
35 #define FETCHER_SERVICE "photos" |
|
36 #define FETCHER_INTERFACE "com.nokia.symbian.IImageFetch" |
|
37 #define FETCHER_OPERATION "fetch()" |
|
38 |
38 |
39 /*! |
39 /*! |
40 Constructor |
40 Constructor |
41 */ |
41 */ |
42 CntImageEditorView::CntImageEditorView() : |
42 CntImageEditorView::CntImageEditorView() : |
178 /*! |
182 /*! |
179 Open camera and get new image for contact |
183 Open camera and get new image for contact |
180 */ |
184 */ |
181 void CntImageEditorView::openCamera() |
185 void CntImageEditorView::openCamera() |
182 { |
186 { |
183 |
187 CNT_ENTRY |
184 } |
188 |
185 |
|
186 /*! |
|
187 Open gallery and select image for contact |
|
188 */ |
|
189 void CntImageEditorView::openGallery() |
|
190 { |
|
191 if (mRequest) |
189 if (mRequest) |
192 { |
190 { |
193 delete mRequest; |
191 delete mRequest; |
194 mRequest = 0; |
192 mRequest = 0; |
195 } |
193 } |
196 |
194 |
197 mRequest = mAppManager.create(FETCHER_SERVICE, FETCHER_INTERFACE, FETCHER_OPERATION, true); |
195 mRequest = mAppManager.create(XQI_CAMERA_CAPTURE, "capture(int,QVariantMap)", false); |
|
196 if ( mRequest ) |
|
197 { |
|
198 int mode = 0; //image mode |
|
199 |
|
200 QVariantMap map; |
|
201 map.insert(XQCAMERA_INDEX, 0); |
|
202 map.insert(XQCAMERA_QUALITY, 0); |
|
203 map.insert(XQCAMERA_MODE_SWITCH, false); |
|
204 map.insert(XQCAMERA_INDEX_SWITCH, false); |
|
205 map.insert(XQCAMERA_QUALITY_CHANGE, true); |
|
206 |
|
207 // Set function parameters |
|
208 QList<QVariant> args; |
|
209 args << mode; |
|
210 args << map; |
|
211 mRequest->setArguments(args); |
|
212 |
|
213 connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleImageChange(const QVariant&))); |
|
214 connect(mRequest, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&))); |
|
215 |
|
216 mRequest->send(); |
|
217 } |
|
218 |
|
219 CNT_EXIT |
|
220 } |
|
221 |
|
222 /*! |
|
223 Open gallery and select image for contact |
|
224 */ |
|
225 void CntImageEditorView::openGallery() |
|
226 { |
|
227 if (mRequest) |
|
228 { |
|
229 delete mRequest; |
|
230 mRequest = 0; |
|
231 } |
|
232 |
|
233 mRequest = mAppManager.create(XQI_IMAGE_FETCH, XQOP_IMAGE_FETCH, true); |
198 if ( mRequest ) |
234 if ( mRequest ) |
199 { |
235 { |
200 connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleImageChange(const QVariant&))); |
236 connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleImageChange(const QVariant&))); |
201 mRequest->send(); |
237 mRequest->send(); |
202 } |
238 } |
245 /*! |
281 /*! |
246 Set the selected image as new QContactAvatar::SubTypeImage |
282 Set the selected image as new QContactAvatar::SubTypeImage |
247 */ |
283 */ |
248 void CntImageEditorView::handleImageChange(const QVariant &value) |
284 void CntImageEditorView::handleImageChange(const QVariant &value) |
249 { |
285 { |
|
286 CNT_ENTRY_ARGS("image path = " << value.toString()) |
|
287 |
250 if(value.canConvert<QString>()) |
288 if(value.canConvert<QString>()) |
251 { |
289 { |
252 CntImageUtility imageUtility; |
290 CntImageUtility imageUtility; |
253 if(imageUtility.isMassStorageAvailable()) |
291 if(imageUtility.isMassStorageAvailable()) |
254 { |
292 { |
|
293 CNT_LOG_ARGS("mass storage available") |
255 /* Copy image and create thumbnail |
294 /* Copy image and create thumbnail |
256 * When contact image removed only copy is deleted |
295 * When contact image removed only copy is deleted |
257 */ |
296 */ |
258 QString imagepath; |
297 QString imagepath; |
259 if(imageUtility.createImage(value.toString(),imagepath)) |
298 if(imageUtility.createImage(value.toString(),imagepath)) |
260 { |
299 { |
|
300 |
261 // If image already assigned, delete |
301 // If image already assigned, delete |
262 QString filePath=mAvatar->imageUrl().toString(); |
302 QString filePath=mAvatar->imageUrl().toString(); |
263 if(!filePath.isEmpty() |
303 if(!filePath.isEmpty() |
264 && imageUtility.isImageRemovable(filePath)) |
304 && imageUtility.isImageRemovable(filePath)) |
265 imageUtility.removeImage(filePath); |
305 imageUtility.removeImage(filePath); |
266 |
306 |
|
307 CNT_LOG_ARGS("image created, image = " << filePath) |
|
308 |
267 mAvatar->setImageUrl(QUrl(imagepath)); |
309 mAvatar->setImageUrl(QUrl(imagepath)); |
268 mThumbnailManager->getThumbnail(imagepath); |
310 mThumbnailManager->getThumbnail(imagepath); |
269 mRemoveImage->setEnabled(true); |
311 mRemoveImage->setEnabled(true); |
270 } |
312 } |
271 } |
313 } |
275 mAvatar->setImageUrl(QUrl(value.toString())); |
317 mAvatar->setImageUrl(QUrl(value.toString())); |
276 mThumbnailManager->getThumbnail(value.toString()); |
318 mThumbnailManager->getThumbnail(value.toString()); |
277 mRemoveImage->setEnabled(true); |
319 mRemoveImage->setEnabled(true); |
278 } |
320 } |
279 } |
321 } |
|
322 |
|
323 CNT_EXIT |
280 } |
324 } |
281 |
325 |
282 void CntImageEditorView::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error) |
326 void CntImageEditorView::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error) |
283 { |
327 { |
|
328 CNT_ENTRY_ARGS("error code = " << error) |
|
329 |
284 Q_UNUSED(data); |
330 Q_UNUSED(data); |
285 Q_UNUSED(id); |
331 Q_UNUSED(id); |
286 if (!error) |
332 if (!error) |
287 { |
333 { |
288 QIcon qicon(pixmap); |
334 QIcon qicon(pixmap); |
289 HbIcon icon(qicon); |
335 HbIcon icon(qicon); |
290 mImageLabel->clear(); |
336 mImageLabel->clear(); |
291 mImageLabel->setIcon(icon); |
337 mImageLabel->setIcon(icon); |
292 } |
338 } |
|
339 |
|
340 CNT_EXIT |
293 } |
341 } |
294 |
342 |
295 void CntImageEditorView::setOrientation(Qt::Orientation orientation) |
343 void CntImageEditorView::setOrientation(Qt::Orientation orientation) |
296 { |
344 { |
297 if (orientation == Qt::Vertical) |
345 if (orientation == Qt::Vertical) |