76 iDrive( -1 ), |
76 iDrive( -1 ), |
77 iReplaceItemId( -1 ), |
77 iReplaceItemId( -1 ), |
78 iRXEntryType( ENSmlNotSet ), |
78 iRXEntryType( ENSmlNotSet ), |
79 iTXEntryType( ENSmlNotSet ), |
79 iTXEntryType( ENSmlNotSet ), |
80 iIsHierarchicalSyncSupported( EFalse ), |
80 iIsHierarchicalSyncSupported( EFalse ), |
81 iParentItemId( 0 ) |
81 iParentItemId( 0 ), |
|
82 iOrphanEvent( EFalse ) |
82 { |
83 { |
83 FLOG(_L("CNSmlAgendaDataStore::CNSmlAgendaDataStore(): BEGIN")); |
84 FLOG(_L("CNSmlAgendaDataStore::CNSmlAgendaDataStore(): BEGIN")); |
84 // RD_MULTICAL |
85 // RD_MULTICAL |
85 iDataMimeType = ENSmlNone; |
86 iDataMimeType = ENSmlNone; |
86 iAgendaAdapterHandler = NULL; |
87 iAgendaAdapterHandler = NULL; |
252 TInt err( KErrNone ); |
253 TInt err( KErrNone ); |
253 if ( aStoreName == KNSmlAgendaFileNameForDefaultDB ) |
254 if ( aStoreName == KNSmlAgendaFileNameForDefaultDB ) |
254 { |
255 { |
255 FLOG(_L("CNSmlAgendaDataStore::DoOpenL: Calling the OpenStoreL: '%S'"), &aStoreName); |
256 FLOG(_L("CNSmlAgendaDataStore::DoOpenL: Calling the OpenStoreL: '%S'"), &aStoreName); |
256 TRAP( err, OpenStoreL() ); |
257 TRAP( err, OpenStoreL() ); |
257 } |
258 } |
258 else |
|
259 { |
|
260 // Provided profile is created from the DS Application |
|
261 FLOG(_L("CNSmlAgendaDataStore::DoOpenL: storename: '%S'"), &aStoreName); |
|
262 if ( iOpenedStoreName ) |
|
263 { |
|
264 delete iOpenedStoreName; |
|
265 iOpenedStoreName = NULL; |
|
266 } |
|
267 iOpenedStoreName = aStoreName.AllocL(); |
|
268 |
|
269 CCalSession* calsession = CCalSession::NewL(); |
|
270 CleanupStack::PushL(calsession); |
|
271 TRAP( err, calsession->OpenL( aStoreName ) ); |
|
272 if ( err ) |
|
273 { |
|
274 FLOG(_L("CNSmlAgendaDataStore::DoOpenL: Cannot open the session: '%d'"), err); |
|
275 CleanupStack::PopAndDestroy( calsession ); |
|
276 User::RequestComplete( iCallerStatus, err ); |
|
277 return; |
|
278 } |
|
279 |
|
280 // Disable notifications |
|
281 TRAP_IGNORE( calsession->DisablePubSubNotificationsL() ); |
|
282 TRAP_IGNORE( calsession->DisableChangeBroadcast() ); |
|
283 // Get ID of database |
|
284 calsession->FileIdL( iOpenedStoreId ); |
|
285 |
|
286 // Close the session |
|
287 CleanupStack::PopAndDestroy( calsession ); |
|
288 } |
|
289 |
259 |
290 if ( err ) |
260 if ( err ) |
291 { |
261 { |
292 User::RequestComplete( iCallerStatus, err ); |
262 User::RequestComplete( iCallerStatus, err ); |
293 return; |
263 return; |
777 iDataMimeType = ENSmlCalendar; |
747 iDataMimeType = ENSmlCalendar; |
778 |
748 |
779 TInt err( KErrNone ); |
749 TInt err( KErrNone ); |
780 // Check the Sync Status |
750 // Check the Sync Status |
781 if( iIsHierarchicalSyncSupported ) |
751 if( iIsHierarchicalSyncSupported ) |
782 { |
752 { |
783 TBool syncstatus( EFalse ); |
753 FLOG(_L("CNSmlAgendaDataStore::DoCreateItemL Supports Hierarchichal")); |
784 TRAP( err, syncstatus = iAgendaAdapterHandler->FolderSyncStatusL( aParent ) ); |
754 // Check that parent exists |
|
755 iParentItemId = aParent; |
|
756 if ( iParentItemId == KDbItemUidRoot |
|
757 && iDataMimeType == ENSmlCalendar ) |
|
758 { |
|
759 FLOG(_L("CNSmlAgendaDataStore::DoCreateItemL: ParentId is NULL")); |
|
760 iParentItemId = NULL; |
|
761 iOrphanEvent = ETrue; |
|
762 iParentItemId = KDbPersonal; |
|
763 } |
|
764 |
|
765 TInt index = KErrNotFound; |
|
766 TInt err = KErrNone; |
|
767 TKeyArrayFix key( 0, ECmpTInt ); // Find key for Ids. |
|
768 |
|
769 err = iCalOffsetArr->Find( iParentItemId, key, index ); |
|
770 |
|
771 if( err != KErrNone && iDataMimeType == ENSmlCalendar ) |
|
772 { |
|
773 FLOG(_L("CNSmlAgendaDataStore::DoCreateItemL: ParentId is NotFound")); |
|
774 iParentItemId = NULL; |
|
775 iOrphanEvent = EFalse; |
|
776 User::RequestComplete( iCallerStatus, KErrNotFound ); |
|
777 return; |
|
778 } |
|
779 // Check the Sync Status |
|
780 TBool syncstatus( EFalse ); |
|
781 TRAP( err, syncstatus = iAgendaAdapterHandler->FolderSyncStatusL( iParentItemId ) ); |
785 if( err || !syncstatus ) |
782 if( err || !syncstatus ) |
786 { |
783 { |
|
784 iOrphanEvent = EFalse; |
787 User::RequestComplete( iCallerStatus, err ); |
785 User::RequestComplete( iCallerStatus, err ); |
788 FLOG(_L("CNSmlAgendaDataStore::DoCreateItemL - Sync Disabled: END")); |
786 FLOG(_L("CNSmlAgendaDataStore::DoCreateItemL - Sync Disabled: END")); |
789 return; |
787 return; |
790 } |
788 } |
791 } |
789 } |
835 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
833 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
836 FLOG(_L("CNSmlAgendaDataStore::DoCreateItemL: end with leave")); |
834 FLOG(_L("CNSmlAgendaDataStore::DoCreateItemL: end with leave")); |
837 return; |
835 return; |
838 } |
836 } |
839 |
837 |
840 if( iIsHierarchicalSyncSupported ) |
838 // TODO: Any other validation is required ? |
841 { |
|
842 // Check that parent exists |
|
843 iParentItemId = aParent; |
|
844 if ( iParentItemId == KDbItemUidRoot |
|
845 && iDataMimeType == ENSmlCalendar ) |
|
846 { |
|
847 FLOG(_L("CNSmlAgendaDataStore::DoCreateItemL: ParentId is NULL")); |
|
848 iParentItemId = NULL; |
|
849 User::RequestComplete( iCallerStatus, KErrGeneral ); |
|
850 return; |
|
851 } |
|
852 |
|
853 TInt index = KErrNotFound; |
|
854 TInt err = KErrNone; |
|
855 TKeyArrayFix key( 0, ECmpTInt ); // Find key for Ids. |
|
856 |
|
857 err = iCalOffsetArr->Find( iParentItemId, key, index ); |
|
858 |
|
859 if( err != KErrNone && iDataMimeType == ENSmlCalendar ) |
|
860 { |
|
861 FLOG(_L("CNSmlAgendaDataStore::DoCreateItemL: ParentId is NotFound")); |
|
862 iParentItemId = NULL; |
|
863 User::RequestComplete( iCallerStatus, KErrNotFound ); |
|
864 return; |
|
865 } |
|
866 } |
|
867 |
|
868 // TODO: Any other validation is required ? |
|
869 |
839 |
870 // Register snapshots if needed |
840 // Register snapshots if needed |
871 if( !iSnapshotRegistered ) |
841 if( !iSnapshotRegistered ) |
872 { |
842 { |
873 RegisterSnapshotL(); |
843 RegisterSnapshotL(); |
2215 |
2185 |
2216 if( err != KErrNone || NULL == calfilename ) |
2186 if( err != KErrNone || NULL == calfilename ) |
2217 { |
2187 { |
2218 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL:Invalid CalendarInfo")); |
2188 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL:Invalid CalendarInfo")); |
2219 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
2189 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
|
2190 iOrphanEvent = EFalse; |
2220 User::Leave( KErrNotFound ); |
2191 User::Leave( KErrNotFound ); |
2221 } |
2192 } |
2222 |
2193 |
2223 agendautil = CNSmlAgendaDataStoreUtil::NewL(); |
2194 agendautil = CNSmlAgendaDataStoreUtil::NewL(); |
2224 if( agendautil ) |
2195 if( agendautil ) |
2231 if ( err || !agendautil ) |
2202 if ( err || !agendautil ) |
2232 { |
2203 { |
2233 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL:Invalid CalendarInfo")); |
2204 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL:Invalid CalendarInfo")); |
2234 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
2205 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
2235 delete calfilename; |
2206 delete calfilename; |
|
2207 iOrphanEvent = EFalse; |
2236 User::Leave( KErrNotFound ); |
2208 User::Leave( KErrNotFound ); |
2237 } |
2209 } |
2238 |
2210 |
2239 if ( iRXEntryType == ENSmlICal ) |
2211 if ( iRXEntryType == ENSmlICal ) |
2240 { |
2212 { |
2251 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
2223 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
2252 delete agendautil; |
2224 delete agendautil; |
2253 delete calfilename; |
2225 delete calfilename; |
2254 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \ |
2226 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \ |
2255 KErrNotSupported: END")); |
2227 KErrNotSupported: END")); |
|
2228 iOrphanEvent = EFalse; |
2256 User::Leave( KErrNotSupported ); |
2229 User::Leave( KErrNotSupported ); |
2257 } |
2230 } |
2258 |
2231 |
2259 // If rdArray is empty or there is multiple items then return error |
2232 // If rdArray is empty or there is multiple items then return error |
2260 // Multiple items are not supported |
2233 // Multiple items are not supported |
2263 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
2236 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
2264 delete agendautil; |
2237 delete agendautil; |
2265 delete calfilename; |
2238 delete calfilename; |
2266 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \ |
2239 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \ |
2267 Multiple items are not supported: END")); |
2240 Multiple items are not supported: END")); |
|
2241 iOrphanEvent = EFalse; |
2268 User::Leave( KErrNotSupported ); |
2242 User::Leave( KErrNotSupported ); |
2269 } |
2243 } |
2270 |
2244 |
2271 err = KErrNone; |
2245 err = KErrNone; |
2272 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: before StoreL")); |
2246 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: before StoreL")); |
2277 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
2251 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
2278 delete agendautil; |
2252 delete agendautil; |
2279 delete calfilename; |
2253 delete calfilename; |
2280 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \ |
2254 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \ |
2281 Error at storing item to database: END")); |
2255 Error at storing item to database: END")); |
|
2256 iOrphanEvent = EFalse; |
2282 User::Leave( KErrGeneral ); |
2257 User::Leave( KErrGeneral ); |
2283 } |
2258 } |
2284 |
2259 |
2285 *iAddItemId = rdArray[0]->LocalUidL(); |
2260 *iAddItemId = rdArray[0]->LocalUidL(); |
2286 CCalEntry* newEntry = agendautil->iEntryView->FetchL( *iAddItemId ); |
2261 CCalEntry* newEntry = agendautil->iEntryView->FetchL( *iAddItemId ); |
2320 CleanupStack::PopAndDestroy();// newEntry, |
2295 CleanupStack::PopAndDestroy();// newEntry, |
2321 } |
2296 } |
2322 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
2297 CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream |
2323 delete agendautil; |
2298 delete agendautil; |
2324 delete calfilename; |
2299 delete calfilename; |
2325 |
2300 |
|
2301 if( iOrphanEvent ) |
|
2302 { |
|
2303 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: Exiting with invalidparent")); |
|
2304 // Set the Orphan Event ID to the cenrep |
|
2305 CRepository* rep = CRepository::NewLC(KRepositoryId); |
|
2306 TInt err = rep->Set( KNsmlDsOrphanEvent, *iAddItemId ); |
|
2307 DBG_ARGS(_S("set the cenrep %d "), err); |
|
2308 User::LeaveIfError(err); |
|
2309 CleanupStack::PopAndDestroy(rep); |
|
2310 iOrphanEvent = EFalse; |
|
2311 User::Leave( KErrPathNotFound ); |
|
2312 } |
2326 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: END")); |
2313 FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: END")); |
2327 } |
2314 } |
2328 |
2315 |
2329 // ----------------------------------------------------------------------------- |
2316 // ----------------------------------------------------------------------------- |
2330 // CNSmlAgendaDataStore::DoCommitReplaceCalItemL |
2317 // CNSmlAgendaDataStore::DoCommitReplaceCalItemL |
3157 CDesCArray* calfilearr = vCalSession->ListCalFilesL(); |
3144 CDesCArray* calfilearr = vCalSession->ListCalFilesL(); |
3158 CleanupStack::PushL(calfilearr); |
3145 CleanupStack::PushL(calfilearr); |
3159 |
3146 |
3160 for(TInt i = 0; i < calfilearr->Count(); i++) |
3147 for(TInt i = 0; i < calfilearr->Count(); i++) |
3161 { |
3148 { |
|
3149 TInt err = KErrNone; |
3162 vCalSubSession = CCalSession::NewL(*vCalSession); |
3150 vCalSubSession = CCalSession::NewL(*vCalSession); |
3163 CleanupStack::PushL(vCalSubSession); |
3151 CleanupStack::PushL(vCalSubSession); |
3164 vCalSubSession->OpenL(calfilearr->MdcaPoint(i)); |
3152 vCalSubSession->OpenL(calfilearr->MdcaPoint(i)); |
3165 |
3153 |
3166 CCalCalendarInfo* caleninfo = vCalSubSession->CalendarInfoL(); |
3154 CCalCalendarInfo* caleninfo = vCalSubSession->CalendarInfoL(); |
3167 CleanupStack::PushL(caleninfo); |
3155 CleanupStack::PushL(caleninfo); |
3168 |
3156 |
|
3157 //Get MARKASDELETE MetaData property |
|
3158 keyBuff.Zero(); |
|
3159 TBool markAsdelete = EFalse; |
|
3160 keyBuff.AppendNum( EMarkAsDelete ); |
|
3161 TPckgC<TBool> pckMarkAsDelete(markAsdelete); |
|
3162 TRAP(err,pckMarkAsDelete.Set(caleninfo->PropertyValueL(keyBuff))); |
|
3163 if ( err == KErrNone ) |
|
3164 { |
|
3165 markAsdelete = pckMarkAsDelete(); |
|
3166 if( markAsdelete ) |
|
3167 { |
|
3168 FLOG(_L("CNSmlAgendaDataStore::IsCalFileAvailableL: Dead Calendar")); |
|
3169 CleanupStack::PopAndDestroy(caleninfo); |
|
3170 CleanupStack::PopAndDestroy(vCalSubSession); |
|
3171 continue; |
|
3172 } |
|
3173 } |
|
3174 |
|
3175 //Get the ProfileId MetaData property |
3169 TInt ProfileId; |
3176 TInt ProfileId; |
3170 keyBuff.Zero(); |
3177 keyBuff.Zero(); |
3171 keyBuff.AppendNum( EDeviceSyncProfileID ); |
3178 keyBuff.AppendNum( EDeviceSyncProfileID ); |
3172 TPckgC<TInt> intBuf(ProfileId); |
3179 TPckgC<TInt> intBuf(ProfileId); |
3173 TRAPD(err,intBuf.Set(caleninfo->PropertyValueL(keyBuff))); |
3180 TRAP(err,intBuf.Set(caleninfo->PropertyValueL(keyBuff))); |
3174 |
3181 |
3175 if( err != KErrNone ) |
3182 if( err != KErrNone ) |
3176 { |
3183 { |
3177 FLOG(_L("CNSmlAgendaDataStore::IsCalFileAvailable: Error while retrieving CalFile Property")); |
3184 FLOG(_L("CNSmlAgendaDataStore::IsCalFileAvailable: Error while retrieving CalFile Property")); |
3178 CleanupStack::PopAndDestroy(caleninfo); |
3185 CleanupStack::PopAndDestroy(caleninfo); |