util/s60pixelmetrics/pm_mapperapp.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    63 #include <stringloader.h>
    63 #include <stringloader.h>
    64 #include <coneresloader.h>
    64 #include <coneresloader.h>
    65 #include <aknglobalnote.h>
    65 #include <aknglobalnote.h>
    66 
    66 
    67 #include <CentralRepository.h>
    67 #include <CentralRepository.h>
    68 #include <AvkonInternalCRKeys.h>    // KAknLayoutId
       
    69 
    68 
    70 #include <Aknsutils.h>
    69 #include <Aknsutils.h>
    71 #include <AknUtils.h>
    70 #include <AknUtils.h>
    72 #include "pixel_metrics.h"
    71 #include "pixel_metrics.h"
    73 
    72 
    87 _LIT(KTab, "\t");
    86 _LIT(KTab, "\t");
    88 _LIT(KEndBraceWithCommaAndCRLF, "},\n");
    87 _LIT(KEndBraceWithCommaAndCRLF, "},\n");
    89 _LIT(KCRLF, "\n");
    88 _LIT(KCRLF, "\n");
    90 
    89 
    91 // Number of header lines in layout data.
    90 // Number of header lines in layout data.
    92 const TInt KHeaderValues = 5;
    91 const TInt KHeaderValues = 4;
    93 
    92 
    94 // ============================ MEMBER FUNCTIONS ===============================
    93 // ============================ MEMBER FUNCTIONS ===============================
    95 
    94 
    96 // -----------------------------------------------------------------------------
    95 // -----------------------------------------------------------------------------
    97 // C++ constructor can NOT contain any code, that
    96 // C++ constructor can NOT contain any code, that
   136 //
   135 //
   137 // -----------------------------------------------------------------------------
   136 // -----------------------------------------------------------------------------
   138 //
   137 //
   139 TKeyResponse CPixelMetricsMapperAppUi::HandleKeyEventL(
   138 TKeyResponse CPixelMetricsMapperAppUi::HandleKeyEventL(
   140         const TKeyEvent& /*aKeyEvent*/,
   139         const TKeyEvent& /*aKeyEvent*/,
   141         TEventCode aType )
   140         TEventCode /*aType*/ )
   142     {
   141     {
   143     return EKeyWasNotConsumed;
   142     return EKeyWasNotConsumed;
   144     }
   143     }
   145 
   144 
   146 // -----------------------------------------------------------------------------
   145 // -----------------------------------------------------------------------------
   154         case EAknSoftkeyExit:
   153         case EAknSoftkeyExit:
   155         case EEikCmdExit:
   154         case EEikCmdExit:
   156             Exit();
   155             Exit();
   157             break;
   156             break;
   158         case ECmdSwitchOutput:
   157         case ECmdSwitchOutput:
       
   158 		    {
       
   159             HBufC* buffer = HBufC::NewLC( 100 );
       
   160             TPtr bufferPtr = buffer->Des();
       
   161             TBool last = ETrue;
       
   162             bufferPtr.Append(_L("Output switched to "));
   159             iFileOutputOn = !iFileOutputOn;
   163             iFileOutputOn = !iFileOutputOn;
       
   164             if (iFileOutputOn)
       
   165                 bufferPtr.Append(_L("file."));
       
   166             else
       
   167                 bufferPtr.Append(_L("screen."));
       
   168             ShowL( *buffer, last );
       
   169 			}
   160             break;
   170             break;
   161         case ECmdStatus:
   171         case ECmdStatus:
   162             {
   172             {
   163             ClearL();
   173             ClearL();
   164 
   174 
   165             // layout
   175             // layout
   166             CRepository* repository = NULL;
       
   167             TInt value = KErrNotFound;
       
   168             TRAPD(ret, repository = CRepository::NewL(KCRUidAvkon));
       
   169             if (ret == KErrNone)
       
   170                 {
       
   171                 ret = repository->Get(KAknLayoutId, value);
       
   172                 }
       
   173             delete repository;
       
   174             ret= 0;
       
   175             HBufC* buffer = HBufC::NewLC( 100 );
   176             HBufC* buffer = HBufC::NewLC( 100 );
   176             TPtr bufferPtr = buffer->Des();
   177             TPtr bufferPtr = buffer->Des();
   177             bufferPtr.Append(_L("Layout: "));
       
   178             if (ret==KErrNone)
       
   179                 {
       
   180                 bufferPtr.AppendNum(value);
       
   181                 }
       
   182             else
       
   183                 {
       
   184                 bufferPtr.Append(_L("(error) "));
       
   185                 bufferPtr.AppendNum(ret);
       
   186                 }
       
   187             TBool last = ETrue;
   178             TBool last = ETrue;
   188             ShowL( *buffer, last );
       
   189             bufferPtr.Zero();
       
   190 
   179 
   191             // Orientation
   180             // Orientation
   192             bufferPtr.Append(_L("Orientation: "));
   181             bufferPtr.Append(_L("Orientation: "));
   193             bufferPtr.AppendNum((TInt)iAvkonAppUi->Orientation());
   182             bufferPtr.AppendNum((TInt)iAvkonAppUi->Orientation());
   194             ShowL( *buffer, last );
   183             ShowL( *buffer, last );
   196 
   185 
   197             // Output
   186             // Output
   198             bufferPtr.Append(_L("Output: "));
   187             bufferPtr.Append(_L("Output: "));
   199             if (iFileOutputOn) bufferPtr.Append(_L("File"));
   188             if (iFileOutputOn) bufferPtr.Append(_L("File"));
   200             else bufferPtr.Append(_L("Screen"));
   189             else bufferPtr.Append(_L("Screen"));
   201             ShowL( *buffer, last );
       
   202             bufferPtr.Zero();
       
   203 
       
   204             // Automode
       
   205             bufferPtr.Append(_L("AutoMode: "));
       
   206             bufferPtr.AppendNum((TInt)iAutoMode);
       
   207             ShowL( *buffer, last );
   190             ShowL( *buffer, last );
   208             bufferPtr.Zero();
   191             bufferPtr.Zero();
   209 
   192 
   210             CAknLayoutConfig::TScreenMode localAppScreenMode = CAknSgcClient::ScreenMode();
   193             CAknLayoutConfig::TScreenMode localAppScreenMode = CAknSgcClient::ScreenMode();
   211             TInt hashValue = localAppScreenMode.ScreenStyleHash();
   194             TInt hashValue = localAppScreenMode.ScreenStyleHash();
   259             ShowL( *buffer, last );
   242             ShowL( *buffer, last );
   260             bufferPtr.Zero();
   243             bufferPtr.Zero();
   261             CleanupStack::PopAndDestroy( buffer );
   244             CleanupStack::PopAndDestroy( buffer );
   262             }
   245             }
   263             break;
   246             break;
   264         case ECmdSwitchMirroring:
       
   265             {
       
   266             // set the shared data value
       
   267             CRepository* repository = NULL;
       
   268             TRAPD(ret, repository = CRepository::NewL(KCRUidAvkon));
       
   269             if (ret == KErrNone)
       
   270                 {
       
   271                 TInt value = KErrNotFound;
       
   272                 repository->Get(KAknLayoutId, value);
       
   273                 if ( value == EAknLayoutIdELAF)
       
   274                     {
       
   275                     value = EAknLayoutIdABRW;
       
   276                     }
       
   277                 else if (value ==EAknLayoutIdABRW)
       
   278                     {
       
   279                     value = EAknLayoutIdELAF;
       
   280                     }
       
   281                 ret = repository->Set(KAknLayoutId, value);
       
   282                 }
       
   283             delete repository;
       
   284             // now inform all open apps of the switch
       
   285             TWsEvent event;
       
   286             event.SetType(KEikDynamicLayoutVariantSwitch);
       
   287             iEikonEnv->WsSession().SendEventToAllWindowGroups(event);
       
   288             }
       
   289             break;
       
   290         case ECmdSwitchOrientation:
   247         case ECmdSwitchOrientation:
   291             {
   248             {
   292             ClearL();
   249             ClearL();
       
   250             HBufC* buffer = HBufC::NewLC( 100 );
       
   251             TPtr bufferPtr = buffer->Des();
       
   252             TBool last = ETrue;
       
   253 
   293             #ifndef __SERIES60_31__
   254             #ifndef __SERIES60_31__
   294             if (!iAvkonAppUi->OrientationCanBeChanged())
   255             if (!iAvkonAppUi->OrientationCanBeChanged())
   295                 {
   256                 {
   296                 HBufC* buffer = HBufC::NewLC( 100 );
       
   297                 TPtr bufferPtr = buffer->Des();
       
   298                 bufferPtr.Append(_L("Orientation cannot be changed."));
   257                 bufferPtr.Append(_L("Orientation cannot be changed."));
   299                 TBool last = EFalse;
       
   300                 ShowL( *buffer, last );
   258                 ShowL( *buffer, last );
   301                 bufferPtr.Zero();
   259                 bufferPtr.Zero();
   302                 delete buffer;
   260                 delete buffer;
       
   261                 break;
   303                 }
   262                 }
   304             #endif //__SERIES60_31__
   263             #endif //__SERIES60_31__
       
   264 
   305             if ( iAvkonAppUi->Orientation() == CAknAppUiBase::EAppUiOrientationPortrait)
   265             if ( iAvkonAppUi->Orientation() == CAknAppUiBase::EAppUiOrientationPortrait)
   306                 {
   266                 {
   307                 iAvkonAppUi->SetOrientationL(CAknAppUiBase::EAppUiOrientationLandscape);
   267                 iAvkonAppUi->SetOrientationL(CAknAppUiBase::EAppUiOrientationLandscape);
   308                 }
   268                 }
   309             else if (iAvkonAppUi->Orientation() == CAknAppUiBase::EAppUiOrientationLandscape)
   269             else if (iAvkonAppUi->Orientation() == CAknAppUiBase::EAppUiOrientationLandscape)
   312                 }
   272                 }
   313             else
   273             else
   314                 {
   274                 {
   315                 // unspecified
   275                 // unspecified
   316                 iAvkonAppUi->SetOrientationL(CAknAppUiBase::EAppUiOrientationLandscape);
   276                 iAvkonAppUi->SetOrientationL(CAknAppUiBase::EAppUiOrientationLandscape);
   317                 /*User::After(100000);
   277                 }
   318                 HBufC* buffer = HBufC::NewLC( 100 );
   278             bufferPtr.Append(_L("Orientation changed."));
   319                 TPtr bufferPtr = buffer->Des();
   279             ShowL( *buffer, last );
   320                 bufferPtr.Append(_L("Orientation unspecified."));
   280             bufferPtr.Zero();
   321                 TBool last = EFalse;
   281             delete buffer;
   322                 ShowL( *buffer, last );
       
   323                 bufferPtr.Zero();
       
   324                 delete buffer;*/
       
   325                 }
       
   326             break;
   282             break;
   327             }
   283             }
   328         case ECmdStartCalculations:
   284         case ECmdStartCalculations:
   329             {
   285             {
   330             ClearL();
   286             ClearL();
   360                 tgt.Zero();
   316                 tgt.Zero();
   361                 tgt.Append(_L("minor_version: \t"));
   317                 tgt.Append(_L("minor_version: \t"));
   362                 tgt.AppendNum(version.minorVersion, EDecimal); // put minor version into text file
   318                 tgt.AppendNum(version.minorVersion, EDecimal); // put minor version into text file
   363                 ShowL( tgt, last );
   319                 ShowL( tgt, last );
   364                 tgt.Zero();
   320                 tgt.Zero();
   365                 // MIRRORED
       
   366                 TBool mirrored = AknLayoutUtils::LayoutMirrored();
       
   367                 tgt.Append(_L("mirrored: \t"));
       
   368                 tgt.AppendNum(mirrored, EDecimal); // put mirrored state into text file
       
   369                 ShowL( tgt, last );
       
   370                 tgt.Zero();
       
   371                 }
   321                 }
   372 
   322 
   373             TInt myValue = KErrNotFound;
   323             TInt myValue = KErrNotFound;
   374             for (;;)
   324             for (;;)
   375                 {
   325                 {
   383                 if (last) break;
   333                 if (last) break;
   384                 // if last before custom values, "jump" to custom base
   334                 // if last before custom values, "jump" to custom base
   385                 if (index==QStyle::PM_SubMenuOverlap) index = QStyle::PM_CustomBase;
   335                 if (index==QStyle::PM_SubMenuOverlap) index = QStyle::PM_CustomBase;
   386                 index++;
   336                 index++;
   387                 }
   337                 }
   388             if (iAutoMode && !iMode)
       
   389                 {
       
   390                 HandleCommandL(ECmdSwitchMirroring);
       
   391                 iMode = ETrue;
       
   392                 }
       
   393             }
   338             }
   394             break;
   339             break;
   395         case ECmdCreateHeaderFile:
   340         case ECmdCreateHeaderFile:
   396             CreateHeaderFileL();
   341             CreateHeaderFileL();
   397             break;
   342             break;
   398         case ECmdSetAutoMode:
       
   399             iAutoMode = !iAutoMode;
       
   400         default:
   343         default:
   401             break;
   344             break;
   402         }
   345         }
   403     }
       
   404 void CPixelMetricsMapperAppUi::DoAutoOperationL()
       
   405     {
       
   406     HandleCommandL(ECmdStartCalculations);
       
   407     iMode = EFalse;
       
   408     HandleCommandL(ECmdSwitchMirroring);
       
   409     }
       
   410 
       
   411 TBool CPixelMetricsMapperAppUi::ReadyForAutoOp() const
       
   412     {
       
   413     return (iAutoMode && iMode);
       
   414     }
   346     }
   415 
   347 
   416 // -----------------------------------------------------------------------------
   348 // -----------------------------------------------------------------------------
   417 //
   349 //
   418 // -----------------------------------------------------------------------------
   350 // -----------------------------------------------------------------------------
   832             TLex lex(oneline);
   764             TLex lex(oneline);
   833             TInt nextValue = -666;
   765             TInt nextValue = -666;
   834             User::LeaveIfError( lex.Val(nextValue) );
   766             User::LeaveIfError( lex.Val(nextValue) );
   835             if ( loop <= KHeaderValues-1)
   767             if ( loop <= KHeaderValues-1)
   836                 {
   768                 {
   837                 if (loop == KHeaderValues -1 ) // true / false values
   769                 bufferLayoutHdr.AppendNum(nextValue);
   838                     {
       
   839                     if (nextValue == 1)
       
   840                         {
       
   841                         bufferLayoutHdr.Append(_L("true"));
       
   842                         }
       
   843                     else
       
   844                         {
       
   845                         bufferLayoutHdr.Append(_L("false"));
       
   846                         }
       
   847                     }
       
   848                 else
       
   849                     {
       
   850                     bufferLayoutHdr.AppendNum(nextValue);
       
   851                     }
       
   852                 }
   770                 }
   853             else
   771             else
   854                 {
   772                 {
   855                 if (nextValue == -909)
   773                 if (nextValue == -909)
   856                     bufferPMData.Append(_L("ECommonStyleValue"));
   774                     bufferPMData.Append(_L("ECommonStyleValue"));
   880 {
   798 {
   881     aFileHandle.Seek(ESeekStart);
   799     aFileHandle.Seek(ESeekStart);
   882     // Layout data is deployed like this:
   800     // Layout data is deployed like this:
   883     // first line - height
   801     // first line - height
   884     // second line - width
   802     // second line - width
   885     // fifth line mirror info
       
   886     TFileName lines;
   803     TFileName lines;
   887     TFileName layoutName;
   804     TFileName layoutName;
   888 
   805 
   889     TInt height = -666;
   806     TInt height = -666;
   890     TInt width = -666;
   807     TInt width = -666;
   891     TInt mirroring = -666;
       
   892     // Collect name information.
   808     // Collect name information.
   893     for (TInt i=0; i<6; i++)
   809     for (TInt i=0; i<6; i++)
   894         {
   810         {
   895         User::LeaveIfError(aFileHandle.Read(lines));
   811         User::LeaveIfError(aFileHandle.Read(lines));
   896         // Remove pixel metrics name and ":"
   812         // Remove pixel metrics name and ":"
   905             }
   821             }
   906         if (i==1) //width is second
   822         if (i==1) //width is second
   907             {
   823             {
   908             error = myLexer.Val(width);
   824             error = myLexer.Val(width);
   909             }
   825             }
   910         if (i==4) //mirror info is fourth
       
   911             {
       
   912             error = myLexer.Val(mirroring);
       
   913             }
       
   914         User::LeaveIfError(error);
   826         User::LeaveIfError(error);
   915         }
   827         }
   916 
   828 
   917     // Interpret results and write name to buffer.
   829     // Interpret results and write name to buffer.
   918     if ( (width == 240 && height == 320) ||
   830     if ( (width == 240 && height == 320) ||
   964         }
   876         }
   965     else
   877     else
   966         {
   878         {
   967         layoutName.Append(_L("Portrait"));
   879         layoutName.Append(_L("Portrait"));
   968         }
   880         }
   969     if (mirroring)
       
   970         {
       
   971         layoutName.Append(_L(" Mirrored"));
       
   972         }
       
   973     return layoutName;
   881     return layoutName;
   974     }
   882     }
   975 
   883 
   976 // -----------------------------------------------------------------------------
   884 // -----------------------------------------------------------------------------
   977 //
   885 //