|
1 /* |
|
2 * Copyright (c) 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: Holds PIM API field and attribute labels |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS HEADER |
|
20 #include "cpimlabelprovider.h" |
|
21 |
|
22 // INTERNAL INCLUDES |
|
23 #include "pimpanics.h" |
|
24 |
|
25 // EXTERNAL INCLUDES |
|
26 #include <barsc.h> |
|
27 #include <barsread.h> |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CPIMLabelProvider::NewL |
|
33 // Two-phased constructor. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CPIMLabelProvider* CPIMLabelProvider::NewL(TResourceReader& aReader) |
|
37 { |
|
38 CPIMLabelProvider* self = CPIMLabelProvider::NewLC(aReader); |
|
39 CleanupStack::Pop(self); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CPIMLabelProvider::NewL |
|
45 // Two-phased constructor. Created item is left to the cleanup stack |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CPIMLabelProvider* CPIMLabelProvider::NewLC(TResourceReader& aReader) |
|
49 { |
|
50 CPIMLabelProvider* self = new(ELeave) CPIMLabelProvider(); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructFromResourceL(aReader); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CPIMLabelProvider::~CPIMLabelProvider |
|
58 // Destructor |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CPIMLabelProvider::~CPIMLabelProvider() |
|
62 { |
|
63 delete iSubElementLabels; |
|
64 delete iSubElementIds; |
|
65 delete iLabel; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CPIMLabelProvider::LabelL |
|
70 // Returns a label of an attribute or field. Caller takes ownership of the value |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 HBufC* CPIMLabelProvider::LabelL(const TInt aId) const |
|
74 { |
|
75 if (aId == iId) |
|
76 { |
|
77 __ASSERT_DEBUG(iLabel, |
|
78 User::Panic(KPIMPanicCategory, EPIMPanicInvalidLabel)); |
|
79 return iLabel->AllocL(); |
|
80 } |
|
81 return NULL; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CPIMLabelProvider::LabelL |
|
86 // Returns a label of an array element. Caller takes ownership of the value |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 HBufC* CPIMLabelProvider::LabelL(const TInt aId, const TInt aElement) const |
|
90 { |
|
91 // Check that field id matches and this field contains sub-elements |
|
92 if (aId == iId && iSubElementIds) |
|
93 { |
|
94 TInt count = iSubElementIds->Count(); |
|
95 for (TInt i(0); i < count; i++) |
|
96 { |
|
97 if (iSubElementIds->At(i) == aElement) |
|
98 { |
|
99 return iSubElementLabels->MdcaPoint(i).AllocL(); |
|
100 } |
|
101 } |
|
102 } |
|
103 return NULL; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // Default C++ constructor |
|
108 // ----------------------------------------------------------------------------- |
|
109 //¨ |
|
110 CPIMLabelProvider::CPIMLabelProvider() |
|
111 { |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CPIMLabelProvider::ConstructFromResourceL |
|
116 // ----------------------------------------------------------------------------- |
|
117 //¨ |
|
118 void CPIMLabelProvider::ConstructFromResourceL(TResourceReader& aReader) |
|
119 { |
|
120 // Read provider identifier and label |
|
121 iId = aReader.ReadInt32(); |
|
122 iLabel = aReader.ReadHBufCL(); |
|
123 |
|
124 TBool hasSubElements(aReader.ReadInt8()); |
|
125 |
|
126 // Read sub elements |
|
127 if (hasSubElements) |
|
128 { |
|
129 // Create arrays. 7 for granularity |
|
130 iSubElementIds = new(ELeave) CArrayFixFlat< TInt >(7); |
|
131 iSubElementLabels = new(ELeave) CDesCArrayFlat(7); |
|
132 |
|
133 TInt subelemCount(aReader.ReadInt16()); |
|
134 for (TInt i(0); i < subelemCount; i++) |
|
135 { |
|
136 iSubElementIds->AppendL(aReader.ReadInt32()); |
|
137 iSubElementLabels->AppendL(aReader.ReadTPtrC()); |
|
138 } |
|
139 } |
|
140 } |
|
141 |
|
142 // End of file |