44
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2004 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: Kuten code query dialog
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
// INCLUDE FILES
|
|
30 |
#include <barsread.h>
|
|
31 |
|
|
32 |
#include <numberconversion.h>
|
|
33 |
#include <AknQueryDialog.h>
|
|
34 |
#include <aknQueryControl.h>
|
|
35 |
#include <aknnotewrappers.h> // CAknInformationNote
|
|
36 |
#include <aknsoundsystem.h>
|
|
37 |
#include <charconv.h>
|
|
38 |
#include <PtiDefs.h> //keys
|
|
39 |
#include <aknfep.rsg>
|
|
40 |
#include <avkon.hrh>
|
|
41 |
|
|
42 |
#include "AknFepUIAvkonCtrlJapaneseKutenQueryDialog.h"
|
|
43 |
|
|
44 |
// MACROS
|
|
45 |
|
|
46 |
// CONSTANTS
|
|
47 |
const TInt KKutenCodeLength = 4;
|
|
48 |
const TInt KDummyUnicode = 0xfffd;
|
|
49 |
const TInt KTextKutenCodeErrorMaxSize = 32;
|
|
50 |
const TText KHalfWidthNotSign = 0x00AC;
|
|
51 |
const TText KFullWidthNotSign = 0xFFE2;
|
|
52 |
|
|
53 |
// ================= MEMBER FUNCTIONS =========================================
|
|
54 |
|
|
55 |
// -----------------------------------------------------------------------------
|
|
56 |
// CAknFepUICtrlJapaneseKutenQueryDialog::NewL
|
|
57 |
// Two-phased constructor.
|
|
58 |
// -----------------------------------------------------------------------------
|
|
59 |
//
|
|
60 |
CAknFepUICtrlJapaneseKutenQueryDialog*
|
|
61 |
CAknFepUICtrlJapaneseKutenQueryDialog::NewL(TInt& aCharCode, const TTone& aTone)
|
|
62 |
{
|
|
63 |
CAknFepUICtrlJapaneseKutenQueryDialog* self =
|
|
64 |
new (ELeave) CAknFepUICtrlJapaneseKutenQueryDialog(aCharCode, aTone);
|
|
65 |
|
|
66 |
return self;
|
|
67 |
}
|
|
68 |
|
|
69 |
// ----------------------------------------------------------------------------
|
|
70 |
// CAknFepUICtrlJapaneseKutenQueryDialog::~CAknFepUICtrlJapaneseKutenQueryDialog()
|
|
71 |
// Destructor.
|
|
72 |
// ----------------------------------------------------------------------------
|
|
73 |
//
|
|
74 |
CAknFepUICtrlJapaneseKutenQueryDialog::~CAknFepUICtrlJapaneseKutenQueryDialog()
|
|
75 |
{
|
|
76 |
}
|
|
77 |
|
|
78 |
// ----------------------------------------------------------------------------
|
|
79 |
// CAknFepUICtrlJapaneseKutenQueryDialog::OfferKeyEventL
|
|
80 |
//
|
|
81 |
// ----------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
TKeyResponse CAknFepUICtrlJapaneseKutenQueryDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,
|
|
84 |
TEventCode aType)
|
|
85 |
{
|
|
86 |
if (aType == EEventKey)
|
|
87 |
{
|
|
88 |
TInt keyCode = aKeyEvent.iCode;
|
|
89 |
switch(keyCode)
|
|
90 |
{
|
|
91 |
case EPtiKey0:
|
|
92 |
case EPtiKey1:
|
|
93 |
case EPtiKey2:
|
|
94 |
case EPtiKey3:
|
|
95 |
case EPtiKey4:
|
|
96 |
case EPtiKey5:
|
|
97 |
case EPtiKey6:
|
|
98 |
case EPtiKey7:
|
|
99 |
case EPtiKey8:
|
|
100 |
case EPtiKey9:
|
|
101 |
{
|
|
102 |
if (iDataText.Length() == KKutenCodeLength)
|
|
103 |
{
|
|
104 |
if (SoundSystem())
|
|
105 |
{
|
|
106 |
SoundSystem()->PlaySound(EErrorTone);
|
|
107 |
}
|
|
108 |
}
|
|
109 |
}
|
|
110 |
break;
|
|
111 |
default:
|
|
112 |
break;
|
|
113 |
}
|
|
114 |
}
|
|
115 |
return CAknTextQueryDialog::OfferKeyEventL(aKeyEvent, aType);
|
|
116 |
}
|
|
117 |
|
|
118 |
// -----------------------------------------------------------------------------
|
|
119 |
// CAknFepUICtrlJapaneseKutenQueryDialog::OkToExitL
|
|
120 |
// This function is called in case pressing OK or Cancel
|
|
121 |
// -----------------------------------------------------------------------------
|
|
122 |
//
|
|
123 |
TBool CAknFepUICtrlJapaneseKutenQueryDialog::OkToExitL(TInt aButtonId)
|
|
124 |
{
|
|
125 |
TBool checkResult = EFalse;
|
|
126 |
iCharCode = ConvertKutenCode2Unicode();
|
|
127 |
if (iCharCode > 0)
|
|
128 |
{
|
|
129 |
checkResult = CAknTextQueryDialog::OkToExitL(aButtonId);
|
|
130 |
}
|
|
131 |
else
|
|
132 |
{
|
|
133 |
TResourceReader reader;
|
|
134 |
TBufC<KTextKutenCodeErrorMaxSize> string;
|
|
135 |
CCoeEnv::Static()->CreateResourceReaderLC(reader, R_AKNFEP_TEXT_KUTEN_INVALID_ERROR);
|
|
136 |
string = reader.ReadTPtrC();
|
|
137 |
CleanupStack::PopAndDestroy(); // reader
|
|
138 |
|
|
139 |
CAknInformationNote* dialog = new(ELeave) CAknInformationNote();
|
|
140 |
dialog->ExecuteLD(string);
|
|
141 |
|
|
142 |
CAknQueryControl* control = QueryControl();
|
|
143 |
if (control)
|
|
144 |
{
|
|
145 |
control->SetTextL(KNullDesC);
|
|
146 |
control->DrawNow();
|
|
147 |
}
|
|
148 |
|
|
149 |
UpdateLeftSoftKeyL();
|
|
150 |
}
|
|
151 |
|
|
152 |
return checkResult;
|
|
153 |
}
|
|
154 |
|
|
155 |
// -----------------------------------------------------------------------------
|
|
156 |
// CAknFepUICtrlJapaneseKutenQueryDialog::UpdateLeftSoftKeyL
|
|
157 |
// Updating left softkey
|
|
158 |
//
|
|
159 |
// If control text is ok then display left soft key
|
|
160 |
// otherwise don't
|
|
161 |
// -----------------------------------------------------------------------------
|
|
162 |
//
|
|
163 |
void CAknFepUICtrlJapaneseKutenQueryDialog::UpdateLeftSoftKeyL()
|
|
164 |
{
|
|
165 |
CAknQueryControl* control = QueryControl();
|
|
166 |
if ( control )
|
|
167 |
{
|
|
168 |
MakeLeftSoftkeyVisibleL();
|
|
169 |
}
|
|
170 |
}
|
|
171 |
|
|
172 |
// ----------------------------------------------------------------------------
|
|
173 |
// CAknFepUICtrlJapaneseKutenQueryDialog::CAknFepUICtrlJapaneseKutenQueryDialog()
|
|
174 |
// Overload constructor.
|
|
175 |
//-----------------------------------------------------------------------------
|
|
176 |
//
|
|
177 |
CAknFepUICtrlJapaneseKutenQueryDialog::CAknFepUICtrlJapaneseKutenQueryDialog(
|
|
178 |
TInt& aCharCode, const TTone& aTone)
|
|
179 |
: CAknTextQueryDialog(iBuffer, aTone),
|
|
180 |
iCharCode(aCharCode),
|
|
181 |
iCbaResId(R_AVKON_SOFTKEYS_CANCEL)
|
|
182 |
{
|
|
183 |
iCharCode = 0;
|
|
184 |
}
|
|
185 |
|
|
186 |
TInt CAknFepUICtrlJapaneseKutenQueryDialog::ExecuteLD(TInt aResourceId)
|
|
187 |
{
|
|
188 |
PrepareLC(aResourceId);
|
|
189 |
CEikEdwin* edwin = STATIC_CAST(CEikEdwin*, (QueryControl()->ControlByLayoutOrNull(EDataLayout)));
|
|
190 |
edwin->SetAknEditorAllowedInputModes(EAknEditorNumericInputMode);
|
|
191 |
edwin->SetAknEditorNumericKeymap(EAknEditorPlainNumberModeKeymap);
|
|
192 |
return(RunLD());
|
|
193 |
}
|
|
194 |
|
|
195 |
// -----------------------------------------------------------------------------
|
|
196 |
// CAknFepUICtrlJapaneseKutenQueryDialog::MakeLeftSoftkeyVisibleL
|
|
197 |
// Set visibility of the left softkey.
|
|
198 |
// -----------------------------------------------------------------------------
|
|
199 |
//
|
|
200 |
void CAknFepUICtrlJapaneseKutenQueryDialog::MakeLeftSoftkeyVisibleL()
|
|
201 |
{
|
|
202 |
TBool visible = EFalse;
|
|
203 |
CAknQueryControl* control = QueryControl();
|
|
204 |
if (control)
|
|
205 |
{
|
|
206 |
control->GetText(iDataText);
|
|
207 |
if (iDataText.Length() == KKutenCodeLength)
|
|
208 |
{
|
|
209 |
visible = ETrue;
|
|
210 |
}
|
|
211 |
}
|
|
212 |
else
|
|
213 |
{
|
|
214 |
visible = EFalse;
|
|
215 |
}
|
|
216 |
|
|
217 |
TUint resid = R_AKNFEP_SOFTKEYS_EMPTY_CANCEL_EMPTY;
|
|
218 |
if (visible)
|
|
219 |
{
|
|
220 |
resid = R_AVKON_SOFTKEYS_OK_CANCEL__OK;
|
|
221 |
}
|
|
222 |
if (iCbaResId != resid)
|
|
223 |
{
|
|
224 |
ButtonGroupContainer().SetCommandSetL(resid);
|
|
225 |
ButtonGroupContainer().DrawDeferred();
|
|
226 |
iCbaResId = resid;
|
|
227 |
}
|
|
228 |
|
|
229 |
}
|
|
230 |
|
|
231 |
// -----------------------------------------------------------------------------
|
|
232 |
// CAknFepUICtrlJapaneseKutenQueryDialog::ConvertKutenCode2Unicode
|
|
233 |
// Convert from Kuten code to unicode, Kuten code is 4 characters which inputted in query dialog.
|
|
234 |
// -----------------------------------------------------------------------------
|
|
235 |
TText CAknFepUICtrlJapaneseKutenQueryDialog::ConvertKutenCode2Unicode()
|
|
236 |
{
|
|
237 |
TText code = 0;
|
|
238 |
if (iBuffer.Length() == KKutenCodeLength)
|
|
239 |
{
|
|
240 |
TBuf<4 + 1> buf;
|
|
241 |
TBool valid = ETrue;
|
|
242 |
buf.FillZ(4 + 1);
|
|
243 |
|
|
244 |
for (TInt i = 0; i < KKutenCodeLength; ++i)
|
|
245 |
{
|
|
246 |
if ((iBuffer[i] >= '0') && (iBuffer[i] <= '9'))
|
|
247 |
{
|
|
248 |
buf[i] = (TText)(iBuffer[i] - '0');
|
|
249 |
}
|
|
250 |
else
|
|
251 |
{
|
|
252 |
valid = EFalse;
|
|
253 |
break;
|
|
254 |
}
|
|
255 |
}
|
|
256 |
if (valid)
|
|
257 |
{
|
|
258 |
TInt hi_code = buf[0] * 10 + buf[1] + 0x20;
|
|
259 |
TInt low_code = buf[2] * 10 + buf[3] + 0x20;
|
|
260 |
code = (TText)((hi_code << 8) + low_code);
|
|
261 |
AdjustJisCode(code);
|
|
262 |
code = JisToSjis((TText)code);
|
|
263 |
if (AdjustSjisCode(code))
|
|
264 |
{
|
|
265 |
code = ConvSjisToUnicode(code);
|
|
266 |
}
|
|
267 |
else
|
|
268 |
{
|
|
269 |
code = 0;
|
|
270 |
}
|
|
271 |
}
|
|
272 |
}
|
|
273 |
|
|
274 |
// '0244" Kuten codes is converted to '0x00AC' unicode of half-width
|
|
275 |
// character. In Japanese variant, Kuten code input must be always
|
|
276 |
// Full-width character, so it converts from '0x00AC' to '0xFFE2'
|
|
277 |
if (code == KHalfWidthNotSign)
|
|
278 |
{
|
|
279 |
code = KFullWidthNotSign;
|
|
280 |
}
|
|
281 |
|
|
282 |
return code;
|
|
283 |
}
|
|
284 |
|
|
285 |
void CAknFepUICtrlJapaneseKutenQueryDialog::AdjustJisCode(TText& aJisCode)
|
|
286 |
{
|
|
287 |
TUint JisHi = (aJisCode >> 8) & 0x000000ff;
|
|
288 |
TUint JisLow = aJisCode & 0x000000ff;
|
|
289 |
|
|
290 |
if ((JisHi < EJisFirstMin) || (JisHi > EJisFirstMax))
|
|
291 |
{
|
|
292 |
JisHi = 0;
|
|
293 |
JisLow = 0;
|
|
294 |
}
|
|
295 |
else
|
|
296 |
{
|
|
297 |
if ((JisLow < EJisSecondMin) || (JisLow > EJisSecondMax))
|
|
298 |
{
|
|
299 |
JisHi = 0;
|
|
300 |
JisLow = 0;
|
|
301 |
}
|
|
302 |
else
|
|
303 |
{
|
|
304 |
if (JisHi == EJisFirstMax)
|
|
305 |
{
|
|
306 |
if (JisLow > EJisLastSecondMax)
|
|
307 |
{
|
|
308 |
JisHi = 0;
|
|
309 |
JisLow = 0;
|
|
310 |
}
|
|
311 |
}
|
|
312 |
}
|
|
313 |
}
|
|
314 |
|
|
315 |
aJisCode = (TText)((JisHi << 8) + JisLow);
|
|
316 |
return;
|
|
317 |
}
|
|
318 |
|
|
319 |
TBool CAknFepUICtrlJapaneseKutenQueryDialog::AdjustSjisCode(TText& aSjisCode)
|
|
320 |
{
|
|
321 |
TUint SjisHi = (aSjisCode >> 8) & 0x000000ff;
|
|
322 |
TUint SjisLow = aSjisCode & 0x000000ff;
|
|
323 |
|
|
324 |
if ((SjisHi < ESjisFirstMin1) || (SjisHi > ESjisFirstMax2)
|
|
325 |
|| ((SjisHi > ESjisFirstMax1) && (SjisHi < ESjisFirstMin2)))
|
|
326 |
{
|
|
327 |
SjisHi = 0;
|
|
328 |
SjisLow = 0;
|
|
329 |
}
|
|
330 |
else
|
|
331 |
{
|
|
332 |
if ((SjisLow < ESjisSecondMin1) || (SjisLow > ESjisSecondMax2)
|
|
333 |
|| ((SjisLow > ESjisSecondMax1) && (SjisLow < ESjisSecondMin2)))
|
|
334 |
{
|
|
335 |
SjisHi = 0;
|
|
336 |
SjisLow = 0;
|
|
337 |
}
|
|
338 |
|
|
339 |
/*
|
|
340 |
else
|
|
341 |
{
|
|
342 |
if (SjisHi == ESjisFirstMax2)
|
|
343 |
{
|
|
344 |
if (SjisLow > ESjisSecondMax2)
|
|
345 |
{
|
|
346 |
SjisHi = 0;
|
|
347 |
SjisLow = 0;
|
|
348 |
}
|
|
349 |
}
|
|
350 |
}
|
|
351 |
*/
|
|
352 |
}
|
|
353 |
|
|
354 |
if (CheckSjisCode((TText)((SjisHi << 8) + SjisLow)))
|
|
355 |
{
|
|
356 |
aSjisCode = (TText)((SjisHi << 8) + SjisLow);
|
|
357 |
return ETrue;
|
|
358 |
}
|
|
359 |
else
|
|
360 |
{
|
|
361 |
return EFalse;
|
|
362 |
}
|
|
363 |
}
|
|
364 |
|
|
365 |
TText CAknFepUICtrlJapaneseKutenQueryDialog::JisToSjis(TText aJisCode)
|
|
366 |
{
|
|
367 |
if (aJisCode == 0)
|
|
368 |
{
|
|
369 |
return 0;
|
|
370 |
}
|
|
371 |
|
|
372 |
TUint jis_hi = (aJisCode >> 8) & 0x000000ff; /* hi byte */
|
|
373 |
TUint jis_lo = aJisCode & 0x000000ff; /* low byte */
|
|
374 |
|
|
375 |
jis_lo += 0x1F;
|
|
376 |
if ((jis_hi & 1) == 0)
|
|
377 |
{
|
|
378 |
jis_hi >>= 1;
|
|
379 |
jis_hi--;
|
|
380 |
jis_lo += 0x5E;
|
|
381 |
}
|
|
382 |
else
|
|
383 |
{
|
|
384 |
jis_hi >>= 1;
|
|
385 |
}
|
|
386 |
if (jis_lo >= 0x7F)
|
|
387 |
{
|
|
388 |
jis_lo++;
|
|
389 |
}
|
|
390 |
jis_hi += (jis_hi > 0x2E) ? 0xB1 : 0x71;
|
|
391 |
|
|
392 |
return (TText)((jis_hi << 8) + jis_lo);
|
|
393 |
}
|
|
394 |
|
|
395 |
TBool CAknFepUICtrlJapaneseKutenQueryDialog::CheckSjisCode(TText aSjisCode)
|
|
396 |
{
|
|
397 |
const TText8 first = (TText8)((aSjisCode >> 8) & 0x000000ff);
|
|
398 |
const TText8 second = (TText8)(aSjisCode & 0x000000ff);
|
|
399 |
if ((((first >= ESjisFirstMin1) && (first <= ESjisFirstMax1))
|
|
400 |
|| ((first >= ESjisFirstMin2) && (first <= ESjisFirstMax2)))
|
|
401 |
&& (((second >= ESjisSecondMin1) && (second <= ESjisSecondMax1))
|
|
402 |
|| ((second >= ESjisSecondMin2) && (second <= ESjisSecondMax2))))
|
|
403 |
{
|
|
404 |
return ETrue;
|
|
405 |
}
|
|
406 |
else
|
|
407 |
{
|
|
408 |
return EFalse;
|
|
409 |
}
|
|
410 |
}
|
|
411 |
|
|
412 |
TText CAknFepUICtrlJapaneseKutenQueryDialog::ConvSjisToUnicode(TText aSjisCode)
|
|
413 |
{
|
|
414 |
TText8 sjis[2];
|
|
415 |
TText unicode = 0;
|
|
416 |
if (aSjisCode & 0xff00)
|
|
417 |
{
|
|
418 |
sjis[0] = (TText8)((aSjisCode & 0xff00) >> 8);
|
|
419 |
sjis[1] = (TText8)(aSjisCode & 0x00ff);
|
|
420 |
}
|
|
421 |
else
|
|
422 |
{
|
|
423 |
sjis[0] = (TText8)aSjisCode;
|
|
424 |
sjis[1] = '\0';
|
|
425 |
}
|
|
426 |
|
|
427 |
TPtrC8 foreign((TUint8*)&sjis[0], sizeof sjis);
|
|
428 |
TPtr16 unicode_des((TUint16*)&unicode, 1);
|
|
429 |
RFs fileServerSession;
|
|
430 |
|
|
431 |
if (fileServerSession.Connect() == 0)
|
|
432 |
{
|
|
433 |
CCnvCharacterSetConverter* charconv = NULL;
|
|
434 |
TRAPD(error, charconv = CCnvCharacterSetConverter::NewL());
|
|
435 |
if (error == KErrNone)
|
|
436 |
{
|
|
437 |
TRAP(error, charconv->PrepareToConvertToOrFromL(KCharacterSetIdentifierShiftJis, fileServerSession));
|
|
438 |
if (error == KErrNone)
|
|
439 |
{
|
|
440 |
TInt state = CCnvCharacterSetConverter::KStateDefault;
|
|
441 |
charconv->ConvertToUnicode(unicode_des, foreign, state);
|
|
442 |
}
|
|
443 |
delete charconv;
|
|
444 |
}
|
|
445 |
fileServerSession.Close();
|
|
446 |
}
|
|
447 |
if (unicode == (TText)KDummyUnicode)
|
|
448 |
{
|
|
449 |
unicode = 0;
|
|
450 |
}
|
|
451 |
return unicode;
|
|
452 |
}
|
|
453 |
|
|
454 |
// End of File
|