contentcontrolsrv/hscontentinfo/src/hscontentinfo.cpp
changeset 85 7feec50967db
parent 4 1a2a00e78665
child 86 e492551a0d54
equal deleted inserted replaced
4:1a2a00e78665 85:7feec50967db
     1 /*
       
     2  * Copyright (c) 2008 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:  
       
    15  *
       
    16  */
       
    17 
       
    18 // System include files
       
    19 #include <utf.h>
       
    20 
       
    21 // User include files
       
    22 #include "hscontentinfo.h"
       
    23 
       
    24 // Local constants
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // -----------------------------------------------------------------------
       
    29 // CHsContentInfo::NewL()
       
    30 // -----------------------------------------------------------------------
       
    31 //
       
    32 EXPORT_C CHsContentInfo* CHsContentInfo::NewL()
       
    33     {
       
    34     CHsContentInfo* self = CHsContentInfo::NewLC();
       
    35     CleanupStack::Pop( self );
       
    36     return self;
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------
       
    40 // CHsContentInfo::NewL()
       
    41 // -----------------------------------------------------------------------
       
    42 //
       
    43 EXPORT_C CHsContentInfo* CHsContentInfo::NewL( RReadStream& aStream )
       
    44     {
       
    45     CHsContentInfo* self = new ( ELeave ) CHsContentInfo();
       
    46     CleanupStack::PushL( self );
       
    47     self->InternalizeL( aStream );
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }   
       
    51     
       
    52 // -----------------------------------------------------------------------
       
    53 // CHsContentInfo::NewLC()
       
    54 // -----------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CHsContentInfo* CHsContentInfo::NewLC()
       
    57     {
       
    58     CHsContentInfo* self = new ( ELeave ) CHsContentInfo();
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     return self;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------
       
    65 // CHsContentInfo::CloneL()
       
    66 // -----------------------------------------------------------------------
       
    67 //
       
    68 EXPORT_C CHsContentInfo* CHsContentInfo::CloneL()
       
    69     {
       
    70     CHsContentInfo* clone = new ( ELeave ) CHsContentInfo();
       
    71     CleanupStack::PushL( clone );
       
    72     
       
    73     clone->iName = Name().AllocL();
       
    74     clone->iUid = Uid().AllocL();
       
    75     clone->iPluginId = PluginId().AllocL();
       
    76     clone->iType = Type().AllocL();
       
    77     clone->iPublisherId = PublisherId().AllocL();
       
    78     clone->iDescription = Description().AllocL();
       
    79     clone->iIconPath = IconPath().AllocL();
       
    80     clone->iMaxInstance = iMaxInstance;
       
    81     clone->iCanBeAdded = iCanBeAdded;
       
    82     clone->iCanBeRemoved = iCanBeRemoved;
       
    83     clone->iInstallationTime = iInstallationTime;
       
    84     clone->iPublisherUid = PublisherUid().AllocL();
       
    85     clone->iIsWrt = iIsWrt;
       
    86     
       
    87     CleanupStack::Pop();
       
    88     return clone;
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------
       
    92 // CHsContentInfo::ConstructL()
       
    93 // -----------------------------------------------------------------------
       
    94 //
       
    95 void CHsContentInfo::ConstructL()
       
    96     {
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------
       
   100 // CHsContentInfo::CHsContentInfo()
       
   101 // -----------------------------------------------------------------------
       
   102 //
       
   103 CHsContentInfo::CHsContentInfo()
       
   104     {
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------
       
   108 // CHsContentInfo::~CHsContentInfo()
       
   109 // -----------------------------------------------------------------------
       
   110 //
       
   111 CHsContentInfo::~CHsContentInfo()
       
   112     {
       
   113     delete iName;
       
   114     delete iUid;
       
   115     delete iPluginId;
       
   116     delete iType;
       
   117     delete iPublisherId;
       
   118     delete iDescription;
       
   119     delete iIconPath;
       
   120     delete iPublisherUid;
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CHsContentInfo::SetNameL
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C void CHsContentInfo::SetNameL( const TDesC8& aName )
       
   128     {
       
   129     delete iName;
       
   130     iName = 0;
       
   131     iName = CnvUtfConverter::ConvertToUnicodeFromUtf8L( aName );
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CHsContentInfo::SetNameL
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 EXPORT_C void CHsContentInfo::SetNameL( const TDesC& aName )
       
   139     {
       
   140     delete iName;
       
   141     iName = 0;
       
   142     iName = aName.AllocL();
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // CHsContentInfo::SetPublisherIdL
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 EXPORT_C void CHsContentInfo::SetPublisherIdL(
       
   150     const TDesC& aPublisherId )
       
   151     {
       
   152     delete iPublisherId;
       
   153     iPublisherId = 0;
       
   154     iPublisherId = aPublisherId.AllocL();
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CHsContentInfo::SetUidL
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C void CHsContentInfo::SetUidL( const TDesC8& aUid )
       
   162     {
       
   163     delete iUid;
       
   164     iUid = 0;
       
   165     iUid = aUid.AllocL();
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CHsContentInfo::SetPluginIdL
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 EXPORT_C void CHsContentInfo::SetPluginIdL( const TDesC8& aId )
       
   173     {
       
   174     delete iPluginId;
       
   175     iPluginId = 0;
       
   176     iPluginId = aId.AllocL();
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // CHsContentInfo::SetTypeL
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 EXPORT_C void CHsContentInfo::SetTypeL( const TDesC8& aType )
       
   184     {
       
   185     delete iType;
       
   186     iType = 0;
       
   187     iType = aType.AllocL();
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CHsContentInfo::Name
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 EXPORT_C const TDesC& CHsContentInfo::Name()const
       
   195     {
       
   196     return ( iName ) ? *iName : KNullDesC();  
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // CHsContentInfo::PublisherId
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 EXPORT_C const TDesC& CHsContentInfo::PublisherId()const
       
   204     {
       
   205     return ( iPublisherId ) ? *iPublisherId : KNullDesC(); 
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // CHsContentInfo::Uid
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 EXPORT_C const TDesC8& CHsContentInfo::Uid()const
       
   213     {
       
   214     return ( iUid ) ? *iUid : KNullDesC8();
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // CHsContentInfo::NameAs8BitLC
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 EXPORT_C HBufC8* CHsContentInfo::NameAs8BitLC()const
       
   222     {    
       
   223     HBufC8* ret( CnvUtfConverter::ConvertFromUnicodeToUtf8L( Name() ) );    
       
   224     CleanupStack::PushL( ret );
       
   225     
       
   226     return ret;
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // CHsContentInfo::PluginId
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 EXPORT_C const TDesC8& CHsContentInfo::PluginId()const
       
   234     {
       
   235     return ( iPluginId ) ? *iPluginId : KNullDesC8();
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // CHsContentInfo::Type
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 EXPORT_C const TDesC8& CHsContentInfo::Type()const
       
   243     {
       
   244     return ( iType ) ? *iType : KNullDesC8();
       
   245     }
       
   246 
       
   247 // -----------------------------------------------------------------------
       
   248 // CPublisherInfo::SetMaxWidgets()
       
   249 // -----------------------------------------------------------------------
       
   250 //
       
   251 EXPORT_C void CHsContentInfo::SetMaxWidgets( TInt aMaxWidget )
       
   252    {
       
   253    iMaxInstance = aMaxWidget;
       
   254    }
       
   255 
       
   256 // -----------------------------------------------------------------------
       
   257 // CPublisherInfo::MaxWidgets()
       
   258 // -----------------------------------------------------------------------
       
   259 //
       
   260 EXPORT_C TInt CHsContentInfo::MaxWidgets() const
       
   261    {
       
   262    return iMaxInstance;
       
   263    }
       
   264    
       
   265 // -----------------------------------------------------------------------
       
   266 // CHsContentInfo::ExternalizeL()
       
   267 // -----------------------------------------------------------------------
       
   268 //     
       
   269 EXPORT_C void CHsContentInfo::ExternalizeL( RWriteStream& aStream )
       
   270 	{
       
   271 	// Keep this externalize routine in-sync with header file's members
       
   272 	
       
   273     // externalize iName	
       
   274     aStream.WriteInt16L( Name().Size() );
       
   275     aStream << Name();
       
   276 	
       
   277     // externalize iUid
       
   278     aStream.WriteInt16L( Uid().Size() );
       
   279     aStream << Uid();
       
   280         
       
   281     // externalize iPluginId;
       
   282     aStream.WriteInt16L( PluginId().Size() );
       
   283     aStream << PluginId();
       
   284     
       
   285     // externalize iType;       
       
   286     aStream.WriteInt16L( Type().Size() );
       
   287     aStream << Type();
       
   288    
       
   289     // externalize iPublisherId;		
       
   290     aStream.WriteInt16L( PublisherId().Size() );
       
   291     aStream << PublisherId();
       
   292 
       
   293     // externalize iDescription;        
       
   294     aStream.WriteInt16L( Description().Size() );
       
   295     aStream << Description();
       
   296        
       
   297     // externalize iIconPath;        
       
   298     aStream.WriteInt16L( IconPath().Size() );
       
   299     aStream << IconPath();
       
   300 
       
   301     // externalize iMaxInstance
       
   302     aStream.WriteInt16L( iMaxInstance );
       
   303     // externalize iCanBeAdded
       
   304     aStream.WriteInt16L( iCanBeAdded );
       
   305     // externalize iCanBeRemoved
       
   306     aStream.WriteInt16L( iCanBeRemoved );    
       
   307     
       
   308     TInt64 time( iInstallationTime.Int64() );
       
   309     
       
   310     TUint32 low( I64LOW( time ) );
       
   311     TUint32 high( I64HIGH( time ) );
       
   312 
       
   313     // externalize iInstallationTime
       
   314     aStream.WriteUint32L( low );
       
   315     aStream.WriteUint32L( high );
       
   316     
       
   317     // externalize iPublisherUid
       
   318     aStream.WriteInt16L( PublisherUid().Size() );
       
   319     aStream << PublisherUid();
       
   320     
       
   321     // externalise iIsWrt
       
   322     aStream.WriteInt16L( iIsWrt );
       
   323 	}
       
   324 
       
   325 // -----------------------------------------------------------------------
       
   326 // CHsContentInfo::SetCanBeAdded()
       
   327 // -----------------------------------------------------------------------
       
   328 //   
       
   329 EXPORT_C void CHsContentInfo::SetCanBeAdded( TBool aValue )
       
   330     {
       
   331     iCanBeAdded = aValue;
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------
       
   335 // CHsContentInfo::CanBeAdded()
       
   336 // -----------------------------------------------------------------------
       
   337 //   
       
   338 EXPORT_C TBool CHsContentInfo::CanBeAdded() const
       
   339     {
       
   340     return iCanBeAdded;
       
   341     }
       
   342 
       
   343 // -----------------------------------------------------------------------
       
   344 // CHsContentInfo::SetCanBeRemoved()
       
   345 // -----------------------------------------------------------------------
       
   346 //   
       
   347 EXPORT_C void CHsContentInfo::SetCanBeRemoved( TBool aValue )
       
   348     {
       
   349     iCanBeRemoved = aValue;
       
   350     }
       
   351 
       
   352 // -----------------------------------------------------------------------
       
   353 // CHsContentInfo::CanBeRemoved()
       
   354 // -----------------------------------------------------------------------
       
   355 //   
       
   356 EXPORT_C TBool CHsContentInfo::CanBeRemoved() const
       
   357     {
       
   358     return iCanBeRemoved;
       
   359     }
       
   360 
       
   361 // -----------------------------------------------------------------------
       
   362 // CHsContentInfo::SetInstallationTime()
       
   363 // -----------------------------------------------------------------------
       
   364 //   
       
   365 EXPORT_C void CHsContentInfo::SetInstallationTime( TTime& aTime )
       
   366     {
       
   367     iInstallationTime = aTime;
       
   368     }
       
   369 
       
   370 // -----------------------------------------------------------------------
       
   371 // CHsContentInfo::InstallationTime()
       
   372 // -----------------------------------------------------------------------
       
   373 //   
       
   374 EXPORT_C TTime CHsContentInfo::InstallationTime() const
       
   375     {
       
   376     return iInstallationTime;
       
   377     }
       
   378 
       
   379 // ---------------------------------------------------------------------------
       
   380 // CHsContentInfo::SetDescriptionL
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 EXPORT_C void CHsContentInfo::SetDescriptionL( const TDesC8& aDescription )
       
   384     {
       
   385     delete iDescription;
       
   386     iDescription = NULL;
       
   387     iDescription = CnvUtfConverter::ConvertToUnicodeFromUtf8L( aDescription );
       
   388     }
       
   389 
       
   390 // -----------------------------------------------------------------------
       
   391 // CHsContentInfo::SetDescriptionL()
       
   392 // -----------------------------------------------------------------------
       
   393 //   
       
   394 EXPORT_C void CHsContentInfo::SetDescriptionL( const TDesC& aDescription )
       
   395     {
       
   396     delete iDescription;
       
   397     iDescription = NULL;
       
   398     iDescription = aDescription.AllocL();
       
   399     }
       
   400 
       
   401 // -----------------------------------------------------------------------
       
   402 // CHsContentInfo::Description()
       
   403 // -----------------------------------------------------------------------
       
   404 //   
       
   405 EXPORT_C const TDesC& CHsContentInfo::Description() const
       
   406     {
       
   407     return ( iDescription ) ? *iDescription : KNullDesC();
       
   408     }
       
   409 
       
   410 // -----------------------------------------------------------------------
       
   411 // CHsContentInfo::SetIconPathL()
       
   412 // -----------------------------------------------------------------------
       
   413 //   
       
   414 EXPORT_C void CHsContentInfo::SetIconPathL( const TDesC& aIconPath )
       
   415     {
       
   416     delete iIconPath;
       
   417     iIconPath = NULL;
       
   418     
       
   419     iIconPath = aIconPath.AllocL();    
       
   420     }
       
   421 
       
   422 // -----------------------------------------------------------------------
       
   423 // CHsContentInfo::IconPath()
       
   424 // -----------------------------------------------------------------------
       
   425 //   
       
   426 EXPORT_C const TDesC& CHsContentInfo::IconPath() const
       
   427     {
       
   428     return ( iIconPath ) ? *iIconPath : KNullDesC();
       
   429     }
       
   430 
       
   431 // -----------------------------------------------------------------------
       
   432 // CHsContentInfo::InternalizeL()
       
   433 // -----------------------------------------------------------------------
       
   434 //   
       
   435 EXPORT_C void CHsContentInfo::InternalizeL( RReadStream& aStream )
       
   436     {
       
   437     TInt length( 0 );	
       
   438 
       
   439     // internalize iName
       
   440     length = aStream.ReadInt16L();
       
   441     delete iName;
       
   442     iName = NULL;
       
   443     iName = HBufC::NewL( aStream, length );
       
   444     
       
   445     // internalize iUid    
       
   446     length = aStream.ReadInt16L();
       
   447     delete iUid;
       
   448     iUid = NULL;
       
   449     iUid = HBufC8::NewL( aStream, length );
       
   450 
       
   451     // internalize iPluginId
       
   452     length = aStream.ReadInt16L();
       
   453     delete iPluginId;
       
   454     iPluginId = NULL;
       
   455     iPluginId = HBufC8::NewL( aStream, length );
       
   456     
       
   457     // internalize iType
       
   458     length = aStream.ReadInt16L();
       
   459     delete iType;
       
   460     iType = NULL;
       
   461     iType = HBufC8::NewL( aStream, length );
       
   462     
       
   463     // internalize iPlublisherId;
       
   464     length = aStream.ReadInt16L();
       
   465     delete iPublisherId;
       
   466     iPublisherId = NULL;
       
   467     iPublisherId = HBufC16::NewL( aStream, length );
       
   468 
       
   469     // internalize iDescription;
       
   470     length = aStream.ReadInt16L();
       
   471     delete iDescription;
       
   472     iDescription = NULL;
       
   473     iDescription = HBufC16::NewL( aStream, length );
       
   474 
       
   475     // internalize iIconPath;
       
   476     length = aStream.ReadInt16L();
       
   477     delete iIconPath;
       
   478     iIconPath = NULL;
       
   479     iIconPath = HBufC16::NewL( aStream, length );
       
   480         
       
   481     // internalize iMaxInstance
       
   482     iMaxInstance = aStream.ReadInt16L();
       
   483     // internalize iCanBeAdded
       
   484     iCanBeAdded = aStream.ReadInt16L();
       
   485     // internalize iCanBeRemoved
       
   486     iCanBeRemoved = aStream.ReadInt16L();
       
   487     
       
   488     TUint32 low( aStream.ReadUint32L() );
       
   489     TUint32 high( aStream.ReadUint32L() );
       
   490     
       
   491     iInstallationTime = TTime( MAKE_TINT64( high, low ) );
       
   492     
       
   493     // internalize iPublisherUid    
       
   494     length = aStream.ReadInt16L();
       
   495     delete iPublisherUid;
       
   496     iPublisherUid = NULL;
       
   497     iPublisherUid = HBufC8::NewL( aStream, length );
       
   498     
       
   499     // internalize iIsWrt
       
   500     iIsWrt = aStream.ReadInt16L();
       
   501     }
       
   502 
       
   503 // -----------------------------------------------------------------------
       
   504 // CHsContentInfo::Size()
       
   505 // -----------------------------------------------------------------------
       
   506 //   
       
   507 EXPORT_C TInt CHsContentInfo::Size( )
       
   508     {
       
   509     TInt size( 0 );   
       
   510     size = size + Name().Size();        // name
       
   511     size = size + Uid().Size();         // uid
       
   512     size = size + PluginId().Size();    // plugin id
       
   513     size = size + Type().Size();        // type
       
   514     size = size + PublisherId().Size(); // publisher id
       
   515     size = size + Description().Size(); // description
       
   516     size = size + IconPath().Size();    // icon path
       
   517     size = size + sizeof( TInt16 );     // max instance
       
   518     size = size + sizeof( TInt16 );     // can be added
       
   519     size = size + sizeof( TInt16 );     // can be removed
       
   520     size = size + sizeof( TUint32 );    // installation time low
       
   521     size = size + sizeof( TUint32 );    // installation time high
       
   522     size = size + PublisherUid().Size();// publisher uid
       
   523     size = size + sizeof( TInt16 );     // is wrt
       
   524     
       
   525     return size;
       
   526     }   
       
   527 
       
   528 // -----------------------------------------------------------------------
       
   529 // CHsContentInfo::SetPublisherUidL()
       
   530 // -----------------------------------------------------------------------
       
   531 //   
       
   532 EXPORT_C void CHsContentInfo::SetPublisherUidL(
       
   533     const TDesC8& aPublisherUid )
       
   534     {
       
   535     delete iPublisherUid;
       
   536     iPublisherUid = 0;
       
   537     iPublisherUid = aPublisherUid.AllocL();
       
   538     }
       
   539 
       
   540 // -----------------------------------------------------------------------
       
   541 // CHsContentInfo::PublisherUid()
       
   542 // -----------------------------------------------------------------------
       
   543 // 
       
   544 EXPORT_C const TDesC8& CHsContentInfo::PublisherUid() const
       
   545     {
       
   546     return ( iPublisherUid ) ? *iPublisherUid : KNullDesC8();
       
   547     }
       
   548 
       
   549 // -----------------------------------------------------------------------
       
   550 // CHsContentInfo::SetIsWrt()
       
   551 // -----------------------------------------------------------------------
       
   552 //   
       
   553 EXPORT_C void CHsContentInfo::SetIsWrt( TBool aIsWrt )    
       
   554     {
       
   555     iIsWrt = aIsWrt;
       
   556     }
       
   557 
       
   558 // -----------------------------------------------------------------------
       
   559 // CHsContentInfo::IsWrt()
       
   560 // -----------------------------------------------------------------------
       
   561 // 
       
   562 EXPORT_C TBool CHsContentInfo::IsWrt() const
       
   563     {
       
   564     return iIsWrt;
       
   565     }
       
   566 
       
   567 // -----------------------------------------------------------------------
       
   568 // CHsContentInfo::MarshalL()
       
   569 // -----------------------------------------------------------------------
       
   570 //   
       
   571 EXPORT_C HBufC8* CHsContentInfo::MarshalL( )
       
   572     {
       
   573 
       
   574     // Externalize message
       
   575     CBufFlat* reqBuf = CBufFlat::NewL( Size() );
       
   576     CleanupStack::PushL( reqBuf );
       
   577     RBufWriteStream reqStream( *reqBuf );
       
   578     CleanupClosePushL( reqStream );
       
   579     ExternalizeL( reqStream );
       
   580     CleanupStack::PopAndDestroy( &reqStream );
       
   581     
       
   582     // Append externalized messgae to a descriptor
       
   583     HBufC8* msgDesc = HBufC8::NewL( reqBuf->Size() );
       
   584     TPtr8 msgPtr( NULL, 0 ); 
       
   585     msgPtr.Set( msgDesc->Des() );
       
   586     reqBuf->Read( 0, msgPtr, reqBuf->Size() );
       
   587     CleanupStack::PopAndDestroy( reqBuf );
       
   588     
       
   589     return msgDesc;
       
   590     
       
   591     }   
       
   592 
       
   593 // End of file