43
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-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: CapUtil implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
|
|
21 |
#include <pathinfo.h>
|
|
22 |
#include <sysutil.h>
|
|
23 |
#include <hal.h>
|
|
24 |
#include <hal_data.h>
|
|
25 |
#include <etelmm.h> // for etel
|
|
26 |
#include <mmtsy_names.h> // for etel
|
|
27 |
#include <utf.h>
|
|
28 |
#include <eikenv.h>
|
|
29 |
#include <driveinfo.h>
|
|
30 |
#include <centralrepository.h>
|
|
31 |
#include <sysutildomaincrkeys.h>
|
|
32 |
|
|
33 |
#include "caputils.h"
|
|
34 |
#include "capability.h"
|
|
35 |
#include "debug.h"
|
|
36 |
|
|
37 |
const TInt KPackageSize = 65536;
|
|
38 |
const TInt KDefaultArrayGranularity = 5;
|
|
39 |
// ============================= MEMBER FUNCTIONS ===============================
|
|
40 |
|
|
41 |
// -----------------------------------------------------------------------------
|
|
42 |
// CapUtil::GetDefaultRootPathL( RFs& aFs, TDes& aRootPath )
|
|
43 |
// Gets default root path
|
|
44 |
// -----------------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
void CapUtil::GetDefaultRootPathL( RFs& aFs, TDes& aRootPath )
|
|
47 |
{
|
|
48 |
TRACE_FUNC_ENTRY;
|
|
49 |
// Use the default mass storage if it is internal drive
|
|
50 |
TInt msDrive;
|
|
51 |
User::LeaveIfError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, msDrive ) );
|
|
52 |
LOGGER_WRITE_1("drive: %d", msDrive);
|
|
53 |
|
|
54 |
TUint msStatus( 0 );
|
|
55 |
TInt err = DriveInfo::GetDriveStatus( aFs, msDrive, msStatus );
|
|
56 |
LOGGER_WRITE_1("DriveInfo::GetDriveStatus err: %d", err);
|
|
57 |
|
|
58 |
// if no errors, also check drive status
|
|
59 |
if( !err && !( msStatus & DriveInfo::EDrivePresent )
|
|
60 |
|| msStatus & DriveInfo::EDriveCorrupt )
|
|
61 |
{
|
|
62 |
LOGGER_WRITE( "Internal mass storage not present or corrupted" );
|
|
63 |
err = KErrNotFound;
|
|
64 |
}
|
|
65 |
|
|
66 |
if ( !err && ( msStatus & DriveInfo::EDriveInternal ) )
|
|
67 |
{
|
|
68 |
// Use internal mass storage
|
|
69 |
LOGGER_WRITE( "Use internal mass storage" );
|
|
70 |
User::LeaveIfError( PathInfo::GetRootPath( aRootPath, msDrive ) );
|
|
71 |
}
|
|
72 |
else
|
|
73 |
{
|
|
74 |
// Use phone memory
|
|
75 |
LOGGER_WRITE( "Use phone memory" );
|
|
76 |
StrCopy( aRootPath, PathInfo::PhoneMemoryRootPath() );
|
|
77 |
}
|
|
78 |
LOGGER_WRITE_1( "rootPath: %S", &aRootPath );
|
|
79 |
TRACE_FUNC_EXIT;
|
|
80 |
}
|
|
81 |
|
|
82 |
// -----------------------------------------------------------------------------
|
|
83 |
// CapUtil::GetMemoryType( RFs& aFs, TDes& aMemoryType, const TInt aDrive )
|
|
84 |
// Gets drive memory type
|
|
85 |
// -----------------------------------------------------------------------------
|
|
86 |
//
|
|
87 |
void CapUtil::GetMemoryType( RFs& aFs, TDes& aMemoryType, const TInt aDrive )
|
|
88 |
{
|
|
89 |
TRACE_FUNC_ENTRY;
|
|
90 |
LOGGER_WRITE_1("aDrive: %d", aDrive);
|
|
91 |
aMemoryType = KNullDesC;
|
|
92 |
TUint driveStatus;
|
|
93 |
TInt err = DriveInfo::GetDriveStatus( aFs, aDrive, driveStatus );
|
|
94 |
if( err )
|
|
95 |
{
|
|
96 |
LOGGER_WRITE_1( "CapUtil::GetMemoryType() : DriveInfo::GetDriveStatus err: %d", err );
|
|
97 |
return;
|
|
98 |
}
|
|
99 |
// search internal or removable drives
|
|
100 |
TBool searchInternalDrives;
|
|
101 |
if( driveStatus & DriveInfo::EDriveInternal )
|
|
102 |
{
|
|
103 |
aMemoryType = KMediaFlash;
|
|
104 |
searchInternalDrives = ETrue;
|
|
105 |
}
|
|
106 |
else
|
|
107 |
{
|
|
108 |
aMemoryType = KMediaMMC;
|
|
109 |
searchInternalDrives = EFalse;
|
|
110 |
}
|
|
111 |
|
|
112 |
TInt typeNumber(0);
|
|
113 |
TInt driveCount;
|
|
114 |
TDriveList driveList;
|
|
115 |
|
|
116 |
err = DriveInfo::GetUserVisibleDrives( aFs, driveList, driveCount );
|
|
117 |
if( err )
|
|
118 |
{
|
|
119 |
LOGGER_WRITE_1( "CapUtil::GetMemoryType() : DriveInfo::GetUserVisibleDrives err: %d", err );
|
|
120 |
return;
|
|
121 |
}
|
|
122 |
|
|
123 |
for( TInt i = EDriveA; i <= aDrive; i++ )
|
|
124 |
{
|
|
125 |
if( driveList[i] )
|
|
126 |
{
|
|
127 |
TUint driveStatus;
|
|
128 |
err = DriveInfo::GetDriveStatus( aFs, i, driveStatus );
|
|
129 |
if( err )
|
|
130 |
{
|
|
131 |
LOGGER_WRITE_1( "CapUtil::GetMemoryType() : DriveInfo::GetDriveStatus err: %d", err );
|
|
132 |
continue;
|
|
133 |
}
|
|
134 |
|
|
135 |
if( !(driveStatus & DriveInfo::EDrivePresent )
|
|
136 |
|| driveStatus & DriveInfo::EDriveCorrupt )
|
|
137 |
{
|
|
138 |
LOGGER_WRITE( "not present or corrupted" );
|
|
139 |
continue;
|
|
140 |
}
|
|
141 |
|
|
142 |
if( driveStatus & DriveInfo::EDriveInternal )
|
|
143 |
{
|
|
144 |
if( searchInternalDrives )
|
|
145 |
{
|
|
146 |
typeNumber++;
|
|
147 |
}
|
|
148 |
}
|
|
149 |
else if( driveStatus & DriveInfo::EDriveRemovable )
|
|
150 |
{
|
|
151 |
if( !searchInternalDrives )
|
|
152 |
{
|
|
153 |
typeNumber++;
|
|
154 |
}
|
|
155 |
}
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
if( typeNumber > 1 )
|
|
160 |
{
|
|
161 |
aMemoryType.AppendNum( typeNumber );
|
|
162 |
}
|
|
163 |
TRACE_FUNC_EXIT;
|
|
164 |
}
|
|
165 |
|
|
166 |
// -----------------------------------------------------------------------------
|
|
167 |
// CapUtil::GetOperatornameL(TDes& aLongName, TDes& aCountryCode, TDes& aNetworkID)
|
|
168 |
// Gets phone operator name, country code, networkID.
|
|
169 |
// -----------------------------------------------------------------------------
|
|
170 |
//
|
|
171 |
void CapUtil::GetOperatorNameL(TDes& aLongName, TDes& aCountryCode, TDes& aNetworkID)
|
|
172 |
{
|
|
173 |
TRACE_FUNC_ENTRY;
|
|
174 |
TUint32 networkCaps;
|
|
175 |
RTelServer::TPhoneInfo phoneInfo;
|
|
176 |
|
|
177 |
RTelServer server;
|
|
178 |
RMobilePhone mobilePhone;
|
|
179 |
User::LeaveIfError( server.Connect() );
|
|
180 |
CleanupClosePushL( server );
|
|
181 |
|
|
182 |
TInt numPhones;
|
|
183 |
User::LeaveIfError( server.EnumeratePhones( numPhones ) );
|
|
184 |
server.GetPhoneInfo( 0, phoneInfo );
|
|
185 |
|
|
186 |
User::LeaveIfError( mobilePhone.Open( server, phoneInfo.iName ) );
|
|
187 |
CleanupClosePushL( mobilePhone );
|
|
188 |
User::LeaveIfError( mobilePhone.GetNetworkCaps( networkCaps ) );
|
|
189 |
|
|
190 |
RMobilePhone::TMobilePhoneNetworkInfoV1 mobilePhoneNetworkInfo;
|
|
191 |
RMobilePhone::TMobilePhoneNetworkInfoV1Pckg mobilePhoneNetworkInfoPckg(
|
|
192 |
mobilePhoneNetworkInfo );
|
|
193 |
RMobilePhone::TMobilePhoneLocationAreaV1 mobilePhoneLocationArea;
|
|
194 |
|
|
195 |
if (networkCaps & RMobilePhone::KCapsGetCurrentNetwork)
|
|
196 |
{
|
|
197 |
TRequestStatus status;
|
|
198 |
mobilePhone.GetCurrentNetwork(
|
|
199 |
status, mobilePhoneNetworkInfoPckg, mobilePhoneLocationArea );
|
|
200 |
User::WaitForRequest( status );
|
|
201 |
User::LeaveIfError( status.Int() );
|
|
202 |
}
|
|
203 |
|
|
204 |
CleanupStack::PopAndDestroy( &mobilePhone );
|
|
205 |
CleanupStack::PopAndDestroy( &server );
|
|
206 |
if ( mobilePhoneNetworkInfo.iLongName.Length() > 0 )
|
|
207 |
{
|
|
208 |
StrCopy( aLongName, mobilePhoneNetworkInfo.iLongName );
|
|
209 |
}
|
|
210 |
else if ( mobilePhoneNetworkInfo.iShortName.Length() > 0 )
|
|
211 |
{
|
|
212 |
StrCopy( aLongName, mobilePhoneNetworkInfo.iShortName );
|
|
213 |
}
|
|
214 |
else
|
|
215 |
{
|
|
216 |
StrCopy( aLongName, mobilePhoneNetworkInfo.iDisplayTag );
|
|
217 |
}
|
|
218 |
StrCopy( aCountryCode, mobilePhoneNetworkInfo.iCountryCode );
|
|
219 |
StrCopy( aNetworkID, mobilePhoneNetworkInfo.iNetworkId );
|
|
220 |
|
|
221 |
TRACE_FUNC_EXIT;
|
|
222 |
}
|
|
223 |
// -----------------------------------------------------------------------------
|
|
224 |
// CapUtil::GetManufacturer(TDes& aText)
|
|
225 |
// Gets phone manufacturer from HAL. In case manufacturer is not known,
|
|
226 |
// -----------------------------------------------------------------------------
|
|
227 |
//
|
|
228 |
void CapUtil::GetManufacturer(TDes& aText)
|
|
229 |
{
|
|
230 |
TRACE_FUNC_ENTRY;
|
|
231 |
TInt num(KErrNotFound);
|
|
232 |
|
|
233 |
HAL::Get(HALData::EManufacturer, num);
|
|
234 |
|
|
235 |
switch (num)
|
|
236 |
{
|
|
237 |
case HALData::EManufacturer_Ericsson:
|
|
238 |
aText=KManufacturerEricsson;
|
|
239 |
break;
|
|
240 |
case HALData::EManufacturer_Motorola:
|
|
241 |
aText=KManufacturerMotorola;
|
|
242 |
break;
|
|
243 |
case HALData::EManufacturer_Nokia:
|
|
244 |
aText=KManufacturerNokia;
|
|
245 |
break;
|
|
246 |
case HALData::EManufacturer_Panasonic:
|
|
247 |
aText=KManufacturerPanasonic;
|
|
248 |
break;
|
|
249 |
case HALData::EManufacturer_Psion:
|
|
250 |
aText=KManufacturerPsion;
|
|
251 |
break;
|
|
252 |
case HALData::EManufacturer_Intel:
|
|
253 |
aText=KManufacturerIntel;
|
|
254 |
break;
|
|
255 |
case HALData::EManufacturer_Cogent:
|
|
256 |
aText=KManufacturerCogent;
|
|
257 |
break;
|
|
258 |
case HALData::EManufacturer_Cirrus:
|
|
259 |
aText=KManufacturerCirrus;
|
|
260 |
break;
|
|
261 |
case HALData::EManufacturer_Linkup:
|
|
262 |
aText=KManufacturerLinkup;
|
|
263 |
break;
|
|
264 |
case HALData::EManufacturer_TexasInstruments:
|
|
265 |
aText=KManufacturerTexasInstruments;
|
|
266 |
break;
|
|
267 |
default:
|
|
268 |
aText=KNullDesC;
|
|
269 |
break;
|
|
270 |
}
|
|
271 |
|
|
272 |
TRACE_FUNC_EXIT;
|
|
273 |
}
|
|
274 |
|
|
275 |
// -----------------------------------------------------------------------------
|
|
276 |
// CapUtil::GetLanguage(TDes& aText)
|
|
277 |
// Gets language
|
|
278 |
// -----------------------------------------------------------------------------
|
|
279 |
//
|
|
280 |
void CapUtil::GetLanguage(TDes& aText)
|
|
281 |
{
|
|
282 |
TRACE_FUNC_ENTRY;
|
|
283 |
TLanguage lang=User::Language();
|
|
284 |
GetLanguageString(lang, aText);
|
|
285 |
TRACE_FUNC_EXIT;
|
|
286 |
}
|
|
287 |
|
|
288 |
// -----------------------------------------------------------------------------
|
|
289 |
// CapUtil::GetSWVersionL(TDes& aVersion, TDes& aDate, TDes& aModel)
|
|
290 |
// Gets SW version, SW version date and device model from SysUtil.
|
|
291 |
// -----------------------------------------------------------------------------
|
|
292 |
//
|
|
293 |
void CapUtil::GetSWVersionL(TDes& aVersion, TDes& aDate, TDes& aModel)
|
|
294 |
{
|
|
295 |
TRACE_FUNC_ENTRY;
|
|
296 |
TBuf<KBufSize> buf;
|
|
297 |
aVersion=KNullDesC;
|
|
298 |
aDate=KNullDesC;
|
|
299 |
aModel=KNullDesC;
|
|
300 |
|
|
301 |
User::LeaveIfError( SysUtil::GetSWVersion( buf ) );
|
|
302 |
RArray<TPtrC> arr(KDefaultArrayGranularity);
|
|
303 |
CleanupClosePushL( arr );
|
|
304 |
|
|
305 |
CapUtil::SplitL(buf, '\n', arr);
|
|
306 |
const TInt KFieldsToFind = 3;
|
|
307 |
if ( arr.Count() < KFieldsToFind )
|
|
308 |
{
|
|
309 |
User::Leave( KErrNotFound );
|
|
310 |
}
|
|
311 |
|
|
312 |
StrCopy( aVersion, arr[0] );
|
|
313 |
aVersion.Trim();
|
|
314 |
|
|
315 |
StrCopy(aModel,arr[2]);
|
|
316 |
aModel.Trim();
|
|
317 |
|
|
318 |
TBuf<KTagSize> date;
|
|
319 |
StrCopy(date, arr[1]);
|
|
320 |
TTime t;
|
|
321 |
t.UniversalTime(); // this is to avoid warnings
|
|
322 |
TRAPD( err, t = ParseDateL( date ) );
|
|
323 |
if ( err == KErrNone )
|
|
324 |
{
|
|
325 |
CapabilityDate( aDate, t );
|
|
326 |
}
|
|
327 |
|
|
328 |
CleanupStack::PopAndDestroy( &arr );
|
|
329 |
|
|
330 |
TRACE_FUNC_EXIT;
|
|
331 |
}
|
|
332 |
|
|
333 |
// -----------------------------------------------------------------------------
|
|
334 |
// CapUtil::InitMemoryInfo(TMemoryInfo& aInfo)
|
|
335 |
// Initializes TMemoryInfo.
|
|
336 |
// -----------------------------------------------------------------------------
|
|
337 |
//
|
|
338 |
void CapUtil::InitMemoryInfo(TMemoryInfo& aInfo)
|
|
339 |
{
|
|
340 |
aInfo.iDriveNum = KErrNotFound;
|
|
341 |
aInfo.iDriveLetter = KNoChar;
|
|
342 |
aInfo.iLocation = KNullDesC;
|
|
343 |
aInfo.iFree = KErrNotFound;
|
|
344 |
aInfo.iUsed = KErrNotFound;
|
|
345 |
aInfo.iShared = EFalse;
|
|
346 |
aInfo.iFileSize = KErrNotFound;
|
|
347 |
aInfo.iFolderSize = KErrNotFound;
|
|
348 |
aInfo.iFileNameSize = KMaxFileName; // TFileName 256
|
|
349 |
aInfo.iFolderNameSize = KMaxFileName; // TFileName 256
|
|
350 |
aInfo.iCaseSensitivity = EFalse;
|
|
351 |
}
|
|
352 |
|
|
353 |
// -----------------------------------------------------------------------------
|
|
354 |
// CapUtil::GetMemoryInfoL( const RFs& aFs, TInt aDriveNumber, TMemoryInfo& aInfo )
|
|
355 |
// Get memory information for one drive.
|
|
356 |
// -----------------------------------------------------------------------------
|
|
357 |
//
|
|
358 |
void CapUtil::GetMemoryInfoL( const RFs& aFs, const TInt aDriveNumber, TMemoryInfo& aInfo )
|
|
359 |
{
|
|
360 |
TRACE_FUNC_ENTRY;
|
|
361 |
LOGGER_WRITE_1(" aDriveNumber: %d", aDriveNumber);
|
|
362 |
|
|
363 |
TVolumeInfo volumeInfo;
|
|
364 |
TDriveInfo driveInfo;
|
|
365 |
|
|
366 |
InitMemoryInfo( aInfo );
|
|
367 |
|
|
368 |
User::LeaveIfError( aFs.Drive(driveInfo, aDriveNumber) );
|
|
369 |
if ( driveInfo.iDriveAtt == (TUint)KDriveAbsent )
|
|
370 |
{
|
|
371 |
LOGGER_WRITE(" iDriveAtt == (TUint)KDriveAbsent, Leave KErrNotFound");
|
|
372 |
User::Leave( KErrNotFound );
|
|
373 |
}
|
|
374 |
|
|
375 |
User::LeaveIfError( aFs.Volume(volumeInfo, aDriveNumber) );
|
|
376 |
|
|
377 |
User::LeaveIfError( aFs.DriveToChar(aDriveNumber, aInfo.iDriveLetter) );
|
|
378 |
aInfo.iDriveNum = aDriveNumber;
|
|
379 |
aInfo.iLocation.Append( aInfo.iDriveLetter );
|
|
380 |
aInfo.iLocation.Append( KDriveDelimiter );
|
|
381 |
aInfo.iLocation.Append( KPathDelimiter );
|
|
382 |
aInfo.iFree = volumeInfo.iFree;
|
|
383 |
aInfo.iUsed = volumeInfo.iSize - volumeInfo.iFree;
|
|
384 |
|
|
385 |
// set free memory up to critical level for all drives
|
|
386 |
CRepository* repository = CRepository::NewLC( KCRUidDiskLevel );
|
|
387 |
TInt criticalLevel(0);
|
|
388 |
User::LeaveIfError( repository->Get( KDiskCriticalThreshold, criticalLevel ) );
|
|
389 |
CleanupStack::PopAndDestroy( repository );
|
|
390 |
criticalLevel += KPackageSize; // add obex package size to critical level
|
|
391 |
LOGGER_WRITE_1( "CapUtil::GetMemoryInfoL() criticalLevel: %d", criticalLevel ) ;
|
|
392 |
if ( aInfo.iFree > criticalLevel )
|
|
393 |
{
|
|
394 |
aInfo.iFree = aInfo.iFree - criticalLevel;
|
|
395 |
}
|
|
396 |
else
|
|
397 |
{
|
|
398 |
aInfo.iFree = 0;
|
|
399 |
}
|
|
400 |
|
|
401 |
aInfo.iFileSize = aInfo.iFree;
|
|
402 |
aInfo.iFolderSize = aInfo.iFree;
|
|
403 |
TRACE_FUNC_EXIT;
|
|
404 |
}
|
|
405 |
|
|
406 |
// -----------------------------------------------------------------------------
|
|
407 |
// CapUtil::GetFileListL( RFs& aFs, const TDesC& aDir,
|
|
408 |
// RArray<TFileName>& aList)
|
|
409 |
// Finds all files in aDir.
|
|
410 |
// -----------------------------------------------------------------------------
|
|
411 |
//
|
|
412 |
void CapUtil::GetFileListL( const RFs& aFs, const TDesC& aDir,
|
|
413 |
RArray<TFileName>& aList)
|
|
414 |
{
|
|
415 |
TRACE_FUNC_ENTRY;
|
|
416 |
|
|
417 |
aList.Reset();
|
|
418 |
|
|
419 |
CDir* dir( NULL );
|
|
420 |
User::LeaveIfError( aFs.GetDir( aDir, KEntryAttMatchMask, ESortByName, dir ) );
|
|
421 |
CleanupStack::PushL( dir );
|
|
422 |
|
|
423 |
for ( TInt i=0; i < dir->Count(); ++i )
|
|
424 |
{
|
|
425 |
TEntry entry = (*dir)[i];
|
|
426 |
if ( !entry.IsDir() )
|
|
427 |
{
|
|
428 |
User::LeaveIfError( aList.Append( entry.iName ) );
|
|
429 |
}
|
|
430 |
}
|
|
431 |
CleanupStack::PopAndDestroy( dir );
|
|
432 |
TRACE_FUNC_EXIT;
|
|
433 |
}
|
|
434 |
|
|
435 |
// -----------------------------------------------------------------------------
|
|
436 |
// CapUtil::CheckFileType(const TDesC& aFile, const TDesC& aExt)
|
|
437 |
// Function checks file extension.
|
|
438 |
// -----------------------------------------------------------------------------
|
|
439 |
//
|
|
440 |
TBool CapUtil::CheckFileType(const TDesC& aFile, const TDesC& aExt)
|
|
441 |
{
|
|
442 |
TRACE_FUNC_ENTRY;
|
|
443 |
TParse parse;
|
|
444 |
parse.Set(aFile, NULL, NULL);
|
|
445 |
TPtrC ptr=parse.Ext();
|
|
446 |
|
|
447 |
TBuf<KTagSize> buf1;
|
|
448 |
TBuf<KTagSize> buf2;
|
|
449 |
|
|
450 |
buf1=ptr;
|
|
451 |
buf2=aExt;
|
|
452 |
|
|
453 |
buf1.LowerCase();
|
|
454 |
buf2.LowerCase();
|
|
455 |
|
|
456 |
if (buf1.Compare(buf2)==0)
|
|
457 |
{
|
|
458 |
LOGGER_WRITE( "CapUtil::CheckFileType(const TDesC& aFile, const TDesC& aExt) : returned ETrue" );
|
|
459 |
return ETrue;
|
|
460 |
}
|
|
461 |
|
|
462 |
else
|
|
463 |
{
|
|
464 |
LOGGER_WRITE( "CapUtil::CheckFileType(const TDesC& aFile, const TDesC& aExt) : returned EFalse" );
|
|
465 |
return EFalse;
|
|
466 |
}
|
|
467 |
}
|
|
468 |
|
|
469 |
// -----------------------------------------------------------------------------
|
|
470 |
// CapUtil::GetLanguageString(TLanguage aId, TDes& aText)
|
|
471 |
// Get language string for aId.
|
|
472 |
// -----------------------------------------------------------------------------
|
|
473 |
//
|
|
474 |
void CapUtil::GetLanguageString(TLanguage aId, TDes& aText)
|
|
475 |
{
|
|
476 |
TRACE_FUNC_ENTRY;
|
|
477 |
aText=KNullDesC;
|
|
478 |
|
|
479 |
TInt count=NUMLANGSTRINGS;
|
|
480 |
for (TInt i=0; i<count; i++)
|
|
481 |
{
|
|
482 |
TLangStringStruct t=KLangStrings[i];
|
|
483 |
if (t.id == (TInt)aId)
|
|
484 |
{
|
|
485 |
aText=t.lang;
|
|
486 |
return;
|
|
487 |
}
|
|
488 |
}
|
|
489 |
TRACE_FUNC_EXIT;
|
|
490 |
}
|
|
491 |
|
|
492 |
// -----------------------------------------------------------------------------
|
|
493 |
// CapUtil::Panic(TInt aReason)
|
|
494 |
// Panic.
|
|
495 |
// -----------------------------------------------------------------------------
|
|
496 |
//
|
|
497 |
#ifdef _DEBUG
|
|
498 |
void CapUtil::Panic(TInt aReason)
|
|
499 |
#else
|
|
500 |
void CapUtil::Panic(TInt /*aReason*/)
|
|
501 |
#endif
|
|
502 |
{
|
|
503 |
TRACE_FUNC_ENTRY;
|
|
504 |
#ifdef _DEBUG
|
|
505 |
_LIT(KPanicCategory,"CapabilitySC");
|
|
506 |
|
|
507 |
User::Panic(KPanicCategory, aReason);
|
|
508 |
#endif
|
|
509 |
TRACE_FUNC_EXIT;
|
|
510 |
}
|
|
511 |
|
|
512 |
// -----------------------------------------------------------------------------
|
|
513 |
// CapUtil::StrCopy(TDes& aTarget, const TDesC& aSource)
|
|
514 |
// String copy with lenght check.
|
|
515 |
// -----------------------------------------------------------------------------
|
|
516 |
//
|
|
517 |
void CapUtil::StrCopy(TDes& aTarget, const TDesC& aSource)
|
|
518 |
{
|
|
519 |
TInt len=aTarget.MaxLength();
|
|
520 |
if(len<aSource.Length())
|
|
521 |
{
|
|
522 |
aTarget.Copy(aSource.Left(len));
|
|
523 |
return;
|
|
524 |
}
|
|
525 |
aTarget.Copy(aSource);
|
|
526 |
}
|
|
527 |
|
|
528 |
// -----------------------------------------------------------------------------
|
|
529 |
// CapUtil::IntToStr(TDes& aText, TInt64 aNum)
|
|
530 |
// Function converts ínteger to string.
|
|
531 |
// -----------------------------------------------------------------------------
|
|
532 |
//
|
|
533 |
void CapUtil::IntToStr(TDes& aText, TInt64 aNum)
|
|
534 |
{
|
|
535 |
aText.Num(aNum);
|
|
536 |
}
|
|
537 |
|
|
538 |
// -----------------------------------------------------------------------------
|
|
539 |
// CapUtil::StrToInt(const TDesC& aText, TInt& aNum)
|
|
540 |
// Function converts string to integer. If string cannot be converted,
|
|
541 |
// error code is returned.
|
|
542 |
// -----------------------------------------------------------------------------
|
|
543 |
//
|
|
544 |
TInt CapUtil::StrToInt(const TDesC& aText, TInt& aNum)
|
|
545 |
{
|
|
546 |
TLex lex(aText);
|
|
547 |
|
|
548 |
TInt err=lex.Val(aNum);
|
|
549 |
return err;
|
|
550 |
}
|
|
551 |
|
|
552 |
// -----------------------------------------------------------------------------
|
|
553 |
// CapUtil::SplitL(const TDesC& aText, const TChar aSeparator,
|
|
554 |
// RArray<TPtrC>& aArray)
|
|
555 |
// Function splits string (eg "name1, name2, name3") into substrings.
|
|
556 |
// -----------------------------------------------------------------------------
|
|
557 |
//
|
|
558 |
void CapUtil::SplitL(const TDesC& aText, const TChar aSeparator,
|
|
559 |
RArray<TPtrC>& aArray)
|
|
560 |
{
|
|
561 |
TRACE_FUNC_ENTRY;
|
|
562 |
TPtrC ptr;
|
|
563 |
ptr.Set(aText);
|
|
564 |
|
|
565 |
for (;;)
|
|
566 |
{
|
|
567 |
TInt pos=ptr.Locate(aSeparator);
|
|
568 |
if (pos==KErrNotFound)
|
|
569 |
{
|
|
570 |
aArray.AppendL(ptr);
|
|
571 |
break;
|
|
572 |
}
|
|
573 |
|
|
574 |
TPtrC subStr=ptr.Left(pos); // get pos characters starting from position 0
|
|
575 |
aArray.AppendL(subStr);
|
|
576 |
|
|
577 |
if (!(ptr.Length()>pos+1))
|
|
578 |
{
|
|
579 |
break;
|
|
580 |
}
|
|
581 |
|
|
582 |
ptr.Set(ptr.Mid(pos+1));// get all characters starting from position pos+1
|
|
583 |
}
|
|
584 |
TRACE_FUNC_EXIT;
|
|
585 |
}
|
|
586 |
|
|
587 |
// -----------------------------------------------------------------------------
|
|
588 |
// CapUtil::ParseDateL(const TDesC& aText)
|
|
589 |
// Function parses date string of the format "dd-mm-yy".
|
|
590 |
// -----------------------------------------------------------------------------
|
|
591 |
//
|
|
592 |
TTime CapUtil::ParseDateL(const TDesC& aText)
|
|
593 |
{
|
|
594 |
TRACE_FUNC_ENTRY;
|
|
595 |
RArray<TPtrC> arr(KDefaultArrayGranularity);
|
|
596 |
CleanupClosePushL( arr );
|
|
597 |
|
|
598 |
CapUtil::SplitL( aText, '-', arr );
|
|
599 |
if ( arr.Count() != 3 )
|
|
600 |
{
|
|
601 |
User::Leave( KErrNotSupported );
|
|
602 |
}
|
|
603 |
|
|
604 |
TInt day;
|
|
605 |
TInt month;
|
|
606 |
TInt year;
|
|
607 |
|
|
608 |
User::LeaveIfError( StrToInt(arr[0], day) );
|
|
609 |
User::LeaveIfError( StrToInt(arr[1], month) );
|
|
610 |
User::LeaveIfError( StrToInt(arr[2], year) );
|
|
611 |
|
|
612 |
TDateTime td;
|
|
613 |
TMonth month2 = Month( month );
|
|
614 |
// if year is defined as two digit, add currect millenium for it
|
|
615 |
const TInt KDefaultMillenium = 2000;
|
|
616 |
if ( year < KDefaultMillenium )
|
|
617 |
{
|
|
618 |
year = year + KDefaultMillenium;
|
|
619 |
}
|
|
620 |
|
|
621 |
|
|
622 |
User::LeaveIfError( td.Set(year, month2, day-1, 0, 0, 0, 0) );
|
|
623 |
|
|
624 |
CleanupStack::PopAndDestroy( &arr );
|
|
625 |
|
|
626 |
TTime t(td);
|
|
627 |
TRACE_FUNC_EXIT;
|
|
628 |
return t;
|
|
629 |
}
|
|
630 |
|
|
631 |
// -----------------------------------------------------------------------------
|
|
632 |
// CapUtil::Month(TInt aNum)
|
|
633 |
// Function return TMonth presentation of integer
|
|
634 |
// -----------------------------------------------------------------------------
|
|
635 |
//
|
|
636 |
TMonth CapUtil::Month(TInt aNum)
|
|
637 |
{
|
|
638 |
TRACE_FUNC_ENTRY;
|
|
639 |
__ASSERT_DEBUG(aNum>=1 && aNum<=12, Panic(KErrArgument));
|
|
640 |
|
|
641 |
switch (aNum)
|
|
642 |
{
|
|
643 |
case 1: return EJanuary;
|
|
644 |
case 2: return EFebruary;
|
|
645 |
case 3: return EMarch;
|
|
646 |
case 4: return EApril;
|
|
647 |
case 5: return EMay;
|
|
648 |
case 6: return EJune;
|
|
649 |
case 7: return EJuly;
|
|
650 |
case 8: return EAugust;
|
|
651 |
case 9: return ESeptember;
|
|
652 |
case 10: return EOctober;
|
|
653 |
case 11: return ENovember;
|
|
654 |
case 12: return EDecember;
|
|
655 |
default: return EJanuary;
|
|
656 |
}
|
|
657 |
}
|
|
658 |
|
|
659 |
// -----------------------------------------------------------------------------
|
|
660 |
// CapUtil::CapabilityDate(TDes& aText, const TTime aTime)
|
|
661 |
// Constructs capability date as string
|
|
662 |
// -----------------------------------------------------------------------------
|
|
663 |
//
|
|
664 |
void CapUtil::CapabilityDate(TDes& aText, const TTime aTime)
|
|
665 |
{
|
|
666 |
TRACE_FUNC_ENTRY;
|
|
667 |
_LIT(KFormat,"%04d%02d%02dT%02d%02d%02dZ");
|
|
668 |
|
|
669 |
TDateTime dt=aTime.DateTime();
|
|
670 |
aText.Format(KFormat, dt.Year(), dt.Month()+1, dt.Day()+1, dt.Hour(),
|
|
671 |
dt.Minute(), dt.Second());
|
|
672 |
TRACE_FUNC_EXIT;
|
|
673 |
}
|
|
674 |
|
|
675 |
// -----------------------------------------------------------------------------
|
|
676 |
// TIdStack::Pop()
|
|
677 |
// Pop id from the stack
|
|
678 |
// -----------------------------------------------------------------------------
|
|
679 |
//
|
|
680 |
TInt TIdStack::Pop()
|
|
681 |
{
|
|
682 |
if (iPos<0)
|
|
683 |
{
|
|
684 |
LOGGER_WRITE( "TIdStack::Pop() returned KErrNotFound" );
|
|
685 |
return KErrNotFound;
|
|
686 |
}
|
|
687 |
|
|
688 |
TInt id=iArray[iPos];
|
|
689 |
iPos--;
|
|
690 |
return id;
|
|
691 |
}
|
|
692 |
|
|
693 |
// -----------------------------------------------------------------------------
|
|
694 |
// TIdStack::Push( TInt aId )
|
|
695 |
// Push id to the stack
|
|
696 |
// -----------------------------------------------------------------------------
|
|
697 |
//
|
|
698 |
void TIdStack::Push( TInt aId )
|
|
699 |
{
|
|
700 |
if ( Size() >= KNestingLimit )
|
|
701 |
{
|
|
702 |
return;
|
|
703 |
}
|
|
704 |
|
|
705 |
iPos++;
|
|
706 |
iArray[iPos] = aId;
|
|
707 |
}
|
|
708 |
|
|
709 |
// -----------------------------------------------------------------------------
|
|
710 |
// TIdStack::Size() const
|
|
711 |
// Size of the stack
|
|
712 |
// -----------------------------------------------------------------------------
|
|
713 |
//
|
|
714 |
TInt TIdStack::Size() const
|
|
715 |
{
|
|
716 |
return iPos+1;
|
|
717 |
}
|
|
718 |
|
|
719 |
// -----------------------------------------------------------------------------
|
|
720 |
// TIdStack::Reset()
|
|
721 |
// Reset the stack.
|
|
722 |
// -----------------------------------------------------------------------------
|
|
723 |
//
|
|
724 |
void TIdStack::Reset()
|
|
725 |
{
|
|
726 |
iArray.Reset();
|
|
727 |
iPos=-1;
|
|
728 |
}
|
|
729 |
|
|
730 |
// End of file
|