phonebookui/Phonebook/View/src/CPbkContactEditorEditContact.cpp
changeset 0 e686773b3f54
child 68 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *           Phonebook Contact editor edit contact strategy.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkContactEditorEditContact.h"
       
    22 #include <coemain.h>
       
    23 #include <coehelp.h>
       
    24 #include <cntdb.h>
       
    25 #include <eikmenup.h>
       
    26 #include <bldvariant.hrh>
       
    27 #include <featmgr.h>
       
    28 #include "CPbkContactEngine.h"
       
    29 #include "CPbkContactItem.h"
       
    30 #include "CPbkDeleteContactQuery.h"
       
    31 #include <CPbkFFSCheck.h>
       
    32 #include <PbkView.rsg>
       
    33 #include <cshelp/phob.hlp.hrh>
       
    34 
       
    35 
       
    36 /// State flag values 
       
    37 enum TStateFlag
       
    38     {
       
    39     EInitialized,
       
    40     EContactSaved,
       
    41     EModified,
       
    42 	EContactDeleted
       
    43     };
       
    44 
       
    45 // ================= MEMBER FUNCTIONS =======================
       
    46 
       
    47 inline CPbkContactEditorEditContact::CPbkContactEditorEditContact
       
    48 		(CPbkContactEngine& aEngine,
       
    49 		CPbkContactItem& aContactItem) :
       
    50 	iEngine(aEngine),
       
    51 	iContactItem(aContactItem)
       
    52 	{
       
    53 	}
       
    54 
       
    55 inline void CPbkContactEditorEditContact::ConstructL()
       
    56 	{
       
    57 	iFFSCheck = CPbkFFSCheck::NewL(CCoeEnv::Static());
       
    58 	}
       
    59 
       
    60 CPbkContactEditorEditContact* CPbkContactEditorEditContact::NewL
       
    61 		(CPbkContactEngine& aEngine,
       
    62 		CPbkContactItem& aContactItem)
       
    63 	{
       
    64 	CPbkContactEditorEditContact* self = new(ELeave) CPbkContactEditorEditContact(aEngine, aContactItem);
       
    65 	CleanupStack::PushL(self);
       
    66 	self->ConstructL();
       
    67 	CleanupStack::Pop(self);
       
    68 	return self;
       
    69 	}
       
    70 
       
    71 CPbkContactEditorEditContact::~CPbkContactEditorEditContact()
       
    72 	{
       
    73     delete iFFSCheck;
       
    74 	}
       
    75 
       
    76 TContactItemId CPbkContactEditorEditContact::SaveContactL()
       
    77 	{
       
    78 	// If contact was deleted, return immediatly with KNullContactId
       
    79 	if (iStateFlags.IsSet(EContactDeleted))
       
    80 		{
       
    81 		return KNullContactId;
       
    82 		}
       
    83 
       
    84     // Check that free FFS space is above critical level before saving to
       
    85     // database
       
    86     if (iStateFlags.IsSet(EModified) && !iStateFlags.IsSet(EContactSaved) && 
       
    87         iStateFlags.IsSet(EInitialized) && iFFSCheck->FFSClCheckL())
       
    88         {
       
    89         iEngine.CommitContactL(iContactItem, ETrue);
       
    90         iStateFlags.Clear(EModified);		
       
    91         }
       
    92     iStateFlags.Set(EContactSaved);
       
    93 
       
    94     return iContactItem.Id();
       
    95 	}
       
    96 
       
    97 void CPbkContactEditorEditContact::GetHelpContext
       
    98 		(TCoeHelpContext& aContext) const
       
    99 	{
       
   100     aContext.iContext = KPHOB_HLP_EDIT_ENTRY;
       
   101 	}
       
   102 
       
   103 void CPbkContactEditorEditContact::SetStateModified()
       
   104     {
       
   105     iStateFlags.Set(EModified);
       
   106     }
       
   107 
       
   108 void CPbkContactEditorEditContact::SetStateInitialized()
       
   109     {
       
   110     iStateFlags.Set(EInitialized);
       
   111     }
       
   112 
       
   113 void CPbkContactEditorEditContact::DeleteContactL()
       
   114 	{
       
   115     // Offer to delete the current contact
       
   116     const TContactItemId contactId = iContactItem.Id();
       
   117     CPbkDeleteContactQuery* dlg = CPbkDeleteContactQuery::NewLC();
       
   118     if (dlg->RunLD(iEngine, contactId))
       
   119         {
       
   120 	    iEngine.CloseContactL(contactId);
       
   121 		iEngine.DeleteContactL(contactId);
       
   122     	iStateFlags.Set(EContactDeleted);
       
   123 		}
       
   124 	}
       
   125 
       
   126 const TDesC& CPbkContactEditorEditContact::DefaultTitle() const
       
   127 	{
       
   128 	return iEngine.UnnamedTitle();
       
   129 	}
       
   130 
       
   131 void CPbkContactEditorEditContact::DynInitMenuPaneL
       
   132         (TInt aResourceId, 
       
   133         CEikMenuPane* aMenuPane)
       
   134     {
       
   135     if (aResourceId == R_CONTACTEDITOR_MENUPANE)
       
   136         {
       
   137         if (!FeatureManager::FeatureSupported(KFeatureIdHelp)) 
       
   138             {
       
   139             // remove non-supported help from menu
       
   140             aMenuPane->SetItemDimmed(EAknCmdHelp, ETrue);
       
   141             }
       
   142         }
       
   143     }
       
   144 
       
   145 //  End of File