contentstorage/caclient/s60/src/camenuiconutility.cpp
changeset 66 32469d7d46ff
child 73 4bc7b118b3df
equal deleted inserted replaced
61:8e5041d13c84 66:32469d7d46ff
       
     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 // conversion
       
    19 #include <XQConversions>
       
    20 // apparc
       
    21 #include <apparc.h>
       
    22 #include <APGCLI.H>
       
    23 // cfbsbitmap
       
    24 #include <APGICNFL.H>
       
    25 
       
    26 #include <HbIcon>
       
    27 #include "camenuiconutility.h"
       
    28 #include "camenuiconmifutility.h"
       
    29 #include "cabitmapadapter.h"
       
    30 #include "caentry.h"
       
    31 #include "caquery.h"
       
    32 #include "caservice.h"
       
    33 #include "cadef.h"
       
    34 
       
    35 const QString appUidAttributeName("application:uid");
       
    36 
       
    37 /*!
       
    38  Get icon from entry.
       
    39  \param entry const reference to CaEntry.
       
    40  \retval icon.
       
    41  */
       
    42 LOCAL_C HbIcon getIconFromEntry(const CaEntry& entry)
       
    43 {
       
    44     HbIcon icon;
       
    45     QString skinId(entry.iconDescription().skinId());
       
    46     if (!skinId.isEmpty()) {
       
    47         icon = HbIcon(skinId);
       
    48     }
       
    49     
       
    50     if (icon.isNull() || !(icon.size().isValid())) {
       
    51         QString fileName(entry.iconDescription().filename());
       
    52         if (!fileName.isEmpty()) {
       
    53         
       
    54             // TODO:
       
    55             // work-around for HbIcon::size() method locking files if returns 
       
    56             // default size, error id: ou1cimx1#279208 Case: mcl06HsDo07 - 
       
    57             // "Cannot delete file" when trying to uninstall sisx file
       
    58             
       
    59             if (entry.entryTypeName() == XQConversions::s60DescToQString(
       
    60                     KCaTypeWidget)) {
       
    61                 icon = QIcon(fileName);
       
    62                 qWarning("Widget icon created by QIcon, "
       
    63                         "as work-around for HbIcon::size");
       
    64             } else {
       
    65                 icon = HbIcon(fileName);
       
    66             }
       
    67         }
       
    68     }
       
    69     return icon;
       
    70 }
       
    71 
       
    72 /*!
       
    73  Get icon from apparc.
       
    74  \param entry const reference to CaEntry.
       
    75  \param sie const reference to icon size.
       
    76  \retval icon.
       
    77  */
       
    78 LOCAL_C HbIcon getIconFromApparcL(const CaEntry& entry, const QSize &size)
       
    79 {
       
    80     HbIcon icon;
       
    81     
       
    82     RApaLsSession apaLsSession;
       
    83     CleanupClosePushL(apaLsSession);
       
    84     User::LeaveIfError(apaLsSession.Connect());
       
    85 
       
    86     QString uidString(entry.attribute(appUidAttributeName));
       
    87     TUid uid;
       
    88     uid = uid.Uid(uidString.toInt());
       
    89     
       
    90     CApaAppServiceInfoArray* skinArray(NULL);
       
    91     TRAPD( err, skinArray = apaLsSession.GetAppServiceOpaqueDataLC(uid, TUid::Uid(0x2002DCF3));
       
    92     if (err == KErrNone && skinArray ) {
       
    93         TArray<TApaAppServiceInfo> tmpArray( skinArray->Array() );
       
    94         if ( tmpArray.Count() ) {
       
    95             TPtrC8 opaque(tmpArray[0].OpaqueData());
       
    96             const TPtrC16 iconName((TText16*) opaque.Ptr(),(opaque.Length()+1)>>1);
       
    97             icon = HbIcon( XQConversions:: s60DescToQString( iconName ) );
       
    98         } 
       
    99     }
       
   100     CleanupStack::PopAndDestroy(skinArray);
       
   101     );
       
   102     
       
   103     if (icon.isNull() || !(icon.size().isValid())) {
       
   104         TSize iconSize(size.width(), size.height());
       
   105         CApaMaskedBitmap* apaMaskedBitmap = CApaMaskedBitmap::NewLC();
       
   106         TInt err = apaLsSession.GetAppIcon(uid,iconSize,*apaMaskedBitmap);
       
   107         
       
   108         TInt iconsCount(0);
       
   109         apaLsSession.NumberOfOwnDefinedIcons(uid, iconsCount);
       
   110         
       
   111         QPixmap pixmap;
       
   112         if ((err == KErrNone) && (iconsCount > 0)) {
       
   113             CaBitmapAdapter::fromBitmapAndMaskToPixmapL(apaMaskedBitmap,
       
   114                     apaMaskedBitmap->Mask(), pixmap);
       
   115     
       
   116             pixmap = pixmap.scaled(size, Qt::KeepAspectRatioByExpanding);
       
   117             icon = HbIcon(QIcon(pixmap));
       
   118         } else {
       
   119             HBufC* fileNameFromApparc;
       
   120             TInt err2 = apaLsSession.GetAppIcon(uid,fileNameFromApparc);
       
   121             CleanupStack::PushL(fileNameFromApparc);
       
   122             if (err2 == KErrNone) {
       
   123                 QString fileName = XQConversions::s60DescToQString(
       
   124                         fileNameFromApparc->Des());
       
   125                 if (fileName.contains(QString(".mif"))) {
       
   126                     
       
   127                     TPtr ptr(fileNameFromApparc->Des());
       
   128                     CaMenuIconMifUtility::GetPixmapByFilenameL(ptr,size,pixmap);
       
   129         
       
   130                     pixmap = pixmap.scaled(size, Qt::KeepAspectRatioByExpanding);
       
   131                     icon = HbIcon(QIcon(pixmap));
       
   132                 }
       
   133             }
       
   134             CleanupStack::Pop(fileNameFromApparc);
       
   135         }
       
   136         
       
   137         CleanupStack::PopAndDestroy(apaMaskedBitmap);
       
   138     }
       
   139     CleanupStack::PopAndDestroy(&apaLsSession);
       
   140     
       
   141     return icon;
       
   142 }
       
   143 
       
   144 /*!
       
   145  Get default icon from theme.
       
   146  \param entry const reference to CaEntry.
       
   147  \retval icon.
       
   148  */
       
   149 LOCAL_C HbIcon getDefaultIcon(const CaEntry& entry)
       
   150 {
       
   151     HbIcon icon;
       
   152     
       
   153     if (entry.entryTypeName() == 
       
   154             XQConversions::s60DescToQString(KCaTypeApp)) {
       
   155         icon = HbIcon("qtg_large_application");
       
   156     } else if (entry.entryTypeName() ==
       
   157             XQConversions::s60DescToQString(KCaTypeFolder) ||
       
   158             entry.entryTypeName() == 
       
   159             XQConversions::s60DescToQString(KCaTypeCollection) ||
       
   160             entry.entryTypeName() == 
       
   161             XQConversions::s60DescToQString(KCaTypeCollectionDownload)) {
       
   162         icon = HbIcon("qtg_large_application");
       
   163     } else if (entry.entryTypeName() ==
       
   164         XQConversions::s60DescToQString(KCaTypeUrl)) {
       
   165         icon = HbIcon("qtg_large_application");
       
   166     } else if (entry.entryTypeName() ==
       
   167         XQConversions::s60DescToQString(KCaTypeWidget)) {
       
   168         icon = HbIcon("qtg_large_application");
       
   169     } else if (entry.entryTypeName() ==
       
   170         XQConversions::s60DescToQString(KCaTypeTemplatedApp)) {
       
   171         icon = HbIcon("qtg_large_application");
       
   172     } else if (entry.entryTypeName() ==
       
   173         XQConversions::s60DescToQString(KCaTypePackage)) {
       
   174         icon = HbIcon("qtg_large_application");
       
   175     }
       
   176     
       
   177     return icon;
       
   178 }
       
   179 
       
   180 /*!
       
   181  Get entry by uid.
       
   182  \param uid application uid.
       
   183  \retval entry.
       
   184  */
       
   185 LOCAL_C CaEntry getEntryByUid(int uid)
       
   186 {
       
   187     CaEntry entry;
       
   188     CaQuery query;
       
   189     query.setAttribute(QString("application:uid"), QString::number(uid));
       
   190     QList< QSharedPointer<CaEntry> > entries = CaService::instance()->getEntries(query);
       
   191     if (!entries.isEmpty()) {
       
   192         entry = *(entries.first());
       
   193     }
       
   194     return entry;
       
   195 }
       
   196 
       
   197 /*!
       
   198  Get icon when uid is defined.
       
   199  \param entry const reference to CaEntry.
       
   200  \param sie const reference to icon size.
       
   201  \retval icon.
       
   202  */
       
   203 HbIcon CaMenuIconUtility::getApplicationIcon(int uid,
       
   204         const QSize &size)
       
   205 {
       
   206     HbIcon icon;
       
   207     CaEntry entry;
       
   208     entry = getEntryByUid(uid);
       
   209     icon = getEntryIcon(entry, size);
       
   210     return icon;
       
   211 }
       
   212 
       
   213 /*!
       
   214  Get icon.
       
   215  \param entry const reference to CaEntry.
       
   216  \param sie const reference to icon size.
       
   217  \retval icon.
       
   218  */
       
   219 HbIcon CaMenuIconUtility::getEntryIcon(const CaEntry& entry,
       
   220         const QSize &size)
       
   221 {
       
   222     HbIcon icon;
       
   223     icon = getIconFromEntry(entry);
       
   224 
       
   225     if (icon.isNull() || !(icon.size().isValid())) {
       
   226         TRAP_IGNORE(icon = getIconFromApparcL(entry, size));
       
   227     }
       
   228 
       
   229     if (icon.isNull() || !(icon.size().isValid())) {
       
   230         icon = getDefaultIcon(entry);
       
   231     }
       
   232     
       
   233     return icon;
       
   234 }
       
   235 
       
   236