qtmobility/plugins/contacts/symbian/src/transform/cnttransformthumbnail.cpp
changeset 4 90517678cc4f
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include "cnttransformthumbnail.h"
       
    42 #include "cntmodelextuids.h"
       
    43 
       
    44 #include "qcontactthumbnail.h"
       
    45 #include "cntsymbiantransformerror.h"
       
    46 
       
    47 #include <QPixmap>
       
    48 #include <QImage>
       
    49 
       
    50 const TSize KMaxThumbnailSize(80, 96);
       
    51 
       
    52 CntTransformThumbnail::CntTransformThumbnail() :
       
    53     m_thumbnailCreator(0)
       
    54 {
       
    55 }
       
    56 
       
    57 CntTransformThumbnail::~CntTransformThumbnail()
       
    58 {
       
    59     delete m_thumbnailCreator;
       
    60 }
       
    61 
       
    62 QList<CContactItemField *> CntTransformThumbnail::transformDetailL(const QContactDetail &detail)
       
    63 {
       
    64     if(detail.definitionName() != QContactThumbnail::DefinitionName)
       
    65         User::Leave(KErrArgument);
       
    66 
       
    67     QList<CContactItemField *> fieldList;
       
    68 
       
    69     //cast to thumbnail
       
    70     const QContactThumbnail &thumbnail(static_cast<const QContactThumbnail&>(detail));
       
    71 
       
    72     if(!thumbnail.thumbnail().isNull()) {
       
    73         // lazy instantiation
       
    74         if(!m_thumbnailCreator) {
       
    75             m_thumbnailCreator = new (ELeave) CntThumbnailCreator();
       
    76         }
       
    77 
       
    78         // Scaling is done before converting to CFbsBitmap because
       
    79         // toSymbianCFbsBitmap may generate a duplicate of the bitmap data
       
    80         // Note: scaling to thumbnail may take some time if the image is big
       
    81         // TODO: aspect ratio?
       
    82         QPixmap scaled = QPixmap::fromImage(thumbnail.thumbnail().scaled(KMaxThumbnailSize.iWidth, KMaxThumbnailSize.iHeight));
       
    83         CFbsBitmap* bitmap = scaled.toSymbianCFbsBitmap();
       
    84         CleanupStack::PushL(bitmap);
       
    85 
       
    86         m_thumbnailCreator->addThumbnailFieldL(&fieldList, bitmap, KMaxThumbnailSize);
       
    87         CleanupStack::Pop(bitmap); // ownership transferred
       
    88     }
       
    89 
       
    90     return fieldList;
       
    91 }
       
    92 
       
    93 QContactDetail *CntTransformThumbnail::transformItemField(const CContactItemField& field, const QContact &contact)
       
    94 {
       
    95 	Q_UNUSED(contact);
       
    96 
       
    97     QContactThumbnail *thumbnail = new QContactThumbnail();
       
    98 
       
    99     if (field.ContentType().ContainsFieldType(KUidContactFieldPicture)
       
   100         || field.ContentType().ContainsFieldType(KUidContactFieldVCardMapJPEG)) {
       
   101         // use the existing QContactAvatar (if available) in case of a pixmap
       
   102         // field.
       
   103         CContactStoreField* storage = field.StoreStorage();
       
   104         QImage image;
       
   105         HBufC8 *theThing = storage->Thing();
       
   106         QByteArray bytes((char*)theThing->Ptr(), theThing->Length());
       
   107         bool loaded = image.loadFromData(bytes, "JPG");
       
   108         if (loaded) {
       
   109             thumbnail->setThumbnail(image);
       
   110         } else {
       
   111             User::Leave(KErrInvalidContactDetail);
       
   112         }
       
   113     }
       
   114 
       
   115     return thumbnail;
       
   116 }
       
   117 
       
   118 bool CntTransformThumbnail::supportsField(TUint32 fieldType) const
       
   119 {
       
   120     bool ret = false;
       
   121     if (fieldType == KUidContactFieldPicture.iUid
       
   122         // Used as "extra mapping/extra field type" by thumbnail data fields
       
   123         || fieldType == KUidContactFieldVCardMapJPEG.iUid) {
       
   124         ret = true;
       
   125     }
       
   126     return ret;
       
   127 }
       
   128 
       
   129 bool CntTransformThumbnail::supportsDetail(QString detailName) const
       
   130 {
       
   131     bool ret = false;
       
   132     if (detailName == QContactThumbnail::DefinitionName) {
       
   133         ret = true;
       
   134     }
       
   135     return ret;
       
   136 }
       
   137 
       
   138 QList<TUid> CntTransformThumbnail::supportedSortingFieldTypes(QString /*detailFieldName*/) const
       
   139 {
       
   140     // Sorting not supported
       
   141     return QList<TUid>();
       
   142 }
       
   143 
       
   144 
       
   145 /*!
       
   146  * Checks whether the subtype is supported
       
   147  *
       
   148  * \a subType The subtype to be checked
       
   149  * \return True if this subtype is supported
       
   150  */
       
   151 bool CntTransformThumbnail::supportsSubType(const QString& /*subType*/) const
       
   152 {
       
   153     // XXX todo
       
   154     return false;
       
   155 }
       
   156 
       
   157 /*!
       
   158  * Returns the filed id corresponding to a field
       
   159  *
       
   160  * \a fieldName The name of the supported field
       
   161  * \return fieldId for the fieldName, 0  if not supported
       
   162  */
       
   163 quint32 CntTransformThumbnail::getIdForField(const QString& /*fieldName*/) const
       
   164 {
       
   165     // XXX todo
       
   166     return 0;
       
   167 }
       
   168 
       
   169 /*!
       
   170  * Modifies the detail definitions. The default detail definitions are
       
   171  * queried from QContactManagerEngine::schemaDefinitions and then modified
       
   172  * with this function in the transform leaf classes.
       
   173  *
       
   174  * \a definitions The detail definitions to modify.
       
   175  * \a contactType The contact type the definitions apply for.
       
   176  */
       
   177 void CntTransformThumbnail::detailDefinitions(QMap<QString, QContactDetailDefinition> &definitions, const QString& contactType) const
       
   178 {
       
   179     Q_UNUSED(contactType);
       
   180     Q_UNUSED(definitions);
       
   181     // Don't need to munge the definition
       
   182 }