|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * Provides phonebook icon array class methods. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <CPbkIconArray.h> // This class |
|
22 #include <barsread.h> // TResourceReader |
|
23 #include <gulicon.h> // CGulIcon |
|
24 #include <coemain.h> // CCoeEnv |
|
25 #include <PbkView.rsg> |
|
26 #include "PbkIconInfo.h" |
|
27 |
|
28 #include <CPbkExtGlobals.h> |
|
29 #include <MPbkExtensionFactory.h> |
|
30 |
|
31 /// Unnamed namespace for local definitions |
|
32 namespace { |
|
33 |
|
34 // LOCAL CONSTANTS AND MACROS |
|
35 |
|
36 #ifdef _DEBUG |
|
37 enum TPanicCode |
|
38 { |
|
39 EPanicPostCond_AppendFromResourceL, |
|
40 EPanicPreCond_FindIcon, |
|
41 EPanicLogic_ReadArrayL, |
|
42 EPanicPreCond_HandleResourceChangeL |
|
43 }; |
|
44 |
|
45 void Panic(TInt aReason) |
|
46 { |
|
47 _LIT(KPanicText, "CPbkIconArray"); |
|
48 User::Panic(KPanicText, aReason); |
|
49 } |
|
50 |
|
51 #endif // _DEBUG |
|
52 |
|
53 } // namespace |
|
54 |
|
55 // ================= MEMBER FUNCTIONS ======================= |
|
56 |
|
57 EXPORT_C CPbkIconArray::CPbkIconArray |
|
58 (TInt aGranurality) : |
|
59 CArrayPtrFlat<CGulIcon>(aGranurality), |
|
60 iIdMap(aGranurality) |
|
61 { |
|
62 } |
|
63 |
|
64 EXPORT_C CPbkIconArray::~CPbkIconArray() |
|
65 { |
|
66 // Free contents of this array for leave-safety |
|
67 ResetAndDestroy(); |
|
68 } |
|
69 |
|
70 EXPORT_C void CPbkIconArray::ConstructFromResourceL |
|
71 (TInt aResId) |
|
72 { |
|
73 AppendIconsFromResourceL(R_PBK_ICON_INFO_ARRAY, aResId); |
|
74 } |
|
75 |
|
76 EXPORT_C void CPbkIconArray::ConstructFromResourceL |
|
77 (TResourceReader& aReader) |
|
78 { |
|
79 CPbkIconInfoContainer* iconInfoContainer = CPbkIconInfoContainer::NewL( |
|
80 R_PBK_ICON_INFO_ARRAY); |
|
81 CleanupStack::PushL(iconInfoContainer); |
|
82 |
|
83 ReadFromResourceL(aReader, *iconInfoContainer); |
|
84 CleanupStack::PopAndDestroy(); // iconInfoContainer |
|
85 } |
|
86 |
|
87 void CPbkIconArray::ReadFromResourceL |
|
88 (TResourceReader& aReader, |
|
89 CPbkIconInfoContainer& aIconInfoContainer) |
|
90 { |
|
91 TInt count = aReader.ReadInt16(); |
|
92 #ifdef _DEBUG |
|
93 const TInt dbgCount = Count() + count; |
|
94 #endif |
|
95 SetReserveL(Count() + count); |
|
96 iIdMap.SetReserveL(iIdMap.Count() + count); |
|
97 while (count-- > 0) |
|
98 { |
|
99 const TPbkIconId iconId = static_cast<TPbkIconId>(aReader.ReadInt8()); |
|
100 CGulIcon* gulIcon = aIconInfoContainer.LoadBitmapL(iconId); |
|
101 __ASSERT_DEBUG(gulIcon, Panic(EPanicLogic_ReadArrayL)); |
|
102 |
|
103 // Following AppendLs call cannot leave due to lack of memory because |
|
104 // of SetReserveL calls above. |
|
105 AppendL(gulIcon); |
|
106 iIdMap.AppendL(iconId); |
|
107 } |
|
108 __ASSERT_DEBUG(Count() == dbgCount && iIdMap.Count() == dbgCount, |
|
109 Panic(EPanicPostCond_AppendFromResourceL)); |
|
110 } |
|
111 |
|
112 EXPORT_C TInt CPbkIconArray::FindIcon |
|
113 (TPbkIconId aIconId) const |
|
114 { |
|
115 __ASSERT_DEBUG(Count() == iIdMap.Count(), |
|
116 Panic(EPanicPreCond_FindIcon)); |
|
117 |
|
118 const TInt count = iIdMap.Count(); |
|
119 for (TInt i=0; i < count; ++i) |
|
120 { |
|
121 if (iIdMap[i] == aIconId) |
|
122 { |
|
123 return i; |
|
124 } |
|
125 } |
|
126 return KErrNotFound; |
|
127 } |
|
128 |
|
129 EXPORT_C void CPbkIconArray::AppendIconsFromResourceL |
|
130 (TInt aArrayIconInfoId, TInt aArrayIconId) |
|
131 { |
|
132 CPbkIconInfoContainer* iconInfoContainer = CPbkIconInfoContainer::NewL( |
|
133 aArrayIconInfoId); |
|
134 CleanupStack::PushL(iconInfoContainer); |
|
135 |
|
136 TResourceReader reader; |
|
137 CCoeEnv::Static()->CreateResourceReaderLC(reader, aArrayIconId); |
|
138 ReadFromResourceL(reader, *iconInfoContainer); |
|
139 CleanupStack::PopAndDestroy(2); // reader, iconInfoContainer |
|
140 } |
|
141 |
|
142 EXPORT_C void CPbkIconArray::RefreshL(TInt aArrayIconInfoId) |
|
143 { |
|
144 __ASSERT_DEBUG(iIdMap.Count() == Count(), |
|
145 Panic(EPanicPreCond_HandleResourceChangeL)); |
|
146 CPbkIconInfoContainer* iconInfoContainer = CPbkIconInfoContainer::NewL( |
|
147 aArrayIconInfoId); |
|
148 CleanupStack::PushL(iconInfoContainer); |
|
149 |
|
150 // Add icons from extensions |
|
151 CPbkExtGlobals* extGlobal = CPbkExtGlobals::InstanceL(); |
|
152 extGlobal->PushL(); |
|
153 MPbkExtensionFactory& factory = extGlobal->FactoryL(); |
|
154 factory.AddPbkFieldIconsL(iconInfoContainer); |
|
155 CleanupStack::PopAndDestroy(extGlobal); |
|
156 |
|
157 const TInt count = iIdMap.Count(); |
|
158 for (TInt i = 0; i < count; ++i) |
|
159 { |
|
160 const TPbkIconId iconId = iIdMap.At(i); |
|
161 CGulIcon* gulIcon = iconInfoContainer->LoadBitmapL(iconId); |
|
162 if (gulIcon) |
|
163 { |
|
164 // replace the old icon only if new one was loaded |
|
165 delete At(i); |
|
166 At(i) = gulIcon; |
|
167 } |
|
168 } |
|
169 |
|
170 CleanupStack::PopAndDestroy(); // iconInfoContainer |
|
171 } |
|
172 |
|
173 // End of File |