browserutilities/feedsengine/FeedsServer/Client/src/Item.cpp
changeset 0 dd21522fd290
child 36 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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:  Holds information about a feed item.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "FeedAttributes.h"
       
    20 #include "FeedsServerFeed.h"
       
    21 #include "Logger.h"
       
    22 
       
    23 // Constants
       
    24 _LIT(KNew, "new");
       
    25 _LIT(KRead, "read");
       
    26 _LIT(KUnread, "unread");
       
    27 
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CItem::NewL
       
    31 //
       
    32 // Two-phased constructor.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CItem* CItem::NewL(CFeedsEntity* aFeedsEntity)
       
    36     {
       
    37     CItem* self = new (ELeave) CItem(aFeedsEntity);
       
    38 
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop();
       
    42 
       
    43     return self;
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CItem::CItem
       
    48 // C++ default constructor can NOT contain any code, that
       
    49 // might leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CItem::CItem(CFeedsEntity* aFeedsEntity):iLeakTracker(CLeakTracker::EItem),
       
    53         iFeedsEntity(aFeedsEntity), iTitle(KNullDesC), 
       
    54         iDescription(KNullDesC), iUrl(KNullDesC), iItemStatus(EUnreadItem), iEnclosures(5)
       
    55     {
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CItem::ConstructL
       
    60 // Symbian 2nd phase constructor can leave.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void CItem::ConstructL()
       
    64     {
       
    65     TPtrC   url;    
       
    66     TPtrC   description; 
       
    67     TPtrC   title;
       
    68     TInt    item;
       
    69 
       
    70     iFeedsEntity->GetTimeValue( EItemAttributeTimestamp, iTimestamp);
       
    71 
       
    72     iFeedsEntity->GetStringValue( EItemAttributeLink, url); 
       
    73     SetAttribute( EItemAttributeLink, url);
       
    74 
       
    75     iFeedsEntity->GetStringValue( EItemAttributeDescription, description);
       
    76     SetAttribute( EItemAttributeDescription, description);    
       
    77 
       
    78     iFeedsEntity->GetStringValue( EItemAttributeTitle, title); 
       
    79     SetAttribute( EItemAttributeTitle, title);
       
    80 
       
    81     iFeedsEntity->GetIntegerValue( EItemAttributeStatus, item);
       
    82 
       
    83     switch(item)
       
    84         {
       
    85         case EItemStatusNew:
       
    86              iItemStatus = ENewItem;
       
    87              break;
       
    88 
       
    89         case EItemStatusRead:
       
    90              iItemStatus = EReadItem;
       
    91              break;
       
    92 
       
    93         case EItemStatusUnread:
       
    94              iItemStatus = EUnreadItem;
       
    95              break;
       
    96         }
       
    97 
       
    98     iId = iFeedsEntity->GetId();
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CItem::~CItem
       
   103 // Deconstructor.
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 CItem::~CItem()
       
   107     {
       
   108     // Delete the enclosures.
       
   109     iEnclosures.ResetAndDestroy();
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CItem::Id
       
   114 //
       
   115 // Returns the item's id.
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 EXPORT_C TInt CItem::Id() const
       
   119     {
       
   120     return iId;
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CItem::Title
       
   125 //
       
   126 // Returns the item's title.
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 EXPORT_C const TDesC& CItem::Title() const
       
   130     {
       
   131     return iTitle;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CItem::Description
       
   136 //
       
   137 // Returns the item's description.
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 EXPORT_C const TDesC& CItem::Description() const
       
   141     {    
       
   142     return iDescription;
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CItem::Url
       
   147 //
       
   148 // Returns the item's url.
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C const TDesC& CItem::Url() const
       
   152     {              
       
   153     return iUrl;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CItem::Date
       
   158 //
       
   159 // Returns the item's date.
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 EXPORT_C const TTime& CItem::Timestamp() const
       
   163     {
       
   164     return iTimestamp;
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CItem::ItemStatus
       
   169 //
       
   170 // Returns the item's status.
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 EXPORT_C TItemStatus CItem::ItemStatus() const
       
   174     {
       
   175     return iItemStatus;
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CItem::EnclosureCount
       
   180 //
       
   181 // Returns the number of enclosures.
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 EXPORT_C TInt CItem::EnclosureCount() const
       
   185     {
       
   186     return iEnclosures.Count();
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CItem::ItemAt
       
   191 //
       
   192 // Returns the enclosure at the given index
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 EXPORT_C const CEnclosure& CItem::EnclosureAt(TInt aIndex) const
       
   196     {
       
   197     // TODO: assert if out of range.
       
   198     return *(iEnclosures[aIndex]);
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CItem::AddEnclosureL
       
   203 //
       
   204 // Appends the new enclosure to the Feed.  aItem is adopted by this method.
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 void CItem::AddEnclosureL(CEnclosure* aEnclosure)
       
   208     {
       
   209     User::LeaveIfError(iEnclosures.Append(aEnclosure));
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CItem::SetAttribute
       
   214 //
       
   215 // Sets an attribute.
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CItem::SetAttribute(TUint aAttribute, const TPtrC& aAttributeValue)
       
   219     {
       
   220     switch (aAttribute)
       
   221         {
       
   222         case EItemAttributeTitle:
       
   223             iTitle.Set(aAttributeValue);
       
   224             break;
       
   225 
       
   226         case EItemAttributeDescription:
       
   227             iDescription.Set(aAttributeValue);
       
   228             break;
       
   229 
       
   230         case EItemAttributeLink:
       
   231             iUrl.Set(aAttributeValue);
       
   232             break;
       
   233 
       
   234         case EItemAttributeStatus:
       
   235             if (aAttributeValue.CompareF(KNew) == 0)
       
   236                 {
       
   237                 iItemStatus = ENewItem;
       
   238                 }
       
   239             else if (aAttributeValue.CompareF(KRead) == 0)
       
   240                 {
       
   241                 iItemStatus = EReadItem;
       
   242                 }
       
   243             else if (aAttributeValue.CompareF(KUnread) == 0)
       
   244                 {
       
   245                 iItemStatus = EUnreadItem;
       
   246                 }
       
   247             break;
       
   248 
       
   249         case EItemAttributeTimestamp:
       
   250             {
       
   251             TLex16  lex(aAttributeValue);
       
   252             TInt64  ts;
       
   253               
       
   254             lex.Val(ts);
       
   255             iTimestamp = ts;
       
   256             }
       
   257             break;
       
   258 
       
   259         case EItemAttributeItemId:
       
   260             {
       
   261             TLex16  lex(aAttributeValue);
       
   262             TInt64  id;
       
   263               
       
   264             lex.Val(id);
       
   265             iId = id;
       
   266             }
       
   267             break;
       
   268 
       
   269         default:
       
   270             break;
       
   271         }
       
   272     }
       
   273 
       
   274 //#ifdef _DEBUG
       
   275 // -----------------------------------------------------------------------------
       
   276 // CItem::Debug_Print
       
   277 //
       
   278 // Prints the item to the log file.
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 EXPORT_C void CItem::Debug_Print(void) const
       
   282     {
       
   283     FEED_LOG(_L("Feeds"), _L("Feeds_Dump.log"), 
       
   284         EFileLoggingModeAppend, _L("\tItem:"));
       
   285 
       
   286     if (iTitle.Length() > 0)
       
   287         {
       
   288         FEED_LOG1(_L("Feeds"), _L("Feeds_Dump.log"), 
       
   289             EFileLoggingModeAppend, _L("\t\tTitle: %S"), &iTitle);
       
   290         }
       
   291 
       
   292     if (iUrl.Length() > 0)
       
   293         {
       
   294         FEED_LOG1(_L("Feeds"), _L("Feeds_Dump.log"), 
       
   295             EFileLoggingModeAppend, _L("\t\tLink: %S"), &iUrl);
       
   296         }
       
   297 
       
   298     if (iDescription.Length() > 0)
       
   299         {
       
   300         FEED_LOG1(_L("Feeds"), _L("Feeds_Dump.log"), 
       
   301             EFileLoggingModeAppend, _L("\t\tDescription: %S"), &iDescription);
       
   302         }
       
   303 
       
   304     switch( iItemStatus )
       
   305         {
       
   306         case ENewItem:
       
   307             {            
       
   308             FEED_LOG1(_L("Feeds"), _L("Feeds_Dump.log"), 
       
   309                 EFileLoggingModeAppend, _L("\t\tStatus: %S"), &KNew());
       
   310             }
       
   311             break;
       
   312         case EReadItem:
       
   313             {            
       
   314             FEED_LOG1(_L("Feeds"), _L("Feeds_Dump.log"), 
       
   315                 EFileLoggingModeAppend, _L("\t\tStatus: %S"), &KRead());
       
   316             }
       
   317             break;
       
   318         case EUnreadItem:
       
   319             {
       
   320             FEED_LOG1(_L("Feeds"), _L("Feeds_Dump.log"), 
       
   321                 EFileLoggingModeAppend, _L("\t\tStatus: %S"), &KUnread());
       
   322             }
       
   323             break;
       
   324         }
       
   325 
       
   326     // Print the enclosures.
       
   327     if (iEnclosures.Count() > 0)
       
   328         {        
       
   329         FEED_LOG(_L("Feeds"), _L("Feeds_Dump.log"), 
       
   330             EFileLoggingModeAppend, _L("\tEnclosures:"));
       
   331 
       
   332         for (TInt i = 0; i < iEnclosures.Count(); i++)
       
   333             {
       
   334             iEnclosures[i]->Debug_Print();
       
   335             }
       
   336         }
       
   337     }