|
1 /* |
|
2 * Copyright (c) 2007 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "mmlistboxmodel.h" |
|
20 #include "mmwidgetsconstants.h" |
|
21 #include <eiktxlbm.h> |
|
22 #include "hnconvutils.h" |
|
23 #include "hnsuiteobserver.h" |
|
24 #include "hnsuitemodel.h" |
|
25 #include "hnitemmodel.h" |
|
26 #include "hnattributebase.h" |
|
27 #include "hnattributeimage.h" |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CMmListBoxModel::CMmListBoxModel() |
|
34 : iSuiteModel( NULL ) |
|
35 { |
|
36 |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CMmListBoxModel::~CMmListBoxModel() |
|
44 { |
|
45 if (iSuiteModel) |
|
46 { |
|
47 iSuiteModel->UnregisterSuiteObserver( this ); |
|
48 } |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CMmListBoxModel* CMmListBoxModel::NewLC() |
|
56 { |
|
57 CMmListBoxModel* self = new (ELeave) CMmListBoxModel(); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CMmListBoxModel* CMmListBoxModel::NewL() |
|
68 { |
|
69 CMmListBoxModel* self = CMmListBoxModel::NewLC(); |
|
70 CleanupStack::Pop( self ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 void CMmListBoxModel::SetSuiteModelL( CHnSuiteModel * aSuiteModel ) |
|
79 { |
|
80 if (iSuiteModel) |
|
81 iSuiteModel->UnregisterSuiteObserver( this ); |
|
82 |
|
83 iSuiteModel = aSuiteModel; |
|
84 UpdateDummyArrayDataL(); |
|
85 |
|
86 if (iSuiteModel) |
|
87 iSuiteModel->RegisterSuiteObserverL( this, EPriorityNormal ); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 CHnAttributeBase* CMmListBoxModel::GetAttribute( TInt aIndex, |
|
95 const TDesC8 & aAttributeName ) |
|
96 { |
|
97 CHnItemModel* item = (iSuiteModel) ? iSuiteModel->GetItemModel( iSuiteModel->IdByIndex( aIndex ) ) : NULL; |
|
98 return (item) ? item->GetAttribute( aAttributeName ) : NULL; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 const TDesC8& CMmListBoxModel::GetAttributeAsText( TInt aIndex, |
|
106 const TDesC8 & aAttributeName ) |
|
107 { |
|
108 CHnAttributeBase* attribute = GetAttribute( aIndex, aAttributeName ); |
|
109 return (attribute) ? attribute->Value() : KNullDesC8; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 CHnIconHolder* CMmListBoxModel::GetAttributeAsRefCountedGraphics( TInt aIndex, |
|
117 const TDesC8 & aAttributeName, TSize* aDesiredIconSize) |
|
118 { |
|
119 CHnAttributeBase* attribute = GetAttribute( aIndex, aAttributeName ); |
|
120 if ( !attribute || attribute->Type() != EImageAttribute ) |
|
121 { |
|
122 return NULL; |
|
123 } |
|
124 return attribute->GetIconHolder( aDesiredIconSize ); |
|
125 } |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void CMmListBoxModel::ConstructL() |
|
131 { |
|
132 CTextListBoxModel::ConstructL(); |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 void CMmListBoxModel::UpdateDummyArrayDataL( ) |
|
140 { |
|
141 CDesCArrayFlat* dataArray = static_cast<CDesC16ArrayFlat*>( ItemTextArray() ); |
|
142 dataArray->Reset(); |
|
143 for( TInt i(0); iSuiteModel && i < iSuiteModel->GetItemModelsCount(); i++ ) |
|
144 { |
|
145 CHnItemModel* itemModel = iSuiteModel->GetItemModel( iSuiteModel->IdByIndex( i ) ); |
|
146 CHnItemModel* emptyItem = iSuiteModel->GetItemModel( iSuiteModel->IdByIndex( -1 ) ); |
|
147 if (!itemModel || itemModel == emptyItem ) |
|
148 { |
|
149 continue; |
|
150 } |
|
151 dataArray->AppendL( KNullDesC16() ); |
|
152 } |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 void CMmListBoxModel::ReorderModelL(TInt aFromIndex, TInt aToIndex) |
|
160 { |
|
161 iSuiteModel->ReorderItemsL( aFromIndex, aToIndex ); |
|
162 UpdateDummyArrayDataL(); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 CHnSuiteModel* CMmListBoxModel::GetSuiteModel() |
|
170 { |
|
171 return iSuiteModel; |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CMmListBoxModel::HandleSuiteEventL( THnCustomSuiteEvent aCustomSuiteEvent, |
|
179 CHnSuiteModel* aModel) |
|
180 { |
|
181 if (iSuiteModel == aModel) |
|
182 { |
|
183 switch ( aCustomSuiteEvent ) |
|
184 { |
|
185 case ESuiteModelDestroyed: |
|
186 iSuiteModel = NULL; |
|
187 break; |
|
188 case ESuiteItemsAdded: |
|
189 case ESuiteItemsRemoved: |
|
190 case ESuiteItemsUpdated: |
|
191 UpdateDummyArrayDataL( ); |
|
192 default: |
|
193 break; |
|
194 } |
|
195 } |
|
196 } |
|
197 |
|
198 // End of file |