33
|
1 |
/*
|
|
2 |
* Copyright (c) 2004-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: Implementation of DialUtils.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
|
|
22 |
#include <featmgr.h> // Feature Manager.
|
|
23 |
#include "dialutilsimpl.h" // Interface.
|
|
24 |
|
|
25 |
#include <centralrepository.h> // Central repository
|
|
26 |
#include <settingsinternalcrkeys.h> // Settings Central Repository keys.
|
|
27 |
|
|
28 |
// CONSTANTS
|
|
29 |
|
|
30 |
// Prefix change Off. See SharedDataKeys.h and SettingsInternalCRKeys.h
|
|
31 |
const TInt KDiUtPrefixChangeOff = 0;
|
|
32 |
// Prefix change On. See SharedDataKeys.h and SettingsInternalCRKeys.h
|
|
33 |
const TInt KDiUtPrefixChangeOn = 1;
|
|
34 |
|
|
35 |
// International prefix.
|
|
36 |
_LIT( KDiUtIntPrefix, "+" );
|
|
37 |
// International prefix.
|
|
38 |
_LIT( KDiUtJapanPrefix, "+81" );
|
|
39 |
// Zero prefix.
|
|
40 |
_LIT( KDiUtZeroPrefix, "0" );
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
45 |
|
|
46 |
// -----------------------------------------------------------------------------
|
|
47 |
// CDialUtilsImpl::CDialUtilsImpl
|
|
48 |
//
|
|
49 |
// C++ default constructor can NOT contain any code, that might leave.
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
CDialUtilsImpl::CDialUtilsImpl()
|
|
53 |
{
|
|
54 |
}
|
|
55 |
|
|
56 |
|
|
57 |
// -----------------------------------------------------------------------------
|
|
58 |
// CDialUtilsImpl::ConstructL
|
|
59 |
//
|
|
60 |
// Symbian 2nd phase constructor can leave.
|
|
61 |
// -----------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
void CDialUtilsImpl::ConstructL()
|
|
64 |
{
|
|
65 |
// Sets up TLS, must be done before FeatureManager is used.
|
|
66 |
FeatureManager::InitializeLibL();
|
|
67 |
|
|
68 |
iRepository = CRepository::NewL( KCRUidTelephonySettings );
|
|
69 |
}
|
|
70 |
|
|
71 |
|
|
72 |
// -----------------------------------------------------------------------------
|
|
73 |
// CDialUtilsImpl::NewL
|
|
74 |
//
|
|
75 |
// Two-phased constructor.
|
|
76 |
// -----------------------------------------------------------------------------
|
|
77 |
//
|
|
78 |
CDialUtilsImpl* CDialUtilsImpl::NewL()
|
|
79 |
{
|
|
80 |
CDialUtilsImpl* self = new( ELeave ) CDialUtilsImpl;
|
|
81 |
|
|
82 |
CleanupStack::PushL( self );
|
|
83 |
self->ConstructL();
|
|
84 |
CleanupStack::Pop();
|
|
85 |
|
|
86 |
return self;
|
|
87 |
}
|
|
88 |
|
|
89 |
|
|
90 |
// -----------------------------------------------------------------------------
|
|
91 |
// CDialUtilsImpl::~CDialUtilsImpl
|
|
92 |
//
|
|
93 |
// Destructor.
|
|
94 |
// -----------------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
CDialUtilsImpl::~CDialUtilsImpl()
|
|
97 |
{
|
|
98 |
delete iRepository;
|
|
99 |
|
|
100 |
// Frees the TLS! Must be done after FeatureManager is used.
|
|
101 |
FeatureManager::UnInitializeLib();
|
|
102 |
}
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
// -----------------------------------------------------------------------------
|
|
107 |
// CDialUtilsImpl::CheckNumber
|
|
108 |
//
|
|
109 |
//
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
//
|
|
112 |
TInt CDialUtilsImpl::CheckNumber( HBufC& aPhoneNumber )
|
|
113 |
{
|
|
114 |
TInt err = KErrNone;
|
|
115 |
TBool checkPrefix =
|
|
116 |
FeatureManager::FeatureSupported( KFeatureIdJapanPrefixChange );
|
|
117 |
|
|
118 |
if ( checkPrefix )
|
|
119 |
{
|
|
120 |
TInt prefixMode = KDiUtPrefixChangeOff; // Default: Off.
|
|
121 |
|
|
122 |
if ( !err )
|
|
123 |
{
|
|
124 |
err = iRepository->Get(
|
|
125 |
KSettingsDialPrefixChangeMode,
|
|
126 |
prefixMode );
|
|
127 |
|
|
128 |
if ( !err )
|
|
129 |
{
|
|
130 |
// Shared data information is ok, so act according to it.
|
|
131 |
switch ( prefixMode )
|
|
132 |
{
|
|
133 |
case KDiUtPrefixChangeOff:
|
|
134 |
{
|
|
135 |
// Nothing needs to be done, so let the phone number to
|
|
136 |
// be unchanged and just break.
|
|
137 |
break;
|
|
138 |
}
|
|
139 |
|
|
140 |
case KDiUtPrefixChangeOn:
|
|
141 |
{
|
|
142 |
TDiUtPrefixText prefixText;
|
|
143 |
|
|
144 |
err = iRepository->Get(
|
|
145 |
KSettingsDialPrefixText,
|
|
146 |
prefixText );
|
|
147 |
|
|
148 |
if ( !err )
|
|
149 |
{
|
|
150 |
err = CombineTexts( aPhoneNumber.Des(), prefixText );
|
|
151 |
}
|
|
152 |
break;
|
|
153 |
}
|
|
154 |
|
|
155 |
default:
|
|
156 |
// Should never happen, value is corrupted.
|
|
157 |
err = KErrCorrupt;
|
|
158 |
break;
|
|
159 |
}
|
|
160 |
}
|
|
161 |
}
|
|
162 |
}
|
|
163 |
return err;
|
|
164 |
}
|
|
165 |
|
|
166 |
|
|
167 |
// -----------------------------------------------------------------------------
|
|
168 |
// CDialUtilsImpl::CombineTexts
|
|
169 |
//
|
|
170 |
//
|
|
171 |
// -----------------------------------------------------------------------------
|
|
172 |
//
|
|
173 |
TInt CDialUtilsImpl::CombineTexts(
|
|
174 |
TPtr aPhoneNumber,
|
|
175 |
const TDiUtPrefixText& aPrefixText ) const
|
|
176 |
{
|
|
177 |
TInt err = KErrNone;
|
|
178 |
|
|
179 |
TInt beginning = 0; // The beginning for replacement.
|
|
180 |
TInt replaceLength = 0; // The string length to be replaced.
|
|
181 |
TInt location = KErrNotFound; // The location of searched string.
|
|
182 |
|
|
183 |
// Try to find Japan prefix.
|
|
184 |
location = aPhoneNumber.Find( KDiUtJapanPrefix );
|
|
185 |
if ( location == beginning )
|
|
186 |
{
|
|
187 |
// The string was found, so make replacement.
|
|
188 |
// Safe because zeroPrefix < KDiUtJapanPrefix.
|
|
189 |
replaceLength = KDiUtJapanPrefix().Length();
|
|
190 |
aPhoneNumber.Replace( beginning, replaceLength, KDiUtZeroPrefix );
|
|
191 |
}
|
|
192 |
else
|
|
193 |
{
|
|
194 |
// Try to find international prefix.
|
|
195 |
location = aPhoneNumber.Find( KDiUtIntPrefix );
|
|
196 |
if ( location == beginning )
|
|
197 |
{
|
|
198 |
replaceLength = KDiUtIntPrefix().Length();
|
|
199 |
// The string was found, so try to make replacement.
|
|
200 |
const TInt phoneNumLength = aPhoneNumber.Length();
|
|
201 |
const TInt prefixLength = aPrefixText.Length();
|
|
202 |
|
|
203 |
TInt stringLength =
|
|
204 |
( phoneNumLength + prefixLength - replaceLength );
|
|
205 |
|
|
206 |
if ( aPhoneNumber.MaxLength() >= stringLength )
|
|
207 |
{
|
|
208 |
// There is enough space to make this replace.
|
|
209 |
aPhoneNumber.Replace( beginning, replaceLength, aPrefixText );
|
|
210 |
}
|
|
211 |
else
|
|
212 |
{
|
|
213 |
// There is no space to combine the strings, so inform it.
|
|
214 |
err = KErrOverflow;
|
|
215 |
}
|
|
216 |
}
|
|
217 |
}
|
|
218 |
|
|
219 |
return err;
|
|
220 |
}
|
|
221 |
|
|
222 |
|
|
223 |
// End of file
|