connectivitymodules/SeCon/services/csc/src/capinfo.cpp
branchRCL_3
changeset 43 4a793f564d72
parent 0 d0791faffa3f
equal deleted inserted replaced
42:0aa8cc770c8a 43:4a793f564d72
       
     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:  CCapInfo implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <utf.h>
       
    22 #include <driveinfo.h>
       
    23 #include <pathinfo.h>    // for PathInfo::SoundsPath
       
    24 #include <seconsdkcrkeys.h>
       
    25 #include "sconsyncservice.h"
       
    26 #include "capinfo.h"
       
    27 #include "caplist.h"
       
    28 #include "capparser.h"
       
    29 #include "caputils.h"
       
    30 #include "stringlist.h"
       
    31 #include "sconversioninfo.h"
       
    32 #include "debug.h"
       
    33 
       
    34 
       
    35 _LIT8( KLineFeed, "\r\n" );
       
    36 
       
    37 const TInt KDefaultArrayGranularity = 5;
       
    38 
       
    39 
       
    40 // ============================= MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CCapInfo::NewL()
       
    44 // Two-phase constructor
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CCapInfo* CCapInfo::NewL()
       
    48     {
       
    49     TRACE_FUNC_ENTRY;
       
    50     CCapInfo* self = new (ELeave) CCapInfo();
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop(self);
       
    54     TRACE_FUNC_EXIT;
       
    55     return self;
       
    56     }
       
    57     
       
    58 // -----------------------------------------------------------------------------
       
    59 // CCapInfo::~CCapInfo()
       
    60 // Destructor
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CCapInfo::~CCapInfo()
       
    64     {
       
    65     TRACE_FUNC_ENTRY;
       
    66     iFsSession.Close();
       
    67     delete iHeapBuf;
       
    68     delete iCapList;
       
    69     delete iSconInfo;
       
    70     TRACE_FUNC_EXIT;
       
    71     }
       
    72     
       
    73 // -----------------------------------------------------------------------------
       
    74 // CCapInfo::CapabilityDocumentL(CBufFlat* aBuf)
       
    75 // Creates capability xml document end places it in aBuf
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CCapInfo::CapabilityDocumentL(CBufFlat* aBuf)
       
    79     {
       
    80     TRACE_FUNC_ENTRY;
       
    81     TInt err( KErrNone );
       
    82     
       
    83     // set buffer where capability document is written
       
    84     SetCapabilityBuf( aBuf );
       
    85     
       
    86     WriteL( KXmlVersion );
       
    87     WriteL( KComment1 );
       
    88     WriteL( KDocType );
       
    89     WriteL( KRootBegin );
       
    90     
       
    91     
       
    92     //
       
    93     // general
       
    94     //
       
    95     TRAP( err, GeneralInfoL() );
       
    96     if ( err != KErrNone )
       
    97         {
       
    98         LOGGER_WRITE_1( "GeneralInfoL failed : %d", err );
       
    99         User::Leave( err ); 
       
   100         }
       
   101     
       
   102     
       
   103     //
       
   104     // services
       
   105     //
       
   106     // Search service files first from C-drive, and then from Z
       
   107     // Do not add same files twice.
       
   108     
       
   109     RArray<TFileName> excludeList( KDefaultArrayGranularity );
       
   110     CleanupClosePushL( excludeList );
       
   111     RArray<TFileName> filesAdded( KDefaultArrayGranularity );
       
   112     CleanupClosePushL( filesAdded );
       
   113     
       
   114     //read service files from C Import folder
       
   115     TRAP( err, ServiceInfoL( KCapabilityDirCImport, excludeList, filesAdded ) );     
       
   116     LOGGER_WRITE_1( "ServiceInfoL(KCapabilityDirCImport) returned : %d", err );
       
   117     for ( TInt i=0; i<filesAdded.Count(); i++ )
       
   118         {
       
   119         excludeList.Append( filesAdded[i] );
       
   120         }
       
   121     filesAdded.Reset();
       
   122     
       
   123     // read service files from C Capability folder
       
   124     TRAP( err, ServiceInfoL( KCapabilityDirC, excludeList, filesAdded ) ); 
       
   125     LOGGER_WRITE_1( "ServiceInfoL(KCapabilityDirC) returned : %d", err );
       
   126     for ( TInt i=0; i<filesAdded.Count(); i++ )
       
   127         {
       
   128         excludeList.Append( filesAdded[i] );
       
   129         }
       
   130     filesAdded.Reset();
       
   131     
       
   132     // read service files from Z Capability folder
       
   133     TRAP( err, ServiceInfoL( KCapabilityDirZ, excludeList, filesAdded ) );
       
   134     LOGGER_WRITE_1( "ServiceInfoL(KCapabilityDirZ) returned : %d", err );
       
   135     
       
   136     CleanupStack::PopAndDestroy( &filesAdded );
       
   137     CleanupStack::PopAndDestroy( &excludeList );
       
   138     
       
   139         
       
   140     // this service does not come from file
       
   141     TRAP( err, FolderServiceL() );
       
   142     LOGGER_WRITE_1( "FolderServiceL() returned : %d", err );
       
   143     
       
   144     TRAP( err, SyncSolutionsServiceL() );
       
   145     LOGGER_WRITE_1( "SyncSolutionsServiceL() returned: %d", err );
       
   146 
       
   147     WriteL( KRootEnd );
       
   148     TRACE_FUNC_EXIT;
       
   149     }
       
   150     
       
   151 // -----------------------------------------------------------------------------
       
   152 // CCapInfo::ConstructL()
       
   153 // Initializes member data
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CCapInfo::ConstructL()
       
   157     {
       
   158     TRACE_FUNC_ENTRY;
       
   159     User::LeaveIfError( iFsSession.Connect() );
       
   160     
       
   161     iHeapBuf = HBufC8::NewL( KMaxSize*2 );
       
   162     iCapList = CCapList::NewL();
       
   163     iIdStack.Reset();
       
   164     
       
   165     iSconInfo = CSconVersionInfo::NewL();
       
   166     TInt err(KErrNone);
       
   167     TRAP(err, iSconInfo->FetchInfoL( iFsSession ));
       
   168     LOGGER_WRITE_1("sconInfo->FetchInfoL() Leaved: %d", err);
       
   169     TRACE_FUNC_EXIT;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CCapInfo::CCapInfo()
       
   174 // Constuctor
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 CCapInfo::CCapInfo()
       
   178     {
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CCapInfo::CapList()
       
   183 // Returns caplist
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 CCapList* CCapInfo::CapList()
       
   187     {
       
   188     TRACE_FUNC;
       
   189     __ASSERT_DEBUG(iCapList, CapUtil::Panic(KErrGeneral));
       
   190     return iCapList;
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CCapInfo::SetCapabilityBuf( CBufFlat* aBuf )
       
   195 // Set capability buffer
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CCapInfo::SetCapabilityBuf( CBufFlat* aBuf )
       
   199     {
       
   200     TRACE_FUNC;
       
   201     iCapabilityBuf=aBuf;
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CCapInfo::GeneralInfoL()
       
   206 // Write general device capability information.
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 void CCapInfo::GeneralInfoL()
       
   210     {
       
   211     TRACE_FUNC_ENTRY;
       
   212     TInt err( KErrNone );
       
   213     TBuf<KBufSize> buf;
       
   214     TBuf<KBufSize> longName;
       
   215     TBuf<KBufSize> coutryCode;
       
   216     TBuf<KBufSize> networkID;
       
   217     
       
   218     WriteTagL(EGeneral, TXmlParser::EElementBegin);
       
   219     
       
   220     if ( !iSconInfo->IsReady() )
       
   221         {
       
   222         LOGGER_WRITE("iSconInfo wasn't ready, call iSconInfo->FetchInfoL");
       
   223         iSconInfo->FetchInfoL( iFsSession );
       
   224         }
       
   225     
       
   226     if ( iSconInfo->iManufacturer )
       
   227         {
       
   228         WriteValueL( EManufacturer, *iSconInfo->iManufacturer );
       
   229         }
       
   230     
       
   231     if ( iSconInfo->iProduct )
       
   232         {
       
   233         WriteValueL( EModel, *iSconInfo->iProduct );
       
   234         }
       
   235     
       
   236     // serial number
       
   237     if ( iSconInfo->iSerialNumber )
       
   238         {
       
   239         WriteValueL( ESN, *iSconInfo->iSerialNumber );
       
   240         }
       
   241     
       
   242     // software version 
       
   243     if ( iSconInfo->iSWVersion )
       
   244         {
       
   245         WriteAttributeL( ESW, *iSconInfo->iSWVersion, iSconInfo->iDate );
       
   246         }
       
   247     
       
   248     // language
       
   249     WriteValueL( ELanguage, iSconInfo->iLanguage );
       
   250 
       
   251     // this must succeed - do not trap
       
   252     MemoryInfoL();
       
   253     
       
   254     // Operator
       
   255     TRAP( err, CapUtil::GetOperatorNameL( longName, coutryCode, networkID ) );
       
   256     LOGGER_WRITE_1( "CapUtil::GGetOperatorNameL returned : %d", err );
       
   257     if( err == KErrNone )
       
   258         {
       
   259         LOGGER_WRITE_3( "CSConFsHandler::GetOperatorNameL longName =  %S coutryCode = %S networkID = %S", &longName, &coutryCode, &networkID );       
       
   260         _LIT( KNetworkInfo, "NetworkInfo" );
       
   261         _LIT( KCurrentNetwork, "CurrentNetwork=" );
       
   262         _LIT( KCountryCode, "CountryCode=" );
       
   263         _LIT( KNetworkID, "NetworkID=" );
       
   264         
       
   265         WriteTagL( EExt, TXmlParser::EElementBegin );
       
   266         WriteValueL( EXNam, KNetworkInfo );
       
   267         
       
   268         // write CurrentNetwork
       
   269         buf.Copy( KCurrentNetwork );
       
   270         buf.Append( longName );
       
   271         WriteValueL( EXVal, buf );
       
   272         
       
   273         // write CountryCode
       
   274         buf.Copy( KCountryCode );
       
   275         buf.Append( coutryCode );
       
   276         WriteValueL( EXVal, buf );
       
   277         
       
   278         // write NetworkID
       
   279         buf.Copy( KNetworkID );
       
   280         buf.Append( networkID );
       
   281         WriteValueL( EXVal, buf );
       
   282         
       
   283         WriteTagL( EExt, TXmlParser::EElementEnd );     
       
   284         }
       
   285     
       
   286     if ( iSconInfo->iModel )
       
   287         {
       
   288         // print modelname (phone model sales name. For example "N01".)
       
   289         WriteTagL( EExt, TXmlParser::EElementBegin );
       
   290         _LIT(KModelName, "ModelName");
       
   291         WriteValueL( EXNam, KModelName );
       
   292         WriteValueL( EXVal, *iSconInfo->iModel );
       
   293         WriteTagL( EExt, TXmlParser::EElementEnd ); 
       
   294         }
       
   295         
       
   296     if ( iSconInfo->iProductCode )
       
   297         {
       
   298         // print productcode
       
   299         WriteTagL( EExt, TXmlParser::EElementBegin );
       
   300         _LIT( KProductCode, "ProductCode" );
       
   301         WriteValueL( EXNam, KProductCode );
       
   302         WriteValueL( EXVal, *iSconInfo->iProductCode );
       
   303         WriteTagL( EExt, TXmlParser::EElementEnd );
       
   304         }
       
   305     
       
   306     
       
   307     // print advanced info
       
   308     WriteTagL( EExt, TXmlParser::EElementBegin );
       
   309     _LIT(KAdvancedDeviceInfo, "AdvancedDeviceInfo");
       
   310     WriteValueL( EXNam, KAdvancedDeviceInfo );
       
   311     
       
   312     TBuf<KSysVersionInfoTextLength> temp;
       
   313     
       
   314     if ( iSconInfo->iRevision )
       
   315         {
       
   316         // product revision. For example "01"
       
   317         _LIT( KRevision, "Revision=" );
       
   318         temp.Copy( KRevision );
       
   319         temp.Append( *iSconInfo->iRevision );
       
   320         LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp );
       
   321         WriteValueL( EXVal, temp );
       
   322         }
       
   323     
       
   324     
       
   325     if ( iSconInfo->iSysVersionInfo )
       
   326         {
       
   327         _LIT( KFWVersion, "FWVersion=" );
       
   328         temp.Copy( KFWVersion );
       
   329         temp.Append( *iSconInfo->iSysVersionInfo );
       
   330         LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp );
       
   331         WriteValueL( EXVal, temp );
       
   332         }
       
   333     
       
   334     SysVersionInfo::TSymbianOSVersion osVersion;
       
   335     err = iSconInfo->GetSymbianVersion( osVersion );
       
   336     LOGGER_WRITE_1("TSymbianOSVersion info error: %d", err)
       
   337     if ( !err )
       
   338         {
       
   339         // Now osVersion contains the Symbian OS version information
       
   340         _LIT( KSymbianOSVersion, "SymbianOSVersion=%d.%d" );
       
   341         temp.Format( KSymbianOSVersion,
       
   342                 osVersion.iMajorVersion,
       
   343                 osVersion.iMinorVersion  );
       
   344         LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp );
       
   345                         
       
   346         WriteValueL( EXVal, temp );
       
   347         }
       
   348     
       
   349     VersionInfo::TPlatformVersion platformVersion;
       
   350     err = iSconInfo->GetS60Version( platformVersion );
       
   351     if ( !err )
       
   352        {
       
   353        _LIT( KS60Version, "S60PlatformVersion=%d.%d" );
       
   354        temp.Format( KS60Version,
       
   355                platformVersion.iMajorVersion,
       
   356                platformVersion.iMinorVersion  );
       
   357        LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp );
       
   358        WriteValueL( EXVal, temp );
       
   359        }
       
   360     
       
   361     
       
   362     if ( iSconInfo->iLangVersion )
       
   363         {
       
   364         _LIT( KLangVersion, "LangVersion=" );
       
   365         temp.Copy( KLangVersion );
       
   366         temp.Append( *iSconInfo->iLangVersion );
       
   367         LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp );
       
   368         WriteValueL( EXVal, temp );
       
   369         }
       
   370     
       
   371     if ( iSconInfo->iLangSWVersion )
       
   372         {
       
   373         _LIT( KLangSWVersion, "LangSWVersion=" );
       
   374         temp.Copy( KLangSWVersion );
       
   375         temp.Append( *iSconInfo->iLangSWVersion );
       
   376         LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp );
       
   377         WriteValueL( EXVal, temp );
       
   378         }
       
   379     
       
   380     if ( iSconInfo->iOPVersion )
       
   381         {
       
   382         // CustomerVersion
       
   383         _LIT( KOPVersion, "OPVersion=" );
       
   384         temp.Copy( KOPVersion );
       
   385         temp.Append( *iSconInfo->iOPVersion );
       
   386         LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp );
       
   387         WriteValueL( EXVal, temp );
       
   388         }
       
   389     
       
   390     // screen size
       
   391     LOGGER_WRITE_2("Size, width: %d, height: %d",
       
   392             iSconInfo->iScreenSize.iWidth,
       
   393             iSconInfo->iScreenSize.iHeight );
       
   394     _LIT( KWidth, "ScreenWidth=%d" );
       
   395     _LIT( KHeight, "ScreenHeight=%d" );
       
   396     
       
   397     temp.Format( KWidth, iSconInfo->iScreenSize.iWidth );
       
   398     WriteValueL( EXVal, temp );
       
   399     
       
   400     temp.Format( KHeight, iSconInfo->iScreenSize.iHeight );
       
   401     WriteValueL( EXVal, temp );
       
   402     
       
   403     WriteTagL( EExt, TXmlParser::EElementEnd ); 
       
   404     // end of advanced info
       
   405     
       
   406     WriteTagL(EGeneral, TXmlParser::EElementEnd);
       
   407     TRACE_FUNC_EXIT;
       
   408     }
       
   409 
       
   410 // -----------------------------------------------------------------------------
       
   411 // CCapInfo::MemoryInfoL()
       
   412 // Create memory info for all drives (RAM excluded).
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 void CCapInfo::MemoryInfoL()
       
   416     {
       
   417     TRACE_FUNC_ENTRY;
       
   418     
       
   419     TMemoryInfo info;
       
   420     TInt devDriveCount = 0;
       
   421     TInt mmcDriveCount = 0;
       
   422     
       
   423     //Write all drivers to folderlisting object
       
   424     TDriveList driveList;
       
   425     // Get all drives that are visible to the user.
       
   426     TInt driveCount;
       
   427     User::LeaveIfError( DriveInfo::GetUserVisibleDrives( iFsSession, driveList, driveCount ) );
       
   428     
       
   429     for( TInt i = EDriveA; i < KMaxDrives; i++ )
       
   430         {
       
   431         if( driveList[i] )
       
   432             {
       
   433             TUint driveStatus;
       
   434             TInt err = DriveInfo::GetDriveStatus( iFsSession, i, driveStatus );
       
   435             if( err )
       
   436                 {
       
   437                 LOGGER_WRITE_1( "CCapInfo::MemoryInfoL() : DriveInfo::GetDriveStatus: %d", i);
       
   438                 continue;
       
   439                 }
       
   440             
       
   441             if( !(driveStatus & DriveInfo::EDrivePresent )
       
   442                 || driveStatus & DriveInfo::EDriveCorrupt
       
   443                 || (driveStatus & DriveInfo::EDriveRemote) )
       
   444                 {
       
   445                 LOGGER_WRITE_1( "skip drive %d", i);
       
   446                 continue;
       
   447                 }
       
   448             
       
   449             TRAP( err, CapUtil::GetMemoryInfoL( iFsSession, i, info ));
       
   450             if ( err )
       
   451                 {
       
   452                 LOGGER_WRITE_1( "CapUtil::GetMemoryInfoL() : Leaved with: %d", err);
       
   453                 continue;
       
   454                 }
       
   455             
       
   456             info.iDriveStatus = driveStatus;
       
   457             if( driveStatus & DriveInfo::EDriveInternal )
       
   458                 {
       
   459                 // if internal (DEV) drive, save drive number
       
   460                 devDriveCount++;
       
   461                 info.iMemNr = devDriveCount;
       
   462                 }
       
   463             else if ( driveStatus & DriveInfo::EDriveRemovable )
       
   464                 {
       
   465                 // if removable (MMC) drive, save drive number
       
   466                 mmcDriveCount++;
       
   467                 info.iMemNr = mmcDriveCount;
       
   468                 }
       
   469             else
       
   470                 {
       
   471                 // was not internal or removable, skip.
       
   472                 LOGGER_WRITE( "CCapInfo::MemoryInfoL() : not internal or removable, skip." );
       
   473                 continue;
       
   474                 }
       
   475                 
       
   476             WriteMemoryInfoL(info);
       
   477             
       
   478             }
       
   479         }
       
   480     
       
   481     TRACE_FUNC_EXIT;
       
   482     }
       
   483 
       
   484 // -----------------------------------------------------------------------------
       
   485 // CCapInfo::MemoryInfoL(TMemoryInfo& aInfo)
       
   486 // Create memory info for all drives (RAM excluded).
       
   487 // -----------------------------------------------------------------------------
       
   488 //
       
   489 void CCapInfo::WriteMemoryInfoL(TMemoryInfo& aInfo)
       
   490     {
       
   491     TRACE_FUNC_ENTRY;
       
   492     TBuf<KBufSize> buf;
       
   493 
       
   494     WriteTagL(EMemory, TXmlParser::EElementBegin);
       
   495 
       
   496     if( aInfo.iDriveStatus & DriveInfo::EDriveInternal )
       
   497         {
       
   498         buf = KMediaFlash;
       
   499         }
       
   500     else
       
   501         {
       
   502         buf = KMediaMMC;  // memory card (MMC)
       
   503         }
       
   504         
       
   505     if( aInfo.iMemNr > 1 )
       
   506         {
       
   507         // append memory number DEV2, MMC2..
       
   508         buf.AppendNum( aInfo.iMemNr ); 
       
   509         }
       
   510     
       
   511     WriteValueL(EMemType, buf);
       
   512     WriteValueL(ELocation, aInfo.iLocation);
       
   513     WriteValueL(EFree, aInfo.iFree);
       
   514     WriteValueL(EUsed, aInfo.iUsed);
       
   515     
       
   516     WriteValueL(EFileNLen, aInfo.iFileNameSize);
       
   517 
       
   518     WriteTagL(EMemory, TXmlParser::EElementEnd);
       
   519     TRACE_FUNC_EXIT;
       
   520     }
       
   521 
       
   522 // -----------------------------------------------------------------------------
       
   523 // CCapInfo::ServiceInfoL(const TDesC& aDir)
       
   524 // Reads service xml-files from directory and writes them into capability 
       
   525 // document.
       
   526 // -----------------------------------------------------------------------------
       
   527 //
       
   528 void CCapInfo::ServiceInfoL(const TDesC& aDir, const RArray<TFileName>& aExcludeList,
       
   529     RArray<TFileName>& aFilesAdded)
       
   530     {
       
   531     TRACE_FUNC_ENTRY;
       
   532     CCapList* capList=CapList();
       
   533 
       
   534     RArray<TFileName> array( KDefaultArrayGranularity );
       
   535     CleanupClosePushL(array);
       
   536 
       
   537     CStringList* stringList=CStringList::NewLC();
       
   538 
       
   539     CapUtil::GetFileListL(iFsSession, aDir, array);
       
   540     
       
   541     _LIT(KFormat, "%S%S");
       
   542     TFileName name;
       
   543     TInt count=array.Count();
       
   544     for (TInt i=0; i<count; i++)
       
   545         {
       
   546         TBool exludeFromList(EFalse);
       
   547         
       
   548         // Check if file is already added to list
       
   549         for ( TInt j=0; j<aExcludeList.Count() && !exludeFromList; j++ )
       
   550             {
       
   551             if ( array[i].CompareF(aExcludeList[j]) == 0 )
       
   552                 {
       
   553                 LOGGER_WRITE_1( "match found at pos %d", j);
       
   554                 exludeFromList = ETrue;
       
   555                 }
       
   556             }
       
   557         
       
   558         if ( !exludeFromList )
       
   559             {
       
   560             name.Format(KFormat, &aDir, &array[i]);
       
   561             if (!CapUtil::CheckFileType(name, KXmlExtension))
       
   562                 {
       
   563                 continue;  // only accept .xml files
       
   564                 }
       
   565             
       
   566             capList->List()->Reset();
       
   567             capList->List()->ReadFromFileL( iFsSession, name );
       
   568             if (capList->FindServiceL(stringList))
       
   569                 {
       
   570                 WriteNewLineL();
       
   571                 WriteFromListL(stringList);
       
   572                 
       
   573                 User::LeaveIfError( aFilesAdded.Append(array[i]) );
       
   574                 LOGGER_WRITE_1( "File '%S' added to list", &array[i] );
       
   575                 }
       
   576             }
       
   577         }
       
   578 
       
   579     CleanupStack::PopAndDestroy(stringList);
       
   580     CleanupStack::PopAndDestroy(&array);
       
   581     TRACE_FUNC_EXIT;
       
   582     }
       
   583 
       
   584 // -----------------------------------------------------------------------------
       
   585 // CCapInfo::FolderServiceL()
       
   586 // Writes folder service. Notice that this service is created in code because
       
   587 // pathinfo component is used to get folder names.
       
   588 // -----------------------------------------------------------------------------
       
   589 //
       
   590 void CCapInfo::FolderServiceL()
       
   591     {
       
   592     TRACE_FUNC_ENTRY;
       
   593     TBuf<KBufSize> rootPath;
       
   594     TBuf<KBufSize> memoryType(KNullDesC);
       
   595     TFileName folderName;
       
   596     _LIT( KFormat, "%S%S" );
       
   597     
       
   598     WriteNewLineL();
       
   599     WriteTagL(EService, TXmlParser::EElementBegin);
       
   600 
       
   601     WriteValueL(EName,  KFolderServiceName);
       
   602     WriteValueL(EUUID,  KFolderServiceUid);
       
   603     WriteValueL(EVersion,  KFolderServiceVersion);
       
   604 
       
   605     WriteTagL(EObject, TXmlParser::EElementBegin);
       
   606     WriteValueL(EType,  KFolderServiceType);
       
   607     WriteTagL(EObject, TXmlParser::EElementEnd);
       
   608     TInt drive;
       
   609     TInt err;
       
   610     
       
   611     CapUtil::GetDefaultRootPathL( iFsSession, rootPath );
       
   612     if( rootPath.Length() > 0 )
       
   613         {
       
   614         err = iFsSession.CharToDrive( rootPath[0], drive );
       
   615         if( err == KErrNone )
       
   616             {
       
   617             CapUtil::GetMemoryType( iFsSession, memoryType, drive );
       
   618             }
       
   619         }
       
   620 
       
   621     // EFolderImages
       
   622     folderName.Format( KFormat, &rootPath, &PathInfo::ImagesPath() );
       
   623     WriteFolderL( KFolderImages, folderName, memoryType );
       
   624     
       
   625     // EFolderGraphics
       
   626     folderName.Format( KFormat, &rootPath, &PathInfo::ImagesPath() );
       
   627     WriteFolderL(KFolderGraphics, folderName, memoryType);
       
   628     
       
   629     // EFolderTones
       
   630     folderName.Format( KFormat, &rootPath, &PathInfo::DigitalSoundsPath() );
       
   631     WriteFolderL(KFolderTones, folderName, memoryType);
       
   632     
       
   633     // EFolderMusic
       
   634     folderName.Format( KFormat, &rootPath, &PathInfo::SoundsPath() );
       
   635     WriteFolderL(KFolderMusic, folderName, memoryType);
       
   636     
       
   637     // EFolderVideos
       
   638     folderName.Format( KFormat, &rootPath, &PathInfo::VideosPath() );
       
   639     WriteFolderL(KFolderVideos, folderName, memoryType);
       
   640     
       
   641     // EFolderInstalls
       
   642     folderName.Format( KFormat, &rootPath, &PathInfo::InstallsPath() );
       
   643     WriteFolderL(KFolderInstalls, folderName, memoryType);
       
   644 
       
   645 
       
   646     WriteTagL(EService, TXmlParser::EElementEnd);
       
   647     WriteNewLineL();
       
   648     TRACE_FUNC_EXIT;
       
   649     }
       
   650 
       
   651 // -----------------------------------------------------------------------------
       
   652 // CCapInfo::SyncSolutionsServiceL()
       
   653 // Reads last used syncSolutions from cenrep and writes to capability object
       
   654 // -----------------------------------------------------------------------------
       
   655 //
       
   656 void CCapInfo::SyncSolutionsServiceL()
       
   657     {
       
   658     TRACE_FUNC_ENTRY;
       
   659     TSConSolutionInfo calendar;
       
   660     TSConSolutionInfo contact;
       
   661     TSConSolutionInfo sms;
       
   662     TSConSolutionInfo bookmark;
       
   663     
       
   664     CSConSyncService *syncService = CSConSyncService::NewLC();
       
   665     syncService->GetSolutionL( KSeconCalendarUid, calendar );
       
   666     syncService->GetSolutionL( KSeconContactsUid, contact );
       
   667     syncService->GetSolutionL( KSeconSmsUid, sms );
       
   668     syncService->GetSolutionL( KSeconBookmarkUid, bookmark );
       
   669     CleanupStack::PopAndDestroy( syncService );
       
   670     
       
   671     WriteSyncSolutionsServiceL( calendar, contact, sms, bookmark );
       
   672     
       
   673     TRACE_FUNC_EXIT;
       
   674     }
       
   675 
       
   676 
       
   677 // -----------------------------------------------------------------------------
       
   678 // CCapInfo::WriteSyncSolutionsServiceL()
       
   679 // Writes SyncSolutionsService data to capability object.
       
   680 // -----------------------------------------------------------------------------
       
   681 //
       
   682 void CCapInfo::WriteSyncSolutionsServiceL( const TSConSolutionInfo& aCalendar,
       
   683         const TSConSolutionInfo& aContact,
       
   684         const TSConSolutionInfo& aSms,
       
   685         const TSConSolutionInfo& aBookmark)
       
   686     {
       
   687     TRACE_FUNC_ENTRY;
       
   688     
       
   689     WriteTagL( EService, TXmlParser::EElementBegin );
       
   690 
       
   691     WriteValueL( EName,  KSyncSolutionsServiceName );
       
   692     WriteValueL( EVersion,  KSyncSolutionsServiceVersion );
       
   693     
       
   694     if ( aCalendar.iUid != 0 )
       
   695         {
       
   696         WriteSolutionTagL( KSyncCalendar, aCalendar );
       
   697         }
       
   698     
       
   699     if ( aContact.iUid != 0 )
       
   700         {
       
   701         WriteSolutionTagL( KSyncContacts, aContact );
       
   702         }
       
   703     
       
   704     if ( aSms.iUid != 0 )
       
   705         {
       
   706         WriteSolutionTagL( KSyncSms, aSms );
       
   707         }
       
   708     
       
   709     if ( aBookmark.iUid != 0 )
       
   710         {
       
   711         WriteSolutionTagL( KSyncBookmark, aBookmark );
       
   712         }
       
   713     
       
   714     /*
       
   715      * <Ext>
       
   716      *   <XNam>DesktopSync</XNam>
       
   717      *   <XVal></XVal>
       
   718      * </Ext>
       
   719      * 
       
   720      */
       
   721     if ( !iSconInfo->iDesktopSyncError )
       
   722         {
       
   723         WriteTagL( EExt, TXmlParser::EElementBegin );
       
   724         WriteValueL( EXNam, KDesktopSync );
       
   725         
       
   726         TBuf<KBufSize> buffer;
       
   727         buffer.AppendNum( iSconInfo->iDesktopSync );
       
   728         
       
   729         WriteValueL( EXVal, buffer );
       
   730         WriteTagL( EExt, TXmlParser::EElementEnd );
       
   731         }
       
   732     
       
   733     
       
   734     
       
   735     WriteTagL( EService, TXmlParser::EElementEnd );
       
   736     TRACE_FUNC_EXIT;
       
   737     }
       
   738 
       
   739 
       
   740 
       
   741 // -----------------------------------------------------------------------------
       
   742 // CCapInfo::WriteSolutionTagL()
       
   743 // Writes SyncSolutionsService solution data to capability object.
       
   744 // -----------------------------------------------------------------------------
       
   745 //
       
   746 void CCapInfo::WriteSolutionTagL( const TDesC& aContentName,
       
   747         const TSConSolutionInfo& aSolution )
       
   748     {
       
   749     TRACE_FUNC_ENTRY;
       
   750     _LIT( KFormatUID, "UID=0x%08x" );
       
   751     _LIT( KFormatName, "Name=%S" );
       
   752     _LIT( KFormatDate, "Timestamp=%04d%02d%02dT%02d%02d%02dZ" );
       
   753     
       
   754     WriteTagL( EExt, TXmlParser::EElementBegin );
       
   755     WriteValueL( EXNam, aContentName );
       
   756     
       
   757     TFileName temp;
       
   758     temp.Format( KFormatUID, aSolution.iUid );
       
   759     WriteValueL( EXVal, temp );
       
   760     
       
   761     temp.Format( KFormatName, &aSolution.iSolutionName );
       
   762     WriteValueL( EXVal, temp );
       
   763     
       
   764     if ( aSolution.iTime.Int64() != 0 )
       
   765         {
       
   766         // write time
       
   767         TDateTime time = aSolution.iTime.DateTime();
       
   768         temp.Format( KFormatDate, time.Year(), time.Month() + 1,
       
   769             time.Day() + 1, time.Hour(), time.Minute(), time.Second() );
       
   770         WriteValueL( EXVal, temp );
       
   771         
       
   772         }
       
   773     
       
   774     
       
   775     WriteTagL( EExt, TXmlParser::EElementEnd );
       
   776     TRACE_FUNC_EXIT;
       
   777     }
       
   778 
       
   779 // -----------------------------------------------------------------------------
       
   780 // CCapInfo::WriteFolderL(const TDesC& aType, const TDesC& aFullName, 
       
   781 // const TDesC& aMemory)
       
   782 // Writes one folder name element.
       
   783 // -----------------------------------------------------------------------------
       
   784 //
       
   785 void CCapInfo::WriteFolderL(const TDesC& aType, const TDesC& aFullName, 
       
   786                             const TDesC& aMemory)
       
   787     {
       
   788     TRACE_FUNC_ENTRY;
       
   789     _LIT(KFormat, "%S=%S");
       
   790 
       
   791     TBuf<KBufSize> buf; 
       
   792     const TInt KReservedSize = 10;
       
   793     if ( aFullName.Length() + KReservedSize > KBufSize )
       
   794         {
       
   795         return;
       
   796         }
       
   797     buf.Format(KFormat, &KFolderNameTag, &aFullName);
       
   798     
       
   799 
       
   800     WriteTagL(EExt, TXmlParser::EElementBegin);
       
   801 
       
   802     WriteValueL(EXNam, aType);
       
   803     WriteValueL(EXVal, buf);
       
   804 
       
   805     buf.Format(KFormat, &KFolderMemoryTypeTag, &aMemory);
       
   806     WriteValueL(EXVal, buf);
       
   807     
       
   808 
       
   809     WriteTagL(EExt, TXmlParser::EElementEnd);
       
   810     TRACE_FUNC_EXIT;
       
   811     }
       
   812 
       
   813 // -----------------------------------------------------------------------------
       
   814 // CCapInfo::WriteL(const TDesC& aText)
       
   815 // Writes one element to capability buffer.
       
   816 // -----------------------------------------------------------------------------
       
   817 //
       
   818 void CCapInfo::WriteL(const TDesC& aText)
       
   819     {
       
   820     if (aText.Length() > iBuf.MaxLength())
       
   821         {
       
   822         User::Leave(KErrTooBig);
       
   823         }
       
   824         
       
   825 
       
   826     iBuf=aText;
       
   827     iBuf.Trim();
       
   828     FormatElement(iBuf);
       
   829     TPtr8 ptr = iHeapBuf->Des();
       
   830 
       
   831     if ( iBuf.Length()+2 > ptr.MaxLength() )
       
   832         {
       
   833         User::Leave(KErrTooBig);
       
   834         }
       
   835         
       
   836     //unicode conversion
       
   837     HBufC8* convBuf = HBufC8::NewLC( iBuf.Size() );
       
   838     TPtr8 convPtr = convBuf->Des();
       
   839     
       
   840     CnvUtfConverter::ConvertFromUnicodeToUtf8(convPtr, iBuf);
       
   841 
       
   842     ptr.Copy(convPtr);
       
   843     ptr.Append( KLineFeed );  // linefeed
       
   844     
       
   845     CleanupStack::PopAndDestroy( convBuf );
       
   846     
       
   847     TInt pos=iCapabilityBuf->Size();
       
   848     iCapabilityBuf->InsertL(pos, ptr);
       
   849 
       
   850     iBuf=KNullDesC;
       
   851     }
       
   852 
       
   853 void CCapInfo::WriteNewLineL()
       
   854     {
       
   855     TInt pos=iCapabilityBuf->Size();
       
   856     iCapabilityBuf->InsertL(pos, KLineFeed );
       
   857     }
       
   858 
       
   859 // -----------------------------------------------------------------------------
       
   860 // CCapInfo::WriteValueL(TInt aId, const TDesC& aValue)
       
   861 // Constructs element with value (eg <Language>en</Language>)
       
   862 // -----------------------------------------------------------------------------
       
   863 //
       
   864 void CCapInfo::WriteValueL(TInt aId, const TDesC& aValue)
       
   865     {
       
   866     // empty values not written to capability object
       
   867     if (aValue.Length()<1)
       
   868         {
       
   869         LOGGER_WRITE( "WriteValueL: value is empty" );
       
   870         return;
       
   871         }
       
   872 
       
   873     TBuf<KBufSize> buf;
       
   874 
       
   875     TRAPD(err, CapParser::MakeElementL(buf, aId, aValue));
       
   876     if (err==KErrNone)
       
   877         {
       
   878         WriteL(buf);
       
   879         }
       
   880     else if (err==KErrTooBig)
       
   881         {
       
   882         WriteBigValueL(aId, aValue);
       
   883         }
       
   884     else
       
   885         {
       
   886         User::Leave(err);
       
   887         }
       
   888     
       
   889     }
       
   890 
       
   891 // -----------------------------------------------------------------------------
       
   892 // CCapInfo::WriteBigValueL(TInt aId, const TDesC& aValue)
       
   893 // Constructs element with value
       
   894 // -----------------------------------------------------------------------------
       
   895 //
       
   896 void CCapInfo::WriteBigValueL(TInt aId, const TDesC& aValue)
       
   897     {
       
   898     HBufC* hBuf=HBufC::NewL(aValue.Length()+KBufSize);
       
   899     CleanupStack::PushL(hBuf);
       
   900 
       
   901     TPtr pBuf(hBuf->Des());
       
   902     CapParser::MakeElementL(pBuf, aId, aValue);
       
   903     WriteL(*hBuf);
       
   904     
       
   905     CleanupStack::PopAndDestroy(hBuf);
       
   906     }
       
   907 
       
   908 // -----------------------------------------------------------------------------
       
   909 // CCapInfo::WriteValueL(TInt aId, TInt64 aValue)
       
   910 // Constructs element with integer value
       
   911 // -----------------------------------------------------------------------------
       
   912 //
       
   913 void CCapInfo::WriteValueL(TInt aId, TInt64 aValue)
       
   914     {
       
   915     TBuf<KBufSize> buf;
       
   916     TBuf<KTagSize> value;
       
   917     CapUtil::IntToStr(value, aValue);
       
   918     CapParser::MakeElementL(buf, aId, value);
       
   919     WriteL(buf);
       
   920     }
       
   921 
       
   922 // -----------------------------------------------------------------------------
       
   923 // CCapInfo::WriteTagL(TInt aId, TInt aType)
       
   924 // Constructs element without value (eg <Memory>)
       
   925 // -----------------------------------------------------------------------------
       
   926 //
       
   927 void CCapInfo::WriteTagL(TInt aId, TInt aType)
       
   928     {
       
   929     TBuf<KBufSize> buf;
       
   930     CapParser::MakeElementL(buf, aId, aType);
       
   931     WriteL(buf);
       
   932     }
       
   933 
       
   934 // -----------------------------------------------------------------------------
       
   935 // CCapInfo::WriteAttributeL(TInt aId, const TDesC& aVersion, const TDesC& aDate)
       
   936 // Constructs element with attributes "Version" and "Date" 
       
   937 // (eg <HW Version="1.5"/>)
       
   938 // -----------------------------------------------------------------------------
       
   939 //
       
   940 void CCapInfo::WriteAttributeL(TInt aId, const TDesC& aVersion, 
       
   941                                 const TDesC& aDate)
       
   942     {
       
   943     // empty values not written to capability object
       
   944     if (aVersion.Length()<1 && aDate.Length()<1)
       
   945         {
       
   946         LOGGER_WRITE( "WriteAttributeL: attributes are empty" );
       
   947         return;
       
   948         }
       
   949     
       
   950     TBuf<KBufSize> buf;
       
   951     CapParser::MakeElementL(buf, aId, aVersion, aDate);
       
   952     WriteL(buf);
       
   953     }
       
   954 
       
   955 // -----------------------------------------------------------------------------
       
   956 // CCapInfo::WriteFromListL(CStringList* aList)
       
   957 // Writes elements from list to capability buffer.
       
   958 // -----------------------------------------------------------------------------
       
   959 //
       
   960 void CCapInfo::WriteFromListL(CStringList* aList)
       
   961     {
       
   962     TInt count=aList->Count();
       
   963 
       
   964     for (TInt i=0; i<count; i++)
       
   965         {
       
   966         WriteL(aList->ReadPtr(i));
       
   967         }
       
   968     }   
       
   969 
       
   970 // -----------------------------------------------------------------------------
       
   971 // CCapInfo::FormatElement(TDes& aText)
       
   972 // Function adds indentation spaces to capability elements to improve 
       
   973 // readability.
       
   974 // -----------------------------------------------------------------------------
       
   975 //
       
   976 void CCapInfo::FormatElement(TDes& aText)
       
   977     {
       
   978     TXmlParser parser;
       
   979 
       
   980     parser.Set(aText);
       
   981     TInt type=parser.Type();
       
   982     TBuf<KTagSize> tag;
       
   983     parser.GetTag(tag);
       
   984         
       
   985     if (type==TXmlParser::EElementEnd)
       
   986         {
       
   987         TInt id1=CapParser::ElementId(tag);
       
   988         TInt id2=iIdStack.Pop();
       
   989         
       
   990         __ASSERT_DEBUG(id1==id2, CapUtil::Panic(KErrGeneral));
       
   991         id1=0;
       
   992         id2=0;
       
   993         }
       
   994 
       
   995     AddFormatText(aText, iIdStack.Size());
       
   996 
       
   997     if (type==TXmlParser::EElementBegin)
       
   998         {
       
   999         TInt id1=CapParser::ElementId(tag);
       
  1000         iIdStack.Push(id1);
       
  1001         }
       
  1002     }
       
  1003 
       
  1004 // -----------------------------------------------------------------------------
       
  1005 // CCapInfo::AddFormatText( TDes& aText, TInt aNum ) const
       
  1006 // Adds format text
       
  1007 // -----------------------------------------------------------------------------
       
  1008 //
       
  1009 void CCapInfo::AddFormatText( TDes& aText, TInt aNum ) const
       
  1010     {
       
  1011     TBuf<KBufSize> buf;
       
  1012     buf = KNullDesC;
       
  1013 
       
  1014     if ( aNum > KNestingLimit )
       
  1015         {
       
  1016         aNum = KNestingLimit;
       
  1017         }
       
  1018         
       
  1019     for ( TInt i=0; i<aNum; i++ )
       
  1020         {
       
  1021         buf.Append( KFormatText );
       
  1022         }
       
  1023     if ( aText.MaxLength()-aText.Length()>buf.Length() )
       
  1024         {
       
  1025         aText.Insert( 0, buf );
       
  1026         }
       
  1027     }
       
  1028     
       
  1029 // End of file
       
  1030 
       
  1031