camerauis/cameraxui/cxengine/tsrc/unit/system_include/thumbnailmanager_qt.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 23 61bc0f252b2b
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
     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 
       
    20 #include "cxutils.h"
       
    21 #include "thumbnailmanager_qt.h"
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 /*!
       
    27 * ThumbnailManager::ThumbnailManager
       
    28 */
       
    29 ThumbnailManager::ThumbnailManager(QObject* parentPtr)
       
    30     : mTimer(this)
       
    31 {
       
    32     Q_UNUSED(parentPtr);
       
    33 
       
    34     mCurrentThumbnailId = 0;
       
    35     mThumbnailManagerIds.clear();
       
    36     mTimer.setSingleShot(true);
       
    37     connect(&mTimer, SIGNAL(timeout()),
       
    38             this, SLOT(emulateThumbnailReady()));
       
    39 }
       
    40 
       
    41 
       
    42 /*!
       
    43 * ThumbnailManager::~ThumbnailManager
       
    44 */
       
    45 ThumbnailManager::~ThumbnailManager()
       
    46 {
       
    47 }
       
    48 
       
    49 
       
    50 
       
    51 /*!
       
    52 * create thumbnail for the given image/video file name and data.
       
    53 */
       
    54 int ThumbnailManager::getThumbnail(const QString& filename, void * clientData, int priority)
       
    55 {
       
    56     CX_DEBUG_ENTER_FUNCTION();
       
    57     Q_UNUSED(priority);
       
    58         
       
    59     int id = 0;
       
    60 
       
    61     if (filename.isNull() || filename.isEmpty()) {
       
    62         id = -1;
       
    63     } else {
       
    64         // generate thumbnail id
       
    65         id = mCurrentThumbnailId;
       
    66         mThumbnailManagerIds.append(mCurrentThumbnailId++);
       
    67     }
       
    68 
       
    69     // try emulating thumbnail ready
       
    70     mTimer.start(1000);
       
    71 
       
    72     CX_DEBUG_EXIT_FUNCTION();
       
    73 
       
    74     return id;
       
    75 }
       
    76 
       
    77 int ThumbnailManager::setThumbnail( const QImage& source, const QString& fileName,
       
    78       void *clientData, int priority)
       
    79 {
       
    80     Q_UNUSED(clientData);
       
    81     Q_UNUSED(priority);
       
    82     Q_UNUSED(source);
       
    83 
       
    84     int status = KErrNone;
       
    85 
       
    86     if (fileName.isNull() || fileName.isEmpty()) {
       
    87         status = KErrNotFound;
       
    88     } else {
       
    89         // generate thumbnail id
       
    90         mThumbnailManagerIds.append(mCurrentThumbnailId);
       
    91     }
       
    92 
       
    93     emit thumbnailReady(QPixmap(), clientData, mCurrentThumbnailId, status);
       
    94 
       
    95     mCurrentThumbnailId++;
       
    96 
       
    97     CX_DEBUG_EXIT_FUNCTION();
       
    98 
       
    99     return mCurrentThumbnailId;
       
   100 }
       
   101 
       
   102 /*!
       
   103 * start canceling creating thumbnail operation
       
   104 */
       
   105 bool ThumbnailManager::cancelRequest(int id)
       
   106 {
       
   107     return mThumbnailManagerIds.contains(id);
       
   108 }
       
   109 
       
   110 
       
   111 /*!
       
   112 * slot that emulates thumbnail ready
       
   113 */
       
   114 void ThumbnailManager::emulateThumbnailReady()
       
   115 {
       
   116     // get the current thumbnail id
       
   117     int id = mCurrentThumbnailId - 1;
       
   118     int status = KErrNone;
       
   119     
       
   120     if (id == -1) {
       
   121         // if there are no valid thumbnails
       
   122         status = KErrNotFound;
       
   123     }
       
   124     emit thumbnailReady(QPixmap(), 0, id, status);
       
   125 }
       
   126