locationsystemui/locationsysui/locnotprefplugin/src/locnotprefplugin.cpp
branchRCL_3
changeset 44 2b4ea9893b66
parent 42 02ba3f1733c6
child 45 6b6920c56e2f
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
     1 /*
       
     2 * Copyright (c) 2006 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:  Location Notation Preferences Plugin View's container
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System Include
       
    20 #include <aknViewAppUi.h>
       
    21 #include <StringLoader.h>           // For String Loader
       
    22 #include <locnotprefpluginview.rsg>
       
    23 #include <barsread.h>               // For TResourceReader
       
    24 #include <bautils.h>
       
    25 
       
    26 // User Includes
       
    27 #include "locnotprefplugin.h"
       
    28 #include "locsettingsuiobserver.h"
       
    29 #include "locsettingsuiparams.h"
       
    30 #include "locnotprefpluginview.h"
       
    31 
       
    32 // Constant Definition
       
    33 /**
       
    34  * Position of Notation Preferences plug-in the Postioning View.
       
    35  * As defined by the Location System UI UI specification, the Location
       
    36  *  notation preferences plug-in should be inserted at the fourth level
       
    37  */
       
    38 const TInt KNotPrefPluginPriority = 0x00000004;
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CLocNotPrefPlugin::CLocNotPrefPlugin
       
    42 // C++ default constructor.
       
    43 // ---------------------------------------------------------------------------
       
    44 CLocNotPrefPlugin::CLocNotPrefPlugin( MLocSettingsUiObserver&   aSettingsUiObserver,
       
    45                                       CAknViewAppUi&            aAppUi )
       
    46     :CLocSettingsUi( aSettingsUiObserver, aAppUi ),
       
    47     iResourceLoader( *CCoeEnv::Static())
       
    48     {
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CLocNotPrefPlugin::~CLocNotPrefPlugin
       
    53 // Destructor.
       
    54 // ---------------------------------------------------------------------------  
       
    55 CLocNotPrefPlugin::~CLocNotPrefPlugin() 
       
    56     {
       
    57     iResourceLoader.Close();
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CLocNotPrefPlugin* CLocNotPrefPlugin::NewL
       
    62 // Symbian OS two-phased constructor
       
    63 // 
       
    64 // @return CLocNotPrefPlugin* Reference to the Settings UI object
       
    65 // ---------------------------------------------------------------------------  
       
    66 CLocNotPrefPlugin* CLocNotPrefPlugin::NewL( TAny* aParam )
       
    67     {
       
    68     CLocSettingsUiParams*   param = reinterpret_cast<CLocSettingsUiParams *>( aParam );
       
    69     MLocSettingsUiObserver& observer = param->SettingsUiObserver();
       
    70     CAknViewAppUi&          appUi = param->AppUi();
       
    71     CLocNotPrefPlugin* self = new (ELeave )CLocNotPrefPlugin( observer,
       
    72                                                               appUi );
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL();
       
    75     CleanupStack::Pop( self );
       
    76     return self; 
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // void CLocNotPrefPlugin::ConstructL
       
    81 // Second phase constructor.
       
    82 // ---------------------------------------------------------------------------  
       
    83 void CLocNotPrefPlugin::ConstructL()
       
    84     {
       
    85     // Open the Resource file for the plugin. The resource file is not 
       
    86     // explicity opened by system. Hence, the opening and closind if tied
       
    87     // down to the time when the DLL is active
       
    88     OpenLocalizedResourceFileL( KLocNotPrefUiResFileName, 
       
    89                                 iResourceLoader );
       
    90                                     
       
    91     // Creating an Application view
       
    92     iView = CLocNotPrefPluginView::NewL( iSettingsUiObserver );
       
    93     
       
    94     // Transferring the view's control to AppUi
       
    95     iAppUi.AddViewL( iView );
       
    96     
       
    97     // Obtaining the View Id for reference
       
    98     iViewId = iView->Id();
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // void CLocNotPrefPlugin::LaunchL
       
   103 // Inherited from CSettingsUi
       
   104 // Launches the Settings UI
       
   105 //
       
   106 // @param aUiLaunchParams   Flags for Launch options
       
   107 // ---------------------------------------------------------------------------  
       
   108 void CLocNotPrefPlugin::LaunchL( TInt       /* aUiLaunchParams */)
       
   109     {
       
   110     // Activate self
       
   111     iAppUi.ActivateLocalViewL( iViewId );
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // void CLocNotPrefPlugin::Close
       
   116 // Inherited from CSettingsUi
       
   117 // Closes the running Settings UI
       
   118 // ---------------------------------------------------------------------------  
       
   119 void CLocNotPrefPlugin::Close()
       
   120     {
       
   121     iView->CloseSettings();
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // void CLocNotPrefPlugin::GetCaptionL
       
   126 // Inherited from CSettingsUi
       
   127 // Method for getting caption of this plugin. This should be the 
       
   128 // localized name of the settings view to be shown in parent view.
       
   129 //
       
   130 // @param aCaption pointer to Caption variable
       
   131 // ---------------------------------------------------------------------------
       
   132 void CLocNotPrefPlugin::GetCaptionL( TDes& aCaption ) const
       
   133     {
       
   134     // Load the Notation preferences setting caption from the resource file 
       
   135     // and hand it back to the callee. It is assuemed here that the calling function has 
       
   136     // allocated enough memory for the aCaption string. If not the fucntion
       
   137     // would leave
       
   138     HBufC* caption = StringLoader::LoadL( R_LOC_SETTINGS_NOTATIONS );
       
   139     
       
   140     if( aCaption.MaxLength() < caption->Length())
       
   141         {
       
   142         User::Leave( KErrNoMemory );
       
   143         }
       
   144     aCaption.Copy( *caption );
       
   145     delete caption; 
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // TInt CLocNotPrefPlugin::GetPriority
       
   150 // Inherited from CSettingsUi
       
   151 // Returns the priority of the UI module. 
       
   152 // 
       
   153 // @return Priority of the Settings UI
       
   154 // ---------------------------------------------------------------------------
       
   155 TInt CLocNotPrefPlugin::GetPriority()
       
   156     {
       
   157     return KNotPrefPluginPriority;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // void CLocNotPrefPlugin::OpenLocalizedResourceFileL
       
   162 // Opens the nearest localized resourcefile using aResourceLoader. 
       
   163 // aResourceLoader should be opened only once before closing it. 
       
   164 // Otherwise it will raise a panic. Therefore it is better to have 
       
   165 // multiple resource loaders.
       
   166 // 
       
   167 // @param aResourceFileName Drive and name of resource file in format 
       
   168 //                          <path>:<rsc_file_name>
       
   169 // @param aResourceLoader Resource loader for the resource. The loader 
       
   170 //                        must not be opened allready or it will raise 
       
   171 //                        a panic. It is caller's responsibility to 
       
   172 //                        close the resource loader after using the 
       
   173 //                        resource.
       
   174 // ---------------------------------------------------------------------------  
       
   175 //
       
   176 void CLocNotPrefPlugin::OpenLocalizedResourceFileL( 
       
   177                                 const TDesC&               aResourceFileName, 
       
   178                                       RConeResourceLoader& aResourceLoader )
       
   179     {
       
   180     RFs fsSession;
       
   181     User::LeaveIfError( fsSession.Connect());
       
   182     
       
   183     // Add the RFs session to the CleanupStack
       
   184     CleanupClosePushL( fsSession );
       
   185     
       
   186     TFileName* tmpName = new( ELeave ) TFileName;
       
   187     CleanupStack::PushL( tmpName );
       
   188     
       
   189     // Append the Resource Files Directory
       
   190     tmpName->Append( KDC_RESOURCE_FILES_DIR );
       
   191     
       
   192     // Append the Ressource File Name
       
   193     tmpName->Append( aResourceFileName );
       
   194     
       
   195     
       
   196     // Obtain the drive where the DLL is installed
       
   197     TFileName* dllDrive = new ( ELeave ) TFileName;
       
   198     CleanupStack::PushL( dllDrive );
       
   199     Dll::FileName( *dllDrive );
       
   200     
       
   201     // Obtain the Complete path for the Resource File
       
   202     TParse parse;
       
   203     User::LeaveIfError( parse.Set( *dllDrive, NULL, NULL ));
       
   204     User::LeaveIfError( parse.Set( parse.Drive(), tmpName, NULL ));
       
   205     TFileName* fileName = new ( ELeave ) TFileName;
       
   206     CleanupStack::PushL( fileName );
       
   207     fileName->Append( parse.FullName());
       
   208     
       
   209     // Get language of resource file
       
   210     BaflUtils::NearestLanguageFile( fsSession, *fileName );
       
   211         
       
   212     // Open resource file    
       
   213     aResourceLoader.OpenL( *fileName );
       
   214     
       
   215     // Pop all the fields
       
   216     CleanupStack::PopAndDestroy( fileName );
       
   217     CleanupStack::PopAndDestroy( dllDrive );
       
   218     CleanupStack::PopAndDestroy( tmpName );
       
   219    
       
   220     CleanupStack::Pop(); // fsSession
       
   221                
       
   222     //If leave occurs before this, close is called automatically when the thread exits.
       
   223     fsSession.Close();
       
   224    
       
   225     }
       
   226 
       
   227