phonebookui/Phonebook2/GroupExtension/src/CPguSetToneCmd.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-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:  A command for setting ringing tone.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPguSetToneCmd.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include <CPbk2ContactRelocator.h>
       
    24 #include <MPbk2ContactUiControl.h>
       
    25 #include <Pbk2GroupUIRes.rsg>
       
    26 #include <Pbk2CommonUi.rsg>
       
    27 
       
    28 // Virtual Phonebook
       
    29 #include <CVPbkContactManager.h>
       
    30 #include <MVPbkStoreContact.h>
       
    31 #include <MVPbkContactOperationBase.h>
       
    32 #include <CVPbkContactLinkArray.h>
       
    33 #include <MVPbkContactGroup.h>
       
    34 #include <MVPbkContactLink.h>
       
    35 
       
    36 // System includes
       
    37 #include <barsread.h>
       
    38 #include <barsc.h>
       
    39 #include <coemain.h>
       
    40 #include <StringLoader.h>
       
    41 #include <aknnotewrappers.h>
       
    42 
       
    43 // Debugging headers
       
    44 #include <Pbk2Debug.h>
       
    45 
       
    46 // ============================ LOCAL FUNCTIONS =============================
       
    47 
       
    48 namespace 
       
    49     {
       
    50     const TInt KFirstElement( 0 );
       
    51     
       
    52     #ifdef _DEBUG
       
    53     	enum TPanicCode
       
    54     	    {
       
    55     	    EPanicLogic_ReadFieldTypeL,
       
    56     	    EPanicLogic_ContactCommitCompelete,
       
    57     	    EPanicPreCond_RelocationProcessCompleteL
       
    58     	    };
       
    59 
       
    60     	void Panic(TInt aReason)
       
    61     	    {
       
    62     	    _LIT(KPanicText, "CPguSetToneCmd");
       
    63     	    User::Panic(KPanicText, aReason);
       
    64     	    }
       
    65     #endif // _DEBUG	    
       
    66     }
       
    67 
       
    68 // ============================ MEMBER FUNCTIONS ============================
       
    69 
       
    70 // --------------------------------------------------------------------------
       
    71 // CPguSetToneCmd::CPguSetToneCmd
       
    72 // C++ default constructor can NOT contain any code, that
       
    73 // might leave.
       
    74 // --------------------------------------------------------------------------
       
    75 //
       
    76 CPguSetToneCmd::CPguSetToneCmd(
       
    77         MPbk2ContactUiControl& aUiControl ) :  
       
    78     CPbk2SetToneBase( aUiControl ),
       
    79     iIsStarted( EFalse )
       
    80     {
       
    81     }
       
    82 
       
    83 // --------------------------------------------------------------------------
       
    84 // CPguSetToneCmd::~CPguSetToneCmd
       
    85 // --------------------------------------------------------------------------
       
    86 //
       
    87 CPguSetToneCmd::~CPguSetToneCmd()
       
    88     {
       
    89     if ( iContacts )
       
    90         {
       
    91         iContacts->ResetAndDestroy();
       
    92         }
       
    93     delete iContacts;
       
    94     delete iCurrentContact;
       
    95     }
       
    96 
       
    97 // --------------------------------------------------------------------------
       
    98 // CPguSetToneCmd::NewL
       
    99 // Two-phased constructor.
       
   100 // --------------------------------------------------------------------------
       
   101 //
       
   102 CPguSetToneCmd* CPguSetToneCmd::NewL(
       
   103     MPbk2ContactUiControl& aUiControl)
       
   104     {
       
   105     CPguSetToneCmd* self = 
       
   106         new( ELeave ) CPguSetToneCmd( aUiControl );
       
   107     CleanupStack::PushL( self );
       
   108     self->ConstructL();
       
   109     CleanupStack::Pop( self );
       
   110     return self;
       
   111     }
       
   112 
       
   113 // --------------------------------------------------------------------------
       
   114 // CPguSetToneCmd::ConstructL
       
   115 // Symbian 2nd phase constructor can leave.
       
   116 // --------------------------------------------------------------------------
       
   117 //
       
   118 void CPguSetToneCmd::ConstructL()
       
   119     {    
       
   120     BaseConstructL();
       
   121     }
       
   122 	
       
   123 // --------------------------------------------------------------------------
       
   124 // CPguSetToneCmd::ContactRelocatedL
       
   125 // --------------------------------------------------------------------------
       
   126 //
       
   127 void CPguSetToneCmd::ContactRelocatedL
       
   128     ( MVPbkStoreContact* aRelocatedContact )
       
   129     {
       
   130     // Takes ownership of the aRelocatedContact
       
   131     delete iCurrentContact;
       
   132     iCurrentContact = aRelocatedContact;
       
   133     }
       
   134 
       
   135 // --------------------------------------------------------------------------
       
   136 // CPguSetToneCmd::ContactRelocationFailed
       
   137 // --------------------------------------------------------------------------
       
   138 //
       
   139 void CPguSetToneCmd::ContactRelocationFailed
       
   140         (TInt aReason, MVPbkStoreContact* aContact)
       
   141     {
       
   142     // We got the ownership of aContact
       
   143     delete aContact;
       
   144     if ( aReason == KErrCancel )
       
   145         {
       
   146         // No error note is to be shown to the user when she
       
   147         // manually cancels the relocation process, therefore
       
   148         // the error code must be converted
       
   149         aReason = KErrNone;
       
   150         }
       
   151     ProcessDismissed( aReason );
       
   152     }
       
   153 
       
   154 // --------------------------------------------------------------------------
       
   155 // CPguSetToneCmd::ContactRelocationFailed
       
   156 // --------------------------------------------------------------------------
       
   157 //
       
   158 void CPguSetToneCmd::ContactsRelocationFailed
       
   159         ( TInt /*aReason*/, CVPbkContactLinkArray* /*aContacts*/ )
       
   160     {
       
   161     // Do nothing
       
   162     }
       
   163 
       
   164 // --------------------------------------------------------------------------
       
   165 // CPguSetToneCmd::RelocationProcessComplete
       
   166 // --------------------------------------------------------------------------
       
   167 //
       
   168 void CPguSetToneCmd::RelocationProcessComplete()
       
   169     {
       
   170     __ASSERT_DEBUG( iCurrentContact, 
       
   171         Panic( EPanicPreCond_RelocationProcessCompleteL ) );
       
   172     // Lock contact for setting ringingtone
       
   173     TRAPD( res, iCurrentContact->LockL( *this ) );
       
   174     if ( res != KErrNone )
       
   175         {
       
   176         ProcessDismissed( res );
       
   177         }
       
   178     }
       
   179 	
       
   180 // --------------------------------------------------------------------------
       
   181 // CPguSetToneCmd::RelocationProcessCompleteL
       
   182 // --------------------------------------------------------------------------
       
   183 //
       
   184 void CPguSetToneCmd::VPbkSingleContactOperationComplete(
       
   185         MVPbkContactOperationBase& /*aOperation*/,
       
   186         MVPbkStoreContact* aContact)
       
   187     {
       
   188     delete iRetrieveOperation;
       
   189     iRetrieveOperation = NULL;
       
   190 
       
   191     if ( !iStoreContact )
       
   192         {
       
   193         // This is the main (group) contact
       
   194        	iStoreContact = aContact;        
       
   195        	iGroup = iStoreContact->Group(); 
       
   196        	// If leaves the iContacts will be not created
       
   197        	TRAP_IGNORE(
       
   198        	    {
       
   199            	CreateLinkArrayL( iGroup->ItemsContainedLC() );       	    
       
   200            	CleanupStack::PopAndDestroy(); // group items
       
   201        	    });
       
   202        	
       
   203        	if ( iContacts && iContacts->Count() > 0 )
       
   204        	    {
       
   205             TRAPD( err, RetrieveContactL( iContacts->At( KFirstElement ) ) );
       
   206             if ( err )
       
   207                 {
       
   208                 ProcessDismissed( err );
       
   209                 }
       
   210        	    }
       
   211        	else
       
   212        	    {
       
   213        	    // There is no contacts linked to group.
       
   214        	    // Stop the process
       
   215             // Show note
       
   216             // If leave occurs the note just go on and exit the command
       
   217             TRAP_IGNORE( ConfirmationL() );
       
   218             // Now, its time to exit the command
       
   219             IssueStopRequest();                   	    
       
   220        	    }
       
   221         }
       
   222     else
       
   223         {
       
   224         // Here we are retrieved a contact from group
       
   225         delete iCurrentContact;
       
   226         iCurrentContact = NULL;
       
   227         
       
   228         iCurrentContact = aContact;
       
   229         
       
   230         TInt err = KErrNone;
       
   231         if ( !iIsStarted )
       
   232             {
       
   233             iIsStarted = ETrue;
       
   234             }
       
   235             
       
   236         TBool contactNeedsRelocation = EFalse;
       
   237         TRAP( err, contactNeedsRelocation = RelocateContactL( iCurrentContact ) );
       
   238         if (err != KErrNone)
       
   239             {
       
   240             ProcessDismissed( err );
       
   241             }
       
   242 
       
   243         if ( !contactNeedsRelocation )
       
   244             {
       
   245             TRAP( err, iCurrentContact->LockL( *this ) );
       
   246             if ( err != KErrNone )
       
   247                 {
       
   248                 ProcessDismissed( err );
       
   249                 }
       
   250             }
       
   251         else
       
   252             {
       
   253             // Relocator has taken the ownership of the contact
       
   254             iCurrentContact = NULL;
       
   255             }   	                
       
   256         }   	
       
   257     }
       
   258 
       
   259 // --------------------------------------------------------------------------
       
   260 // CPguSetToneCmd::RelocationProcessCompleteL
       
   261 // --------------------------------------------------------------------------
       
   262 //
       
   263 void CPguSetToneCmd::VPbkSingleContactOperationFailed(
       
   264         MVPbkContactOperationBase& /*aOperation*/, 
       
   265         TInt aError )
       
   266     {
       
   267     ProcessDismissed( aError );
       
   268     }
       
   269       
       
   270 // --------------------------------------------------------------------------
       
   271 // CPguSetToneCmd::RelocationProcessCompleteL
       
   272 // --------------------------------------------------------------------------
       
   273 //
       
   274 void CPguSetToneCmd::ContactOperationCompleted( TContactOpResult aResult )
       
   275     {
       
   276     if ( aResult.iOpCode == EContactLock )
       
   277         {
       
   278         TRAPD( err, SetToneAndCommitL( iCurrentContact ) );        
       
   279         if ( err != KErrNone )
       
   280             {
       
   281             ProcessDismissed( err );
       
   282             }
       
   283         }
       
   284     else if ( aResult.iOpCode == EContactCommit )
       
   285         {
       
   286         // Remove first item 'cause it has already been gone through
       
   287         iContacts->Delete( KFirstElement );
       
   288         if ( iContacts->Count() > 0 )
       
   289             {
       
   290             TRAPD( err, RetrieveContactL( iContacts->At( KFirstElement ) ) );
       
   291             if ( err )
       
   292                 {
       
   293                 ProcessDismissed( err );
       
   294                 }
       
   295             }
       
   296         else
       
   297             {
       
   298             // Show note
       
   299             TRAP_IGNORE( ConfirmationL() );
       
   300             // Now, its time to exit the command
       
   301             IssueStopRequest();            
       
   302             }
       
   303         }    
       
   304     }
       
   305 
       
   306 // --------------------------------------------------------------------------
       
   307 // CPguSetToneCmd::RelocationProcessCompleteL
       
   308 // --------------------------------------------------------------------------
       
   309 //
       
   310 void CPguSetToneCmd::ContactOperationFailed
       
   311     (TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/)
       
   312     {
       
   313     ProcessDismissed( aErrorCode );
       
   314     }
       
   315 
       
   316 // --------------------------------------------------------------------------
       
   317 // CPguSetToneCmd::CreateLinkArrayL
       
   318 // --------------------------------------------------------------------------
       
   319 //
       
   320 void CPguSetToneCmd::CreateLinkArrayL( MVPbkContactLinkArray* aArray )
       
   321     {
       
   322     if ( iContacts )
       
   323         {
       
   324         iContacts->ResetAndDestroy();
       
   325         delete iContacts;
       
   326         iContacts = NULL;
       
   327         }
       
   328     
       
   329     iContacts = CVPbkContactLinkArray::NewL();
       
   330     TInt count( aArray->Count() );
       
   331     for ( TInt i = 0; i < count; ++i )
       
   332         {
       
   333         iContacts->AppendL( ( *aArray )[i].CloneLC() );
       
   334         CleanupStack::Pop(); // clone
       
   335         }
       
   336     }
       
   337 
       
   338 // --------------------------------------------------------------------------
       
   339 // CPguSetToneCmd::ConfirmationNoteL
       
   340 // --------------------------------------------------------------------------
       
   341 //
       
   342 void CPguSetToneCmd::ConfirmationL()
       
   343 	{
       
   344     TParse toneName;
       
   345     toneName.Set( iToneFilename, NULL, NULL );	
       
   346     HBufC* noteText = NULL;
       
   347     if ( toneName.Name().Length() == 0 )
       
   348         {
       
   349         HBufC* defaultName = CCoeEnv::Static()->AllocReadResourceLC
       
   350             ( R_QTN_PHOP_SELI_DEFAULT_RTONE );
       
   351         noteText = StringLoader::LoadL(
       
   352             R_QTN_PHOB_NOTE_RTONE_SET_TO_GRP, *defaultName );
       
   353         CleanupStack::PopAndDestroy(); // defaultName
       
   354         CleanupStack::PushL(noteText);
       
   355         }
       
   356     else
       
   357         {
       
   358         noteText = StringLoader::LoadLC(
       
   359             R_QTN_PHOB_NOTE_RTONE_SET_TO_GRP, toneName.Name() );
       
   360         }
       
   361 
       
   362     CAknConfirmationNote* noteDlg = 
       
   363         new (ELeave) CAknConfirmationNote( ETrue );
       
   364     noteDlg->ExecuteLD( *noteText );
       
   365     CleanupStack::PopAndDestroy(); // notetext	
       
   366 	}
       
   367 
       
   368 //  End of File