gssettingsuis/Gs/GSPDataConnectionPlugin/src/GSPDataConnectionPlugin.cpp
changeset 68 13e71d907dc3
equal deleted inserted replaced
40:6465d5bb863a 68:13e71d907dc3
       
     1 /*
       
     2 * Copyright (c) 2007 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:  GSPDataConnectionPlugin implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // User includes
       
    20 #include    "GSPDataConnectionPlugin.h"
       
    21 #include    "GSPDataConnectionModel.h"
       
    22 #include    <gsparentplugin.h>
       
    23 #include    <gscommon.hrh>
       
    24 #include    <gspdataconnectionpluginrsc.rsg> // GUI Resource
       
    25 #include    <gsprivatepluginproviderids.h>
       
    26 #include    <gsfwviewuids.h>
       
    27 
       
    28 // System includes
       
    29 #include    <aknnotewrappers.h>
       
    30 #include    <aknradiobuttonsettingpage.h>
       
    31 #include    <akntextsettingpage.h>
       
    32 #include    <aknViewAppUi.h>
       
    33 #include    <bautils.h>
       
    34 #include    <featmgr.h>
       
    35 #include    <hlplch.h> // HlpLauncher
       
    36 #include    <StringLoader.h>
       
    37 #include    <telephonydomainpskeys.h>
       
    38 #include    <apgtask.h>
       
    39 
       
    40 // Constants
       
    41 
       
    42 // ========================= MEMBER FUNCTIONS ================================
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CGSPDataConnectionPlugin::CGSPDataConnectionPlugin()
       
    46 // Constructor
       
    47 //
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CGSPDataConnectionPlugin::CGSPDataConnectionPlugin()
       
    51     : iResources( *iCoeEnv )
       
    52     {
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CGSPDataConnectionPlugin::~CGSPDataConnectionPlugin()
       
    58 // Destructor
       
    59 //
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CGSPDataConnectionPlugin::~CGSPDataConnectionPlugin()
       
    63     {
       
    64     iResources.Close();
       
    65 
       
    66     if( iModel )
       
    67         {
       
    68         delete iModel;
       
    69         }
       
    70     }
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CGSPDataConnectionPlugin::ConstructL(const TRect& aRect)
       
    75 // Symbian OS two-phased constructor
       
    76 //
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 void CGSPDataConnectionPlugin::ConstructL()
       
    80     {
       
    81     iModel = CGSPDataConnectionModel::NewL();
       
    82     OpenLocalizedResourceFileL( KPDataConnectionResourceFileName, iResources );
       
    83     BaseConstructL( R_GS_PDATACONNECTION_VIEW );
       
    84     }
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CGSPDataConnectionPlugin::NewL()
       
    89 // Static constructor
       
    90 //
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CGSPDataConnectionPlugin* CGSPDataConnectionPlugin::NewL( TAny* /*aInitParams*/ )
       
    94     {
       
    95     CGSPDataConnectionPlugin* self = new( ELeave ) CGSPDataConnectionPlugin();
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL();
       
    98     CleanupStack::Pop( self );
       
    99     return self;
       
   100     }
       
   101 
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CGSPDataConnectionPlugin::Id
       
   105 //
       
   106 //
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 TUid CGSPDataConnectionPlugin::Id() const
       
   110     {
       
   111     return KGSPDataConnectionPluginUID;
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CGSPDataConnectionPlugin::DoActivateL
       
   116 //
       
   117 //
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CGSPDataConnectionPlugin::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
       
   121                                   TUid /*aCustomMessageId*/,
       
   122                                   const TDesC8& /*aCustomMessage*/ )
       
   123     {
       
   124     }
       
   125 
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CGSPDataConnectionPlugin::DoDeactivate
       
   129 //
       
   130 //
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CGSPDataConnectionPlugin::DoDeactivate()
       
   134     {
       
   135     }
       
   136 
       
   137 
       
   138 // ========================= From CGSPluginInterface ==================
       
   139 
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CGSPDataConnectionPlugin::GetCaptionL
       
   143 //
       
   144 //
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CGSPDataConnectionPlugin::GetCaptionL( TDes& aCaption ) const
       
   148     {
       
   149     HBufC* result = StringLoader::LoadL( R_GS_PDATACONNECTION_PLUGIN_CAPTION );
       
   150     aCaption.Copy( *result );
       
   151     delete result;
       
   152     }
       
   153 
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CGSPDataConnectionPlugin::PluginProviderCategory
       
   157 //
       
   158 //
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 TInt CGSPDataConnectionPlugin::PluginProviderCategory() const
       
   162     {
       
   163     return KGSPluginProviderInternal;
       
   164     }
       
   165 
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CGSPDataConnectionPlugin::ItemType()
       
   169 //
       
   170 //
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TGSListboxItemTypes CGSPDataConnectionPlugin::ItemType()
       
   174     {
       
   175     return EGSItemTypeSettingDialog;
       
   176     }
       
   177 
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CGSPDataConnectionPlugin::GetValue()
       
   181 //
       
   182 //
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CGSPDataConnectionPlugin::GetValue( const TGSPluginValueKeys aKey,
       
   186                                          TDes& aValue )
       
   187     {
       
   188     TRAPD( err, GetValueL( aValue ) );
       
   189     if ( err != KErrNone )
       
   190         {
       
   191         CGSPluginInterface::GetValue( aKey, aValue );
       
   192         }
       
   193     }
       
   194 
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CGSPDataConnectionPlugin::GetValueL()
       
   198 //
       
   199 // Leaving version of GetValue()
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CGSPDataConnectionPlugin::GetValueL( TDes& aValue )
       
   203     {
       
   204     TInt attachState = iModel->PDataAttachL();
       
   205     HBufC* result;
       
   206 
       
   207     switch( attachState )
       
   208         {
       
   209         case KAttachSettingWhenAvailable:
       
   210             result = StringLoader::LoadL( R_GS_PDATACONN_WHEN_ENABLE_TEXT );
       
   211             aValue.Copy( *result );
       
   212             delete result;
       
   213             break;
       
   214 
       
   215         case KAttachSettingWhenNeeded:
       
   216             result = StringLoader::LoadL( R_GS_PDATACONN_WHEN_NEEDED_TEXT );
       
   217             aValue.Copy( *result );
       
   218             delete result;
       
   219          default:
       
   220             break;
       
   221         }
       
   222 
       
   223     }
       
   224 
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CGSPDataConnectionPlugin::HandleSelection()
       
   228 //
       
   229 //
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CGSPDataConnectionPlugin::HandleSelection(
       
   233     const TGSSelectionTypes aSelectionType )
       
   234     {
       
   235     switch( aSelectionType )
       
   236         {
       
   237         case EGSSelectionBySelectionKey:
       
   238         case EGSSelectionByMenu:
       
   239             TRAP_IGNORE( SetAttachStateL() ); // Launch setting page to change value.
       
   240             break;
       
   241         default:
       
   242             break;
       
   243         }
       
   244 
       
   245     }
       
   246 
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CGSPDataConnectionPlugin::ShowAttachSettingPageL()
       
   250 //
       
   251 // Indexes of Attach on/off items in a listbox are not the same as aPDataConnectionState
       
   252 // value. Therefore matching between these two is required.
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 TBool CGSPDataConnectionPlugin::ShowAttachSettingPageL( TInt& aPDataConnectionState )
       
   256     {
       
   257     TInt previousPDataConnectionState = aPDataConnectionState;
       
   258     TBool isValueUpdated = EFalse;
       
   259     
       
   260     CDesCArrayFlat* items = iCoeEnv->ReadDesC16ArrayResourceL( 
       
   261                             R_GS_PDATACONNECTION_SETTING_PAGE_LBX );
       
   262     CleanupStack::PushL( items );
       
   263     
       
   264     if( items->Count() != 2 )
       
   265         {
       
   266         CAknRadioButtonSettingPage* dlg =
       
   267             new (ELeave) CAknRadioButtonSettingPage
       
   268                                      ( R_GS_PDATACONNECTION_SETTING_PAGE,
       
   269                                        aPDataConnectionState,
       
   270                                        items );
       
   271         dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged );
       
   272         }
       
   273     else
       
   274         {
       
   275         if (aPDataConnectionState == 0)
       
   276             {
       
   277             aPDataConnectionState = 1;
       
   278             }
       
   279         else
       
   280             {
       
   281             aPDataConnectionState = 0;
       
   282             }
       
   283         }
       
   284     
       
   285     CleanupStack::PopAndDestroy( items );
       
   286     
       
   287     // Check if aPDataConnectionState has been changed:
       
   288     if( previousPDataConnectionState != aPDataConnectionState )
       
   289         {
       
   290         isValueUpdated = ETrue;
       
   291         }
       
   292     return isValueUpdated;
       
   293     }
       
   294 
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CGSPDataConnectionPlugin::SetAttachStateL()
       
   298 //
       
   299 //
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 void CGSPDataConnectionPlugin::SetAttachStateL()
       
   303     {
       
   304     // Get information of if there are open connections
       
   305     TInt PDataConnectionState = iModel->PDataAttachL();
       
   306     const TBool isValueUpdated = ShowAttachSettingPageL( PDataConnectionState );
       
   307     
       
   308     if ( isValueUpdated )
       
   309         {
       
   310         // Store updated Active Idle state:
       
   311         iModel->SetPDataAttachL( PDataConnectionState );
       
   312         // Update Attach item's value to lbx:
       
   313         CGSParentPlugin* parent = static_cast<CGSParentPlugin*>(
       
   314             AppUi()->View( KGSPDataPluginUid ) );// This is the parent plugin
       
   315         parent->UpdateView();
       
   316         }
       
   317     }
       
   318 
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // CGSPDataConnectionPlugin::OpenLocalizedResourceFileL()
       
   322 //
       
   323 //
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 void CGSPDataConnectionPlugin::OpenLocalizedResourceFileL(
       
   327     const TDesC& aResourceFileName,
       
   328     RConeResourceLoader& aResourceLoader )
       
   329     {
       
   330     RFs fsSession;
       
   331     User::LeaveIfError( fsSession.Connect() );
       
   332 
       
   333     // Find the resource file:
       
   334     TParse parse;
       
   335     parse.Set( aResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   336     TFileName fileName( parse.FullName() );
       
   337 
       
   338     // Get language of resource file:
       
   339     BaflUtils::NearestLanguageFile( fsSession, fileName );
       
   340 
       
   341     // Open resource file:
       
   342     aResourceLoader.OpenL( fileName );
       
   343 
       
   344     // If leave occurs before this, close is called automatically when the
       
   345     // thread exits.
       
   346     fsSession.Close();
       
   347     }
       
   348 
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CGSPDataConnectionPlugin::TGSMenuActivationItems()
       
   352 //
       
   353 //
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 TGSMenuActivationItems CGSPDataConnectionPlugin::MenuActivationItem()
       
   357     {
       
   358     return EGSMenuActivationItemChange;
       
   359     }
       
   360 
       
   361 
       
   362 // ----------------------------------------------------------------------------
       
   363 // CGSPDataConnectionPlugin
       
   364 //
       
   365 // Provides the visibility status of self to framework.
       
   366 // ----------------------------------------------------------------------------
       
   367 //
       
   368 TBool CGSPDataConnectionPlugin::Visible() const
       
   369     {
       
   370     if ( FeatureManager::FeatureSupported( KFeatureIdIpPush ))
       
   371         {
       
   372         return EFalse;
       
   373         }
       
   374     return ETrue;
       
   375     }
       
   376 
       
   377 // End of file