phonebookui/Phonebook2/UIControls/src/TPbk2DeleteItemManager.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     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:  Phonebook 2 contact editor delete item manager.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "TPbk2DeleteItemManager.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "MPbk2ContactEditorFieldArray.h"
       
    23 #include <MPbk2ContactEditorField.h>
       
    24 #include <Pbk2UIControls.rsg>
       
    25 #include <CPbk2PresentationContact.h>
       
    26 #include <CPbk2PresentationContactFieldCollection.h>
       
    27 #include <CPbk2PresentationContactField.h>
       
    28 #include <CVPbkContactManager.h>
       
    29 #include <CVPbkSpeedDialAttribute.h>
       
    30 #include <MPbk2ApplicationServices.h>
       
    31 #include <MPbk2AppUi.h>
       
    32 #include "CPbk2ContactEditorArrayItem.h"
       
    33 #include <MPbk2ApplicationServices.h>
       
    34 
       
    35 // System includes
       
    36 #include <StringLoader.h>
       
    37 #include <aknnotewrappers.h>
       
    38 #include <featmgr.h>
       
    39 
       
    40 // --------------------------------------------------------------------------
       
    41 // TPbk2DeleteItemManager::TPbk2DeleteItemManager
       
    42 // --------------------------------------------------------------------------
       
    43 //
       
    44 TPbk2DeleteItemManager::TPbk2DeleteItemManager
       
    45         ( CPbk2PresentationContact& aContact,
       
    46           MPbk2ContactEditorFieldArray& aFieldArray,
       
    47           MPbk2ApplicationServices* aAppServices ):
       
    48             iContact( aContact ),
       
    49             iFieldArray( aFieldArray ),
       
    50             iAppServices( aAppServices )
       
    51     {
       
    52     }
       
    53 
       
    54 // --------------------------------------------------------------------------
       
    55 // TPbk2DeleteItemManager::DeleteFieldL
       
    56 // --------------------------------------------------------------------------
       
    57 //
       
    58 TBool TPbk2DeleteItemManager::DeleteFieldL( TInt aControlId )
       
    59     {
       
    60     TBool result = EFalse;
       
    61     CPbk2ContactEditorArrayItem* uiField = iFieldArray.Find(aControlId);
       
    62     if (uiField)
       
    63         {
       
    64         HBufC* prompt = NULL;
       
    65         if(uiField->ContactEditorField())
       
    66         	{
       
    67         	prompt = StringLoader::LoadLC(R_QTN_PHOB_QUERY_DELETE_ITEM, 
       
    68 						uiField->ContactEditorField()->FieldLabel());
       
    69         	}
       
    70         else if(uiField->ContactEditorUIField())
       
    71         	{
       
    72         	prompt = StringLoader::LoadLC(R_QTN_PHOB_QUERY_DELETE_ITEM, 
       
    73 						uiField->ContactEditorUIField()->FieldLabel());
       
    74         	}
       
    75 		CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
    76 		CleanupStack::PushL(dlg);
       
    77         dlg->SetPromptL(*prompt);
       
    78 		CleanupStack::Pop(); // dlg
       
    79         if(dlg->ExecuteLD(R_PBK2_GENERAL_CONFIRMATION_QUERY))
       
    80             {
       
    81             if(uiField->ContactEditorField())
       
    82             	{
       
    83             	MVPbkStoreContactField& storeField = 
       
    84 					uiField->ContactEditorField()->ContactField();
       
    85 		 
       
    86 				InformDeleteSpeedDialL(storeField);
       
    87             	}
       
    88                                      
       
    89             // Delete the field
       
    90             iFieldArray.RemoveField(*uiField);
       
    91             result = ETrue;
       
    92             }
       
    93         CleanupStack::PopAndDestroy(prompt);
       
    94         }
       
    95     return result;
       
    96     }
       
    97 
       
    98 // --------------------------------------------------------------------------
       
    99 // TPbk2DeleteItemManager::InformDeleteSpeedDialL
       
   100 // --------------------------------------------------------------------------
       
   101 //
       
   102 inline void TPbk2DeleteItemManager::InformDeleteSpeedDialL
       
   103         ( const MVPbkStoreContactField& storeField ) const
       
   104     {
       
   105     // Utilise attribute manager to find out does
       
   106     // the contact field have a speed dial defined
       
   107     TBool hasSpeedDial = EFalse;
       
   108     if( iAppServices )
       
   109         {
       
   110         hasSpeedDial = iAppServices->ContactManager().ContactAttributeManagerL().HasFieldAttributeL
       
   111 			( CVPbkSpeedDialAttribute::Uid(), storeField );
       
   112         }
       
   113     else
       
   114         {
       
   115         hasSpeedDial = Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   116             ContactManager().ContactAttributeManagerL().HasFieldAttributeL
       
   117                 ( CVPbkSpeedDialAttribute::Uid(), storeField );
       
   118         }
       
   119         
       
   120 	if ( hasSpeedDial )
       
   121         {
       
   122         HBufC* note = StringLoader::LoadLC
       
   123             ( R_QTN_PHOB_NOTE_SPEED_DIAL_DEL );
       
   124         CAknConfirmationNote* dlg = 
       
   125             new ( ELeave ) CAknConfirmationNote( ETrue );
       
   126         dlg->ExecuteLD( *note );
       
   127         CleanupStack::PopAndDestroy(); // note
       
   128         }
       
   129     }
       
   130 
       
   131 // End of File