contentstorage/caclient/s60/src/camenuiconutility.cpp
changeset 124 e36b2f4799c0
parent 121 0b3699f6c654
equal deleted inserted replaced
121:0b3699f6c654 124:e36b2f4799c0
    26 #include <apaid.h>
    26 #include <apaid.h>
    27 #endif
    27 #endif
    28 // cfbsbitmap
    28 // cfbsbitmap
    29 #include <apgicnfl.h>
    29 #include <apgicnfl.h>
    30 
    30 
       
    31 #include <rsatsession.h>
       
    32 #include <tsaticoninfo.h>
       
    33 #include <rsatservice.h>// MCL
       
    34 
       
    35 #include <e32property.h>
       
    36 #include <bitdev.h>
       
    37 
       
    38 #include <AknIconUtils.h>
       
    39 
       
    40 
    31 #include <HbIcon>
    41 #include <HbIcon>
    32 
    42 
       
    43 #include "ca2internalCRkeys.h"
    33 #include "camenuiconutility.h"
    44 #include "camenuiconutility.h"
    34 #include "cabitmapadapter.h"
       
    35 #include "caentry.h"
    45 #include "caentry.h"
    36 #include "caquery.h"
    46 #include "caquery.h"
    37 #include "caservice.h"
    47 #include "caservice.h"
    38 #include "cadef.h"
    48 #include "cadef.h"
    39 
    49 
    40 const char appUidAttributeName[] = "application:uid";
    50 const char appUidAttributeName[] = "application:uid";
    41 
    51 
       
    52 LOCAL_C void getIconFromFile(HbIcon& icon, const QSizeF &size)
       
    53 {
       
    54     if ((icon.iconName().contains(QChar('.')) ||
       
    55         (icon.iconName().contains(QChar('/'))) ||
       
    56         (icon.iconName().contains(QChar('\\'))) )
       
    57         && !icon.isNull() && icon.size().isValid()) {
       
    58         icon.setSize(size);
       
    59         icon = HbIcon(QIcon(icon.pixmap()));
       
    60     }    
       
    61 }
       
    62 
       
    63 /*!
       
    64  Convert from bitmap and mask to qpixmap
       
    65  \param input bitmap.
       
    66  \param pixmap to prepare.
       
    67  \retval void.
       
    68  */
       
    69 LOCAL_C void fromBitmapAndMaskToPixmap(CFbsBitmap* fbsBitmap,
       
    70         CFbsBitmap* fbsMask, QPixmap& pixmap)
       
    71 {
       
    72     pixmap = pixmap.fromSymbianCFbsBitmap(fbsBitmap);
       
    73     QPixmap mask;
       
    74     mask = mask.fromSymbianCFbsBitmap(fbsMask);
       
    75     pixmap.setAlphaChannel(mask);
       
    76 }
       
    77 
    42 /*!
    78 /*!
    43  Get icon from entry.
    79  Get icon from entry.
    44  \param entry const reference to CaEntry.
    80  \param entry const reference to CaEntry.
    45  \retval icon.
    81  \retval icon.
    46  */
    82  */
    48 {
    84 {
    49     HbIcon icon;
    85     HbIcon icon;
    50     QString skinId(entry.iconDescription().skinId());
    86     QString skinId(entry.iconDescription().skinId());
    51     if (!skinId.isEmpty()) {
    87     if (!skinId.isEmpty()) {
    52         icon = HbIcon(skinId);
    88         icon = HbIcon(skinId);
       
    89         getIconFromFile(icon, size);
    53     }
    90     }
    54     
    91     
    55     if (icon.isNull() || !(icon.size().isValid())) {
    92     if (icon.isNull() || !(icon.size().isValid())) {
    56         QString fileName(entry.iconDescription().filename());
    93         QString fileName(entry.iconDescription().filename());
    57         if (!fileName.isEmpty()) {
    94         if (!fileName.isEmpty()) {
    58             icon = HbIcon(fileName);
    95             icon = HbIcon(fileName);
    59             if (fileName.contains(QChar('.'))
    96             getIconFromFile(icon, size);
    60                     && !icon.isNull() && icon.size().isValid()) {
       
    61                 icon.setSize(size);
       
    62                 icon = HbIcon(QIcon(icon.pixmap()));
       
    63             }
       
    64         }
    97         }
    65     }
    98     }
    66     return icon;
    99     return icon;
    67 }
   100 }
    68 
   101 
   103         TInt iconsCount(0);
   136         TInt iconsCount(0);
   104         apaLsSession.NumberOfOwnDefinedIcons(uid, iconsCount);
   137         apaLsSession.NumberOfOwnDefinedIcons(uid, iconsCount);
   105         
   138         
   106         QPixmap pixmap;
   139         QPixmap pixmap;
   107         if ((err == KErrNone) && (iconsCount > 0)) {
   140         if ((err == KErrNone) && (iconsCount > 0)) {
   108             CaBitmapAdapter::fromBitmapAndMaskToPixmapL(apaMaskedBitmap,
   141             fromBitmapAndMaskToPixmap(apaMaskedBitmap,
   109                     apaMaskedBitmap->Mask(), pixmap);
   142                     apaMaskedBitmap->Mask(), pixmap);
   110     
   143     
   111             pixmap = pixmap.scaled(size.toSize(), 
   144             pixmap = pixmap.scaled(size.toSize(), 
   112                 Qt::KeepAspectRatioByExpanding);
   145                 Qt::KeepAspectRatioByExpanding);
   113             icon = HbIcon(QIcon(pixmap));
   146             icon = HbIcon(QIcon(pixmap));
   213     entry = getEntryByUid(uid);
   246     entry = getEntryByUid(uid);
   214     icon = getEntryIcon(entry, size);
   247     icon = getEntryIcon(entry, size);
   215     return icon;
   248     return icon;
   216 }
   249 }
   217 
   250 
       
   251 
       
   252 #ifdef COVERAGE_MEASUREMENT
       
   253 #pragma CTC SKIP
       
   254 #endif //COVERAGE_MEASUREMENT (Icon can be created only from SIM)
       
   255 /*!
       
   256  Get bitmap.
       
   257  \param aIconEF icon information array
       
   258  \retval bitmap.
       
   259  */
       
   260 LOCAL_C CFbsBitmap* getSatBitmapL()
       
   261     {
       
   262     RSatSession satSession;
       
   263     CleanupClosePushL(satSession);
       
   264     RSatService satIcon;
       
   265     CleanupClosePushL(satIcon);
       
   266 
       
   267     satSession.ConnectL();
       
   268     satIcon.OpenL(satSession);
       
   269 
       
   270     
       
   271     TInt iconId(KErrNone);
       
   272     RProperty::Get(KCRUidCa, KCaSatUIIconId, iconId);
       
   273     
       
   274     CFbsBitmap* bitmap(NULL);
       
   275 
       
   276     if (iconId != KErrNone) {
       
   277         RIconEf iconEf;
       
   278         satIcon.GetIconInfoL(TUint8(iconId), iconEf);
       
   279         CleanupClosePushL(iconEf);
       
   280 
       
   281         TInt selectedIconIndex(KErrNotFound);
       
   282         TSize selectedIconSize(0, 0);
       
   283         
       
   284         for (TInt i = 0; i < iconEf.Count(); ++i) {
       
   285             if ((iconEf[i].IconSize().iHeight * iconEf[i].IconSize().iWidth)
       
   286                 >= (selectedIconSize.iHeight * selectedIconSize.iWidth))
       
   287                 if (bitmap) {
       
   288                     delete bitmap;
       
   289                     bitmap = NULL;
       
   290                 }
       
   291             // test and select index of icon which is not too big
       
   292             bitmap = satIcon.GetIconL( iconEf[ i ] );
       
   293             if (bitmap) //!bitmap if iIcon is too big
       
   294             {
       
   295                 selectedIconSize = iconEf[i].IconSize();
       
   296                 selectedIconIndex = i;
       
   297             }
       
   298         }
       
   299         if (selectedIconIndex != KErrNotFound) {
       
   300             if (bitmap) {
       
   301                 delete bitmap;
       
   302                 bitmap = NULL;
       
   303             }
       
   304             bitmap = satIcon.GetIconL( iconEf[ selectedIconIndex ] );
       
   305         }
       
   306         CleanupStack::PopAndDestroy(&iconEf);
       
   307     }
       
   308     
       
   309     CleanupStack::PopAndDestroy(&satIcon);
       
   310     CleanupStack::PopAndDestroy(&satSession);
       
   311     
       
   312     return bitmap;
       
   313 }
       
   314 #ifdef COVERAGE_MEASUREMENT
       
   315 #pragma CTC ENDSKIP
       
   316 #endif //COVERAGE_MEASUREMENT
       
   317 
       
   318 
       
   319 
       
   320 #ifdef COVERAGE_MEASUREMENT
       
   321 #pragma CTC SKIP
       
   322 #endif //COVERAGE_MEASUREMENT (Icon can be created only from SIM)
       
   323 /*!
       
   324  Get bitmap.
       
   325  \param aIconEF icon information array
       
   326  \retval bitmap.
       
   327  */
       
   328 LOCAL_C CFbsBitmap* getSatMaskL(CFbsBitmap* aBitmap)
       
   329     {
       
   330     CFbsBitmap* mask(new (ELeave) CFbsBitmap);
       
   331     CleanupStack::PushL(mask);
       
   332 
       
   333     User::LeaveIfError(mask->Create(aBitmap->SizeInPixels(), EGray256));
       
   334 
       
   335     CFbsBitmapDevice* maskDevice = CFbsBitmapDevice::NewL(mask);
       
   336     CleanupStack::PushL(maskDevice);
       
   337     CFbsBitGc* maskGc;
       
   338     User::LeaveIfError(maskDevice->CreateContext(maskGc));
       
   339     CleanupStack::PushL(maskGc);
       
   340     maskGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   341     maskGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   342     maskGc->SetBrushColor(KRgbBlack);
       
   343     maskGc->Clear();
       
   344     maskGc->SetBrushColor(KRgbWhite);
       
   345     maskGc->DrawRect(TRect(TPoint(), aBitmap->SizeInPixels()));
       
   346     CleanupStack::PopAndDestroy(maskGc);
       
   347     CleanupStack::PopAndDestroy(maskDevice);
       
   348     CleanupStack::Pop(mask);
       
   349     return mask;
       
   350 }
       
   351 #ifdef COVERAGE_MEASUREMENT
       
   352 #pragma CTC ENDSKIP
       
   353 #endif //COVERAGE_MEASUREMENT
       
   354 
       
   355 
       
   356 #ifdef COVERAGE_MEASUREMENT
       
   357 #pragma CTC SKIP
       
   358 #endif //COVERAGE_MEASUREMENT (Icon can be created only from SIM)
       
   359 /*!
       
   360  Get icon from entry.
       
   361  \param entry const reference to CaEntry.
       
   362  \retval icon.
       
   363  */
       
   364 LOCAL_C HbIcon getSatIconL()
       
   365 {
       
   366     HbIcon icon;
       
   367     QPixmap pixmap;
       
   368     CFbsBitmap* bitmap(NULL);
       
   369     CFbsBitmap* mask(NULL);
       
   370     bitmap = getSatBitmapL();
       
   371     if(bitmap)
       
   372     {
       
   373         mask = getSatMaskL(bitmap);
       
   374         fromBitmapAndMaskToPixmap(bitmap, mask, pixmap);
       
   375         icon = HbIcon(QIcon(pixmap));
       
   376     }
       
   377    
       
   378 
       
   379     delete mask;
       
   380     delete bitmap;
       
   381     return icon;
       
   382 
       
   383 }
       
   384 #ifdef COVERAGE_MEASUREMENT
       
   385 #pragma CTC ENDSKIP
       
   386 #endif //COVERAGE_MEASUREMENT
       
   387 
       
   388 
   218 /*!
   389 /*!
   219  Get icon.
   390  Get icon.
   220  \param entry const reference to CaEntry.
   391  \param entry const reference to CaEntry.
   221  \param sie const reference to icon size.
   392  \param sie const reference to icon size.
   222  \retval icon.
   393  \retval icon.
   223  */
   394  */
   224 HbIcon CaMenuIconUtility::getEntryIcon(const CaEntry& entry,
   395 HbIcon CaMenuIconUtility::getEntryIcon(const CaEntry& entry, const QSizeF &size)
   225         const QSizeF &size)
   396 {
   226 {
   397     HbIcon icon;
   227     HbIcon icon;
   398 
   228     icon = getIconFromEntry(entry, size);
   399     icon = getIconFromEntry(entry, size);
   229  
   400     
       
   401     if ((icon.isNull() || !(icon.size().isValid())) &&
       
   402         entry.attribute(appUidAttributeName).toInt() == KSatUid.iUid) {
       
   403         TRAP_IGNORE(icon = getSatIconL());
       
   404     }
       
   405     
   230     if (icon.isNull() || !(icon.size().isValid())) {
   406     if (icon.isNull() || !(icon.size().isValid())) {
   231         QString uidString(entry.attribute(appUidAttributeName));
   407         QString uidString(entry.attribute(appUidAttributeName));
   232         bool uidOk(false);
   408         bool uidOk(false);
   233         int uidValue = uidString.toInt(&uidOk);
   409         int uidValue = uidString.toInt(&uidOk);
   234         if (!uidOk) {
   410         if (!uidOk) {
   237         }
   413         }
   238         if (uidOk) {
   414         if (uidOk) {
   239             TRAP_IGNORE(icon = getIconFromApparcL(uidValue, size));
   415             TRAP_IGNORE(icon = getIconFromApparcL(uidValue, size));
   240         }
   416         }
   241     }
   417     }
   242  
   418 
   243     if (icon.isNull() || !(icon.size().isValid())) {
   419     if (icon.isNull() || !(icon.size().isValid())) {
   244         icon = getDefaultIcon(entry);
   420         icon = getDefaultIcon(entry);
   245     }
   421     }
   246  
   422 
   247     if (entry.entryTypeName() == XQConversions::s60DescToQString(
   423     if (entry.entryTypeName() == XQConversions::s60DescToQString(
   248             KCaTypeWidget)) {
   424         KCaTypeWidget)) {
   249         icon.addProportionalBadge(Qt::AlignBottom | Qt::AlignRight,
   425         icon.addProportionalBadge(Qt::AlignBottom | Qt::AlignRight,
   250 		    HbIcon("qtg_small_homescreen"), QSizeF(0.5, 0.5));
   426             HbIcon("qtg_small_homescreen"), QSizeF(0.5, 0.5));
   251     }
   427     }
   252     return icon;
   428     return icon;
   253 }
   429 }
   254 
   430 
       
   431 
       
   432