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.
20 #ifndef __CPbkViewState_H__
21 #define __CPbkViewState_H__
24 #include <e32base.h> // CBase
25 #include <cntdef.h> // TContactItemId, CContactIdArray
27 // FORWARD DECLARATIONS
30 class CPbkFieldDataArray;
35 * Generic Phonebook view state class. Class can be used to pass parameters
36 * the Phonebook application when launching the application with the symbian
37 * view launching mechanism.
39 class CPbkViewState : public CBase
59 /// Focus the first item in list views
61 /// Focus the last item in list views
63 /// Reset state to the view's initial state
64 EInitialized = 0x0004,
65 /// Send application to background
66 ESendToBackground = 0x0008
69 public: // Constructors and destructor
71 * Creates and returns a new instance of this class.
73 IMPORT_C static CPbkViewState* NewL();
76 * Like NewL(), but leaves the object on the cleanup stack
79 IMPORT_C static CPbkViewState* NewLC();
82 * Creates and returns a new instance of this class initialized
84 * @param aStream A view state stream to internalize.
86 IMPORT_C static CPbkViewState* NewL(RReadStream& aStream);
89 * Like NewL(RReadStream& aStream) but leaves the object on
91 * @see NewL(RReadStream& aStream)
92 * @param aStream A view state stream to internalize.
94 IMPORT_C static CPbkViewState* NewLC(RReadStream& aStream);
97 * Creates and returns a new instance of this class initialized
99 * @param aBuf A view state buffer to internalize.
101 IMPORT_C static CPbkViewState* NewL(const TDesC8& aBuf);
104 * Like NewL(const TDesC8& aBuf) but leaves the object on
106 * @see NewL(const TDesC8& aBuf)
107 * @param aBuf A view state buffer to internalize.
109 IMPORT_C static CPbkViewState* NewLC(const TDesC8& aBuf);
118 * Returns the message uid for use with view server messages.
120 IMPORT_C static TUid Uid();
123 * Returns id of the focused contact.
124 * @return Contact item id of the focused contact, KNullContactId if not set.
126 IMPORT_C TContactItemId FocusedContactId() const;
129 * Returns id of the topmost contact.
130 * @return Contact item id of the top contact, KNullContactId if not set.
132 IMPORT_C TContactItemId TopContactId() const;
135 * Returns const array of marked contacts ids, NULL if not set.
136 * @return Contact id array of the marked contacts, NULL if not set.
138 IMPORT_C const CContactIdArray* MarkedContactIds() const;
141 * Returns array of marked contacts ids, NULL if not set. Owmership not
143 * @return Contact id array of the marked contacts, NULL if not set.
145 IMPORT_C CContactIdArray* MarkedContactIds();
148 * Returns index of the focused field (field is from FocusedContactId()),
149 * -1 when no field focused.
150 * @return Index of the focused field, -1 if no field is focused.
152 IMPORT_C TInt FocusedFieldIndex() const;
155 * Returns index of the topmost field (field is from FocusedContactId()),
156 * -1 when no topmost field.
157 * @return Index of the topmost field, -1 if no topmost field.
159 IMPORT_C TInt TopFieldIndex() const;
162 * Returns field data array, NULL if not set.
163 * @return Field data array object, NULL if not set.
165 IMPORT_C CPbkFieldDataArray* FieldDataArray() const;
168 * Returns the focused contact id's parent, KNullContactId if not set.
169 * @return Focused contact id's parent, KNullContactId if not set.
171 IMPORT_C TContactItemId ParentContactId() const;
174 * Returns the view state flags. See CPbkViewState::TFlags.
175 * @return View state object flags
177 IMPORT_C TUint Flags() const;
181 * Sets id of the focused contact to aId.
182 * @param aId Sets the focused contact id.
184 IMPORT_C void SetFocusedContactId(TContactItemId aId);
187 * Sets id of the topmost contact to aId.
188 * @param aId Sets the topmost contact id.
190 IMPORT_C void SetTopContactId(TContactItemId aId);
193 * Sets the array of marked contact ids to aArray. Destroys previous
194 * array and takes ownership of aArray.
195 * @param aArray Sets the marked contact ids.
197 IMPORT_C void SetMarkedContactIds(CContactIdArray* aArray);
200 * Sets index of the focused field to aIndex (field from
201 * FocusedContactId()), -1 when no field focused.
202 * @param aIndex Sets focused field index.
204 IMPORT_C void SetFocusedFieldIndex(TInt aIndex);
207 * Sets index of the topmost field to aIndex (field from
208 * FocusedContactId()), -1 when no topmost field.
209 * @param aIndex Sets the topmost field index.
211 IMPORT_C void SetTopFieldIndex(TInt aIndex);
214 * Sets field data array to aArray. Destroys previous array
215 * and takes ownership of aArray.
216 * @param aFieldDataArray Sets the field data array.
218 IMPORT_C void SetFieldDataArray(CPbkFieldDataArray* aFieldDataArray);
221 * Reset this state to empty.
223 IMPORT_C void Reset();
226 * Sets the focused contact ids parent contact id.
227 * @param aParentContactId Sets the contact ids parent id.
229 IMPORT_C void SetParentContactId(TContactItemId aParentContactId);
232 * Sets the view state flags.
233 * @param aFlags Sets the view state parameters. See CPbkViewState::TFlags.
235 IMPORT_C void SetFlags(TUint aFlags);
238 * Merges another view state to this view state by setting values from the
239 * parameter and overriding any previous values in this state.
241 * @param aOtherState The state to merge to this state. The
242 * properties which have a value in aOtherState
243 * override properties in this object. The aOtherState
244 * object may be modified by this function.
246 /*IMPORT_C*/ void MergeViewState(CPbkViewState& aOtherState);
248 public: // Stream support
250 * Packages and returns this object in a buffer. Caller is responsible
251 * of deleting the buffer.
252 * @return Packaged state in a buffer.
254 IMPORT_C HBufC8* PackL() const;
257 * Like PackL, but leaves the buffer on the cleanup stack.
259 * @return Packaged state in a buffer.
261 IMPORT_C HBufC8* PackLC() const;
264 * Sets this state from aPack previously created with PackL.
267 * @param aPack Previously packaged state.
269 IMPORT_C void UnpackL(const TDesC8& aPack);
272 * Externalizes this object to aStream.
274 * @param aSteam Stream where to externalize this objects state.
276 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
279 * Internalizes this object from aStream.
281 * @param aStream A stream from where this objects state can be internalized from.
283 IMPORT_C void InternalizeL(RReadStream& aStream);
285 public: // Support functions
286 IMPORT_C TBool operator==(const CPbkViewState& aRhs) const;
288 private: // Implementation
292 /// Own: Id of the focused contact
293 TContactItemId iFocusedContactId;
294 /// Own: Id of the topmost contact
295 TContactItemId iTopContactId;
296 /// Own: Index of the focused field
297 TInt iFocusedFieldIndex;
298 /// Own: Index of the top field
300 /// Own: Array of marked contacts
301 CContactIdArray* iMarkedContactIds;
302 /// Own: Field data array
303 CPbkFieldDataArray* iFieldDataArray;
304 /// Own: Id of the focused contacts parent
305 TContactItemId iParentContactId;
309 private: // const static data
310 static const TUid KUid;
315 ** View state binary stream format **
317 - View parameter UID is 0x101f4ccf
319 - Format of the stream in (slightly freeform) BNF:
321 <stream> ::= <command>+
322 <command> ::= Int8(opcode) parameters
323 <opcode> ::= EEnd | EFocusedContactId | ETopContactId | EMarkedContactIds |
324 EFocusedFieldIndex | ETopFieldIndex | EFieldDataArray
325 <command> ::= EEnd // no further commands are read after EEnd. EEnd is not mandatory in a stream.
326 <command> ::= EFocusedContactId Int32(TContactItemId)
327 <command> ::= ETopContactId Int32(TContactItemId)
328 <command> ::= EMarkedContactIds (Int32(count) { Int32(TContactItemId) }) // count is count TContactItemIds
329 <command> ::= EFocusedFieldIndex Int32(index)
330 <command> ::= ETopFieldIndex Int32(index)
331 <command> ::= EFieldDataArray <contactdata>
332 <command> ::= EParentContactId Int32(TContactItemId)
334 <contactdata> ::= Int32(count) { fielddata } // count is count of fieldatas
335 <fielddata> ::= <fieldtype> data
336 <fieldtype> ::= ETypeText | ETypeTime
337 <fielddata> ::= ETypeText (Int32(length) text) // length is length of text in chars, text is unicode
338 <fielddata> ::= ETypeTime (Int32(high) Int32(low)) // high and low words of a TTime's internal Int64
342 EFocusedContactId = 1,
344 EMarkedContactIds = 3,
345 EFocusedFieldIndex = 4,
351 Activate Phonebook's contact info view to show contact with id 5 and field
354 // Write parameters in a buffer
356 RDesWriteStream stream(param);
358 param.WriteInt8L(1); // opcode EFocusedContactId
359 param.WriteInt32L(5); // Contact id 5
360 param.WriteInt8L(4); // opcode EFocusedFieldIndex
361 param.WriteInt32L(3); // field index 3
363 CleanupStack::PopAndDestroy(); // stream
365 // Make view id with Phonebook's app UID3 and Contact Info View's id
366 const TVwsViewId viewId(0x101f4cce, 4);
369 AppUi()->ActivateViewL(viewId, TUid::Uid(0x101f4ccf), param);
372 - Same example as above, now using CPbkViewState:
374 #include <CPbkViewState.h> // need also to add PbkView.lib into projects .mmp
375 #include <PbkUID.h> // Phonebook UIDs
377 CPbkViewState* pbkViewParam = CPbkViewState::NewLC();
378 pbkViewParam->SetFocusedContactId(5);
379 pbkViewParam->SetFocusedFieldIndex(3);
380 HBufC8* paramBuf = pbkViewParam->PackLC();
382 // Make view id with Phonebook's app UID3 and Contact Info View's id
383 const TVwsViewId viewId(KPbkUID3, 4);
386 AppUi()->ActivateViewL(viewId, CPbkViewState::Uid(), *paramBuf);
389 CleanupStack::PopAndDestroy(2); // paramBuf, pbkViewParam
391 - The latter example is cleaner, but using CPbkViewState from your
392 application means that your application will have a dependency to
393 CPbkViewState.h and PbkView.lib at compile time and to PbkView.dll at
398 #endif // __CPbkViewState_H__