|
1 /* |
|
2 * Copyright (c) 2008 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: CMSRuleMultiselectionSetting class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mediaservant.rsg> |
|
20 #include <akncheckboxsettingpage.h> |
|
21 #include <StringLoader.h> |
|
22 #include <utf.h> |
|
23 |
|
24 #include "cmsqlpropertycontainer.h" |
|
25 #include "cmsqlpropertyitem.h" |
|
26 #include "msrulemultiselectionsetting.h" |
|
27 #include "msconstants.h" |
|
28 #include "msmultiselectiondialog.h" |
|
29 #include "msdebug.h" |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KItemArrayGranularity = 3; |
|
33 |
|
34 // -------------------------------------------------------------------------- |
|
35 // CMSRuleMultiselectionSetting::NewL |
|
36 // -------------------------------------------------------------------------- |
|
37 // |
|
38 CMSRuleMultiselectionSetting* CMSRuleMultiselectionSetting::NewL( |
|
39 TInt aIdentifier, |
|
40 TInt aTitleResource, |
|
41 TInt aFirstPopupItemResource, |
|
42 TInt aAnyItemTextResource, |
|
43 CCmSqlPropertyContainer* aMetadataArray, |
|
44 RArray<TInt>* aArray, |
|
45 TInt aItemTextResource, |
|
46 TDes& aText) |
|
47 { |
|
48 LOG(_L("[MediaServant]\t CMSRuleMultiselectionSetting::NewL")); |
|
49 |
|
50 CMSRuleMultiselectionSetting* self = |
|
51 CMSRuleMultiselectionSetting::NewLC( |
|
52 aIdentifier, |
|
53 aTitleResource, |
|
54 aFirstPopupItemResource, |
|
55 aAnyItemTextResource, |
|
56 aMetadataArray, |
|
57 aArray, |
|
58 aItemTextResource, |
|
59 aText ); |
|
60 |
|
61 CleanupStack::Pop(self); |
|
62 |
|
63 return self; |
|
64 } |
|
65 |
|
66 // -------------------------------------------------------------------------- |
|
67 // CMSRuleMultiselectionSetting::NewLC |
|
68 // -------------------------------------------------------------------------- |
|
69 // |
|
70 CMSRuleMultiselectionSetting* CMSRuleMultiselectionSetting::NewLC( |
|
71 TInt aIdentifier, |
|
72 TInt aTitleResource, |
|
73 TInt aFirstPopupItemResource, |
|
74 TInt aAnyItemTextResource, |
|
75 CCmSqlPropertyContainer* aMetadataArray, |
|
76 RArray<TInt>* aArray, |
|
77 TInt aItemTextResource, |
|
78 TDes& aText) |
|
79 { |
|
80 LOG(_L("[MediaServant]\t CMSRuleMultiselectionSetting::NewLC")); |
|
81 |
|
82 CMSRuleMultiselectionSetting* self = |
|
83 new (ELeave) CMSRuleMultiselectionSetting( |
|
84 aIdentifier, |
|
85 aTitleResource, |
|
86 aFirstPopupItemResource, |
|
87 aAnyItemTextResource, |
|
88 aMetadataArray, |
|
89 aArray, |
|
90 aItemTextResource, |
|
91 aText ); |
|
92 |
|
93 CleanupStack::PushL(self); |
|
94 self->ConstructL(); |
|
95 |
|
96 return self; |
|
97 } |
|
98 |
|
99 // -------------------------------------------------------------------------- |
|
100 // CMSRuleMultiselectionSetting::ConstructL |
|
101 // -------------------------------------------------------------------------- |
|
102 // |
|
103 void CMSRuleMultiselectionSetting::ConstructL() |
|
104 { |
|
105 LOG(_L("[MediaServant]\t CMSRuleMultiselectionSetting::ConstructL")); |
|
106 |
|
107 iItemArray = |
|
108 new ( ELeave ) CSelectionItemList( KItemArrayGranularity ); |
|
109 |
|
110 } |
|
111 |
|
112 // -------------------------------------------------------------------------- |
|
113 // CMSRuleMultiselectionSetting::SetSettingItemTextL |
|
114 // -------------------------------------------------------------------------- |
|
115 // |
|
116 void CMSRuleMultiselectionSetting::SetSettingItemTextL() |
|
117 { |
|
118 LOG(_L("[MediaServant]\t CMSRuleMultiselectionSetting::\ |
|
119 SetSettingItemTextL")); |
|
120 |
|
121 HBufC* itemText = NULL; |
|
122 |
|
123 if ( iSelectedItemCount == 1 ) |
|
124 { |
|
125 // only one item selected so we can use item index to find text |
|
126 CSelectableItem* apu = (*iItemArray)[ iSelectedItemIndex ]; |
|
127 itemText = apu->ItemText().AllocLC(); |
|
128 } |
|
129 else if ( iSelectedItemCount > 1 ) |
|
130 { |
|
131 itemText = StringLoader::LoadLC( iItemTextResource, |
|
132 iSelectedItemCount ); |
|
133 // do number conversion |
|
134 TPtr ptr = itemText->Des(); |
|
135 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr ); |
|
136 |
|
137 } |
|
138 else |
|
139 { |
|
140 itemText = StringLoader::LoadLC( iAnyItemTextResource ); |
|
141 } |
|
142 |
|
143 // Set new text |
|
144 SetExternalText( *itemText ); |
|
145 // Load text |
|
146 LoadL(); |
|
147 |
|
148 CleanupStack::PopAndDestroy( itemText ); |
|
149 } |
|
150 |
|
151 // -------------------------------------------------------------------------- |
|
152 // CMSRuleMultiselectionSetting::CMSRuleMultiselectionSetting |
|
153 // -------------------------------------------------------------------------- |
|
154 // |
|
155 CMSRuleMultiselectionSetting::CMSRuleMultiselectionSetting( |
|
156 TInt aIdentifier, |
|
157 TInt aTitleResource, |
|
158 TInt aFirstPopupItemResource, |
|
159 TInt aAnyItemTextResource, |
|
160 CCmSqlPropertyContainer* aMetadataArray, |
|
161 RArray<TInt>* aArray, |
|
162 TInt aItemTextResource, |
|
163 TDes& aText |
|
164 ) : |
|
165 CMSTextSettingItem( aIdentifier, aText ), |
|
166 iItemTextResource ( aItemTextResource ), |
|
167 iText( aText ), |
|
168 iList (aArray), |
|
169 iMetadataArray( aMetadataArray ), |
|
170 iTitleResource( aTitleResource ), |
|
171 iFirstPopupItemResource( aFirstPopupItemResource ), |
|
172 iAnyItemTextResource( aAnyItemTextResource ) |
|
173 { |
|
174 } |
|
175 |
|
176 // -------------------------------------------------------------------------- |
|
177 // CMSRuleMultiselectionSetting::~CMSRuleMultiselectionSetting() |
|
178 // -------------------------------------------------------------------------- |
|
179 // |
|
180 CMSRuleMultiselectionSetting::~CMSRuleMultiselectionSetting() |
|
181 { |
|
182 LOG(_L("[MediaServant]\t CMSRuleMultiselectionSetting::\ |
|
183 ~CMSRuleMultiselectionSetting")); |
|
184 |
|
185 if ( iItemArray ) |
|
186 { |
|
187 iItemArray->ResetAndDestroy(); |
|
188 delete iItemArray; |
|
189 } |
|
190 } |
|
191 |
|
192 // -------------------------------------------------------------------------- |
|
193 // CMSRuleMultiselectionSetting::EditItemL( TBool aCalledFromMenu ) |
|
194 // -------------------------------------------------------------------------- |
|
195 // |
|
196 void CMSRuleMultiselectionSetting::EditItemL( TBool /*aCalledFromMenu*/ ) |
|
197 { |
|
198 LOG(_L("[MediaServant]\t CMSRuleMultiselectionSetting::EditItemL")); |
|
199 |
|
200 HBufC* title = StringLoader::LoadLC( iTitleResource ); |
|
201 CMSMultiselectionDialog* dlg = |
|
202 CMSMultiselectionDialog::NewL(iItemArray, *title); |
|
203 |
|
204 // reset dialog acceptance indicator |
|
205 SetAcceptState( EFalse ); |
|
206 |
|
207 // launch dialog |
|
208 if ( dlg->ExecuteLD( R_MS_MULTISELECTION_DIALOG ) ) |
|
209 { |
|
210 // dialog accepted |
|
211 SetAcceptState( ETrue ); |
|
212 |
|
213 // reset selected item count |
|
214 iSelectedItemCount = 0; |
|
215 |
|
216 // remove previous items |
|
217 iList->Reset(); |
|
218 |
|
219 // Check if first item ("Any") is selected |
|
220 if ( (*iItemArray)[ 0 ]->SelectionStatus() == EFalse ) |
|
221 { |
|
222 AppendSelectedItemsToListL(); |
|
223 } |
|
224 |
|
225 // set item text |
|
226 SetSettingItemTextL(); |
|
227 // load and update text |
|
228 LoadL(); |
|
229 UpdateListBoxTextL(); |
|
230 } |
|
231 CleanupStack::PopAndDestroy( title ); |
|
232 } |
|
233 |
|
234 // -------------------------------------------------------------------------- |
|
235 // CMSRuleMultiselectionSetting::CreateSelectionItemListL |
|
236 // Creates selection item list |
|
237 // -------------------------------------------------------------------------- |
|
238 // |
|
239 void CMSRuleMultiselectionSetting::CreateSelectionItemListL() |
|
240 { |
|
241 LOG(_L("[MediaServant]\t CMSRuleMultiselectionSetting::\ |
|
242 CreateSelectionItemListL")); |
|
243 |
|
244 // delete old items |
|
245 iItemArray->ResetAndDestroy(); |
|
246 iSelectedItemCount = 0; |
|
247 |
|
248 // Cycle trough all metadata items |
|
249 iMetadataArray->SortPropertyItem(); |
|
250 for ( TInt idx = 0; idx < iMetadataArray->PropertyItemCount(); idx++ ) |
|
251 { |
|
252 CCmSqlPropertyItem* propertyItem = |
|
253 iMetadataArray->PropertyItem( idx ); |
|
254 |
|
255 HBufC* itemStr = CnvUtfConverter::ConvertToUnicodeFromUtf8L( |
|
256 propertyItem->Name() ); |
|
257 CleanupStack::PushL( itemStr ); |
|
258 |
|
259 // Check if item was selected last time |
|
260 TInt found = iList->Find( propertyItem->Id() ); |
|
261 |
|
262 CSelectableItem* item; |
|
263 |
|
264 if ( found != KErrNotFound ) |
|
265 { |
|
266 // create item - selected |
|
267 item = new ( ELeave ) CSelectableItem( *itemStr, ETrue ); |
|
268 iSelectedItemCount++; |
|
269 iSelectedItemIndex = idx + 1; //first item is "any" |
|
270 } |
|
271 else |
|
272 { |
|
273 // create item - not selected |
|
274 item = new ( ELeave ) CSelectableItem( *itemStr, EFalse ); |
|
275 } |
|
276 |
|
277 CleanupStack::PushL( item ); |
|
278 |
|
279 // item must be constructed |
|
280 item->ConstructL(); |
|
281 |
|
282 // append item to list |
|
283 iItemArray->AppendL(item); |
|
284 |
|
285 CleanupStack::Pop( item ); |
|
286 CleanupStack::PopAndDestroy( itemStr ); |
|
287 } |
|
288 |
|
289 // Create and append default item (Any/None) |
|
290 HBufC* itemName = StringLoader::LoadLC( iFirstPopupItemResource ); |
|
291 CSelectableItem* item = NULL; |
|
292 if ( iSelectedItemCount ) |
|
293 { |
|
294 item = new ( ELeave ) CSelectableItem( *itemName, EFalse ); |
|
295 } |
|
296 else |
|
297 { |
|
298 item = new ( ELeave ) CSelectableItem( *itemName, ETrue ); |
|
299 } |
|
300 |
|
301 CleanupStack::PushL( item ); |
|
302 item->ConstructL(); |
|
303 iItemArray->InsertL(0, item); |
|
304 CleanupStack::Pop( item ); |
|
305 CleanupStack::PopAndDestroy( itemName ); |
|
306 |
|
307 } |
|
308 |
|
309 // -------------------------------------------------------------------------- |
|
310 // CMSRuleMultiselectionSetting::AppendSelectedItemsToListL |
|
311 // Appends selected items to the list |
|
312 // -------------------------------------------------------------------------- |
|
313 // |
|
314 void CMSRuleMultiselectionSetting::AppendSelectedItemsToListL() |
|
315 { |
|
316 LOG(_L("[MediaServant]\t CMSRuleMultiselectionSetting::\ |
|
317 AppendSelectedItemsToListL")); |
|
318 |
|
319 // first index '0' is "Any" |
|
320 for ( TInt index = 1; index < iItemArray->Count(); index++ ) |
|
321 { |
|
322 if ( (*iItemArray)[index]->SelectionStatus() ) |
|
323 { |
|
324 CCmSqlPropertyItem* propertyItem = |
|
325 iMetadataArray->PropertyItem( index - 1 ); |
|
326 iList->AppendL( propertyItem->Id() ); |
|
327 iSelectedItemCount++; |
|
328 iSelectedItemIndex = index; |
|
329 } |
|
330 } |
|
331 } |
|
332 |
|
333 // -------------------------------------------------------------------------- |
|
334 // CMSRuleMultiselectionSetting::CreateItemListL |
|
335 // Creates item list and updates listbox |
|
336 // -------------------------------------------------------------------------- |
|
337 // |
|
338 void CMSRuleMultiselectionSetting::CreateItemListL() |
|
339 { |
|
340 // Create item list |
|
341 CreateSelectionItemListL(); |
|
342 // set item text |
|
343 SetSettingItemTextL(); |
|
344 // update listbox |
|
345 UpdateListBoxTextL(); |
|
346 } |
|
347 |
|
348 // End of File |
|
349 |