src/screensaverutility.cpp
changeset 14 8a173132b0aa
parent 2 058b1fc1663a
equal deleted inserted replaced
2:058b1fc1663a 14:8a173132b0aa
     1 /*
       
     2 * Copyright (c) 2004 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:   Defines screensaver utility tools.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <coecntrl.h>
       
    21 #include <akntranseffect.h>
       
    22 #include <data_caging_path_literals.hrh>
       
    23 #include <gulicon.h>
       
    24 
       
    25 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
    26 #include <akntransitionutils.h>
       
    27 #endif
       
    28 
       
    29 #include "screensaverutility.h"
       
    30 #include "screensaverappui.h"
       
    31 #include "ScreensaverUtils.h"
       
    32 
       
    33 
       
    34 // Screensaver window group priority boost (to ensure it's on top)
       
    35 const TInt KSSWinPriorityBoost = 2;
       
    36 
       
    37 _LIT(KSsBitmapName, "\\ssbackground.mbm");
       
    38 _LIT(KSsBitmapUserDrive, "c:");
       
    39 _LIT(KSsBitmapSystemDrive, "z:");
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CScreensaverUtility::Panic( TInt aPanic )
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 void ScreensaverUtility::Panic( TInt aPanic )
       
    46     {
       
    47     User::Panic( _L("Screensaver"),aPanic );
       
    48     }
       
    49 
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CScreensaverUtility::FlushDrawBuffer( TInt aPanic )
       
    53 // Flushes pending draw commands. A "must" before activating power save
       
    54 // mode, so that the image can be copied to power save memory
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void ScreensaverUtility::FlushDrawBuffer()
       
    58     {
       
    59     CCoeEnv::Static()->WsSession().Flush();
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CScreensaverUtility::ScreenRotated( TInt aPanic )
       
    64 // Checks if screen has been rotated
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 TBool ScreensaverUtility::ScreenRotated()
       
    68     {
       
    69     TPixelsAndRotation pxRot;
       
    70     CCoeEnv::Static()->ScreenDevice()->GetDefaultScreenSizeAndRotation(pxRot);
       
    71 
       
    72     // Rotated, if 90 or 270 degrees
       
    73     return ((pxRot.iRotation == CFbsBitGc::EGraphicsOrientationRotated90)
       
    74             || (pxRot.iRotation == CFbsBitGc::EGraphicsOrientationRotated270));
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // ScreensaverUtility::Query12HourClock
       
    79 // Query whether 12-hour clock is displayed
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 TBool ScreensaverUtility::Query12HourClock( )
       
    83     {
       
    84     TLocale locale;
       
    85     return (locale.TimeFormat() == ETime12);
       
    86     }
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // ScreensaverUtility::BringToForeground
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void ScreensaverUtility::BringToForeground()
       
    94     {
       
    95 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
    96     const TInt KSsaCustomActivateContextNum = 1002;
       
    97 
       
    98     GfxTransEffect::BeginFullScreen( KSsaCustomActivateContextNum, TRect( ),
       
    99         AknTransEffect::EParameterType, AknTransEffect::GfxTransParam(
       
   100             KUidScreensaverApp,
       
   101             AknTransEffect::TParameter::EActivateExplicitContinue ) );
       
   102 #endif
       
   103     CEikonEnv::Static()->SetAutoForwarding( ETrue );
       
   104     CEikonEnv::Static()->BringForwards( ETrue, ECoeWinPriorityAlwaysAtFront
       
   105         + KSSWinPriorityBoost );
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // ScreensaverUtility::SendToBackground
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void ScreensaverUtility::SendToBackground()
       
   113     {
       
   114 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
   115 
       
   116     // Start the exit effect context even if this is actually application switch. The exit context
       
   117     // makes possible to map effect by using the *previous* application uid (=Screen Saver).
       
   118     // Note: Not allowed to call GfxTransEffect::EndFullScreen() as AVKON takes care of that when
       
   119     // EApplicationExit context is used! 
       
   120     const TInt KSsaCustomDeactivateContextNum = 1001;
       
   121 
       
   122     //condition takes care of special case of incomeing call (should not have effect then)
       
   123     if ( CAknTransitionUtils::GetData( KScreensaverCallStateChange ) == NULL )
       
   124         {
       
   125         GfxTransEffect::BeginFullScreen( KSsaCustomDeactivateContextNum,
       
   126             TRect( ), AknTransEffect::EParameterType,
       
   127             AknTransEffect::GfxTransParam( KUidScreensaverApp,
       
   128                 AknTransEffect::TParameter::EActivateExplicitContinue ) );
       
   129         }
       
   130 
       
   131     CAknTransitionUtils::RemoveData( KScreensaverCallStateChange );
       
   132 #endif
       
   133 
       
   134     CEikonEnv::Static()->BringForwards( EFalse );
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // ScreensaverUtility::IsDrivePresent
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 TBool ScreensaverUtility::IsDrivePresent(TInt aDrive)
       
   142     {
       
   143     RFs& fs = CCoeEnv::Static()->FsSession();
       
   144 
       
   145     TInt error = KErrNone;
       
   146     TDriveInfo driveInfo;
       
   147     error = fs.Drive(driveInfo, aDrive );
       
   148 
       
   149     // Not present, locked or unknown is bad
       
   150     if ((error != KErrNone) ||
       
   151         (driveInfo.iMediaAtt & KMediaAttLocked) ||
       
   152         (driveInfo.iType == EMediaNotPresent) ||
       
   153         (driveInfo.iType == EMediaUnknown))
       
   154         {
       
   155         return EFalse;
       
   156         }
       
   157 
       
   158     // Read-only is fine
       
   159     return ETrue;
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // ScreensaverUtility::LoadBitmapL
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 CGulIcon* ScreensaverUtility::LoadBitmapL()
       
   167     {
       
   168     CGulIcon *icon = CGulIcon::NewL();
       
   169     CleanupStack::PushL( icon );
       
   170     icon->SetBitmap(new (ELeave) CFbsBitmap());
       
   171     CFbsBitmap* mask = new (ELeave) CFbsBitmap();
       
   172 
       
   173     // First try user path and then system path.
       
   174     TInt error;
       
   175     TFileName path;
       
   176     path.Copy(KSsBitmapUserDrive);
       
   177     path.Append(KDC_APP_BITMAP_DIR);
       
   178     path.Append(KSsBitmapName);
       
   179 
       
   180     for (TInt i = 0; i < 2; i++)
       
   181         {
       
   182         error = icon->Bitmap()->Load(path, 0);
       
   183         if (error == KErrNone)
       
   184             {
       
   185             error = mask->Load(path, 1);
       
   186             if (error != KErrNone)
       
   187                 {
       
   188                 delete mask;
       
   189                 }
       
   190             else
       
   191                 {
       
   192                 icon->SetMask( mask );
       
   193                 }
       
   194             CleanupStack::Pop(); // icon
       
   195             return icon;
       
   196             }
       
   197             path.Copy(KSsBitmapSystemDrive);
       
   198             path.Append(KDC_APP_BITMAP_DIR);
       
   199             path.Append(KSsBitmapName);
       
   200         }
       
   201 
       
   202     CleanupStack::PopAndDestroy(); // icon
       
   203     return NULL;
       
   204     }
       
   205 
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // ScreensaverUtility::StopWServHeartBeat
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void ScreensaverUtility::StopWServHeartBeat()
       
   212     {
       
   213     SCRLOGGER_WRITE("Model: Stopping WServ HB, snoozing...");
       
   214     RWsSession ws;
       
   215     TInt err = ws.Connect( );
       
   216     if ( !err )
       
   217         {
       
   218         ws.PrepareForSwitchOff( );
       
   219         ws.Close( );
       
   220         }
       
   221     }
       
   222 
       
   223 // End of file