omacpadapters/WAPAdapter/Src/CWPWAPMMSItem.cpp
changeset 42 aa33c2cb9a50
equal deleted inserted replaced
41:c742e1129640 42:aa33c2cb9a50
       
     1 /*
       
     2 * Copyright (c) 2002-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:  One MMS setting item.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <msvapi.h>
       
    23 #include <mmsclient.h> 
       
    24 #include <mtclreg.h>
       
    25 #include <cmmanagerext.h>
       
    26 #include <cmconnectionmethodext.h>
       
    27 #include <cmpluginpacketdatadef.h>
       
    28 #include <CWPCharacteristic.h>
       
    29 #include <CWPParameter.h>
       
    30 #include <CWPAdapter.h>
       
    31 #include "CWPWAPMMSItem.h"
       
    32 #include "WPWAPItemFactory.h"
       
    33 #include "WPWAPUtil.h"
       
    34 
       
    35 #ifdef __MESSAGING_API_V2__
       
    36 #include <mmssettings.h>
       
    37 #endif
       
    38 
       
    39 // CONSTANTS
       
    40 const TInt KUrlMaxLength = 255;
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CWPWAPMMSItem::CWPWAPMMSItem
       
    44 // C++ default constructor can NOT contain any code, that
       
    45 // might leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CWPWAPMMSItem::CWPWAPMMSItem(  const TDesC& aTitle, 
       
    49     const TDesC& aDefaultName, 
       
    50     CWPCharacteristic& aCharacteristic, 
       
    51     CCommsDatabase*& aDb, 
       
    52     RCmManagerExt*& aCmManager )
       
    53 : CWPWAPItemBase( aTitle, aDefaultName, aCharacteristic, aDb, aCmManager )
       
    54     {
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CWPWAPMMSItem::ConstructL
       
    59 // Symbian 2nd phase constructor can leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CWPWAPMMSItem::ConstructL()
       
    63     {
       
    64     BaseConstructL();
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CWPWAPMMSItem::NewL
       
    69 // Two-phased constructor.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CWPWAPMMSItem* CWPWAPMMSItem::NewL( const TDesC& aTitle, 
       
    73     const TDesC& aDefaultName, 
       
    74     CWPCharacteristic& aCharacteristic, 
       
    75     CCommsDatabase*& aDb, 
       
    76     RCmManagerExt*& aCmManager )
       
    77     {
       
    78     CWPWAPMMSItem* self = new(ELeave) CWPWAPMMSItem( aTitle, aDefaultName, 
       
    79         aCharacteristic, aDb, aCmManager ); 
       
    80     CleanupStack::PushL(self);
       
    81     self->ConstructL();
       
    82     CleanupStack::Pop(self);
       
    83     return self;
       
    84     }
       
    85 
       
    86 // Destructor
       
    87 CWPWAPMMSItem::~CWPWAPMMSItem()
       
    88     {
       
    89     iLinks.Close();
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CWPWAPMMSItem::SaveL
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CWPWAPMMSItem::SaveL()
       
    97     {
       
    98     CreateDbL();
       
    99 	TBool check = EFalse;
       
   100     RCmConnectionMethodExt cm;
       
   101     TUint32 bearer = 0;
       
   102     for( TInt i( 0 ); i < iLinks.Count() && check == EFalse ; i++ )
       
   103        {
       
   104        CWPCharacteristic* curr = iLinks[i];
       
   105        TPckgBuf<TUint32> uidPckg;
       
   106        const TInt pkgLength( uidPckg.MaxLength() );
       
   107        for( TInt dataNum( 0 ); check == EFalse && curr->Data( dataNum ).Length() == pkgLength;dataNum++ )
       
   108           {
       
   109           uidPckg.Copy( curr->Data( dataNum ) );
       
   110           // Read the access point pointed to by TO-NAPID or TO-PROXY
       
   111           cm = iCmManager->ConnectionMethodL( uidPckg() );
       
   112           CleanupClosePushL( cm );
       
   113           bearer = cm.GetIntAttributeL( CMManager::ECmBearerType );
       
   114           if( bearer == KUidPacketDataBearerType )
       
   115             {
       
   116             // Item left on cleanup stack
       
   117             check = ETrue;
       
   118             }
       
   119           else
       
   120             {
       
   121             CleanupStack::PopAndDestroy(); // cm
       
   122             }
       
   123           }
       
   124         }
       
   125     
       
   126     WriteHomePageL( cm );    
       
   127     CleanupStack::PopAndDestroy(); // cm
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CWPWAPMMSItem::CanSetAsDefault
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 TBool CWPWAPMMSItem::CanSetAsDefault() const
       
   135     {
       
   136     return ETrue;
       
   137     }
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CWPWAPMMSItem::SetAsDefaultL
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CWPWAPMMSItem::SetAsDefaultL()
       
   145     {
       
   146     // Open Messaging Server session
       
   147     CMsvSession* session = CMsvSession::OpenSyncL( *this );
       
   148     CleanupStack::PushL( session );
       
   149 
       
   150     // Read the MMS client information via registry
       
   151     CClientMtmRegistry* registry = CClientMtmRegistry::NewL( *session );
       
   152     CleanupStack::PushL( registry );
       
   153     
       
   154     CMmsClientMtm* mmsClient = 
       
   155         static_cast<CMmsClientMtm*>( registry->NewMtmL( KUidMsgTypeMultimedia ) );
       
   156     CleanupStack::PushL( mmsClient );
       
   157 
       
   158 #ifdef __MESSAGING_API_V2__
       
   159 
       
   160     CMmsSettings* mmsSettings = CMmsSettings::NewL();
       
   161     CleanupStack::PushL( mmsSettings );
       
   162     
       
   163     mmsClient->RestoreSettingsL();
       
   164 
       
   165     mmsSettings->CopyL( mmsClient->MmsSettings() );
       
   166     TInt apCount =  mmsSettings->AccessPointCount();
       
   167     TInt index;
       
   168     for ( index = 0; index < apCount; index++)
       
   169 	    {
       
   170 	  	    mmsSettings->DeleteAccessPointL( 0 );	
       
   171 	    }
       
   172 	  mmsSettings->AddAccessPointL( iUID, 0 );    
       
   173     mmsClient->SetSettingsL( *mmsSettings );
       
   174     mmsClient->StoreSettingsL();
       
   175 
       
   176     CleanupStack::PopAndDestroy(); // mmsSettings
       
   177 
       
   178 #else
       
   179 
       
   180     mmsClient->LoadMessageL();
       
   181     // Set the correct access point and save
       
   182     mmsClient->SetFirstAccessPoint( iUID );
       
   183     mmsClient->SaveMessageL();
       
   184 
       
   185 #endif
       
   186 
       
   187     CleanupStack::PopAndDestroy(3); // mmsClient, registry, session
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CWPWAPMMSItem::ValidateL
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 TBool CWPWAPMMSItem::ValidateL()
       
   195     {
       
   196     return iLinks.Count() > 0
       
   197         && iAddr
       
   198         && iAddr->Length() <=KUrlMaxLength
       
   199         && WPWAPUtil::CheckURI( *iAddr );
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CWPWAPMMSItem::ResourceL
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CWPWAPMMSItem::ResourceL( CWPCharacteristic& aResource )
       
   207     {     
       
   208     MWPWAPItemBase* item = WPWAPItemFactory::CreateBookmarkLC( KNullDesC, 
       
   209         KNullDesC, aResource, iLink ); // iDb is NULL but it's not used.
       
   210 
       
   211     // Not supporting resources without startpage.
       
   212     if ( item->CanSetAsDefault() && !iAddr )
       
   213         {
       
   214         iAddr = item->Address().AllocL();
       
   215         }
       
   216     CleanupStack::PopAndDestroy();
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CWPWAPMMSItem::AddL
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 void CWPWAPMMSItem::AddL( RPointerArray<MWPWAPItemBase>& aShownItems,
       
   224                               RPointerArray<MWPWAPItemBase>& /*aHiddenItems*/ )
       
   225     {
       
   226     User::LeaveIfError( aShownItems.Append( this ) );
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CWPWAPMMSItem::VisitLinkL
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CWPWAPMMSItem::VisitLinkL( CWPCharacteristic& aLink )
       
   234     {
       
   235     CWPWAPItemBase::VisitLinkL( aLink );
       
   236     User::LeaveIfError( iLinks.Append( &aLink ) );
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CWPWAPMMSItem::HandleSessionEventL
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void CWPWAPMMSItem::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, 
       
   244     TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   245     {
       
   246     }
       
   247 
       
   248 
       
   249 
       
   250 //  End of File