2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Phonebook contact editor dialog.
20 #ifndef __CPbkContactEditorDlg_H__
21 #define __CPbkContactEditorDlg_H__
24 #include <AknForm.h> // CAknForm
25 #include <cntdef.h> // TContactItemId
26 #include <babitflags.h> // TBitFlags
29 // FORWARD DECLARATIONS
31 class CPbkContextPaneIcon;
32 class CPbkThumbnailPopup;
33 class CPbkThumbnailCmd;
34 class CPbkContactEditorFieldArray;
35 class CPbkContactEngine;
36 class CPbkContactItem;
37 class MPbkContactEditorStrategy;
38 class MPbkEditorOkToExitCallback;
39 class CAknNavigationControlContainer;
45 * A contact editing dialog implementation. This class can be used
46 * to construct an UI editor dialog that is specifically tailored
47 * to edit contacts in a similar fashion as in the platform contacts
50 class CPbkContactEditorDlg :
53 public: // Constructors and destructor
55 * Creates an instance of an editor dialog for an aContactItem.
57 * @param aEngine Phonebook engine
58 * @param aContactItem Contact item to edit
59 * @param aIsNewContact Set to ETrue if aContactItem is a new contact
60 * (not yet in the database)
61 * @param aFocusIndex Optional index of field to focus initially,
62 * default behaviour is to focus the topmost field.
63 * @param aEdited If ETrue sets the contact initially to the edited state.
64 * Use when some data is added to aContactItem
65 * that needs to be saved even if user edits
66 * nothing. Default behaviour is to set the contact to
68 * @return A new dialog object.
70 IMPORT_C static CPbkContactEditorDlg* NewL
71 (CPbkContactEngine& aEngine,
72 CPbkContactItem& aContactItem,
75 TBool aEdited=EFalse);
80 ~CPbkContactEditorDlg();
84 * Sets aSelfPtr to NULL when this dialog is destroyed.
85 * @precond Precondition: !aSelfPtr || *aSelfPtr==this
87 IMPORT_C void ResetWhenDestroyed(CPbkContactEditorDlg** aSelfPtr);
90 * Runs the dialog. This object is destroyed when this function
92 * NOTE: Current status pane layout is replaced with the
93 * Phonebook one. Restoring the original pane is left to be
94 * the responsibility of the caller.
96 * @return The id of the saved contact. KNullContactId if not saved.
97 * Please note that the contact item (aContactItem passed
98 * to NewL) might be modified even if it is not saved to the
101 IMPORT_C TContactItemId ExecuteLD();
104 * Hides the 'Exit' command from the options menu. This must be called
105 * before calling ExecuteLD.
107 IMPORT_C void HideExitCommand();
110 * Sets help context. There are many applications using contact editor
111 * and they may have an own help topic to be shown, when editor's help
112 * is launched. With this command it's possible to define the used
113 * help content. If not called after, uses Phonebook's own help context
115 * @param aContext Help context to use
117 IMPORT_C void SetHelpContext(TCoeHelpContext aContext);
120 * Sets exit callback. The callback is called before exit happens.
121 * If the callback returns EFalse, the exit process is cancelled.
122 * @param aCallback Exit callback
124 IMPORT_C void SetExitCallback(MPbkEditorOkToExitCallback* aCallback);
127 * Sets the exit command in the options menu to forward aCommandId to the
128 * application framework. Allows clients to process and capture the exit
129 * command in the application exit situation.
130 * @param aCommandId Command id to send to the framework when the exit
133 IMPORT_C void SetExitCommandId(TInt aCommandId);
135 private: // from CCoeControl
136 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
137 void GetHelpContext(TCoeHelpContext& aContext) const;
139 private: // Command handlers
142 void CmdEditItemLabelL();
144 void CmdDeleteItemL();
145 void CmdFetchThumbnailL();
146 void CmdRemoveThumbnailL();
148 private: // From CAknForm
149 void PreLayoutDynInitL();
150 void PostLayoutDynInitL();
151 void SetInitialCurrentLine();
152 void ProcessCommandL(TInt aCommandId);
153 void DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane);
154 TBool OkToExitL(TInt aKeycode);
155 void HandleControlStateChangeL(TInt aControlId);
157 protected: // Constructors
159 (CPbkContactEngine& aEngine,
160 CPbkContactItem& aContactItem,
162 void BaseConstructL(TBool aIsNewContact, TBool aEdited);
164 protected: // Implementation
165 void StoreTitlePaneTextL();
166 void ConstructContextMenuL();
167 void ConstructNaviPaneL();
168 TBool IsNewContact() const;
169 void UpdateTitlePaneL();
170 void CloseAllPopups();
171 TBool ContactAlreadyExistsL();
172 TBool DuplicateNameMatchL(CContactIdArray* aIdArray);
173 TBool CheckForDuplicateEntryL();
174 void ReloadThumbnailL();
176 void WriteContactToDbL();
178 /// State flag values for CPbkContactEditorDlg
181 EHideExit, // Hide exit
182 EEscKeyReceived, /// Espace key received
183 EUnderDestruction // The dialog is under destruction
187 /// Ref: Contact item under editing
188 CPbkContactItem& iContactItem;
189 /// Own: Contact editor field manager
190 CPbkContactEditorFieldArray* iFieldManager;
193 /// Ref; Contact engine
194 CPbkContactEngine& iEngine;
195 /// Own: Index of field to focus initially
198 mutable TBitFlags iStateFlags;
199 /// Ref: pointer to ExecuteLD return value
200 TContactItemId* iSavedContactPtr;
201 /// Ref: application's title pane
202 CAknTitlePane* iTitlePane;
203 /// Own: Title pane text to restore on exit
204 HBufC* iStoredTitlePaneText;
205 /// Own: Phonebook context pane icon
206 CPbkContextPaneIcon* iContextPaneIcon;
207 /// Own: Thumbnail image handler
208 CPbkThumbnailPopup* iThumbnailHandler;
209 /// Own: context menu bar
210 CEikMenuBar* iContextMenuBar;
211 /// Own: Thumbnail command handler
212 CPbkThumbnailCmd* iThumbnailCmd;
213 /// Own: editor dialog strategy
214 MPbkContactEditorStrategy* iEditorStrategy;
216 * Ref: self pointer for easier leave handling
217 * @invariant !iSelfPtr || *iSelfPtr==this
219 CPbkContactEditorDlg** iSelfPtr;
221 /// Own: for adding extensions
222 CExtension* iExtension;
223 /// Own: the help context to use
224 TCoeHelpContext iHelpContext;
225 /// Ref: Contact editor exit callback
226 MPbkEditorOkToExitCallback* iExitCallback;
227 /// Own: exit command id
229 /// Ref: status pane handle
230 CAknNavigationControlContainer* iNaviContainer;
233 friend class CExtension;
236 #endif // __CPbkContactEditorDlg_H__