2939 TPtrC timeStamp(KNullDesC); |
2939 TPtrC timeStamp(KNullDesC); |
2940 TPtrC title(KNullDesC); |
2940 TPtrC title(KNullDesC); |
2941 TPtrC description(KNullDesC); |
2941 TPtrC description(KNullDesC); |
2942 TPtrC link(KNullDesC); |
2942 TPtrC link(KNullDesC); |
2943 TPtrC itemIdStr(KNullDesC); |
2943 TPtrC itemIdStr(KNullDesC); |
|
2944 TBool isNewItem(EFalse); |
2944 |
2945 |
2945 // Get the values. |
2946 // Get the values. |
2946 for (TInt i = 0; i < aAttributes.Count(); i++) |
2947 for (TInt i = 0; i < aAttributes.Count(); i++) |
2947 { |
2948 { |
2948 switch (aAttributes[i].token) |
2949 switch (aAttributes[i].token) |
2966 case EItemAttributeTimestamp: |
2967 case EItemAttributeTimestamp: |
2967 timeStamp.Set(aAttributes[i].value); |
2968 timeStamp.Set(aAttributes[i].value); |
2968 break; |
2969 break; |
2969 } |
2970 } |
2970 } |
2971 } |
2971 |
|
2972 // Ignore the item if it is already in the database. |
|
2973 // TODO: Don't ignore it if the timestamp changes. In this case |
|
2974 // the item needs to be updated below rather than inserted. |
|
2975 TInt id; |
|
2976 |
|
2977 if (FindItemL(aFeedId, itemIdStr, id)) |
|
2978 { |
|
2979 // If the item is found then append it's id to aItemIds. |
|
2980 aItemIds.AppendL(id); |
|
2981 |
|
2982 return EFalse; |
|
2983 } |
|
2984 |
|
2985 // Otherwise this is a new item so append the provided id to aItemIds. |
|
2986 else |
|
2987 { |
|
2988 aItemIds.AppendL(aItemId); |
|
2989 } |
|
2990 |
2972 |
2991 // If timeStamp was provided convert it into a TTime otherwise just |
2973 // If timeStamp was provided convert it into a TTime otherwise just |
2992 // use the current time. |
2974 // use the current time. |
2993 TTime date; |
2975 TTime date; |
2994 |
2976 |
3002 } |
2984 } |
3003 else |
2985 else |
3004 { |
2986 { |
3005 date.UniversalTime(); |
2987 date.UniversalTime(); |
3006 } |
2988 } |
3007 |
2989 |
3008 // Update the database. |
2990 // Ignore the item if it is already in the database. |
3009 iItemTable.Reset(); |
2991 // If the timestamp chnages the item needs to be updated |
3010 iItemTable.InsertL(); |
2992 // rather than inserted. |
3011 |
2993 TInt id; |
|
2994 |
|
2995 if (FindItemL(aFeedId, itemIdStr, id)) |
|
2996 { |
|
2997 TDbSeekKey seekKey( id ); |
|
2998 // Update the database. |
|
2999 iItemTable.SeekL(seekKey); |
|
3000 iItemTable.GetL(); |
|
3001 |
|
3002 TBuf<(KMaxTimeFormatSpec + KMaxShortDateFormatSpec) * 2> previousTimestamp; |
|
3003 TTime previousDate = iItemTable.ColTime(iItemColSet->ColNo(KDate)); |
|
3004 previousDate.FormatL(previousTimestamp, TTimeFormatSpec()); |
|
3005 |
|
3006 if (date == previousDate) |
|
3007 { |
|
3008 // If the item is found and timestamp remains same then just |
|
3009 // append it's id to aItemIds. |
|
3010 aItemIds.AppendL(id); |
|
3011 return isNewItem; |
|
3012 } |
|
3013 else |
|
3014 { |
|
3015 // If the item is found and the timestamp has changed then make sure that |
|
3016 // the new itemId is appened to aItemIds. |
|
3017 aItemIds.AppendL(aItemId); |
|
3018 iItemTable.GetL(); |
|
3019 iItemTable.UpdateL(); |
|
3020 } |
|
3021 } |
|
3022 |
|
3023 // Otherwise this is a new item so append the provided id to aItemIds. |
|
3024 else |
|
3025 { |
|
3026 aItemIds.AppendL(aItemId); |
|
3027 |
|
3028 // Update the database. |
|
3029 iItemTable.Reset(); |
|
3030 iItemTable.InsertL(); |
|
3031 isNewItem = ETrue; |
|
3032 } |
|
3033 |
3012 iItemTable.SetColL(iItemColSet->ColNo(KItemId), aItemId); |
3034 iItemTable.SetColL(iItemColSet->ColNo(KItemId), aItemId); |
3013 iItemTable.SetColL(iItemColSet->ColNo(KFeedId), aFeedId); |
3035 iItemTable.SetColL(iItemColSet->ColNo(KFeedId), aFeedId); |
3014 iItemTable.SetColL(iItemColSet->ColNo(KDate), date); |
3036 iItemTable.SetColL(iItemColSet->ColNo(KDate), date); |
3015 iItemTable.SetColL(iItemColSet->ColNo(KItemStatus), ENewItem); |
3037 iItemTable.SetColL(iItemColSet->ColNo(KItemStatus), ENewItem); |
3016 iItemTable.SetColL(iItemColSet->ColNo(KTitle_100MaxLen), title.Left(K100MaxLen)); |
3038 iItemTable.SetColL(iItemColSet->ColNo(KTitle_100MaxLen), title.Left(K100MaxLen)); |
3017 WriteLongTextL(iItemTable, iItemColSet->ColNo(KDescription), description); |
3039 WriteLongTextL(iItemTable, iItemColSet->ColNo(KDescription), description); |
3018 WriteLongTextL(iItemTable, iItemColSet->ColNo(KWebUrl), link); |
3040 WriteLongTextL(iItemTable, iItemColSet->ColNo(KWebUrl), link); |
3019 WriteLongTextL(iItemTable, iItemColSet->ColNo(KItemIdStr), itemIdStr); |
3041 WriteLongTextL(iItemTable, iItemColSet->ColNo(KItemIdStr), itemIdStr); |
3020 |
3042 |
3021 iItemTable.PutL(); |
3043 iItemTable.PutL(); |
3022 |
3044 return isNewItem; |
3023 return ETrue; |
|
3024 } |
3045 } |
3025 |
3046 |
3026 |
3047 |
3027 // ----------------------------------------------------------------------------- |
3048 // ----------------------------------------------------------------------------- |
3028 // CFeedsDatabase::CommitEnclosureL |
3049 // CFeedsDatabase::CommitEnclosureL |
4503 TPtrC title( KNullDesC ); |
4524 TPtrC title( KNullDesC ); |
4504 title.Set(iItemTable.ColDes16(iItemColSet->ColNo(KTitle_100MaxLen))); |
4525 title.Set(iItemTable.ColDes16(iItemColSet->ColNo(KTitle_100MaxLen))); |
4505 HBufC* idStr = NULL; |
4526 HBufC* idStr = NULL; |
4506 ReadLongTextL(iItemTable, iItemColSet->ColNo(KItemIdStr), idStr); |
4527 ReadLongTextL(iItemTable, iItemColSet->ColNo(KItemIdStr), idStr); |
4507 CleanupStack::PushL(idStr); |
4528 CleanupStack::PushL(idStr); |
|
4529 TPtrC idStrPtr(idStr->Des()); |
4508 |
4530 |
4509 switch( itemStatus ) |
4531 switch( itemStatus ) |
4510 { |
4532 { |
4511 case EUnreadItem: |
4533 case EUnreadItem: |
4512 { |
4534 { |
4513 FEED_LOG6(_L("Feeds"), _L("Feeds_DB.log"), |
4535 FEED_LOG6(_L("Feeds"), _L("Feeds_DB.log"), |
4514 EFileLoggingModeAppend, _L("%d\t%d\t%S\t%S\t%S\t%S"), |
4536 EFileLoggingModeAppend, _L("%d\t%d\t%S\t%S\t%S\t%S"), |
4515 itemId, feedId, &KUnread(), &idStr->Des(), &title, ×tamp); |
4537 itemId, feedId, &KUnread(), &idStrPtr, &title, ×tamp); |
4516 } |
4538 } |
4517 break; |
4539 break; |
4518 case EReadItem: |
4540 case EReadItem: |
4519 { |
4541 { |
4520 FEED_LOG6(_L("Feeds"), _L("Feeds_DB.log"), |
4542 FEED_LOG6(_L("Feeds"), _L("Feeds_DB.log"), |
4521 EFileLoggingModeAppend, _L("%d\t%d\t%S\t%S\t%S\t%S"), |
4543 EFileLoggingModeAppend, _L("%d\t%d\t%S\t%S\t%S\t%S"), |
4522 itemId, feedId, &KRead(), &idStr->Des(), &title, ×tamp); |
4544 itemId, feedId, &KRead(), &idStrPtr, &title, ×tamp); |
4523 } |
4545 } |
4524 break; |
4546 break; |
4525 case ENewItem: |
4547 case ENewItem: |
4526 { |
4548 { |
4527 FEED_LOG6(_L("Feeds"), _L("Feeds_DB.log"), |
4549 FEED_LOG6(_L("Feeds"), _L("Feeds_DB.log"), |
4528 EFileLoggingModeAppend, _L("%d\t%d\t%S\t%S\t%S\t%S"), |
4550 EFileLoggingModeAppend, _L("%d\t%d\t%S\t%S\t%S\t%S"), |
4529 itemId, feedId, &KNew(), &idStr->Des(), &title, ×tamp); |
4551 itemId, feedId, &KNew(), &idStrPtr, &title, ×tamp); |
4530 } |
4552 } |
4531 break; |
4553 break; |
4532 } |
4554 } |
4533 |
4555 |
4534 CleanupStack::PopAndDestroy(/*idStr*/); |
4556 CleanupStack::PopAndDestroy(/*idStr*/); |