63
|
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: Utility class to hold the search sequence for predictive search.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include <s32mem.h>
|
|
21 |
#include "CPsQuery.h"
|
|
22 |
#include "CPsQueryItem.h"
|
|
23 |
#include "CPcsDebug.h"
|
|
24 |
|
|
25 |
// ============================== MEMBER FUNCTIONS ============================
|
|
26 |
|
|
27 |
|
|
28 |
// ----------------------------------------------------------------------------
|
|
29 |
// CPsQuery::NewL
|
|
30 |
// Two Phase constructor
|
|
31 |
// ----------------------------------------------------------------------------
|
|
32 |
EXPORT_C CPsQuery* CPsQuery::NewL()
|
|
33 |
{
|
|
34 |
CPsQuery* self = new (ELeave) CPsQuery();
|
|
35 |
CleanupStack::PushL(self);
|
|
36 |
self->ConstructL();
|
|
37 |
CleanupStack::Pop();
|
|
38 |
return self;
|
|
39 |
|
|
40 |
}
|
|
41 |
|
|
42 |
// ----------------------------------------------------------------------------
|
|
43 |
// CPsQuery::CPsQuery
|
|
44 |
// Default constructor
|
|
45 |
// ----------------------------------------------------------------------------
|
|
46 |
CPsQuery::CPsQuery()
|
|
47 |
{
|
|
48 |
}
|
|
49 |
|
|
50 |
// ----------------------------------------------------------------------------
|
|
51 |
// CPsQuery::ConstructL
|
|
52 |
// Two phase construction
|
|
53 |
// ----------------------------------------------------------------------------
|
|
54 |
void CPsQuery::ConstructL()
|
|
55 |
{
|
|
56 |
}
|
|
57 |
|
|
58 |
// ----------------------------------------------------------------------------
|
|
59 |
// CPsQuery::~CPsQuery
|
|
60 |
// Destructor
|
|
61 |
// ----------------------------------------------------------------------------
|
|
62 |
EXPORT_C CPsQuery::~CPsQuery()
|
|
63 |
{
|
|
64 |
Reset();
|
|
65 |
}
|
|
66 |
|
|
67 |
// ----------------------------------------------------------------------------
|
|
68 |
// CPsQuery::InsertL
|
|
69 |
// Add a query item to the search sequence
|
|
70 |
// ----------------------------------------------------------------------------
|
|
71 |
EXPORT_C void CPsQuery::InsertL(const CPsQueryItem& aQueryItem, TInt aIndex)
|
|
72 |
{
|
|
73 |
if( (aIndex >= 0)
|
|
74 |
&& (aIndex <= (iSearchQuery.Count() + 1))
|
|
75 |
&& (this->Count() < KPsQueryMaxLen) )
|
|
76 |
{
|
|
77 |
iSearchQuery.Insert(&aQueryItem, aIndex);
|
|
78 |
}
|
|
79 |
}
|
|
80 |
|
|
81 |
// ----------------------------------------------------------------------------
|
|
82 |
// CPsQuery::AppendL
|
|
83 |
// Appends a query item to the search sequence
|
|
84 |
// ----------------------------------------------------------------------------
|
|
85 |
EXPORT_C void CPsQuery::AppendL(const CPsQueryItem& aQueryItem)
|
|
86 |
{
|
|
87 |
if(this->Count() < KPsQueryMaxLen )
|
|
88 |
iSearchQuery.AppendL(&aQueryItem);
|
|
89 |
}
|
|
90 |
|
|
91 |
// ----------------------------------------------------------------------------
|
|
92 |
// CPsQuery::GetItemAtL
|
|
93 |
// Returns the query item at the specified index
|
|
94 |
// ----------------------------------------------------------------------------
|
|
95 |
EXPORT_C CPsQueryItem& CPsQuery:: GetItemAtL(TInt aIndex)
|
|
96 |
{
|
|
97 |
if ( aIndex < 0 || aIndex >= iSearchQuery.Count())
|
|
98 |
{
|
|
99 |
User::Leave(KErrArgument);
|
|
100 |
}
|
|
101 |
|
|
102 |
return (*(iSearchQuery[aIndex]));
|
|
103 |
}
|
|
104 |
|
|
105 |
// ----------------------------------------------------------------------------
|
|
106 |
// CPsQuery::QueryAsStringL
|
|
107 |
// Returns the search sequence
|
|
108 |
// ----------------------------------------------------------------------------
|
|
109 |
EXPORT_C TDesC& CPsQuery:: QueryAsStringLC()
|
|
110 |
{
|
|
111 |
HBufC* query = HBufC::NewLC(KPsQueryMaxLen);
|
|
112 |
|
|
113 |
for(TInt arrayIndex =0 ; arrayIndex < iSearchQuery.Count();arrayIndex++)
|
|
114 |
{
|
|
115 |
query->Des().Append((iSearchQuery[arrayIndex])->Character());
|
|
116 |
}
|
|
117 |
|
|
118 |
return *query;
|
|
119 |
}
|
|
120 |
|
|
121 |
// ----------------------------------------------------------------------------
|
|
122 |
// CPsQuery::Remove
|
|
123 |
// Deletes the query item at the specified index
|
|
124 |
// ----------------------------------------------------------------------------
|
|
125 |
EXPORT_C void CPsQuery:: Remove(TInt aIndex)
|
|
126 |
{
|
|
127 |
if (aIndex >= 0 && aIndex <= (iSearchQuery.Count() - 1))
|
|
128 |
{
|
|
129 |
delete iSearchQuery[aIndex];
|
|
130 |
iSearchQuery.Remove(aIndex);
|
|
131 |
}
|
|
132 |
}
|
|
133 |
|
|
134 |
// ----------------------------------------------------------------------------
|
|
135 |
// CPsQuery::Reset
|
|
136 |
// Deletes the entire search query
|
|
137 |
// ----------------------------------------------------------------------------
|
|
138 |
EXPORT_C void CPsQuery:: Reset()
|
|
139 |
{
|
|
140 |
for ( TInt arrayIndex = 0; arrayIndex < iSearchQuery.Count(); arrayIndex++ )
|
|
141 |
{
|
|
142 |
delete iSearchQuery[arrayIndex];
|
|
143 |
}
|
|
144 |
iSearchQuery.Reset();
|
|
145 |
}
|
|
146 |
|
|
147 |
// ----------------------------------------------------------------------------
|
|
148 |
// CPsQuery::KeyboardModeL
|
|
149 |
// Returns the keyboard input mode for the search query
|
|
150 |
// ----------------------------------------------------------------------------
|
|
151 |
EXPORT_C TKeyboardModes CPsQuery:: KeyboardModeL()
|
|
152 |
{
|
|
153 |
TKeyboardModes keyboardMode = EModeUndefined;
|
|
154 |
|
|
155 |
if(iSearchQuery.Count() > 0)
|
|
156 |
{
|
|
157 |
keyboardMode = iSearchQuery[0]->Mode();
|
|
158 |
for(TInt arrayIndex =1 ; arrayIndex < iSearchQuery.Count() ;arrayIndex++)
|
|
159 |
{
|
|
160 |
if(keyboardMode != iSearchQuery[arrayIndex]->Mode())
|
|
161 |
{
|
|
162 |
keyboardMode = EModeUndefined;
|
|
163 |
break;
|
|
164 |
}
|
|
165 |
}
|
|
166 |
}
|
|
167 |
|
|
168 |
return keyboardMode;
|
|
169 |
}
|
|
170 |
|
|
171 |
// ----------------------------------------------------------------------------
|
|
172 |
// CPsQuery::Count
|
|
173 |
// Returns the length of the query
|
|
174 |
// ----------------------------------------------------------------------------
|
|
175 |
EXPORT_C TInt CPsQuery:: Count()
|
|
176 |
{
|
|
177 |
return (iSearchQuery.Count());
|
|
178 |
}
|
|
179 |
|
|
180 |
// ----------------------------------------------------------------------------
|
|
181 |
// Deprecated: Use CPcsDebug::PrintQuery
|
|
182 |
// CPsQuery::PrintQuery
|
|
183 |
// Prints the query as array of query items (query items cannot be spaces)
|
|
184 |
// Used only for debugging
|
|
185 |
// ----------------------------------------------------------------------------
|
|
186 |
EXPORT_C void CPsQuery:: PrintQuery()
|
|
187 |
{
|
|
188 |
PRINT1 ( _L("CPsQuery::PrintQuery: Number of items : %d"), iSearchQuery.Count());
|
|
189 |
for(TInt i = 0; i < iSearchQuery.Count(); i++)
|
|
190 |
{
|
|
191 |
TUint inputKey = iSearchQuery[i]->Character().GetUpperCase();
|
|
192 |
TBuf<2> buffer;
|
|
193 |
buffer.Format(_L("%c"), inputKey);
|
|
194 |
switch(iSearchQuery[i]->Mode())
|
|
195 |
{
|
|
196 |
case EPredictiveDefaultKeyboard:
|
|
197 |
PRINT2 ( _L("Character at index %d: '%S' (EPredictiveDefaultKeyboard)"),
|
|
198 |
i, &buffer);
|
|
199 |
break;
|
|
200 |
case ENonPredictive:
|
|
201 |
PRINT2 ( _L("Character at index %d: '%S' (ENonPredictive)"),
|
|
202 |
i, &buffer);
|
|
203 |
break;
|
|
204 |
case EPredictiveItuT:
|
|
205 |
PRINT2 ( _L("Character at index %d: '%S' (EPredictiveItuT)"),
|
|
206 |
i, &buffer);
|
|
207 |
break;
|
|
208 |
case EPredictiveQwerty:
|
|
209 |
PRINT2 ( _L("Character at index %d: '%S' (EPredictiveQwerty)"),
|
|
210 |
i, &buffer);
|
|
211 |
break;
|
|
212 |
default:
|
|
213 |
PRINT3 ( _L("Character at index %d: '%S' (mode=%d)"),
|
|
214 |
i, &buffer, iSearchQuery[i]->Mode());
|
|
215 |
break;
|
|
216 |
}
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
// ----------------------------------------------------------------------------
|
|
221 |
// CPsQuery::ExternalizeL
|
|
222 |
// Writes 'this' to aStream
|
|
223 |
// ----------------------------------------------------------------------------
|
|
224 |
EXPORT_C void CPsQuery::ExternalizeL(RWriteStream& aStream) const
|
|
225 |
{
|
|
226 |
aStream.WriteUint8L(iSearchQuery.Count()); // Number of query items
|
|
227 |
for ( TInt index = 0; index < iSearchQuery.Count(); index++ )
|
|
228 |
{
|
|
229 |
(iSearchQuery[index])->ExternalizeL(aStream);
|
|
230 |
}
|
|
231 |
}
|
|
232 |
|
|
233 |
// ----------------------------------------------------------------------------
|
|
234 |
// CPsQuery::InternalizeL
|
|
235 |
// Initializes 'this' with the contents of aStream
|
|
236 |
// ----------------------------------------------------------------------------
|
|
237 |
EXPORT_C void CPsQuery::InternalizeL(RReadStream& aStream)
|
|
238 |
{
|
|
239 |
// Read number of query items
|
|
240 |
TInt numQueryItems = aStream.ReadUint8L();
|
|
241 |
|
|
242 |
// Internalize each item
|
|
243 |
for ( TInt index = 0; index < numQueryItems; index++ )
|
|
244 |
{
|
|
245 |
CPsQueryItem *item = CPsQueryItem::NewL();
|
|
246 |
item->InternalizeL(aStream);
|
|
247 |
this->AppendL(*item);
|
|
248 |
}
|
|
249 |
}
|
|
250 |
|