|
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: Model class for Events management UI start-up view. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Includes |
|
20 #include <e32keys.h> |
|
21 #include <barsread.h> // For TResourceReader |
|
22 #include <bautils.h> |
|
23 #include <StringLoader.h> |
|
24 #include <evtmgmtui.rsg> |
|
25 #include <eikenv.h> |
|
26 #include <AknUtils.h> |
|
27 #include <aknsfld.h> // For SearchField |
|
28 |
|
29 // User Includes |
|
30 #include "evtmgmtuifiltermodel.h" |
|
31 |
|
32 // Constants |
|
33 const TInt KMaxConversionBufferLength = 0x200; |
|
34 |
|
35 // ========================= MEMBER FUNCTIONS ================================ |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // CEvtMgmtUiStartupLBModel::CEvtMgmtUiStartupLBModel |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CEvtMgmtUiFilterModel::CEvtMgmtUiFilterModel() |
|
42 { |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CEvtMgmtUiFilterModel::~CEvtMgmtUiFilterModel |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CEvtMgmtUiFilterModel::~CEvtMgmtUiFilterModel() |
|
50 { |
|
51 // Delete the Buffers |
|
52 delete iBuffer; |
|
53 iBuffer = NULL; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CEvtMgmtUiFilterModel* CEvtMgmtUiFilterModel::NewL |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CEvtMgmtUiFilterModel* CEvtMgmtUiFilterModel::NewL() |
|
61 { |
|
62 CEvtMgmtUiFilterModel* self = CEvtMgmtUiFilterModel::NewLC(); |
|
63 CleanupStack::Pop( self ); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CEvtMgmtUiFilterModel* CEvtMgmtUiFilterModel::NewLC |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CEvtMgmtUiFilterModel* CEvtMgmtUiFilterModel::NewLC() |
|
72 { |
|
73 CEvtMgmtUiFilterModel* self = new( ELeave )CEvtMgmtUiFilterModel(); |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL(); |
|
76 return self; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // void CEvtMgmtUiFilterModel::ConstructL |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CEvtMgmtUiFilterModel::ConstructL() |
|
84 { |
|
85 // Allocate the Conversion Buffer |
|
86 iBuffer = HBufC16::NewL( KMaxConversionBufferLength ); |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // TInt CEvtMgmtUiFilterModel::MdcaCount() const |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 TInt CEvtMgmtUiFilterModel::MdcaCount() const |
|
94 { |
|
95 return iActualItemTextArray->MdcaCount(); |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // TPtrC16 CEvtMgmtUiFilterModel::MdcaPoint() const |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 TPtrC16 CEvtMgmtUiFilterModel::MdcaPoint( TInt aIndex ) const |
|
103 { |
|
104 if( !aIndex ) |
|
105 { |
|
106 TRAP_IGNORE( UpdateTextL() ); |
|
107 return *iBuffer; |
|
108 } |
|
109 else |
|
110 { |
|
111 return iActualItemTextArray->MdcaPoint(aIndex); |
|
112 } |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CEvtMgmtUiFilterModel::GetZeroIndex() |
|
117 // It will return Search Text |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 TPtrC16 CEvtMgmtUiFilterModel::GetZeroIndex() |
|
121 { |
|
122 return iActualItemTextArray->MdcaPoint(0); |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CEvtMgmtUiFilterModel::GetSearchTextL() |
|
127 // It will return Search Text |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CEvtMgmtUiFilterModel::SetItemTextArray(MDesCArray* aActualItemTextArray) |
|
131 { |
|
132 iActualItemTextArray = NULL; |
|
133 iActualItemTextArray = aActualItemTextArray; |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // CEvtMgmtUiFilterModel::GetSearchTextL() |
|
138 // It will return Search Text |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CEvtMgmtUiFilterModel::SetSearchField(CAknSearchField* aSearchField) |
|
142 { |
|
143 iSearchField = NULL; |
|
144 iSearchField = aSearchField; |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // CEvtMgmtUiFilterModel::GetSearchTextL() |
|
149 // It will return Search Text |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 void CEvtMgmtUiFilterModel::GetSearchTextL(HBufC*& aString) const |
|
153 { |
|
154 if( aString ) |
|
155 { |
|
156 delete aString; |
|
157 aString = NULL; |
|
158 } |
|
159 |
|
160 if(!iSearchField) |
|
161 { |
|
162 aString = KNullDesC().AllocL(); |
|
163 return; |
|
164 } |
|
165 |
|
166 // Fetch filter from search field |
|
167 TInt searchTextLength = iSearchField->TextLength(); |
|
168 |
|
169 if( searchTextLength ) |
|
170 { |
|
171 aString = HBufC::NewL(searchTextLength); |
|
172 TPtr filter = aString->Des(); |
|
173 iSearchField->GetSearchText(filter); |
|
174 } |
|
175 else |
|
176 { |
|
177 aString = KNullDesC().AllocL(); |
|
178 } |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // CEvtMgmtUiFilterModel::UpdateTextL() |
|
183 // It will return type of events |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CEvtMgmtUiFilterModel::UpdateTextL() const |
|
187 { |
|
188 // Allocate the Conversion Buffer |
|
189 HBufC* buffer = NULL; |
|
190 |
|
191 GetSearchTextL(buffer); |
|
192 |
|
193 // Zero the internal buffer |
|
194 TPtr16 ptr( iBuffer->Des()); |
|
195 ptr.Zero(); |
|
196 |
|
197 if( buffer->Length() ) |
|
198 { |
|
199 // Format "%d\t%S\t%S\t%d" |
|
200 ptr.AppendNum( 0 ); |
|
201 ptr.Append( EKeyTab ); |
|
202 ptr.Append( *buffer ); |
|
203 ptr.Append( EKeyTab ); |
|
204 ptr.Append( EKeyTab ); |
|
205 } |
|
206 else |
|
207 { |
|
208 if( iActualItemTextArray->MdcaCount() > 1 ) |
|
209 { |
|
210 ptr.Append( iActualItemTextArray->MdcaPoint(1) ); |
|
211 } |
|
212 else |
|
213 { |
|
214 // Format "%d\t%S\t%S\t%d" |
|
215 ptr.AppendNum( 0 ); |
|
216 ptr.Append( EKeyTab ); |
|
217 ptr.Append( *buffer ); |
|
218 ptr.Append( EKeyTab ); |
|
219 ptr.Append( EKeyTab ); |
|
220 } |
|
221 } |
|
222 |
|
223 delete buffer; |
|
224 } |