|
1 /* |
|
2 * Copyright (c) 2005-2006 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: Generic Active Idle Content item and Content item iterator definitions. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef M_AICONTENTMODEL_H |
|
21 #define M_AICONTENTMODEL_H |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <libc/stddef.h> // For wchar_t |
|
25 |
|
26 /** |
|
27 * Maximum length for a content item textual id. |
|
28 * |
|
29 * @see TAiContentItem::id |
|
30 */ |
|
31 const TInt KAiContentIdMaxLength = 255; |
|
32 |
|
33 /** |
|
34 * Maximum length for content type. |
|
35 * |
|
36 * @see TAiContentItem::type |
|
37 */ |
|
38 const TInt KAiContentTypeMaxLength = 255; |
|
39 |
|
40 /** |
|
41 * Null value for content id. Plug-in content model should never use this id |
|
42 * value in its content model. |
|
43 */ |
|
44 const TInt KAiNullContentId = KErrNotFound; |
|
45 |
|
46 /** |
|
47 * Encapsulates metadata of single plug-ins content item. The class is used |
|
48 * as building block for the plug-ins content model, abstracts content |
|
49 * selector, content reference and event. |
|
50 */ |
|
51 struct TAiContentItem |
|
52 { |
|
53 /** |
|
54 * Plug-in specific id of this content item. |
|
55 */ |
|
56 TInt id; |
|
57 |
|
58 /** |
|
59 * Textual id of this content item. Used for binding content items to |
|
60 * UI elements. |
|
61 * |
|
62 * @see KAiContentIdMaxLength |
|
63 */ |
|
64 const wchar_t* cid; |
|
65 |
|
66 /** |
|
67 * Content item data MIME type. For example "text/plain" for textual |
|
68 * content. |
|
69 * |
|
70 * @see KAiContentTypeMaxLength |
|
71 */ |
|
72 const char* type; |
|
73 }; |
|
74 |
|
75 /** |
|
76 * Helper function for accessing Content item textual id TAiContentItem::cid. |
|
77 * |
|
78 * This function's performance is relative to O(N) where N is the length of |
|
79 * the textual id in characters. If the id of the same content item is accessed |
|
80 * repeatedly (for example in a loop) store the returned id in a local TPtrC |
|
81 * variable instead of calling this function repeatedly. |
|
82 * |
|
83 * @param aContentItem content item whose textual id to return. |
|
84 * @return textual id of aContentItem as a descriptor. |
|
85 */ |
|
86 inline TPtrC16 ContentCid( const TAiContentItem& aContentItem ) |
|
87 { |
|
88 return TPtrC16( (const TText16*) aContentItem.cid ); |
|
89 } |
|
90 |
|
91 /** |
|
92 * Helper function for accessing Content item data type TAiContentItem::type. |
|
93 * |
|
94 * This function's performance is relative to O(N) where N is the length of |
|
95 * the type name in characters. If the type of the same content item is accessed |
|
96 * repeatedly (for example in a loop) store the returned type in a local TPtrC8 |
|
97 * variable instead of calling this function repeatedly. |
|
98 * |
|
99 * @param aContentItem content item whose type to return. |
|
100 * @return data type of aContentItem as a descriptor. |
|
101 */ |
|
102 inline TPtrC8 ContentType( const TAiContentItem& aContentItem ) |
|
103 { |
|
104 return TPtrC8( (const TText8*) aContentItem.type ); |
|
105 } |
|
106 |
|
107 |
|
108 /** |
|
109 * Mime type for passing bitmap content data. |
|
110 * The content data should contain a packaged CGulIcon object pointer when this |
|
111 * MIME tyoe is used. |
|
112 * |
|
113 * @see CGulIcon |
|
114 * @see MAiContentObserver::PublishPtr |
|
115 */ |
|
116 const char KAiContentTypeBitmap[] = "image/x-s60-bitmap"; |
|
117 |
|
118 /** |
|
119 * MIME type for passing textual data. |
|
120 * |
|
121 * @see MAiContentObserver::Publish |
|
122 */ |
|
123 const char KAiContentTypeText[] = "text/plain"; |
|
124 |
|
125 |
|
126 /** |
|
127 * Abstract interface which provides services to iterate content items |
|
128 * supported by the plug-in. Only used by the Active Idle Framework. |
|
129 * Each plug-in must provide implementation of interface to access: |
|
130 * content selectors, content references, and events. Instances of interface |
|
131 * are accessed through method GetProperty in interface CAiContentPublisher. |
|
132 * |
|
133 * @since S60 3.2 |
|
134 */ |
|
135 class MAiContentItemIterator |
|
136 { |
|
137 public: |
|
138 /** |
|
139 * Tests if this enumeration contains more elements. |
|
140 * |
|
141 * @return ETrue if this iterator object contains at least one more |
|
142 * element to provide; EFalse otherwise. |
|
143 */ |
|
144 virtual TBool HasNext() const = 0; |
|
145 |
|
146 /** |
|
147 * Returns the next element of this iterator if this enumeration object |
|
148 * has at least one more element to provide. |
|
149 * |
|
150 * @return The next element. |
|
151 * @leave KErrOverflow if iterator is at the end of range. |
|
152 */ |
|
153 virtual const TAiContentItem& NextL() = 0; |
|
154 |
|
155 /** |
|
156 * Returns the first element of this iterator which matches aId. |
|
157 * |
|
158 * @param aId - unique identification of the content item, corresponds |
|
159 * to TAiContentItem::id. |
|
160 * @return The first element matching aId. |
|
161 * @leave KErrNotFound if element matching aId is not found from the |
|
162 * complete iterator range. |
|
163 */ |
|
164 virtual const TAiContentItem& ItemL( TInt aId ) const = 0; |
|
165 |
|
166 /** |
|
167 * Returns the first element of this iterator which matches aCid. |
|
168 * |
|
169 * @param aCid - textual identification of the content item, corresponds |
|
170 * to TAiContentItem::cid. |
|
171 * @return The first element matching aCid. |
|
172 * @leave KErrNotFound if element matching aCid is not found from the |
|
173 * complete iterator range. |
|
174 */ |
|
175 virtual const TAiContentItem& ItemL( const TDesC& aCid ) const = 0; |
|
176 |
|
177 /** |
|
178 * Resets iterator to the first item in the list. |
|
179 */ |
|
180 virtual void Reset() = 0; |
|
181 |
|
182 /** |
|
183 * Release the iterator. |
|
184 */ |
|
185 virtual void Release() = 0; |
|
186 |
|
187 protected: |
|
188 /** |
|
189 * Protected destructor prevents deletion through this interface. |
|
190 */ |
|
191 ~MAiContentItemIterator() { } |
|
192 |
|
193 private: |
|
194 /** |
|
195 * Required to implement CleanupReleasePushL(MAiContentItemIterator*). |
|
196 */ |
|
197 static void Cleanup(TAny* aSelf); |
|
198 friend void CleanupReleasePushL(MAiContentItemIterator*); |
|
199 }; |
|
200 |
|
201 /** |
|
202 * Helper function which calls MAiContentItemIterator::Release() with NULL |
|
203 * checking. Especially useful in destructors. |
|
204 */ |
|
205 inline void Release(MAiContentItemIterator* aObj) |
|
206 { |
|
207 if (aObj) aObj->Release(); |
|
208 } |
|
209 |
|
210 /** |
|
211 * |
|
212 */ |
|
213 inline void CleanupReleasePushL(MAiContentItemIterator* aObj) |
|
214 { |
|
215 CleanupStack::PushL( |
|
216 TCleanupItem(&MAiContentItemIterator::Cleanup, aObj) ); |
|
217 } |
|
218 |
|
219 /** |
|
220 * Required to implement CleanupReleasePushL(MAiContentItemIterator*). |
|
221 * Inline to avoid problems with multiple definitions. |
|
222 */ |
|
223 inline void MAiContentItemIterator::Cleanup(TAny* aSelf) |
|
224 { |
|
225 ::Release(static_cast<MAiContentItemIterator*>(aSelf)); |
|
226 } |
|
227 |
|
228 |
|
229 |
|
230 #endif // M_AICONTENTMODEL_H |