camerauis/cameraxui/cxengine/src/cxethumbnailmanagersymbian.cpp
changeset 19 d9aefe59d544
child 29 699651f2666f
child 43 0e652f8f1fbd
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
       
     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 #include <QString>
       
    19 #include <thumbnailmanager_qt.h>
       
    20 
       
    21 #include "cxutils.h"
       
    22 #include "cxethumbnailmanagersymbian.h"
       
    23 
       
    24 //#define CXE_USE_THUMBNAIL_MANAGER
       
    25 
       
    26 
       
    27 /*!
       
    28 * CxeThumbnailManagerSymbian::CxeThumbnailManagerSymbian
       
    29 */
       
    30 CxeThumbnailManagerSymbian::CxeThumbnailManagerSymbian()
       
    31 {
       
    32     CX_DEBUG_ENTER_FUNCTION();
       
    33 
       
    34 #ifdef CXE_USE_THUMBNAIL_MANAGER
       
    35 
       
    36     mThumbnailManager = new ThumbnailManager();
       
    37 
       
    38     // connect thumbnail ready signal from thumbnailmanager
       
    39     connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void *, int, int)),
       
    40             this, SLOT(thumbnailReady(QPixmap, void *, int, int)));
       
    41 #endif
       
    42 
       
    43     CX_DEBUG_EXIT_FUNCTION();
       
    44 }
       
    45 
       
    46 
       
    47 /*!
       
    48 * CxeThumbnailManagerSymbian::~CxeThumbnailManagerSymbian
       
    49 */
       
    50 CxeThumbnailManagerSymbian::~CxeThumbnailManagerSymbian()
       
    51 {
       
    52     CX_DEBUG_ENTER_FUNCTION();
       
    53 
       
    54 #ifdef CXE_USE_THUMBNAIL_MANAGER
       
    55     mThumbnailRequests.clear();
       
    56     delete mThumbnailManager;
       
    57 #endif
       
    58 
       
    59     CX_DEBUG_EXIT_FUNCTION();
       
    60 }
       
    61 
       
    62 
       
    63 
       
    64 /*!
       
    65 * Creates a thumbnail based on the snapshot data.
       
    66 @param filename - name of the image/video filename
       
    67 @param snapshot - snapshot data from image/video
       
    68 */
       
    69 void CxeThumbnailManagerSymbian::createThumbnail(const QString& filename,
       
    70                                                  QPixmap /*snapshot*/)
       
    71 {
       
    72     CX_DEBUG_ENTER_FUNCTION();
       
    73 
       
    74 #ifdef CXE_USE_THUMBNAIL_MANAGER
       
    75     TPtrC16 fName(reinterpret_cast<const TUint16*>(filename.utf16()));
       
    76     CX_DEBUG(("Create thumbnail! filename = %s", filename.toAscii().constData()));
       
    77 
       
    78     if (mThumbnailManager) {
       
    79         CX_DEBUG(("creating thumbnails"));
       
    80         //!@todo Thumbnail manager interface needs to be changed to use QImage
       
    81         // instead of QPixmap for setThumbnail. Until then, using qetThumbnail.
       
    82         int thumbnailId = mThumbnailManager->getThumbnail(filename, 0);
       
    83         if (thumbnailId != -1) {
       
    84             CX_DEBUG(("Thumbnail ID = %d", thumbnailId));
       
    85             mThumbnailRequests.insert(filename, thumbnailId);
       
    86         } else {
       
    87             CX_DEBUG(("error initializing data to thumbnail manager"));
       
    88         }
       
    89     }
       
    90 #else
       
    91     Q_UNUSED(filename);
       
    92 #endif
       
    93 
       
    94     CX_DEBUG_EXIT_FUNCTION();
       
    95 }
       
    96 
       
    97 
       
    98 
       
    99 /*!
       
   100 * start canceling creating thumbnail operation
       
   101 */
       
   102 void CxeThumbnailManagerSymbian::cancelThumbnail(const QString& filename)
       
   103 {
       
   104     CX_DEBUG_ENTER_FUNCTION();
       
   105 
       
   106 #ifdef CXE_USE_THUMBNAIL_MANAGER
       
   107     if (mThumbnailRequests.contains(filename)) {
       
   108         int thumbnailId = mThumbnailRequests.value(filename);
       
   109         if (mThumbnailManager &&
       
   110             mThumbnailManager->cancelRequest(thumbnailId)) {
       
   111             // thumbnail creation cancelled sucessfully
       
   112             mThumbnailRequests.remove(filename);
       
   113         }
       
   114     }
       
   115 #else
       
   116     Q_UNUSED(filename);
       
   117 #endif
       
   118     CX_DEBUG_EXIT_FUNCTION();
       
   119 }
       
   120 
       
   121 
       
   122 /**!
       
   123 * Slot that notifies when final thumbnail bitmap generation or loading is complete.
       
   124 * @param pixmap     An object representing the resulting thumbnail.
       
   125 * @param clientData Client data
       
   126 * @param id         Request ID for the operation
       
   127 * @param errorCode  error code
       
   128 */
       
   129 void CxeThumbnailManagerSymbian::thumbnailReady(QPixmap thumbnail, void * data, int id, int error)
       
   130 {
       
   131 
       
   132     CX_DEBUG_ENTER_FUNCTION();
       
   133 
       
   134     Q_UNUSED(data);
       
   135 #ifdef CXE_USE_THUMBNAIL_MANAGER
       
   136     CX_DEBUG(("CxeThumbnailManagerSymbian::thumbnailReady error = %d", error));
       
   137 
       
   138     QString key;
       
   139     QHash<QString, int>::const_iterator i = mThumbnailRequests.constBegin();
       
   140 
       
   141     while (i != mThumbnailRequests.constEnd()) {
       
   142         if (i.value() == id) {
       
   143             key = i.key();
       
   144             break;
       
   145         }
       
   146         ++i;
       
   147     }
       
   148 
       
   149     if (mThumbnailRequests.contains(key)) {
       
   150         CX_DEBUG(("Thumbnail created for filename = %s", key.toAscii().constData()));
       
   151         mThumbnailRequests.remove(key);
       
   152         emit thumbnailReady(thumbnail, error);
       
   153     }
       
   154 #else
       
   155     Q_UNUSED(thumbnail);
       
   156     Q_UNUSED(id);
       
   157     Q_UNUSED(error);
       
   158 #endif
       
   159 
       
   160     CX_DEBUG_EXIT_FUNCTION();
       
   161 }