mulwidgets/common/src/mulutility.cpp
branchRCL_3
changeset 25 4ea6f81c838a
parent 23 514d98f21c43
child 26 0e9bb658ef58
equal deleted inserted replaced
23:514d98f21c43 25:4ea6f81c838a
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Implementation for utility class
       
    15 *
       
    16 */
       
    17 
       
    18 // Includes
       
    19 
       
    20 // Class header
       
    21 #include "mulutility.h"
       
    22 
       
    23 #include "mul/mulmodelutility.h"
       
    24 #include "mulassert.h"
       
    25 #include <osn/ustring.h>
       
    26 #include <f32file.h>
       
    27 #include <eikenv.h>
       
    28 #include <aknappui.h>
       
    29 #include <AknUtils.h>
       
    30 
       
    31 // Local includes
       
    32 #include "mulassert.h"
       
    33 //for logs
       
    34 #include "mullog.h"
       
    35 namespace Alf
       
    36     {
       
    37         
       
    38 //-----------------------------------------------------------------------------
       
    39 // AbsolutePath
       
    40 //-----------------------------------------------------------------------------
       
    41 //
       
    42 OSN_EXPORT bool MulUtility::AbsolutePath(UString& aRelativePath)
       
    43     {
       
    44     MUL_LOG_INFO("aakash::MulUtility::AbsolutePath");
       
    45     bool result = false;
       
    46     aRelativePath.insert(0,"c:");
       
    47     HBufC* relBuffer =NULL;
       
    48         
       
    49     TRAPD(err, relBuffer = HBufC::NewL(aRelativePath.getCharLength()))
       
    50     __MUL_ASSERT(err == KErrNone ,_L("Bad Alloc")); 
       
    51     
       
    52     try
       
    53 	    {  
       
    54 	    TPtr ptr = relBuffer->Des()              ;
       
    55 	    MulModelUtility::ConvertUStringToTDes(aRelativePath,ptr);    
       
    56 			
       
    57 	    if(IsFileExists(*relBuffer))
       
    58 	    	{
       
    59 	    	result = true;
       
    60 	    	}
       
    61 	   	else
       
    62 		   	{		   	
       
    63 		   	aRelativePath.replace(0,"z");
       
    64 		    MulModelUtility::ConvertUStringToTDes(aRelativePath,ptr);    
       
    65 		    if(IsFileExists(*relBuffer))
       
    66 		    	{
       
    67 		    	result = true;
       
    68 		    	}
       
    69 		    else
       
    70 		    	{
       
    71 		    	aRelativePath.erase(0,2);	
       
    72 		    	}		
       
    73 		   	}
       
    74 	   	   	    
       
    75 	    }
       
    76 	catch(...)
       
    77 		{
       
    78 		
       
    79 		}
       
    80 	delete relBuffer;	
       
    81     return result;
       
    82     }
       
    83 
       
    84 //-----------------------------------------------------------------------------
       
    85 // IsLandscape
       
    86 //-----------------------------------------------------------------------------
       
    87 //    
       
    88 OSN_EXPORT  bool MulUtility::IsLandscape()
       
    89 	{
       
    90 	MUL_LOG_INFO("aakash::MulUtility::IsLandscape");
       
    91 	CAknAppUiBase::TAppUiOrientation 
       
    92         orientation = static_cast<CAknAppUi*>((CEikonEnv::Static()->EikAppUi()))->Orientation();
       
    93         
       
    94                             
       
    95 	if (orientation == CAknAppUiBase::EAppUiOrientationLandscape)
       
    96     {
       
    97   	 return true;
       
    98    
       
    99     }
       
   100     
       
   101      else if (orientation == CAknAppUiBase::EAppUiOrientationUnspecified )
       
   102      {
       
   103         AknLayoutUtils::TAknCbaLocation cbaLocation = AknLayoutUtils::CbaLocation();
       
   104         if ( (cbaLocation == AknLayoutUtils::EAknCbaLocationRight) ||
       
   105              (cbaLocation == AknLayoutUtils::EAknCbaLocationLeft) )
       
   106             {
       
   107             //landscape
       
   108             return true;
       
   109             }
       
   110         else
       
   111             {
       
   112             // Portrait
       
   113             return false;
       
   114             }
       
   115     }
       
   116     return false;
       
   117     
       
   118 	}
       
   119 
       
   120 //-----------------------------------------------------------------------------
       
   121 // IsFileExists
       
   122 //-----------------------------------------------------------------------------
       
   123 //  
       
   124 bool MulUtility::IsFileExists(/*const char* afilePath*/const TDesC& aFilePath)
       
   125     {
       
   126     MUL_LOG_INFO("aakash::MulUtility::IsFileExists");
       
   127     bool result(false);
       
   128     
       
   129   	  
       
   130     RFs fSession;
       
   131     TInt fsError = fSession.Connect();    
       
   132     __MUL_ASSERT(fsError == KErrNone,_L("File Session unable to connect"));    
       
   133     
       
   134     RFile chkFile;    
       
   135     TInt errCode = chkFile.Open(fSession,aFilePath,EFileRead);
       
   136     if(KErrPathNotFound != errCode)
       
   137     	{
       
   138     	result = true;	
       
   139     	}    
       
   140     chkFile.Close();	
       
   141     fSession.Close();		
       
   142     return result;        
       
   143     }
       
   144     
       
   145 // ---------------------------------------------------------------------------
       
   146 // IsPoolResource   
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 OSN_EXPORT bool MulUtility::IsPoolResource(const UString& aImageTag)
       
   150     {    
       
   151     TPtrC8 src((TUint8*)aImageTag.getUtf8());
       
   152     _LIT8(KMulTag,"MUL_RP");
       
   153 
       
   154     return ( KErrNotFound != src.FindC(KMulTag));    
       
   155     }
       
   156 //----------------------------------------------------------------------------
       
   157 //IsQwerty
       
   158 //----------------------------------------------------------------------------
       
   159 OSN_EXPORT bool MulUtility::IsQwerty()
       
   160 	{
       
   161 		CKeyBoardUtility* iKBUtility = CKeyBoardUtility::NewL();
       
   162 		if(iKBUtility)
       
   163 		{
       
   164 			return iKBUtility->IsQwerty();
       
   165 		}
       
   166 		return false;
       
   167 	}
       
   168 
       
   169     } // namespace ends
       
   170 
       
   171 // End of file