|
1 /* |
|
2 * Copyright (c) 2009 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: caentry.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QSharedDataPointer> |
|
19 #include <QDebug> |
|
20 #include <HbIcon> |
|
21 |
|
22 #include "caentry.h" |
|
23 #include "caentry_p.h" |
|
24 #include "caobjectadapter.h" |
|
25 #include "caiconcache.h" |
|
26 #include "caclienttest_global.h" |
|
27 |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 /*! |
|
32 * \class CaEntry |
|
33 * |
|
34 * \brief This abstract class describes particular entry. |
|
35 * |
|
36 * To create instance of CaEntry object, you have to use service's object's |
|
37 * createEntry() method. |
|
38 * |
|
39 * \example |
|
40 * \code |
|
41 * QSharedPointer<CaService> service = CaService::instance(); |
|
42 * // default you create item (ItemEntryRole) |
|
43 * CaEntry entry; |
|
44 * // to create CaEntry invoking setText() and setEntryTypeName() methods |
|
45 * is obligatoried |
|
46 * entry.setText("Text"); |
|
47 * entry.setEntryTypeName("TypeName"); |
|
48 * CaEntry * resultEntry = service->createEntry(entry); |
|
49 * ... |
|
50 * delete resultEntry; |
|
51 * ... |
|
52 * |
|
53 * // if you want create group, you should use entry role parametr |
|
54 * CaEntry entryGroup(GroupEntryRole); |
|
55 * ... |
|
56 * resultEntry = service->createEntry(entryGroup); |
|
57 * |
|
58 * \endcode |
|
59 */ |
|
60 |
|
61 /*! |
|
62 * Constructor. |
|
63 * \param entryRole entry's role. |
|
64 */ |
|
65 CaEntry::CaEntry(EntryRole entryRole) : |
|
66 m_d(new CaEntryPrivate(this)) |
|
67 { |
|
68 m_d->setRole(entryRole); |
|
69 } |
|
70 |
|
71 /*! |
|
72 * Copy constructor. |
|
73 * \param entry const reference to CaEntry. |
|
74 * |
|
75 * \code |
|
76 * ... |
|
77 * CaEntry * copyEntry( *resultEntry ); |
|
78 * \endcode |
|
79 */ |
|
80 CaEntry::CaEntry(const CaEntry &entry) : |
|
81 m_d(new CaEntryPrivate(this)) |
|
82 { |
|
83 *m_d = *(entry.m_d); |
|
84 } |
|
85 |
|
86 /*! |
|
87 Copy assignment operator. |
|
88 \param entry const reference to CaEntry. |
|
89 |
|
90 \retval reference to CaEntry. |
|
91 |
|
92 \code |
|
93 ... |
|
94 CaEntry * copyEntry; |
|
95 copyEntry = resultEntry; |
|
96 \endcode |
|
97 */ |
|
98 CaEntry &CaEntry::operator=(const CaEntry &entry) |
|
99 { |
|
100 if (this != &entry) { |
|
101 m_d = entry.m_d; |
|
102 } |
|
103 return *this; |
|
104 } |
|
105 |
|
106 /*! |
|
107 Destructor. |
|
108 */ |
|
109 CaEntry::~CaEntry() |
|
110 { |
|
111 |
|
112 } |
|
113 |
|
114 /*! |
|
115 Returns item id. |
|
116 \retval item id. |
|
117 |
|
118 \code |
|
119 ... |
|
120 // after create entry, we can get entry's id |
|
121 resultEntry = service->createEntry(entry); |
|
122 int entryId = resultEntry->id(); |
|
123 ... |
|
124 \endcode |
|
125 */ |
|
126 int CaEntry::id() const |
|
127 { |
|
128 return m_d->id(); |
|
129 } |
|
130 |
|
131 /*! |
|
132 Returns item name. |
|
133 \retval name of the item. |
|
134 |
|
135 \code |
|
136 ... |
|
137 QString entryText = resultEntry->text(); |
|
138 ... |
|
139 \endcode |
|
140 */ |
|
141 QString CaEntry::text() const |
|
142 { |
|
143 return m_d->text(); |
|
144 } |
|
145 |
|
146 /*! |
|
147 Sets name of the item. |
|
148 \param text new name of the item. |
|
149 |
|
150 \code |
|
151 ... |
|
152 QString entryText( QString("EntryText") ); |
|
153 resultEntry->setText( entryText); |
|
154 ... |
|
155 \endcode |
|
156 */ |
|
157 void CaEntry::setText(const QString &text) |
|
158 { |
|
159 m_d->setText(text); |
|
160 } |
|
161 |
|
162 /*! |
|
163 Returns item description. |
|
164 \retval description of the item. |
|
165 |
|
166 \code |
|
167 ... |
|
168 QString entryDescription = resultEntry->description(); |
|
169 ... |
|
170 \endcode |
|
171 */ |
|
172 QString CaEntry::description() const |
|
173 { |
|
174 return m_d->description(); |
|
175 } |
|
176 |
|
177 /*! |
|
178 Sets description of the item. |
|
179 \param new description of the item. |
|
180 |
|
181 \code |
|
182 ... |
|
183 QString entryDescription( QString("EntryDescription") ); |
|
184 resultEntry->entryDescription(entryDescription); |
|
185 ... |
|
186 \endcode |
|
187 */ |
|
188 void CaEntry::setDescription(const QString &description) |
|
189 { |
|
190 m_d->setDescription(description); |
|
191 } |
|
192 |
|
193 /*! |
|
194 Returns copy of icon description of the entry. |
|
195 \retval icon Description (CaIconDescription). |
|
196 |
|
197 \code |
|
198 ... |
|
199 CaIconDescription iconDesc; |
|
200 iconDesc.setBitmapId(5555); |
|
201 iconDesc.setFilename(QString("fileName")); |
|
202 iconDesc.setMaskId(5556); |
|
203 iconDesc.setSkinMajorId(5557); |
|
204 iconDesc.setSkinMinorId(5558); |
|
205 |
|
206 resultEntry->setIconDescription( iconDesc ); |
|
207 |
|
208 CaIconDescription entryIcon; |
|
209 entryIcon = resultEntry->iconDescription(); |
|
210 ... |
|
211 \b Output: |
|
212 iconDesc == entryIcon |
|
213 |
|
214 \endcode |
|
215 */ |
|
216 CaIconDescription CaEntry::iconDescription() const |
|
217 { |
|
218 return m_d->iconDescription(); |
|
219 } |
|
220 |
|
221 /*! |
|
222 Sets icon description |
|
223 \param iconDescription const reference to CaIconDescription |
|
224 |
|
225 \code |
|
226 ... |
|
227 CaIconDescription iconDesc; |
|
228 iconDesc.setBitmapId(5555); |
|
229 iconDesc.setFilename(QString("fileName")); |
|
230 iconDesc.setMaskId(5556); |
|
231 iconDesc.setSkinMajorId(5557); |
|
232 iconDesc.setSkinMinorId(5558); |
|
233 |
|
234 resultEntry->setIconDescription( iconDesc ); |
|
235 ... |
|
236 \b Output: |
|
237 iconDesc == resultEntry->iconDescription(); |
|
238 |
|
239 \endcode |
|
240 */ |
|
241 void CaEntry::setIconDescription(const CaIconDescription &iconDescription) |
|
242 { |
|
243 m_d->setIconDescription(iconDescription); |
|
244 } |
|
245 |
|
246 /*! |
|
247 Returns items flags. |
|
248 \retval flags. |
|
249 |
|
250 \code |
|
251 ... |
|
252 TUint flags = contentarsenal::RemovableEntryFlag |
|
253 |contentarsenal::VisibleEntryFlag; |
|
254 resultEntry->setFlags( flags ); |
|
255 |
|
256 EntryFlags entryFlags = resultEntry->flags(); |
|
257 |
|
258 \b Output: |
|
259 flags == entryFlags |
|
260 |
|
261 \endcode |
|
262 */ |
|
263 EntryFlags CaEntry::flags() const |
|
264 { |
|
265 return m_d->flags(); |
|
266 } |
|
267 |
|
268 /*! |
|
269 Sets flags. |
|
270 \param flags entry flags. |
|
271 |
|
272 \code |
|
273 ... |
|
274 TUint flags = contentarsenal::RemovableEntryFlag |
|
275 |contentarsenal::VisibleEntryFlag; |
|
276 resultEntry->setFlags( flags ); |
|
277 ... |
|
278 \endcode |
|
279 */ |
|
280 void CaEntry::setFlags(EntryFlags flags) |
|
281 { |
|
282 m_d->setFlags(flags); |
|
283 } |
|
284 |
|
285 /*! |
|
286 Returns a name of an entry type. |
|
287 \retval name of entry type. |
|
288 |
|
289 \code |
|
290 CaEntry entry; |
|
291 entry.setText( "Text" ); |
|
292 entry.setEntryTypeName( "TypeName" ); |
|
293 CaEntry * resultEntry = service->createEntry( entry ); |
|
294 |
|
295 QString entryTypeName = resultEntry->entryTypeName(); |
|
296 \b Output: |
|
297 entryTypeName == "TypeName" |
|
298 |
|
299 \endcode |
|
300 */ |
|
301 QString CaEntry::entryTypeName() const |
|
302 { |
|
303 return m_d->entryTypeName(); |
|
304 } |
|
305 |
|
306 /*! |
|
307 Sets name of entry type. |
|
308 \param entryTypeName name of entry type (const reference). |
|
309 |
|
310 \code |
|
311 ... |
|
312 resultEntry->setEntryTypeName("EntryTypeName"); |
|
313 |
|
314 \b Output: |
|
315 resultEntry->entryTypeName == "EntryTypeName" |
|
316 |
|
317 \endcode |
|
318 */ |
|
319 void CaEntry::setEntryTypeName(const QString &entryTypeName) |
|
320 { |
|
321 m_d->setEntryTypeName(entryTypeName); |
|
322 } |
|
323 |
|
324 /*! |
|
325 Returns item attributes. |
|
326 \retval map of attributes indexed by their names. |
|
327 |
|
328 \code |
|
329 ... |
|
330 QString attrName_1( "name_1" ); |
|
331 QString attrValue_1( "value_1" ); |
|
332 QString attrName_2( "name_2" ); |
|
333 QString attrValue_2( "value_2" ); |
|
334 resultEntry->setAttribute( attrName_1, attrValue_1 ); |
|
335 resultEntry->setAttribute( attrName_2, attrValue_2 ); |
|
336 ... |
|
337 QMap<QString, QString> attrMap = entryAttrValue = resultEntry->attributes(); |
|
338 |
|
339 \b Output: |
|
340 attrMap[0] == name: name_1, value: value_1 |
|
341 attrMap[1] == name: name_2, value: value_2 |
|
342 |
|
343 \endcode |
|
344 */ |
|
345 QMap<QString, QString> CaEntry::attributes() const |
|
346 { |
|
347 return m_d->attributes(); |
|
348 } |
|
349 |
|
350 /*! |
|
351 \param name name of an attribute |
|
352 \retval value of attribute |
|
353 |
|
354 \code |
|
355 ... |
|
356 QString attrName_1( "name_1" ); |
|
357 QString attrValue_1( "value_1" ); |
|
358 QString attrName_2( "name_2" ); |
|
359 QString attrValue_2( "value_2" ); |
|
360 resultEntry->setAttribute( attrName_1, attrValue_1 ); |
|
361 resultEntry->setAttribute( attrName_2, attrValue_2 ); |
|
362 ... |
|
363 QString entryAttrValue = resultEntry->attribute( attrName_1 ); |
|
364 |
|
365 \b Output: |
|
366 entryAttrValue == "attrValue_1" |
|
367 |
|
368 \endcode |
|
369 */ |
|
370 QString CaEntry::attribute(const QString &name) const |
|
371 { |
|
372 return m_d->attribute(name); |
|
373 } |
|
374 |
|
375 /*! |
|
376 Sets attribute. |
|
377 \param name name of an attribute. |
|
378 \param value value of an attribute. |
|
379 |
|
380 \code |
|
381 ... |
|
382 QString attrName_1( "name_1" ); |
|
383 QString attrValue_1( "value_1" ); |
|
384 QString attrName_2( "name_2" ); |
|
385 QString attrValue_2( "value_2" ); |
|
386 resultEntry->setAttribute( attrName_1, attrValue_1 ); |
|
387 resultEntry->setAttribute( attrName_2, attrValue_2 ); |
|
388 |
|
389 \endcode |
|
390 */ |
|
391 void CaEntry::setAttribute(const QString &name, const QString &value) |
|
392 { |
|
393 m_d->setAttribute(name, value); |
|
394 } |
|
395 |
|
396 /*! |
|
397 Creates an icon. |
|
398 \param size icon size to display |
|
399 \retval created icon (HbIcon). |
|
400 |
|
401 \code |
|
402 ... |
|
403 QSize iconSize( 50, 80 ); |
|
404 HbIcon icon = resultEntry->makeIcon( iconSize ); |
|
405 |
|
406 \b Output: |
|
407 icon.width() == 50 |
|
408 icon.height() == 80 |
|
409 icon.size() == iconSize; |
|
410 \endcode |
|
411 */ |
|
412 HbIcon CaEntry::makeIcon(const QSize &size) const |
|
413 { |
|
414 CACLIENTTEST_FUNC_ENTRY("CaEntry::makeIcon"); |
|
415 HbIcon icon; |
|
416 if (CaIconCache::cache()->exist(*this,size)) { |
|
417 icon = CaIconCache::cache()->icon(*this,size); |
|
418 } else { |
|
419 icon = m_d->makeIcon(size); |
|
420 CaIconCache::cache()->insert(*this, size, icon); |
|
421 } |
|
422 CACLIENTTEST_FUNC_EXIT("CaEntry::makeIcon"); |
|
423 return icon; |
|
424 } |
|
425 |
|
426 /*! |
|
427 Sets entry id. |
|
428 \param id item id. |
|
429 */ |
|
430 void CaEntry::setId(int id) |
|
431 { |
|
432 m_d->setId(id); |
|
433 } |
|
434 /*! |
|
435 Gets entry role. |
|
436 \retval entry's role. |
|
437 |
|
438 \code |
|
439 CaEntry entry; |
|
440 entry.setText("Text"); |
|
441 entry.setEntryTypeName("TypeName"); |
|
442 CaEntry * resultEntry = service->createEntry(entry); |
|
443 |
|
444 EntryRole entryRole = resultEntry->role(); |
|
445 |
|
446 \b Output: |
|
447 entryRole == ItemEntryRole |
|
448 |
|
449 \endcode |
|
450 |
|
451 \code |
|
452 CaEntry entryGroup( GroupEntryRole ); |
|
453 entryGroup.setText("Text"); |
|
454 entryGroup.setEntryTypeName("TypeName"); |
|
455 CaEntry * resultGroup = service->createEntry(entryGroup); |
|
456 EntryRole groupRole = resultGroup->role(); |
|
457 |
|
458 \b Output: |
|
459 groupRole == GroupEntryRole |
|
460 |
|
461 \endcode |
|
462 */ |
|
463 EntryRole CaEntry::role() const |
|
464 { |
|
465 return m_d->role(); |
|
466 } |
|
467 |
|
468 |
|
469 /* |
|
470 Constructor |
|
471 \param entryPublic associated public entry |
|
472 */ |
|
473 CaEntryPrivate::CaEntryPrivate(CaEntry *entryPublic) : |
|
474 m_q(entryPublic), mId(0), mText(), mDescription(), mIconDescription(), |
|
475 mFlags(RemovableEntryFlag|VisibleEntryFlag),mEntryTypeName(), |
|
476 mAttributes() |
|
477 { |
|
478 } |
|
479 /*! |
|
480 Copy assignment operator. |
|
481 \param entry const reference to CaEntryPrivate. |
|
482 \retval reference to CaEntryPrivate. |
|
483 */ |
|
484 CaEntryPrivate &CaEntryPrivate::operator=(const CaEntryPrivate &entry) |
|
485 { |
|
486 mId = entry.mId; |
|
487 mText = entry.mText; |
|
488 mDescription = entry.mDescription; |
|
489 mIconDescription = entry.mIconDescription; |
|
490 mFlags = entry.mFlags; |
|
491 mEntryTypeName = entry.mEntryTypeName; |
|
492 mAttributes = entry.mAttributes; |
|
493 mEntryRole = entry.mEntryRole; |
|
494 return *this; |
|
495 } |
|
496 |
|
497 /*! |
|
498 Destructor |
|
499 */ |
|
500 CaEntryPrivate::~CaEntryPrivate() |
|
501 { |
|
502 } |
|
503 |
|
504 /*! |
|
505 \retval item id |
|
506 */ |
|
507 int CaEntryPrivate::id() const |
|
508 { |
|
509 return mId; |
|
510 } |
|
511 |
|
512 /*! |
|
513 \retval name of the item. |
|
514 */ |
|
515 QString CaEntryPrivate::text() const |
|
516 { |
|
517 return mText; |
|
518 } |
|
519 |
|
520 /*! |
|
521 Sets name of the item. |
|
522 \param text new name of the item. |
|
523 */ |
|
524 void CaEntryPrivate::setText(const QString &text) |
|
525 { |
|
526 mText = text; |
|
527 } |
|
528 |
|
529 /*! |
|
530 \retval description of the item. |
|
531 */ |
|
532 QString CaEntryPrivate::description() const |
|
533 { |
|
534 return mDescription; |
|
535 } |
|
536 |
|
537 /*! |
|
538 Sets description of the item. |
|
539 \param text new name of the item. |
|
540 */ |
|
541 void CaEntryPrivate::setDescription(const QString &description) |
|
542 { |
|
543 mDescription = description; |
|
544 } |
|
545 |
|
546 /*! |
|
547 \retval icon Description (CaIconDescription). |
|
548 */ |
|
549 CaIconDescription CaEntryPrivate::iconDescription() const |
|
550 { |
|
551 return mIconDescription; |
|
552 } |
|
553 |
|
554 /*! |
|
555 Sets icon description |
|
556 \param iconDescription const reference to CaIconDescription |
|
557 */ |
|
558 void CaEntryPrivate::setIconDescription( |
|
559 const CaIconDescription &iconDescription) |
|
560 { |
|
561 mIconDescription = iconDescription; |
|
562 } |
|
563 |
|
564 /*! |
|
565 \retval flags |
|
566 */ |
|
567 EntryFlags CaEntryPrivate::flags() const |
|
568 { |
|
569 return mFlags; |
|
570 } |
|
571 |
|
572 /*! |
|
573 Sets flags. |
|
574 \param flags entry flags. |
|
575 */ |
|
576 void CaEntryPrivate::setFlags(EntryFlags flags) |
|
577 { |
|
578 mFlags = flags; |
|
579 } |
|
580 |
|
581 /*! |
|
582 \retval name of entry type. |
|
583 */ |
|
584 QString CaEntryPrivate::entryTypeName() const |
|
585 { |
|
586 return mEntryTypeName; |
|
587 } |
|
588 |
|
589 /*! |
|
590 Sets name of entry type. |
|
591 \param entryTypeName name of entry type (const reference) |
|
592 */ |
|
593 void CaEntryPrivate::setEntryTypeName(const QString &entryTypeName) |
|
594 { |
|
595 mEntryTypeName = entryTypeName; |
|
596 } |
|
597 |
|
598 /*! |
|
599 \retval map of attributes indexed by their names |
|
600 */ |
|
601 QMap<QString, QString> CaEntryPrivate::attributes() const |
|
602 { |
|
603 return mAttributes; |
|
604 } |
|
605 |
|
606 /*! |
|
607 \param name name of an attribute |
|
608 \retval value of attribute |
|
609 */ |
|
610 QString CaEntryPrivate::attribute(const QString &name) const |
|
611 { |
|
612 return mAttributes.value(name); |
|
613 } |
|
614 |
|
615 /*! |
|
616 Sets attribute. |
|
617 \param name name of an attribute. |
|
618 \param value value of an attribute. |
|
619 */ |
|
620 void CaEntryPrivate::setAttribute(const QString &name, const QString &value) |
|
621 { |
|
622 mAttributes.insert(name, value); |
|
623 } |
|
624 |
|
625 /*! |
|
626 Creates an icon. |
|
627 \param size icon size to display |
|
628 \retval created icon (HbIcon). |
|
629 */ |
|
630 HbIcon CaEntryPrivate::makeIcon(const QSize &size) const |
|
631 { |
|
632 return CaObjectAdapter::makeIcon(*m_q, size); |
|
633 } |
|
634 |
|
635 /*! |
|
636 Sets entry id. |
|
637 \param id item id. |
|
638 */ |
|
639 void CaEntryPrivate::setId(int id) |
|
640 { |
|
641 mId = id; |
|
642 } |
|
643 /*! |
|
644 Sets entry role. |
|
645 \retval entry's role. |
|
646 */ |
|
647 EntryRole CaEntryPrivate::role() const |
|
648 { |
|
649 return mEntryRole; |
|
650 } |
|
651 /*! |
|
652 Gets entry role. |
|
653 \param role entry's role. |
|
654 */ |
|
655 void CaEntryPrivate::setRole(const EntryRole &role) |
|
656 { |
|
657 mEntryRole = role; |
|
658 } |
|
659 |