2 * Copyright (c) 2004-2007 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.
14 * Description: An interface for store contacts.
19 #ifndef MVPBKSTORECONTACT_H
20 #define MVPBKSTORECONTACT_H
25 #include <mvpbkbasecontact.h>
26 #include <mvpbkviewcontact.h>
28 // Includes needed for covariant return types
29 #include <mvpbkstorecontactfieldcollection.h>
31 // FORWARD DECLARATIONS
32 class MVPbkContactStore;
33 class MVPbkContactObserver;
34 class MVPbkStoreContactField;
36 class MVPbkContactLinkArray;
37 class MVPbkContactGroup;
38 class MVPbkStoreContactProperties;
41 const TInt KVPbkStoreContactUnlimitedNumber = -1;
43 //Use this UID to access contact store extension 2.
44 // Used as a parameter to ContactStoreExtension() method.
45 const TUid KMVPbkStoreContactExtension2Uid = { 2 };
49 * An interface for store contacts.
51 * A store contact is a contact that includes all the fields of
52 * the contact. For this reason it usually contains more data compared
53 * to the corresponding view contact. It can contain all types of fields that
54 * are supported by the its parent store.
56 * The store contact can be edited if it's not read-only. The client must
57 * first lock the existing contact then edit it and finally commit the changes.
59 * @see MVPbkContactStore
60 * @see MVPbkViewContact
62 class MVPbkStoreContact : public MVPbkBaseContact,
63 public MVPbkObjectHierarchy
66 virtual ~MVPbkStoreContact() { }
68 public: // From MVPbkBaseContact (covariant return types)
69 const MVPbkStoreContactFieldCollection& Fields() const =0;
71 public: // New functions
73 * Pushes an item on the cleanup stack.
75 * Clients must use either this function or CleanupDeletePushL
78 * CleanupStack::PushL(TAny*) must not be used because the virtual
79 * destructor of M-class won't be called.
80 * This function should be used to make sure that the virtual destructor
81 * of this object is called when popped and destroyed from the cleanup
87 * Returns this contact's parent store.
89 * @return The parent store of the contact.
91 virtual MVPbkContactStore& ParentStore() const =0;
94 * Returns this contact's fields (read-write).
96 * @return A collection of contact fields.
98 virtual MVPbkStoreContactFieldCollection& Fields() =0;
101 * Creates a new field for this contact.
103 * The new field must be added to the contact using AddFieldL.
105 * @param aFieldType A type of the field to create. Must be found in
106 * ParentStore().SupportedFieldTypes().
107 * @return A new field object. The returned object is left on the
109 * @exception KErrNotSupported if the field type is not supported.
110 * @exception KErrAccessDenied if the contact can not be modified.
112 virtual MVPbkStoreContactField* CreateFieldLC(
113 const MVPbkFieldType& aFieldType) const =0;
116 * Adds a new field to the contact.
118 * The field must be previously created with CreateFieldLC and
119 * it must NOT be used after adding.
121 * If the client needs the field after adding it must be retrieved
124 * @param aField A new field that was created using CreateFieldLC.
125 * This object takes ownership of the field.
126 * @precond aField must not be NULL or
127 * VPbkError::Panic(VPbkError::ENullContactField) is raised.
128 * @precond aField must be returned from this->CreateFieldLC or
129 * VPbkError::Panic(VPbkError::EInvalidContactField) panic is raised.
130 * @postcond this->Fields().FieldCount() ==
131 * old(this->Fields().FieldCount()) + 1
132 * @return The index of the new field in the field collection.
133 * @exception KErrAccessDenied if the contact can not be modified.
135 virtual TInt AddFieldL(MVPbkStoreContactField* aField) =0;
138 * Removes a field from the contact.
140 * @param aIndex A zero-based index of the field to remove.
141 * @precond aIndex >= 0 && aIndex < FieldCount().
142 * Panics with VPbkError::EInvalidFieldIndex.
143 * @precond The contact is not read-only otherwise panics with
144 * VPbkError::EInvalidAccessToReadOnlyContact.
145 * @postcond this->Fields().FieldCount() ==
146 * old(this->Fields().FieldCount()) - 1
148 virtual void RemoveField(TInt aIndex) =0;
151 * Removes all the fields from the contact.
153 * @precond The contact is not read-only otherwise panics with
154 * VPbkError::EInvalidAccessToReadOnlyContact.
155 * @postcond this->Fields().FieldCount() == 0
157 virtual void RemoveAllFields() =0;
160 * Locks this contact for modification asynchronously.
162 * Once the observer is notified this contact is locked and cab
165 * @param aObserver The observer to call back when the operation
166 * completes. The observer will not be called if this
168 * @exception KErrInUse If another asynchronous operation is
169 * already in progress.
170 * @exception KErrAccessDenied if the contact can not be modified.
172 virtual void LockL(MVPbkContactObserver& aObserver) const =0;
175 * Saves the contact to its associated store asynchronously.
177 * LockL must have been called before commit if this is
178 * an existing contact. Otherwise ContactOperationFailed is called
179 * with KErrAccessDenied.
181 * @param aObserver The observer to call back when this operation
182 * completes. The observer will not be called if this
184 * @exception KErrInUse If another asynchronous operation is already
186 * @exception KErrAccessDenied if the contact can not be modified.
188 virtual void CommitL(MVPbkContactObserver& aObserver) const =0;
191 * Returns the identifiers of the groups that the contact
194 * @return The groups that this contact belongs to.
196 virtual MVPbkContactLinkArray* GroupsJoinedLC() const =0;
199 * Returns the group interface of the store contact if this contact
201 * If this contact is not a group, NULL is returned.
203 * @return The group interface or NULL.
205 virtual MVPbkContactGroup* Group() =0;
208 * Returns the maximum amount of fields of given type that can be
209 * inserted to the contact.
211 * E.g. A USIM ADN contact can have 1 or more phone numbers but there
212 * is a limit that the store in USIM defines.
213 * On the other hand the contact in the Contacts Model data base
214 * doesn't have limits.
216 * @param aType The field type of the field
217 * @return The maximum amount fields of given type in the contact
218 * or KVPbkStoreContactUnlimitedNumber it there is no limit
219 * set by the store contact
221 virtual TInt MaxNumberOfFieldL(const MVPbkFieldType& aType) const =0;
225 * Returns an extension point for this interface or NULL.
227 * @param aExtensionUid no extensions defined currently.
228 * @return An extension point for this interface or NULL.
230 virtual TAny* StoreContactExtension(TUid /*aExtensionUid*/)
233 public: // from MVPbkBaseContact
235 virtual TBool IsSame(const MVPbkBaseContact& aOtherContact) const
237 return aOtherContact.IsSame(*this);
241 virtual TBool IsSame(const MVPbkViewContact& aOtherContact) const
243 return aOtherContact.IsSame(*this, &ContactStore());
249 inline void MVPbkStoreContact::PushL()
251 CleanupDeletePushL(this);
254 #endif // MVPBKSTORECONTACT_H