javamanager/javainstaller/installer/src.s60/iconconverter/iconconverter.cpp
changeset 50 023eef975703
parent 21 2a9601315dfc
child 57 59b3b4473dc8
equal deleted inserted replaced
49:35baca0e7a2e 50:023eef975703
    18 */
    18 */
    19 
    19 
    20 
    20 
    21 #include <zipfile.h>
    21 #include <zipfile.h>
    22 #include <time.h>
    22 #include <time.h>
       
    23 #include <BitmapTransforms.h>
    23 
    24 
    24 #include "javacommonutils.h"
    25 #include "javacommonutils.h"
    25 #include "logger.h"
    26 #include "logger.h"
    26 #include "mifconverter.h"
    27 #include "mifconverter.h"
    27 #include "iconconverter.h"
    28 #include "iconconverter.h"
       
    29 #include "iconsizeutils.h"      // TIconSizes 
       
    30 #include "iconsizenotifier.h"   // KUidIconSizeNotifPlugin
    28 
    31 
    29 namespace java
    32 namespace java
    30 {
    33 {
    31 
    34 
    32 /**
    35 /**
    33  * The icon in S60 temporary drive
    36  * The icon in S60 temporary drive
    34  */
    37  */
    35 _LIT(KTempIconName, "D:\\micon.mbm");
    38 _LIT(KTempIconName1, "D:\\micon1.mbm");
    36 
    39 _LIT(KTempMaskName1, "D:\\mmask1.mbm");
    37 /**
    40 
    38  * The mask in S60 temporary drive
    41 #ifdef RD_JAVA_S60_RELEASE_9_2
    39  */
    42 _LIT(KTempIconName2, "D:\\micon2.mbm");
    40 _LIT(KTempMaskName, "D:\\mmask.mbm");
    43 _LIT(KTempMaskName2, "D:\\mmask2.mbm");
       
    44 #endif // RD_JAVA_S60_RELEASE_9_2
    41 
    45 
    42 
    46 
    43 // MIF file constants
    47 // MIF file constants
    44 const TInt KMifFileHeaderUid = 0x34232342;
    48 const TInt KMifFileHeaderUid = 0x34232342;
    45 const TInt KMifFileHeaderVersion = 2;
    49 const TInt KMifFileHeaderVersion = 2;
    49 const TInt KMifIconHeaderVersion = 1;
    53 const TInt KMifIconHeaderVersion = 1;
    50 const TInt KMifIconHeaderType = 1;
    54 const TInt KMifIconHeaderType = 1;
    51 const TInt KMifIconHeaderAnimated = 0;
    55 const TInt KMifIconHeaderAnimated = 0;
    52 
    56 
    53 
    57 
    54 
       
    55 CIconConverter* CIconConverter::NewL(RFs& aRFs)
    58 CIconConverter* CIconConverter::NewL(RFs& aRFs)
    56 {
    59 {
    57     return new(ELeave) CIconConverter(aRFs);
    60     return new(ELeave) CIconConverter(aRFs);
    58 }
    61 }
    59 
       
    60 
    62 
    61 CIconConverter::CIconConverter(RFs &aRFs)
    63 CIconConverter::CIconConverter(RFs &aRFs)
    62 {
    64 {
    63     iRFs = aRFs;
    65     iRFs = aRFs;
    64     iImageDecoder = NULL;
    66     iImageDecoder = NULL;
    77 CIconConverter::~CIconConverter()
    79 CIconConverter::~CIconConverter()
    78 {
    80 {
    79     // Do NOT close file server session
    81     // Do NOT close file server session
    80     delete iBitmapMask;
    82     delete iBitmapMask;
    81     delete iBitmap;
    83     delete iBitmap;
       
    84     delete iBitmapMaskScaledCopy;
       
    85     delete iBitmapScaledCopy;
    82     delete iImageDecoder;
    86     delete iImageDecoder;
    83 
    87 
    84     RFbsSession::Disconnect();
    88     RFbsSession::Disconnect();
    85 
    89 
    86     delete iActiveListener;
    90     delete iActiveListener;
   244     iImageDecoder->Convert(&(iActiveListener->iStatus),
   248     iImageDecoder->Convert(&(iActiveListener->iStatus),
   245                            *iBitmap,
   249                            *iBitmap,
   246                            *iBitmapMask);
   250                            *iBitmapMask);
   247 
   251 
   248     CActiveScheduler::Start();
   252     CActiveScheduler::Start();
   249     err = iActiveListener->iStatus.Int();
   253     User::LeaveIfError(iActiveListener->iStatus.Int());
       
   254 
       
   255     // Scale icons
       
   256     TIconSizes sizes(GetIdealIconSizes());
       
   257     CBitmapScaler* scaler = CBitmapScaler::NewL();
       
   258     CleanupStack::PushL(scaler);
       
   259     scaler->SetQualityAlgorithm(CBitmapScaler::EMaximumQuality);
       
   260 
       
   261     // Scale for Menu
       
   262     ILOG2(EJavaInstaller, "Scaling Menu icon to (%d, %d)", 
       
   263         sizes.iMenuIconSize.iWidth, sizes.iMenuIconSize.iHeight);
       
   264     iBitmapScaledCopy = new(ELeave) CFbsBitmap;
       
   265     iBitmapMaskScaledCopy = new(ELeave) CFbsBitmap;
       
   266     ScaleL(*scaler, sizes.iMenuIconSize);
       
   267     User::LeaveIfError(iBitmapScaledCopy->Save(KTempIconName1));
       
   268     User::LeaveIfError(iBitmapMaskScaledCopy->Save(KTempMaskName1));
       
   269     iBitmapScaledCopy->Reset();
       
   270     iBitmapMaskScaledCopy->Reset();
       
   271 
       
   272 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   273     // Scale for App Manager
       
   274     ILOG2(EJavaInstaller, "Scaling App Mgr icon to (%d, %d)", 
       
   275         sizes.iMenuIconSize.iWidth, sizes.iMenuIconSize.iHeight);
       
   276     ScaleL(*scaler, sizes.iAppMgrIconSize);
       
   277     User::LeaveIfError(iBitmapScaledCopy->Save(KTempIconName2));
       
   278     User::LeaveIfError(iBitmapMaskScaledCopy->Save(KTempMaskName2));
       
   279     iBitmapScaledCopy->Reset();
       
   280     iBitmapMaskScaledCopy->Reset();
       
   281 #endif // RD_JAVA_S60_RELEASE_9_2
       
   282 
       
   283     CleanupStack::PopAndDestroy(scaler);
   250     delete iActiveListener;
   284     delete iActiveListener;
   251     iActiveListener = NULL;
   285     iActiveListener = NULL;
   252     if (err != KErrNone)
   286 
   253     {
   287     // Construct multi bitmap file from bitmap and mask files (2 files)
   254         User::Leave(err);
   288 #ifdef RD_JAVA_S60_RELEASE_9_2
   255     }
   289     const TInt KBmpCount = 4;
   256 
   290     TInt32 sourceIds[] = {0, 0, 0, 0};
   257     // store bitmap to two temp files
   291 #else
   258     User::LeaveIfError(iBitmap->Save(KTempIconName));
   292     const TInt KBmpCount = 2;
   259     User::LeaveIfError(iBitmapMask->Save(KTempMaskName));
       
   260 
       
   261     // construct multi bitmap file from bitmap and mask files (2 files)
       
   262     TInt32 sourceIds[] = {0, 0};
   293     TInt32 sourceIds[] = {0, 0};
   263     TFileName** filenames = new(ELeave) TFileName*[2];
   294 #endif // RD_JAVA_S60_RELEASE_9_2
       
   295     
       
   296     TFileName** filenames = new(ELeave) TFileName*[KBmpCount];
   264     CleanupStack::PushL(filenames);
   297     CleanupStack::PushL(filenames);
   265     filenames[0] = new(ELeave) TFileName(KTempIconName);
   298     filenames[0] = new(ELeave) TFileName(KTempIconName1);
   266     CleanupStack::PushL(filenames[0]);
   299     CleanupStack::PushL(filenames[0]);
   267     filenames[1] = new(ELeave) TFileName(KTempMaskName);
   300     filenames[1] = new(ELeave) TFileName(KTempMaskName1);
   268     CleanupStack::PushL(filenames[1]);
   301     CleanupStack::PushL(filenames[1]);
   269 
   302     
   270     CFbsBitmap::StoreL(aOutputFile, 2, (const TDesC**)filenames, sourceIds);
   303 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   304     filenames[2] = new(ELeave) TFileName(KTempIconName2);
       
   305     CleanupStack::PushL(filenames[2]);
       
   306     filenames[3] = new(ELeave) TFileName(KTempMaskName2);
       
   307     CleanupStack::PushL(filenames[3]);
       
   308 #endif // RD_JAVA_S60_RELEASE_9_2
       
   309     
       
   310     CFbsBitmap::StoreL(aOutputFile, KBmpCount, (const TDesC**)filenames, sourceIds);
   271 
   311 
   272     // Now try to delete the temp icon and mask files,
   312     // Now try to delete the temp icon and mask files,
   273     // ignore possible errors
   313     // ignore possible errors
   274     (void)iRFs.Delete(KTempIconName);
   314     (void)iRFs.Delete(KTempIconName1);
   275     (void)iRFs.Delete(KTempMaskName);
   315     (void)iRFs.Delete(KTempMaskName1);
   276 
   316     
       
   317 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   318     (void)iRFs.Delete(KTempIconName2);
       
   319     (void)iRFs.Delete(KTempMaskName2);
       
   320     CleanupStack::PopAndDestroy(filenames[3]);
       
   321     CleanupStack::PopAndDestroy(filenames[2]);
       
   322 #endif // RD_JAVA_S60_RELEASE_9_2
       
   323     
   277     CleanupStack::PopAndDestroy(filenames[1]);
   324     CleanupStack::PopAndDestroy(filenames[1]);
   278     CleanupStack::PopAndDestroy(filenames[0]);
   325     CleanupStack::PopAndDestroy(filenames[0]);
   279     CleanupStack::PopAndDestroy(filenames);
   326     CleanupStack::PopAndDestroy(filenames);
   280     CleanupStack::PopAndDestroy(apIconBuf);
   327     CleanupStack::PopAndDestroy(apIconBuf);
   281 
   328 
   369     }
   416     }
   370 
   417 
   371     mimeTypes.ResetAndDestroy();
   418     mimeTypes.ResetAndDestroy();
   372 }
   419 }
   373 
   420 
       
   421 void CIconConverter::ScaleL(CBitmapScaler& aScaler, const TSize aSize)
       
   422 {
       
   423     ASSERT(iBitmapScaledCopy);
       
   424     ASSERT(iBitmapMaskScaledCopy);
       
   425 
       
   426     User::LeaveIfError(iBitmapScaledCopy->Create(aSize, EColor16M));
       
   427     User::LeaveIfError(iBitmapMaskScaledCopy->Create(aSize, EGray256));
       
   428 
       
   429     iActiveListener->InitialiseActiveListener();
       
   430     aScaler.Scale(&iActiveListener->iStatus, *iBitmap, *iBitmapScaledCopy, ETrue);
       
   431     CActiveScheduler::Start();
       
   432     User::LeaveIfError(iActiveListener->iStatus.Int());
       
   433 
       
   434     iActiveListener->InitialiseActiveListener();
       
   435     aScaler.Scale(&iActiveListener->iStatus, *iBitmapMask, *iBitmapMaskScaledCopy, ETrue);
       
   436     CActiveScheduler::Start();
       
   437     User::LeaveIfError(iActiveListener->iStatus.Int());
       
   438 }
       
   439 
       
   440 TIconSizes CIconConverter::GetIdealIconSizes()
       
   441 {
       
   442     TIconSizes fallbackSizes;
       
   443     fallbackSizes.iMenuIconSize = TSize(KIconInMenuFallbackSize, KIconInMenuFallbackSize);
       
   444     fallbackSizes.iAppMgrIconSize = TSize(KIconInAppMgrFallbackSize, KIconInAppMgrFallbackSize);
       
   445     
       
   446 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   447     RNotifier notifier;
       
   448     TInt err = notifier.Connect();
       
   449     if (KErrNone != err)
       
   450     {
       
   451         ELOG1(EJavaInstaller, "CIconConverter::GetIdealIconSizes #1 err = %d", err);
       
   452         return fallbackSizes;
       
   453     }
       
   454     
       
   455     CleanupClosePushL(notifier);
       
   456 
       
   457     TPckgBuf<TIconSizes> des;
       
   458     iActiveListener->InitialiseActiveListener();
       
   459     notifier.StartNotifierAndGetResponse(iActiveListener->iStatus,
       
   460                                          KUidIconSizeNotifPlugin, des, des);
       
   461     CActiveScheduler::Start();
       
   462     notifier.CancelNotifier(KUidIconSizeNotifPlugin);
       
   463     err = iActiveListener->iStatus.Int();
       
   464     
       
   465     CleanupStack::PopAndDestroy(&notifier);
       
   466     
       
   467     if (KErrNone != err)
       
   468     {
       
   469         ELOG1(EJavaInstaller, "CIconConverter::GetIdealIconSizes #2 err = %d", err);
       
   470         return fallbackSizes;
       
   471     }
       
   472     else
       
   473     {
       
   474         return des();
       
   475     }
       
   476 #else
       
   477     return fallbackSizes;
       
   478 #endif
       
   479 }
       
   480 
   374 } // namespace java
   481 } // namespace java