connectivitymodules/SeCon/services/csc/src/caputils.cpp
changeset 17 aabe5387f5ce
parent 0 d0791faffa3f
child 18 1b39655331a3
equal deleted inserted replaced
0:d0791faffa3f 17:aabe5387f5ce
     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     StrCopy( aLongName, mobilePhoneNetworkInfo.iLongName );
       
   207     StrCopy( aCountryCode, mobilePhoneNetworkInfo.iCountryCode );
       
   208     StrCopy( aNetworkID, mobilePhoneNetworkInfo.iNetworkId );
       
   209     
       
   210     TRACE_FUNC_EXIT;
       
   211     }
       
   212 // -----------------------------------------------------------------------------
       
   213 // CapUtil::GetManufacturer(TDes& aText)
       
   214 // Gets phone manufacturer from HAL. In case manufacturer is not known,
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CapUtil::GetManufacturer(TDes& aText)
       
   218     {
       
   219     TRACE_FUNC_ENTRY;
       
   220     TInt num(KErrNotFound);
       
   221     
       
   222     HAL::Get(HALData::EManufacturer, num);
       
   223     
       
   224     switch (num)
       
   225         {
       
   226         case HALData::EManufacturer_Ericsson:
       
   227             aText=KManufacturerEricsson; 
       
   228             break;
       
   229         case HALData::EManufacturer_Motorola:
       
   230             aText=KManufacturerMotorola; 
       
   231             break;
       
   232         case HALData::EManufacturer_Nokia:
       
   233             aText=KManufacturerNokia; 
       
   234             break;
       
   235         case HALData::EManufacturer_Panasonic:
       
   236             aText=KManufacturerPanasonic; 
       
   237             break;
       
   238         case HALData::EManufacturer_Psion:
       
   239             aText=KManufacturerPsion; 
       
   240             break;
       
   241         case HALData::EManufacturer_Intel:
       
   242             aText=KManufacturerIntel; 
       
   243             break;
       
   244         case HALData::EManufacturer_Cogent:
       
   245             aText=KManufacturerCogent; 
       
   246             break;
       
   247         case HALData::EManufacturer_Cirrus:
       
   248             aText=KManufacturerCirrus; 
       
   249             break;
       
   250         case HALData::EManufacturer_Linkup:
       
   251             aText=KManufacturerLinkup; 
       
   252             break;
       
   253         case HALData::EManufacturer_TexasInstruments:
       
   254             aText=KManufacturerTexasInstruments; 
       
   255             break;
       
   256         default: 
       
   257             aText=KNullDesC; 
       
   258             break;
       
   259         }
       
   260 
       
   261     TRACE_FUNC_EXIT;
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CapUtil::GetLanguage(TDes& aText)
       
   266 // Gets language
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 void CapUtil::GetLanguage(TDes& aText)
       
   270     {
       
   271     TRACE_FUNC_ENTRY;
       
   272     TLanguage lang=User::Language();
       
   273     GetLanguageString(lang, aText);
       
   274     TRACE_FUNC_EXIT;
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CapUtil::GetSWVersionL(TDes& aVersion, TDes& aDate, TDes& aModel)
       
   279 // Gets SW version, SW version date  and device model from SysUtil. 
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CapUtil::GetSWVersionL(TDes& aVersion, TDes& aDate, TDes& aModel)
       
   283     {
       
   284     TRACE_FUNC_ENTRY;
       
   285     TBuf<KBufSize> buf;
       
   286     aVersion=KNullDesC;
       
   287     aDate=KNullDesC;
       
   288     aModel=KNullDesC;
       
   289 
       
   290     User::LeaveIfError( SysUtil::GetSWVersion( buf ) );
       
   291     RArray<TPtrC> arr(KDefaultArrayGranularity);
       
   292     CleanupClosePushL( arr );
       
   293 
       
   294     CapUtil::SplitL(buf, '\n', arr);
       
   295     const TInt KFieldsToFind = 3;
       
   296     if ( arr.Count() < KFieldsToFind )
       
   297         {
       
   298         User::Leave( KErrNotFound );
       
   299         }
       
   300     
       
   301     StrCopy( aVersion, arr[0] );
       
   302     aVersion.Trim();
       
   303 
       
   304     StrCopy(aModel,arr[2]);
       
   305     aModel.Trim();
       
   306 
       
   307     TBuf<KTagSize> date;
       
   308     StrCopy(date, arr[1]);
       
   309     TTime t;
       
   310     t.UniversalTime(); // this is to avoid warnings
       
   311     TRAPD( err, t = ParseDateL( date ) );
       
   312     if ( err == KErrNone )
       
   313         {
       
   314         CapabilityDate( aDate, t );
       
   315         }
       
   316     
       
   317     CleanupStack::PopAndDestroy( &arr );
       
   318     
       
   319     TRACE_FUNC_EXIT;
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CapUtil::InitMemoryInfo(TMemoryInfo& aInfo)
       
   324 // Initializes TMemoryInfo.
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 void CapUtil::InitMemoryInfo(TMemoryInfo& aInfo)
       
   328     {
       
   329     aInfo.iDriveNum        = KErrNotFound;
       
   330     aInfo.iDriveLetter     = KNoChar;
       
   331     aInfo.iLocation        = KNullDesC;
       
   332     aInfo.iFree            = KErrNotFound;
       
   333     aInfo.iUsed            = KErrNotFound;
       
   334     aInfo.iShared          = EFalse;
       
   335     aInfo.iFileSize        = KErrNotFound;
       
   336     aInfo.iFolderSize      = KErrNotFound;
       
   337     aInfo.iFileNameSize    = KMaxFileName;    // TFileName 256
       
   338     aInfo.iFolderNameSize  = KMaxFileName;    // TFileName 256
       
   339     aInfo.iCaseSensitivity = EFalse;
       
   340     }
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // CapUtil::GetMemoryInfoL( const RFs& aFs, TInt aDriveNumber, TMemoryInfo& aInfo )
       
   344 // Get memory information for one drive.
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 void CapUtil::GetMemoryInfoL( const RFs& aFs, const TInt aDriveNumber, TMemoryInfo& aInfo )
       
   348     {
       
   349     TRACE_FUNC_ENTRY;
       
   350     LOGGER_WRITE_1("  aDriveNumber: %d", aDriveNumber);
       
   351     
       
   352     TVolumeInfo volumeInfo;
       
   353     TDriveInfo driveInfo;
       
   354 
       
   355     InitMemoryInfo( aInfo );
       
   356 
       
   357     User::LeaveIfError( aFs.Drive(driveInfo, aDriveNumber) ); 
       
   358     if ( driveInfo.iDriveAtt == (TUint)KDriveAbsent ) 
       
   359         {
       
   360         LOGGER_WRITE(" iDriveAtt == (TUint)KDriveAbsent, Leave KErrNotFound");
       
   361         User::Leave( KErrNotFound );
       
   362         }
       
   363                 
       
   364     User::LeaveIfError( aFs.Volume(volumeInfo, aDriveNumber) );
       
   365 
       
   366     User::LeaveIfError( aFs.DriveToChar(aDriveNumber, aInfo.iDriveLetter) );
       
   367     aInfo.iDriveNum = aDriveNumber;
       
   368     aInfo.iLocation.Append( aInfo.iDriveLetter );
       
   369     aInfo.iLocation.Append( KDriveDelimiter );
       
   370     aInfo.iLocation.Append( KPathDelimiter );
       
   371     aInfo.iFree = volumeInfo.iFree;
       
   372     aInfo.iUsed = volumeInfo.iSize - volumeInfo.iFree;
       
   373     
       
   374     // set free memory up to critical level for all drives
       
   375     CRepository* repository = CRepository::NewLC( KCRUidDiskLevel );
       
   376     TInt criticalLevel(0);
       
   377     User::LeaveIfError( repository->Get( KDiskCriticalThreshold, criticalLevel ) );
       
   378     CleanupStack::PopAndDestroy( repository );
       
   379     criticalLevel += KPackageSize; // add obex package size to critical level
       
   380     LOGGER_WRITE_1( "CapUtil::GetMemoryInfoL() criticalLevel: %d", criticalLevel ) ;
       
   381     if ( aInfo.iFree > criticalLevel )
       
   382         {
       
   383         aInfo.iFree = aInfo.iFree - criticalLevel;
       
   384         }       
       
   385     else
       
   386         {
       
   387         aInfo.iFree = 0;
       
   388         }
       
   389     
       
   390     aInfo.iFileSize = aInfo.iFree;
       
   391     aInfo.iFolderSize = aInfo.iFree;
       
   392     TRACE_FUNC_EXIT;
       
   393     }
       
   394 
       
   395 // -----------------------------------------------------------------------------
       
   396 // CapUtil::GetFileListL( RFs& aFs, const TDesC& aDir, 
       
   397 // RArray<TFileName>& aList)
       
   398 // Finds all files in aDir.
       
   399 // -----------------------------------------------------------------------------
       
   400 //
       
   401 void CapUtil::GetFileListL( const RFs& aFs, const TDesC& aDir, 
       
   402                             RArray<TFileName>& aList)
       
   403     {
       
   404     TRACE_FUNC_ENTRY;
       
   405     
       
   406     aList.Reset();
       
   407     
       
   408     CDir* dir( NULL );
       
   409     User::LeaveIfError( aFs.GetDir( aDir, KEntryAttMatchMask, ESortByName, dir ) );
       
   410     CleanupStack::PushL( dir );
       
   411     
       
   412     for ( TInt i=0; i < dir->Count(); ++i )
       
   413         {
       
   414         TEntry entry = (*dir)[i];
       
   415         if ( !entry.IsDir() )
       
   416             {
       
   417             User::LeaveIfError( aList.Append( entry.iName ) );
       
   418             }
       
   419         }
       
   420     CleanupStack::PopAndDestroy( dir );
       
   421     TRACE_FUNC_EXIT;
       
   422     }
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // CapUtil::CheckFileType(const TDesC& aFile, const TDesC& aExt)
       
   426 // Function checks file extension.
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 TBool CapUtil::CheckFileType(const TDesC& aFile, const TDesC& aExt)
       
   430     {
       
   431     TRACE_FUNC_ENTRY;
       
   432     TParse parse;
       
   433     parse.Set(aFile, NULL, NULL);
       
   434     TPtrC ptr=parse.Ext();
       
   435 
       
   436     TBuf<KTagSize> buf1;
       
   437     TBuf<KTagSize> buf2;
       
   438     
       
   439     buf1=ptr;
       
   440     buf2=aExt;
       
   441     
       
   442     buf1.LowerCase();
       
   443     buf2.LowerCase();
       
   444 
       
   445     if (buf1.Compare(buf2)==0)
       
   446         {
       
   447         LOGGER_WRITE( "CapUtil::CheckFileType(const TDesC& aFile, const TDesC& aExt) : returned ETrue" );
       
   448         return ETrue;
       
   449         }
       
   450         
       
   451     else
       
   452         {
       
   453         LOGGER_WRITE( "CapUtil::CheckFileType(const TDesC& aFile, const TDesC& aExt) : returned EFalse" );
       
   454         return EFalse;
       
   455         }
       
   456     }
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // CapUtil::GetLanguageString(TLanguage aId, TDes& aText)
       
   460 // Get language string for aId.
       
   461 // -----------------------------------------------------------------------------
       
   462 //
       
   463 void CapUtil::GetLanguageString(TLanguage aId, TDes& aText)
       
   464     {
       
   465     TRACE_FUNC_ENTRY;
       
   466     aText=KNullDesC;
       
   467     
       
   468     TInt count=NUMLANGSTRINGS;
       
   469     for (TInt i=0; i<count; i++)
       
   470         {
       
   471         TLangStringStruct t=KLangStrings[i];
       
   472         if (t.id == (TInt)aId)
       
   473             {
       
   474             aText=t.lang;
       
   475             return;
       
   476             }
       
   477         }
       
   478     TRACE_FUNC_EXIT;
       
   479     }
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CapUtil::Panic(TInt aReason)
       
   483 // Panic.
       
   484 // -----------------------------------------------------------------------------
       
   485 //
       
   486 #ifdef _DEBUG
       
   487 void CapUtil::Panic(TInt aReason)
       
   488 #else
       
   489 void CapUtil::Panic(TInt /*aReason*/)
       
   490 #endif
       
   491     {
       
   492     TRACE_FUNC_ENTRY;
       
   493 #ifdef _DEBUG
       
   494     _LIT(KPanicCategory,"CapabilitySC");
       
   495 
       
   496     User::Panic(KPanicCategory, aReason);
       
   497 #endif
       
   498     TRACE_FUNC_EXIT;
       
   499     }
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 // CapUtil::StrCopy(TDes& aTarget, const TDesC& aSource)
       
   503 // String copy with lenght check.
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 void CapUtil::StrCopy(TDes& aTarget, const TDesC& aSource)
       
   507     {
       
   508     TInt len=aTarget.MaxLength();
       
   509     if(len<aSource.Length()) 
       
   510         {
       
   511         aTarget.Copy(aSource.Left(len));
       
   512         return;
       
   513         }
       
   514     aTarget.Copy(aSource);
       
   515     }
       
   516 
       
   517 // -----------------------------------------------------------------------------
       
   518 // CapUtil::IntToStr(TDes& aText, TInt64 aNum)
       
   519 // Function converts ínteger to string.
       
   520 // -----------------------------------------------------------------------------
       
   521 //
       
   522 void CapUtil::IntToStr(TDes& aText, TInt64 aNum)
       
   523     {
       
   524     aText.Num(aNum);
       
   525     }
       
   526 
       
   527 // -----------------------------------------------------------------------------
       
   528 // CapUtil::StrToInt(const TDesC& aText, TInt& aNum)
       
   529 // Function converts string to integer. If string cannot be converted,
       
   530 // error code is returned.
       
   531 // -----------------------------------------------------------------------------
       
   532 //
       
   533 TInt CapUtil::StrToInt(const TDesC& aText, TInt& aNum)
       
   534     {
       
   535     TLex lex(aText);
       
   536 
       
   537     TInt err=lex.Val(aNum); 
       
   538     return err;
       
   539     }
       
   540 
       
   541 // -----------------------------------------------------------------------------
       
   542 // CapUtil::SplitL(const TDesC& aText, const TChar aSeparator, 
       
   543 // RArray<TPtrC>& aArray)
       
   544 // Function splits string (eg "name1, name2, name3") into substrings.
       
   545 // -----------------------------------------------------------------------------
       
   546 //
       
   547 void CapUtil::SplitL(const TDesC& aText, const TChar aSeparator, 
       
   548                     RArray<TPtrC>& aArray)
       
   549     {
       
   550     TRACE_FUNC_ENTRY;
       
   551     TPtrC ptr;
       
   552     ptr.Set(aText);
       
   553 
       
   554     for (;;)
       
   555         {
       
   556         TInt pos=ptr.Locate(aSeparator);
       
   557         if (pos==KErrNotFound)
       
   558             {
       
   559             aArray.AppendL(ptr);
       
   560             break;
       
   561             }
       
   562 
       
   563         TPtrC subStr=ptr.Left(pos); // get pos characters starting from position 0
       
   564         aArray.AppendL(subStr);
       
   565 
       
   566         if (!(ptr.Length()>pos+1))
       
   567             {
       
   568             break;
       
   569             }
       
   570             
       
   571         ptr.Set(ptr.Mid(pos+1));// get all characters starting from position pos+1
       
   572         }
       
   573     TRACE_FUNC_EXIT;
       
   574     }
       
   575 
       
   576 // -----------------------------------------------------------------------------
       
   577 // CapUtil::ParseDateL(const TDesC& aText)
       
   578 // Function parses date string of the format "dd-mm-yy".
       
   579 // -----------------------------------------------------------------------------
       
   580 //
       
   581 TTime CapUtil::ParseDateL(const TDesC& aText)
       
   582     {
       
   583     TRACE_FUNC_ENTRY;
       
   584     RArray<TPtrC> arr(KDefaultArrayGranularity);
       
   585     CleanupClosePushL( arr );
       
   586 
       
   587     CapUtil::SplitL( aText, '-', arr );
       
   588     if ( arr.Count() != 3 )
       
   589         {
       
   590         User::Leave( KErrNotSupported );
       
   591         }
       
   592            
       
   593     TInt day; 
       
   594     TInt month; 
       
   595     TInt year;
       
   596     
       
   597     User::LeaveIfError( StrToInt(arr[0], day) );
       
   598     User::LeaveIfError( StrToInt(arr[1], month) );
       
   599     User::LeaveIfError( StrToInt(arr[2], year) );
       
   600 
       
   601     TDateTime td;
       
   602     TMonth month2 = Month( month );
       
   603     // if year is defined as two digit, add currect millenium for it
       
   604     const TInt KDefaultMillenium = 2000;
       
   605     if ( year < KDefaultMillenium )
       
   606         {
       
   607         year = year + KDefaultMillenium;
       
   608         }
       
   609         
       
   610 
       
   611     User::LeaveIfError( td.Set(year, month2, day-1, 0, 0, 0, 0) );
       
   612 
       
   613     CleanupStack::PopAndDestroy( &arr );
       
   614     
       
   615     TTime t(td);
       
   616     TRACE_FUNC_EXIT;
       
   617     return t;
       
   618 }
       
   619 
       
   620 // -----------------------------------------------------------------------------
       
   621 // CapUtil::Month(TInt aNum)
       
   622 // Function return TMonth presentation of integer
       
   623 // -----------------------------------------------------------------------------
       
   624 //
       
   625 TMonth CapUtil::Month(TInt aNum)
       
   626     {
       
   627     TRACE_FUNC_ENTRY;
       
   628     __ASSERT_DEBUG(aNum>=1 && aNum<=12, Panic(KErrArgument));
       
   629 
       
   630     switch (aNum)
       
   631         {
       
   632         case 1: return EJanuary;
       
   633         case 2: return EFebruary;
       
   634         case 3: return EMarch;
       
   635         case 4: return EApril;
       
   636         case 5: return EMay;
       
   637         case 6: return EJune;
       
   638         case 7: return EJuly;
       
   639         case 8: return EAugust;
       
   640         case 9: return ESeptember;
       
   641         case 10: return EOctober;
       
   642         case 11: return ENovember;
       
   643         case 12: return EDecember;
       
   644         default: return EJanuary;
       
   645         }
       
   646     }
       
   647 
       
   648 // -----------------------------------------------------------------------------
       
   649 // CapUtil::CapabilityDate(TDes& aText, const TTime aTime)
       
   650 // Constructs capability date as string
       
   651 // -----------------------------------------------------------------------------
       
   652 //
       
   653 void CapUtil::CapabilityDate(TDes& aText, const TTime aTime)
       
   654     {
       
   655     TRACE_FUNC_ENTRY;
       
   656     _LIT(KFormat,"%04d%02d%02dT%02d%02d%02dZ");
       
   657 
       
   658     TDateTime dt=aTime.DateTime();
       
   659     aText.Format(KFormat, dt.Year(), dt.Month()+1, dt.Day()+1, dt.Hour(),
       
   660      dt.Minute(), dt.Second());
       
   661     TRACE_FUNC_EXIT;
       
   662     }
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // TIdStack::Pop()
       
   666 // Pop id from the stack
       
   667 // -----------------------------------------------------------------------------
       
   668 //
       
   669 TInt TIdStack::Pop()
       
   670     {
       
   671     if (iPos<0)
       
   672         {
       
   673         LOGGER_WRITE( "TIdStack::Pop() returned KErrNotFound" );
       
   674         return KErrNotFound;
       
   675         }
       
   676         
       
   677     TInt id=iArray[iPos];
       
   678     iPos--;
       
   679     return id;
       
   680     }
       
   681 
       
   682 // -----------------------------------------------------------------------------
       
   683 // TIdStack::Push( TInt aId )
       
   684 // Push id to the stack
       
   685 // -----------------------------------------------------------------------------
       
   686 //
       
   687 void TIdStack::Push( TInt aId )
       
   688     {
       
   689     if ( Size() >= KNestingLimit )
       
   690         {
       
   691         return;
       
   692         }
       
   693         
       
   694     iPos++;
       
   695     iArray[iPos] = aId;
       
   696     }
       
   697 
       
   698 // -----------------------------------------------------------------------------
       
   699 // TIdStack::Size() const
       
   700 // Size of the stack
       
   701 // -----------------------------------------------------------------------------
       
   702 //
       
   703 TInt TIdStack::Size() const
       
   704     {
       
   705     return iPos+1;
       
   706     }
       
   707 
       
   708 // -----------------------------------------------------------------------------
       
   709 // TIdStack::Reset()
       
   710 // Reset the stack.
       
   711 // -----------------------------------------------------------------------------
       
   712 //
       
   713 void TIdStack::Reset()
       
   714     {
       
   715     iArray.Reset();
       
   716     iPos=-1;
       
   717     }
       
   718 
       
   719 // End of file