|
1 /* |
|
2 * Copyright (c) 2002-2005 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: Represents the searched data |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CCASearchData.h" |
|
21 #include "PrivateEngineDefinitions.h" |
|
22 |
|
23 #include "ChatDebugPrint.h" |
|
24 |
|
25 // ================= MEMBER FUNCTIONS ======================= |
|
26 |
|
27 // Two-phased constructor. |
|
28 CCASearchData* CCASearchData::NewL() |
|
29 { |
|
30 CCASearchData* self = new ( ELeave ) CCASearchData; |
|
31 |
|
32 CleanupStack::PushL( self ); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop( self ); |
|
35 |
|
36 return self; |
|
37 } |
|
38 |
|
39 // Destructor |
|
40 CCASearchData::~CCASearchData() |
|
41 { |
|
42 delete iResults; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------- |
|
46 // CCASearchData::NoMoreResultsAvailable |
|
47 // --------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C TBool CCASearchData::NoMoreResultsAvailable() const |
|
50 { |
|
51 return iCompleted; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // CCASearchData::SearchResultType |
|
56 // --------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C TImpsSearchResultType CCASearchData::SearchResultType() const |
|
59 { |
|
60 return iSearchResultType; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------- |
|
64 // CCASearchData::SearchData |
|
65 // --------------------------------------------------------- |
|
66 // |
|
67 EXPORT_C TPtrC CCASearchData::SearchData( TInt aIndex ) const |
|
68 { |
|
69 CHAT_DP( D_CHAT_LIT( "CCASearchData::SearchData with index %d" ), aIndex ); |
|
70 CHAT_DP( D_CHAT_LIT( "SearchDataCount is %d" ), iResults->MdcaCount() ); |
|
71 |
|
72 return iResults->MdcaPoint( aIndex ); |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------- |
|
76 // CCASearchData::SearchDataCount |
|
77 // --------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C TInt CCASearchData::SearchDataCount() const |
|
80 { |
|
81 CHAT_DP( D_CHAT_LIT( " CCASearchData::SearchDataCount is %d " ), |
|
82 iResults->MdcaCount() ); |
|
83 |
|
84 return iResults->MdcaCount(); |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------- |
|
88 // CCASearchData::HowManyResultsAvailable |
|
89 // --------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C TInt CCASearchData::HowManyResultsAvailable() const |
|
92 { |
|
93 CHAT_DP( D_CHAT_LIT( "CCASearchData::HowManyResultsAvailable is %d" ), |
|
94 iMaximumResultsAvailable ); |
|
95 |
|
96 return iMaximumResultsAvailable; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CCASearchData::NextSearchIndex |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 TInt CCASearchData::NextSearchIndex() const |
|
104 { |
|
105 CHAT_DP( D_CHAT_LIT( "CCASearchData::NextSearchIndex is %d" ), |
|
106 iServerNextIndex ); |
|
107 |
|
108 return iServerNextIndex; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------- |
|
112 // CCASearchData::UpdateDataL |
|
113 // --------------------------------------------------------- |
|
114 // |
|
115 void CCASearchData::UpdateDataL( TInt aIndex, |
|
116 TBool aCompleted, |
|
117 TImpsSearchResultType aType, |
|
118 MDesCArray* aResults, |
|
119 TInt /*aSearchLimit*/ ) |
|
120 { |
|
121 CHAT_DP( D_CHAT_LIT( "CCASearchData::UpdateDataL()" ) ); |
|
122 |
|
123 iServerNextIndex = aIndex; |
|
124 |
|
125 iCompleted = aCompleted; |
|
126 |
|
127 iSearchResultType = aType; |
|
128 |
|
129 if ( aResults ) |
|
130 { |
|
131 TInt count( aResults->MdcaCount() ); |
|
132 |
|
133 CHAT_DP( D_CHAT_LIT( "New results %d" ), aResults->MdcaCount() ); |
|
134 |
|
135 for ( TInt arrayIndex( 0 ); arrayIndex < count; ++arrayIndex ) |
|
136 { |
|
137 TPtrC searchData( aResults->MdcaPoint( arrayIndex ) ); |
|
138 // We don't care about index |
|
139 TInt ignore; |
|
140 // Don't add duplicates |
|
141 if ( iResults->Find( searchData, ignore ) != 0 ) |
|
142 { |
|
143 iResults->AppendL( searchData ); |
|
144 } |
|
145 } |
|
146 |
|
147 // Check iServerNextIndex against really received results |
|
148 // If server for some reason gives wrong index it |
|
149 // messes up our logic and causes crashes |
|
150 TInt resultCount = iResults->MdcaCount(); |
|
151 if ( iServerNextIndex > resultCount && !iCompleted ) |
|
152 { |
|
153 iServerNextIndex = resultCount; |
|
154 } |
|
155 |
|
156 CHAT_DP( D_CHAT_LIT( "We have results %d" ), resultCount ); |
|
157 } |
|
158 else // Search was succesfull, but there were no results so clear the array |
|
159 { |
|
160 iResults->Reset(); |
|
161 } |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------- |
|
165 // CCASearchData::ClearResults |
|
166 // --------------------------------------------------------- |
|
167 // |
|
168 void CCASearchData::ClearResults() |
|
169 { |
|
170 CHAT_DP_TXT( "CCASearchData::ClearResults()...starts" ); |
|
171 iServerNextIndex = 0; |
|
172 |
|
173 iMaximumResultsAvailable = 0; |
|
174 |
|
175 iCompleted = EFalse; |
|
176 |
|
177 iResults->Reset(); |
|
178 |
|
179 CHAT_DP_TXT( "CCASearchData::ClearResults()...over" ); |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------- |
|
183 // CCASearchData::WeHaveData |
|
184 // --------------------------------------------------------- |
|
185 // |
|
186 TBool CCASearchData::WeHaveData( TInt aNextIndex ) const |
|
187 { |
|
188 TBool haveData( aNextIndex < iServerNextIndex ); |
|
189 CHAT_DP( D_CHAT_LIT( "CCASearchData::WeHaveData()...Havedata: %d" ), |
|
190 haveData ); |
|
191 return haveData; |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------- |
|
195 // CCASearchData::UpdateMaximumPossibleResults |
|
196 // --------------------------------------------------------- |
|
197 // |
|
198 void CCASearchData::UpdateMaximumPossibleResults( TInt aMaxResults ) |
|
199 { |
|
200 iMaximumResultsAvailable = aMaxResults; |
|
201 } |
|
202 |
|
203 // C++ default constructor can NOT contain any code, that |
|
204 // might leave. |
|
205 // |
|
206 CCASearchData::CCASearchData() |
|
207 : iCompleted( EFalse ), |
|
208 iServerNextIndex( 0 ), |
|
209 iMaximumResultsAvailable( 0 ) |
|
210 { |
|
211 } |
|
212 |
|
213 // Symbian OS default constructor can leave. |
|
214 void CCASearchData::ConstructL() |
|
215 { |
|
216 CHAT_DP_TXT( "CCASearchData::ConstructL()...starts" ); |
|
217 |
|
218 iResults = new ( ELeave )CDesCArrayFlat( KSearchDataGranularity ); |
|
219 |
|
220 CHAT_DP_TXT( " ConstructL()...ends" ); |
|
221 } |
|
222 |
|
223 // End of File |