landmarksui/uicontrols/src/CLmkUiUtils.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2002 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:    LandmarksUi Content File -
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 // Added for testing
       
    22 #include <eikcapc.h>
       
    23 #include <eikimage.h>
       
    24 #include <data_caging_path_literals.hrh>
       
    25 #include <bautils.h>
       
    26 #include <akntitle.h>
       
    27 #include <StringLoader.h>
       
    28 #include <akncontext.h>
       
    29 #include <aknappui.h>
       
    30 #include <AknIconUtils.h>
       
    31 #include <EPos_CPosLandmark.h>
       
    32 #include <lmkerrors.h>
       
    33 
       
    34 #include "CLmkUiUtils.h"
       
    35 #include "MLmkEditorUiBuilder.h"
       
    36 #include "MLmkFieldData.h"
       
    37 #include "CLmkFieldData.h"
       
    38 #include "CLmkFields.h"
       
    39 #include "LmkConsts.h"
       
    40 #include "landmarks.hrh"
       
    41 
       
    42 // CONSTANTS
       
    43 /// Unnamed namespace for local definitions
       
    44 namespace {
       
    45     const TInt KPosUrlColon (3);
       
    46  
       
    47     _LIT( KPanicMsg, "CLmkUiUtils" );
       
    48 
       
    49     void Panic( TPanicCode aReason )
       
    50         {
       
    51         User::Panic( KPanicMsg, aReason );
       
    52         } 
       
    53     } // namespace
       
    54 
       
    55 //============================ MEMBER FUNCTIONS ===============================
       
    56 //----------------------------------------------------------------------------
       
    57 // CLmkUiUtils::NewL
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 CLmkUiUtils* CLmkUiUtils::NewL()
       
    61     {
       
    62     CLmkUiUtils* self = new( ELeave ) CLmkUiUtils();
       
    63     CleanupStack::PushL( self );
       
    64     self->ConstructL();
       
    65     CleanupStack::Pop(); //self
       
    66     return self;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CLmkUiUtils::CLmkUiUtils
       
    71 // C++ default constructor can NOT contain any code, that
       
    72 // might leave.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CLmkUiUtils::CLmkUiUtils()
       
    76     {
       
    77     }
       
    78 
       
    79 // ----------------------------------------------------------------------------
       
    80 // CLmkUiUtils::ConstructL
       
    81 // ----------------------------------------------------------------------------
       
    82 //
       
    83 void CLmkUiUtils::ConstructL()
       
    84     {
       
    85     iNaviPane = static_cast<CAknNavigationControlContainer*>(
       
    86             StatusPane()->ControlL( TUid::Uid(EEikStatusPaneUidNavi) ) );
       
    87 
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CLmkUiUtils::~CLmkUiUtils()
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 CLmkUiUtils::~CLmkUiUtils()
       
    95     {
       
    96     CEikonEnv* env = CEikonEnv::Static();
       
    97     env->DeleteResourceFile( iResourceOffset );
       
    98 
       
    99     if ( iNaviLabel )
       
   100         {
       
   101         if (iNaviPane)
       
   102 	        {
       
   103 	        iNaviPane->Pop( iNaviLabel );
       
   104 	        }
       
   105         delete iNaviLabel;     
       
   106         iNaviLabel = NULL;
       
   107         } 
       
   108     
       
   109     delete iOldImage;
       
   110     delete iStoredTitlePaneText;
       
   111 
       
   112     //If RestoreOldNaviPaneL is not called, it
       
   113     //must do atleast now
       
   114     if ( iStoredDecorator )
       
   115         {
       
   116         TRAPD( error, RestoreOldNaviPaneL() );
       
   117         if ( error != KErrNone )
       
   118             {
       
   119             env->HandleError( error );
       
   120             }
       
   121         }
       
   122     delete iStoredDecorator;
       
   123     }
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // CLmkUiUtils::StoreTitlePaneL
       
   127 // ----------------------------------------------------------------------------
       
   128 //
       
   129 void CLmkUiUtils::StoreTitlePaneL()
       
   130 	{
       
   131     CEikStatusPane* statusPane = StatusPane();
       
   132     if ( statusPane && statusPane->PaneCapabilities(
       
   133         TUid::Uid(EEikStatusPaneUidTitle) ).IsPresent() )
       
   134         {
       
   135         iTitlePane = static_cast<CAknTitlePane*>( statusPane->
       
   136                             ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   137 
       
   138         if ( iTitlePane->Text() )
       
   139             {
       
   140             iStoredTitlePaneText = iTitlePane->Text()->AllocL();
       
   141             }
       
   142         }
       
   143 	}
       
   144 
       
   145 // ----------------------------------------------------------------------------
       
   146 // CLmkUiUtils::ChangeTitlePaneL
       
   147 // ----------------------------------------------------------------------------
       
   148 //
       
   149 EXPORT_C void CLmkUiUtils::ChangeTitlePaneL( HBufC* aTitle )
       
   150 	{
       
   151     CEikStatusPane* statusPane = StatusPane();
       
   152     if ( statusPane && statusPane->PaneCapabilities(
       
   153         TUid::Uid(EEikStatusPaneUidTitle) ).IsPresent() )
       
   154         {
       
   155         CAknTitlePane* titlePane = static_cast<CAknTitlePane*>( statusPane->
       
   156                             ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   157         titlePane->SetText( aTitle ); // Takes ownership of aTitle
       
   158         }
       
   159 	}
       
   160 
       
   161 // ----------------------------------------------------------------------------
       
   162 // CLmkUiUtils::ChangeTitlePaneL
       
   163 // ----------------------------------------------------------------------------
       
   164 //
       
   165 EXPORT_C void CLmkUiUtils::ChangeTitlePaneL( TInt aResourceText )
       
   166     {
       
   167     if ( aResourceText != KZeroResourceId )
       
   168         {
       
   169         HBufC* buf = StringLoader::LoadLC( aResourceText );
       
   170         ChangeTitlePaneL( buf );
       
   171         CleanupStack::Pop(); // buf, ownership transferred
       
   172         }
       
   173     }
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CLmkUiUtils::GetFileWithCorrectDriveL
       
   177 // ----------------------------------------------------------------------------
       
   178 //
       
   179 EXPORT_C void CLmkUiUtils::GetFileWithCorrectDriveL( TFileName& aFileName )
       
   180     {
       
   181     TFileName* dllDrive = new( ELeave ) TFileName;
       
   182     CleanupStack::PushL( dllDrive );
       
   183     TParse* parse = new( ELeave ) TParse;
       
   184     CleanupStack::PushL( parse );
       
   185 
       
   186     Dll::FileName( *dllDrive );
       
   187 	User::LeaveIfError( parse->Set( *dllDrive, NULL, NULL ) );
       
   188     *dllDrive = parse->Drive(); // contains drive, e.g. "c:"
       
   189     User::LeaveIfError( parse->Set( *dllDrive, &aFileName, NULL ) );
       
   190 	aFileName = parse->FullName();
       
   191 
       
   192     CleanupStack::PopAndDestroy( 2 ); // parse, dlldrive
       
   193     }
       
   194 
       
   195 // ----------------------------------------------------
       
   196 // CLmkUiUtils::AvkonIconFileL
       
   197 // ----------------------------------------------------
       
   198 //
       
   199 TFileName* CLmkUiUtils::AvkonIconFileLC()
       
   200     {
       
   201     TFileName* iconFile = new(ELeave) TFileName(AknIconUtils::AvkonIconFileName());
       
   202     CleanupStack::PushL(iconFile);
       
   203     //return AknIconUtils::AvkonIconFileName(); //fix
       
   204     return iconFile;
       
   205     }
       
   206 
       
   207 // ----------------------------------------------------
       
   208 // CLmkUiUtils::LmkUiIconFileL
       
   209 // ----------------------------------------------------
       
   210 //
       
   211 TFileName* CLmkUiUtils::LmkUiIconFileLC()
       
   212     {
       
   213     TFileName* file = new(ELeave) TFileName( KLmkSystemMbmPath );
       
   214     CleanupStack::PushL(file);
       
   215     file->Append( KLmkUiIconFileName ); //always safe
       
   216     GetFileWithCorrectDriveL( *file );
       
   217     return file;
       
   218     }
       
   219 
       
   220 // ----------------------------------------------------------------------------
       
   221 // CLmkUiUtils::RestoreOldTitlePane
       
   222 // ----------------------------------------------------------------------------
       
   223 //
       
   224 void CLmkUiUtils::RestoreOldTitlePane()
       
   225     {
       
   226     if ( iTitlePane && iStoredTitlePaneText )
       
   227         {
       
   228         // iTitlePane takes ownership of iStoredTitlePaneText
       
   229         iTitlePane->SetText( iStoredTitlePaneText );
       
   230         iStoredTitlePaneText = NULL;
       
   231         }
       
   232     }
       
   233 
       
   234 // ----------------------------------------------------------------------------
       
   235 // CLmkUiUtils::ReadLmkUiResourceFileL
       
   236 // ----------------------------------------------------------------------------
       
   237 //
       
   238 void CLmkUiUtils::ReadLmkUiResourceFileL()
       
   239 	{
       
   240 	CEikonEnv* env = CEikonEnv::Static();
       
   241     TFileName* file = new( ELeave ) TFileName;
       
   242     CleanupStack::PushL( file );
       
   243 
       
   244     file->Append( KLmkTmp_RESOURCE_FILES_DIR ); // always safe
       
   245     file->Append( KLmkUiRscFileName ); // always safe
       
   246     GetFileWithCorrectDriveL( *file ) ;
       
   247     BaflUtils::NearestLanguageFile( env->FsSession(), *file );
       
   248     iResourceOffset = env->AddResourceFileL( *file );
       
   249 
       
   250     CleanupStack::PopAndDestroy( file );
       
   251 	}
       
   252 
       
   253 // ----------------------------------------------------
       
   254 // CLmkUiUtils::CreateDefaultNaviPaneL
       
   255 // ----------------------------------------------------
       
   256 //
       
   257 void CLmkUiUtils::CreateDefaultNaviPaneL()
       
   258     {
       
   259     iNaviPane->PushDefaultL();
       
   260     }
       
   261 
       
   262 // ----------------------------------------------------
       
   263 // CLmkUiUtils::CreateNaviLabelL
       
   264 // ----------------------------------------------------
       
   265 //
       
   266 void CLmkUiUtils::CreateNaviLabelL( const TDesC& aLabel )
       
   267     {
       
   268     __ASSERT_ALWAYS( iNaviPane, Panic( KLmkPanicNullPointer ) );
       
   269     if ( iNaviLabel )
       
   270         {
       
   271         iNaviPane->Pop( iNaviLabel );
       
   272         delete iNaviLabel;
       
   273         iNaviLabel = NULL;
       
   274         }
       
   275 
       
   276     iNaviLabel = iNaviPane->CreateNavigationLabelL( aLabel );
       
   277     iNaviPane->PushL( *iNaviLabel ); // activate navi label in navi pane
       
   278     }
       
   279 
       
   280 // ----------------------------------------------------
       
   281 // CLmkUiUtils::StoreNaviPaneL
       
   282 // ----------------------------------------------------
       
   283 //
       
   284 void CLmkUiUtils::StoreNaviPaneL()
       
   285     {
       
   286     iStoredDecorator = iNaviPane->Top();
       
   287     }
       
   288 
       
   289 // ----------------------------------------------------
       
   290 // CLmkUiUtils::RestoreOldNaviPaneL
       
   291 // ----------------------------------------------------
       
   292 //
       
   293 void CLmkUiUtils::RestoreOldNaviPaneL()
       
   294     {
       
   295     if ( iStoredDecorator && iNaviPane )
       
   296         {
       
   297         iNaviPane->PushL( *iStoredDecorator );
       
   298         iStoredDecorator = NULL;
       
   299         }
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CLmkUiUtils::SwapNewContextIcon
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 void CLmkUiUtils::SwapNewContextIconL( CEikImage* aNewImage )
       
   307     {
       
   308     SetContextPaneL();
       
   309     if ( iContextPane )
       
   310         {
       
   311         iOldImage = iContextPane->SwapPicture( aNewImage );
       
   312         }
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CLmkUiUtils::SetOldContextIcon
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 void CLmkUiUtils::SetOldContextIcon()
       
   320     {
       
   321     if ( iContextPane && iOldImage && iOldImage->Bitmap())
       
   322         {
       
   323         iContextPane->SetPicture( iOldImage );
       
   324         iOldImage = NULL;
       
   325         }
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CLmkUiUtils::UpdateContextIconL
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 void CLmkUiUtils::UpdateContextIconL( CEikImage* aNewImage )
       
   333     {
       
   334     SetContextPaneL();
       
   335     if ( iContextPane )
       
   336         {
       
   337         iContextPane->SetPicture( aNewImage );
       
   338         }
       
   339     }
       
   340 
       
   341 // ----------------------------------------------------------------------------
       
   342 // CLmkUiUtils::StatusPane
       
   343 // ----------------------------------------------------------------------------
       
   344 //
       
   345 CEikStatusPane* CLmkUiUtils::StatusPane()
       
   346     {
       
   347     return CEikonEnv::Static()->AppUiFactory()->StatusPane();
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CLmkUiUtils::SetContextPane
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 void CLmkUiUtils::SetContextPaneL()
       
   355     {
       
   356     iContextPane = static_cast<CAknContextPane*>(
       
   357                 StatusPane()->ControlL( TUid::Uid(
       
   358                     EEikStatusPaneUidContext ) ) );
       
   359     }
       
   360 
       
   361 
       
   362 // ----------------------------------------------------------------------------
       
   363 // CLmkUiUtils::ChangeLmNameLabelIconL()
       
   364 // ----------------------------------------------------------------------------
       
   365 //
       
   366 EXPORT_C void CLmkUiUtils::ChangeLmNameLabelIconL (
       
   367               MLmkEditorUiBuilder& aUiBuilder,
       
   368               MLmkFieldData& nameField)
       
   369 	{
       
   370 	if ( nameField.FieldType() == EName )
       
   371 		{
       
   372 		CEikImage* image = new(ELeave) CEikImage();
       
   373 		CleanupStack::PushL( image );
       
   374 		//TFileName* defaultIconFile =  CLmkUiUtils::LmkUiIconFileLC();
       
   375 		// No need to add iconFile to cleanupstack since it is a member variable from CLmkFieldData class
       
   376 		HBufC* iconFile = nameField.IconPath();
       
   377 		TInt err = KErrNotFound;
       
   378 		CFbsBitmap* bitmap = NULL;
       
   379 		CFbsBitmap* mask = NULL;
       
   380 
       
   381 		if (iconFile) // landmark has a defined icon
       
   382 			{
       
   383 			if ( nameField.IconId() != KErrNotFound )
       
   384 				{
       
   385 				TRAP(err,AknIconUtils::CreateIconL( bitmap, mask,
       
   386 									   *iconFile, nameField.IconId(),
       
   387 									   nameField.IconId()+1 ););
       
   388 				}
       
   389 
       
   390 			image->SetPictureOwnedExternally(EFalse);
       
   391 			image->SetPicture(bitmap, mask);
       
   392 			image->CopyControlContextFrom(aUiBuilder.LineControl( nameField.UniqueFieldIdentity() ));
       
   393 			image->SetContainerWindowL(*aUiBuilder.LineControl( nameField.UniqueFieldIdentity() ));
       
   394 			image->SetNonFocusing();
       
   395 			image->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   396 			delete aUiBuilder.LineControl(nameField.UniqueFieldIdentity())->iBitmap;
       
   397 			aUiBuilder.LineControl(nameField.UniqueFieldIdentity())->iBitmap = image;
       
   398 			aUiBuilder.LineControl(nameField.UniqueFieldIdentity())->iBitmap = image;
       
   399 
       
   400 			TRect rect = aUiBuilder.LineControl(nameField.UniqueFieldIdentity())->Rect();
       
   401 			rect.Resize(-1, -1);
       
   402 			aUiBuilder.LineControl(nameField.UniqueFieldIdentity())->SetRect(rect);
       
   403 			rect.Resize(1, 1);
       
   404 			aUiBuilder.LineControl(nameField.UniqueFieldIdentity())->SetRect(rect);
       
   405 			}
       
   406 		CleanupStack::Pop(image);
       
   407 		}
       
   408 	}
       
   409 
       
   410 // ----------------------------------------------------------------------------
       
   411 // CLmkUiUtils::FindIfWebAddrFieldIsEmpty()
       
   412 // ----------------------------------------------------------------------------
       
   413 //
       
   414 TBool CLmkUiUtils::FindIfWebAddrFieldIsEmpty (const TDes& aUrl)
       
   415 	{
       
   416 	TBool result = EFalse;
       
   417 	TInt totalLength = aUrl.Length();
       
   418 	TInt forSlashPos = aUrl.Find(KProtocol);
       
   419 	if (((forSlashPos + KPosUrlColon) > 0 &&
       
   420 		(forSlashPos + KPosUrlColon) >= totalLength ))
       
   421 		{
       
   422 		result = ETrue;
       
   423 		}
       
   424     return result;
       
   425 	}
       
   426 //  End of File